@@ -11,6 +11,7 @@ import { npmAutoInstall } from './npm-auto-install.js';
11
11
import jsonPlugin from '../json-plugin.js' ;
12
12
import sizeWarningPlugin from './size-warning-plugin.js' ;
13
13
import { onWarn } from '../../lib/output-utils.js' ;
14
+ import aliasPlugin from '../aliases-plugin.js' ;
14
15
15
16
/** @type {import('rollup').WarningHandlerWithDefault } */
16
17
function customWarn ( warning ) {
@@ -22,6 +23,41 @@ function customWarn(warning) {
22
23
onWarn ( warning ) ;
23
24
}
24
25
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
+
25
61
/**
26
62
* @param {string } requestId
27
63
* @param {object } options
@@ -30,29 +66,38 @@ function customWarn(warning) {
30
66
* @param {string } options.cacheDir
31
67
* @param {string } options.cwd
32
68
* @param {string } options.registryUrl
69
+ * @param {Record<string, string> } options.alias
33
70
* @param {Map<string, string> } options.resolutionCache
34
71
*/
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
+ ) {
36
76
const meta = getPackageInfo ( requestId ) ;
37
77
const pkgName = meta . name ;
38
78
39
79
/** @type {Map<string, string> } */
40
80
const browserReplacement = new Map ( ) ;
41
81
82
+ console . log ( 'REQUEST' , requestId ) ;
83
+
42
84
const bundle = await rollup . rollup ( {
43
85
input : requestId ,
44
86
external : [ ...builtinModules ] ,
45
87
onwarn : customWarn ,
46
88
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 } ) ,
52
90
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
+ } )
56
101
]
57
102
} ) ;
58
103
0 commit comments