From 3177f94b12e213f20c2aed07775254f6ef7e73a7 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 30 Sep 2022 06:55:04 +0200 Subject: [PATCH] fix(multi-entry): prepare for Rollup 3 BREAKING CHANGES: Requires Node 14 --- packages/multi-entry/README.md | 2 +- packages/multi-entry/package.json | 26 ++++++++++++------- packages/multi-entry/rollup.config.js | 10 ------- packages/multi-entry/rollup.config.mjs | 11 ++++++++ .../test/node_modules/current-package | 1 + .../multi-entry/test/{test.js => test.mjs} | 14 ++++++++-- pnpm-lock.yaml | 13 +++++----- 7 files changed, 48 insertions(+), 29 deletions(-) delete mode 100755 packages/multi-entry/rollup.config.js create mode 100755 packages/multi-entry/rollup.config.mjs create mode 120000 packages/multi-entry/test/node_modules/current-package rename packages/multi-entry/test/{test.js => test.mjs} (84%) diff --git a/packages/multi-entry/README.md b/packages/multi-entry/README.md index b5e74b5be..5d531d69d 100755 --- a/packages/multi-entry/README.md +++ b/packages/multi-entry/README.md @@ -17,7 +17,7 @@ _Note: `default` exports cannot be combined and exported by this plugin. Only na ## Requirements -This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.3.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/multi-entry/package.json b/packages/multi-entry/package.json index a76e460e6..6cf3fab85 100755 --- a/packages/multi-entry/package.json +++ b/packages/multi-entry/package.json @@ -13,10 +13,15 @@ "author": "rollup", "homepage": "https://github.com/rollup/plugins/tree/master/packages/multi-entry/#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": ">=10.0.0" + "node": ">=14.0.0" }, "scripts": { "build": "rollup -c", @@ -33,6 +38,7 @@ }, "files": [ "dist", + "!dist/**/*.map", "types", "README.md", "LICENSE" @@ -46,20 +52,22 @@ "entries" ], "peerDependencies": { - "rollup": "^1.20.0 || ^2.0.0" + "rollup": "^1.20.0||^2.0.0||^3.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } }, "dependencies": { "@rollup/plugin-virtual": "^2.0.3", - "matched": "^5.0.0" + "matched": "^5.0.1" }, "devDependencies": { - "rollup": "^2.67.3" + "rollup": "^3.0.0-7" }, "types": "./types/index.d.ts", "ava": { - "babel": { - "compileEnhancements": false - }, "files": [ "!**/fixtures/**", "!**/helpers/**", diff --git a/packages/multi-entry/rollup.config.js b/packages/multi-entry/rollup.config.js deleted file mode 100755 index afb523097..000000000 --- a/packages/multi-entry/rollup.config.js +++ /dev/null @@ -1,10 +0,0 @@ -const pkg = require('./package.json'); - -export default { - input: 'src/index.js', - external: Object.keys(pkg.dependencies), - output: [ - { format: 'cjs', file: pkg.main, exports: 'auto' }, - { format: 'es', file: pkg.module } - ] -}; diff --git a/packages/multi-entry/rollup.config.mjs b/packages/multi-entry/rollup.config.mjs new file mode 100755 index 000000000..80558c224 --- /dev/null +++ b/packages/multi-entry/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/multi-entry/test/node_modules/current-package b/packages/multi-entry/test/node_modules/current-package new file mode 120000 index 000000000..c25bddb6d --- /dev/null +++ b/packages/multi-entry/test/node_modules/current-package @@ -0,0 +1 @@ +../.. \ No newline at end of file diff --git a/packages/multi-entry/test/test.js b/packages/multi-entry/test/test.mjs similarity index 84% rename from packages/multi-entry/test/test.js rename to packages/multi-entry/test/test.mjs index e23575ab1..5799db92f 100755 --- a/packages/multi-entry/test/test.js +++ b/packages/multi-entry/test/test.mjs @@ -1,11 +1,13 @@ /* eslint-disable no-bitwise */ +import { createRequire } from 'module'; + import test from 'ava'; import { rollup } from 'rollup'; -import { getCode } from '../../../util/test'; +import multiEntry from 'current-package'; -import multiEntry from '../'; +import { getCode } from '../../../util/test.js'; test('takes a single file as input', async (t) => { const bundle = await rollup({ input: 'test/fixtures/0.js', plugins: [multiEntry()] }); @@ -81,3 +83,11 @@ test('makes a bundle with entryFileName as the filename', async (t) => { const [result] = await getCode(bundle, { format: 'cjs' }, true); t.is(result.fileName, 'testing.js'); }); + +test('works as CJS plugin', async (t) => { + const require = createRequire(import.meta.url); + const multiEntryPluginCjs = require('current-package'); + const bundle = await rollup({ input: 'test/fixtures/0.js', plugins: [multiEntryPluginCjs()] }); + const code = await getCode(bundle); + t.truthy(code.includes('exports.zero = zero;')); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a1e37f5c8..3d8e84c43 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -364,13 +364,13 @@ importers: packages/multi-entry: specifiers: '@rollup/plugin-virtual': ^2.0.3 - matched: ^5.0.0 - rollup: ^2.67.3 + matched: ^5.0.1 + rollup: ^3.0.0-7 dependencies: - '@rollup/plugin-virtual': 2.1.0_rollup@2.79.1 + '@rollup/plugin-virtual': 2.1.0_rollup@3.0.0-7 matched: 5.0.1 devDependencies: - rollup: 2.79.1 + rollup: 3.0.0-7 packages/node-resolve: specifiers: @@ -2173,13 +2173,13 @@ packages: typescript: 4.8.3 dev: true - /@rollup/plugin-virtual/2.1.0_rollup@2.79.1: + /@rollup/plugin-virtual/2.1.0_rollup@3.0.0-7: resolution: {integrity: sha512-CPPAtlKT53HFqC8jFHb/V5WErpU8Hrq2TyCR0A7kPQMlF2wNUf0o1xuAc+Qxj8NCZM0Z3Yvl+FbUXfJjVWqDwA==} engines: {node: '>=8.0.0'} peerDependencies: rollup: ^1.20.0||^2.0.0 dependencies: - rollup: 2.79.1 + rollup: 3.0.0-7 dev: false /@rollup/pluginutils/3.1.0: @@ -6777,7 +6777,6 @@ packages: hasBin: true optionalDependencies: fsevents: 2.3.2 - dev: true /run-parallel/1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}