@doubao-dev/taro-plugin-platform-doubao 0.10.3 → 0.11.0
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
package/dist/file-system.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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.nodeFileSystem = void 0;
|
|
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
|
-
exports.nodeFileSystem = {
|
|
11
|
-
system: typescript_1.default.sys,
|
|
12
|
-
exists: node_fs_1.default.existsSync,
|
|
13
|
-
realpath: node_fs_1.default.realpathSync,
|
|
14
|
-
entries: (directory) => node_fs_1.default.readdirSync(directory, { withFileTypes: true }),
|
|
15
|
-
readText: (filename) => node_fs_1.default.readFileSync(filename, 'utf8'),
|
|
16
|
-
writeText(filename, content) {
|
|
17
|
-
node_fs_1.default.mkdirSync(node_path_1.default.dirname(filename), { recursive: true });
|
|
18
|
-
node_fs_1.default.writeFileSync(filename, content);
|
|
19
|
-
},
|
|
20
|
-
copyFile(source, destination) {
|
|
21
|
-
node_fs_1.default.mkdirSync(node_path_1.default.dirname(destination), { recursive: true });
|
|
22
|
-
node_fs_1.default.copyFileSync(source, destination);
|
|
23
|
-
},
|
|
24
|
-
removeFile: node_fs_1.default.unlinkSync,
|
|
25
|
-
withOutput(outputRoot, emit) {
|
|
26
|
-
const parent = node_path_1.default.dirname(outputRoot);
|
|
27
|
-
node_fs_1.default.mkdirSync(parent, { recursive: true });
|
|
28
|
-
const stage = node_fs_1.default.mkdtempSync(node_path_1.default.join(parent, '.doubao-source-'));
|
|
29
|
-
try {
|
|
30
|
-
const result = emit(stage);
|
|
31
|
-
if (node_fs_1.default.existsSync(outputRoot)) {
|
|
32
|
-
node_fs_1.default.rmSync(outputRoot, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
node_fs_1.default.renameSync(stage, outputRoot);
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
node_fs_1.default.rmSync(stage, { recursive: true, force: true });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=file-system.js.map
|
package/dist/files.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
import type { FileSystem } from './file-system';
|
|
3
|
-
export declare const sourcePattern: RegExp;
|
|
4
|
-
export declare const declarationPattern: RegExp;
|
|
5
|
-
export declare const printer: ts.Printer;
|
|
6
|
-
export declare function fail(message: string): never;
|
|
7
|
-
export declare function isTypeOnlyModule(specifier: string): boolean;
|
|
8
|
-
export declare function inside(root: string, filename: string): boolean;
|
|
9
|
-
export declare function walk(fileSystem: FileSystem, root: string): string[];
|
|
10
|
-
export declare function readSource(fileSystem: FileSystem, filename: string): ts.SourceFile;
|
|
11
|
-
export declare function createProgram(fileSystem: FileSystem, rootNames: string[], options: ts.CompilerOptions): ts.Program;
|
|
12
|
-
export declare function relativeImport(from: string, to: string): string;
|
|
13
|
-
export declare function resolveSource(fileSystem: FileSystem, filename: string): string | undefined;
|
|
14
|
-
export declare function resolveSourceOrAsset(fileSystem: FileSystem, filename: string): string | undefined;
|
|
15
|
-
export declare function moduleName(node: ts.Node): ts.StringLiteral | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* True when the reference is erased at compile time: `import type`, `export type`, `import('x').T`, or an
|
|
18
|
-
* import whose named bindings are all inline `type` specifiers.
|
|
19
|
-
*/
|
|
20
|
-
export declare function isTypeOnlyReference(node: ts.Node): boolean;
|
|
21
|
-
export declare function collectValueIdentifiers(source: ts.SourceFile): Set<string>;
|
|
22
|
-
export declare function collectQualifiedTypeRoots(source: ts.SourceFile): Set<string>;
|
|
23
|
-
export declare function rewrite(source: ts.SourceFile, replace: (literal: ts.StringLiteral, owner: ts.Node) => string): string;
|
|
24
|
-
//# sourceMappingURL=files.d.ts.map
|
package/dist/files.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
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.printer = exports.declarationPattern = exports.sourcePattern = void 0;
|
|
7
|
-
exports.fail = fail;
|
|
8
|
-
exports.isTypeOnlyModule = isTypeOnlyModule;
|
|
9
|
-
exports.inside = inside;
|
|
10
|
-
exports.walk = walk;
|
|
11
|
-
exports.readSource = readSource;
|
|
12
|
-
exports.createProgram = createProgram;
|
|
13
|
-
exports.relativeImport = relativeImport;
|
|
14
|
-
exports.resolveSource = resolveSource;
|
|
15
|
-
exports.resolveSourceOrAsset = resolveSourceOrAsset;
|
|
16
|
-
exports.moduleName = moduleName;
|
|
17
|
-
exports.isTypeOnlyReference = isTypeOnlyReference;
|
|
18
|
-
exports.collectValueIdentifiers = collectValueIdentifiers;
|
|
19
|
-
exports.collectQualifiedTypeRoots = collectQualifiedTypeRoots;
|
|
20
|
-
exports.rewrite = rewrite;
|
|
21
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
22
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
23
|
-
exports.sourcePattern = /\.[cm]?[jt]sx?$/;
|
|
24
|
-
exports.declarationPattern = /\.d\.[cm]?ts$/;
|
|
25
|
-
exports.printer = typescript_1.default.createPrinter({ newLine: typescript_1.default.NewLineKind.LineFeed });
|
|
26
|
-
function fail(message) {
|
|
27
|
-
throw new Error(`[doubao] ${message}`);
|
|
28
|
-
}
|
|
29
|
-
function isTypeOnlyModule(specifier) {
|
|
30
|
-
return (specifier === 'react' ||
|
|
31
|
-
specifier.startsWith('react/') ||
|
|
32
|
-
specifier === 'react-dom' ||
|
|
33
|
-
specifier.startsWith('react-dom/') ||
|
|
34
|
-
specifier.startsWith('@tarojs/'));
|
|
35
|
-
}
|
|
36
|
-
function inside(root, filename) {
|
|
37
|
-
const relative = node_path_1.default.relative(root, filename);
|
|
38
|
-
return (relative === '' ||
|
|
39
|
-
(!relative.startsWith(`..${node_path_1.default.sep}`) && relative !== '..' && !node_path_1.default.isAbsolute(relative)));
|
|
40
|
-
}
|
|
41
|
-
function walk(fileSystem, root) {
|
|
42
|
-
return fileSystem.entries(root).flatMap((entry) => {
|
|
43
|
-
if (['node_modules', '.git'].includes(entry.name)) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
const filename = node_path_1.default.join(root, entry.name);
|
|
47
|
-
if (entry.isSymbolicLink()) {
|
|
48
|
-
fail(`Symbolic links in source assets are unsupported: ${filename}`);
|
|
49
|
-
}
|
|
50
|
-
return entry.isDirectory() ? walk(fileSystem, filename) : [filename];
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function readSource(fileSystem, filename) {
|
|
54
|
-
return typescript_1.default.createSourceFile(filename, fileSystem.readText(filename), typescript_1.default.ScriptTarget.Latest, true);
|
|
55
|
-
}
|
|
56
|
-
function createProgram(fileSystem, rootNames, options) {
|
|
57
|
-
return typescript_1.default.createProgram(rootNames, options, typescript_1.default.createIncrementalCompilerHost(options, fileSystem.system));
|
|
58
|
-
}
|
|
59
|
-
function relativeImport(from, to) {
|
|
60
|
-
let relative = node_path_1.default.relative(node_path_1.default.dirname(from), to).split(node_path_1.default.sep).join('/');
|
|
61
|
-
if (/(?:\.d)?\.m[jt]s$/.test(relative)) {
|
|
62
|
-
relative = relative.replace(/(?:\.d)?\.m[jt]s$/, '.mjs');
|
|
63
|
-
}
|
|
64
|
-
else if (/(?:\.d)?\.c[jt]s$/.test(relative)) {
|
|
65
|
-
relative = relative.replace(/(?:\.d)?\.c[jt]s$/, '.cjs');
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
relative = relative.replace(/(?:\.d)?\.[jt]sx?$/, '');
|
|
69
|
-
}
|
|
70
|
-
if (!relative.startsWith('.')) {
|
|
71
|
-
relative = `./${relative}`;
|
|
72
|
-
}
|
|
73
|
-
return relative;
|
|
74
|
-
}
|
|
75
|
-
function resolveSource(fileSystem, filename) {
|
|
76
|
-
if (/\.mjs$/.test(filename)) {
|
|
77
|
-
const base = filename.slice(0, -4);
|
|
78
|
-
return [filename, `${base}.mts`, `${base}.mjs`, `${base}.d.mts`].find((candidate) => fileSystem.system.fileExists(candidate));
|
|
79
|
-
}
|
|
80
|
-
if (/\.cjs$/.test(filename)) {
|
|
81
|
-
const base = filename.slice(0, -4);
|
|
82
|
-
return [filename, `${base}.cts`, `${base}.cjs`, `${base}.d.cts`].find((candidate) => fileSystem.system.fileExists(candidate));
|
|
83
|
-
}
|
|
84
|
-
const base = filename.replace(/\.[jt]sx?$/, '');
|
|
85
|
-
return [
|
|
86
|
-
filename,
|
|
87
|
-
...[
|
|
88
|
-
'.ts',
|
|
89
|
-
'.tsx',
|
|
90
|
-
'.js',
|
|
91
|
-
'.jsx',
|
|
92
|
-
'.mts',
|
|
93
|
-
'.cts',
|
|
94
|
-
'.mjs',
|
|
95
|
-
'.cjs',
|
|
96
|
-
'.json',
|
|
97
|
-
'.d.ts',
|
|
98
|
-
'.d.mts',
|
|
99
|
-
'.d.cts'
|
|
100
|
-
].map((extension) => base + extension),
|
|
101
|
-
...[
|
|
102
|
-
'index.ts',
|
|
103
|
-
'index.tsx',
|
|
104
|
-
'index.js',
|
|
105
|
-
'index.jsx',
|
|
106
|
-
'index.mts',
|
|
107
|
-
'index.cts',
|
|
108
|
-
'index.mjs',
|
|
109
|
-
'index.cjs',
|
|
110
|
-
'index.d.ts'
|
|
111
|
-
].map((name) => node_path_1.default.join(base, name))
|
|
112
|
-
].find((candidate) => fileSystem.system.fileExists(candidate));
|
|
113
|
-
}
|
|
114
|
-
function resolveSourceOrAsset(fileSystem, filename) {
|
|
115
|
-
return (resolveSource(fileSystem, filename) ?? (fileSystem.system.fileExists(filename) ? filename : undefined));
|
|
116
|
-
}
|
|
117
|
-
function moduleName(node) {
|
|
118
|
-
if ((typescript_1.default.isImportDeclaration(node) || typescript_1.default.isExportDeclaration(node)) &&
|
|
119
|
-
node.moduleSpecifier &&
|
|
120
|
-
typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
|
|
121
|
-
return node.moduleSpecifier;
|
|
122
|
-
}
|
|
123
|
-
if (typescript_1.default.isImportTypeNode(node) &&
|
|
124
|
-
typescript_1.default.isLiteralTypeNode(node.argument) &&
|
|
125
|
-
typescript_1.default.isStringLiteral(node.argument.literal)) {
|
|
126
|
-
return node.argument.literal;
|
|
127
|
-
}
|
|
128
|
-
if (typescript_1.default.isCallExpression(node) &&
|
|
129
|
-
(node.expression.kind === typescript_1.default.SyntaxKind.ImportKeyword ||
|
|
130
|
-
(typescript_1.default.isIdentifier(node.expression) && node.expression.text === 'require'))) {
|
|
131
|
-
if (node.arguments.length !== 1 || !typescript_1.default.isStringLiteral(node.arguments[0])) {
|
|
132
|
-
fail(`Dynamic module paths are unsupported in ${node.getSourceFile().fileName}`);
|
|
133
|
-
}
|
|
134
|
-
return node.arguments[0];
|
|
135
|
-
}
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* True when the reference is erased at compile time: `import type`, `export type`, `import('x').T`, or an
|
|
140
|
-
* import whose named bindings are all inline `type` specifiers.
|
|
141
|
-
*/
|
|
142
|
-
function isTypeOnlyReference(node) {
|
|
143
|
-
if (typescript_1.default.isImportDeclaration(node)) {
|
|
144
|
-
const clause = node.importClause;
|
|
145
|
-
if (!clause) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
if (clause.isTypeOnly) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
return (!clause.name &&
|
|
152
|
-
!!clause.namedBindings &&
|
|
153
|
-
typescript_1.default.isNamedImports(clause.namedBindings) &&
|
|
154
|
-
clause.namedBindings.elements.length > 0 &&
|
|
155
|
-
clause.namedBindings.elements.every((element) => element.isTypeOnly));
|
|
156
|
-
}
|
|
157
|
-
if (typescript_1.default.isExportDeclaration(node)) {
|
|
158
|
-
return (node.isTypeOnly ||
|
|
159
|
-
(!!node.exportClause &&
|
|
160
|
-
typescript_1.default.isNamedExports(node.exportClause) &&
|
|
161
|
-
node.exportClause.elements.length > 0 &&
|
|
162
|
-
node.exportClause.elements.every((element) => element.isTypeOnly)));
|
|
163
|
-
}
|
|
164
|
-
return typescript_1.default.isImportTypeNode(node);
|
|
165
|
-
}
|
|
166
|
-
function collectValueIdentifiers(source) {
|
|
167
|
-
const names = new Set();
|
|
168
|
-
if (exports.declarationPattern.test(source.fileName)) {
|
|
169
|
-
return names;
|
|
170
|
-
}
|
|
171
|
-
const visit = (node) => {
|
|
172
|
-
if (typescript_1.default.isExpressionWithTypeArguments(node)) {
|
|
173
|
-
visit(node.expression);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (typescript_1.default.isTypeNode(node) ||
|
|
177
|
-
typescript_1.default.isInterfaceDeclaration(node) ||
|
|
178
|
-
typescript_1.default.isTypeAliasDeclaration(node) ||
|
|
179
|
-
typescript_1.default.isImportDeclaration(node)) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if (typescript_1.default.isExportDeclaration(node)) {
|
|
183
|
-
if (node.isTypeOnly || node.moduleSpecifier) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
if (node.exportClause && typescript_1.default.isNamedExports(node.exportClause)) {
|
|
187
|
-
for (const element of node.exportClause.elements) {
|
|
188
|
-
if (!element.isTypeOnly) {
|
|
189
|
-
names.add((element.propertyName ?? element.name).text);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
if (typescript_1.default.isHeritageClause(node) && node.token === typescript_1.default.SyntaxKind.ImplementsKeyword) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (typescript_1.default.isIdentifier(node)) {
|
|
199
|
-
const parent = node.parent;
|
|
200
|
-
const isMemberName = parent &&
|
|
201
|
-
((typescript_1.default.isPropertyAccessExpression(parent) && parent.name === node) ||
|
|
202
|
-
(typescript_1.default.isPropertyAssignment(parent) && parent.name === node) ||
|
|
203
|
-
(typescript_1.default.isMethodDeclaration(parent) && parent.name === node) ||
|
|
204
|
-
(typescript_1.default.isPropertyDeclaration(parent) && parent.name === node) ||
|
|
205
|
-
(typescript_1.default.isGetAccessorDeclaration(parent) && parent.name === node) ||
|
|
206
|
-
(typescript_1.default.isSetAccessorDeclaration(parent) && parent.name === node) ||
|
|
207
|
-
(typescript_1.default.isBindingElement(parent) && parent.propertyName === node) ||
|
|
208
|
-
(typescript_1.default.isJsxAttribute(parent) && parent.name === node));
|
|
209
|
-
if (!isMemberName) {
|
|
210
|
-
names.add(node.text);
|
|
211
|
-
}
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
typescript_1.default.forEachChild(node, visit);
|
|
215
|
-
};
|
|
216
|
-
typescript_1.default.forEachChild(source, visit);
|
|
217
|
-
return names;
|
|
218
|
-
}
|
|
219
|
-
function collectQualifiedTypeRoots(source) {
|
|
220
|
-
const roots = new Set();
|
|
221
|
-
const leftmost = (entity) => typescript_1.default.isIdentifier(entity) ? entity : leftmost(entity.left);
|
|
222
|
-
const visit = (node) => {
|
|
223
|
-
if (typescript_1.default.isTypeQueryNode(node)) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (typescript_1.default.isQualifiedName(node)) {
|
|
227
|
-
roots.add(leftmost(node.left).text);
|
|
228
|
-
}
|
|
229
|
-
typescript_1.default.forEachChild(node, visit);
|
|
230
|
-
};
|
|
231
|
-
typescript_1.default.forEachChild(source, visit);
|
|
232
|
-
return roots;
|
|
233
|
-
}
|
|
234
|
-
function rewrite(source, replace) {
|
|
235
|
-
const result = typescript_1.default.transform(source, [
|
|
236
|
-
(context) => {
|
|
237
|
-
const replacements = new Map();
|
|
238
|
-
const visit = (node) => {
|
|
239
|
-
const literal = moduleName(node);
|
|
240
|
-
if (literal) {
|
|
241
|
-
replacements.set(literal, replace(literal, node));
|
|
242
|
-
}
|
|
243
|
-
const replacement = typescript_1.default.isStringLiteral(node) ? replacements.get(node) : undefined;
|
|
244
|
-
if (replacement !== undefined) {
|
|
245
|
-
return typescript_1.default.factory.createStringLiteral(replacement);
|
|
246
|
-
}
|
|
247
|
-
return typescript_1.default.visitEachChild(node, visit, context);
|
|
248
|
-
};
|
|
249
|
-
return (node) => typescript_1.default.visitNode(node, visit);
|
|
250
|
-
}
|
|
251
|
-
]);
|
|
252
|
-
const output = exports.printer.printFile(result.transformed[0]);
|
|
253
|
-
result.dispose();
|
|
254
|
-
return output;
|
|
255
|
-
}
|
|
256
|
-
//# sourceMappingURL=files.js.map
|
|
@@ -1,122 +0,0 @@
|
|
|
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.prunePlatformBranches = prunePlatformBranches;
|
|
7
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
-
function unwrap(expression) {
|
|
9
|
-
while (typescript_1.default.isParenthesizedExpression(expression)) {
|
|
10
|
-
expression = expression.expression;
|
|
11
|
-
}
|
|
12
|
-
return expression;
|
|
13
|
-
}
|
|
14
|
-
function isTaroEnv(expression) {
|
|
15
|
-
const node = unwrap(expression);
|
|
16
|
-
if (!typescript_1.default.isPropertyAccessExpression(node) || node.name.text !== 'TARO_ENV') {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
const env = node.expression;
|
|
20
|
-
return (typescript_1.default.isPropertyAccessExpression(env) &&
|
|
21
|
-
env.name.text === 'env' &&
|
|
22
|
-
typescript_1.default.isIdentifier(env.expression) &&
|
|
23
|
-
env.expression.text === 'process');
|
|
24
|
-
}
|
|
25
|
-
function evaluate(condition) {
|
|
26
|
-
const node = unwrap(condition);
|
|
27
|
-
if (!typescript_1.default.isBinaryExpression(node)) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const operator = node.operatorToken.kind;
|
|
31
|
-
if (operator === typescript_1.default.SyntaxKind.AmpersandAmpersandToken || operator === typescript_1.default.SyntaxKind.BarBarToken) {
|
|
32
|
-
const left = evaluate(node.left);
|
|
33
|
-
if (left === undefined) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const shortCircuits = operator === typescript_1.default.SyntaxKind.AmpersandAmpersandToken ? !left : left;
|
|
37
|
-
return shortCircuits ? left : evaluate(node.right);
|
|
38
|
-
}
|
|
39
|
-
if (operator !== typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken &&
|
|
40
|
-
operator !== typescript_1.default.SyntaxKind.ExclamationEqualsEqualsToken) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const literal = isTaroEnv(node.left)
|
|
44
|
-
? unwrap(node.right)
|
|
45
|
-
: isTaroEnv(node.right)
|
|
46
|
-
? unwrap(node.left)
|
|
47
|
-
: undefined;
|
|
48
|
-
if (!literal || !typescript_1.default.isStringLiteral(literal)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const matches = literal.text === 'doubao';
|
|
52
|
-
return operator === typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken ? matches : !matches;
|
|
53
|
-
}
|
|
54
|
-
function references(source) {
|
|
55
|
-
const names = new Set();
|
|
56
|
-
function visit(node) {
|
|
57
|
-
if (typescript_1.default.isImportDeclaration(node)) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (typescript_1.default.isIdentifier(node)) {
|
|
61
|
-
names.add(node.text);
|
|
62
|
-
}
|
|
63
|
-
typescript_1.default.forEachChild(node, visit);
|
|
64
|
-
}
|
|
65
|
-
visit(source);
|
|
66
|
-
return names;
|
|
67
|
-
}
|
|
68
|
-
/** Select platform branches before imports are mapped to the Doubao runtime. */
|
|
69
|
-
function prunePlatformBranches(source) {
|
|
70
|
-
const result = typescript_1.default.transform(source, [
|
|
71
|
-
(context) => {
|
|
72
|
-
const visit = (node) => {
|
|
73
|
-
if (typescript_1.default.isIfStatement(node)) {
|
|
74
|
-
const value = evaluate(node.expression);
|
|
75
|
-
if (value !== undefined) {
|
|
76
|
-
const selected = value ? node.thenStatement : node.elseStatement;
|
|
77
|
-
return selected ? typescript_1.default.visitNode(selected, visit) : typescript_1.default.factory.createEmptyStatement();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (typescript_1.default.isConditionalExpression(node)) {
|
|
81
|
-
const value = evaluate(node.condition);
|
|
82
|
-
if (value !== undefined) {
|
|
83
|
-
return typescript_1.default.visitNode(value ? node.whenTrue : node.whenFalse, visit);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return typescript_1.default.visitEachChild(node, visit, context);
|
|
87
|
-
};
|
|
88
|
-
return (file) => typescript_1.default.visitNode(file, visit, typescript_1.default.isSourceFile);
|
|
89
|
-
}
|
|
90
|
-
]);
|
|
91
|
-
const pruned = result.transformed[0];
|
|
92
|
-
result.dispose();
|
|
93
|
-
if (pruned === source) {
|
|
94
|
-
return source;
|
|
95
|
-
}
|
|
96
|
-
const before = references(source);
|
|
97
|
-
const after = references(pruned);
|
|
98
|
-
return typescript_1.default.factory.updateSourceFile(pruned, pruned.statements.flatMap((node) => {
|
|
99
|
-
if (!typescript_1.default.isImportDeclaration(node) ||
|
|
100
|
-
!typescript_1.default.isStringLiteral(node.moduleSpecifier) ||
|
|
101
|
-
node.moduleSpecifier.text !== '@tarojs/components') {
|
|
102
|
-
return [node];
|
|
103
|
-
}
|
|
104
|
-
const clause = node.importClause;
|
|
105
|
-
const bindings = clause?.namedBindings;
|
|
106
|
-
if (!clause || !bindings || !typescript_1.default.isNamedImports(bindings)) {
|
|
107
|
-
return [node];
|
|
108
|
-
}
|
|
109
|
-
const kept = bindings.elements.filter(({ name }) => !before.has(name.text) || after.has(name.text));
|
|
110
|
-
if (kept.length === bindings.elements.length) {
|
|
111
|
-
return [node];
|
|
112
|
-
}
|
|
113
|
-
if (!kept.length && !clause.name) {
|
|
114
|
-
return [];
|
|
115
|
-
}
|
|
116
|
-
const nextClause = typescript_1.default.factory.updateImportClause(clause, clause.isTypeOnly, clause.name, kept.length ? typescript_1.default.factory.updateNamedImports(bindings, kept) : undefined);
|
|
117
|
-
return [
|
|
118
|
-
typescript_1.default.factory.updateImportDeclaration(node, node.modifiers, nextClause, node.moduleSpecifier, node.attributes)
|
|
119
|
-
];
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=platform-branches.js.map
|
package/dist/project-files.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { FileSystem } from './file-system';
|
|
2
|
-
import type { ProjectModel } from './project';
|
|
3
|
-
export declare function planProjectFiles(fileSystem: FileSystem, model: ProjectModel): {
|
|
4
|
-
hasConfig: boolean;
|
|
5
|
-
write(): void;
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=project-files.d.ts.map
|
package/dist/project-files.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
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.planProjectFiles = planProjectFiles;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const files_1 = require("./files");
|
|
9
|
-
const configName = 'doubao.config.ts';
|
|
10
|
-
const manifestName = 'manifest.yaml';
|
|
11
|
-
const configMarker = '// Generated by @doubao-dev/taro-plugin-platform-doubao.\n';
|
|
12
|
-
function resolveInput(fileSystem, model, option, name) {
|
|
13
|
-
const filename = node_path_1.default.resolve(model.project, option ?? name);
|
|
14
|
-
if (!fileSystem.system.fileExists(filename)) {
|
|
15
|
-
if (option !== undefined) {
|
|
16
|
-
(0, files_1.fail)(`Missing project file: ${filename}`);
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
const resolved = fileSystem.realpath(filename);
|
|
21
|
-
if ((0, files_1.inside)(model.outputRoot, resolved)) {
|
|
22
|
-
(0, files_1.fail)(`Project file must be outside the output project: ${filename}`);
|
|
23
|
-
}
|
|
24
|
-
return resolved;
|
|
25
|
-
}
|
|
26
|
-
function importPath(directory, filename) {
|
|
27
|
-
const relative = node_path_1.default
|
|
28
|
-
.relative(directory, filename)
|
|
29
|
-
.split(node_path_1.default.sep)
|
|
30
|
-
.join('/')
|
|
31
|
-
.replace(/\.tsx?$/, '');
|
|
32
|
-
return JSON.stringify(relative.startsWith('../') ? relative : `./${relative}`);
|
|
33
|
-
}
|
|
34
|
-
function planConfig(fileSystem, outputRoot, source) {
|
|
35
|
-
const filename = ['.js', '.ts', '.mjs']
|
|
36
|
-
.map((extension) => node_path_1.default.join(outputRoot, `doubao.config${extension}`))
|
|
37
|
-
.find((candidate) => fileSystem.exists(candidate)) ?? node_path_1.default.join(outputRoot, configName);
|
|
38
|
-
const extension = node_path_1.default.extname(filename);
|
|
39
|
-
const baseFile = node_path_1.default.join(outputRoot, `doubao.config.local${extension}`);
|
|
40
|
-
const previous = fileSystem.exists(filename) ? fileSystem.readText(filename) : undefined;
|
|
41
|
-
const managed = previous?.startsWith(configMarker);
|
|
42
|
-
if (source || managed) {
|
|
43
|
-
checkDestination(fileSystem, filename);
|
|
44
|
-
checkDestination(fileSystem, baseFile);
|
|
45
|
-
}
|
|
46
|
-
if (!source) {
|
|
47
|
-
return managed
|
|
48
|
-
? () => {
|
|
49
|
-
if (fileSystem.exists(baseFile)) {
|
|
50
|
-
fileSystem.writeText(filename, fileSystem.readText(baseFile));
|
|
51
|
-
fileSystem.removeFile(baseFile);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
fileSystem.removeFile(filename);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
: undefined;
|
|
58
|
-
}
|
|
59
|
-
if (previous !== undefined &&
|
|
60
|
-
!managed &&
|
|
61
|
-
fileSystem.exists(baseFile) &&
|
|
62
|
-
fileSystem.readText(baseFile) !== previous) {
|
|
63
|
-
(0, files_1.fail)(`Cannot preserve the target config because ${baseFile} already exists`);
|
|
64
|
-
}
|
|
65
|
-
const hasBase = (previous !== undefined && !managed) || fileSystem.exists(baseFile);
|
|
66
|
-
const recordType = extension === '.ts' ? ': Record<string, unknown>' : '';
|
|
67
|
-
const unknownType = extension === '.ts' ? ': unknown' : '';
|
|
68
|
-
const predicate = extension === '.ts' ? ': value is Record<string, unknown>' : '';
|
|
69
|
-
const content = `${configMarker}import sourceConfig from ${importPath(outputRoot, source)};
|
|
70
|
-
import defines from './src/taro.defines';
|
|
71
|
-
${hasBase ? `import targetConfig from ${importPath(outputRoot, baseFile)};` : 'const targetConfig = {};'}
|
|
72
|
-
|
|
73
|
-
function mergeConfig(target${recordType}, source${recordType})${recordType} {
|
|
74
|
-
const merged = { ...target };
|
|
75
|
-
for (const [key, value] of Object.entries(source)) {
|
|
76
|
-
const existing = Object.hasOwn(merged, key) ? merged[key] : undefined;
|
|
77
|
-
Object.defineProperty(merged, key, {
|
|
78
|
-
value: isPlainObject(existing) && isPlainObject(value) ? mergeConfig(existing, value) : value,
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: true,
|
|
81
|
-
writable: true
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return merged;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function isPlainObject(value${unknownType})${predicate} {
|
|
88
|
-
return value !== null && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const config = mergeConfig(targetConfig, sourceConfig);
|
|
92
|
-
export default mergeConfig(config, {
|
|
93
|
-
source: { define: defines }
|
|
94
|
-
});
|
|
95
|
-
`;
|
|
96
|
-
return () => {
|
|
97
|
-
if (previous !== undefined && !managed) {
|
|
98
|
-
fileSystem.writeText(baseFile, previous);
|
|
99
|
-
}
|
|
100
|
-
fileSystem.writeText(filename, content);
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function checkDestination(fileSystem, filename) {
|
|
104
|
-
if (fileSystem.exists(filename) && fileSystem.realpath(filename) !== filename) {
|
|
105
|
-
(0, files_1.fail)(`Cannot write through a symbolic link: ${filename}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function planProjectFiles(fileSystem, model) {
|
|
109
|
-
const config = resolveInput(fileSystem, model, model.options.doubaoConfig, configName);
|
|
110
|
-
const manifest = resolveInput(fileSystem, model, model.options.manifest, manifestName);
|
|
111
|
-
const writeConfig = planConfig(fileSystem, model.outputRoot, config);
|
|
112
|
-
const targetManifest = node_path_1.default.join(model.outputRoot, manifestName);
|
|
113
|
-
if (manifest) {
|
|
114
|
-
checkDestination(fileSystem, targetManifest);
|
|
115
|
-
}
|
|
116
|
-
const manifestText = manifest && fileSystem.readText(manifest);
|
|
117
|
-
return {
|
|
118
|
-
hasConfig: Boolean(config),
|
|
119
|
-
write() {
|
|
120
|
-
if (writeConfig) {
|
|
121
|
-
writeConfig();
|
|
122
|
-
}
|
|
123
|
-
if (manifestText !== undefined) {
|
|
124
|
-
fileSystem.writeText(targetManifest, manifestText);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=project-files.js.map
|
package/dist/project.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { readConfig } from './config';
|
|
2
|
-
import type { FileSystem } from './file-system';
|
|
3
|
-
import type { PxTransformOptions } from './pxtransform';
|
|
4
|
-
export interface Options {
|
|
5
|
-
appId: string;
|
|
6
|
-
name?: string;
|
|
7
|
-
pxtransform?: boolean | PxTransformOptions;
|
|
8
|
-
doubaoConfig?: string;
|
|
9
|
-
manifest?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface ProjectOptions extends Options {
|
|
12
|
-
appPath: string;
|
|
13
|
-
sourceRoot?: string;
|
|
14
|
-
outputRoot?: string;
|
|
15
|
-
alias?: Record<string, string>;
|
|
16
|
-
env?: Record<string, unknown>;
|
|
17
|
-
defineConstants?: Record<string, unknown>;
|
|
18
|
-
designWidth?: PxTransformOptions['designWidth'];
|
|
19
|
-
deviceRatio?: PxTransformOptions['deviceRatio'];
|
|
20
|
-
}
|
|
21
|
-
export interface PackageInfo {
|
|
22
|
-
name?: string;
|
|
23
|
-
}
|
|
24
|
-
/** Version recorded in the generated source report. */
|
|
25
|
-
export interface PluginInfo {
|
|
26
|
-
version: string;
|
|
27
|
-
}
|
|
28
|
-
export declare const marker = ".doubao-generated.json";
|
|
29
|
-
export declare const generator = "@doubao-dev/taro-plugin-platform-doubao";
|
|
30
|
-
/** Everything the later stages need to know about the input project; produced without writing anything. */
|
|
31
|
-
export interface ProjectModel {
|
|
32
|
-
options: ProjectOptions;
|
|
33
|
-
project: string;
|
|
34
|
-
sourceRoot: string;
|
|
35
|
-
outputRoot: string;
|
|
36
|
-
appFile: string;
|
|
37
|
-
appConfig: ReturnType<typeof readConfig>;
|
|
38
|
-
pages: string[];
|
|
39
|
-
pageFiles: string[];
|
|
40
|
-
styles: string[];
|
|
41
|
-
ambientDeclarations: string[];
|
|
42
|
-
defines: Record<string, string>;
|
|
43
|
-
resolveLocal(from: string, specifier: string): string | undefined;
|
|
44
|
-
packageInfo: PackageInfo;
|
|
45
|
-
pluginInfo: PluginInfo;
|
|
46
|
-
}
|
|
47
|
-
export declare function analyzeProject(options: ProjectOptions, fileSystem: FileSystem): ProjectModel;
|
|
48
|
-
//# sourceMappingURL=project.d.ts.map
|