Giter VIP home page Giter VIP logo

funpack's People

Contributors

doteric avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

funpack's Issues

Infinite Loop in 1.3.0

I'm guessing this is related to circular dependencies again.

Function
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;
}
package.json ``` { "name": "@lambdapub/testpoints", "main": "testpoints.js", "type": "module", "scripts": { "lint": "eslint .", "lint-fix": "eslint --fix .", "test": "NODE_ENV=test tap -R dot", "build": "funpack" }, "engines": { "node": ">=16.13.0" }, "devDependencies": { "funpack": "^1.3.0", }, "dependencies": { "@aws-sdk/client-ssm": "^3.222.0", }, "funpack": { "settings": { "outputDir": "../dist", "cleanupOutputDir": false, "esbuildConfigOverride": { "format": "esm", "target": "node16", "sourcemap": true, "splitting": true }, "packageFieldsToCopy": [ "type" ] }, "functions": { "activitypub": "./testpoints.js" } } } ```

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'
]

TODO: Add settings presets

  • Basic (Default, current setup)
  • ESM (esmodules with additionally copying the type from the package.json)
  • ESM with splitting? Same as above, but additionally with splitting?
  • Anything else?

AWS lambda esm builds

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"
        }
      },

Request: Code splitting

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.