Skip to content

Commit

Permalink
change/API! ~ add ESM module packaging
Browse files Browse the repository at this point in the history
- adds an ESM wrapper to provide simple ESM support (as suggested in "Node Modules at War"

* ref: [Node Modules at War](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1) @@ <https://archive.is/zl0qg>
* ref: [yargs ~ 'Road to ESM/Deno'](yargs/yargs#1706)
  • Loading branch information
rivy committed Dec 28, 2020
1 parent e04fdac commit 56d640a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions package.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions 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_;
1 change: 1 addition & 0 deletions src/esm-wrapper/package.json
@@ -0,0 +1 @@
{"type": "module"}

0 comments on commit 56d640a

Please sign in to comment.