Skip to content

Commit f5181ce

Browse files
wojtekmajmskec
authored andcommitted
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 9f2619a commit f5181ce

File tree

134 files changed

+645
-436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+645
-436
lines changed

.changeset/lazy-news-laugh.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@react-pdf/primitives': minor
3+
'@react-pdf/stylesheet': minor
4+
'@react-pdf/examples': minor
5+
'@react-pdf/renderer': minor
6+
'@react-pdf/textkit': minor
7+
'@react-pdf/layout': minor
8+
'@react-pdf/pdfkit': minor
9+
'@react-pdf/png-js': minor
10+
'@react-pdf/render': minor
11+
'@react-pdf/svgkit': minor
12+
'@react-pdf/image': minor
13+
'@react-pdf/font': minor
14+
'@react-pdf/fns': minor
15+
---
16+
17+
Add support for native ESM

.eslintrc.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

.eslintrc.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"parser": "babel-eslint",
3+
"env": {
4+
"browser": true,
5+
"es6": true,
6+
"node": true
7+
},
8+
"extends": [
9+
"plugin:react/recommended",
10+
"airbnb",
11+
"prettier",
12+
"plugin:react/jsx-runtime"
13+
],
14+
"globals": {
15+
"URL": false,
16+
"BROWSER": false,
17+
"Atomics": "readonly",
18+
"SharedArrayBuffer": "readonly"
19+
},
20+
"parserOptions": {
21+
"ecmaFeatures": {
22+
"jsx": true
23+
},
24+
"ecmaVersion": 2018,
25+
"sourceType": "module"
26+
},
27+
"plugins": ["react", "jest"],
28+
"rules": {
29+
"func-names": 0,
30+
"no-continue": 1,
31+
"no-cond-assign": 1,
32+
"react/prop-types": 0,
33+
"prefer-destructuring": 1,
34+
"no-use-before-define": 1,
35+
"no-underscore-dangle": 0,
36+
"prefer-object-spread": 0,
37+
"import/no-named-as-default": 0,
38+
"react/state-in-constructor": 0,
39+
"react/jsx-filename-extension": 0,
40+
"react/jsx-props-no-spreading": 0,
41+
"react/destructuring-assignment": 0,
42+
"import/no-unresolved": ["error", { "ignore": ["^yoga-layout"] }]
43+
},
44+
"overrides": [
45+
{
46+
"files": ["**/*.test.js", "**/tests/**/*.js", "setup.jest.js"],
47+
"env": {
48+
"jest": true
49+
},
50+
"rules": {
51+
"import/no-extraneous-dependencies": 0
52+
}
53+
}
54+
]
55+
}

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
presets: [
33
[
44
'@babel/preset-env',

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
projects: [
33
'<rootDir>packages/fns',
44
'<rootDir>packages/font',

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"license": "MIT",
66
"author": "Diego Muracciole <[email protected]>",
77
"homepage": "https://github.com/diegomura/react-pdf#readme",
8+
"type": "module",
89
"repository": "[email protected]:diegomura/react-pdf.git",
910
"workspaces": [
1011
"packages/*"
@@ -16,7 +17,7 @@
1617
"bootstrap": "lerna bootstrap",
1718
"prepublish": "lerna run build",
1819
"lint": "eslint packages",
19-
"test": "jest",
20+
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
2021
"dev": "lerna run dev --scope @react-pdf/examples",
2122
"changeset": "changeset",
2223
"version-packages": "changeset version",
@@ -25,7 +26,6 @@
2526
"devDependencies": {
2627
"@babel/cli": "^7.20.7",
2728
"@babel/core": "^7.20.7",
28-
"@babel/node": "^7.20.7",
2929
"@babel/plugin-proposal-class-properties": "^7.18.6",
3030
"@babel/plugin-proposal-decorators": "^7.20.13",
3131
"@babel/plugin-proposal-optional-chaining": "^7.20.7",
@@ -34,6 +34,7 @@
3434
"@babel/preset-react": "^7.18.6",
3535
"@changesets/changelog-github": "^0.4.8",
3636
"@changesets/cli": "^2.26.0",
37+
"@jest/globals": "^29.5.0",
3738
"@rollup/plugin-alias": "^3.1.8",
3839
"@rollup/plugin-babel": "^5.3.0",
3940
"@rollup/plugin-commonjs": "^21.0.1",
@@ -67,6 +68,7 @@
6768
"react-dom": "^18.2.0",
6869
"rimraf": "^2.6.3",
6970
"rollup": "^2.60.1",
71+
"rollup-plugin-copy": "^3.5.0",
7072
"rollup-plugin-ignore": "^1.0.10",
7173
"rollup-plugin-local-resolve": "^1.0.7",
7274
"rollup-plugin-polyfill-node": "^0.9.0",

packages/examples/.eslintrc.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/examples/.eslintrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": ["../../.eslintrc.json", "plugin:react/recommended"],
3+
"rules": {
4+
"react/prop-types": 0,
5+
"jsx-a11y/anchor-is-valid": 0,
6+
"react/jsx-one-expression-per-line": 0
7+
}
8+
}

packages/fns/babel.config.js

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

packages/fns/jest.config.js

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

0 commit comments

Comments
 (0)