Skip to content

Commit

Permalink
test: validate canonical exports after inline transform (#5699)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Jan 19, 2024
1 parent 447852f commit 59c5b59
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ codegen/sdk-codegen/smithy-build-*.json
*/out/
*/*/out/
workspace
./scripts/compilation/tmp/*.mjs

.turbo
coverage
Expand Down
13 changes: 13 additions & 0 deletions scripts/compilation/Inliner.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = class Inliner {
async tsc() {
await spawnProcess("yarn", ["tsc", "-p", "tsconfig.cjs.json"], { cwd: this.packageDirectory });
console.log("Finished recompiling ./dist-cjs in " + this.package);
this.canonicalExports = Object.keys(require(this.outfile));
return this;
}

Expand All @@ -57,6 +58,7 @@ module.exports = class Inliner {
*/
async discoverVariants() {
if (this.bailout) {
console.log("Inliner bailout.");
return this;
}
this.variantEntries = Object.entries(this.pkgJson["react-native"] ?? {});
Expand Down Expand Up @@ -338,6 +340,17 @@ module.exports = class Inliner {
" were not found in the index."
);
}

// check ESM compat.
const tmpFileContents = this.canonicalExports
.filter((sym) => !sym.includes(":"))
.map((sym) => `import { ${sym} } from "${this.pkgJson.name}";`)
.join("\n");
fs.writeFileSync(path.join(__dirname, "tmp", this.package + ".mjs"), tmpFileContents, "utf-8");
await spawnProcess("node", [path.join(__dirname, "tmp", this.package + ".mjs")]);
console.log("ESM compatibility verified.");
fs.rmSync(path.join(__dirname, "tmp", this.package + ".mjs"));

return this;
}
};
1 change: 1 addition & 0 deletions scripts/compilation/tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mjs

0 comments on commit 59c5b59

Please sign in to comment.