Skip to content

Commit 2b1bf05

Browse files
authored
fix: check runtime exports to generate esm annotation list (#1147)
1 parent 1d85e7d commit 2b1bf05

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

.changeset/silent-spies-marry.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
"@smithy/abort-controller": patch
3+
"@smithy/chunked-blob-reader": patch
4+
"@smithy/chunked-blob-reader-native": patch
5+
"@smithy/config-resolver": patch
6+
"@smithy/core": patch
7+
"@smithy/credential-provider-imds": patch
8+
"@smithy/eventstream-codec": patch
9+
"@smithy/eventstream-serde-browser": patch
10+
"@smithy/eventstream-serde-config-resolver": patch
11+
"@smithy/eventstream-serde-node": patch
12+
"@smithy/eventstream-serde-universal": patch
13+
"@smithy/experimental-identity-and-auth": patch
14+
"@smithy/fetch-http-handler": patch
15+
"@smithy/hash-blob-browser": patch
16+
"@smithy/hash-node": patch
17+
"@smithy/hash-stream-node": patch
18+
"@smithy/invalid-dependency": patch
19+
"@smithy/is-array-buffer": patch
20+
"@smithy/md5-js": patch
21+
"@smithy/middleware-apply-body-checksum": patch
22+
"@smithy/middleware-compression": patch
23+
"@smithy/middleware-content-length": patch
24+
"@smithy/middleware-endpoint": patch
25+
"@smithy/middleware-retry": patch
26+
"@smithy/middleware-serde": patch
27+
"@smithy/middleware-stack": patch
28+
"@smithy/node-config-provider": patch
29+
"@smithy/node-http-handler": patch
30+
"@smithy/property-provider": patch
31+
"@smithy/protocol-http": patch
32+
"@smithy/querystring-builder": patch
33+
"@smithy/querystring-parser": patch
34+
"@smithy/service-client-documentation-generator": patch
35+
"@smithy/service-error-classification": patch
36+
"@smithy/shared-ini-file-loader": patch
37+
"@smithy/signature-v4": patch
38+
"@smithy/smithy-client": patch
39+
"@smithy/types": patch
40+
"@smithy/url-parser": patch
41+
"@smithy/util-base64": patch
42+
"@smithy/util-body-length-browser": patch
43+
"@smithy/util-body-length-node": patch
44+
"@smithy/util-buffer-from": patch
45+
"@smithy/util-config-provider": patch
46+
"@smithy/util-defaults-mode-browser": patch
47+
"@smithy/util-defaults-mode-node": patch
48+
"@smithy/util-endpoints": patch
49+
"@smithy/util-hex-encoding": patch
50+
"@smithy/util-middleware": patch
51+
"@smithy/util-retry": patch
52+
"@smithy/util-stream": patch
53+
"@smithy/util-stream-browser": patch
54+
"@smithy/util-stream-node": patch
55+
"@smithy/util-uri-escape": patch
56+
"@smithy/util-utf8": patch
57+
"@smithy/util-waiter": patch
58+
"@smithy/util-test": patch
59+
---
60+
61+
generate dist-cjs with runtime list of export names for esm

scripts/compilation/Inliner.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,33 @@ module.exports = class Inliner {
276276
}
277277

278278
/**
279-
* step 6: we validate that the index.js file has a require statement
279+
* Step 6: "Annotate the CommonJS export names for ESM import in node",
280+
* except, correctly.
281+
*/
282+
async annotateCjsExportNames() {
283+
if (this.bailout) {
284+
return this;
285+
}
286+
const exportNames = Object.keys(require(this.outfile));
287+
/* (find and replace the following)
288+
0 && (module.exports = {
289+
...
290+
});
291+
*/
292+
this.indexContents = this.indexContents.replace(
293+
/0 && \(module\.exports = \{((.|\n)*?)\}\);/,
294+
`
295+
0 && (module.exports = {
296+
${exportNames.join(",\n ")}
297+
});
298+
`
299+
);
300+
fs.writeFileSync(this.outfile, this.indexContents, "utf-8");
301+
return this;
302+
}
303+
304+
/**
305+
* step 7: we validate that the index.js file has a require statement
280306
* for any variant files, to ensure they are not in the inlined (bundled) index.
281307
*/
282308
async validate() {

scripts/inline.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ if (!package) {
3535
await inliner.rewriteStubs();
3636
await inliner.fixVariantImportPaths();
3737
await inliner.dedupeExternals();
38+
await inliner.annotateCjsExportNames();
3839
await inliner.validate();
3940
})();
4041
}

0 commit comments

Comments
 (0)