@doubao-dev/taro-plugin-platform-doubao 0.10.3 → 0.11.0-rc.10
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/README.md +57 -152
- package/dist/compiler.d.ts +23 -13
- package/dist/compiler.js +44 -45
- package/dist/emit/index.d.ts +11 -0
- package/dist/emit/index.js +63 -0
- package/dist/index.js +8 -16
- package/dist/plans/host-deps.d.ts +45 -0
- package/dist/plans/host-deps.js +246 -0
- package/dist/plans/project-files.d.ts +8 -0
- package/dist/plans/project-files.js +309 -0
- package/dist/plans/pxtransform.d.ts +6 -0
- package/dist/{pxtransform.js → plans/pxtransform.js} +14 -17
- package/dist/plans/scaffold.d.ts +10 -0
- package/dist/plans/scaffold.js +114 -0
- package/dist/plans/sources/class-components.d.ts +11 -0
- package/dist/{class-components.js → plans/sources/class-components.js} +171 -59
- package/dist/plans/sources/dead-branches.d.ts +36 -0
- package/dist/plans/sources/dead-branches.js +415 -0
- package/dist/plans/sources/index.d.ts +36 -0
- package/dist/plans/sources/index.js +57 -0
- package/dist/plans/sources/styles.d.ts +7 -0
- package/dist/plans/sources/styles.js +111 -0
- package/dist/plans/sources/transform.d.ts +9 -0
- package/dist/plans/sources/transform.js +396 -0
- package/dist/plans/sources/vendor/bundle.d.ts +23 -0
- package/dist/plans/sources/vendor/bundle.js +221 -0
- package/dist/plans/sources/vendor/class-loader.d.ts +9 -0
- package/dist/plans/sources/vendor/class-loader.js +41 -0
- package/dist/plans/sources/vendor/index.d.ts +34 -0
- package/dist/plans/sources/vendor/index.js +62 -0
- package/dist/plans/sources/vendor/manifest.d.ts +43 -0
- package/dist/plans/sources/vendor/manifest.js +182 -0
- package/dist/plans/sources/vendor/output.d.ts +4 -0
- package/dist/plans/sources/vendor/output.js +68 -0
- package/dist/project/app.d.ts +3 -0
- package/dist/project/app.js +160 -0
- package/dist/project/defines.d.ts +3 -0
- package/dist/project/defines.js +89 -0
- package/dist/project/imports.d.ts +95 -0
- package/dist/project/imports.js +122 -0
- package/dist/project/index.d.ts +82 -0
- package/dist/project/index.js +182 -0
- package/dist/project/program.d.ts +15 -0
- package/dist/project/program.js +60 -0
- package/dist/project/resolver.d.ts +24 -0
- package/dist/project/resolver.js +96 -0
- package/dist/runner.d.ts +3 -2
- package/dist/runner.js +6 -4
- package/dist/shared/errors.d.ts +6 -0
- package/dist/shared/errors.js +16 -0
- package/dist/shared/layout.d.ts +32 -0
- package/dist/shared/layout.js +85 -0
- package/dist/shared/paths.d.ts +16 -0
- package/dist/shared/paths.js +83 -0
- package/dist/shared/syntax.d.ts +31 -0
- package/dist/shared/syntax.js +276 -0
- package/dist/verify.d.ts +4 -0
- package/dist/verify.js +35 -0
- package/package.json +3 -1
- package/dist/class-components.d.ts +0 -6
- package/dist/config.d.ts +0 -8
- package/dist/config.js +0 -274
- package/dist/file-system.d.ts +0 -21
- package/dist/file-system.js +0 -42
- package/dist/files.d.ts +0 -24
- package/dist/files.js +0 -256
- package/dist/platform-branches.d.ts +0 -4
- package/dist/platform-branches.js +0 -122
- package/dist/project-files.d.ts +0 -7
- package/dist/project-files.js +0 -129
- package/dist/project.d.ts +0 -48
- package/dist/project.js +0 -314
- package/dist/pxtransform.d.ts +0 -17
- package/dist/scaffold.d.ts +0 -15
- package/dist/scaffold.js +0 -103
- package/dist/transform.d.ts +0 -11
- package/dist/transform.js +0 -318
- package/dist/validate.d.ts +0 -4
- package/dist/validate.js +0 -27
- package/templates/taro.defines.ts +0 -2
|
@@ -0,0 +1,396 @@
|
|
|
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.discoverSources = discoverSources;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
+
const imports_1 = require("../../project/imports");
|
|
11
|
+
const errors_1 = require("../../shared/errors");
|
|
12
|
+
const layout_1 = require("../../shared/layout");
|
|
13
|
+
const paths_1 = require("../../shared/paths");
|
|
14
|
+
const syntax_1 = require("../../shared/syntax");
|
|
15
|
+
const pxtransform_1 = require("../pxtransform");
|
|
16
|
+
const class_components_1 = require("./class-components");
|
|
17
|
+
const dead_branches_1 = require("./dead-branches");
|
|
18
|
+
const styles_1 = require("./styles");
|
|
19
|
+
const manifest_1 = require("./vendor/manifest");
|
|
20
|
+
function rewriteQualifiedRoot(source, fromName, toName) {
|
|
21
|
+
const replaceLeftmost = (entity) => typescript_1.default.isIdentifier(entity)
|
|
22
|
+
? entity.text === fromName
|
|
23
|
+
? typescript_1.default.factory.createIdentifier(toName)
|
|
24
|
+
: entity
|
|
25
|
+
: typescript_1.default.factory.updateQualifiedName(entity, replaceLeftmost(entity.left), entity.right);
|
|
26
|
+
const result = typescript_1.default.transform(source, [
|
|
27
|
+
(context) => {
|
|
28
|
+
const visit = (node) => {
|
|
29
|
+
if (typescript_1.default.isTypeQueryNode(node)) {
|
|
30
|
+
return node;
|
|
31
|
+
}
|
|
32
|
+
if (typescript_1.default.isQualifiedName(node)) {
|
|
33
|
+
return typescript_1.default.factory.updateQualifiedName(node, replaceLeftmost(node.left), typescript_1.default.visitNode(node.right, visit));
|
|
34
|
+
}
|
|
35
|
+
return typescript_1.default.visitEachChild(node, visit, context);
|
|
36
|
+
};
|
|
37
|
+
return (node) => typescript_1.default.visitNode(node, visit);
|
|
38
|
+
}
|
|
39
|
+
]);
|
|
40
|
+
const transformed = result.transformed[0];
|
|
41
|
+
result.dispose();
|
|
42
|
+
return transformed;
|
|
43
|
+
}
|
|
44
|
+
function allocateAlias(source, base, used) {
|
|
45
|
+
let candidate = base;
|
|
46
|
+
while (source.text.includes(candidate) || used.has(candidate)) {
|
|
47
|
+
candidate += '_';
|
|
48
|
+
}
|
|
49
|
+
used.add(candidate);
|
|
50
|
+
return candidate;
|
|
51
|
+
}
|
|
52
|
+
function normalizeReactImports(source, valueIdentifiers, qualifiedTypeRoots) {
|
|
53
|
+
if (paths_1.declarationPattern.test(source.fileName)) {
|
|
54
|
+
return source;
|
|
55
|
+
}
|
|
56
|
+
const emitTypeOnly = paths_1.typeScriptPattern.test(source.fileName);
|
|
57
|
+
const renames = [];
|
|
58
|
+
const usedAliases = new Set();
|
|
59
|
+
const updated = typescript_1.default.factory.updateSourceFile(source, source.statements.flatMap((node) => {
|
|
60
|
+
if (!typescript_1.default.isImportDeclaration(node) || !typescript_1.default.isStringLiteral(node.moduleSpecifier) || !node.importClause) {
|
|
61
|
+
return [node];
|
|
62
|
+
}
|
|
63
|
+
const specifier = node.moduleSpecifier.text;
|
|
64
|
+
const clause = node.importClause;
|
|
65
|
+
const namespaceBinding = clause.namedBindings && typescript_1.default.isNamespaceImport(clause.namedBindings)
|
|
66
|
+
? clause.namedBindings.name
|
|
67
|
+
: undefined;
|
|
68
|
+
if (specifier === '@tarojs/taro') {
|
|
69
|
+
const taroIdentifier = clause.name ?? namespaceBinding;
|
|
70
|
+
if (!emitTypeOnly ||
|
|
71
|
+
!taroIdentifier ||
|
|
72
|
+
clause.isTypeOnly ||
|
|
73
|
+
!valueIdentifiers.has(taroIdentifier.text) ||
|
|
74
|
+
!qualifiedTypeRoots.has(taroIdentifier.text)) {
|
|
75
|
+
return [node];
|
|
76
|
+
}
|
|
77
|
+
const typeAlias = allocateAlias(source, '__TaroTypes', usedAliases);
|
|
78
|
+
renames.push([taroIdentifier.text, typeAlias]);
|
|
79
|
+
return [
|
|
80
|
+
typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(true, typescript_1.default.factory.createIdentifier(typeAlias), undefined), typescript_1.default.factory.createStringLiteral('@tarojs/taro')),
|
|
81
|
+
node
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
if (specifier !== 'react' && specifier !== 'react-dom') {
|
|
85
|
+
return [node];
|
|
86
|
+
}
|
|
87
|
+
const reactIdentifier = clause.name ?? namespaceBinding;
|
|
88
|
+
if (!reactIdentifier) {
|
|
89
|
+
return [node];
|
|
90
|
+
}
|
|
91
|
+
const hasValueUsage = !clause.isTypeOnly && valueIdentifiers.has(reactIdentifier.text);
|
|
92
|
+
const hasQualifiedTypeUsage = emitTypeOnly && qualifiedTypeRoots.has(reactIdentifier.text);
|
|
93
|
+
const statements = [];
|
|
94
|
+
if (!hasValueUsage) {
|
|
95
|
+
if (emitTypeOnly) {
|
|
96
|
+
statements.push(typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(true, undefined, typescript_1.default.factory.createNamespaceImport(reactIdentifier)), typescript_1.default.factory.createStringLiteral(specifier)));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
if (hasQualifiedTypeUsage) {
|
|
101
|
+
const typeAlias = allocateAlias(source, '__ReactTypes', usedAliases);
|
|
102
|
+
renames.push([reactIdentifier.text, typeAlias]);
|
|
103
|
+
statements.push(typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(true, undefined, typescript_1.default.factory.createNamespaceImport(typescript_1.default.factory.createIdentifier(typeAlias))), typescript_1.default.factory.createStringLiteral(specifier)));
|
|
104
|
+
}
|
|
105
|
+
statements.push(typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(false, undefined, typescript_1.default.factory.createNamespaceImport(reactIdentifier)), typescript_1.default.factory.createStringLiteral(specifier)));
|
|
106
|
+
}
|
|
107
|
+
if (clause.namedBindings && typescript_1.default.isNamedImports(clause.namedBindings)) {
|
|
108
|
+
statements.push(typescript_1.default.factory.updateImportDeclaration(node, node.modifiers, typescript_1.default.factory.updateImportClause(clause, clause.isTypeOnly, undefined, clause.namedBindings), node.moduleSpecifier, node.attributes));
|
|
109
|
+
}
|
|
110
|
+
return statements;
|
|
111
|
+
}));
|
|
112
|
+
return renames.reduce((current, [fromName, toName]) => rewriteQualifiedRoot(current, fromName, toName), updated);
|
|
113
|
+
}
|
|
114
|
+
/** Moves type-only bindings of `split` modules into `import type`, so values and types can be rewritten apart. */
|
|
115
|
+
function splitTypeReferences(source, valueIdentifiers, split) {
|
|
116
|
+
if (paths_1.declarationPattern.test(source.fileName)) {
|
|
117
|
+
return source;
|
|
118
|
+
}
|
|
119
|
+
const emitTypeOnly = paths_1.typeScriptPattern.test(source.fileName);
|
|
120
|
+
return typescript_1.default.factory.updateSourceFile(source, source.statements.flatMap((node) => {
|
|
121
|
+
if (typescript_1.default.isExportDeclaration(node) &&
|
|
122
|
+
node.moduleSpecifier &&
|
|
123
|
+
typescript_1.default.isStringLiteral(node.moduleSpecifier) &&
|
|
124
|
+
split(node.moduleSpecifier.text) &&
|
|
125
|
+
!node.isTypeOnly &&
|
|
126
|
+
node.exportClause &&
|
|
127
|
+
typescript_1.default.isNamedExports(node.exportClause)) {
|
|
128
|
+
const types = node.exportClause.elements.filter((element) => element.isTypeOnly);
|
|
129
|
+
const values = node.exportClause.elements.filter((element) => !element.isTypeOnly);
|
|
130
|
+
if (!types.length) {
|
|
131
|
+
return [node];
|
|
132
|
+
}
|
|
133
|
+
const emitted = [];
|
|
134
|
+
if (emitTypeOnly) {
|
|
135
|
+
emitted.push(typescript_1.default.factory.updateExportDeclaration(node, node.modifiers, true, typescript_1.default.factory.createNamedExports(types.map((element) => typescript_1.default.factory.updateExportSpecifier(element, false, element.propertyName, element.name))), node.moduleSpecifier, node.attributes));
|
|
136
|
+
}
|
|
137
|
+
if (values.length) {
|
|
138
|
+
emitted.push(typescript_1.default.factory.updateExportDeclaration(node, node.modifiers, false, typescript_1.default.factory.createNamedExports(values), node.moduleSpecifier, node.attributes));
|
|
139
|
+
}
|
|
140
|
+
return emitted;
|
|
141
|
+
}
|
|
142
|
+
const clause = typescript_1.default.isImportDeclaration(node) ? node.importClause : undefined;
|
|
143
|
+
if (!typescript_1.default.isImportDeclaration(node) ||
|
|
144
|
+
!typescript_1.default.isStringLiteral(node.moduleSpecifier) ||
|
|
145
|
+
!split(node.moduleSpecifier.text) ||
|
|
146
|
+
!clause ||
|
|
147
|
+
clause.isTypeOnly) {
|
|
148
|
+
return [node];
|
|
149
|
+
}
|
|
150
|
+
const namedElements = clause.namedBindings && typescript_1.default.isNamedImports(clause.namedBindings) ? clause.namedBindings.elements : [];
|
|
151
|
+
const types = namedElements.filter((element) => element.isTypeOnly || !valueIdentifiers.has(element.name.text));
|
|
152
|
+
const values = namedElements.filter((element) => !element.isTypeOnly && valueIdentifiers.has(element.name.text));
|
|
153
|
+
const defaultIsType = Boolean(clause.name && !valueIdentifiers.has(clause.name.text));
|
|
154
|
+
const namespaceIsType = Boolean(clause.namedBindings &&
|
|
155
|
+
typescript_1.default.isNamespaceImport(clause.namedBindings) &&
|
|
156
|
+
!valueIdentifiers.has(clause.namedBindings.name.text));
|
|
157
|
+
if (!types.length && !defaultIsType && !namespaceIsType) {
|
|
158
|
+
return [node];
|
|
159
|
+
}
|
|
160
|
+
const emitted = [];
|
|
161
|
+
if (emitTypeOnly &&
|
|
162
|
+
namespaceIsType &&
|
|
163
|
+
clause.namedBindings &&
|
|
164
|
+
typescript_1.default.isNamespaceImport(clause.namedBindings)) {
|
|
165
|
+
emitted.push(typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(true, undefined, clause.namedBindings), typescript_1.default.factory.createStringLiteral(node.moduleSpecifier.text)));
|
|
166
|
+
}
|
|
167
|
+
if (emitTypeOnly && defaultIsType && clause.name) {
|
|
168
|
+
emitted.push(typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(true, clause.name, undefined), typescript_1.default.factory.createStringLiteral(node.moduleSpecifier.text)));
|
|
169
|
+
}
|
|
170
|
+
if (emitTypeOnly && types.length) {
|
|
171
|
+
emitted.push(typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(true, undefined, typescript_1.default.factory.createNamedImports(types.map((element) => typescript_1.default.factory.createImportSpecifier(false, element.propertyName, element.name)))), typescript_1.default.factory.createStringLiteral(node.moduleSpecifier.text)));
|
|
172
|
+
}
|
|
173
|
+
const remainingDefault = defaultIsType ? undefined : clause.name;
|
|
174
|
+
const remainingNamespace = !namespaceIsType && clause.namedBindings && typescript_1.default.isNamespaceImport(clause.namedBindings)
|
|
175
|
+
? clause.namedBindings
|
|
176
|
+
: undefined;
|
|
177
|
+
const remainingBindings = remainingNamespace ?? (values.length ? typescript_1.default.factory.createNamedImports(values) : undefined);
|
|
178
|
+
if (remainingDefault || remainingBindings) {
|
|
179
|
+
emitted.push(typescript_1.default.factory.updateImportDeclaration(node, node.modifiers, typescript_1.default.factory.updateImportClause(clause, false, remainingDefault, remainingBindings), node.moduleSpecifier, node.attributes));
|
|
180
|
+
}
|
|
181
|
+
return emitted;
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Discovers the application sources, styles and static assets reachable from the pages (and `app.doubao.*`)
|
|
186
|
+
* using the 3-stage `ts.Program + TypeChecker` pipeline, without writing anything to disk.
|
|
187
|
+
*/
|
|
188
|
+
function discoverSources(ctx, model) {
|
|
189
|
+
const { options, layout, appFile, appDoubaoFile, pages, pageFiles, styles, ambientDeclarations, compiledDefines, resolveLocal, imports, program } = model;
|
|
190
|
+
const { appPath, sourcePath } = ctx.paths;
|
|
191
|
+
const { targetSource } = layout;
|
|
192
|
+
for (const [name, purpose] of layout_1.reservedDirectories) {
|
|
193
|
+
if (node_fs_1.default.existsSync(node_path_1.default.join(sourcePath, name))) {
|
|
194
|
+
(0, errors_1.fail)(`${name} is reserved for ${purpose}: ${sourcePath}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const allSourceTreeFiles = (0, paths_1.walk)(sourcePath);
|
|
198
|
+
const collected = new Set();
|
|
199
|
+
const collectedAmbient = new Set();
|
|
200
|
+
const files = new Map();
|
|
201
|
+
const copies = new Map();
|
|
202
|
+
const relativeOutput = (outputFile) => node_path_1.default.relative(targetSource, outputFile);
|
|
203
|
+
const vendor = new manifest_1.VendorManifest();
|
|
204
|
+
const externalAssets = new Set();
|
|
205
|
+
const inlinedIdentifierKeys = new Set(compiledDefines.identifiers.keys());
|
|
206
|
+
// Every exported page runs in its own isolated Lynx View context and needs `pxTransform` setup.
|
|
207
|
+
const setupFile = node_path_1.default.join(targetSource, layout_1.setupDirectory, 'setup.ts');
|
|
208
|
+
files.set(relativeOutput(setupFile), (0, pxtransform_1.renderPxTransformSetup)(ctx, options));
|
|
209
|
+
// Kit owns the canonical .tsx entry. Keep an ordinary page imported by a platform wrapper elsewhere.
|
|
210
|
+
const relocatedFiles = new Map();
|
|
211
|
+
pageFiles.forEach((file, index) => {
|
|
212
|
+
const canonical = node_path_1.default.join(sourcePath, `${pages[index]}.tsx`);
|
|
213
|
+
if (file !== canonical) {
|
|
214
|
+
const ordinary = resolveLocal(file, node_path_1.default.join(sourcePath, pages[index]));
|
|
215
|
+
for (const filename of new Set([ordinary, canonical])) {
|
|
216
|
+
if (filename && node_fs_1.default.existsSync(filename)) {
|
|
217
|
+
relocatedFiles.set(filename, node_path_1.default.join(targetSource, layout_1.setupDirectory, node_path_1.default.relative(sourcePath, filename)));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
const canonicalAppEntry = node_path_1.default.join(targetSource, 'app.ts');
|
|
223
|
+
if (appDoubaoFile) {
|
|
224
|
+
relocatedFiles.set(appDoubaoFile, node_path_1.default.extname(appDoubaoFile) === '.ts'
|
|
225
|
+
? canonicalAppEntry
|
|
226
|
+
: node_path_1.default.join(targetSource, layout_1.setupDirectory, node_path_1.default.relative(sourcePath, appDoubaoFile)));
|
|
227
|
+
}
|
|
228
|
+
// In module mode, `routes.ts` at the module root is reserved for the exported route manifest.
|
|
229
|
+
if (layout.moduleName) {
|
|
230
|
+
for (const ext of ['.ts', '.tsx', '.js', '.jsx', '.mts', '.cts']) {
|
|
231
|
+
const routesCandidate = node_path_1.default.join(sourcePath, `routes${ext}`);
|
|
232
|
+
if (node_fs_1.default.existsSync(routesCandidate)) {
|
|
233
|
+
relocatedFiles.set(routesCandidate, node_path_1.default.join(targetSource, layout_1.setupDirectory, `routes${ext}`));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function rewriteScriptFile(filename, outputFile) {
|
|
238
|
+
const parsed = program.getSourceFile(filename);
|
|
239
|
+
const isDeclaration = paths_1.declarationPattern.test(filename);
|
|
240
|
+
let normalized;
|
|
241
|
+
if (isDeclaration) {
|
|
242
|
+
normalized = (0, syntax_1.sanitizeAmbientDeclaration)(parsed, inlinedIdentifierKeys);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
// Stage 1 (Read-Only on original Program-bound AST): evaluate defines & mark dead branches.
|
|
246
|
+
const branchAnalysis = (0, dead_branches_1.analyzeSourceBranches)(parsed, compiledDefines, program.checker);
|
|
247
|
+
// Stage 2 (Read-Only on original Program-bound AST): collect live symbols & cross-file React classes.
|
|
248
|
+
const symbolUsage = (0, syntax_1.collectLiveSymbolUsage)(parsed, program.checker, branchAnalysis.deadNodes);
|
|
249
|
+
const reactClassRanges = (0, class_components_1.detectReactClassRanges)(parsed, program.checker, branchAnalysis.deadNodes);
|
|
250
|
+
// Stage 3 (Transform): inline defines, prune dead branches & dead imports, wrap classes & normalize.
|
|
251
|
+
const pruned = (0, dead_branches_1.applyDefinesAndPruneBranches)(parsed, branchAnalysis, symbolUsage.liveReferencedNames);
|
|
252
|
+
const classWrapped = (0, class_components_1.wrapClassRenders)(pruned, undefined, undefined, reactClassRanges);
|
|
253
|
+
normalized = splitTypeReferences(normalizeReactImports(classWrapped, symbolUsage.valueImportNames, symbolUsage.qualifiedTypeRoots), symbolUsage.valueImportNames, (specifier) => (0, imports_1.isTypeOnlyModule)(specifier) || imports.probe(specifier, filename).kind === 'vendor');
|
|
254
|
+
}
|
|
255
|
+
const namespaces = (0, manifest_1.collectNamespaceUsage)(normalized, (specifier) => imports.probe(specifier, filename).kind === 'vendor');
|
|
256
|
+
const output = (0, syntax_1.rewrite)(normalized, (literal, owner) => {
|
|
257
|
+
const from = literal.text;
|
|
258
|
+
const typeOnly = isDeclaration || (0, syntax_1.isTypeOnlyReference)(owner);
|
|
259
|
+
if ((0, imports_1.isTypeOnlyModule)(from) && typeOnly) {
|
|
260
|
+
return from;
|
|
261
|
+
}
|
|
262
|
+
const target = imports.resolve(from, filename, true);
|
|
263
|
+
switch (target.kind) {
|
|
264
|
+
case 'source':
|
|
265
|
+
return (0, paths_1.relativeModule)(outputFile, collect(target.file));
|
|
266
|
+
case 'outside':
|
|
267
|
+
if (isDeclaration && paths_1.declarationPattern.test(target.file)) {
|
|
268
|
+
return (0, paths_1.relativeModule)(outputFile, collectAmbient(target.file));
|
|
269
|
+
}
|
|
270
|
+
return (0, errors_1.fail)(`Local import leaves sourceRoot: ${target.file}`);
|
|
271
|
+
case 'unresolved':
|
|
272
|
+
return (0, errors_1.fail)(`Unresolved local import ${from} in ${filename}`);
|
|
273
|
+
case 'vendor':
|
|
274
|
+
return (0, paths_1.relativeImport)(outputFile, node_path_1.default.join(targetSource, vendor.record(from, owner, namespaces, typeOnly)));
|
|
275
|
+
case 'external':
|
|
276
|
+
return target.specifier;
|
|
277
|
+
case 'asset':
|
|
278
|
+
if (!typeOnly) {
|
|
279
|
+
externalAssets.add(from);
|
|
280
|
+
}
|
|
281
|
+
return from;
|
|
282
|
+
case 'unsupported':
|
|
283
|
+
return typeOnly ? from : (0, errors_1.fail)((0, imports_1.unsupportedModule)(from, filename));
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
files.set(relativeOutput(outputFile), pageFiles.includes(filename)
|
|
287
|
+
? syntax_1.printer.printFile((0, class_components_1.wrapPage)(typescript_1.default.createSourceFile(filename, output, typescript_1.default.ScriptTarget.Latest, true)))
|
|
288
|
+
: output);
|
|
289
|
+
}
|
|
290
|
+
function collectAmbient(filename) {
|
|
291
|
+
if (!(0, paths_1.inside)(appPath, filename)) {
|
|
292
|
+
(0, errors_1.fail)(`Local import leaves project: ${filename}`);
|
|
293
|
+
}
|
|
294
|
+
const outputFile = node_path_1.default.join(targetSource, layout_1.ambientDirectory, node_path_1.default.relative(appPath, filename));
|
|
295
|
+
if (collectedAmbient.has(filename)) {
|
|
296
|
+
return outputFile;
|
|
297
|
+
}
|
|
298
|
+
collectedAmbient.add(filename);
|
|
299
|
+
rewriteScriptFile(filename, outputFile);
|
|
300
|
+
return outputFile;
|
|
301
|
+
}
|
|
302
|
+
function collect(filename) {
|
|
303
|
+
if (!(0, paths_1.inside)(sourcePath, filename)) {
|
|
304
|
+
(0, errors_1.fail)(`Local import leaves sourceRoot: ${filename}`);
|
|
305
|
+
}
|
|
306
|
+
const outputFile = relocatedFiles.get(filename) ?? node_path_1.default.join(targetSource, node_path_1.default.relative(sourcePath, filename));
|
|
307
|
+
if (collected.has(filename)) {
|
|
308
|
+
return outputFile;
|
|
309
|
+
}
|
|
310
|
+
collected.add(filename);
|
|
311
|
+
if (paths_1.sourcePattern.test(filename)) {
|
|
312
|
+
rewriteScriptFile(filename, outputFile);
|
|
313
|
+
}
|
|
314
|
+
return outputFile;
|
|
315
|
+
}
|
|
316
|
+
for (const file of allSourceTreeFiles.filter((name) => !paths_1.sourcePattern.test(name) && node_path_1.default.basename(name) !== '.DS_Store')) {
|
|
317
|
+
if (node_fs_1.default.lstatSync(file).isSymbolicLink()) {
|
|
318
|
+
(0, errors_1.fail)(`Symbolic links in source assets are unsupported: ${file}`);
|
|
319
|
+
}
|
|
320
|
+
const outputFile = node_path_1.default.join(targetSource, node_path_1.default.relative(sourcePath, file));
|
|
321
|
+
const rewritten = (0, imports_1.isStylesheet)(file)
|
|
322
|
+
? (0, styles_1.rewriteStylesheetAliases)(file, outputFile, sourcePath, (target) => node_path_1.default.join(targetSource, node_path_1.default.relative(sourcePath, target)), resolveLocal)
|
|
323
|
+
: undefined;
|
|
324
|
+
if (rewritten !== undefined) {
|
|
325
|
+
files.set(relativeOutput(outputFile), rewritten);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
copies.set(relativeOutput(outputFile), file);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (appDoubaoFile) {
|
|
332
|
+
const emittedAppFile = collect(appDoubaoFile);
|
|
333
|
+
if (emittedAppFile !== canonicalAppEntry) {
|
|
334
|
+
const relApp = (0, paths_1.relativeImport)(canonicalAppEntry, emittedAppFile);
|
|
335
|
+
files.set(relativeOutput(canonicalAppEntry), `export * from ${JSON.stringify(relApp)};\nexport { default } from ${JSON.stringify(relApp)};\n`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const styleBaseFile = appDoubaoFile ?? appFile;
|
|
339
|
+
for (const [index, file] of pageFiles.entries()) {
|
|
340
|
+
const outputFile = collect(file);
|
|
341
|
+
const styleImports = styles.map((style) => {
|
|
342
|
+
const absolute = resolveLocal(styleBaseFile, style) ?? (0, errors_1.fail)(`Missing App style ${style}`);
|
|
343
|
+
return `import ${JSON.stringify((0, paths_1.relativeAsset)(outputFile, collect(absolute)))};\n`;
|
|
344
|
+
});
|
|
345
|
+
// Initialize before evaluating the page's dependencies.
|
|
346
|
+
const setupImport = `import ${JSON.stringify((0, paths_1.relativeImport)(outputFile, setupFile))};\n`;
|
|
347
|
+
const pageKey = relativeOutput(outputFile);
|
|
348
|
+
files.set(pageKey, setupImport + styleImports.join('') + files.get(pageKey));
|
|
349
|
+
const entryFile = node_path_1.default.join(targetSource, `${pages[index]}.tsx`);
|
|
350
|
+
if (entryFile !== outputFile) {
|
|
351
|
+
files.set(relativeOutput(entryFile), `export { default } from ${JSON.stringify((0, paths_1.relativeImport)(entryFile, outputFile))};\n`);
|
|
352
|
+
}
|
|
353
|
+
const configBase = node_path_1.default.join(sourcePath, `${pages[index]}.config`);
|
|
354
|
+
const pageConfigFile = resolveLocal(file, `${configBase}.doubao`) ?? resolveLocal(file, configBase);
|
|
355
|
+
const { alias } = ctx.runOpts?.config ?? ctx.initialConfig;
|
|
356
|
+
if (pageConfigFile &&
|
|
357
|
+
Object.keys(ctx.helper.readConfig(pageConfigFile, { alias, defineConstants: model.defines }) ?? {})
|
|
358
|
+
.length) {
|
|
359
|
+
(0, errors_1.fail)(`Page configuration needs explicit migration: ${pageConfigFile}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
for (const file of allSourceTreeFiles.filter((name) => paths_1.declarationPattern.test(name))) {
|
|
363
|
+
collect(file);
|
|
364
|
+
}
|
|
365
|
+
for (const file of ambientDeclarations) {
|
|
366
|
+
collectAmbient(file);
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
collect,
|
|
370
|
+
has: (filename) => collected.has(filename),
|
|
371
|
+
files,
|
|
372
|
+
copies,
|
|
373
|
+
get sourceFiles() {
|
|
374
|
+
return [...collected]
|
|
375
|
+
.filter((file) => paths_1.sourcePattern.test(file))
|
|
376
|
+
.map((file) => node_path_1.default.relative(sourcePath, file))
|
|
377
|
+
.sort();
|
|
378
|
+
},
|
|
379
|
+
get assetFiles() {
|
|
380
|
+
return allSourceTreeFiles
|
|
381
|
+
.filter((file) => !paths_1.sourcePattern.test(file) && node_path_1.default.basename(file) !== '.DS_Store')
|
|
382
|
+
.map((file) => node_path_1.default.relative(sourcePath, file))
|
|
383
|
+
.sort();
|
|
384
|
+
},
|
|
385
|
+
vendor,
|
|
386
|
+
get warnings() {
|
|
387
|
+
const assets = [...externalAssets].sort();
|
|
388
|
+
return assets.length
|
|
389
|
+
? [
|
|
390
|
+
`Third-party stylesheets and assets are not bundled; install their packages in the output project: ${assets.join(', ')}`
|
|
391
|
+
]
|
|
392
|
+
: [];
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IPluginContext } from '@tarojs/service';
|
|
2
|
+
import type { ProjectModel } from '../../../project';
|
|
3
|
+
import { type VendorEntry } from './manifest';
|
|
4
|
+
export interface BundleOutput {
|
|
5
|
+
/** Emitted script files, keyed by their path inside the vendor directory. */
|
|
6
|
+
files: Map<string, string>;
|
|
7
|
+
/** Emitted CSS and static assets from Rspack, keyed by their path inside the vendor directory. */
|
|
8
|
+
binaryAssets: Map<string, Buffer>;
|
|
9
|
+
/** Application modules imported by bundled packages (absolute), with their importers. */
|
|
10
|
+
sourceImports: Map<string, Set<string>>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Specifier prefix for application modules imported by bundled packages; the rest is the module path relative
|
|
14
|
+
* to the source root. The output stage points it at the generated module.
|
|
15
|
+
*/
|
|
16
|
+
export declare const sourcePrefix = "__doubao_src__/";
|
|
17
|
+
/**
|
|
18
|
+
* Bundles `entries` into ESM with Rspack. Taro, React and Doubao packages stay external; JSX is preserved for
|
|
19
|
+
* the Kit build. Application modules stay external as `sourcePrefix` placeholders, so the application keeps a
|
|
20
|
+
* single instance of each.
|
|
21
|
+
*/
|
|
22
|
+
export declare function bundle(ctx: IPluginContext, model: ProjectModel, entries: VendorEntry[]): Promise<BundleOutput>;
|
|
23
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1,221 @@
|
|
|
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.sourcePrefix = void 0;
|
|
7
|
+
exports.bundle = bundle;
|
|
8
|
+
const node_module_1 = require("node:module");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const imports_1 = require("../../../project/imports");
|
|
11
|
+
const errors_1 = require("../../../shared/errors");
|
|
12
|
+
const paths_1 = require("../../../shared/paths");
|
|
13
|
+
const manifest_1 = require("./manifest");
|
|
14
|
+
/**
|
|
15
|
+
* Specifier prefix for application modules imported by bundled packages; the rest is the module path relative
|
|
16
|
+
* to the source root. The output stage points it at the generated module.
|
|
17
|
+
*/
|
|
18
|
+
exports.sourcePrefix = '__doubao_src__/';
|
|
19
|
+
/** Proxy entry: re-exports only what the application reads, which also works for CommonJS packages. */
|
|
20
|
+
function renderEntry({ specifier, names, star }) {
|
|
21
|
+
const source = JSON.stringify(specifier);
|
|
22
|
+
const lines = [];
|
|
23
|
+
if (star) {
|
|
24
|
+
lines.push(`export * from ${source};`);
|
|
25
|
+
}
|
|
26
|
+
if (names.size) {
|
|
27
|
+
lines.push(`export { ${[...names].sort().map(manifest_1.exportName).join(', ')} } from ${source};`);
|
|
28
|
+
}
|
|
29
|
+
if (!lines.length) {
|
|
30
|
+
lines.push(`import ${source};`, 'export {};');
|
|
31
|
+
}
|
|
32
|
+
return `${lines.join('\n')}\n`;
|
|
33
|
+
}
|
|
34
|
+
const swcPreserve = (tsx) => ({
|
|
35
|
+
jsc: {
|
|
36
|
+
parser: { syntax: 'typescript', tsx },
|
|
37
|
+
target: 'esnext',
|
|
38
|
+
// JSX stays in the output for the Kit (ReactLynx) build.
|
|
39
|
+
transform: { react: { runtime: 'preserve' } }
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
function resolveProjectLoader(name, appPath) {
|
|
43
|
+
const projectRequire = (0, node_module_1.createRequire)(node_path_1.default.join(appPath, 'package.json'));
|
|
44
|
+
const searchPaths = [appPath];
|
|
45
|
+
try {
|
|
46
|
+
searchPaths.push(node_path_1.default.dirname(projectRequire.resolve('@tarojs/webpack5-runner/package.json')));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Project may not use @tarojs/webpack5-runner; fall back to appPath only.
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return projectRequire.resolve(name, { paths: searchPaths });
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Bundles `entries` into ESM with Rspack. Taro, React and Doubao packages stay external; JSX is preserved for
|
|
60
|
+
* the Kit build. Application modules stay external as `sourcePrefix` placeholders, so the application keeps a
|
|
61
|
+
* single instance of each.
|
|
62
|
+
*/
|
|
63
|
+
async function bundle(ctx, model, entries) {
|
|
64
|
+
const { appPath, sourcePath } = ctx.paths;
|
|
65
|
+
const { defines, bundleResolve, imports, layout } = model;
|
|
66
|
+
const { rspack } = await import('@rspack/core');
|
|
67
|
+
// Virtual entries stay inside the project so package resolution uses its node_modules.
|
|
68
|
+
const virtualDirectory = node_path_1.default.join(appPath, 'node_modules', '.cache', 'doubao-vendor');
|
|
69
|
+
const entryDirectory = node_path_1.default.join(virtualDirectory, 'entries');
|
|
70
|
+
const reactModule = node_path_1.default.join(virtualDirectory, 'react.mjs');
|
|
71
|
+
const reactDomModule = node_path_1.default.join(virtualDirectory, 'react-dom.mjs');
|
|
72
|
+
const output = { files: new Map(), binaryAssets: new Map(), sourceImports: new Map() };
|
|
73
|
+
const sassLoader = resolveProjectLoader('sass-loader', appPath);
|
|
74
|
+
const lessLoader = resolveProjectLoader('less-loader', appPath);
|
|
75
|
+
const styleRules = [
|
|
76
|
+
...(sassLoader ? [{ test: /\.s[ac]ss$/i, type: 'css/auto', use: [{ loader: sassLoader }] }] : []),
|
|
77
|
+
...(lessLoader ? [{ test: /\.less$/i, type: 'css/auto', use: [{ loader: lessLoader }] }] : [])
|
|
78
|
+
];
|
|
79
|
+
const virtualModules = Object.fromEntries(entries.map((entry) => [node_path_1.default.join(entryDirectory, `${entry.name}.js`), renderEntry(entry)]));
|
|
80
|
+
// Preserve default imports while sharing the application's React compatibility entry.
|
|
81
|
+
const renderDefaultFacade = (target) => `import * as React from '${target}';\nexport * from '${target}';\nexport default React;\n`;
|
|
82
|
+
virtualModules[reactModule] = renderDefaultFacade(imports_1.runtimeModules.react);
|
|
83
|
+
virtualModules[reactDomModule] = renderDefaultFacade(imports_1.runtimeModules.reactDom);
|
|
84
|
+
const entryNames = new Set(entries.map((entry) => entry.name));
|
|
85
|
+
const stats = await new Promise((resolve, reject) => {
|
|
86
|
+
rspack({
|
|
87
|
+
mode: 'none',
|
|
88
|
+
context: appPath,
|
|
89
|
+
target: ['web', 'es2022'],
|
|
90
|
+
experiments: { css: true },
|
|
91
|
+
entry: Object.fromEntries(entries.map((entry) => [entry.name, node_path_1.default.join(entryDirectory, `${entry.name}.js`)])),
|
|
92
|
+
output: {
|
|
93
|
+
path: node_path_1.default.join(virtualDirectory, 'output'),
|
|
94
|
+
// Entries keep their names; shared and runtime chunks go to `chunks/`.
|
|
95
|
+
filename: ({ chunk }) => chunk?.name && entryNames.has(chunk.name) ? '[name].js' : 'chunks/[name].js',
|
|
96
|
+
chunkFilename: 'chunks/[name].js',
|
|
97
|
+
cssFilename: '[name].css',
|
|
98
|
+
cssChunkFilename: 'chunks/[name].css',
|
|
99
|
+
module: true,
|
|
100
|
+
chunkFormat: 'module',
|
|
101
|
+
library: { type: 'modern-module' }
|
|
102
|
+
},
|
|
103
|
+
resolve: bundleResolve,
|
|
104
|
+
externalsType: 'module',
|
|
105
|
+
externals: [
|
|
106
|
+
({ request, contextInfo }, callback) => {
|
|
107
|
+
const issuer = contextInfo?.issuer;
|
|
108
|
+
const importer = issuer || 'a third-party package';
|
|
109
|
+
// React is left to the replacement plugin, which resolves the facade instead of externalizing a
|
|
110
|
+
// missing default.
|
|
111
|
+
if (!request || request === 'react' || request === 'react-dom') {
|
|
112
|
+
return callback();
|
|
113
|
+
}
|
|
114
|
+
// Package-internal relative imports are the common case; only resolve those reaching the source root.
|
|
115
|
+
if (!(0, imports_1.isBareSpecifier)(request) &&
|
|
116
|
+
!(issuer && (0, paths_1.inside)(sourcePath, node_path_1.default.resolve(node_path_1.default.dirname(issuer), request)))) {
|
|
117
|
+
return callback();
|
|
118
|
+
}
|
|
119
|
+
const target = imports.resolve(request, issuer || appPath);
|
|
120
|
+
switch (target.kind) {
|
|
121
|
+
case 'source': {
|
|
122
|
+
const importers = output.sourceImports.get(target.file) ?? new Set();
|
|
123
|
+
importers.add(importer);
|
|
124
|
+
output.sourceImports.set(target.file, importers);
|
|
125
|
+
return callback(undefined, exports.sourcePrefix + (0, paths_1.posixPath)(node_path_1.default.relative(sourcePath, target.file)));
|
|
126
|
+
}
|
|
127
|
+
case 'asset':
|
|
128
|
+
return callback();
|
|
129
|
+
case 'unsupported':
|
|
130
|
+
return callback(new Error((0, imports_1.unsupportedModule)(request, importer)));
|
|
131
|
+
case 'external':
|
|
132
|
+
return callback(undefined, target.specifier);
|
|
133
|
+
default:
|
|
134
|
+
// Vendored packages, aliases outside the source root and missing files: Rspack resolves them.
|
|
135
|
+
return callback();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
module: {
|
|
140
|
+
parser: { javascript: { jsx: true, dynamicImportMode: 'eager' } },
|
|
141
|
+
rules: [
|
|
142
|
+
{
|
|
143
|
+
// Runs on the package source, before TypeScript is stripped.
|
|
144
|
+
test: /\.[cm]?[jt]sx?$/,
|
|
145
|
+
enforce: 'pre',
|
|
146
|
+
exclude: virtualDirectory,
|
|
147
|
+
loader: require.resolve('./class-loader')
|
|
148
|
+
},
|
|
149
|
+
{ test: /\.[cm]?ts$/, loader: 'builtin:swc-loader', options: swcPreserve(false) },
|
|
150
|
+
{ test: /\.tsx$/, loader: 'builtin:swc-loader', options: swcPreserve(true) },
|
|
151
|
+
{ test: /\.css$/i, type: 'css/auto' },
|
|
152
|
+
...styleRules,
|
|
153
|
+
{
|
|
154
|
+
test: /\.(?:png|jpe?g|gif|svg|webp|avif|bmp|ico|woff2?|ttf|eot|otf)$/i,
|
|
155
|
+
type: 'asset/inline'
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
plugins: [
|
|
160
|
+
new rspack.experiments.VirtualModulesPlugin(virtualModules),
|
|
161
|
+
(compiler) => {
|
|
162
|
+
compiler.hooks.shouldEmit.tap('DoubaoVendor', (compilation) => {
|
|
163
|
+
const chunkCss = new Map();
|
|
164
|
+
for (const chunk of compilation.chunks) {
|
|
165
|
+
const jsFiles = [...chunk.files].filter((file) => paths_1.sourcePattern.test(file));
|
|
166
|
+
const cssFiles = [...chunk.files].filter((file) => file.endsWith('.css'));
|
|
167
|
+
if (jsFiles.length && cssFiles.length) {
|
|
168
|
+
for (const jsFile of jsFiles) {
|
|
169
|
+
chunkCss.set(jsFile, cssFiles);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const { name, source } of compilation.getAssets()) {
|
|
174
|
+
if (paths_1.sourcePattern.test(name)) {
|
|
175
|
+
const cssImports = (chunkCss.get(name) ?? [])
|
|
176
|
+
.map((cssFile) => `import ${JSON.stringify((0, paths_1.relativeAsset)(name, cssFile))};\n`)
|
|
177
|
+
.join('');
|
|
178
|
+
output.files.set(name, cssImports + source.source().toString());
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
output.binaryAssets.set(name, source.buffer());
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
new rspack.NormalModuleReplacementPlugin(/^react$/, reactModule),
|
|
188
|
+
new rspack.NormalModuleReplacementPlugin(/^react-dom$/, reactDomModule),
|
|
189
|
+
new rspack.DefinePlugin(defines)
|
|
190
|
+
],
|
|
191
|
+
optimization: {
|
|
192
|
+
minimize: false,
|
|
193
|
+
nodeEnv: false,
|
|
194
|
+
moduleIds: 'deterministic',
|
|
195
|
+
chunkIds: 'deterministic',
|
|
196
|
+
// One runtime holds the module registry, so modules shared across entries run once.
|
|
197
|
+
// `~` never occurs in entry names (see `VendorManifest`), so a package named `runtime` cannot clash.
|
|
198
|
+
runtimeChunk: { name: layout.vendorRuntimeChunk },
|
|
199
|
+
splitChunks: { chunks: 'all', minSize: 0 }
|
|
200
|
+
}
|
|
201
|
+
}, (error, result) => {
|
|
202
|
+
if (error || !result) {
|
|
203
|
+
reject(error ?? new Error('[doubao] Vendor build produced no result'));
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
resolve(result);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
if (stats.hasErrors()) {
|
|
211
|
+
const { errors = [] } = stats.toJson({ all: false, errors: true });
|
|
212
|
+
// Drop stack frames; the messages already name the importing module.
|
|
213
|
+
const messages = errors.map((error) => error.message
|
|
214
|
+
.split('\n')
|
|
215
|
+
.filter((line) => !/^\s*│?\s*at /.test(line))
|
|
216
|
+
.join('\n'));
|
|
217
|
+
(0, errors_1.fail)(`Failed to bundle third-party packages:\n${messages.join('\n')}`);
|
|
218
|
+
}
|
|
219
|
+
return output;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rspack loader for bundled package files: applies the same class component handling as application
|
|
3
|
+
* sources, so Taro page callbacks (`componentDidShow`, `componentDidHide`) reach components in packages.
|
|
4
|
+
* Only ES classes in ES modules are recognized; classes compiled to ES5 or CommonJS are left unchanged.
|
|
5
|
+
*/
|
|
6
|
+
export default function classComponentLoader(this: {
|
|
7
|
+
resourcePath: string;
|
|
8
|
+
}, content: string): string;
|
|
9
|
+
//# sourceMappingURL=class-loader.d.ts.map
|