Skip to content

Commit

Permalink
fix: check runtime exports to generate esm annotation list (#1147)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Jan 19, 2024
1 parent 1d85e7d commit 2b1bf05
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .changeset/silent-spies-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
"@smithy/abort-controller": patch
"@smithy/chunked-blob-reader": patch
"@smithy/chunked-blob-reader-native": patch
"@smithy/config-resolver": patch
"@smithy/core": patch
"@smithy/credential-provider-imds": patch
"@smithy/eventstream-codec": patch
"@smithy/eventstream-serde-browser": patch
"@smithy/eventstream-serde-config-resolver": patch
"@smithy/eventstream-serde-node": patch
"@smithy/eventstream-serde-universal": patch
"@smithy/experimental-identity-and-auth": patch
"@smithy/fetch-http-handler": patch
"@smithy/hash-blob-browser": patch
"@smithy/hash-node": patch
"@smithy/hash-stream-node": patch
"@smithy/invalid-dependency": patch
"@smithy/is-array-buffer": patch
"@smithy/md5-js": patch
"@smithy/middleware-apply-body-checksum": patch
"@smithy/middleware-compression": patch
"@smithy/middleware-content-length": patch
"@smithy/middleware-endpoint": patch
"@smithy/middleware-retry": patch
"@smithy/middleware-serde": patch
"@smithy/middleware-stack": patch
"@smithy/node-config-provider": patch
"@smithy/node-http-handler": patch
"@smithy/property-provider": patch
"@smithy/protocol-http": patch
"@smithy/querystring-builder": patch
"@smithy/querystring-parser": patch
"@smithy/service-client-documentation-generator": patch
"@smithy/service-error-classification": patch
"@smithy/shared-ini-file-loader": patch
"@smithy/signature-v4": patch
"@smithy/smithy-client": patch
"@smithy/types": patch
"@smithy/url-parser": patch
"@smithy/util-base64": patch
"@smithy/util-body-length-browser": patch
"@smithy/util-body-length-node": patch
"@smithy/util-buffer-from": patch
"@smithy/util-config-provider": patch
"@smithy/util-defaults-mode-browser": patch
"@smithy/util-defaults-mode-node": patch
"@smithy/util-endpoints": patch
"@smithy/util-hex-encoding": patch
"@smithy/util-middleware": patch
"@smithy/util-retry": patch
"@smithy/util-stream": patch
"@smithy/util-stream-browser": patch
"@smithy/util-stream-node": patch
"@smithy/util-uri-escape": patch
"@smithy/util-utf8": patch
"@smithy/util-waiter": patch
"@smithy/util-test": patch
---

generate dist-cjs with runtime list of export names for esm
28 changes: 27 additions & 1 deletion scripts/compilation/Inliner.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,33 @@ module.exports = class Inliner {
}

/**
* step 6: we validate that the index.js file has a require statement
* Step 6: "Annotate the CommonJS export names for ESM import in node",
* except, correctly.
*/
async annotateCjsExportNames() {
if (this.bailout) {
return this;
}
const exportNames = Object.keys(require(this.outfile));
/* (find and replace the following)
0 && (module.exports = {
...
});
*/
this.indexContents = this.indexContents.replace(
/0 && \(module\.exports = \{((.|\n)*?)\}\);/,
`
0 && (module.exports = {
${exportNames.join(",\n ")}
});
`
);
fs.writeFileSync(this.outfile, this.indexContents, "utf-8");
return this;
}

/**
* step 7: we validate that the index.js file has a require statement
* for any variant files, to ensure they are not in the inlined (bundled) index.
*/
async validate() {
Expand Down
1 change: 1 addition & 0 deletions scripts/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if (!package) {
await inliner.rewriteStubs();
await inliner.fixVariantImportPaths();
await inliner.dedupeExternals();
await inliner.annotateCjsExportNames();
await inliner.validate();
})();
}

0 comments on commit 2b1bf05

Please sign in to comment.