diff --git a/package.json b/package.json index 3725bd9..3d4fccc 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,17 @@ "main": "dist/cjs/index.js", "module": "dist/cjs/esm-wrapper/index.js", "types": "dist/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": [ + { + "import": "./dist/cjs/esm-wrapper/index.js", + "require": "./dist/cjs/index.js", + "types": "./dist/types/index.d.ts" + }, + "./dist/cjs/index.js" + ] + }, "keywords": [ "common", "cross-platform", @@ -44,6 +55,7 @@ "# build # build/compile package": "", "build": "run-s _:regen:build", "build:cjs": "tsc -p tsconfig/tsconfig.cjs.json", + "build:cjs/esm": "shx mkdir -p build/cjs && shx cp -r src/esm-wrapper build/cjs", "## build:esm * [2020-12-22; rivy] TS compiles to ESMs are broken due to extension mishandling (use `rollup`)": "tsc -p tsconfig/tsconfig.esm.json", "build:umd": "tsc -p tsconfig/tsconfig.umd.json", "build:tests": "tsc -p tsconfig/tsconfig.tests.json", diff --git a/src/esm-wrapper/index.js b/src/esm-wrapper/index.js new file mode 100644 index 0000000..4746195 --- /dev/null +++ b/src/esm-wrapper/index.js @@ -0,0 +1,9 @@ +/* eslint-env node */ +// # spell-checker:ignore Deno + +import _ from '../index.js'; +// note: not usable by `deno`; +// ...`deno` is unable to load (the CJS module) '../index.js' via import => `'../index.js' does not provide an export named 'default'` + +const default_ = _; +export default default_; diff --git a/src/esm-wrapper/package.json b/src/esm-wrapper/package.json new file mode 100644 index 0000000..6990891 --- /dev/null +++ b/src/esm-wrapper/package.json @@ -0,0 +1 @@ +{"type": "module"} diff --git a/src/index.ts b/src/index.ts index 307ada3..c0cd18b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,8 @@ const haveModuleExports_ = typeof module === 'object' && module.exports; // ## maint ~ [2020-12-23; rivy] although tested, `nyc` is unable to instrument ESM/.mjs correctly in order show coverage for testing the *else* clause /* istanbul ignore else */ if (haveModuleExports_) { - // enables direct require from CJS (eg, `const m = require('...');`); skipped for ESM + // enables direct require from CJS (eg, `const module = require('...');`), but generally disables any other exports + // * skipped for ESM (missing `module.exports`) // eslint-disable-next-line functional/immutable-data module.exports = default_; }