Skip to content

Commit 9d8a6f8

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 5e493d9 commit 9d8a6f8

Some content is hidden

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

47 files changed

+79
-44
lines changed

babel.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
extends: '../../babel.config.js',
33
};

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
automock: false,
33
testRegex: 'tests/.*?(test)\\.js$',
44
};

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@
55
"description": "Resolve overall document component's layout",
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/layout"
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
},

rollup.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ const configBase = {
2929
};
3030

3131
const config = Object.assign({}, configBase, {
32-
output: [
33-
getESM({ file: 'lib/index.es.js' }),
34-
getCJS({ file: 'lib/index.cjs.js' }),
35-
],
32+
output: [getESM({ file: 'lib/index.js' }), getCJS({ file: 'lib/index.cjs' })],
3633
});
3734

3835
export default config;

setupTests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* eslint-disable */
2+
import { createRequire } from 'module';
3+
24
import '../../polyfills';
35

6+
const require = createRequire(import.meta.url);
7+
48
global.BROWSER = false;
59

610
const customGlobal = global;

src/image/measureImage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Yoga from 'yoga-layout/sync';
1+
import Yoga from '../../yoga';
22

33
import getRatio from './getRatio';
44
import getMargin from '../node/getMargin';

src/node/getBorderWidth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Yoga from 'yoga-layout/sync';
1+
import Yoga from '../../yoga';
22

33
const getComputedBorder = (yogaNode, edge) =>
44
yogaNode ? yogaNode.getComputedBorder(edge) : 0;

src/node/getMargin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Yoga from 'yoga-layout/sync';
1+
import Yoga from '../../yoga';
22

33
const getComputedMargin = (node, edge) => {
44
const { yogaNode } = node;

src/node/getPadding.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Yoga from 'yoga-layout/sync';
1+
import Yoga from '../../yoga';
22

33
const getComputedPadding = (node, edge) => {
44
const { yogaNode } = node;

src/node/setAlign.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Yoga from 'yoga-layout/sync';
21
import { upperFirst } from '@react-pdf/fns';
2+
import Yoga from '../../yoga';
33

44
const ALIGN = {
55
'flex-start': Yoga.ALIGN_FLEX_START,

0 commit comments

Comments
 (0)