diff --git a/.changeset/silent-spies-marry.md b/.changeset/silent-spies-marry.md new file mode 100644 index 00000000000..95c1871bd53 --- /dev/null +++ b/.changeset/silent-spies-marry.md @@ -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 diff --git a/scripts/compilation/Inliner.js b/scripts/compilation/Inliner.js index fd7ce645d86..910765f3d47 100644 --- a/scripts/compilation/Inliner.js +++ b/scripts/compilation/Inliner.js @@ -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() { diff --git a/scripts/inline.js b/scripts/inline.js index 6ece8ec2f5d..031b147e22f 100644 --- a/scripts/inline.js +++ b/scripts/inline.js @@ -35,6 +35,7 @@ if (!package) { await inliner.rewriteStubs(); await inliner.fixVariantImportPaths(); await inliner.dedupeExternals(); + await inliner.annotateCjsExportNames(); await inliner.validate(); })(); }