@@ -11,6 +11,7 @@ import { npmAutoInstall } from './npm-auto-install.js';
1111import jsonPlugin from '../json-plugin.js' ;
1212import sizeWarningPlugin from './size-warning-plugin.js' ;
1313import { onWarn } from '../../lib/output-utils.js' ;
14+ import aliasPlugin from '../aliases-plugin.js' ;
1415
1516/** @type {import('rollup').WarningHandlerWithDefault } */
1617function customWarn ( warning ) {
@@ -22,6 +23,41 @@ function customWarn(warning) {
2223 onWarn ( warning ) ;
2324}
2425
26+ /**
27+ * @param {object } options
28+ * @param {boolean } options.autoInstall
29+ * @param {boolean } options.production
30+ * @param {string } options.cacheDir
31+ * @param {string } options.cwd
32+ * @param {string } options.registryUrl
33+ * @param {string } [options.requestId]
34+ * @param {Map<string, string> } options.resolutionCache
35+ * @param {Map<string, string> } options.browserReplacement
36+ * @returns {import('rollup').Plugin[] }
37+ */
38+ export function getNpmPlugins ( {
39+ autoInstall,
40+ production,
41+ cacheDir,
42+ cwd,
43+ resolutionCache,
44+ registryUrl,
45+ browserReplacement,
46+ requestId
47+ } ) {
48+ // @ts -ignore
49+ return [
50+ browserFieldPlugin ( { browserReplacement } ) ,
51+ ! production && requestId && npmExternalDeps ( { requestId } ) ,
52+ ! process . env . DISABLE_LOCAL_NPM && npmLocalPackage ( { root : cwd } ) ,
53+ autoInstall && npmAutoInstall ( { cacheDir, registryUrl } ) ,
54+ npmLoad ( { browserReplacement, resolutionCache, production } ) ,
55+ commonjsPlugin ( { production } ) ,
56+ subPackageLegacy ( ) ,
57+ sizeWarningPlugin ( )
58+ ] . filter ( Boolean ) ;
59+ }
60+
2561/**
2662 * @param {string } requestId
2763 * @param {object } options
@@ -30,29 +66,38 @@ function customWarn(warning) {
3066 * @param {string } options.cacheDir
3167 * @param {string } options.cwd
3268 * @param {string } options.registryUrl
69+ * @param {Record<string, string> } options.alias
3370 * @param {Map<string, string> } options.resolutionCache
3471 */
35- export async function npmBundle ( requestId , { autoInstall, production, cacheDir, cwd, resolutionCache, registryUrl } ) {
72+ export async function npmBundle (
73+ requestId ,
74+ { autoInstall, production, cacheDir, cwd, resolutionCache, registryUrl, alias }
75+ ) {
3676 const meta = getPackageInfo ( requestId ) ;
3777 const pkgName = meta . name ;
3878
3979 /** @type {Map<string, string> } */
4080 const browserReplacement = new Map ( ) ;
4181
82+ console . log ( 'REQUEST' , requestId ) ;
83+
4284 const bundle = await rollup . rollup ( {
4385 input : requestId ,
4486 external : [ ...builtinModules ] ,
4587 onwarn : customWarn ,
4688 plugins : [
47- browserFieldPlugin ( { browserReplacement } ) ,
48- npmExternalDeps ( { requestId } ) ,
49- ! process . env . DISABLE_LOCAL_NPM && npmLocalPackage ( { root : cwd } ) ,
50- autoInstall && npmAutoInstall ( { cacheDir, registryUrl } ) ,
51- npmLoad ( { browserReplacement, resolutionCache } ) ,
89+ aliasPlugin ( { alias } ) ,
5290 jsonPlugin ( { root : cwd } ) ,
53- commonjsPlugin ( { production } ) ,
54- subPackageLegacy ( { rootId : requestId } ) ,
55- sizeWarningPlugin ( )
91+ ...getNpmPlugins ( {
92+ requestId,
93+ autoInstall,
94+ production,
95+ cacheDir,
96+ cwd,
97+ resolutionCache,
98+ registryUrl,
99+ browserReplacement
100+ } )
56101 ]
57102 } ) ;
58103
0 commit comments