Skip to content

Commit

Permalink
fix(commonjs): prepare for Rollup 3 (#1300)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: Requires Node 14
  • Loading branch information
lukastaegert authored Oct 9, 2022
1 parent 552aa96 commit f56bf9e
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 288 deletions.
2 changes: 1 addition & 1 deletion packages/commonjs/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 (v12.0.0+) and Rollup v2.68.0+. If you are using [`@rollup/plugin-node-resolve`](https://github.com/rollup/plugins/tree/master/packages/node-resolve), it should be v13.0.6+.
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.68.0+. If you are using [`@rollup/plugin-node-resolve`](https://github.com/rollup/plugins/tree/master/packages/node-resolve), it should be v13.0.6+.

## Install

Expand Down
40 changes: 23 additions & 17 deletions packages/commonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/es/index.js"
"import": "./dist/es/index.js",
"types": "./types/index.d.ts",
"default": "./dist/cjs/index.js"
},
"engines": {
"node": ">= 12.0.0"
"node": ">=14.0.0"
},
"scripts": {
"build": "rollup -c",
Expand All @@ -39,6 +40,7 @@
},
"files": [
"dist",
"!dist/**/*.map",
"types",
"README.md",
"LICENSE"
Expand All @@ -52,29 +54,33 @@
"require"
],
"peerDependencies": {
"rollup": "^2.68.0"
"rollup": "^2.68.0||^3.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
},
"dependencies": {
"@rollup/pluginutils": "^3.1.0",
"@rollup/pluginutils": "^4.2.1",
"commondir": "^1.0.1",
"estree-walker": "^2.0.1",
"glob": "^7.1.6",
"is-reference": "^1.2.1",
"magic-string": "^0.25.7",
"resolve": "^1.17.0"
"estree-walker": "^2.0.2",
"glob": "^8.0.3",
"is-reference": "1.2.1",
"magic-string": "^0.26.4"
},
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.0",
"@rollup/plugin-node-resolve": "^14.1.0",
"locate-character": "^2.0.5",
"require-relative": "^0.8.7",
"rollup": "^2.68.0",
"shx": "^0.3.2",
"source-map": "^0.7.3",
"source-map-support": "^0.5.19",
"typescript": "^3.9.7"
"rollup": "3.0.0-7",
"shx": "^0.3.4",
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
"typescript": "^4.8.3"
},
"types": "types/index.d.ts",
"types": "./types/index.d.ts",
"ava": {
"workerThreads": false,
"files": [
Expand Down
25 changes: 0 additions & 25 deletions packages/commonjs/rollup.config.js

This file was deleted.

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

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

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

const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));

export default {
...createConfig({ pkg }),
input: 'src/index.js',
plugins: [json()]
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const externalNamed = require('external-esm-named');
const externalMixed = require('external-esm-mixed');
const externalDefault = require('external-esm-default');

t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');
t.deepEqual(externalNamed, { foo: 'foo', default: { foo: 'foo' } }, 'external named');
t.deepEqual(externalMixed, { default: 'bar', foo: 'foo' }, 'external mixed');
t.deepEqual(externalDefault, { default: 'bar' }, 'external default');
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ t.deepEqual(namedExports, { foo: 'foo' }, 'named exports');
t.deepEqual(mixedExports, { foo: 'foo', default: 'bar' }, 'mixed exports');
t.deepEqual(defaultExport, 'bar', 'default export');
t.deepEqual(noExports, {}, 'no exports');
t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');
t.deepEqual(externalNamed, { foo: 'foo', default: { foo: 'foo' } }, 'external named');
t.deepEqual(externalMixed, { foo: 'foo', default: 'bar' }, 'external mixed');
t.deepEqual(externalDefault, 'bar', 'external default');
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ t.deepEqual(namedExports, { foo: 'foo' }, 'named exports');
t.deepEqual(mixedExports, { foo: 'foo', default: 'bar' }, 'mixed exports');
t.deepEqual(defaultExport, { default: 'bar' }, 'default export');
t.deepEqual(noExports, {}, 'no exports');
t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');
t.deepEqual(externalNamed, { foo: 'foo', default: { foo: 'foo' } }, 'external named');
t.deepEqual(externalMixed, { foo: 'foo', default: 'bar' }, 'external mixed');
t.deepEqual(externalDefault, { default: 'bar' }, 'external default');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const externalNamed = require('external-esm-named');
const externalMixed = require('external-esm-mixed');
const externalDefault = require('external-esm-default');

t.deepEqual(externalNamed, { foo: 'foo' }, 'named');
t.deepEqual(externalNamed, { foo: 'foo', default: { foo: 'foo' } }, 'named');
t.deepEqual(externalMixed, 'bar', 'mixed');
t.deepEqual(externalDefault, { default: 'bar' }, 'default');
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ t.deepEqual(namedExports, { foo: 'foo' }, 'named exports');
t.deepEqual(mixedExports, { foo: 'foo', default: 'bar' }, 'mixed exports');
t.deepEqual(defaultExport, { default: 'bar' }, 'default export');
t.deepEqual(noExports, {}, 'no exports');
t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');
t.deepEqual(externalNamed, { foo: 'foo', default: { foo: 'foo' } }, 'external named');
t.deepEqual(externalMixed, { foo: 'foo', default: 'bar' }, 'external mixed');
t.deepEqual(externalDefault, { default: 'bar' }, 'external default');
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ t.deepEqual(namedExports, { foo: 'foo' }, 'named exports');
t.deepEqual(mixedExports, { foo: 'foo', default: 'bar' }, 'mixed exports');
t.deepEqual(defaultExport, { default: 'bar' }, 'default export');
t.deepEqual(noExports, {}, 'no exports');
t.deepEqual(externalNamed, { foo: 'foo' }, 'external named');
t.deepEqual(externalNamed, { foo: 'foo', default: { foo: 'foo' } }, 'external named');
t.deepEqual(externalMixed, { foo: 'foo', default: 'bar' }, 'external mixed');
t.deepEqual(externalDefault, { default: 'bar' }, 'external default');
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ t.deepEqual(dep, {
});

t.deepEqual(external, {
foo: 'foo'
foo: 'foo',
default: { foo: 'foo' }
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ module.exports = {
{
buildEnd() {
assert.deepStrictEqual(
warnings.map(({ code, source }) => {
return { code, source };
warnings.map(({ code, exporter, ...rest }) => {
return { code, exporter };
}),
[{ code: 'UNRESOLVED_IMPORT', source: 'path' }]
[{ code: 'UNRESOLVED_IMPORT', exporter: 'path' }]
);
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/commonjs/test/helpers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ function runCodeSplitTest(codeMap, t, configContext = {}) {
}

async function getCodeMapFromBundle(bundle, options = {}) {
const generated = await bundle.generate({ exports: 'auto', format: 'cjs', ...options });
const generated = await bundle.generate({
interop: 'compat',
exports: 'auto',
format: 'cjs',
...options
});
const codeMap = {};
for (const chunk of generated.output) {
codeMap[chunk.fileName] = chunk.code;
Expand Down
Loading

0 comments on commit f56bf9e

Please sign in to comment.