Skip to content

Commit

Permalink
maint/build ~ add rollup for ESM generation
Browse files Browse the repository at this point in the history
- TypeScript fails to correctly generate an ESM module with correct line endings
  - ref: <microsoft/TypeScript#18442 (comment)>
  - ref: <microsoft/TypeScript#18442>
  - ref: <microsoft/TypeScript#37582>
  - ref: <microsoft/TypeScript#35148>
  • Loading branch information
rivy committed Jan 11, 2021
1 parent 1cea465 commit cda2874
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ref: <https://devhints.io/rollup>
// setup: `npm i rollup @rollup/plugin-typescript` or `npm i rollup rollup-plugin-typescript2` (for visible TS error output)

// import typescript from '@rollup/plugin-typescript';
import typescript from 'rollup-plugin-typescript2';

export default [
// ES module build (replaces broken basic TypeScript compilation)
// * ref: <https://github.com/microsoft/TypeScript/issues/18442> , <https://github.com/alshdavid/rxjs/blob/main/rollup.config.js#L10>
// * ref: <https://github.com/microsoft/TypeScript/pull/35148>
// * ref: <https://github.com/microsoft/TypeScript/issues/37582>
{
preserveModules: true,
input: ['src/index.ts'],
external: ['path', 'os'],
output: [{ exports: 'auto', dir: 'build/esm', format: 'esm', entryFileNames: '[name].mjs' }],
plugins: [typescript({ tsconfig: './tsconfig/tsconfig.esm.json' })],
},
];
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"build:cjs": "shx rm -fr build/cjs && tsc -p tsconfig/tsconfig.cjs.json",
"build:cjs/esm": "shx rm -fr build/cjs/esm-wrapper && 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:esm": "shx rm -fr build/esm && rollup -c .rollup.config.js",
"build:umd": "shx rm -fr build/umd && tsc -p tsconfig/tsconfig.umd.json",
"build:tests": "shx rm -fr build/cjs+tests && tsc -p tsconfig/tsconfig.tests.json",
"build:types": "shx rm -fr build/types && tsc -p tsconfig/tsconfig.types.json && run-s --silent _:update:dist.types",
Expand Down Expand Up @@ -177,6 +178,8 @@
"remark-footnotes": "^3.0.0",
"remark-preset-lint-recommended": "^5.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.36.1",
"rollup-plugin-typescript2": "^0.29.0",
"shx": "^0.3.3",
"ts-node": "^9.0.0",
"tsd": "^0.13.1",
Expand Down

0 comments on commit cda2874

Please sign in to comment.