1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-12 18:42:18 -05:00
denoland-deno/tests/registry/npm/@denotest/install-launch-cjs-temp-dir/1.0.0/install.js
David Sherret f091d1ad69
feat(node): stabilize detecting if CJS via "type": "commonjs" in a package.json (#26439)
This will respect `"type": "commonjs"` in a package.json to determine if
`.js`/`.jsx`/`.ts`/.tsx` files are CJS or ESM. If the file is found to
be ESM it will be loaded as ESM though.
2024-11-13 15:10:09 +00:00

12 lines
478 B
JavaScript

const tempDir = Deno.makeTempDirSync();
try {
// should work requiring these because this was launched via a node binary entrypoint
Deno.writeTextFileSync(`${tempDir}/index.js`, "module.exports = require('./other');");
Deno.writeTextFileSync(`${tempDir}/other.js`, "module.exports = (a, b) => a + b;");
const add = require(`${tempDir}/index.js`);
if (add(1, 2) !== 3) {
throw new Error("FAILED");
}
} finally {
Deno.removeSync(tempDir, { recursive: true });
}