@tarojs/webpack5-runner 4.2.1-beta.0 → 4.2.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugins/AsyncSubPackagePlugin.js +489 -0
- package/dist/plugins/AsyncSubPackagePlugin.js.map +1 -0
- package/dist/plugins/BuildNativePlugin.js +15 -11
- package/dist/plugins/BuildNativePlugin.js.map +1 -1
- package/dist/plugins/HarmonyPlugin.js +1 -1
- package/dist/plugins/HarmonyPlugin.js.map +1 -1
- package/dist/plugins/MiniCompileModePlugin.js +49 -4
- package/dist/plugins/MiniCompileModePlugin.js.map +1 -1
- package/dist/plugins/MiniPlugin.js +261 -56
- package/dist/plugins/MiniPlugin.js.map +1 -1
- package/dist/plugins/SubPackageIndiePlugin.js +1022 -0
- package/dist/plugins/SubPackageIndiePlugin.js.map +1 -0
- package/dist/plugins/TaroNormalModule.js +16 -0
- package/dist/plugins/TaroNormalModule.js.map +1 -1
- package/dist/plugins/TaroNormalModulesPlugin.js +127 -6
- package/dist/plugins/TaroNormalModulesPlugin.js.map +1 -1
- package/dist/plugins/TaroSingleEntryPlugin.js +1 -1
- package/dist/plugins/TaroSingleEntryPlugin.js.map +1 -1
- package/dist/template/comp.js +2 -1
- package/dist/utils/asyncSubPackage.js +106 -0
- package/dist/utils/asyncSubPackage.js.map +1 -0
- package/dist/utils/component.js +2 -1
- package/dist/utils/component.js.map +1 -1
- package/dist/utils/forceCustomWrapper.js +17 -0
- package/dist/utils/forceCustomWrapper.js.map +1 -0
- package/dist/webpack/HarmonyWebpackPlugin.js +3 -1
- package/dist/webpack/HarmonyWebpackPlugin.js.map +1 -1
- package/dist/webpack/MiniBaseConfig.js +2 -0
- package/dist/webpack/MiniBaseConfig.js.map +1 -1
- package/package.json +12 -12
|
@@ -0,0 +1,1022 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.subPackageIndieCustomWrapperRootsKey = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const helper_1 = require("@tarojs/helper");
|
|
9
|
+
const loader_utils_1 = require("loader-utils");
|
|
10
|
+
const component_1 = require("../utils/component");
|
|
11
|
+
const webpack_1 = require("../utils/webpack");
|
|
12
|
+
const MiniPlugin_1 = require("./MiniPlugin");
|
|
13
|
+
exports.subPackageIndieCustomWrapperRootsKey = '__taroSubPackageIndieCustomWrapperRoots';
|
|
14
|
+
const PLUGIN_NAME = 'TaroSubPackageIndiePlugin';
|
|
15
|
+
class SubPackageIndiePlugin {
|
|
16
|
+
constructor(miniPlugin) {
|
|
17
|
+
this.moduleRequestMap = new Map();
|
|
18
|
+
this.subPackageIndieConfigsCache = null;
|
|
19
|
+
this.allIndieRootsCache = null;
|
|
20
|
+
this.allMainPackageRootsCache = null;
|
|
21
|
+
this.subPackageIndieMatchCache = new Map();
|
|
22
|
+
this.entriesByRootCache = null;
|
|
23
|
+
this.componentByNameCache = null;
|
|
24
|
+
this.rootConfigContentCache = new Map();
|
|
25
|
+
this.forceCustomWrapperByRootCache = new Map();
|
|
26
|
+
this.scopedComponentConfigByCompilation = new WeakMap();
|
|
27
|
+
this.rootUsingCustomWrapperByCompilation = new WeakMap();
|
|
28
|
+
this.miniPlugin = miniPlugin;
|
|
29
|
+
this.options = miniPlugin.options;
|
|
30
|
+
}
|
|
31
|
+
invalidateRunCache() {
|
|
32
|
+
this.subPackageIndieConfigsCache = null;
|
|
33
|
+
this.allIndieRootsCache = null;
|
|
34
|
+
this.allMainPackageRootsCache = null;
|
|
35
|
+
this.subPackageIndieMatchCache.clear();
|
|
36
|
+
this.entriesByRootCache = null;
|
|
37
|
+
this.componentByNameCache = null;
|
|
38
|
+
this.rootConfigContentCache.clear();
|
|
39
|
+
this.forceCustomWrapperByRootCache.clear();
|
|
40
|
+
}
|
|
41
|
+
apply() {
|
|
42
|
+
this.miniPlugin.hooks.modifyEntries.tap(PLUGIN_NAME, entries => {
|
|
43
|
+
const shouldSkipRootEntries = this.hasSubPackageIndieMainPackageRoot() && this.options.newBlended;
|
|
44
|
+
if (!shouldSkipRootEntries)
|
|
45
|
+
return entries;
|
|
46
|
+
return Object.assign(Object.assign({}, entries), { skipRootComp: true, skipRootWrapper: true });
|
|
47
|
+
});
|
|
48
|
+
this.miniPlugin.hooks.afterResolveModule.tap(PLUGIN_NAME, (resolveData) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
if (!this.options.newBlended)
|
|
51
|
+
return;
|
|
52
|
+
const issuer = (_a = resolveData.contextInfo) === null || _a === void 0 ? void 0 : _a.issuer;
|
|
53
|
+
const request = resolveData.request;
|
|
54
|
+
const resource = ((_b = resolveData.createData) === null || _b === void 0 ? void 0 : _b.resource) || resolveData.resource;
|
|
55
|
+
if (issuer && request && resource) {
|
|
56
|
+
this.setResolvedRequestResource(issuer, request, resource);
|
|
57
|
+
}
|
|
58
|
+
if (resolveData.request !== helper_1.taroJsComponents)
|
|
59
|
+
return;
|
|
60
|
+
if (!issuer || !issuer.startsWith(this.options.sourceDir))
|
|
61
|
+
return;
|
|
62
|
+
const componentName = this.miniPlugin.getComponentName(issuer);
|
|
63
|
+
const root = this.isInSubPackageIndieRoot(componentName);
|
|
64
|
+
if (!root)
|
|
65
|
+
return;
|
|
66
|
+
resolveData.dependencies.forEach((dependency) => {
|
|
67
|
+
var _a;
|
|
68
|
+
if (((_a = dependency.ids) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
69
|
+
dependency.ids.forEach((id) => {
|
|
70
|
+
const dashedName = this.toDashedComponentName(id);
|
|
71
|
+
if (!component_1.componentConfig.scopedIncludes.has(root)) {
|
|
72
|
+
component_1.componentConfig.scopedIncludes.set(root, new Set());
|
|
73
|
+
}
|
|
74
|
+
component_1.componentConfig.scopedIncludes.get(root).add(dashedName);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
this.miniPlugin.hooks.modifyChunkRequire.tap(PLUGIN_NAME, (result, chunkId, miniType) => {
|
|
80
|
+
if (!this.options.newBlended)
|
|
81
|
+
return result;
|
|
82
|
+
if (this.miniPlugin.nativeComponents.has(chunkId) || miniType === helper_1.META_TYPE.STATIC) {
|
|
83
|
+
const isSubPackageIndie = this.isInSubPackageIndieRoot(chunkId);
|
|
84
|
+
if (isSubPackageIndie) {
|
|
85
|
+
return {
|
|
86
|
+
source: result.source,
|
|
87
|
+
handled: true,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (miniType === helper_1.META_TYPE.PAGE) {
|
|
92
|
+
const subPackageIndieRoot = this.isInSubPackageIndieRoot(chunkId);
|
|
93
|
+
if (subPackageIndieRoot) {
|
|
94
|
+
return {
|
|
95
|
+
source: (0, webpack_1.addRequireToSource)(chunkId, result.source, [{ name: `${subPackageIndieRoot}/app` }]),
|
|
96
|
+
handled: true,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
});
|
|
102
|
+
this.miniPlugin.hooks.modifySkipRootTemplates.tap(PLUGIN_NAME, skip => {
|
|
103
|
+
return skip || (this.hasSubPackageIndieMainPackageRoot() && this.options.newBlended);
|
|
104
|
+
});
|
|
105
|
+
this.miniPlugin.hooks.generateExtraFiles.tap(PLUGIN_NAME, (customWrapperRoots, compilation, compiler) => {
|
|
106
|
+
if (!this.options.newBlended)
|
|
107
|
+
return customWrapperRoots;
|
|
108
|
+
if (!this.getSubPackageIndieConfigs().length)
|
|
109
|
+
return customWrapperRoots;
|
|
110
|
+
const roots = this.generateSubPackageIndieFiles(compilation, compiler, this.options.template, 'base');
|
|
111
|
+
compilation[exports.subPackageIndieCustomWrapperRootsKey] = roots;
|
|
112
|
+
return roots;
|
|
113
|
+
});
|
|
114
|
+
this.miniPlugin.hooks.modifyComponentConfig.tap(PLUGIN_NAME, ({ config, component }, customWrapperRoots) => {
|
|
115
|
+
const indieMatch = this.getSubPackageIndieMatch(component.name);
|
|
116
|
+
if (!indieMatch || component.isNative)
|
|
117
|
+
return;
|
|
118
|
+
const importBaseCompPath = this.getRootRelativePath(component.path, indieMatch.root, this.miniPlugin.getTargetFilePath(MiniPlugin_1.baseCompName, ''));
|
|
119
|
+
const importCustomWrapperPath = this.getRootRelativePath(component.path, indieMatch.root, this.miniPlugin.getTargetFilePath(MiniPlugin_1.customWrapperName, ''));
|
|
120
|
+
config.content.usingComponents = Object.assign({}, config.content.usingComponents);
|
|
121
|
+
const isRootUsingCustomWrapper = customWrapperRoots.has(indieMatch.root);
|
|
122
|
+
const isRootRecursiveDisabled = this.isRecursiveComponentDisabledForRoot(indieMatch.root);
|
|
123
|
+
if (isRootUsingCustomWrapper && !isRootRecursiveDisabled && !config.content.usingComponents[MiniPlugin_1.customWrapperName]) {
|
|
124
|
+
config.content.usingComponents[MiniPlugin_1.customWrapperName] = importCustomWrapperPath;
|
|
125
|
+
}
|
|
126
|
+
if (!this.options.template.isSupportRecursive && !isRootRecursiveDisabled && !config.content.usingComponents[MiniPlugin_1.baseCompName]) {
|
|
127
|
+
config.content.usingComponents[MiniPlugin_1.baseCompName] = importBaseCompPath;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.miniPlugin.hooks.modifyPageConfig.tap(PLUGIN_NAME, (context, page, customWrapperRoots) => {
|
|
131
|
+
const subPackageIndieRoot = this.isInSubPackageIndieRoot(page.name);
|
|
132
|
+
if (!subPackageIndieRoot)
|
|
133
|
+
return context;
|
|
134
|
+
const isPageRecursiveDisabled = this.isRecursiveComponentDisabledForRoot(subPackageIndieRoot);
|
|
135
|
+
const shouldUseCustomWrapper = customWrapperRoots.has(subPackageIndieRoot) && !isPageRecursiveDisabled;
|
|
136
|
+
return Object.assign(Object.assign({}, context), { importBaseTemplatePath: this.getRootRelativePath(page.path, subPackageIndieRoot, this.miniPlugin.getTemplatePath('base')), importBaseCompPath: this.getRootRelativePath(page.path, subPackageIndieRoot, this.miniPlugin.getTargetFilePath(MiniPlugin_1.baseCompName, '')), importCustomWrapperPath: this.getRootRelativePath(page.path, subPackageIndieRoot, this.miniPlugin.getTargetFilePath(MiniPlugin_1.customWrapperName, '')), shouldUseCustomWrapper,
|
|
137
|
+
isPageRecursiveDisabled });
|
|
138
|
+
});
|
|
139
|
+
this.miniPlugin.hooks.afterGenerateFiles.tap(PLUGIN_NAME, (compilation, compiler) => {
|
|
140
|
+
if (this.hasSubPackageIndieMainPackageRoot() && this.options.newBlended) {
|
|
141
|
+
this.generateMainPackageRuntimeFiles(compilation, compiler);
|
|
142
|
+
}
|
|
143
|
+
if (this.getSubPackageIndieConfigs().length) {
|
|
144
|
+
this.cleanSubPackageIndieAppConfig(compilation, compiler);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
this.miniPlugin.hooks.optimizeAssets.tap(PLUGIN_NAME, compilation => {
|
|
148
|
+
if (!this.options.newBlended)
|
|
149
|
+
return;
|
|
150
|
+
const hasSubPackageIndieCustomWrapperRoots = compilation[exports.subPackageIndieCustomWrapperRootsKey] instanceof Set;
|
|
151
|
+
const subPackageIndieCustomWrapperRoots = hasSubPackageIndieCustomWrapperRoots
|
|
152
|
+
? compilation[exports.subPackageIndieCustomWrapperRootsKey]
|
|
153
|
+
: new Set();
|
|
154
|
+
this.getAllIndieRoots().forEach(root => {
|
|
155
|
+
if (this.isRecursiveComponentDisabledForRoot(root)) {
|
|
156
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.baseCompName}.js`];
|
|
157
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.baseCompName}${this.options.fileType.config}`];
|
|
158
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.baseCompName}${this.options.fileType.templ}`];
|
|
159
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.customWrapperName}.js`];
|
|
160
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.customWrapperName}${this.options.fileType.config}`];
|
|
161
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.customWrapperName}${this.options.fileType.templ}`];
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const isRootUsingCustomWrapper = hasSubPackageIndieCustomWrapperRoots
|
|
165
|
+
? subPackageIndieCustomWrapperRoots.has(root)
|
|
166
|
+
: this.isSubPackageIndieRootUsingCustomWrapper(compilation, root, this.getScopedSubPackageIndieComponentConfig(compilation, root).thirdPartyComponents);
|
|
167
|
+
if (isRootUsingCustomWrapper)
|
|
168
|
+
return;
|
|
169
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.customWrapperName}.js`];
|
|
170
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.customWrapperName}${this.options.fileType.config}`];
|
|
171
|
+
delete compilation.assets[`${root}/${MiniPlugin_1.customWrapperName}${this.options.fileType.templ}`];
|
|
172
|
+
});
|
|
173
|
+
if (this.hasSubPackageIndieMainPackageRoot()) {
|
|
174
|
+
const styleExt = this.options.fileType.style;
|
|
175
|
+
const runtimeChunks = ['app', ...this.options.commonChunks];
|
|
176
|
+
runtimeChunks.forEach(chunkName => {
|
|
177
|
+
delete compilation.assets[`${chunkName}.js`];
|
|
178
|
+
delete compilation.assets[`${chunkName}${styleExt}`];
|
|
179
|
+
});
|
|
180
|
+
delete compilation.assets[`app-origin${styleExt}`];
|
|
181
|
+
delete compilation.assets[`${MiniPlugin_1.baseCompName}.js`];
|
|
182
|
+
delete compilation.assets[`${MiniPlugin_1.customWrapperName}.js`];
|
|
183
|
+
delete compilation.assets[`common-templates${this.options.fileType.templ}`];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
this.miniPlugin.hooks.modifyConfig.tap(PLUGIN_NAME, (config, componentName) => {
|
|
187
|
+
const subPackageIndieRoot = this.isInSubPackageIndieRoot(componentName);
|
|
188
|
+
if (subPackageIndieRoot && this.miniPlugin.nativeComponents.has(componentName)) {
|
|
189
|
+
const styleIsolation = this.options.template.isSupportRecursive
|
|
190
|
+
? MiniPlugin_1.STYLE_ISOLATION_APPLY_SHARED
|
|
191
|
+
: MiniPlugin_1.STYLE_ISOLATION_SHARED;
|
|
192
|
+
config.styleIsolation = config.styleIsolation || styleIsolation;
|
|
193
|
+
config.isNewBlended = true;
|
|
194
|
+
}
|
|
195
|
+
return config;
|
|
196
|
+
});
|
|
197
|
+
this.miniPlugin.hooks.modifyShouldProcessStyles.tap(PLUGIN_NAME, shouldProcess => {
|
|
198
|
+
const hasMainPackageRoot = this.hasSubPackageIndieMainPackageRoot() && this.options.newBlended;
|
|
199
|
+
return shouldProcess || hasMainPackageRoot;
|
|
200
|
+
});
|
|
201
|
+
this.miniPlugin.hooks.modifyStyleImport.tap(PLUGIN_NAME, (context, page) => {
|
|
202
|
+
if (!this.options.newBlended)
|
|
203
|
+
return context;
|
|
204
|
+
const indieMatch = this.getSubPackageIndieMatch(page.name);
|
|
205
|
+
if (!indieMatch)
|
|
206
|
+
return context;
|
|
207
|
+
if (this.miniPlugin.nativeComponents.has(page.name)) {
|
|
208
|
+
if (indieMatch.isMainPackageRoot) {
|
|
209
|
+
return Object.assign(Object.assign({}, context), { importStatement: `@import ${JSON.stringify((0, loader_utils_1.urlToRequest)('./app' + this.options.fileType.style))};\n`, shouldSkip: false, isMainPackageRoot: true });
|
|
210
|
+
}
|
|
211
|
+
return Object.assign(Object.assign({}, context), { importStatement: '', shouldSkip: true, isMainPackageRoot: false });
|
|
212
|
+
}
|
|
213
|
+
if (indieMatch.isMainPackageRoot) {
|
|
214
|
+
return Object.assign(Object.assign({}, context), { importStatement: `@import ${JSON.stringify((0, loader_utils_1.urlToRequest)('./app' + this.options.fileType.style))};\n`, shouldSkip: false, isMainPackageRoot: true });
|
|
215
|
+
}
|
|
216
|
+
return context;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
getRootRelativePath(fromPath, root, targetPath) {
|
|
220
|
+
return (0, helper_1.promoteRelativePath)(node_path_1.default.relative(fromPath, node_path_1.default.join(this.options.sourceDir, root, targetPath)));
|
|
221
|
+
}
|
|
222
|
+
normalizeIndieRoot(root) {
|
|
223
|
+
if (root.endsWith('/index')) {
|
|
224
|
+
return node_path_1.default.dirname(root);
|
|
225
|
+
}
|
|
226
|
+
return root;
|
|
227
|
+
}
|
|
228
|
+
parseIndieRootConfig(rootConfig) {
|
|
229
|
+
var _a;
|
|
230
|
+
if (typeof rootConfig === 'string') {
|
|
231
|
+
return { path: this.normalizeIndieRoot(rootConfig), originalPath: rootConfig, disableRecursiveComponent: false };
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
path: this.normalizeIndieRoot(rootConfig.path),
|
|
235
|
+
originalPath: rootConfig.path,
|
|
236
|
+
disableRecursiveComponent: !!rootConfig.disableRecursiveComponent,
|
|
237
|
+
asyncRoot: (_a = rootConfig.asyncSubPackage) === null || _a === void 0 ? void 0 : _a.asyncRoot,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
getSubPackageIndieConfigs() {
|
|
241
|
+
if (this.subPackageIndieConfigsCache)
|
|
242
|
+
return this.subPackageIndieConfigsCache;
|
|
243
|
+
const appConfig = this.miniPlugin.appConfig;
|
|
244
|
+
const subPackageIndie = appConfig === null || appConfig === void 0 ? void 0 : appConfig.subPackageIndie;
|
|
245
|
+
if (!Array.isArray(subPackageIndie)) {
|
|
246
|
+
this.subPackageIndieConfigsCache = [];
|
|
247
|
+
return this.subPackageIndieConfigsCache;
|
|
248
|
+
}
|
|
249
|
+
const appPages = new Set((appConfig === null || appConfig === void 0 ? void 0 : appConfig.pages) || []);
|
|
250
|
+
this.subPackageIndieConfigsCache = subPackageIndie.map(({ mainPackageRoot, subPackageRoots = [] }) => {
|
|
251
|
+
var _a;
|
|
252
|
+
const mainParsed = this.parseIndieRootConfig(mainPackageRoot);
|
|
253
|
+
if (!appPages.has(mainParsed.originalPath) && ((_a = this.options.logger) === null || _a === void 0 ? void 0 : _a.quiet) === false) {
|
|
254
|
+
(0, helper_1.printLog)("warning" /* processTypeEnum.WARNING */, 'subPackageIndie', `mainPackageRoot.path "${mainParsed.originalPath}" 未配置在 app.config 的 pages 中,请补充 pages: [..., "${mainParsed.originalPath}"],否则主包入口页面文件不会生成。`);
|
|
255
|
+
}
|
|
256
|
+
const subParsedList = subPackageRoots.map(root => this.parseIndieRootConfig(root));
|
|
257
|
+
const disableRecursiveComponentRoots = new Set();
|
|
258
|
+
const asyncSubPackageRootMap = new Map();
|
|
259
|
+
if (mainParsed.disableRecursiveComponent) {
|
|
260
|
+
disableRecursiveComponentRoots.add(mainParsed.path);
|
|
261
|
+
}
|
|
262
|
+
if (mainParsed.asyncRoot) {
|
|
263
|
+
asyncSubPackageRootMap.set(mainParsed.path, mainParsed.asyncRoot);
|
|
264
|
+
}
|
|
265
|
+
subParsedList.forEach(sub => {
|
|
266
|
+
if (sub.disableRecursiveComponent) {
|
|
267
|
+
disableRecursiveComponentRoots.add(sub.path);
|
|
268
|
+
}
|
|
269
|
+
if (sub.asyncRoot) {
|
|
270
|
+
asyncSubPackageRootMap.set(sub.path, sub.asyncRoot);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
return {
|
|
274
|
+
mainPackageRoot: mainParsed.path,
|
|
275
|
+
subPackageRoots: Array.from(new Set(subParsedList.map(sub => sub.path))),
|
|
276
|
+
disableRecursiveComponentRoots,
|
|
277
|
+
asyncSubPackageRootMap,
|
|
278
|
+
};
|
|
279
|
+
});
|
|
280
|
+
return this.subPackageIndieConfigsCache;
|
|
281
|
+
}
|
|
282
|
+
getAllIndieRoots() {
|
|
283
|
+
if (!this.allIndieRootsCache) {
|
|
284
|
+
this.allIndieRootsCache = Array.from(new Set(this.getSubPackageIndieConfigs().flatMap(({ mainPackageRoot, subPackageRoots }) => [mainPackageRoot, ...subPackageRoots])));
|
|
285
|
+
}
|
|
286
|
+
return this.allIndieRootsCache;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* 获取所有配置了 asyncSubPackage 的 root -> asyncRoot 映射
|
|
290
|
+
* key: source root 路径, value: asyncRoot 路径
|
|
291
|
+
*/
|
|
292
|
+
getAsyncSubPackageRootMap() {
|
|
293
|
+
const result = new Map();
|
|
294
|
+
for (const config of this.getSubPackageIndieConfigs()) {
|
|
295
|
+
for (const [sourceRoot, asyncRoot] of config.asyncSubPackageRootMap) {
|
|
296
|
+
result.set(sourceRoot, asyncRoot);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* 获取 asyncSubPackage 运行时路径解析锚点。
|
|
303
|
+
* blended 场景下动态组件实际渲染在 mainPackageRoot 页面上下文中,
|
|
304
|
+
* require.async 也应始终基于当前 mainRoot route 计算到 asyncRoot/index 的相对路径。
|
|
305
|
+
* sourceRoot -> asyncRoot 映射仍用于 chunk/style/template 归属;运行时只需要 mainPackageRoot -> asyncRoot。
|
|
306
|
+
*/
|
|
307
|
+
getAsyncSubPackageRuntimeRoots() {
|
|
308
|
+
const result = [];
|
|
309
|
+
const seen = new Set();
|
|
310
|
+
const push = (sourceRoot, asyncRoot) => {
|
|
311
|
+
const key = `${sourceRoot}${asyncRoot}`;
|
|
312
|
+
if (seen.has(key))
|
|
313
|
+
return;
|
|
314
|
+
seen.add(key);
|
|
315
|
+
result.push({ sourceRoot, asyncRoot });
|
|
316
|
+
};
|
|
317
|
+
for (const config of this.getSubPackageIndieConfigs()) {
|
|
318
|
+
const asyncRoots = new Set(config.asyncSubPackageRootMap.values());
|
|
319
|
+
for (const asyncRoot of asyncRoots) {
|
|
320
|
+
push(config.mainPackageRoot, asyncRoot);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
getAllMainPackageRoots() {
|
|
326
|
+
if (!this.allMainPackageRootsCache) {
|
|
327
|
+
this.allMainPackageRootsCache = Array.from(new Set(this.getSubPackageIndieConfigs().map(item => item.mainPackageRoot)));
|
|
328
|
+
}
|
|
329
|
+
return this.allMainPackageRootsCache;
|
|
330
|
+
}
|
|
331
|
+
hasSubPackageIndieMainPackageRoot() {
|
|
332
|
+
return this.getAllMainPackageRoots().length > 0;
|
|
333
|
+
}
|
|
334
|
+
isRecursiveComponentDisabledForRoot(root) {
|
|
335
|
+
return this.getSubPackageIndieConfigs().some(config => config.disableRecursiveComponentRoots.has(root));
|
|
336
|
+
}
|
|
337
|
+
getSubPackageIndieMatch(pageName) {
|
|
338
|
+
if (!this.options.newBlended)
|
|
339
|
+
return null;
|
|
340
|
+
if (this.subPackageIndieMatchCache.has(pageName)) {
|
|
341
|
+
return this.subPackageIndieMatchCache.get(pageName) || null;
|
|
342
|
+
}
|
|
343
|
+
const configs = this.getSubPackageIndieConfigs();
|
|
344
|
+
for (const config of configs) {
|
|
345
|
+
if (pageName.startsWith(config.mainPackageRoot + '/') || pageName === config.mainPackageRoot) {
|
|
346
|
+
const match = {
|
|
347
|
+
config,
|
|
348
|
+
root: config.mainPackageRoot,
|
|
349
|
+
isMainPackageRoot: true,
|
|
350
|
+
};
|
|
351
|
+
this.subPackageIndieMatchCache.set(pageName, match);
|
|
352
|
+
return match;
|
|
353
|
+
}
|
|
354
|
+
for (const root of config.subPackageRoots) {
|
|
355
|
+
if (pageName.startsWith(root + '/') || pageName === root) {
|
|
356
|
+
const match = {
|
|
357
|
+
config,
|
|
358
|
+
root,
|
|
359
|
+
isMainPackageRoot: false,
|
|
360
|
+
};
|
|
361
|
+
this.subPackageIndieMatchCache.set(pageName, match);
|
|
362
|
+
return match;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
this.subPackageIndieMatchCache.set(pageName, null);
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
isInSubPackageIndieRoot(pageName) {
|
|
370
|
+
var _a;
|
|
371
|
+
return ((_a = this.getSubPackageIndieMatch(pageName)) === null || _a === void 0 ? void 0 : _a.root) || null;
|
|
372
|
+
}
|
|
373
|
+
getModuleSourceContent(module) {
|
|
374
|
+
var _a;
|
|
375
|
+
try {
|
|
376
|
+
const source = (_a = module === null || module === void 0 ? void 0 : module.originalSource) === null || _a === void 0 ? void 0 : _a.call(module);
|
|
377
|
+
if (!source || typeof source.source !== 'function')
|
|
378
|
+
return '';
|
|
379
|
+
return String(source.source() || '');
|
|
380
|
+
}
|
|
381
|
+
catch (_err) {
|
|
382
|
+
return '';
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
getModuleResource(module) {
|
|
386
|
+
var _a;
|
|
387
|
+
const resource = (module === null || module === void 0 ? void 0 : module.resource) || ((_a = module === null || module === void 0 ? void 0 : module.rootModule) === null || _a === void 0 ? void 0 : _a.resource);
|
|
388
|
+
return typeof resource === 'string' ? resource : undefined;
|
|
389
|
+
}
|
|
390
|
+
collectFlattenedModules(module, collected, visited = new Set()) {
|
|
391
|
+
if (!module || visited.has(module))
|
|
392
|
+
return;
|
|
393
|
+
visited.add(module);
|
|
394
|
+
collected.add(module);
|
|
395
|
+
const nestedModuleCollections = [module.rootModule, module.modules, module._modules];
|
|
396
|
+
nestedModuleCollections.forEach(item => {
|
|
397
|
+
if (!item)
|
|
398
|
+
return;
|
|
399
|
+
if (item && typeof item[Symbol.iterator] === 'function') {
|
|
400
|
+
for (const nested of item) {
|
|
401
|
+
this.collectFlattenedModules(nested, collected, visited);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
this.collectFlattenedModules(item, collected, visited);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
getCompilationModuleResourceMap(compilation) {
|
|
410
|
+
const moduleMap = new Map();
|
|
411
|
+
for (const module of compilation.modules) {
|
|
412
|
+
const flattenedModules = new Set();
|
|
413
|
+
this.collectFlattenedModules(module, flattenedModules);
|
|
414
|
+
flattenedModules.forEach(flattenedModule => {
|
|
415
|
+
const resource = this.getModuleResource(flattenedModule);
|
|
416
|
+
if (resource) {
|
|
417
|
+
moduleMap.set(resource, flattenedModule);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return moduleMap;
|
|
422
|
+
}
|
|
423
|
+
getChunksBySubPackageIndieRoot(compilation, root) {
|
|
424
|
+
const chunks = new Set();
|
|
425
|
+
this.getSubPackageIndieEntriesByRoot(root).forEach(({ name }) => {
|
|
426
|
+
const entryChunk = Array.from(compilation.chunks).find(chunk => chunk.name === name);
|
|
427
|
+
if (!entryChunk)
|
|
428
|
+
return;
|
|
429
|
+
chunks.add(entryChunk);
|
|
430
|
+
entryChunk.groupsIterable.forEach(group => {
|
|
431
|
+
group.chunks.forEach(chunk => chunks.add(chunk));
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
return chunks;
|
|
435
|
+
}
|
|
436
|
+
getSubPackageIndieModules(compilation, root) {
|
|
437
|
+
const modules = new Set();
|
|
438
|
+
this.getChunksBySubPackageIndieRoot(compilation, root).forEach(chunk => {
|
|
439
|
+
for (const module of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
440
|
+
this.collectFlattenedModules(module, modules);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
return modules;
|
|
444
|
+
}
|
|
445
|
+
normalizeModuleRequestMapKey(resource) {
|
|
446
|
+
if (!resource || typeof resource !== 'string')
|
|
447
|
+
return null;
|
|
448
|
+
const resourceWithoutLoader = resource.split('!').pop();
|
|
449
|
+
if (!resourceWithoutLoader)
|
|
450
|
+
return null;
|
|
451
|
+
const resourcePath = resourceWithoutLoader.split('?')[0];
|
|
452
|
+
if (!resourcePath)
|
|
453
|
+
return null;
|
|
454
|
+
return node_path_1.default.normalize(resourcePath);
|
|
455
|
+
}
|
|
456
|
+
getModuleRequestMapKeys(resource) {
|
|
457
|
+
const keys = new Set();
|
|
458
|
+
if (resource && typeof resource === 'string') {
|
|
459
|
+
keys.add(resource);
|
|
460
|
+
}
|
|
461
|
+
const normalizedResource = this.normalizeModuleRequestMapKey(resource);
|
|
462
|
+
if (normalizedResource) {
|
|
463
|
+
keys.add(normalizedResource);
|
|
464
|
+
}
|
|
465
|
+
return Array.from(keys);
|
|
466
|
+
}
|
|
467
|
+
setResolvedRequestResource(issuer, request, resource) {
|
|
468
|
+
this.getModuleRequestMapKeys(issuer).forEach(key => {
|
|
469
|
+
if (!this.moduleRequestMap.has(key)) {
|
|
470
|
+
this.moduleRequestMap.set(key, new Map());
|
|
471
|
+
}
|
|
472
|
+
this.moduleRequestMap.get(key).set(request, resource);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
getResolvedRequestResource(issuerResource, request) {
|
|
476
|
+
var _a;
|
|
477
|
+
for (const key of this.getModuleRequestMapKeys(issuerResource)) {
|
|
478
|
+
const resolvedResource = (_a = this.moduleRequestMap.get(key)) === null || _a === void 0 ? void 0 : _a.get(request);
|
|
479
|
+
if (resolvedResource)
|
|
480
|
+
return resolvedResource;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
getResolvedModuleByResource(moduleResourceMap, resource) {
|
|
484
|
+
const exactModule = moduleResourceMap.get(resource);
|
|
485
|
+
if (exactModule)
|
|
486
|
+
return exactModule;
|
|
487
|
+
const normalizedResource = this.normalizeModuleRequestMapKey(resource);
|
|
488
|
+
if (!normalizedResource)
|
|
489
|
+
return null;
|
|
490
|
+
const normalizedModule = moduleResourceMap.get(normalizedResource);
|
|
491
|
+
if (normalizedModule)
|
|
492
|
+
return normalizedModule;
|
|
493
|
+
for (const [moduleResource, module] of moduleResourceMap.entries()) {
|
|
494
|
+
if (this.normalizeModuleRequestMapKey(moduleResource) === normalizedResource) {
|
|
495
|
+
return module;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
resolveRequestedModule(moduleResourceMap, issuerModule, request) {
|
|
501
|
+
const issuerResource = this.getModuleResource(issuerModule);
|
|
502
|
+
const resolvedResource = this.getResolvedRequestResource(issuerResource, request);
|
|
503
|
+
if (resolvedResource) {
|
|
504
|
+
const resolvedModule = this.getResolvedModuleByResource(moduleResourceMap, resolvedResource);
|
|
505
|
+
if (resolvedModule)
|
|
506
|
+
return resolvedModule;
|
|
507
|
+
}
|
|
508
|
+
if (issuerResource && /^[.\\/]/.test(request)) {
|
|
509
|
+
const requestPath = node_path_1.default.resolve(node_path_1.default.dirname(issuerResource), request);
|
|
510
|
+
const resolvedPath = (0, helper_1.resolveMainFilePath)(requestPath);
|
|
511
|
+
const requestModule = this.getResolvedModuleByResource(moduleResourceMap, resolvedPath);
|
|
512
|
+
if (requestModule)
|
|
513
|
+
return requestModule;
|
|
514
|
+
}
|
|
515
|
+
for (const module of moduleResourceMap.values()) {
|
|
516
|
+
if (!module)
|
|
517
|
+
continue;
|
|
518
|
+
if (module.rawRequest === request || module.userRequest === request || module.request === request) {
|
|
519
|
+
return module;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
resolveImportBindingToTaroComponentName(moduleResourceMap, issuerModule, binding, propertyName, visited = new Set()) {
|
|
525
|
+
if (!(binding === null || binding === void 0 ? void 0 : binding.source))
|
|
526
|
+
return null;
|
|
527
|
+
if (binding.kind === 'namespace') {
|
|
528
|
+
if (!propertyName)
|
|
529
|
+
return null;
|
|
530
|
+
if (binding.source === helper_1.taroJsComponents) {
|
|
531
|
+
return propertyName;
|
|
532
|
+
}
|
|
533
|
+
const targetModule = this.resolveRequestedModule(moduleResourceMap, issuerModule, binding.source);
|
|
534
|
+
if (!targetModule) {
|
|
535
|
+
if (!/^[.\\/]/.test(binding.source)) {
|
|
536
|
+
return propertyName;
|
|
537
|
+
}
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
return this.resolveModuleExportToTaroComponentName(moduleResourceMap, targetModule, propertyName, visited);
|
|
541
|
+
}
|
|
542
|
+
const importedName = binding.imported || propertyName;
|
|
543
|
+
if (!importedName || importedName === 'default')
|
|
544
|
+
return null;
|
|
545
|
+
if (binding.source === helper_1.taroJsComponents) {
|
|
546
|
+
return importedName;
|
|
547
|
+
}
|
|
548
|
+
const targetModule = this.resolveRequestedModule(moduleResourceMap, issuerModule, binding.source);
|
|
549
|
+
if (!targetModule) {
|
|
550
|
+
if (!/^[.\\/]/.test(binding.source)) {
|
|
551
|
+
return importedName;
|
|
552
|
+
}
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
return this.resolveModuleExportToTaroComponentName(moduleResourceMap, targetModule, importedName, visited);
|
|
556
|
+
}
|
|
557
|
+
resolveModuleExportToTaroComponentName(moduleResourceMap, module, exportName, visited = new Set()) {
|
|
558
|
+
var _a, _b;
|
|
559
|
+
const moduleResource = this.getModuleResource(module);
|
|
560
|
+
if (!moduleResource)
|
|
561
|
+
return null;
|
|
562
|
+
const visitKey = `${moduleResource}::${exportName}`;
|
|
563
|
+
if (visited.has(visitKey))
|
|
564
|
+
return null;
|
|
565
|
+
visited.add(visitKey);
|
|
566
|
+
const exportBinding = (_a = module === null || module === void 0 ? void 0 : module.exportBindings) === null || _a === void 0 ? void 0 : _a[exportName];
|
|
567
|
+
if (exportBinding) {
|
|
568
|
+
if (exportBinding.kind === 'reexport' && exportBinding.source) {
|
|
569
|
+
if (exportBinding.source === helper_1.taroJsComponents) {
|
|
570
|
+
return exportBinding.imported || exportName;
|
|
571
|
+
}
|
|
572
|
+
const targetModule = this.resolveRequestedModule(moduleResourceMap, module, exportBinding.source);
|
|
573
|
+
if (targetModule) {
|
|
574
|
+
const resolvedName = this.resolveModuleExportToTaroComponentName(moduleResourceMap, targetModule, exportBinding.imported || exportName, visited);
|
|
575
|
+
if (resolvedName)
|
|
576
|
+
return resolvedName;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
if (exportBinding.kind === 'local' && exportBinding.local) {
|
|
580
|
+
const importedBinding = (_b = module === null || module === void 0 ? void 0 : module.importedBindings) === null || _b === void 0 ? void 0 : _b[exportBinding.local];
|
|
581
|
+
if (importedBinding) {
|
|
582
|
+
const resolvedName = this.resolveImportBindingToTaroComponentName(moduleResourceMap, module, importedBinding, undefined, visited);
|
|
583
|
+
if (resolvedName)
|
|
584
|
+
return resolvedName;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
for (const source of (module === null || module === void 0 ? void 0 : module.exportAllSources) || []) {
|
|
589
|
+
if (source === helper_1.taroJsComponents) {
|
|
590
|
+
return exportName;
|
|
591
|
+
}
|
|
592
|
+
const targetModule = this.resolveRequestedModule(moduleResourceMap, module, source);
|
|
593
|
+
if (!targetModule)
|
|
594
|
+
continue;
|
|
595
|
+
const resolvedName = this.resolveModuleExportToTaroComponentName(moduleResourceMap, targetModule, exportName, visited);
|
|
596
|
+
if (resolvedName)
|
|
597
|
+
return resolvedName;
|
|
598
|
+
}
|
|
599
|
+
return null;
|
|
600
|
+
}
|
|
601
|
+
resolveUsedComponentRefToTaroComponentName(moduleResourceMap, module, componentRef) {
|
|
602
|
+
var _a, _b;
|
|
603
|
+
if (!componentRef)
|
|
604
|
+
return null;
|
|
605
|
+
if (componentRef.kind === 'identifier') {
|
|
606
|
+
const binding = (_a = module === null || module === void 0 ? void 0 : module.importedBindings) === null || _a === void 0 ? void 0 : _a[componentRef.name];
|
|
607
|
+
if (!binding) {
|
|
608
|
+
return componentRef.name;
|
|
609
|
+
}
|
|
610
|
+
const resolvedName = this.resolveImportBindingToTaroComponentName(moduleResourceMap, module, binding);
|
|
611
|
+
return resolvedName || componentRef.name;
|
|
612
|
+
}
|
|
613
|
+
if (componentRef.kind === 'member') {
|
|
614
|
+
const binding = (_b = module === null || module === void 0 ? void 0 : module.importedBindings) === null || _b === void 0 ? void 0 : _b[componentRef.object];
|
|
615
|
+
if (!binding) {
|
|
616
|
+
return componentRef.property || null;
|
|
617
|
+
}
|
|
618
|
+
const resolvedName = this.resolveImportBindingToTaroComponentName(moduleResourceMap, module, binding, componentRef.property);
|
|
619
|
+
return resolvedName || componentRef.property || null;
|
|
620
|
+
}
|
|
621
|
+
return null;
|
|
622
|
+
}
|
|
623
|
+
shouldSkipSubPackageIndieModule(module, root) {
|
|
624
|
+
const resource = this.getModuleResource(module);
|
|
625
|
+
if (typeof resource !== 'string' || !resource.startsWith(this.options.sourceDir)) {
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
const componentName = this.miniPlugin.getComponentName(resource);
|
|
629
|
+
const targetRoot = this.isInSubPackageIndieRoot(componentName);
|
|
630
|
+
return !!targetRoot && targetRoot !== root;
|
|
631
|
+
}
|
|
632
|
+
collectModuleResolvedComponentIncludes(compilation, root) {
|
|
633
|
+
const includes = new Set();
|
|
634
|
+
const moduleResourceMap = this.getCompilationModuleResourceMap(compilation);
|
|
635
|
+
for (const module of this.getSubPackageIndieModules(compilation, root)) {
|
|
636
|
+
if (this.shouldSkipSubPackageIndieModule(module, root))
|
|
637
|
+
continue;
|
|
638
|
+
for (const elementName of (module === null || module === void 0 ? void 0 : module.elementNameSet) || []) {
|
|
639
|
+
if (!component_1.componentConfig.thirdPartyComponents.has(elementName)) {
|
|
640
|
+
includes.add(elementName);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
for (const binding of Object.values((module === null || module === void 0 ? void 0 : module.importedBindings) || {})) {
|
|
644
|
+
const resolvedComponentName = this.resolveImportBindingToTaroComponentName(moduleResourceMap, module, binding);
|
|
645
|
+
if (!resolvedComponentName)
|
|
646
|
+
continue;
|
|
647
|
+
const dashedName = this.toDashedComponentName(resolvedComponentName);
|
|
648
|
+
if (!component_1.componentConfig.thirdPartyComponents.has(dashedName)) {
|
|
649
|
+
includes.add(dashedName);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
for (const componentRef of (module === null || module === void 0 ? void 0 : module.usedComponentRefs) || []) {
|
|
653
|
+
const resolvedComponentName = this.resolveUsedComponentRefToTaroComponentName(moduleResourceMap, module, componentRef);
|
|
654
|
+
if (!resolvedComponentName)
|
|
655
|
+
continue;
|
|
656
|
+
const dashedName = this.toDashedComponentName(resolvedComponentName);
|
|
657
|
+
if (!component_1.componentConfig.thirdPartyComponents.has(dashedName)) {
|
|
658
|
+
includes.add(dashedName);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return includes;
|
|
663
|
+
}
|
|
664
|
+
expandScopedIncludes(includes) {
|
|
665
|
+
const scopedIncludes = new Set(includes);
|
|
666
|
+
if (scopedIncludes.has('view')) {
|
|
667
|
+
scopedIncludes.add('catch-view');
|
|
668
|
+
scopedIncludes.add('static-view');
|
|
669
|
+
scopedIncludes.add('pure-view');
|
|
670
|
+
scopedIncludes.add('click-view');
|
|
671
|
+
}
|
|
672
|
+
if (scopedIncludes.has('image')) {
|
|
673
|
+
scopedIncludes.add('static-image');
|
|
674
|
+
}
|
|
675
|
+
if (scopedIncludes.has('text')) {
|
|
676
|
+
scopedIncludes.add('static-text');
|
|
677
|
+
}
|
|
678
|
+
return scopedIncludes;
|
|
679
|
+
}
|
|
680
|
+
toDashedComponentName(componentName) {
|
|
681
|
+
return componentName.replace(/[A-Z]/g, (match, offset) => `${offset === 0 ? '' : '-'}${match.toLowerCase()}`);
|
|
682
|
+
}
|
|
683
|
+
collectScopedInnerComponents(compilation, root) {
|
|
684
|
+
const includes = new Set();
|
|
685
|
+
const scopedIncludes = component_1.componentConfig.scopedIncludes.get(root);
|
|
686
|
+
if (scopedIncludes && scopedIncludes.size > 0) {
|
|
687
|
+
scopedIncludes.forEach(name => includes.add(name));
|
|
688
|
+
}
|
|
689
|
+
this.collectModuleResolvedComponentIncludes(compilation, root).forEach(name => includes.add(name));
|
|
690
|
+
const finalIncludes = includes.size > 0
|
|
691
|
+
? includes
|
|
692
|
+
: new Set(component_1.componentConfig.includes);
|
|
693
|
+
return this.expandScopedIncludes(finalIncludes);
|
|
694
|
+
}
|
|
695
|
+
isSubPackageIndieRootUsingCustomWrapperByModules(compilation, root) {
|
|
696
|
+
const moduleResourceMap = this.getCompilationModuleResourceMap(compilation);
|
|
697
|
+
for (const module of this.getSubPackageIndieModules(compilation, root)) {
|
|
698
|
+
if (this.shouldSkipSubPackageIndieModule(module, root))
|
|
699
|
+
continue;
|
|
700
|
+
for (const componentRef of (module === null || module === void 0 ? void 0 : module.usedComponentRefs) || []) {
|
|
701
|
+
const resolvedComponentName = this.resolveUsedComponentRefToTaroComponentName(moduleResourceMap, module, componentRef);
|
|
702
|
+
if (resolvedComponentName === 'CustomWrapper') {
|
|
703
|
+
return true;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
isSubPackageIndieRootUsingCustomWrapper(compilation, root, scopedThirdPartyComponents) {
|
|
710
|
+
if (scopedThirdPartyComponents === null || scopedThirdPartyComponents === void 0 ? void 0 : scopedThirdPartyComponents.has(MiniPlugin_1.customWrapperName)) {
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
let cache = this.rootUsingCustomWrapperByCompilation.get(compilation);
|
|
714
|
+
if (!cache) {
|
|
715
|
+
cache = new Map();
|
|
716
|
+
this.rootUsingCustomWrapperByCompilation.set(compilation, cache);
|
|
717
|
+
}
|
|
718
|
+
if (cache.has(root)) {
|
|
719
|
+
return cache.get(root) || false;
|
|
720
|
+
}
|
|
721
|
+
const usingCustomWrapper = this.isSubPackageIndieRootUsingCustomWrapperByModules(compilation, root);
|
|
722
|
+
cache.set(root, usingCustomWrapper);
|
|
723
|
+
return usingCustomWrapper;
|
|
724
|
+
}
|
|
725
|
+
resolveUsingComponentTarget(filePath, componentPath) {
|
|
726
|
+
if (componentPath.startsWith('plugin://'))
|
|
727
|
+
return null;
|
|
728
|
+
let sourcePath = componentPath;
|
|
729
|
+
if (node_path_1.default.isAbsolute(componentPath)) {
|
|
730
|
+
sourcePath = helper_1.fs.existsSync(componentPath)
|
|
731
|
+
? componentPath
|
|
732
|
+
: node_path_1.default.resolve(this.options.sourceDir, `.${componentPath}`);
|
|
733
|
+
}
|
|
734
|
+
else {
|
|
735
|
+
const isRelativePath = /^[.\\/]/;
|
|
736
|
+
if (!isRelativePath.test(componentPath))
|
|
737
|
+
return null;
|
|
738
|
+
sourcePath = node_path_1.default.resolve(node_path_1.default.dirname(filePath), componentPath);
|
|
739
|
+
}
|
|
740
|
+
const targetPath = (0, helper_1.resolveMainFilePath)(sourcePath);
|
|
741
|
+
const targetName = this.miniPlugin.getComponentName(targetPath);
|
|
742
|
+
return {
|
|
743
|
+
path: targetPath,
|
|
744
|
+
name: targetName,
|
|
745
|
+
root: this.isInSubPackageIndieRoot(targetName),
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
cloneThirdPartyComponent(thirdPartyComponents, componentName) {
|
|
749
|
+
const attrs = component_1.componentConfig.thirdPartyComponents.get(componentName);
|
|
750
|
+
if (!attrs || thirdPartyComponents.has(componentName))
|
|
751
|
+
return;
|
|
752
|
+
thirdPartyComponents.set(componentName, new Set(attrs));
|
|
753
|
+
}
|
|
754
|
+
getSubPackageIndieEntriesByRoot(root) {
|
|
755
|
+
if (!this.entriesByRootCache) {
|
|
756
|
+
const entriesByRoot = new Map();
|
|
757
|
+
[...this.miniPlugin.pages, ...this.miniPlugin.components].forEach(item => {
|
|
758
|
+
const indieRoot = this.isInSubPackageIndieRoot(item.name);
|
|
759
|
+
if (!indieRoot)
|
|
760
|
+
return;
|
|
761
|
+
if (!entriesByRoot.has(indieRoot)) {
|
|
762
|
+
entriesByRoot.set(indieRoot, new Map());
|
|
763
|
+
}
|
|
764
|
+
entriesByRoot.get(indieRoot).set(item.name, item);
|
|
765
|
+
});
|
|
766
|
+
this.entriesByRootCache = new Map();
|
|
767
|
+
entriesByRoot.forEach((entries, indieRoot) => {
|
|
768
|
+
this.entriesByRootCache.set(indieRoot, Array.from(entries.values()));
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
return this.entriesByRootCache.get(root) || [];
|
|
772
|
+
}
|
|
773
|
+
getSubPackageIndieRootEntry(root) {
|
|
774
|
+
const entries = this.getSubPackageIndieEntriesByRoot(root);
|
|
775
|
+
return entries.find(entry => entry.name === `${root}/index`) || entries.find(entry => entry.name === root) || entries[0];
|
|
776
|
+
}
|
|
777
|
+
getSubPackageIndieRootConfigContent(root) {
|
|
778
|
+
var _a;
|
|
779
|
+
if (this.rootConfigContentCache.has(root)) {
|
|
780
|
+
return this.rootConfigContentCache.get(root);
|
|
781
|
+
}
|
|
782
|
+
const entry = this.getSubPackageIndieRootEntry(root);
|
|
783
|
+
const content = entry
|
|
784
|
+
? (_a = this.miniPlugin.filesConfig[this.miniPlugin.getConfigFilePath(entry.name)]) === null || _a === void 0 ? void 0 : _a.content
|
|
785
|
+
: undefined;
|
|
786
|
+
this.rootConfigContentCache.set(root, content);
|
|
787
|
+
return content;
|
|
788
|
+
}
|
|
789
|
+
getSubPackageIndieRootUsingComponents(root) {
|
|
790
|
+
const content = this.getSubPackageIndieRootConfigContent(root);
|
|
791
|
+
return Object.assign({}, content === null || content === void 0 ? void 0 : content.usingComponents);
|
|
792
|
+
}
|
|
793
|
+
getSubPackageIndieRootComponentPlaceholder(root) {
|
|
794
|
+
const content = this.getSubPackageIndieRootConfigContent(root);
|
|
795
|
+
const componentPlaceholder = content === null || content === void 0 ? void 0 : content.componentPlaceholder;
|
|
796
|
+
if (!componentPlaceholder || Object.keys(componentPlaceholder).length === 0)
|
|
797
|
+
return undefined;
|
|
798
|
+
return Object.assign({}, componentPlaceholder);
|
|
799
|
+
}
|
|
800
|
+
isForceCustomWrapperEnabledForRoot(root) {
|
|
801
|
+
var _a;
|
|
802
|
+
if (this.options.template.isSupportRecursive)
|
|
803
|
+
return false;
|
|
804
|
+
if (this.forceCustomWrapperByRootCache.has(root)) {
|
|
805
|
+
return this.forceCustomWrapperByRootCache.get(root) || false;
|
|
806
|
+
}
|
|
807
|
+
const entries = this.getSubPackageIndieEntriesByRoot(root);
|
|
808
|
+
for (const entry of entries) {
|
|
809
|
+
if (entry === null || entry === void 0 ? void 0 : entry.isNative)
|
|
810
|
+
continue;
|
|
811
|
+
const content = (_a = this.miniPlugin.filesConfig[this.miniPlugin.getConfigFilePath(entry.name)]) === null || _a === void 0 ? void 0 : _a.content;
|
|
812
|
+
if (content === null || content === void 0 ? void 0 : content.forceCustomWrapper) {
|
|
813
|
+
this.forceCustomWrapperByRootCache.set(root, true);
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
this.forceCustomWrapperByRootCache.set(root, false);
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
getComponentByName(componentName) {
|
|
821
|
+
if (!this.componentByNameCache) {
|
|
822
|
+
this.componentByNameCache = new Map();
|
|
823
|
+
[...this.miniPlugin.pages, ...this.miniPlugin.components].forEach(item => {
|
|
824
|
+
this.componentByNameCache.set(item.name, item);
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
return this.componentByNameCache.get(componentName);
|
|
828
|
+
}
|
|
829
|
+
getScopedSubPackageIndieComponentConfig(compilation, root) {
|
|
830
|
+
var _a;
|
|
831
|
+
let cache = this.scopedComponentConfigByCompilation.get(compilation);
|
|
832
|
+
if (!cache) {
|
|
833
|
+
cache = new Map();
|
|
834
|
+
this.scopedComponentConfigByCompilation.set(compilation, cache);
|
|
835
|
+
}
|
|
836
|
+
if (cache.has(root)) {
|
|
837
|
+
return cache.get(root);
|
|
838
|
+
}
|
|
839
|
+
const thirdPartyComponents = new Map();
|
|
840
|
+
const queue = [...this.getSubPackageIndieEntriesByRoot(root)];
|
|
841
|
+
const visited = new Set();
|
|
842
|
+
while (queue.length) {
|
|
843
|
+
const current = queue.shift();
|
|
844
|
+
if (!current || visited.has(current.name))
|
|
845
|
+
continue;
|
|
846
|
+
visited.add(current.name);
|
|
847
|
+
const fileConfig = (_a = this.miniPlugin.filesConfig[this.miniPlugin.getConfigFilePath(current.name)]) === null || _a === void 0 ? void 0 : _a.content;
|
|
848
|
+
const usingComponents = fileConfig === null || fileConfig === void 0 ? void 0 : fileConfig.usingComponents;
|
|
849
|
+
if (!usingComponents)
|
|
850
|
+
continue;
|
|
851
|
+
for (const [componentName, componentValue] of Object.entries(usingComponents)) {
|
|
852
|
+
if (componentName === MiniPlugin_1.customWrapperName) {
|
|
853
|
+
this.cloneThirdPartyComponent(thirdPartyComponents, componentName);
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
if (!component_1.componentConfig.thirdPartyComponents.has(componentName))
|
|
857
|
+
continue;
|
|
858
|
+
const componentPath = componentValue instanceof Array ? componentValue[0] : componentValue;
|
|
859
|
+
const target = this.resolveUsingComponentTarget(current.path, componentPath);
|
|
860
|
+
this.cloneThirdPartyComponent(thirdPartyComponents, componentName);
|
|
861
|
+
if (!target)
|
|
862
|
+
continue;
|
|
863
|
+
const targetComponent = this.getComponentByName(target.name);
|
|
864
|
+
if (targetComponent && (!target.root || target.root === root) && !visited.has(targetComponent.name)) {
|
|
865
|
+
queue.push(targetComponent);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
const scopedComponentConfig = {
|
|
870
|
+
includes: this.collectScopedInnerComponents(compilation, root),
|
|
871
|
+
exclude: new Set(component_1.componentConfig.exclude),
|
|
872
|
+
thirdPartyComponents,
|
|
873
|
+
includeAll: false,
|
|
874
|
+
skipRecursiveComponent: false,
|
|
875
|
+
};
|
|
876
|
+
cache.set(root, scopedComponentConfig);
|
|
877
|
+
return scopedComponentConfig;
|
|
878
|
+
}
|
|
879
|
+
generateSubPackageIndieScriptFile(compilation, compiler, filePath, content) {
|
|
880
|
+
const { RawSource } = compiler.webpack.sources;
|
|
881
|
+
compilation.assets[this.miniPlugin.getTargetFilePath(filePath, '.js')] = new RawSource(content);
|
|
882
|
+
}
|
|
883
|
+
createRecursiveComponentWrapperSource(componentName, forceCustomWrapper = false) {
|
|
884
|
+
const args = [];
|
|
885
|
+
if (componentName) {
|
|
886
|
+
args.push(JSON.stringify(componentName));
|
|
887
|
+
}
|
|
888
|
+
else if (forceCustomWrapper) {
|
|
889
|
+
args.push('undefined');
|
|
890
|
+
}
|
|
891
|
+
if (forceCustomWrapper) {
|
|
892
|
+
args.push('true');
|
|
893
|
+
}
|
|
894
|
+
return `const registerRecursiveComponent = globalThis.__taroRegisterRecursiveComponent
|
|
895
|
+
|
|
896
|
+
if (typeof registerRecursiveComponent !== 'function') {
|
|
897
|
+
throw new Error('globalThis.__taroRegisterRecursiveComponent is not a function')
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
registerRecursiveComponent(${args.join(', ')})
|
|
901
|
+
`;
|
|
902
|
+
}
|
|
903
|
+
generateSubPackageIndieFiles(compilation, compiler, template, baseTemplateName) {
|
|
904
|
+
const customWrapperRoots = new Set();
|
|
905
|
+
if (!this.getSubPackageIndieConfigs().length)
|
|
906
|
+
return customWrapperRoots;
|
|
907
|
+
const allIndieRoots = this.getAllIndieRoots();
|
|
908
|
+
allIndieRoots.forEach(root => {
|
|
909
|
+
const scopedComponentConfig = this.getScopedSubPackageIndieComponentConfig(compilation, root);
|
|
910
|
+
const isRecursiveDisabled = this.isRecursiveComponentDisabledForRoot(root);
|
|
911
|
+
if (isRecursiveDisabled) {
|
|
912
|
+
scopedComponentConfig.skipRecursiveComponent = true;
|
|
913
|
+
}
|
|
914
|
+
const forceCustomWrapperForRoot = isRecursiveDisabled
|
|
915
|
+
? false
|
|
916
|
+
: this.isForceCustomWrapperEnabledForRoot(root);
|
|
917
|
+
const isRootUsingCustomWrapper = isRecursiveDisabled
|
|
918
|
+
? false
|
|
919
|
+
: this.isSubPackageIndieRootUsingCustomWrapper(compilation, root, scopedComponentConfig.thirdPartyComponents);
|
|
920
|
+
if (isRootUsingCustomWrapper) {
|
|
921
|
+
customWrapperRoots.add(root);
|
|
922
|
+
if (!scopedComponentConfig.thirdPartyComponents.has(MiniPlugin_1.customWrapperName)) {
|
|
923
|
+
const attrs = component_1.componentConfig.thirdPartyComponents.get(MiniPlugin_1.customWrapperName);
|
|
924
|
+
scopedComponentConfig.thirdPartyComponents.set(MiniPlugin_1.customWrapperName, new Set(attrs || []));
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
this.miniPlugin.generateTemplateFile(compilation, compiler, `${root}/${baseTemplateName}`, template.buildTemplate, scopedComponentConfig);
|
|
928
|
+
this.miniPlugin.generateXSFile(compilation, compiler, `${root}/utils`);
|
|
929
|
+
if (!template.isSupportRecursive && !isRecursiveDisabled) {
|
|
930
|
+
this.generateSubPackageIndieScriptFile(compilation, compiler, `${root}/${MiniPlugin_1.baseCompName}`, this.createRecursiveComponentWrapperSource(undefined, forceCustomWrapperForRoot));
|
|
931
|
+
this.miniPlugin.generateTemplateFile(compilation, compiler, `${root}/${MiniPlugin_1.baseCompName}`, template.buildBaseComponentTemplate, this.options.fileType.templ);
|
|
932
|
+
const compConfig = {
|
|
933
|
+
component: true,
|
|
934
|
+
styleIsolation: MiniPlugin_1.STYLE_ISOLATION_APPLY_SHARED,
|
|
935
|
+
usingComponents: {
|
|
936
|
+
[MiniPlugin_1.baseCompName]: `./${MiniPlugin_1.baseCompName}`,
|
|
937
|
+
},
|
|
938
|
+
};
|
|
939
|
+
if (isRootUsingCustomWrapper) {
|
|
940
|
+
compConfig.usingComponents[MiniPlugin_1.customWrapperName] = `./${MiniPlugin_1.customWrapperName}`;
|
|
941
|
+
}
|
|
942
|
+
this.miniPlugin.generateConfigFile(compilation, compiler, `${root}/${MiniPlugin_1.baseCompName}`, compConfig);
|
|
943
|
+
}
|
|
944
|
+
if (isRootUsingCustomWrapper) {
|
|
945
|
+
this.generateSubPackageIndieScriptFile(compilation, compiler, `${root}/${MiniPlugin_1.customWrapperName}`, this.createRecursiveComponentWrapperSource(MiniPlugin_1.customWrapperName, forceCustomWrapperForRoot));
|
|
946
|
+
this.miniPlugin.generateTemplateFile(compilation, compiler, `${root}/${MiniPlugin_1.customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
947
|
+
const customWrapperConfig = {
|
|
948
|
+
component: true,
|
|
949
|
+
styleIsolation: MiniPlugin_1.STYLE_ISOLATION_APPLY_SHARED,
|
|
950
|
+
usingComponents: Object.assign(Object.assign({}, this.getSubPackageIndieRootUsingComponents(root)), { [MiniPlugin_1.baseCompName]: `./${MiniPlugin_1.baseCompName}`, [MiniPlugin_1.customWrapperName]: `./${MiniPlugin_1.customWrapperName}` }),
|
|
951
|
+
};
|
|
952
|
+
const componentPlaceholder = this.getSubPackageIndieRootComponentPlaceholder(root);
|
|
953
|
+
if (componentPlaceholder) {
|
|
954
|
+
customWrapperConfig.componentPlaceholder = componentPlaceholder;
|
|
955
|
+
}
|
|
956
|
+
this.miniPlugin.generateConfigFile(compilation, compiler, `${root}/${MiniPlugin_1.customWrapperName}`, customWrapperConfig);
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
return customWrapperRoots;
|
|
960
|
+
}
|
|
961
|
+
cleanSubPackageIndieAppConfig(compilation, compiler) {
|
|
962
|
+
var _a;
|
|
963
|
+
const { RawSource } = compiler.webpack.sources;
|
|
964
|
+
const appCfgPath = this.miniPlugin.getConfigFilePath(this.miniPlugin.appEntry);
|
|
965
|
+
const appCfgName = node_path_1.default.basename(appCfgPath).replace(node_path_1.default.extname(appCfgPath), '');
|
|
966
|
+
const fc = (_a = this.miniPlugin.filesConfig) === null || _a === void 0 ? void 0 : _a[appCfgName];
|
|
967
|
+
if (!(fc === null || fc === void 0 ? void 0 : fc.content))
|
|
968
|
+
return;
|
|
969
|
+
delete fc.content.subPackageIndie;
|
|
970
|
+
compilation.assets[this.miniPlugin.getConfigPath(appCfgName)] = new RawSource(JSON.stringify(fc.content, null, 2));
|
|
971
|
+
}
|
|
972
|
+
generateMainPackageRuntimeFiles(compilation, compiler) {
|
|
973
|
+
var _a, _b;
|
|
974
|
+
const { commonChunks, fileType } = this.options;
|
|
975
|
+
const mainPackageRoots = this.getAllMainPackageRoots();
|
|
976
|
+
if (!mainPackageRoots.length)
|
|
977
|
+
return;
|
|
978
|
+
const styleExt = fileType.style;
|
|
979
|
+
const templateExt = fileType.templ;
|
|
980
|
+
const runtimeChunks = ['app', ...commonChunks];
|
|
981
|
+
const commonTemplates = `common-templates${templateExt}`;
|
|
982
|
+
const appJsContent = compilation.assets['app.js'];
|
|
983
|
+
let patchedAppJsContent = appJsContent;
|
|
984
|
+
if (appJsContent) {
|
|
985
|
+
const { RawSource } = compiler.webpack.sources;
|
|
986
|
+
const originalSource = String(((_b = (_a = appJsContent).source) === null || _b === void 0 ? void 0 : _b.call(_a)) || String(appJsContent));
|
|
987
|
+
const registrarExpr = `(typeof globalThis.__taroRegisterRecursiveComponent==="function"||(globalThis.__taroRegisterRecursiveComponent=function(componentName,forceCustomWrapper){const cache=__webpack_require__.c||{};let createRecursiveComponentConfig;for(const key in cache){const exports=cache[key]&&cache[key].exports;if(exports&&typeof exports.createRecursiveComponentConfig==="function"){createRecursiveComponentConfig=exports.createRecursiveComponentConfig;break;}}if(typeof createRecursiveComponentConfig!=="function"){const modules=__webpack_require__.m||{};for(const moduleId in modules){const moduleFactory=modules[moduleId];if(!moduleFactory||typeof moduleFactory!=="function")continue;const source=String(moduleFactory);if(source.indexOf("createRecursiveComponentConfig")===-1)continue;const exports=__webpack_require__(moduleId);if(exports&&typeof exports.createRecursiveComponentConfig==="function"){createRecursiveComponentConfig=exports.createRecursiveComponentConfig;break;}}}if(typeof createRecursiveComponentConfig!=="function"){throw new Error("Cannot find createRecursiveComponentConfig in webpack modules");}Component(createRecursiveComponentConfig(componentName,forceCustomWrapper));}))`;
|
|
988
|
+
let patchedSource = originalSource;
|
|
989
|
+
if (/,\s*exports\.taroApp\s*=/.test(patchedSource)) {
|
|
990
|
+
patchedSource = patchedSource.replace(/,\s*exports\.taroApp\s*=/, `,${registrarExpr},exports.taroApp=`);
|
|
991
|
+
}
|
|
992
|
+
else {
|
|
993
|
+
patchedSource = patchedSource.replace(/exports\.taroApp\s*=/, `;${registrarExpr};exports.taroApp=`);
|
|
994
|
+
}
|
|
995
|
+
patchedAppJsContent = new RawSource(patchedSource);
|
|
996
|
+
}
|
|
997
|
+
mainPackageRoots.forEach(mainPackageRoot => {
|
|
998
|
+
runtimeChunks.forEach(chunkName => {
|
|
999
|
+
const jsFile = `${chunkName}.js`;
|
|
1000
|
+
if (compilation.assets[jsFile]) {
|
|
1001
|
+
const jsContent = chunkName === 'app'
|
|
1002
|
+
? patchedAppJsContent
|
|
1003
|
+
: compilation.assets[jsFile];
|
|
1004
|
+
compilation.assets[`${mainPackageRoot}/${jsFile}`] = jsContent;
|
|
1005
|
+
}
|
|
1006
|
+
const cssFile = `${chunkName}${styleExt}`;
|
|
1007
|
+
if (compilation.assets[cssFile]) {
|
|
1008
|
+
compilation.assets[`${mainPackageRoot}/${cssFile}`] = compilation.assets[cssFile];
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
const appOriginCss = `app-origin${styleExt}`;
|
|
1012
|
+
if (compilation.assets[appOriginCss]) {
|
|
1013
|
+
compilation.assets[`${mainPackageRoot}/${appOriginCss}`] = compilation.assets[appOriginCss];
|
|
1014
|
+
}
|
|
1015
|
+
if (compilation.assets[commonTemplates]) {
|
|
1016
|
+
compilation.assets[`${mainPackageRoot}/${commonTemplates}`] = compilation.assets[commonTemplates];
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
exports.default = SubPackageIndiePlugin;
|
|
1022
|
+
//# sourceMappingURL=SubPackageIndiePlugin.js.map
|