Skip to content

Commit fc27759

Browse files
authored
feat: add support for native ESM imports, make repository ESM-first (diegomura#2409)
* Set "type": "module" and add "exports" * Convert Babel config to ESM * Add our own node-gyp so that canvas can be built * Fix parse:afm command, remove useless babel-node * Convert Jest config and CJS Jest tests to ESM * Convert ESLint config to JSON * Allow extraneous dependencies in test files * Change .size-limit config extension to .cjs * Fix build * Add changeset * Add types * Fix faux ESM yoga-layout import * Make ESLint happy * Remove unnecessary eslint-disable * Fix broken imports in browserify-zlib See browserify/browserify-zlib#45 * Fix Jest command? * Use .cjs and .js instead of .cjs.js and .es.js respectively, copy types for each outputted file separately * Remove direct node-gyp dependency * Move Yoga hack to a separate file
1 parent 1da59b8 commit fc27759

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

Diff for: babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = { extends: '../../babel.config.js' };
1+
export default { extends: '../../babel.config.js' };

Diff for: jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = {
1+
export default {
22
testRegex: 'tests/.*?(test)\\.js$',
33
};

Diff for: package.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@
55
"description": "React-pdf helper functions",
66
"author": "Diego Muracciole <[email protected]>",
77
"homepage": "https://github.com/diegomura/react-pdf#readme",
8-
"main": "lib/index.cjs.js",
9-
"module": "lib/index.es.js",
8+
"type": "module",
9+
"main": "./lib/index.cjs",
10+
"module": "./lib/index.js",
11+
"exports": {
12+
".": {
13+
"import": "./lib/index.js",
14+
"require": "./lib/index.cjs",
15+
"default": "./lib/index.js"
16+
}
17+
},
1018
"repository": {
1119
"type": "git",
1220
"url": "https://github.com/diegomura/react-pdf.git",
1321
"directory": "packages/fns"
1422
},
1523
"scripts": {
16-
"test": "jest",
24+
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
1725
"build": "rimraf ./lib && rollup -c",
1826
"watch": "rimraf ./lib && rollup -c -w"
1927
},

Diff for: rollup.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ const getPlugins = () => [
2727

2828
const config = {
2929
input,
30-
output: [
31-
getESM({ file: 'lib/index.es.js' }),
32-
getCJS({ file: 'lib/index.cjs.js' }),
33-
],
30+
output: [getESM({ file: 'lib/index.js' }), getCJS({ file: 'lib/index.cjs' })],
3431
external: getExternal(),
3532
plugins: getPlugins(),
3633
};

0 commit comments

Comments
 (0)