Skip to content

Update entrypoint.js to enable star exportsΒ #219

@ojkelly

Description

@ojkelly

Discussed in #102

Originally posted by icereval January 4, 2021
Is your feature request related to a problem? Please describe.
Unable to load the handler function from entrypoint.js in AWS Lambda.

Describe the solution you'd like
When loading the bundle.zip into AWS Lambda and referencing its handler function via bundle/entrypoint.js, it would be ideal if the entrypoint.js was re-exporting module functions.

Describe alternatives you've considered
Leveraging typescript, we can convert a simple export within the existing project, and thus copy its transpiled __exportStar polyfill to a custom app.js (nearly equivalent to entrypoint.js).

https://github.com/ojkelly/yarn.build/blob/trunk/packages/plugins/plugin-build/src/commands/bundle/index.ts#L274-L284

app.js

'use strict';
require('./.pnp.js').setup();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  if (k2 === undefined) k2 = k;
  Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
  if (k2 === undefined) k2 = k;
  o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
  for (var p in m) if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, '__esModule', { value: true });
__exportStar(require(`./packages/${process.env.PACKAGE_NAME}/dist/index.js`), exports);

Additional context
This would depend on the project's tsconfig.json target polyfills, and would likely be best to perform this step in the yarn bundle command itself, with a call to tsc and an entrypoint.ts file.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions