From c7dba6265c0577044769e4528f27dc23005644ae Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 30 Sep 2022 06:56:01 +0200 Subject: [PATCH] fix(node-resolve): prepare for Rollup 3 BREAKING CHANGES: Requires Node 14 --- packages/node-resolve/README.md | 2 +- packages/node-resolve/package.json | 38 +++++---- packages/node-resolve/rollup.config.js | 18 ---- packages/node-resolve/rollup.config.mjs | 13 +++ packages/node-resolve/src/index.js | 4 +- packages/node-resolve/src/rollup-version.js | 31 +++++++ packages/node-resolve/test/jail.js | 8 +- .../test/node_modules/current-package | 1 + .../{side-effects.js => side-effects.mjs} | 10 ++- .../test/snapshots/dedupe-custom.js.snap | Bin 172 -> 233 bytes .../test/snapshots/dedupe.js.snap | Bin 357 -> 410 bytes .../node-resolve/test/snapshots/jail.js.md | 20 ----- .../node-resolve/test/snapshots/jail.js.snap | Bin 433 -> 0 bytes .../node-resolve/test/snapshots/only.js.snap | Bin 177 -> 229 bytes .../test/snapshots/prefer-builtins.js.md | 6 +- .../test/snapshots/prefer-builtins.js.snap | Bin 308 -> 388 bytes .../test/snapshots/root-dir.js.snap | Bin 143 -> 202 bytes .../test/snapshots/side-effects.js.snap | Bin 449 -> 0 bytes ...side-effects.js.md => side-effects.mjs.md} | 4 +- .../test/snapshots/side-effects.mjs.snap | Bin 0 -> 563 bytes .../node-resolve/test/snapshots/test.js.snap | Bin 1618 -> 0 bytes .../snapshots/{test.js.md => test.mjs.md} | 80 +----------------- .../node-resolve/test/snapshots/test.mjs.snap | Bin 0 -> 867 bytes .../node-resolve/test/{test.js => test.mjs} | 58 ++++++------- pnpm-lock.yaml | 55 ++++++------ 25 files changed, 143 insertions(+), 205 deletions(-) delete mode 100755 packages/node-resolve/rollup.config.js create mode 100755 packages/node-resolve/rollup.config.mjs create mode 100644 packages/node-resolve/src/rollup-version.js create mode 120000 packages/node-resolve/test/node_modules/current-package rename packages/node-resolve/test/{side-effects.js => side-effects.mjs} (93%) delete mode 100644 packages/node-resolve/test/snapshots/jail.js.md delete mode 100644 packages/node-resolve/test/snapshots/jail.js.snap delete mode 100644 packages/node-resolve/test/snapshots/side-effects.js.snap rename packages/node-resolve/test/snapshots/{side-effects.js.md => side-effects.mjs.md} (93%) create mode 100644 packages/node-resolve/test/snapshots/side-effects.mjs.snap delete mode 100644 packages/node-resolve/test/snapshots/test.js.snap rename packages/node-resolve/test/snapshots/{test.js.md => test.mjs.md} (67%) create mode 100644 packages/node-resolve/test/snapshots/test.mjs.snap rename packages/node-resolve/test/{test.js => test.mjs} (91%) diff --git a/packages/node-resolve/README.md b/packages/node-resolve/README.md index 210925662..566d4fe71 100755 --- a/packages/node-resolve/README.md +++ b/packages/node-resolve/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 v2.78.0+. ## Install diff --git a/packages/node-resolve/package.json b/packages/node-resolve/package.json index b500e4467..4234b53f4 100644 --- a/packages/node-resolve/package.json +++ b/packages/node-resolve/package.json @@ -15,13 +15,13 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", - "type": "commonjs", "exports": { - "require": "./dist/cjs/index.js", - "import": "./dist/es/index.js" + "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", @@ -40,6 +40,7 @@ }, "files": [ "dist", + "!dist/**/*.map", "types", "README.md", "LICENSE" @@ -52,32 +53,35 @@ "modules" ], "peerDependencies": { - "rollup": "^2.78.0" + "rollup": "^2.78.0||^3.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } }, "dependencies": { - "@rollup/pluginutils": "^3.1.0", - "@types/resolve": "1.17.1", + "@rollup/pluginutils": "^4.2.1", + "@types/resolve": "1.20.2", "deepmerge": "^4.2.2", - "is-builtin-module": "^3.1.0", + "is-builtin-module": "^3.2.0", "is-module": "^1.0.0", - "resolve": "^1.19.0" + "resolve": "^1.22.1" }, "devDependencies": { - "@babel/core": "^7.10.5", + "@babel/core": "^7.19.1", "@babel/plugin-transform-typescript": "^7.10.5", "@rollup/plugin-babel": "^5.1.0", "@rollup/plugin-commonjs": "^22.0.2", "@rollup/plugin-json": "^4.1.0", - "es5-ext": "^0.10.53", - "rollup": "^2.78.1", - "source-map": "^0.7.3", + "es5-ext": "^0.10.62", + "rollup": "^3.0.0-7", + "source-map": "^0.7.4", "string-capitalize": "^1.0.1" }, - "types": "types/index.d.ts", + "types": "./types/index.d.ts", "ava": { - "babel": { - "compileEnhancements": false - }, + "workerThreads": false, "files": [ "!**/fixtures/**", "!**/helpers/**", diff --git a/packages/node-resolve/rollup.config.js b/packages/node-resolve/rollup.config.js deleted file mode 100755 index 65e518f3c..000000000 --- a/packages/node-resolve/rollup.config.js +++ /dev/null @@ -1,18 +0,0 @@ -import json from '@rollup/plugin-json'; - -import { emitModulePackageFile } from '../../shared/rollup.config'; - -import pkg from './package.json'; - -export default { - input: 'src/index.js', - plugins: [json()], - external: [...Object.keys(pkg.dependencies), 'fs', 'path', 'os', 'util', 'url'], - onwarn: (warning) => { - throw Object.assign(new Error(), warning); - }, - output: [ - { file: pkg.main, format: 'cjs', exports: 'named' }, - { file: pkg.module, format: 'es', plugins: [emitModulePackageFile()] } - ] -}; diff --git a/packages/node-resolve/rollup.config.mjs b/packages/node-resolve/rollup.config.mjs new file mode 100755 index 000000000..15c7bcf3a --- /dev/null +++ b/packages/node-resolve/rollup.config.mjs @@ -0,0 +1,13 @@ +import { readFileSync } from 'fs'; + +import json from '@rollup/plugin-json'; + +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: [json()] +}; diff --git a/packages/node-resolve/src/index.js b/packages/node-resolve/src/index.js index 0da8f54f2..3e663bc0c 100644 --- a/packages/node-resolve/src/index.js +++ b/packages/node-resolve/src/index.js @@ -5,12 +5,13 @@ import isBuiltinModule from 'is-builtin-module'; import deepMerge from 'deepmerge'; import isModule from 'is-module'; -import { version } from '../package.json'; +import { version, peerDependencies } from '../package.json'; import { isDirCached, isFileCached, readCachedFile } from './cache'; import handleDeprecatedOptions from './deprecated-options'; import { fileExists, readFile, realpath } from './fs'; import resolveImportSpecifiers from './resolveImportSpecifiers'; +import validateVersion from './rollup-version.js'; import { getMainFields, getPackageName, normalizeInput } from './util'; const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js'; @@ -249,6 +250,7 @@ export function nodeResolve(opts = {}) { version, buildStart(buildOptions) { + validateVersion(this.meta.rollupVersion, peerDependencies.rollup); rollupOptions = buildOptions; for (const warning of warnings) { diff --git a/packages/node-resolve/src/rollup-version.js b/packages/node-resolve/src/rollup-version.js new file mode 100644 index 000000000..20a0f6396 --- /dev/null +++ b/packages/node-resolve/src/rollup-version.js @@ -0,0 +1,31 @@ +const versionRegexp = /\^(\d+\.\d+\.\d+)/g; + +export default function validateVersion(actualVersion, peerDependencyVersion) { + let minMajor = Infinity; + let minMinor = Infinity; + let minPatch = Infinity; + let foundVersion; + // eslint-disable-next-line no-cond-assign + while ((foundVersion = versionRegexp.exec(peerDependencyVersion))) { + const [foundMajor, foundMinor, foundPatch] = foundVersion[1].split('.').map(Number); + if (foundMajor < minMajor) { + minMajor = foundMajor; + minMinor = foundMinor; + minPatch = foundPatch; + } + } + if (!actualVersion) { + throw new Error( + `Insufficient Rollup version: "@rollup/plugin-node-resolve" requires at least rollup@${minMajor}.${minMinor}.${minPatch}.` + ); + } + const [major, minor, patch] = actualVersion.split('.').map(Number); + if ( + major < minMajor || + (major === minMajor && (minor < minMinor || (minor === minMinor && patch < minPatch))) + ) { + throw new Error( + `Insufficient rollup version: "@rollup/plugin-node-resolve" requires at least rollup@${minMajor}.${minMinor}.${minPatch} but found rollup@${actualVersion}.` + ); + } +} diff --git a/packages/node-resolve/test/jail.js b/packages/node-resolve/test/jail.js index 299acc5f1..6832372b4 100644 --- a/packages/node-resolve/test/jail.js +++ b/packages/node-resolve/test/jail.js @@ -22,10 +22,12 @@ test('mark module outside the jail as external', async (t) => { ] }); const imports = await getImports(bundle); - - t.snapshot(warnings); - t.is(warnings.length, 1); t.deepEqual(imports, ['string/uppercase.js']); + + t.is(warnings.length, 1, 'number of warnings'); + const [{ exporter, id }] = warnings; + t.is(exporter, 'string/uppercase.js', 'exporter'); + t.is(id.endsWith('jail.js'), true, 'id'); }); test('bundle module defined inside the jail', async (t) => { diff --git a/packages/node-resolve/test/node_modules/current-package b/packages/node-resolve/test/node_modules/current-package new file mode 120000 index 000000000..c25bddb6d --- /dev/null +++ b/packages/node-resolve/test/node_modules/current-package @@ -0,0 +1 @@ +../.. \ No newline at end of file diff --git a/packages/node-resolve/test/side-effects.js b/packages/node-resolve/test/side-effects.mjs similarity index 93% rename from packages/node-resolve/test/side-effects.js rename to packages/node-resolve/test/side-effects.mjs index 8415e42fa..f35c54ead 100755 --- a/packages/node-resolve/test/side-effects.js +++ b/packages/node-resolve/test/side-effects.mjs @@ -1,14 +1,16 @@ import { join } from 'path'; +import { fileURLToPath } from 'url'; import test from 'ava'; import { rollup } from 'rollup'; - import commonjs from '@rollup/plugin-commonjs'; -import { nodeResolve } from '..'; -import { getCode, testBundle } from '../../../util/test'; +import { nodeResolve } from 'current-package'; + +import { getCode, testBundle } from '../../../util/test.js'; -process.chdir(join(__dirname, 'fixtures')); +const DIRNAME = fileURLToPath(new URL('.', import.meta.url)); +process.chdir(join(DIRNAME, 'fixtures')); const failOnWarn = (t) => (warning) => t.fail(`No warnings were expected, got:\n${warning.code}\n${warning.message}`); diff --git a/packages/node-resolve/test/snapshots/dedupe-custom.js.snap b/packages/node-resolve/test/snapshots/dedupe-custom.js.snap index 80551406ab85a58827bc275341326e62a278afe9..8a9db7906aa5d7e89f6f9dd4611510ecb9843add 100644 GIT binary patch literal 233 zcmVzj(ZR8slZ%sK(=VW->!Yn&`BS8iL`S}f z_(`oXm^gUJUPcD_1KA&4Q^r5E=E_|_pQr3?^>l&A?|ch#}mg j$nc~#J(yP?u*9TqX;K?Qe~#N8jDP1ZAL!Vx>;M1&n5Ah7 literal 172 zcmZ<^b5sbrJy7#dj}&YU^Gmu6gKU?k0$$*rKrl9cFX=ICbjf61CFPlVju zEP@>z8X6}~Z=BfKI8lB@n`g_!nT-=eCrngUFtoHbw7n{*rVz*=c)@o|)5b|_x;}mO XF32cp;{32si=83n=9b0-KqmkImd!wV diff --git a/packages/node-resolve/test/snapshots/dedupe.js.snap b/packages/node-resolve/test/snapshots/dedupe.js.snap index 95266450221956d68dd152f046d2a47818689967..dc1fc95cdabb91ade7aa300f4a71c973edb64b0f 100644 GIT binary patch literal 410 zcmV;L0cHL{RzVwnDk&ei`NWMoH=3l{ zAl0kR0JtUOXIZb;BT|bb*6hVdcm0aYx4Ie0%py!~Z)H;RT2^4|6bI6wDp zhOV literal 357 zcmV-r0h<0nRzV|i??IT)FZfV2e=CjhZ9Bby*2n}1SPYH|r9Bb+H9 zAi%)L%fQIQz{n3&!z9AU%)rPh$jBO$nwVSy<8c*%cveOE`6X!Tc){wN^Ye;Jb5o08 zqLN_sy2(&sD}?q@=Mi?E6jtXYXJqE2U~^v~>F(nVPR=h#O>s$0DFsq6QQ=~+sBQ{G z7@LDdQ8c1ETpQH@gb%P7jLjz*l!mkrIH>efQd0}`vWkfhaYbw)j$#Y|2XG0=-va;u Da;cvv diff --git a/packages/node-resolve/test/snapshots/jail.js.md b/packages/node-resolve/test/snapshots/jail.js.md deleted file mode 100644 index b9ee3395b..000000000 --- a/packages/node-resolve/test/snapshots/jail.js.md +++ /dev/null @@ -1,20 +0,0 @@ -# Snapshot report for `test/jail.js` - -The actual snapshot is saved in `jail.js.snap`. - -Generated by [AVA](https://avajs.dev). - -## mark module outside the jail as external - -> Snapshot 1 - - [ - { - code: 'UNRESOLVED_IMPORT', - importer: 'jail.js', - message: '\'string/uppercase.js\' is imported by jail.js, but could not be resolved – treating it as an external dependency', - source: 'string/uppercase.js', - toString: Function {}, - url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency', - }, - ] diff --git a/packages/node-resolve/test/snapshots/jail.js.snap b/packages/node-resolve/test/snapshots/jail.js.snap deleted file mode 100644 index f2e90e743b5dc11bee535e4e5f74262632e9087f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 433 zcmV;i0Z#rwRzV~Ej2H1*+?6IkL1}_G02EOrrGI)i#QNGh3Qcpo9p`}s@ z!3u&rf}+u6*1$rLD?`@fK8>65`AN6c>l|OS_AZawr=9LuN?iy>5f_Sz_`)8NAZ!d} zN@tI#lw^N>HMV84eUC5)+2$t%<})hq$PVcyA_4 zd0AS7F>hZf70FH46+8@eG?Wc42JS!yK6NQ`*T+OK6RzV84$ z$_2<&qbc5uW~i<%=!Rc!5-X1S6Gzgv${;mC@Ge6{-QbNFBtRk#?oO6HMy`YKb1()4 zFULi(F1}KmVy9MHwLGVUS*gjDWjR&sYxKsAKu;`WfV`v(Z7|&!&O%e78};+n9niV( fU_hukuf+xr$iFutCTvM4{a5e-SeDg-YXJZNy-;B6 literal 177 zcmV;i08alwRzV z+mkQJ&9b|3>S|{B{_8P}V9`t<_FvV){9L@Td-9sKi}F9t0qOyX_5d+613TDcMh*sH fMm9l4R>z{E#7ag+7>l2upKeM3#ADQo`Tzg`Egn$) diff --git a/packages/node-resolve/test/snapshots/prefer-builtins.js.md b/packages/node-resolve/test/snapshots/prefer-builtins.js.md index 75d479022..e7555b12c 100644 --- a/packages/node-resolve/test/snapshots/prefer-builtins.js.md +++ b/packages/node-resolve/test/snapshots/prefer-builtins.js.md @@ -10,9 +10,11 @@ Generated by [AVA](https://avajs.dev). [ { - chunkName: 'prefer-builtin', code: 'EMPTY_BUNDLE', - message: 'Generated an empty chunk: "prefer-builtin"', + message: 'Generated an empty chunk: "prefer-builtin".', + names: [ + 'prefer-builtin', + ], toString: Function {}, }, ] diff --git a/packages/node-resolve/test/snapshots/prefer-builtins.js.snap b/packages/node-resolve/test/snapshots/prefer-builtins.js.snap index a68c04dd6996992cfa42761ae165ca333ba2632d..d6da3e281c2b09e9da94589fe3c36116546af784 100644 GIT binary patch literal 388 zcmV-~0ek*IRzVqrYjV|3x$uDj1vj4_a;oe)c0K3{ob9ni{InDDlDN zh%)LpCTOCGmn)1L$tEUN*31`S$SfPcSDDmEwxABB z6X(yJ?L)NiUl-6OZ)grJ* zphCcROz8m11iUs>0u^GBGFN3%1*N2;a?;lu8&=@vav&VNRQ8SAnWs+htu`?RP zsT^O>&O~E``gEm0=ZruT;K&VEG<%s$CNE!Yl!+IAGyVY*#k`9B0RRBVx2L%P literal 308 zcmV-40n7eDRzVU(cj+wF)^ibHfUXGId;F6-uymSUeNst|a5MOe*mF6XvWaj5FG9z(-J_P_X7GKSI G0RRB)V0tzH diff --git a/packages/node-resolve/test/snapshots/root-dir.js.snap b/packages/node-resolve/test/snapshots/root-dir.js.snap index 98b3cdf3b0adf2ca8c0a2ef47ccfc01a5551a418..0515c698de9dfb0710eaa358cac4fa880d0f2ab5 100644 GIT binary patch literal 202 zcmV;*05$(XRzV7E0T^P zUgNM^M<0s_00000000AZj4=wrKo9^EM6CV6zQNK?Um${DyWVb+C3o55ZW9!2@|5^e zjj?r_X@;4qn^)K7@x>w1(7FHs E0R1*t9smFU literal 143 zcmZ<^b5sb`nVidcAiuX<8oE- tQZ(MKuz!V$sjK2z4g2tg8ut5L7P>8DSapqa5y$o@hGSx~Q<{Oc001H>Hf#U@ diff --git a/packages/node-resolve/test/snapshots/side-effects.js.snap b/packages/node-resolve/test/snapshots/side-effects.js.snap deleted file mode 100644 index a095c83e5a8308c2aa01dde31fe25d7389884546..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 449 zcmV;y0Y3ggRzVoq<(6yuF8O|9+oQ+G00NajZ0yU``AEcgOM`9MiG?$}&N6~UPXKY( zu}B&B*Ma}M&YFq%t39(}1dILx;%?D{)7^5evGSF!723MfubL4os>Z~?F!kV@au@rh zsk@ji{kz|^^(Z4)Gy;g%7_rD&E6*33<(R$3@%^)2MzClX5N~lYc~HA`{y(F9hNiw0 zzAubm(T70H40JgNFtRcTGG?on7N;r{mlS0tm#ABFaV6*H73b%q>gD98YpAEBrWPm^ zXQreoq^6~%0u^YYt0>M$%*n|w$FC?iF*6S&iej-NK8r~=P6eNF7&g(@CQLa~m>e@qjvFGEnU|7U0h45bYfMYbDNaSPkQFA! rSyEJrD#eB&WdxIAhnonN0^3GG=#rMNGor diff --git a/packages/node-resolve/test/snapshots/side-effects.js.md b/packages/node-resolve/test/snapshots/side-effects.mjs.md similarity index 93% rename from packages/node-resolve/test/snapshots/side-effects.js.md rename to packages/node-resolve/test/snapshots/side-effects.mjs.md index 228e59801..0711bc012 100644 --- a/packages/node-resolve/test/snapshots/side-effects.js.md +++ b/packages/node-resolve/test/snapshots/side-effects.mjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `test/side-effects.js` +# Snapshot report for `test/side-effects.mjs` -The actual snapshot is saved in `side-effects.js.snap`. +The actual snapshot is saved in `side-effects.mjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/packages/node-resolve/test/snapshots/side-effects.mjs.snap b/packages/node-resolve/test/snapshots/side-effects.mjs.snap new file mode 100644 index 0000000000000000000000000000000000000000..71461c0e78c9624c7a6f4d5f6d8f9c193a0f2032 GIT binary patch literal 563 zcmV-30?hqERzVo*KK7@VCr z^aZBDL&y;dnU3TTch5Xo@LJ)^EURGQs6ZFykdcE-8}y(pIHC||;B*cOGdVFqdn*f{ zQ}ACFO35HU?zNJwq`X8s>4`^!iAV6k=`;)uI-QiPCxg3&hK~nhsqNs&K_?nK`Zt5q z94(|Y9+N#|yJj+Ef7%1Dq;AwtdIdk#Lt5fa7d`P(<*4>7FBRy(w+9v_^BIp77QJB?7oqX&Rr`jE~kCzpPe-*u$JpQfV|AET?z=c8orWrz;<~#rA7{zva?g=UfY} z?_58)esbLtNpfFo_C)*8IXM?1es#OuM08jq5qG&`BY7ZNoUA80vcx+Ii{}?eh$h>Q zY@^9uMAnMz&XQ@Xa2DaM)nF!#$J&DJ$hL!<)X`=G?M1Y;Qmjz5+ApK0Lg(fM0085U B3Az9P literal 0 HcmV?d00001 diff --git a/packages/node-resolve/test/snapshots/test.js.snap b/packages/node-resolve/test/snapshots/test.js.snap deleted file mode 100644 index 83f4e677a760ab0f96a3c69163da2314b484aff0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1618 zcmV-Y2Cex)RzVj*X zZ2?iKk5o+%B{l>UqC8SX0wnTK5hYj+LBJ|R@ec(QOfcxT)7z#GDFjUUfHy3%`a%8u!Ckie{ z@3mpZW=A1py=!S(#dh`3cl+;tqq*YKI?UK-V-U(Lh;8af$=tbOR_&2ZEo+Wp#-0Jp zia&h(fhp#e=CU4vQwnHiU2z(6sEzJx@MzsJZm>C%nZ^ zO-#d#eKQ`RwWAKaoF}wLC1`Jt*wyA-h8cT&I6~`w`lU%ISDrt8VDF=ojy5)9#!gB= zXnk4MvHZ+7H2#NHdm!b#d6=;cfDMcGE^+2Bdg$t(%Y}}(_9Dz!Mf#L%7cgVj03uKfQyNagrs?pU1sI7<$v7%kmL+*4jy9SY8?B_IB!q_} z3<^oqJE!0XgrkyijGrnB=cUHGDoP$|m8l{LwKR)Vx-~_W{6(Gbg#ne9M8y{1+%+)9 zp;DPsCApID3K1nDNTQd@gcFIxI@*Y%iquOQ5h?W$)yFI8Bp^^uq0oVfdPiPSG-?}6 zhy39>3>H5T!l1rUMxy6O^7v|b@goNTD9V?oN3JO1b9~ohdcvX`)-#H;(A`0%`3bj$pH@37LMBzS6o*8zD@T}y9WVUhh+Si*w&rE?w5in8n?r^7k7|9F{Jqn-gP@zI+E zty4(d0@oQR;)6PHQ3wgh3Tzydn2nS|oGN>c;NgHvCqW7nAPL`MPcS1Kulv`f=~z}4`c8d+$b@lUTc%+% z^|ehiY!QYnuG7ZD)?a5BBfADxae_j7d@#ze4O3;UrzyIRDZ?}&rE)p(b} zy?YL{O8+fi^h<}R=*^+*OP^!#CW!$%m1}8ny Snapshot 1 - 'Could not resolve \'./foo\' from unresolved-local.js' + 'Could not resolve "./foo" from "unresolved-local.js"' ## allows custom moduleDirectories with legacy customResolveOptions.moduleDirectory @@ -23,56 +23,6 @@ Generated by [AVA](https://avajs.dev). }, ] -## ignores deep-import non-modules - -> Snapshot 1 - - [ - { - code: 'UNRESOLVED_IMPORT', - importer: 'deep-import-non-module.js', - message: '\'foo/deep\' is imported by deep-import-non-module.js, but could not be resolved – treating it as an external dependency', - source: 'foo/deep', - toString: Function {}, - url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency', - }, - ] - -## respects the package.json sideEffects property for files in root package by default - -> Snapshot 1 - - `'use strict';␊ - ␊ - console.log('main');␊ - ` - -## ignores the package.json sideEffects property for files in root package with "ignoreSideEffectsForRoot" option - -> Snapshot 1 - - `'use strict';␊ - ␊ - console.log('side effect');␊ - ␊ - console.log('main');␊ - ` - -## handles package side-effects - -> Snapshot 1 - - [ - 'array-dep1', - 'array-dep3', - 'array-dep5', - 'array-index', - 'false-dep1', - 'true-dep1', - 'true-dep2', - 'true-index', - ] - ## throws error for removed customResolveOptions.preserveSymlinks option > Snapshot 1 @@ -176,27 +126,3 @@ Generated by [AVA](https://avajs.dev). Error { message: 'node-resolve: `customResolveOptions.packageIterator` is no longer an option. If you need this, please open an issue.', } - -## respects the package.json sideEffects property for files in the root package and supports deep side effects - -> Snapshot 1 - - `'use strict';␊ - ␊ - console.log('deep side effect');␊ - ␊ - console.log('shallow side effect');␊ - ␊ - console.log('main');␊ - ` - -## does not prefix the sideEffects property if the side effect contains a "/" - -> Snapshot 1 - - `'use strict';␊ - ␊ - console.log('shallow side effect');␊ - ␊ - console.log('main');␊ - ` diff --git a/packages/node-resolve/test/snapshots/test.mjs.snap b/packages/node-resolve/test/snapshots/test.mjs.snap new file mode 100644 index 0000000000000000000000000000000000000000..84b2de596e380c8c7ce0eb6ed1b510b03acfc6fb GIT binary patch literal 867 zcmV-p1DyOpRzVSAF60SO3c(A;cHm}6>G1r(g zTnxd9?;nc@00000000Bcmd$R{KoG~hY13AGG>PB!vw!;KYGfpgaOE!G}Nyi8tUy7&~#AHZ|DARvT&Mb#`X=@88VWbJVDF zVYbw}4^%VF>ERu1OVLr7N+~2}4GhbKV`gEdup=~5iyu7zi2YDnj$2Q(nN;gYh258ZwMmsK3F)W_=&dMY+MWSS%Xox`DXa5cS~90;pxgc?r5?ViHP119g=lQ(1`vknv3ep&8!#ko3&^Cia{(Ss zQF%ajx^2#!mg+zMXa@ftq{J%e^Y=PuU45+U#H9(J&0iuVR zI?A6$GWwP!BN2zuvB=agttZ389Fuz%T^5o)4c@}hxPE1cs}l#;sMyr7EhNJxDY4cV zkFLM3S;A_^ffY(j4bj7dnWg>;=yR5UTCuW8rHbcqQapnWDU#9mEE&1+7!CDt7glQA zCD4Cg>QW0NriN(gT+INav!>BK(~m4U$pkGyPv=E727aLaLF(cggJY4YVVX;hDY_T< tlqI44xP;RC{I8s=;HnTG0`JC1Oh2>4q!W}}sPw;q{Q=vSZ8^db004SVp7{U( literal 0 HcmV?d00001 diff --git a/packages/node-resolve/test/test.js b/packages/node-resolve/test/test.mjs similarity index 91% rename from packages/node-resolve/test/test.js rename to packages/node-resolve/test/test.mjs index a9faff3c7..c16f4ead3 100755 --- a/packages/node-resolve/test/test.js +++ b/packages/node-resolve/test/test.mjs @@ -1,16 +1,17 @@ import { dirname, join, resolve } from 'path'; +import { fileURLToPath } from 'url'; -import babel from '@rollup/plugin-babel'; +import { babel } from '@rollup/plugin-babel'; import commonjs from '@rollup/plugin-commonjs'; - import test from 'ava'; import { rollup } from 'rollup'; -import { nodeResolve } from '..'; +import { nodeResolve } from 'current-package'; -import { evaluateBundle, getCode, getImports, testBundle } from '../../../util/test'; +import { evaluateBundle, getCode, getImports, testBundle } from '../../../util/test.js'; -process.chdir(join(__dirname, 'fixtures')); +const DIRNAME = fileURLToPath(new URL('.', import.meta.url)); +process.chdir(join(DIRNAME, 'fixtures')); const failOnWarn = (t) => (warning) => t.fail(`No warnings were expected, got:\n${warning.code}\n${warning.message}`); @@ -312,10 +313,12 @@ test('ignores deep-import non-modules', async (t) => { ] }); const imports = await getImports(bundle); - - t.is(warnings.length, 1); - t.snapshot(warnings); t.deepEqual(imports, ['foo/deep']); + + t.is(warnings.length, 1, 'number of warnings'); + const [{ exporter, id }] = warnings; + t.is(exporter, 'foo/deep', 'exporter'); + t.is(id.endsWith('deep-import-non-module.js'), true, 'id'); }); test('generates manual chunks', async (t) => { @@ -323,15 +326,15 @@ test('generates manual chunks', async (t) => { const bundle = await rollup({ input: 'manualchunks.js', onwarn: failOnWarn(t), - manualChunks: { - [chunkName]: ['simple'] - }, plugins: [nodeResolve()] }); const { output } = await bundle.generate({ - format: 'esm', - chunkFileNames: '[name]' + format: 'es', + chunkFileNames: '[name]', + manualChunks: { + [chunkName]: ['simple'] + } }); t.truthy(output.find(({ fileName }) => fileName === chunkName)); @@ -341,10 +344,9 @@ test('resolves dynamic imports', async (t) => { const bundle = await rollup({ input: 'dynamic.js', onwarn: failOnWarn(t), - inlineDynamicImports: true, plugins: [nodeResolve()] }); - const { module } = await testBundle(t, bundle); + const { module } = await testBundle(t, bundle, { options: { inlineDynamicImports: true } }); const result = await module.exports; t.is(result.default, 42); }); @@ -357,7 +359,7 @@ test('can resolve imports with hash in path', async (t) => { nodeResolve(), { load(id) { - if (id === resolve(__dirname, 'fixtures', 'node_modules', 'test', '#', 'foo.js')) { + if (id === resolve(DIRNAME, 'fixtures', 'node_modules', 'test', '#', 'foo.js')) { return 'export default "resolved with hash"'; } return null; @@ -380,7 +382,7 @@ test('can resolve imports with search params', async (t) => { load(id) { if ( id === - resolve(__dirname, 'fixtures', 'node_modules', 'test', 'index.js?foo=bar&lorem=ipsum') + resolve(DIRNAME, 'fixtures', 'node_modules', 'test', 'index.js?foo=bar&lorem=ipsum') ) { return 'export default "resolved with search params"'; } @@ -404,13 +406,7 @@ test('can resolve imports with search params and hash', async (t) => { load(id) { if ( id === - resolve( - __dirname, - 'fixtures', - 'node_modules', - 'test', - 'index.js?foo=bar&lorem=ipsum#foo' - ) + resolve(DIRNAME, 'fixtures', 'node_modules', 'test', 'index.js?foo=bar&lorem=ipsum#foo') ) { return 'export default "resolved with search params and hash"'; } @@ -499,7 +495,7 @@ test('passes on "isEntry" flag', async (t) => { custom: { 'node-resolve': { resolved: { - id: join(__dirname, 'fixtures', 'entry', 'other.js'), + id: join(DIRNAME, 'fixtures', 'entry', 'other.js'), moduleSideEffects: null } } @@ -514,7 +510,7 @@ test('passes on "isEntry" flag', async (t) => { custom: { 'node-resolve': { resolved: { - id: join(__dirname, 'fixtures', 'entry', 'main.js'), + id: join(DIRNAME, 'fixtures', 'entry', 'main.js'), moduleSideEffects: null } } @@ -530,7 +526,7 @@ test('passes on "isEntry" flag', async (t) => { custom: { 'node-resolve': { resolved: { - id: join(__dirname, 'fixtures', 'entry', 'dep.js'), + id: join(DIRNAME, 'fixtures', 'entry', 'dep.js'), moduleSideEffects: null } } @@ -573,7 +569,7 @@ test('passes on custom options', async (t) => { test: 42, 'node-resolve': { resolved: { - id: join(__dirname, 'fixtures', 'entry', 'main.js'), + id: join(DIRNAME, 'fixtures', 'entry', 'main.js'), moduleSideEffects: null } } @@ -589,7 +585,7 @@ test('passes on custom options', async (t) => { custom: { 'node-resolve': { resolved: { - id: join(__dirname, 'fixtures', 'entry', 'other.js'), + id: join(DIRNAME, 'fixtures', 'entry', 'other.js'), moduleSideEffects: null } } @@ -634,7 +630,7 @@ test('allow other plugins to take over resolution', async (t) => { name: 'change-resolution', resolveId(importee) { // Only resolve if the id has been pre-resolved by node-resolve - if (importee === join(__dirname, 'fixtures', 'entry', 'main.js')) { + if (importee === join(DIRNAME, 'fixtures', 'entry', 'main.js')) { return { id: join(dirname(importee), 'other.js'), meta: { 'change-resolution': 'changed' } @@ -645,7 +641,7 @@ test('allow other plugins to take over resolution', async (t) => { load(id) { const info = this.getModuleInfo(id); - t.is(info.id, join(__dirname, 'fixtures', 'entry', 'other.js')); + t.is(info.id, join(DIRNAME, 'fixtures', 'entry', 'other.js')); t.deepEqual(info.meta, { 'change-resolution': 'changed' }); } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d8e84c43..df4ce8f39 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -374,24 +374,24 @@ importers: packages/node-resolve: specifiers: - '@babel/core': ^7.10.5 + '@babel/core': ^7.19.1 '@babel/plugin-transform-typescript': ^7.10.5 '@rollup/plugin-babel': ^5.1.0 '@rollup/plugin-commonjs': ^22.0.2 '@rollup/plugin-json': ^4.1.0 - '@rollup/pluginutils': ^3.1.0 - '@types/resolve': 1.17.1 + '@rollup/pluginutils': ^4.2.1 + '@types/resolve': 1.20.2 deepmerge: ^4.2.2 - es5-ext: ^0.10.53 - is-builtin-module: ^3.1.0 + es5-ext: ^0.10.62 + is-builtin-module: ^3.2.0 is-module: ^1.0.0 - resolve: ^1.19.0 - rollup: ^2.78.1 - source-map: ^0.7.3 + resolve: ^1.22.1 + rollup: ^3.0.0-7 + source-map: ^0.7.4 string-capitalize: ^1.0.1 dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - '@types/resolve': 1.17.1 + '@rollup/pluginutils': 4.2.1 + '@types/resolve': 1.20.2 deepmerge: 4.2.2 is-builtin-module: 3.2.0 is-module: 1.0.0 @@ -399,11 +399,11 @@ importers: devDependencies: '@babel/core': 7.19.1 '@babel/plugin-transform-typescript': 7.19.1_@babel+core@7.19.1 - '@rollup/plugin-babel': 5.3.1_r56fldxoyazzliugjcx2ns4pma - '@rollup/plugin-commonjs': 22.0.2_rollup@2.79.1 - '@rollup/plugin-json': 4.1.0_rollup@2.79.1 + '@rollup/plugin-babel': 5.3.1_7nxlpq7csoud2kb557q5ujip64 + '@rollup/plugin-commonjs': 22.0.2_rollup@3.0.0-7 + '@rollup/plugin-json': 4.1.0_rollup@3.0.0-7 es5-ext: 0.10.62 - rollup: 2.79.1 + rollup: 3.0.0-7 source-map: 0.7.4 string-capitalize: 1.0.1 @@ -1974,7 +1974,7 @@ packages: slash: 3.0.0 dev: true - /@rollup/plugin-babel/5.3.1_r56fldxoyazzliugjcx2ns4pma: + /@rollup/plugin-babel/5.3.1_7nxlpq7csoud2kb557q5ujip64: resolution: {integrity: sha512-WFfdLWU/xVWKeRQnKmIAQULUI7Il0gZnBIH/ZFO069wYIfPu+8zrfp/KMW0atmELoRDq8FbiP3VCss9MhCut7Q==} engines: {node: '>= 10.0.0'} peerDependencies: @@ -1987,8 +1987,8 @@ packages: dependencies: '@babel/core': 7.19.1 '@babel/helper-module-imports': 7.18.6 - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - rollup: 2.79.1 + '@rollup/pluginutils': 3.1.0_rollup@3.0.0-7 + rollup: 3.0.0-7 dev: true /@rollup/plugin-buble/0.21.3_rollup@2.79.1: @@ -2047,29 +2047,20 @@ packages: rollup: 2.79.1 dev: true - /@rollup/plugin-commonjs/22.0.2_rollup@2.79.1: + /@rollup/plugin-commonjs/22.0.2_rollup@3.0.0-7: resolution: {integrity: sha512-//NdP6iIwPbMTcazYsiBMbJW7gfmpHom33u1beiIoHDEM0Q9clvtQB1T0efvMqHeKsGohiHo97BCPCkBXdscwg==} engines: {node: '>= 12.0.0'} peerDependencies: rollup: ^2.68.0 dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 + '@rollup/pluginutils': 3.1.0_rollup@3.0.0-7 commondir: 1.0.1 estree-walker: 2.0.2 glob: 7.2.3 is-reference: 1.2.1 magic-string: 0.25.9 resolve: 1.22.1 - rollup: 2.79.1 - dev: true - - /@rollup/plugin-json/4.1.0_rollup@2.79.1: - resolution: {integrity: sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==} - peerDependencies: - rollup: ^1.20.0 || ^2.0.0 - dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - rollup: 2.79.1 + rollup: 3.0.0-7 dev: true /@rollup/plugin-json/4.1.0_rollup@3.0.0-7: @@ -2405,6 +2396,7 @@ packages: /@types/node/18.7.21: resolution: {integrity: sha512-rLFzK5bhM0YPyCoTC8bolBjMk7bwnZ8qeZUBslBfjZQou2ssJdWslx9CZ8DGM+Dx7QXQiiTVZ/6QO6kwtHkZCA==} + dev: true /@types/normalize-package-data/2.4.1: resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} @@ -2422,6 +2414,11 @@ packages: resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} dependencies: '@types/node': 18.7.21 + dev: true + + /@types/resolve/1.20.2: + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} + dev: false /@types/responselike/1.0.0: resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==}