@build-script/dual-package-runtime

when require() without extension, try .cjs first, and then .js. see @build-script/typescript-transformer-dual-package.

Usage no npm install needed!

<script type="module">
  import buildScriptDualPackageRuntime from 'https://cdn.skypack.dev/@build-script/dual-package-runtime';
</script>

README

dual package runtime

When you run require("./some/file"), it will try "some/file.js" first, and throw if not found.
But with this package, it will try "some/file.cjs" first, then "some/file.js", if both not found, throw.

Note: this will not effect any import, only affect require()(include transpiled ones).

Usage:

import "@build-script/dual-package-runtime";

import { xxx } from "./some-my-files";

Or

require("@build-script/dual-package-runtime");

const { xxx } = require("./some-my-files");

Example

index.js:

require('./test');

test.cjs:

console.log('test.cjs has been imported');

test.js:

console.log('test.js has been imported');
  • node ./index.js:
    test.js has been imported
  • node -r "@build-script/dual-package-runtime" ./index.js:
    test.cjs has been imported