Skip to content

Commit

Permalink
fix(json): prepare for Rollup 3 (#1291)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: Requires Node 14
  • Loading branch information
lukastaegert authored Oct 10, 2022
1 parent facf7cb commit fe33e68
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 75 deletions.
6 changes: 4 additions & 2 deletions packages/json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Requirements

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

## Install

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

```js
// src/index.js
import pkg from './package.json';
import { readFileSync } from 'fs';

const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
console.log(`running version ${pkg.version}`);
```
Expand Down
34 changes: 23 additions & 11 deletions packages/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
"author": "rollup",
"homepage": "https://github.com/rollup/plugins/tree/master/packages/json#readme",
"bugs": "https://github.com/rollup/plugins/issues",
"main": "dist/index.js",
"module": "dist/index.es.js",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"exports": {
"types": "./types/index.d.ts",
"import": "./dist/es/index.js",
"default": "./dist/cjs/index.js"
},
"engines": {
"node": ">=14.0.0"
},
"scripts": {
"build": "rollup -c",
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
Expand All @@ -31,6 +39,7 @@
},
"files": [
"dist",
"!dist/**/*.map",
"types",
"README.md",
"LICENSE"
Expand All @@ -44,22 +53,25 @@
"modules"
],
"peerDependencies": {
"rollup": "^1.20.0 || ^2.0.0"
"rollup": "^1.20.0||^2.0.0||^3.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
},
"dependencies": {
"@rollup/pluginutils": "^3.0.8"
"@rollup/pluginutils": "^4.2.1"
},
"devDependencies": {
"@rollup/plugin-buble": "^0.21.0",
"@rollup/plugin-node-resolve": "^8.4.0",
"rollup": "^2.67.3",
"source-map-support": "^0.5.19"
"@rollup/plugin-node-resolve": "^14.1.0",
"rollup": "^3.0.0-7",
"source-map-support": "^0.5.21"
},
"types": "types/index.d.ts",
"types": "./types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
},
"workerThreads": false,
"files": [
"!**/fixtures/**",
"!**/helpers/**",
Expand Down
15 changes: 0 additions & 15 deletions packages/json/rollup.config.js

This file was deleted.

13 changes: 13 additions & 0 deletions packages/json/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { readFileSync } from 'fs';

import buble from '@rollup/plugin-buble';

import { createConfig } from '../../shared/rollup.config.mjs';

export default {
...createConfig({
pkg: JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
}),
input: 'src/index.js',
plugins: [buble()]
};
66 changes: 33 additions & 33 deletions packages/json/test/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,17 @@

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

Generated by [AVA](https://ava.li).
Generated by [AVA](https://avajs.dev).

## generates correct code with compact=true

> Snapshot 1
'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};'

## generates correct code with namedExports=false

> Snapshot 1
`export default {␊
validKey: true,␊
"invalid-key": 1,␊
nested: {␊
subKey: "ok"␊
},␊
array: [␊
1,␊
"2"␊
],␊
"function": "not used",␊
"null": null␊
};`

## generates correct code with preferConst
## generates properly formatted code

> Snapshot 1
`export const validKey = true;␊
export const nested = {␊
`export var validKey = true;␊
export var nested = {␊
subKey: "ok"␊
};␊
export const array = [␊
export var array = [␊
1,␊
"2"␊
];␊
Expand All @@ -50,15 +26,15 @@ Generated by [AVA](https://ava.li).
};␊
`

## generates properly formatted code
## generates correct code with preferConst

> Snapshot 1
`export var validKey = true;␊
export var nested = {␊
`export const validKey = true;␊
export const nested = {␊
subKey: "ok"␊
};␊
export var array = [␊
export const array = [␊
1,␊
"2"␊
];␊
Expand Down Expand Up @@ -93,3 +69,27 @@ Generated by [AVA](https://ava.li).
"null": null␊
};␊
`

## generates correct code with compact=true

> Snapshot 1
'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};'

## generates correct code with namedExports=false

> Snapshot 1
`export default {␊
validKey: true,␊
"invalid-key": 1,␊
nested: {␊
subKey: "ok"␊
},␊
array: [␊
1,␊
"2"␊
],␊
"function": "not used",␊
"null": null␊
};`
Binary file modified packages/json/test/snapshots/test.js.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/json/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('generates named exports', async (t) => {
plugins: [json()]
});

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

t.is(result.version, '1.33.7');
t.is(code.indexOf('this-should-be-excluded'), -1, 'should exclude unused properties');
Expand Down
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fe33e68

Please sign in to comment.