Skip to content

Commit fe33e68

Browse files
authored
fix(json): prepare for Rollup 3 (#1291)
BREAKING CHANGES: Requires Node 14
1 parent facf7cb commit fe33e68

File tree

8 files changed

+87
-75
lines changed

8 files changed

+87
-75
lines changed

β€Žpackages/json/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## Requirements
1515

16-
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+.
16+
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.
1717

1818
## Install
1919

@@ -46,7 +46,9 @@ With an accompanying file `src/index.js`, the local `package.json` file would no
4646

4747
```js
4848
// src/index.js
49-
import pkg from './package.json';
49+
import { readFileSync } from 'fs';
50+
51+
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
5052
console.log(`running version ${pkg.version}`);
5153
```
5254

β€Žpackages/json/package.json

+23-11
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313
"author": "rollup",
1414
"homepage": "https://github.com/rollup/plugins/tree/master/packages/json#readme",
1515
"bugs": "https://github.com/rollup/plugins/issues",
16-
"main": "dist/index.js",
17-
"module": "dist/index.es.js",
16+
"main": "./dist/cjs/index.js",
17+
"module": "./dist/es/index.js",
18+
"exports": {
19+
"types": "./types/index.d.ts",
20+
"import": "./dist/es/index.js",
21+
"default": "./dist/cjs/index.js"
22+
},
23+
"engines": {
24+
"node": ">=14.0.0"
25+
},
1826
"scripts": {
1927
"build": "rollup -c",
2028
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
@@ -31,6 +39,7 @@
3139
},
3240
"files": [
3341
"dist",
42+
"!dist/**/*.map",
3443
"types",
3544
"README.md",
3645
"LICENSE"
@@ -44,22 +53,25 @@
4453
"modules"
4554
],
4655
"peerDependencies": {
47-
"rollup": "^1.20.0 || ^2.0.0"
56+
"rollup": "^1.20.0||^2.0.0||^3.0.0"
57+
},
58+
"peerDependenciesMeta": {
59+
"rollup": {
60+
"optional": true
61+
}
4862
},
4963
"dependencies": {
50-
"@rollup/pluginutils": "^3.0.8"
64+
"@rollup/pluginutils": "^4.2.1"
5165
},
5266
"devDependencies": {
5367
"@rollup/plugin-buble": "^0.21.0",
54-
"@rollup/plugin-node-resolve": "^8.4.0",
55-
"rollup": "^2.67.3",
56-
"source-map-support": "^0.5.19"
68+
"@rollup/plugin-node-resolve": "^14.1.0",
69+
"rollup": "^3.0.0-7",
70+
"source-map-support": "^0.5.21"
5771
},
58-
"types": "types/index.d.ts",
72+
"types": "./types/index.d.ts",
5973
"ava": {
60-
"babel": {
61-
"compileEnhancements": false
62-
},
74+
"workerThreads": false,
6375
"files": [
6476
"!**/fixtures/**",
6577
"!**/helpers/**",

β€Žpackages/json/rollup.config.js

-15
This file was deleted.

β€Žpackages/json/rollup.config.mjs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { readFileSync } from 'fs';
2+
3+
import buble from '@rollup/plugin-buble';
4+
5+
import { createConfig } from '../../shared/rollup.config.mjs';
6+
7+
export default {
8+
...createConfig({
9+
pkg: JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
10+
}),
11+
input: 'src/index.js',
12+
plugins: [buble()]
13+
};

β€Žpackages/json/test/snapshots/test.js.md

+33-33
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,17 @@
22

33
The actual snapshot is saved in `test.js.snap`.
44

5-
Generated by [AVA](https://ava.li).
5+
Generated by [AVA](https://avajs.dev).
66

7-
## generates correct code with compact=true
8-
9-
> Snapshot 1
10-
11-
'export var validKey=true;export var nested={subKey:"ok"};export var array=[1,"2"];export default{validKey:validKey,"invalid-key":1,nested:nested,array:array,"function":"not used","null":null};'
12-
13-
## generates correct code with namedExports=false
14-
15-
> Snapshot 1
16-
17-
`export default {␊
18-
validKey: true,␊
19-
"invalid-key": 1,␊
20-
nested: {␊
21-
subKey: "ok"␊
22-
},␊
23-
array: [␊
24-
1,␊
25-
"2"␊
26-
],␊
27-
"function": "not used",␊
28-
"null": null␊
29-
};`
30-
31-
## generates correct code with preferConst
7+
## generates properly formatted code
328

339
> Snapshot 1
3410
35-
`export const validKey = true;␊
36-
export const nested = {␊
11+
`export var validKey = true;␊
12+
export var nested = {␊
3713
subKey: "ok"␊
3814
};␊
39-
export const array = [␊
15+
export var array = [␊
4016
1,␊
4117
"2"␊
4218
];␊
@@ -50,15 +26,15 @@ Generated by [AVA](https://ava.li).
5026
};␊
5127
`
5228

53-
## generates properly formatted code
29+
## generates correct code with preferConst
5430

5531
> Snapshot 1
5632
57-
`export var validKey = true;␊
58-
export var nested = {␊
33+
`export const validKey = true;␊
34+
export const nested = {␊
5935
subKey: "ok"␊
6036
};␊
61-
export var array = [␊
37+
export const array = [␊
6238
1,␊
6339
"2"␊
6440
];␊
@@ -93,3 +69,27 @@ Generated by [AVA](https://ava.li).
9369
"null": null␊
9470
};␊
9571
`
72+
73+
## generates correct code with compact=true
74+
75+
> Snapshot 1
76+
77+
'export var validKey=true;export var nested={subKey:"ok"};export var array=[1,"2"];export default{validKey:validKey,"invalid-key":1,nested:nested,array:array,"function":"not used","null":null};'
78+
79+
## generates correct code with namedExports=false
80+
81+
> Snapshot 1
82+
83+
`export default {␊
84+
validKey: true,␊
85+
"invalid-key": 1,␊
86+
nested: {␊
87+
subKey: "ok"␊
88+
},␊
89+
array: [␊
90+
1,␊
91+
"2"␊
92+
],␊
93+
"function": "not used",␊
94+
"null": null␊
95+
};`
33 Bytes
Binary file not shown.

β€Žpackages/json/test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test('generates named exports', async (t) => {
4848
plugins: [json()]
4949
});
5050

51-
const { code, result } = await testBundle(t, bundle, { exports: {} });
51+
const { code, result } = await testBundle(t, bundle, { inject: { exports: {} } });
5252

5353
t.is(result.version, '1.33.7');
5454
t.is(code.indexOf('this-should-be-excluded'), -1, 'should exclude unused properties');

β€Žpnpm-lock.yaml

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)