Skip to content

Commit

Permalink
fix(alias,auto-install,babel,beep,buble,commonjs,data-uri,dsv,dynamic…
Browse files Browse the repository at this point in the history
…-import-vars,eslint,esm-shim,graphql,html,image,inject,json,legacy,multi-entry,node-resolve,pluginutils,replace,run,strip,sucrase,swc,terser,typescript,url,virtual,wasm,yaml): ensure rollup 4 compatibility
  • Loading branch information
lukastaegert committed Sep 27, 2023
1 parent 4fcc32a commit 59c6151
Show file tree
Hide file tree
Showing 58 changed files with 401 additions and 378 deletions.
4 changes: 2 additions & 2 deletions packages/alias/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"alias"
],
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0"
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -65,7 +65,7 @@
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-typescript": "^9.0.1",
"del-cli": "^5.0.0",
"rollup": "^3.2.3",
"rollup": "^4.0.0-23",
"typescript": "^4.8.3"
},
"types": "./types/index.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions packages/alias/test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ test('Forwards isEntry and custom options to a custom resolver', (t) => {
{
source: 'nonEntry',
importer: '/src/importer.js',
options: { assertions: {}, isEntry: false, custom: { test: 42 } }
options: { attributes: {}, isEntry: false, custom: { test: 42 } }
}
]
).then((result) => {
Expand All @@ -464,7 +464,7 @@ test('Forwards isEntry and custom options to a custom resolver', (t) => {
'entry-point',
'/src/importer.js',
{
assertions: {},
attributes: {},
custom: void 0,
isEntry: true
}
Expand All @@ -473,7 +473,7 @@ test('Forwards isEntry and custom options to a custom resolver', (t) => {
'non-entry-point',
'/src/importer.js',
{
assertions: {},
attributes: {},
custom: { test: 42 },
isEntry: false
}
Expand Down Expand Up @@ -514,7 +514,7 @@ test('Forwards isEntry and custom options to other plugins', (t) => {
'entry-point',
'/src/importer.js',
{
assertions: {},
attributes: {},
custom: void 0,
isEntry: true
}
Expand All @@ -523,7 +523,7 @@ test('Forwards isEntry and custom options to other plugins', (t) => {
'non-entry-point',
'/src/importer.js',
{
assertions: {},
attributes: {},
custom: { test: 42 },
isEntry: false
}
Expand Down
4 changes: 2 additions & 2 deletions packages/auto-install/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"modules"
],
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0"
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -65,7 +65,7 @@
"@rollup/plugin-typescript": "^9.0.1",
"del": "^6.1.1",
"node-noop": "^1.0.0",
"rollup": "^3.2.3",
"rollup": "^4.0.0-23",
"typescript": "^4.8.3"
},
"types": "./types/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"peerDependencies": {
"@babel/core": "^7.0.0",
"@types/babel__core": "^7.1.9",
"rollup": "^1.20.0||^2.0.0||^3.0.0"
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -79,7 +79,7 @@
"@rollup/plugin-json": "^5.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@types/babel__core": "^7.1.9",
"rollup": "^3.2.3",
"rollup": "^4.0.0-23",
"source-map": "^0.7.4"
},
"types": "./types/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/beep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
"rollup"
],
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0"
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
},
"devDependencies": {
"rollup": "^3.2.3",
"rollup": "^4.0.0-23",
"strip-ansi": "^7.0.1"
},
"types": "types/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/buble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"modules"
],
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0"
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -68,7 +68,7 @@
"devDependencies": {
"@rollup/plugin-typescript": "^9.0.1",
"del-cli": "^5.0.0",
"rollup": "^3.2.3",
"rollup": "^4.0.0-23",
"source-map": "^0.7.4",
"typescript": "^4.8.3"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/commonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"require"
],
"peerDependencies": {
"rollup": "^2.68.0||^3.0.0"
"rollup": "^2.68.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -74,7 +74,7 @@
"@rollup/plugin-node-resolve": "^15.0.0",
"locate-character": "^2.0.5",
"require-relative": "^0.8.7",
"rollup": "^3.19.0",
"rollup": "^4.0.0-23",
"shx": "^0.3.4",
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
Expand Down
2 changes: 1 addition & 1 deletion packages/commonjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export default function commonjs(options = {}) {
try {
return transformAndCheckExports.call(this, code, id);
} catch (err) {
return this.error(err, err.loc);
return this.error(err, err.pos);
}
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/commonjs/src/resolve-require-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
currentlyResolvingForParent.add(source);
const resolved =
(await rollupContext.resolve(source, parentId, {
skipSelf: false,
custom: { 'node-resolve': { isRequire: true } }
})) || resolveExtensions(source, parentId, extensions);
currentlyResolvingForParent.delete(source);
Expand Down
3 changes: 3 additions & 0 deletions packages/commonjs/src/transform-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ export default async function transformCommonjs(
}
if (!ignoreDynamicRequires) {
if (isShorthandProperty(parent)) {
// as key and value are the same object, isReference regards
// both as references, so we need to skip now
skippedNodes.add(parent.value);
magicString.prependRight(node.start, 'require: ');
}
replacedDynamicRequires.push(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ module.exports = {
plugins: [
{
async buildStart() {
await this.resolve('./other.js', ID_MAIN, { isEntry: true, custom: { test: 42 } });
await this.resolve('./other.js', ID_MAIN, {
skipSelf: false,
isEntry: true,
custom: { test: 42 }
});
},
buildEnd() {
assert.deepStrictEqual(resolveIdArgs, [
['other.js', 'main.js', { assertions: {}, custom: { test: 42 }, isEntry: true }],
['main.js', void 0, { assertions: {}, custom: {}, isEntry: true }]
['other.js', 'main.js', { attributes: {}, custom: { test: 42 }, isEntry: true }],
['main.js', void 0, { attributes: {}, custom: {}, isEntry: true }]
]);
},
resolveId(source, importer, options) {
Expand Down
115 changes: 46 additions & 69 deletions packages/commonjs/test/snapshots/function.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,24 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
{
'generated-lib2.js': `'use strict';␊
'main.js': `'use strict';␊
␊
var main2 = require('./main2.js');␊
␊
/* eslint-disable import/no-dynamic-require, global-require */␊
␊
let message;␊
␊
for (const index of [1, 2]) {␊
try {␊
message = main2.createCommonjsRequire("/fixtures/function/dynamic-require-code-splitting")(\`./target${index}.js\`);␊
} catch (err) {␊
({ message } = err);␊
}␊
t.is(message, index.toString());␊
}␊
`,
'main2.js': `'use strict';␊
␊
var target1;␊
var hasRequiredTarget1;␊
Expand Down Expand Up @@ -1211,28 +1228,6 @@ Generated by [AVA](https://avajs.dev).
␊
exports.createCommonjsRequire = createCommonjsRequire;␊
`,
'main.js': `'use strict';␊
␊
var lib2 = require('./generated-lib2.js');␊
␊
/* eslint-disable import/no-dynamic-require, global-require */␊
␊
let message;␊
␊
for (const index of [1, 2]) {␊
try {␊
message = lib2.createCommonjsRequire("/fixtures/function/dynamic-require-code-splitting")(\`./target${index}.js\`);␊
} catch (err) {␊
({ message } = err);␊
}␊
t.is(message, index.toString());␊
}␊
`,
'main2.js': `'use strict';␊
␊
require('./generated-lib2.js');␊
␊
`,
}

## dynamic-require-different-loader
Expand Down Expand Up @@ -1511,6 +1506,7 @@ Generated by [AVA](https://avajs.dev).
␊
/* eslint-disable import/no-dynamic-require, global-require */␊
␊
␊
t.is(result, 'submodule');␊
`,
}
Expand Down Expand Up @@ -3454,6 +3450,9 @@ Generated by [AVA](https://avajs.dev).
const getGlobalPollution = () => 'foo';␊
␊
// this test makes sure that "submodule" is not wrapped in commonjs␊
// helper due to its use of "typeof module", given that "submodule" has es6 exports.␊
// any attempt to wrap it in a function will just fail as it's invalid syntax.␊
␊
␊
t.is(getGlobalPollution(), global.pollution);␊
`,
Expand Down Expand Up @@ -4023,11 +4022,11 @@ Generated by [AVA](https://avajs.dev).
{
'main.js': `'use strict';␊
␊
var other = require('./other-77ad7026.js');␊
var other = require('./other.js');␊
␊
t.is(other.foo, 'foo');␊
t.is(other, 'foo');␊
`,
'other-77ad7026.js': `'use strict';␊
'other.js': `'use strict';␊
␊
function getDefaultExportFromCjs (x) {␊
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊
Expand All @@ -4037,15 +4036,7 @@ Generated by [AVA](https://avajs.dev).
␊
var foo = /*@__PURE__*/getDefaultExportFromCjs(other);␊
␊
exports.foo = foo;␊
`,
'other.js': `'use strict';␊
␊
var other = require('./other-77ad7026.js');␊
␊
␊
␊
module.exports = other.foo;␊
module.exports = foo;␊
`,
}

Expand Down Expand Up @@ -5124,6 +5115,16 @@ Generated by [AVA](https://avajs.dev).
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊
}␊
␊
var foo;␊
var hasRequiredFoo;␊
␊
function requireFoo () {␊
if (hasRequiredFoo) return foo;␊
hasRequiredFoo = 1;␊
foo = 1;␊
return foo;␊
}␊
␊
var multiply;␊
var hasRequiredMultiply;␊
␊
Expand All @@ -5136,16 +5137,6 @@ Generated by [AVA](https://avajs.dev).
return multiply;␊
}␊
␊
var foo;␊
var hasRequiredFoo;␊
␊
function requireFoo () {␊
if (hasRequiredFoo) return foo;␊
hasRequiredFoo = 1;␊
foo = 1;␊
return foo;␊
}␊
␊
/* eslint-disable global-require */␊
␊
var main = function () {␊
Expand Down Expand Up @@ -5930,45 +5921,31 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
{
'_virtual/_commonjsHelpers.js': `'use strict';␊
'main.js': `'use strict';␊
␊
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊
␊
function getDefaultExportFromCjs (x) {␊
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊
}␊
␊
exports.commonjsGlobal = commonjsGlobal;␊
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;␊
`,
'main.js': `'use strict';␊
␊
var _commonjsHelpers = require('./_virtual/_commonjsHelpers.js');␊
var main$1 = require('./main2.js');␊
␊
var mainExports = main$1.__require();␊
var main = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(mainExports);␊
␊
module.exports = main;␊
`,
'main2.js': `'use strict';␊
␊
var _commonjsHelpers = require('./_virtual/_commonjsHelpers.js');␊
␊
var main;␊
var main$1;␊
var hasRequiredMain;␊
␊
function requireMain () {␊
if (hasRequiredMain) return main;␊
if (hasRequiredMain) return main$1;␊
hasRequiredMain = 1;␊
_commonjsHelpers.commonjsGlobal.main = 'main';␊
commonjsGlobal.main = 'main';␊
console.log('main');␊
␊
main = 'main';␊
return main;␊
main$1 = 'main';␊
return main$1;␊
}␊
␊
exports.__require = requireMain;␊
var mainExports = requireMain();␊
var main = /*@__PURE__*/getDefaultExportFromCjs(mainExports);␊
␊
module.exports = main;␊
`,
}

Expand Down
Binary file modified packages/commonjs/test/snapshots/function.js.snap
Binary file not shown.
Loading

0 comments on commit 59c6151

Please sign in to comment.