Skip to content

Commit 59c5b59

Browse files
authored
test: validate canonical exports after inline transform (#5699)
1 parent 447852f commit 59c5b59

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ codegen/sdk-codegen/smithy-build-*.json
4040
*/out/
4141
*/*/out/
4242
workspace
43+
./scripts/compilation/tmp/*.mjs
4344

4445
.turbo
4546
coverage

scripts/compilation/Inliner.js

+13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = class Inliner {
4848
async tsc() {
4949
await spawnProcess("yarn", ["tsc", "-p", "tsconfig.cjs.json"], { cwd: this.packageDirectory });
5050
console.log("Finished recompiling ./dist-cjs in " + this.package);
51+
this.canonicalExports = Object.keys(require(this.outfile));
5152
return this;
5253
}
5354

@@ -57,6 +58,7 @@ module.exports = class Inliner {
5758
*/
5859
async discoverVariants() {
5960
if (this.bailout) {
61+
console.log("Inliner bailout.");
6062
return this;
6163
}
6264
this.variantEntries = Object.entries(this.pkgJson["react-native"] ?? {});
@@ -338,6 +340,17 @@ module.exports = class Inliner {
338340
" were not found in the index."
339341
);
340342
}
343+
344+
// check ESM compat.
345+
const tmpFileContents = this.canonicalExports
346+
.filter((sym) => !sym.includes(":"))
347+
.map((sym) => `import { ${sym} } from "${this.pkgJson.name}";`)
348+
.join("\n");
349+
fs.writeFileSync(path.join(__dirname, "tmp", this.package + ".mjs"), tmpFileContents, "utf-8");
350+
await spawnProcess("node", [path.join(__dirname, "tmp", this.package + ".mjs")]);
351+
console.log("ESM compatibility verified.");
352+
fs.rmSync(path.join(__dirname, "tmp", this.package + ".mjs"));
353+
341354
return this;
342355
}
343356
};

scripts/compilation/tmp/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.mjs

0 commit comments

Comments
 (0)