From ab1de1ff201c0640633b92805923e42afdc33410 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 8 Oct 2021 09:27:28 +0200 Subject: [PATCH] fix(node-resolve): pass on isEntry flag --- packages/node-resolve/package.json | 2 +- packages/node-resolve/src/index.js | 15 ++- .../node-resolve/test/fixtures/entry/dep.js | 0 .../node-resolve/test/fixtures/entry/main.js | 3 + .../node-resolve/test/fixtures/entry/other.js | 1 + .../root-package-side-effect/index.js | 2 + .../node-resolve/test/snapshots/dedupe.js.md | 24 ++-- .../test/snapshots/dedupe.js.snap | Bin 354 -> 357 bytes .../node-resolve/test/snapshots/only.js.md | 6 +- .../node-resolve/test/snapshots/only.js.snap | Bin 154 -> 154 bytes .../node-resolve/test/snapshots/test.js.md | 99 ++++++++-------- .../node-resolve/test/snapshots/test.js.snap | Bin 1437 -> 1459 bytes packages/node-resolve/test/test.js | 110 ++++++++++++++---- pnpm-lock.yaml | 44 +++---- 14 files changed, 192 insertions(+), 114 deletions(-) create mode 100644 packages/node-resolve/test/fixtures/entry/dep.js create mode 100644 packages/node-resolve/test/fixtures/entry/main.js create mode 100644 packages/node-resolve/test/fixtures/entry/other.js diff --git a/packages/node-resolve/package.json b/packages/node-resolve/package.json index 3600fa92e..39131c9d1 100644 --- a/packages/node-resolve/package.json +++ b/packages/node-resolve/package.json @@ -68,7 +68,7 @@ "@rollup/plugin-commonjs": "^16.0.0", "@rollup/plugin-json": "^4.1.0", "es5-ext": "^0.10.53", - "rollup": "^2.42.0", + "rollup": "^2.58.0", "source-map": "^0.7.3", "string-capitalize": "^1.0.1" }, diff --git a/packages/node-resolve/src/index.js b/packages/node-resolve/src/index.js index 473e590e4..8d6ee47b9 100644 --- a/packages/node-resolve/src/index.js +++ b/packages/node-resolve/src/index.js @@ -72,7 +72,7 @@ export function nodeResolve(opts = {}) { const browserMapCache = new Map(); let preserveSymlinks; - const doResolveId = async (context, importee, importer, opts) => { + const doResolveId = async (context, importee, importer, custom) => { // strip query params from import const [importPath, params] = importee.split('?'); const importSuffix = `${params ? `?${params}` : ''}`; @@ -142,8 +142,7 @@ export function nodeResolve(opts = {}) { } const warn = (...args) => context.warn(...args); - const isRequire = - opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire; + const isRequire = custom && custom['node-resolve'] && custom['node-resolve'].isRequire; const exportConditions = isRequire ? conditionsCjs : conditionsEsm; if (useBrowserOverrides && !exportConditions.includes('browser')) @@ -250,7 +249,7 @@ export function nodeResolve(opts = {}) { isDirCached.clear(); }, - async resolveId(importee, importer, opts) { + async resolveId(importee, importer, resolveOptions) { if (importee === ES6_BROWSER_EMPTY) { return importee; } @@ -261,9 +260,13 @@ export function nodeResolve(opts = {}) { importer = undefined; } - const resolved = await doResolveId(this, importee, importer, opts); + const resolved = await doResolveId(this, importee, importer, resolveOptions.custom); if (resolved) { - const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true }); + const resolvedResolved = await this.resolve( + resolved.id, + importer, + Object.assign({ skipSelf: true }, resolveOptions) + ); const isExternal = !!(resolvedResolved && resolvedResolved.external); if (isExternal) { return false; diff --git a/packages/node-resolve/test/fixtures/entry/dep.js b/packages/node-resolve/test/fixtures/entry/dep.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/node-resolve/test/fixtures/entry/main.js b/packages/node-resolve/test/fixtures/entry/main.js new file mode 100644 index 000000000..3539759cb --- /dev/null +++ b/packages/node-resolve/test/fixtures/entry/main.js @@ -0,0 +1,3 @@ +import './dep.js'; + +console.log('main'); diff --git a/packages/node-resolve/test/fixtures/entry/other.js b/packages/node-resolve/test/fixtures/entry/other.js new file mode 100644 index 000000000..8bbad80dc --- /dev/null +++ b/packages/node-resolve/test/fixtures/entry/other.js @@ -0,0 +1 @@ +console.log('other'); diff --git a/packages/node-resolve/test/fixtures/root-package-side-effect/index.js b/packages/node-resolve/test/fixtures/root-package-side-effect/index.js index 3425e6f0f..f481fecb7 100644 --- a/packages/node-resolve/test/fixtures/root-package-side-effect/index.js +++ b/packages/node-resolve/test/fixtures/root-package-side-effect/index.js @@ -1 +1,3 @@ import './side-effect.js'; + +console.log('main'); diff --git a/packages/node-resolve/test/snapshots/dedupe.js.md b/packages/node-resolve/test/snapshots/dedupe.js.md index 5e20bc021..e007008c4 100644 --- a/packages/node-resolve/test/snapshots/dedupe.js.md +++ b/packages/node-resolve/test/snapshots/dedupe.js.md @@ -4,34 +4,34 @@ The actual snapshot is saved in `dedupe.js.snap`. Generated by [AVA](https://avajs.dev). -## dedupes deep imports by package name if dedupe is set +## single module version is bundled if dedupe is set > Snapshot 1 { - React: 'react/deep.js:root', - ReactConsumer: 'react-consumer:react/deep.js:root', + React: 'react:root', + ReactConsumer: 'react-consumer:react:root', } -## dedupes scoped deep imports by package name if dedupe is set +## dedupes deep imports by package name if dedupe is set > Snapshot 1 { - ScopedDeduped: 'scoped-deduped:root', - ScopedDedupedConsumer: 'scoped-deduped-consumer:scoped-deduped:root', + React: 'react/deep.js:root', + ReactConsumer: 'react-consumer:react/deep.js:root', } -## multiple module versions are bundled if dedupe is not set +## dedupes scoped deep imports by package name if dedupe is set > Snapshot 1 { - React: 'react:root', - ReactConsumer: 'react-consumer:react:child', + ScopedDeduped: 'scoped-deduped:root', + ScopedDedupedConsumer: 'scoped-deduped-consumer:scoped-deduped:root', } -## single module version is bundled if dedupe is set +## single module version is bundled if dedupe is set as a function > Snapshot 1 @@ -40,11 +40,11 @@ Generated by [AVA](https://avajs.dev). ReactConsumer: 'react-consumer:react:root', } -## single module version is bundled if dedupe is set as a function +## multiple module versions are bundled if dedupe is not set > Snapshot 1 { React: 'react:root', - ReactConsumer: 'react-consumer:react:root', + ReactConsumer: 'react-consumer:react:child', } diff --git a/packages/node-resolve/test/snapshots/dedupe.js.snap b/packages/node-resolve/test/snapshots/dedupe.js.snap index e91f821dc56a81106e1c33bf00e70c36b552dfcc..95266450221956d68dd152f046d2a47818689967 100644 GIT binary patch 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 literal 354 zcmV-o0iFIqRzVZZsF3sSkk$D@*+mCs2@;) zXv32GsVR%*I=mK8+xH1dE05AR}u~YGQH;j3-nC;_0WPrWWXB6 Snapshot 1 [] -## regex +## handles nested entry modules > Snapshot 1 [] -## specify the only packages to resolve +## regex > Snapshot 1 diff --git a/packages/node-resolve/test/snapshots/only.js.snap b/packages/node-resolve/test/snapshots/only.js.snap index 89cdbb5f9302c414868f7af877670752b58a2332..4b155d45fff4ebc1a18cafaf214a20eb12d80223 100644 GIT binary patch literal 154 zcmV;L0A>F{RzVBlvv5g2xIZ{^HWC&0QZHE IUcCSS01g62jQ{`u literal 154 zcmZ<^b5sbg2@Agi_6I7{#Dyj*F8D*0{>1~6dePE1HhNc#|f z_0XS~JsYb(&Dz@i$^P8Kq!b3mRE2GoKka9|KA4^Cd)ocuRjphH$q6f@1$N8aomb-LU(z5Z#&z~z7voQ1=k9@rs GXdwXc Snapshot 1 + + 'Could not resolve \'./foo\' from unresolved-local.js' + ## allows custom moduleDirectories with legacy customResolveOptions.moduleDirectory > Snapshot 1 @@ -17,21 +23,6 @@ Generated by [AVA](https://avajs.dev). }, ] -## handles package side-effects - -> Snapshot 1 - - [ - 'array-dep1', - 'array-dep3', - 'array-dep5', - 'array-index', - 'false-dep1', - 'true-dep1', - 'true-dep2', - 'true-index', - ] - ## ignores deep-import non-modules > Snapshot 1 @@ -47,129 +38,141 @@ Generated by [AVA](https://avajs.dev). }, ] -## ignores the package.json sideEffects property for files in root package with "ignoreSideEffectsForRoot" option +## respects the package.json sideEffects property for files in root package by default > Snapshot 1 `'use strict';␊ ␊ - console.log('side effect');␊ + console.log('main');␊ ` -## respects the package.json sideEffects property for files in root package by default +## 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');␊ ` -## throws error for removed customResolveOptions.basedir option +## handles package side-effects > Snapshot 1 - Error { - message: 'node-resolve: `customResolveOptions.basedir` is no longer an option. If you need this, please open an issue.', - } + [ + 'array-dep1', + 'array-dep3', + 'array-dep5', + 'array-index', + 'false-dep1', + 'true-dep1', + 'true-dep2', + 'true-index', + ] -## throws error for removed customResolveOptions.extensions option +## throws error for removed customResolveOptions.preserveSymlinks option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.extensions` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.preserveSymlinks` is no longer an option. We now always use the rollup `preserveSymlinks` option.', } -## throws error for removed customResolveOptions.includeCoreModules option +## throws error for removed customResolveOptions.basedir option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.includeCoreModules` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.basedir` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.isDirectory option +## throws error for removed customResolveOptions.package option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.isDirectory` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.package` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.isFile option +## throws error for removed customResolveOptions.extensions option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.isFile` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.extensions` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.package option +## throws error for removed customResolveOptions.includeCoreModules option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.package` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.includeCoreModules` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.packageFilter option +## throws error for removed customResolveOptions.readFile option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.packageFilter` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.readFile` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.packageIterator option +## throws error for removed customResolveOptions.isFile option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.packageIterator` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.isFile` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.pathFilter option +## throws error for removed customResolveOptions.isDirectory option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.pathFilter` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.isDirectory` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.paths option +## throws error for removed customResolveOptions.realpath option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.paths` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.realpath` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.preserveSymlinks option +## throws error for removed customResolveOptions.packageFilter option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.preserveSymlinks` is no longer an option. We now always use the rollup `preserveSymlinks` option.', + message: 'node-resolve: `customResolveOptions.packageFilter` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.readFile option +## throws error for removed customResolveOptions.pathFilter option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.readFile` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.pathFilter` is no longer an option. If you need this, please open an issue.', } -## throws error for removed customResolveOptions.realpath option +## throws error for removed customResolveOptions.paths option > Snapshot 1 Error { - message: 'node-resolve: `customResolveOptions.realpath` is no longer an option. If you need this, please open an issue.', + message: 'node-resolve: `customResolveOptions.paths` is no longer an option. If you need this, please open an issue.', } -## throws error if local id is not resolved +## throws error for removed customResolveOptions.packageIterator option > Snapshot 1 - 'Could not resolve \'./foo\' from unresolved-local.js' + Error { + message: 'node-resolve: `customResolveOptions.packageIterator` is no longer an option. If you need this, please open an issue.', + } diff --git a/packages/node-resolve/test/snapshots/test.js.snap b/packages/node-resolve/test/snapshots/test.js.snap index 5998414a57eb36bd4d268510715b8aadc16262c9..956e33b1a44fa8907def64051a9db40f8b7a0588 100644 GIT binary patch literal 1459 zcmV;k1x)%uRzVp7u6-$SBDsyUCYx&hIZK*UD;@qf4ty4R=3~s!eT4{ZUUT`LXP-RQ)B5ex zvEXylCu5GTEkbDP?MGg%m-_4_`o7yfJQ!GmIr>g9Lfe*ox+1V}*`rtfSu6Dy^)+LT zY7-IK8T-B|9^D+Yc$$u;Ti)M;Ir>-$LT~T>amkAQYfERI*`yw8w17now8DkZ-YVPF z*%jN%U#sofTl?FE7cfU#f!_ToP(1hH^OvqZIPvfK=+`>T(P^a!on2G0aoI(5rhi&c zTfWVD0dsUEkQF(&fAM5&nFZqh&XBsrB2pUsDL{y2) zh{WU=Rfr%H#y9#%LkCGSoye3%i53^tN|KbQpiDonwC^+{Cl zA&9bpj%AJ|^Q+|ZMFm7;O8S;(nw`O@1HB1U581Wq#u;WCDZ@$@FKS)T5NKao+Z<>J zEEw5dmJMjI!CK<Bw7I!x9)s|c@(I5%L{U^6-@To36U{0- zyii$2Gm|Df4r2gF1ljW^RA(K)x2DnnEgHR`25h^c}R!C5=58H&e1Eeh#*0C N`7eWZv|>^c0017O$PEAh literal 1437 zcmV;O1!DR^RzV!rI17A`T%Lu;Gw(xNbZW=6ZYYX?wTZd&_;$HDCk{ z0-}jwJ~Cqh7$PB{s8I<%2#^RqgMZ+RB!Uhhk$()L_y-33?rCqc2S^t+)+S%hIlu3m zbHCsB{qE^KzhZ={&})0XTefQO>hf8qH*3dQY})~Z-&wGDpOkriS^uN1&?^T%iazl^ zX6Qbc@W%Jy^7#*(yLjckia!>jpBgbk4I4tc5?{9_g)I@Azx8Og{q4P&p$&F~d{sy0 zKfP|2dwiSp%rd~wypSZRe14=d6%!PlLp5Rv|)yR3pVYfdTDF> z%<4{U!-n%G1|pcDJH{bo_Z_Xj^5d!K?e5)sB3CEBhZ(xs1Cg(tzG=k;bb4@FL|?hh zejYRQEwI3?s}FYV*N>e&e8;POU0?KKhF&X2sIJAcWpHBMJL~7J`DADR(_dnS&aQxb z*E*)onZCXH<%XVp4L_fM7BjR1EME6Z`nG}H-e`|=W#{p4e!vWMc@f$=>Bvh>(tvY< z@%k}*t3MXkbRRu^NdS6Nw!a0S8`VXrxP zBDN#!^kG+uY8scI`LS&yk`;jlRH`Y`8d^`HyrJnzsx3EeP3xi}Yr!=5sk(+nvMEWF zd$cGKH6klSQse|x2`3YU%?y&|6z~k;qzsqUh@nxUCn-@CNixzTI(nb{x_^-(mWp8* z<1{LW>Wzst$4OQ(h)k&fltitDq$LWAU;>rRiK3<%^uH&P=J+01Q_@6~Vu;XQoywZo zEom;9Vz`JhFBt+|ps2J(5e$izHm6iEoK(sQO`=rVO6w`AI$Fu|NEgRrp{P<`SJZ4t zlPOkSQkv6~CCx+~!-)(U(`jk{!4!2an??B_aOp0VOKBg)`WO_}3^n24?f>TpIgt<7 zE>H|ffcNnBM@#E|o_5Rep}lY-q^VZ9sMYM`xU2{E(KpsHM!Wr6j) zUN6EPmWA;cKWHs-WuScwY%kb3vky0wU0{cBextJ1ST~$>W|H$=E1_j066)X~f!4s+ z5pHXYv@TiJxUj3aWoc_$`-s_YF_l(S$fE^J5hzUua%ezSO-O22Yt5|RMbQ$ zVTb|^Q8_d{!>Kat5U>KxQwwlfz=||5G}0;TJ;{~S-DJqTDN}48GJvuUQ{zm(d8g1I zP+s@X@pyR9zXHjVl*HYB4dNg)9tS!2@0sHnw$M9b;osG$Q-Rh1+X2=Dx?Fv8Z94u+ zn-i8U=~&bp?pof^7H$qN8sojK9d23IKOAx;81iM1I}At?6cnTI+CxFW$ALJ5qyusk z9lk<@kJTEINs4@uq~HOjDnWUinVaB9v85#=Am`9f*k@o1@;?QCB8{D-3XVP4=qIFVT4R|-kWz}Jla=h`D~+ovn-$8@{P~=M38&0 r<#ZGl#yLr&!yf3geB*T0815 (warning) => + t.fail(`No warnings were expected, got:\n${warning.code}\n${warning.message}`); + +const getLastPathFragment = (path) => path && path.split(/[\\/]/).slice(-1)[0]; + test('finds a module with jsnext:main', async (t) => { const bundle = await rollup({ input: 'jsnext.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [nodeResolve({ mainFields: ['jsnext:main', 'module', 'main'] })] }); const { module } = await testBundle(t, bundle); @@ -25,7 +30,7 @@ test('finds a module with jsnext:main', async (t) => { test('finds and converts a basic CommonJS module', async (t) => { const bundle = await rollup({ input: 'commonjs.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [nodeResolve({ mainFields: ['main'] }), commonjs()] }); const { module } = await testBundle(t, bundle); @@ -36,7 +41,7 @@ test('finds and converts a basic CommonJS module', async (t) => { test('handles a trailing slash', async (t) => { const bundle = await rollup({ input: 'trailing-slash.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [nodeResolve({ mainFields: ['main'] }), commonjs()] }); const { module } = await testBundle(t, bundle); @@ -47,7 +52,7 @@ test('handles a trailing slash', async (t) => { test('finds a file inside a package directory', async (t) => { const bundle = await rollup({ input: 'granular.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve(), babel({ @@ -73,7 +78,7 @@ test('finds a file inside a package directory', async (t) => { test('loads local directories by finding index.js within them', async (t) => { const bundle = await rollup({ input: 'local-index/main.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [nodeResolve()] }); const { module } = await testBundle(t, bundle); @@ -84,7 +89,7 @@ test('loads local directories by finding index.js within them', async (t) => { test('loads package directories by finding index.js within them', async (t) => { const bundle = await rollup({ input: 'package-index.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [nodeResolve()] }); const code = await getCode(bundle); @@ -95,7 +100,7 @@ test('loads package directories by finding index.js within them', async (t) => { test('supports non-standard extensions', async (t) => { const bundle = await rollup({ input: 'extensions/main.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve({ extensions: ['.js', '.wut'] @@ -109,7 +114,7 @@ test('does not fallback to standard node resolve algorithm if error with exports try { await rollup({ input: 'exports-error-no-fallback/main.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve({ extensions: ['.js'] @@ -125,7 +130,7 @@ test('does not fallback to standard node resolve algorithm if error with exports test('supports JS extensions in TS when referring to TS imports', async (t) => { const bundle = await rollup({ input: 'ts-import-js-extension/import-ts-with-js-extension.ts', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve({ extensions: ['.js', '.ts'] @@ -144,7 +149,7 @@ test('supports JS extensions in TS when referring to TS imports', async (t) => { test('supports JS extensions in TS actually importing JS with export map', async (t) => { const bundle = await rollup({ input: 'ts-import-js-extension-for-js-file-export-map/import-js-with-js-extension.ts', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve({ extensions: ['.js', '.ts'] @@ -163,7 +168,7 @@ test('supports JS extensions in TS actually importing JS with export map', async test('handles package.json being a directory earlier in the path', async (t) => { const bundle = await rollup({ input: 'package-json-in-path/package.json/main.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve({ extensions: ['.js'] @@ -175,14 +180,14 @@ test('handles package.json being a directory earlier in the path', async (t) => }); test('ignores IDs with null character', async (t) => { - const result = await nodeResolve().resolveId('\0someid', 'test.js'); + const result = await nodeResolve().resolveId('\0someid', 'test.js', {}); t.is(result, null); }); test('finds and uses an .mjs module', async (t) => { const bundle = await rollup({ input: 'module-mjs.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [nodeResolve({ preferBuiltins: false })] }); const { module } = await testBundle(t, bundle); @@ -193,7 +198,7 @@ test('finds and uses an .mjs module', async (t) => { test('supports ./ in entry filename', async (t) => { const bundle = await rollup({ input: './jsnext.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [nodeResolve({})] }); const { module } = await testBundle(t, bundle); @@ -206,7 +211,7 @@ test('throws error if local id is not resolved', async (t) => { try { await rollup({ input: 'unresolved-local.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [nodeResolve()] }); } catch (e) { @@ -217,7 +222,7 @@ test('throws error if local id is not resolved', async (t) => { test('allows custom moduleDirectories', async (t) => { const bundle = await rollup({ input: 'custom-module-dir/main.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve({ moduleDirectories: ['js_modules'] @@ -269,7 +274,7 @@ test('generates manual chunks', async (t) => { const chunkName = 'mychunk'; const bundle = await rollup({ input: 'manualchunks.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), manualChunks: { [chunkName]: ['simple'] }, @@ -287,7 +292,7 @@ test('generates manual chunks', async (t) => { test('resolves dynamic imports', async (t) => { const bundle = await rollup({ input: 'dynamic.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), inlineDynamicImports: true, plugins: [nodeResolve()] }); @@ -299,6 +304,7 @@ test('resolves dynamic imports', async (t) => { test('respects the package.json sideEffects property for files in root package by default', async (t) => { const bundle = await rollup({ input: 'root-package-side-effect/index.js', + onwarn: failOnWarn(t), plugins: [ nodeResolve({ rootDir: 'root-package-side-effect' @@ -314,6 +320,7 @@ test('respects the package.json sideEffects property for files in root package b test('ignores the package.json sideEffects property for files in root package with "ignoreSideEffectsForRoot" option', async (t) => { const bundle = await rollup({ input: 'root-package-side-effect/index.js', + onwarn: failOnWarn(t), plugins: [ nodeResolve({ rootDir: 'root-package-side-effect', @@ -330,6 +337,7 @@ test('ignores the package.json sideEffects property for files in root package wi test('handles package side-effects', async (t) => { const bundle = await rollup({ input: 'side-effects.js', + onwarn: failOnWarn(t), plugins: [nodeResolve()] }); await testBundle(t, bundle); @@ -341,7 +349,7 @@ test('handles package side-effects', async (t) => { test('can resolve imports with hash in path', async (t) => { const bundle = await rollup({ input: 'hash-in-path.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve(), { @@ -362,7 +370,7 @@ test('can resolve imports with hash in path', async (t) => { test('can resolve imports with search params', async (t) => { const bundle = await rollup({ input: 'search-params.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve(), { @@ -386,7 +394,7 @@ test('can resolve imports with search params', async (t) => { test('can resolve imports with search params and hash', async (t) => { const bundle = await rollup({ input: 'search-params-and-hash.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), plugins: [ nodeResolve(), { @@ -416,7 +424,7 @@ test('can resolve imports with search params and hash', async (t) => { test('marks a module as external if the resolved version is external', async (t) => { const bundle = await rollup({ input: 'resolved-external/main.js', - onwarn: () => t.fail('No warnings were expected'), + onwarn: failOnWarn(t), external: [/node_modules/], plugins: [nodeResolve()] }); @@ -454,3 +462,61 @@ test('marks a module as external if the resolved version is external', async (t) t.fail('expecting error'); }); }); + +test('passes on "isEntry" flag', async (t) => { + const resolveOptions = []; + await rollup({ + input: 'entry/main.js', + onwarn: failOnWarn(t), + plugins: [ + nodeResolve(), + { + name: 'test', + buildStart() { + // A emitted chunk with an importer must not lose its "isEntry" flag after node-resolve + this.emitFile({ type: 'chunk', importer: 'entry/main.js', id: './other.js' }); + }, + resolveId(source, importer, options) { + resolveOptions.push([ + getLastPathFragment(source), + getLastPathFragment(importer), + options + ]); + } + } + ] + }); + t.deepEqual(resolveOptions, [ + ['other.js', 'main.js', { custom: void 0, isEntry: true }], + ['main.js', void 0, { custom: void 0, isEntry: true }], + ['dep.js', 'main.js', { custom: void 0, isEntry: false }] + ]); +}); + +test.only('passes on custom options', async (t) => { + const resolveOptions = []; + await rollup({ + input: 'entry/other.js', + onwarn: failOnWarn(t), + plugins: [ + nodeResolve(), + { + name: 'test', + async buildStart() { + await this.resolve('entry/main.js', void 0, { isEntry: false, custom: { test: 42 } }); + }, + resolveId(source, importer, options) { + resolveOptions.push([ + getLastPathFragment(source), + getLastPathFragment(importer), + options + ]); + } + } + ] + }); + t.deepEqual(resolveOptions, [ + ['main.js', void 0, { custom: { test: 42 }, isEntry: false }], + ['other.js', void 0, { custom: {}, isEntry: true }] + ]); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f8b03411c..e549b46a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -381,11 +381,11 @@ importers: es5-ext: ^0.10.53 is-module: ^1.0.0 resolve: ^1.19.0 - rollup: ^2.42.0 + rollup: ^2.58.0 source-map: ^0.7.3 string-capitalize: ^1.0.1 dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.47.0 + '@rollup/pluginutils': 3.1.0_rollup@2.58.0 '@types/resolve': 1.17.1 builtin-modules: 3.1.0 deepmerge: 4.2.2 @@ -394,11 +394,11 @@ importers: devDependencies: '@babel/core': 7.12.3 '@babel/plugin-transform-typescript': 7.12.1_@babel+core@7.12.3 - '@rollup/plugin-babel': 5.2.1_@babel+core@7.12.3+rollup@2.47.0 - '@rollup/plugin-commonjs': 16.0.0_rollup@2.47.0 - '@rollup/plugin-json': 4.1.0_rollup@2.47.0 + '@rollup/plugin-babel': 5.2.1_@babel+core@7.12.3+rollup@2.58.0 + '@rollup/plugin-commonjs': 16.0.0_rollup@2.58.0 + '@rollup/plugin-json': 4.1.0_rollup@2.58.0 es5-ext: 0.10.53 - rollup: 2.47.0 + rollup: 2.58.0 source-map: 0.7.3 string-capitalize: 1.0.1 @@ -510,7 +510,7 @@ importers: '@rollup/pluginutils': 3.1.0_rollup@2.32.1 resolve: 1.18.1 devDependencies: - '@rollup/plugin-buble': link:../buble + '@rollup/plugin-buble': 0.21.3_rollup@2.32.1 '@rollup/plugin-commonjs': 11.1.0_rollup@2.32.1 '@rollup/plugin-typescript': 5.0.2_rollup@2.32.1+typescript@4.2.4 '@types/node': 10.17.48 @@ -2046,7 +2046,7 @@ packages: slash: 3.0.0 dev: true - /@rollup/plugin-babel/5.2.1_@babel+core@7.12.3+rollup@2.47.0: + /@rollup/plugin-babel/5.2.1_@babel+core@7.12.3+rollup@2.58.0: resolution: {integrity: sha512-Jd7oqFR2dzZJ3NWANDyBjwTtX/lYbZpVcmkHrfQcpvawHs9E4c0nYk5U2mfZ6I/DZcIvy506KZJi54XK/jxH7A==} engines: {node: '>= 10.0.0'} peerDependencies: @@ -2059,8 +2059,8 @@ packages: dependencies: '@babel/core': 7.12.3 '@babel/helper-module-imports': 7.12.1 - '@rollup/pluginutils': 3.1.0_rollup@2.47.0 - rollup: 2.47.0 + '@rollup/pluginutils': 3.1.0_rollup@2.58.0 + rollup: 2.58.0 dev: true /@rollup/plugin-buble/0.21.3_rollup@2.32.1: @@ -2107,20 +2107,20 @@ packages: rollup: 2.32.1 dev: true - /@rollup/plugin-commonjs/16.0.0_rollup@2.47.0: + /@rollup/plugin-commonjs/16.0.0_rollup@2.58.0: resolution: {integrity: sha512-LuNyypCP3msCGVQJ7ki8PqYdpjfEkE/xtFa5DqlF+7IBD0JsfMZ87C58heSwIMint58sAUZbt3ITqOmdQv/dXw==} engines: {node: '>= 8.0.0'} peerDependencies: rollup: ^2.30.0 dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.47.0 + '@rollup/pluginutils': 3.1.0_rollup@2.58.0 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.18.1 - rollup: 2.47.0 + rollup: 2.58.0 dev: true /@rollup/plugin-json/4.1.0_rollup@2.32.1: @@ -2141,13 +2141,13 @@ packages: rollup: 2.39.0 dev: true - /@rollup/plugin-json/4.1.0_rollup@2.47.0: + /@rollup/plugin-json/4.1.0_rollup@2.58.0: resolution: {integrity: sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==} peerDependencies: rollup: ^1.20.0 || ^2.0.0 dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.47.0 - rollup: 2.47.0 + '@rollup/pluginutils': 3.1.0_rollup@2.58.0 + rollup: 2.58.0 dev: true /@rollup/plugin-node-resolve/10.0.0_rollup@2.32.1: @@ -2284,7 +2284,7 @@ packages: picomatch: 2.2.2 rollup: 2.39.0 - /@rollup/pluginutils/3.1.0_rollup@2.47.0: + /@rollup/pluginutils/3.1.0_rollup@2.58.0: resolution: {integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==} engines: {node: '>= 8.0.0'} peerDependencies: @@ -2293,7 +2293,7 @@ packages: '@types/estree': 0.0.39 estree-walker: 1.0.1 picomatch: 2.2.2 - rollup: 2.47.0 + rollup: 2.58.0 /@rollup/pluginutils/4.1.1: resolution: {integrity: sha512-clDjivHqWGXi7u+0d2r2sBi4Ie6VLEAzWMIkvJLnDmxoOhBYOTfzGbOQBA32THHm11/LiJbd01tJUpJsbshSWQ==} @@ -7336,16 +7336,16 @@ packages: fsevents: 2.3.2 dev: true - /rollup/2.47.0: - resolution: {integrity: sha512-rqBjgq9hQfW0vRmz+0S062ORRNJXvwRpzxhFXORvar/maZqY6za3rgQ/p1Glg+j1hnc1GtYyQCPiAei95uTElg==} + /rollup/2.54.0: + resolution: {integrity: sha512-RHzvstAVwm9A751NxWIbGPFXs3zL4qe/eYg+N7WwGtIXVLy1cK64MiU37+hXeFm1jqipK6DGgMi6Z2hhPuCC3A==} engines: {node: '>=10.0.0'} hasBin: true optionalDependencies: fsevents: 2.3.2 dev: true - /rollup/2.54.0: - resolution: {integrity: sha512-RHzvstAVwm9A751NxWIbGPFXs3zL4qe/eYg+N7WwGtIXVLy1cK64MiU37+hXeFm1jqipK6DGgMi6Z2hhPuCC3A==} + /rollup/2.58.0: + resolution: {integrity: sha512-NOXpusKnaRpbS7ZVSzcEXqxcLDOagN6iFS8p45RkoiMqPHDLwJm758UF05KlMoCRbLBTZsPOIa887gZJ1AiXvw==} engines: {node: '>=10.0.0'} hasBin: true optionalDependencies: