From d4cfa0eb94c06cf3a1b615a6e14e4f467ec1e5d5 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 30 Sep 2022 07:00:07 +0200 Subject: [PATCH] fix(strip): prepare for Rollup 3 BREAKING CHANGES: Requires Node 14 --- packages/strip/README.md | 2 +- packages/strip/package.json | 33 ++-- packages/strip/rollup.config.js | 10 - packages/strip/rollup.config.mjs | 11 ++ packages/strip/test/snapshots/test.js.md | 210 ++++++++++----------- packages/strip/test/snapshots/test.js.snap | Bin 1395 -> 1341 bytes packages/strip/test/test.js | 1 - pnpm-lock.yaml | 24 +-- 8 files changed, 148 insertions(+), 143 deletions(-) delete mode 100755 packages/strip/rollup.config.js create mode 100755 packages/strip/rollup.config.mjs diff --git a/packages/strip/README.md b/packages/strip/README.md index 43e8dd4e0..d15a84b69 100755 --- a/packages/strip/README.md +++ b/packages/strip/README.md @@ -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 diff --git a/packages/strip/package.json b/packages/strip/package.json index 0d34e982e..0faf04e76 100644 --- a/packages/strip/package.json +++ b/packages/strip/package.json @@ -13,8 +13,16 @@ "author": "Rich Harris", "homepage": "https://github.com/rollup/plugins/tree/master/packages/strip#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", @@ -28,6 +36,7 @@ }, "files": [ "dist", + "!dist/**/*.map", "types" ], "keywords": [ @@ -37,22 +46,24 @@ "javascript" ], "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.1.0", - "estree-walker": "^2.0.1", - "magic-string": "^0.25.7" + "@rollup/pluginutils": "^4.2.1", + "estree-walker": "^2.0.2", + "magic-string": "^0.26.4" }, "devDependencies": { - "acorn": "^7.3.1", - "rollup": "^2.67.3" + "acorn": "^8.8.0", + "rollup": "^3.0.0-7" }, "types": "./types/index.d.ts", "ava": { - "babel": { - "compileEnhancements": false - }, "files": [ "!**/fixtures/**", "!**/helpers/**", diff --git a/packages/strip/rollup.config.js b/packages/strip/rollup.config.js deleted file mode 100755 index e16318f7b..000000000 --- a/packages/strip/rollup.config.js +++ /dev/null @@ -1,10 +0,0 @@ -import pkg from './package.json'; - -export default { - input: 'src/index.js', - external: Object.keys(pkg.dependencies), - output: [ - { format: 'cjs', file: pkg.main, exports: 'auto' }, - { format: 'esm', file: pkg.module } - ] -}; diff --git a/packages/strip/rollup.config.mjs b/packages/strip/rollup.config.mjs new file mode 100755 index 000000000..80558c224 --- /dev/null +++ b/packages/strip/rollup.config.mjs @@ -0,0 +1,11 @@ +import { readFileSync } from 'fs'; + +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: [] +}; diff --git a/packages/strip/test/snapshots/test.js.md b/packages/strip/test/snapshots/test.js.md index 0fde251ad..bf2e3f316 100644 --- a/packages/strip/test/snapshots/test.js.md +++ b/packages/strip/test/snapshots/test.js.md @@ -2,7 +2,7 @@ The actual snapshot is saved in `test.js.snap`. -Generated by [AVA](https://ava.li). +Generated by [AVA](https://avajs.dev). ## can be configured to make no changes @@ -19,51 +19,49 @@ Generated by [AVA](https://ava.li). }␊ ` -## does not remove debugger statements with debugger: false +## excluded files do not get changed > Snapshot 1 - `export default function foo() {␊ + `/* eslint-disable */␊ + export default function foo() {␊ before();␊ debugger;␊ + logging:␊ + console.log('a');␊ + console.error('b');␊ after();␊ }␊ ` -## empty functions list leaves assert statements +## removes debugger statements > Snapshot 1 - `/* eslint-disable */␊ - function foo(message) {␊ - assert.equal(arguments.length, 1);␊ - assert.equal(typeof arguments[0], 'string');␊ - bar(message);␊ + `export default function foo() {␊ + before();␊ + after();␊ }␊ ` -## empty functions list leaves console statements +## does not remove debugger statements with debugger: false > Snapshot 1 - `/* eslint-disable */␊ - export default function foo() {␊ + `export default function foo() {␊ before();␊ - logging:␊ - console.log('a');␊ - console.error('b');␊ + debugger;␊ after();␊ }␊ ` -## excluded files do not get changed +## empty functions list leaves console statements > Snapshot 1 `/* eslint-disable */␊ export default function foo() {␊ before();␊ - debugger;␊ logging:␊ console.log('a');␊ console.error('b');␊ @@ -71,52 +69,42 @@ Generated by [AVA](https://ava.li). }␊ ` -## function calls without object are replaced with (void 0) - -> Snapshot 1 - - `/* eslint-disable */␊ - before();␊ - (void 0).t();␊ - after();␊ - ` - -## leaves console statements if custom functions are provided +## removes console statements > Snapshot 1 `foo(123);␊ - console.error('b');␊ bar(789);␊ ` -## only removes specified blocks +## removes assert statements > Snapshot 1 - `before();␊ - first: {␊ - things();␊ + `/* eslint-disable */␊ + function foo(message) {␊ + bar(message);␊ }␊ - after();␊ - again();␊ ` -## removes assert statements +## empty functions list leaves assert statements > Snapshot 1 `/* eslint-disable */␊ function foo(message) {␊ + assert.equal(arguments.length, 1);␊ + assert.equal(typeof arguments[0], 'string');␊ bar(message);␊ }␊ ` -## removes console statements +## leaves console statements if custom functions are provided > Snapshot 1 `foo(123);␊ + console.error('b');␊ bar(789);␊ ` @@ -129,14 +117,26 @@ Generated by [AVA](https://ava.li). c();␊ ` -## removes debugger statements +## rewrtestes inline call expressions (not expression statements) as void 0 > Snapshot 1 - `export default function foo() {␊ - before();␊ - after();␊ - }␊ + `DEBUG && (void 0);␊ + ` + +## rewrtestes inline if expessions as void 0 + +> Snapshot 1 + + `if (DEBUG) (void 0);␊ + ` + +## rewrites expressions as void 0 in lambdas + +> Snapshot 1 + + `/* eslint-disable */␊ + console.log(['h', 'e', 'y'].forEach((letter) => (void 0)))␊ ` ## removes expressions in if blocks @@ -147,50 +147,63 @@ Generated by [AVA](https://ava.li). }␊ ` -## removes labeled blocks +## removes methods of this > Snapshot 1 - `before();␊ - unittest: {␊ - test('some test', (assert) => {␊ - });␊ + `a();␊ + b();␊ + ` + +## removes super calls + +> Snapshot 1 + + `/* eslint-disable */␊ + class Foo {␊ + bar() {␊ + a();␊ + b();␊ + }␊ }␊ - after();␊ ` -## removes labeled blocks when filtered function is present +## replaces case body with void 0 > Snapshot 1 - `before();␊ - after();␊ + `switch (a) {␊ + case 1:␊ + (void 0);␊ + }␊ ` -## removes labeled blocks when functions list is empty +## rewrtestes inline while expressions as void 0 > Snapshot 1 - `before();␊ - after();␊ + `while (test()) (void 0);␊ ` -## removes labeled even with awkward spacing +## supports object destructuring assignments with default values > Snapshot 1 - `/* eslint-disable */␊ - before();␊ - again();␊ - after();␊ + `export function fn({ foo = (void 0), bar } = {}) {␊ + const { baz = (void 0) } = bar;␊ + }␊ ` -## removes methods of this +## removes labeled blocks > Snapshot 1 - `a();␊ - b();␊ + `before();␊ + unittest: {␊ + test('some test', (assert) => {␊ + });␊ + }␊ + after();␊ ` ## removes multiple labeled blocks @@ -202,64 +215,69 @@ Generated by [AVA](https://ava.li). again();␊ ` -## removes super calls +## only removes specified blocks > Snapshot 1 - `/* eslint-disable */␊ - class Foo {␊ - bar() {␊ - a();␊ - b();␊ - }␊ + `before();␊ + first: {␊ + things();␊ }␊ + after();␊ + again();␊ ` -## removing a lable also works for expressions +## removes labeled blocks when filtered function is present > Snapshot 1 - `/* eslint-disable */␊ - before();after();␊ + `before();␊ + after();␊ ` -## replaces case body with void 0 +## removes labeled blocks when functions list is empty > Snapshot 1 - `switch (a) {␊ - case 1:␊ - (void 0);␊ - }␊ + `before();␊ + after();␊ ` -## rewrites expressions as void 0 in lambdas +## whitespace between label and colon is accepted > Snapshot 1 `/* eslint-disable */␊ - console.log(['h', 'e', 'y'].forEach((letter) => (void 0)))␊ + before();␊ + after();␊ ` -## rewrtestes inline call expressions (not expression statements) as void 0 +## removing a lable also works for expressions > Snapshot 1 - `DEBUG && (void 0);␊ + `/* eslint-disable */␊ + before();after();␊ ` -## rewrtestes inline if expessions as void 0 +## the same label can occur multiple times and all are removed > Snapshot 1 - `if (DEBUG) (void 0);␊ + `/* eslint-disable */␊ + before();␊ + again();␊ + after();␊ ` -## rewrtestes inline while expressions as void 0 +## removes labeled even with awkward spacing > Snapshot 1 - `while (test()) (void 0);␊ + `/* eslint-disable */␊ + before();␊ + again();␊ + after();␊ ` ## spaces around . in function calls are accepted @@ -286,30 +304,12 @@ Generated by [AVA](https://ava.li). after();␊ ` -## supports object destructuring assignments with default values - -> Snapshot 1 - - `export function fn({ foo = (void 0), bar } = {}) {␊ - const { baz = (void 0) } = bar;␊ - }␊ - ` - -## the same label can occur multiple times and all are removed - -> Snapshot 1 - - `/* eslint-disable */␊ - before();␊ - again();␊ - after();␊ - ` - -## whitespace between label and colon is accepted +## function calls without object are replaced with (void 0) > Snapshot 1 `/* eslint-disable */␊ before();␊ + (void 0).t();␊ after();␊ ` diff --git a/packages/strip/test/snapshots/test.js.snap b/packages/strip/test/snapshots/test.js.snap index e828bef8131dc140b15a02d6601f1f6c0158d6ea..b65a5ba547251c254dc20fd10b0014df62c72679 100644 GIT binary patch literal 1341 zcmV-D1;YA4RzVZugdd9t00000000BkS6y!#MHEen5RzX|1xPK>ato+lhtzF|AgN10e1rlL5~xB2 zRYjWJy}LVPykmA|?U=|9Jn;jN5U=eo<<5@xW3p?`;` zs6VeiMa{Lq)3*bbf{zf$G~#idVF+5nn4KV`5`u)KF)FT7Hc^Sx>enY>$Ta)@>2q5z zY?;sY^IMlM{l0a32T%!~>RTaK%ohkdw|jUxk(q`NBbE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lock.yaml b/pnpm-lock.yaml index de01c82ca..aa0ac2771 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -474,18 +474,18 @@ importers: packages/strip: specifiers: - '@rollup/pluginutils': ^3.1.0 - acorn: ^7.3.1 - estree-walker: ^2.0.1 - magic-string: ^0.25.7 - rollup: ^2.67.3 + '@rollup/pluginutils': ^4.2.1 + acorn: ^8.8.0 + estree-walker: ^2.0.2 + magic-string: ^0.26.4 + rollup: ^3.0.0-7 dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 + '@rollup/pluginutils': 4.2.1 estree-walker: 2.0.2 - magic-string: 0.25.9 + magic-string: 0.26.7 devDependencies: - acorn: 7.4.1 - rollup: 2.79.1 + acorn: 8.8.0 + rollup: 3.0.0-7 packages/sucrase: specifiers: @@ -2731,12 +2731,6 @@ packages: engines: {node: '>=0.4.0'} hasBin: true - /acorn/7.4.1: - resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==} - engines: {node: '>=0.4.0'} - hasBin: true - dev: true - /acorn/8.8.0: resolution: {integrity: sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==} engines: {node: '>=0.4.0'}