From c9f60017013914ca65eefe86a7bac66018253f41 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 30 Sep 2022 06:58:11 +0200 Subject: [PATCH] fix(replace): prepare for Rollup 3 BREAKING CHANGES: Requires Node 14 --- packages/replace/README.md | 2 +- packages/replace/package.json | 34 ++++++++++++++++++++--------- packages/replace/rollup.config.js | 15 ------------- packages/replace/rollup.config.mjs | 13 +++++++++++ packages/replace/test/form.js | 2 +- packages/replace/test/function.js | 2 +- packages/replace/test/misc.js | 4 ++-- packages/replace/test/sourcemaps.js | 2 +- pnpm-lock.yaml | 30 ++++++++++--------------- 9 files changed, 55 insertions(+), 49 deletions(-) delete mode 100755 packages/replace/rollup.config.js create mode 100755 packages/replace/rollup.config.mjs diff --git a/packages/replace/README.md b/packages/replace/README.md index c81dd9be9..cc3e32d38 100644 --- a/packages/replace/README.md +++ b/packages/replace/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/replace/package.json b/packages/replace/package.json index c2e352d35..442d41af2 100644 --- a/packages/replace/package.json +++ b/packages/replace/package.json @@ -13,8 +13,16 @@ "author": "Rich Harris ", "homepage": "https://github.com/rollup/plugins/tree/master/packages/replace#readme", "bugs": "https://github.com/rollup/plugins/issues", - "main": "dist/rollup-plugin-replace.cjs.js", - "module": "dist/rollup-plugin-replace.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", @@ -31,6 +39,7 @@ }, "files": [ "dist", + "!dist/**/*.map", "src", "types", "README.md" @@ -44,21 +53,26 @@ "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.1.0", - "magic-string": "^0.25.7" + "@rollup/pluginutils": "^4.2.1", + "magic-string": "^0.26.4" }, "devDependencies": { "@rollup/plugin-buble": "^0.21.3", - "del-cli": "^3.0.1", + "del-cli": "^5.0.0", "locate-character": "^2.0.5", - "rollup": "^2.67.3", - "source-map": "^0.7.3", - "typescript": "^3.9.7" + "rollup": "^3.0.0-7", + "source-map": "^0.7.4", + "typescript": "^4.8.3" }, - "types": "types/index.d.ts", + "types": "./types/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/replace/rollup.config.js b/packages/replace/rollup.config.js deleted file mode 100755 index 2244813fc..000000000 --- a/packages/replace/rollup.config.js +++ /dev/null @@ -1,15 +0,0 @@ -import buble from '@rollup/plugin-buble'; - -import pkg from './package.json'; - -const external = Object.keys(pkg.dependencies).concat('path'); - -export default { - input: 'src/index.js', - plugins: [buble()], - external, - output: [ - { file: pkg.main, format: 'cjs', exports: 'auto' }, - { file: pkg.module, format: 'es' } - ] -}; diff --git a/packages/replace/rollup.config.mjs b/packages/replace/rollup.config.mjs new file mode 100755 index 000000000..888000cd3 --- /dev/null +++ b/packages/replace/rollup.config.mjs @@ -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()] +}; diff --git a/packages/replace/test/form.js b/packages/replace/test/form.js index 998d699c7..9685dcc99 100644 --- a/packages/replace/test/form.js +++ b/packages/replace/test/form.js @@ -6,7 +6,7 @@ const { readdirSync, readFileSync } = require('fs'); const test = require('ava'); -const replace = require('../dist/rollup-plugin-replace.cjs.js'); +const replace = require('..'); const transformContext = {}; diff --git a/packages/replace/test/function.js b/packages/replace/test/function.js index fa15d002d..20dab0779 100644 --- a/packages/replace/test/function.js +++ b/packages/replace/test/function.js @@ -7,7 +7,7 @@ const { readdirSync } = require('fs'); const test = require('ava'); const { rollup } = require('rollup'); -const replace = require('../dist/rollup-plugin-replace.cjs.js'); +const replace = require('..'); const { execute, getCodeFromBundle } = require('./helpers/util'); diff --git a/packages/replace/test/misc.js b/packages/replace/test/misc.js index 97124a702..cedfbcfff 100644 --- a/packages/replace/test/misc.js +++ b/packages/replace/test/misc.js @@ -5,7 +5,7 @@ const { join } = require('path'); const test = require('ava'); const { rollup } = require('rollup'); -const replace = require('../dist/rollup-plugin-replace.cjs.js'); +const replace = require('..'); const { getOutputFromGenerated } = require('./helpers/util'); @@ -63,7 +63,7 @@ test('can be configured with output plugins', async (t) => { }) ); - t.is(code.trim(), 'log("environment", "production");'); + t.is(code.trim(), 'log("environment", "production");\n//# sourceMappingURL=main.js.map'); t.truthy(map); }); diff --git a/packages/replace/test/sourcemaps.js b/packages/replace/test/sourcemaps.js index 1cff04538..65cc5e0cd 100644 --- a/packages/replace/test/sourcemaps.js +++ b/packages/replace/test/sourcemaps.js @@ -10,7 +10,7 @@ delete global.fetch; const { SourceMapConsumer } = require('source-map'); global.fetch = fetch; -const replace = require('../dist/rollup-plugin-replace.cjs.js'); +const replace = require('..'); const { getOutputFromGenerated } = require('./helpers/util'); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5e29fb549..a9cd5dffc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -437,23 +437,23 @@ importers: packages/replace: specifiers: '@rollup/plugin-buble': ^0.21.3 - '@rollup/pluginutils': ^3.1.0 - del-cli: ^3.0.1 + '@rollup/pluginutils': ^4.2.1 + del-cli: ^5.0.0 locate-character: ^2.0.5 - magic-string: ^0.25.7 - rollup: ^2.67.3 - source-map: ^0.7.3 - typescript: ^3.9.7 + magic-string: ^0.26.4 + rollup: ^3.0.0-7 + source-map: ^0.7.4 + typescript: ^4.8.3 dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - magic-string: 0.25.9 + '@rollup/pluginutils': 4.2.1 + magic-string: 0.26.7 devDependencies: - '@rollup/plugin-buble': 0.21.3_rollup@2.79.1 - del-cli: 3.0.1 + '@rollup/plugin-buble': 0.21.3_rollup@3.0.0-7 + del-cli: 5.0.0 locate-character: 2.0.5 - rollup: 2.79.1 + rollup: 3.0.0-7 source-map: 0.7.4 - typescript: 3.9.10 + typescript: 4.8.3 packages/run: specifiers: @@ -7398,12 +7398,6 @@ packages: is-typedarray: 1.0.0 dev: true - /typescript/3.9.10: - resolution: {integrity: sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==} - engines: {node: '>=4.2.0'} - hasBin: true - dev: true - /typescript/4.8.3: resolution: {integrity: sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==} engines: {node: '>=4.2.0'}