doteric / funpack Goto Github PK
View Code? Open in Web Editor NEWFunctions Packager (for AWS Lambdas for example)
Home Page: https://www.npmjs.com/package/funpack
Functions Packager (for AWS Lambdas for example)
Home Page: https://www.npmjs.com/package/funpack
I'm guessing this is related to circular dependencies again.
import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm";
import fs from 'fs';
let local;
try {
const json = fs.readFileSync('./config.json');
local = JSON.parse(json);
} catch (e) {
console.error('Could not parse local config: ' + e.message);
local = {};
}
async function getParameter (Name, WithDecryption = true) {
const client = new SSMClient();
const command = new GetParameterCommand({
Name,
WithDecryption,
});
const { Parameter } = await client.send(command);
return Parameter;
}
export async function activitypub (event, context) {
const config = getParameter(local.SSM_PARAMETER);
const res = {
statusCode: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify({ event, context, local, config }),
};
return res;
}
It drops into a loop of this, over and over:
Circular dependency detected! Chain: [
'../node_modules/@aws-sdk/client-ssm/dist-cjs/index.js',
'../node_modules/@aws-sdk/client-ssm/dist-cjs/SSMClient.js',
'../node_modules/@aws-sdk/client-ssm/dist-cjs/runtimeConfig.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sts/dist-cjs/index.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sts/dist-cjs/STS.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sts/dist-cjs/STSClient.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sts/dist-cjs/runtimeConfig.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-node/dist-cjs/defaultProvider.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/index.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/fromSSO.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/resolveSSOCredentials.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/token-providers/dist-cjs/index.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/token-providers/dist-cjs/fromSso.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/token-providers/dist-cjs/getNewSsoOidcToken.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sso-oidc/dist-cjs/index.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sso-oidc/dist-cjs/SSOOIDCClient.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sso-oidc/dist-cjs/runtimeConfig.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sso-oidc/dist-cjs/runtimeConfig.shared.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sso-oidc/dist-cjs/endpoint/endpointResolver.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-endpoints/dist-cjs/index.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-endpoints/dist-cjs/resolveEndpoint.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-endpoints/dist-cjs/utils/index.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-endpoints/dist-cjs/utils/evaluateRules.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-endpoints/dist-cjs/utils/evaluateErrorRule.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-endpoints/dist-cjs/utils/evaluateExpression.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-endpoints/dist-cjs/utils/callFunction.js',
'../node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-endpoints/dist-cjs/utils/evaluateExpression.js'
]
type
from the package.json)Thanks for the project! ๐ The "type": "module"
isn't passed down to package.json on built functions. AWS lambda thinks the module is a commonJS module and fails to parse.
Another option tried is editing the esbuild ext:
"esbuildConfigOverride": {
"format": "esm",
"target": "node18",
"outExtension": {
".js": ".mjs"
}
},
If you have anything you would like to be added, changed or fixed then feel free to create an issue or discussion and we'll see what we can sort out.
Appreciate the feedback also ๐ช
My function file has a collection of dynamically imported pathways that I only load on request, to reduce cold start time.
const ROUTES = {
route1: () => import('./routes/route1.js'),
route2: () => import('./routes/route2.js')
};
I tried to enable esbuild's code splitting function through config overrides, like so:
"funpack": {
"settings": {
"outputDir": "./dist",
"esbuildConfigOverride": {
"format": "esm",
"target": "node16",
"sourcemap": true,
"splitting": true,
"outdir": "./dist",
"outfile": ""
}
},
"functions": {
"activitypub": "./endpoints.js"
}
}
Note, I had to pass an empty string to outfile, because you can't use both outdir and outfile at the same time.
The problem is, when generatePackageJson hits this blank outfile, it throws up an error, because it doesn't know where to write the main file. Esbuild is generating an endpoints.js
file in the dist folder, so I'm thinking this an configuration concern? I'm not sure how to address it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.