@doubao-dev/taro-plugin-platform-doubao 0.10.2 → 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.
Files changed (80) hide show
  1. package/README.md +57 -152
  2. package/dist/compiler.d.ts +23 -13
  3. package/dist/compiler.js +44 -45
  4. package/dist/emit/index.d.ts +11 -0
  5. package/dist/emit/index.js +63 -0
  6. package/dist/index.js +8 -16
  7. package/dist/plans/host-deps.d.ts +45 -0
  8. package/dist/plans/host-deps.js +246 -0
  9. package/dist/plans/project-files.d.ts +8 -0
  10. package/dist/plans/project-files.js +309 -0
  11. package/dist/plans/pxtransform.d.ts +6 -0
  12. package/dist/{pxtransform.js → plans/pxtransform.js} +14 -17
  13. package/dist/plans/scaffold.d.ts +10 -0
  14. package/dist/plans/scaffold.js +114 -0
  15. package/dist/plans/sources/class-components.d.ts +11 -0
  16. package/dist/{class-components.js → plans/sources/class-components.js} +171 -59
  17. package/dist/plans/sources/dead-branches.d.ts +36 -0
  18. package/dist/plans/sources/dead-branches.js +415 -0
  19. package/dist/plans/sources/index.d.ts +36 -0
  20. package/dist/plans/sources/index.js +57 -0
  21. package/dist/plans/sources/styles.d.ts +7 -0
  22. package/dist/plans/sources/styles.js +111 -0
  23. package/dist/plans/sources/transform.d.ts +9 -0
  24. package/dist/plans/sources/transform.js +396 -0
  25. package/dist/plans/sources/vendor/bundle.d.ts +23 -0
  26. package/dist/plans/sources/vendor/bundle.js +221 -0
  27. package/dist/plans/sources/vendor/class-loader.d.ts +9 -0
  28. package/dist/plans/sources/vendor/class-loader.js +41 -0
  29. package/dist/plans/sources/vendor/index.d.ts +34 -0
  30. package/dist/plans/sources/vendor/index.js +62 -0
  31. package/dist/plans/sources/vendor/manifest.d.ts +43 -0
  32. package/dist/plans/sources/vendor/manifest.js +182 -0
  33. package/dist/plans/sources/vendor/output.d.ts +4 -0
  34. package/dist/plans/sources/vendor/output.js +68 -0
  35. package/dist/project/app.d.ts +3 -0
  36. package/dist/project/app.js +160 -0
  37. package/dist/project/defines.d.ts +3 -0
  38. package/dist/project/defines.js +89 -0
  39. package/dist/project/imports.d.ts +95 -0
  40. package/dist/project/imports.js +122 -0
  41. package/dist/project/index.d.ts +82 -0
  42. package/dist/project/index.js +182 -0
  43. package/dist/project/program.d.ts +15 -0
  44. package/dist/project/program.js +60 -0
  45. package/dist/project/resolver.d.ts +24 -0
  46. package/dist/project/resolver.js +96 -0
  47. package/dist/runner.d.ts +3 -2
  48. package/dist/runner.js +6 -4
  49. package/dist/shared/errors.d.ts +6 -0
  50. package/dist/shared/errors.js +16 -0
  51. package/dist/shared/layout.d.ts +32 -0
  52. package/dist/shared/layout.js +85 -0
  53. package/dist/shared/paths.d.ts +16 -0
  54. package/dist/shared/paths.js +83 -0
  55. package/dist/shared/syntax.d.ts +31 -0
  56. package/dist/shared/syntax.js +276 -0
  57. package/dist/verify.d.ts +4 -0
  58. package/dist/verify.js +35 -0
  59. package/package.json +3 -1
  60. package/dist/class-components.d.ts +0 -6
  61. package/dist/config.d.ts +0 -8
  62. package/dist/config.js +0 -274
  63. package/dist/file-system.d.ts +0 -21
  64. package/dist/file-system.js +0 -42
  65. package/dist/files.d.ts +0 -24
  66. package/dist/files.js +0 -256
  67. package/dist/platform-branches.d.ts +0 -4
  68. package/dist/platform-branches.js +0 -122
  69. package/dist/project-files.d.ts +0 -7
  70. package/dist/project-files.js +0 -129
  71. package/dist/project.d.ts +0 -48
  72. package/dist/project.js +0 -314
  73. package/dist/pxtransform.d.ts +0 -17
  74. package/dist/scaffold.d.ts +0 -15
  75. package/dist/scaffold.js +0 -103
  76. package/dist/transform.d.ts +0 -11
  77. package/dist/transform.js +0 -318
  78. package/dist/validate.d.ts +0 -4
  79. package/dist/validate.js +0 -27
  80. package/templates/taro.defines.ts +0 -2
package/dist/project.js DELETED
@@ -1,314 +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.generator = exports.marker = void 0;
7
- exports.analyzeProject = analyzeProject;
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const typescript_1 = __importDefault(require("typescript"));
10
- const config_1 = require("./config");
11
- const files_1 = require("./files");
12
- exports.marker = '.doubao-generated.json';
13
- exports.generator = '@doubao-dev/taro-plugin-platform-doubao';
14
- function isPlainObject(value) {
15
- if (typeof value !== 'object' || value === null || Array.isArray(value)) {
16
- return false;
17
- }
18
- const prototype = Object.getPrototypeOf(value);
19
- return prototype === Object.prototype || prototype === null;
20
- }
21
- function formatInlineDefineValue(key, value, seen) {
22
- if (typeof value === 'string') {
23
- if (!value.trim()) {
24
- (0, files_1.fail)(`Invalid empty define expression for ${key}`);
25
- }
26
- return value;
27
- }
28
- if (typeof value === 'number') {
29
- return Object.is(value, -0) ? '-0' : String(value);
30
- }
31
- if (typeof value === 'boolean' || value === null) {
32
- return String(value);
33
- }
34
- if (Array.isArray(value)) {
35
- if (seen.has(value)) {
36
- (0, files_1.fail)(`Circular define value for ${key}`);
37
- }
38
- const nextSeen = new Set(seen);
39
- nextSeen.add(value);
40
- const elements = value.map((item) => item === undefined ? 'undefined' : formatInlineDefineValue(key, item, nextSeen));
41
- return `[${elements.join(', ')}]`;
42
- }
43
- if (isPlainObject(value)) {
44
- if (seen.has(value)) {
45
- (0, files_1.fail)(`Circular define value for ${key}`);
46
- }
47
- const nextSeen = new Set(seen);
48
- nextSeen.add(value);
49
- const properties = Object.entries(value)
50
- .filter(([, subValue]) => subValue !== undefined)
51
- .map(([subKey, subValue]) => `${JSON.stringify(subKey)}: ${formatInlineDefineValue(`${key}.${subKey}`, subValue, nextSeen)}`);
52
- return `{${properties.join(', ')}}`;
53
- }
54
- (0, files_1.fail)(`Unsupported define value for ${key}`);
55
- }
56
- function collectDefineEntry(defines, key, value, seen) {
57
- if (value === undefined) {
58
- return;
59
- }
60
- if (isPlainObject(value)) {
61
- if (seen.has(value)) {
62
- (0, files_1.fail)(`Circular define value for ${key}`);
63
- }
64
- const entries = Object.entries(value).filter(([, subValue]) => subValue !== undefined);
65
- if (!entries.length) {
66
- defines[key] = '{}';
67
- return;
68
- }
69
- const nextSeen = new Set(seen);
70
- nextSeen.add(value);
71
- for (const [subKey, subValue] of entries) {
72
- collectDefineEntry(defines, `${key}.${subKey}`, subValue, nextSeen);
73
- }
74
- return;
75
- }
76
- defines[key] = formatInlineDefineValue(key, value, seen);
77
- }
78
- function buildDefines(env, defineConstants) {
79
- const defines = {};
80
- for (const [key, value] of Object.entries(env ?? {})) {
81
- const targetKey = key.startsWith('process.env.') ? key : `process.env.${key}`;
82
- collectDefineEntry(defines, targetKey, value, new Set());
83
- }
84
- for (const [key, value] of Object.entries(defineConstants ?? {})) {
85
- collectDefineEntry(defines, key, value, new Set());
86
- }
87
- defines['process.env.TARO_ENV'] = JSON.stringify('doubao');
88
- return defines;
89
- }
90
- function rebaseFromCommonAncestor(fileSystem, rawAnchor, realAnchor, targetPath) {
91
- if ((0, files_1.inside)(rawAnchor, targetPath)) {
92
- return node_path_1.default.resolve(realAnchor, node_path_1.default.relative(rawAnchor, targetPath));
93
- }
94
- let ancestor = rawAnchor;
95
- while (!(0, files_1.inside)(ancestor, targetPath)) {
96
- const parent = node_path_1.default.dirname(ancestor);
97
- if (parent === ancestor) {
98
- return targetPath;
99
- }
100
- ancestor = parent;
101
- }
102
- if (!fileSystem.exists(ancestor)) {
103
- return targetPath;
104
- }
105
- return node_path_1.default.resolve(fileSystem.realpath(ancestor), node_path_1.default.relative(ancestor, targetPath));
106
- }
107
- function checkOutput(fileSystem, project, sourceRoot, outputRoot) {
108
- let existingParent = outputRoot;
109
- while (!fileSystem.exists(existingParent)) {
110
- const parent = node_path_1.default.dirname(existingParent);
111
- if (parent === existingParent) {
112
- (0, files_1.fail)(`Output has no existing parent: ${outputRoot}`);
113
- }
114
- existingParent = parent;
115
- }
116
- if (fileSystem.realpath(existingParent) !== existingParent) {
117
- (0, files_1.fail)('Output cannot pass through a symbolic link');
118
- }
119
- if ((0, files_1.inside)(outputRoot, sourceRoot) ||
120
- (0, files_1.inside)(sourceRoot, outputRoot) ||
121
- outputRoot === project ||
122
- !(0, files_1.inside)(project, sourceRoot)) {
123
- (0, files_1.fail)('Source and output directories must be separate; output cannot contain the project source');
124
- }
125
- if (!fileSystem.exists(node_path_1.default.join(outputRoot, 'package.json'))) {
126
- (0, files_1.fail)(`Output must be an existing Doubao project with a package.json: ${outputRoot}. ` +
127
- 'Create one first, for example with `pnpm create @doubao-dev <dir> --template empty`');
128
- }
129
- // Only a previously generated source directory may be replaced.
130
- const targetSource = node_path_1.default.join(outputRoot, 'src');
131
- if (fileSystem.exists(targetSource) && fileSystem.entries(targetSource).length) {
132
- const markerFile = node_path_1.default.join(targetSource, exports.marker);
133
- if (!fileSystem.exists(markerFile) ||
134
- JSON.parse(fileSystem.readText(markerFile)).generator !== exports.generator) {
135
- (0, files_1.fail)(`Refusing to overwrite an unmanaged directory: ${targetSource}. Move or remove it first`);
136
- }
137
- }
138
- }
139
- function readPages(fileSystem, sourceRoot, appConfig) {
140
- if (!Array.isArray(appConfig.pages) ||
141
- !appConfig.pages.length ||
142
- !appConfig.pages.every((page) => typeof page === 'string')) {
143
- (0, files_1.fail)('app.config pages must be a nonempty array of paths');
144
- }
145
- for (const key of Object.keys(appConfig)) {
146
- if (!['pages', 'window', 'darkMode', 'darkmode'].includes(key)) {
147
- (0, files_1.fail)(`App configuration ${key} is not supported yet`);
148
- }
149
- }
150
- for (const key of ['darkMode', 'darkmode']) {
151
- if (appConfig[key] !== undefined && typeof appConfig[key] !== 'boolean') {
152
- (0, files_1.fail)(`app.config ${key} must be a boolean`);
153
- }
154
- }
155
- if (appConfig.darkMode !== undefined &&
156
- appConfig.darkmode !== undefined &&
157
- appConfig.darkMode !== appConfig.darkmode) {
158
- (0, files_1.fail)('Conflicting darkMode and darkmode in app.config');
159
- }
160
- const pages = appConfig.pages;
161
- if (new Set(pages).size !== pages.length) {
162
- (0, files_1.fail)('Duplicate page paths in app.config');
163
- }
164
- const pageFiles = pages.map((page) => {
165
- if (node_path_1.default.posix.normalize(page) !== page ||
166
- page.startsWith('/') ||
167
- page.includes('\\') ||
168
- page.startsWith('..') ||
169
- /\.[jt]sx?$/.test(page)) {
170
- (0, files_1.fail)(`Invalid page path: ${page}`);
171
- }
172
- const filename = node_path_1.default.join(sourceRoot, page);
173
- return ((0, files_1.resolveSource)(fileSystem, `${filename}.doubao`) ??
174
- (0, files_1.resolveSource)(fileSystem, filename) ??
175
- (0, files_1.fail)(`Missing page: ${page}`));
176
- });
177
- return { pages, pageFiles };
178
- }
179
- function createLocalResolver(fileSystem, rawProject, project, sourceRoot, outputRoot, aliasOption) {
180
- const aliases = Object.entries(aliasOption ?? {})
181
- .map(([rawKey, rawValue]) => {
182
- const key = rawKey === '/' ? '/' : rawKey.replace(/\/+$/, '');
183
- const rebased = rebaseFromCommonAncestor(fileSystem, rawProject, project, node_path_1.default.resolve(rawProject, rawValue));
184
- return [key, fileSystem.exists(rebased) ? fileSystem.realpath(rebased) : rebased];
185
- })
186
- .sort(([left], [right]) => right.length - left.length);
187
- const foundConfig = typescript_1.default.findConfigFile(project, (filename) => fileSystem.system.fileExists(filename));
188
- const configFile = foundConfig && (0, files_1.inside)(project, foundConfig) ? foundConfig : undefined;
189
- const parsedConfig = configFile
190
- ? typescript_1.default.parseJsonConfigFileContent(typescript_1.default.readConfigFile(configFile, (filename) => fileSystem.system.readFile(filename)).config, fileSystem.system, node_path_1.default.dirname(configFile))
191
- : undefined;
192
- const compilerOptions = parsedConfig?.options ?? {};
193
- const configDir = configFile ? node_path_1.default.dirname(configFile) : project;
194
- const pathsBaseRaw = compilerOptions.pathsBasePath ?? compilerOptions.baseUrl ?? configDir;
195
- const pathsBase = rebaseFromCommonAncestor(fileSystem, rawProject, project, node_path_1.default.resolve(project, pathsBaseRaw));
196
- const pathEntries = Object.entries(compilerOptions.paths ?? {}).sort(([left], [right]) => {
197
- const leftPrefix = left.includes('*') ? left.indexOf('*') : left.length + 1;
198
- const rightPrefix = right.includes('*') ? right.indexOf('*') : right.length + 1;
199
- return rightPrefix - leftPrefix || right.length - left.length;
200
- });
201
- const resolveFromPaths = (specifier) => {
202
- for (const [pattern, mappings] of pathEntries) {
203
- const starIndex = pattern.indexOf('*');
204
- let matched;
205
- if (starIndex === -1) {
206
- if (specifier !== pattern) {
207
- continue;
208
- }
209
- }
210
- else {
211
- const prefix = pattern.slice(0, starIndex);
212
- const suffix = pattern.slice(starIndex + 1);
213
- if (!specifier.startsWith(prefix) ||
214
- !specifier.endsWith(suffix) ||
215
- specifier.length < prefix.length + suffix.length) {
216
- continue;
217
- }
218
- matched = specifier.slice(prefix.length, suffix.length ? specifier.length - suffix.length : undefined);
219
- }
220
- for (const mapping of mappings) {
221
- const target = matched === undefined ? mapping : mapping.replace('*', matched);
222
- const candidate = rebaseFromCommonAncestor(fileSystem, rawProject, project, node_path_1.default.resolve(pathsBase, target));
223
- const resolved = (0, files_1.resolveSourceOrAsset)(fileSystem, candidate);
224
- if (resolved && (0, files_1.inside)(project, resolved)) {
225
- return resolved;
226
- }
227
- }
228
- }
229
- return undefined;
230
- };
231
- const resolveLocal = (from, specifier) => {
232
- const alias = aliases.find(([name]) => specifier === name || specifier.startsWith(`${name}/`));
233
- if (alias) {
234
- const subpath = specifier.slice(alias[0].length).replace(/^\/+/, '');
235
- return (0, files_1.resolveSourceOrAsset)(fileSystem, node_path_1.default.resolve(alias[1], subpath));
236
- }
237
- if (specifier.startsWith('.')) {
238
- return (0, files_1.resolveSourceOrAsset)(fileSystem, node_path_1.default.resolve(node_path_1.default.dirname(from), specifier));
239
- }
240
- const fromPaths = resolveFromPaths(specifier);
241
- if (fromPaths) {
242
- return fromPaths;
243
- }
244
- const resolvedModule = typescript_1.default.resolveModuleName(specifier, from, compilerOptions, fileSystem.system).resolvedModule;
245
- if (resolvedModule && !resolvedModule.isExternalLibraryImport) {
246
- const rebased = rebaseFromCommonAncestor(fileSystem, rawProject, project, resolvedModule.resolvedFileName);
247
- if ((0, files_1.inside)(project, rebased)) {
248
- return rebased;
249
- }
250
- }
251
- return undefined;
252
- };
253
- const buildConfigDir = node_path_1.default.join(project, 'config');
254
- const ambientDeclarations = (parsedConfig?.fileNames ?? [])
255
- .filter((filename) => files_1.declarationPattern.test(filename))
256
- .map((filename) => rebaseFromCommonAncestor(fileSystem, rawProject, project, node_path_1.default.resolve(filename)))
257
- .filter((filename) => (0, files_1.inside)(project, filename) &&
258
- !(0, files_1.inside)(sourceRoot, filename) &&
259
- !(0, files_1.inside)(outputRoot, filename) &&
260
- !(0, files_1.inside)(buildConfigDir, filename) &&
261
- !filename.split(node_path_1.default.sep).includes('node_modules') &&
262
- fileSystem.exists(filename));
263
- for (const filename of ambientDeclarations) {
264
- if (fileSystem.realpath(filename) !== filename) {
265
- (0, files_1.fail)(`Symbolic links in source assets are unsupported: ${filename}`);
266
- }
267
- }
268
- return {
269
- hasTsConfig: Boolean(configFile),
270
- compilerOptions,
271
- ambientDeclarations: [...new Set(ambientDeclarations)].sort(),
272
- resolveLocal
273
- };
274
- }
275
- function analyzeProject(options, fileSystem) {
276
- if (!options.appId?.trim()) {
277
- (0, files_1.fail)('Configure appId in the platform plugin options');
278
- }
279
- const rawProject = node_path_1.default.resolve(options.appPath);
280
- const project = fileSystem.realpath(rawProject);
281
- const sourceRoot = fileSystem.realpath(node_path_1.default.resolve(project, options.sourceRoot ?? 'src'));
282
- const outputRoot = rebaseFromCommonAncestor(fileSystem, rawProject, project, node_path_1.default.resolve(rawProject, options.outputRoot ?? 'dist/doubao'));
283
- checkOutput(fileSystem, project, sourceRoot, outputRoot);
284
- const { ambientDeclarations, resolveLocal } = createLocalResolver(fileSystem, rawProject, project, sourceRoot, outputRoot, options.alias);
285
- const appConfigFile = (0, files_1.resolveSource)(fileSystem, node_path_1.default.join(sourceRoot, 'app.config')) ?? (0, files_1.fail)('Missing app.config.ts');
286
- const appConfig = (0, config_1.readConfig)(fileSystem, appConfigFile, 'defineAppConfig', (from, specifier) => {
287
- const resolved = resolveLocal(from, specifier);
288
- if (resolved && !(0, files_1.inside)(sourceRoot, resolved)) {
289
- (0, files_1.fail)(`Local import leaves sourceRoot: ${resolved}`);
290
- }
291
- return resolved;
292
- });
293
- const { pages, pageFiles } = readPages(fileSystem, sourceRoot, appConfig);
294
- const appFile = (0, files_1.resolveSource)(fileSystem, node_path_1.default.join(sourceRoot, 'app')) ?? (0, files_1.fail)('Missing app.tsx');
295
- const styles = (0, config_1.appStyles)(fileSystem, appFile);
296
- const defines = buildDefines(options.env, options.defineConstants);
297
- return {
298
- options,
299
- project,
300
- sourceRoot,
301
- outputRoot,
302
- appFile,
303
- appConfig,
304
- pages,
305
- pageFiles,
306
- styles,
307
- ambientDeclarations,
308
- defines,
309
- resolveLocal,
310
- packageInfo: JSON.parse(fileSystem.readText(node_path_1.default.join(project, 'package.json'))),
311
- pluginInfo: JSON.parse(fileSystem.readText(node_path_1.default.join(__dirname, '..', 'package.json')))
312
- };
313
- }
314
- //# sourceMappingURL=project.js.map
@@ -1,17 +0,0 @@
1
- import type { Input } from 'postcss';
2
- import type { ProjectOptions } from './project';
3
- export interface PxTransformOptions {
4
- designWidth?: number | ((input: Input) => number);
5
- deviceRatio?: Record<number, number>;
6
- propList?: string[];
7
- selectorBlackList?: (string | RegExp)[];
8
- onePxTransform?: boolean;
9
- minPixelValue?: number;
10
- unitPrecision?: number;
11
- mediaQuery?: boolean;
12
- exclude?: (filename: string) => boolean;
13
- }
14
- /** PostCSS runs in the output project, after its stylesheet preprocessors. */
15
- export declare function renderPostcssConfig(options: ProjectOptions): string | undefined;
16
- export declare function renderPxTransformSetup(options: ProjectOptions): string;
17
- //# sourceMappingURL=pxtransform.d.ts.map
@@ -1,15 +0,0 @@
1
- import type { FileSystem } from './file-system';
2
- import type { ProjectModel } from './project';
3
- /** Writes the app entry, app configuration, Taro declarations and define constants into `targetSource`. */
4
- export declare function writeScaffold(fileSystem: FileSystem, targetSource: string, model: ProjectModel): void;
5
- /** Define constants only apply through the build config, which the user owns. */
6
- export declare function checkDefineConfig(fileSystem: FileSystem, outputRoot: string): string[];
7
- /** Update only generated configuration; preserve user-owned and inherited configuration. */
8
- export declare function planPostcssConfig(fileSystem: FileSystem, outputRoot: string, content: string | undefined): {
9
- warnings: string[];
10
- update?: {
11
- filename: string;
12
- content: string | undefined;
13
- };
14
- };
15
- //# sourceMappingURL=scaffold.d.ts.map
package/dist/scaffold.js DELETED
@@ -1,103 +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.writeScaffold = writeScaffold;
7
- exports.checkDefineConfig = checkDefineConfig;
8
- exports.planPostcssConfig = planPostcssConfig;
9
- const node_os_1 = require("node:os");
10
- const node_path_1 = __importDefault(require("node:path"));
11
- const files_1 = require("./files");
12
- /** Files written into the generated `src/`, alongside the transformed sources. */
13
- const templateRoot = node_path_1.default.join(__dirname, '..', 'templates');
14
- const definesModule = 'taro.defines';
15
- const configNames = ['doubao.config.ts', 'doubao.config.mts', 'doubao.config.js', 'doubao.config.mjs'];
16
- /** Serializes a value for a template placeholder. */
17
- function formatPlaceholder(value) {
18
- return JSON.stringify(value, null, 2);
19
- }
20
- /** Writes the app entry, app configuration, Taro declarations and define constants into `targetSource`. */
21
- function writeScaffold(fileSystem, targetSource, model) {
22
- const { options, packageInfo, appConfig, pages } = model;
23
- const darkMode = appConfig.darkMode ?? appConfig.darkmode;
24
- const appConfigValue = {
25
- appId: options.appId,
26
- name: options.name ?? packageInfo.name ?? options.appId,
27
- pages,
28
- ...(typeof darkMode === 'boolean' ? { darkMode } : {})
29
- };
30
- const placeholders = {
31
- __APP_CONFIG__: formatPlaceholder(appConfigValue),
32
- __DEFINES__: formatPlaceholder(model.defines)
33
- };
34
- for (const entry of fileSystem.entries(templateRoot)) {
35
- const target = node_path_1.default.join(targetSource, entry.name);
36
- if (fileSystem.exists(target)) {
37
- (0, files_1.fail)(`Source file conflicts with a generated file: ${entry.name}`);
38
- }
39
- const content = fileSystem
40
- .readText(node_path_1.default.join(templateRoot, entry.name))
41
- .replaceAll(/__[A-Z_]+__/g, (key) => placeholders[key] ?? key);
42
- fileSystem.writeText(target, content);
43
- }
44
- }
45
- /** Define constants only apply through the build config, which the user owns. */
46
- function checkDefineConfig(fileSystem, outputRoot) {
47
- const configFile = configNames
48
- .map((name) => node_path_1.default.join(outputRoot, name))
49
- .find((name) => fileSystem.exists(name));
50
- if (configFile && fileSystem.readText(configFile).includes(definesModule)) {
51
- return [];
52
- }
53
- return [
54
- `${configFile ? node_path_1.default.basename(configFile) : 'doubao.config.ts'} does not use src/${definesModule}.ts; ` +
55
- `import it and set \`source: { define: defines }\` so Taro env and defineConstants apply`
56
- ];
57
- }
58
- const postcssMarker = '// Generated by @doubao-dev/taro-plugin-platform-doubao.\n';
59
- /** Update only generated configuration; preserve user-owned and inherited configuration. */
60
- function planPostcssConfig(fileSystem, outputRoot, content) {
61
- const filename = node_path_1.default.join(outputRoot, 'postcss.config.cjs');
62
- const previous = fileSystem.exists(filename) ? fileSystem.readText(filename) : '';
63
- const owned = previous.startsWith(postcssMarker) ||
64
- previous === "module.exports = require('./src/__taro_compat__/postcss.cjs');\n";
65
- if (content === undefined) {
66
- return { warnings: [], ...(owned ? { update: { filename, content } } : {}) };
67
- }
68
- const extensions = ['ts', 'cts', 'mts', 'js', 'cjs', 'mjs'];
69
- const names = [
70
- '.postcssrc',
71
- ...['json', 'yaml', 'yml', ...extensions].map((extension) => `.postcssrc.${extension}`),
72
- ...extensions.map((extension) => `postcss.config.${extension}`)
73
- ];
74
- let existing;
75
- // Match PostCSS's upward search, including package.json configuration.
76
- for (let directory = outputRoot;; directory = node_path_1.default.dirname(directory)) {
77
- const packageFile = node_path_1.default.join(directory, 'package.json');
78
- const packageInfo = fileSystem.exists(packageFile)
79
- ? JSON.parse(fileSystem.readText(packageFile))
80
- : undefined;
81
- existing = packageInfo?.postcss
82
- ? packageFile
83
- : names
84
- .map((name) => node_path_1.default.join(directory, name))
85
- .find((name) => fileSystem.exists(name) && fileSystem.readText(name).trim());
86
- if (existing || directory === (0, node_os_1.homedir)() || directory === node_path_1.default.dirname(directory)) {
87
- break;
88
- }
89
- }
90
- if (existing && !(existing === filename && owned)) {
91
- return {
92
- warnings: [`Configure postcss-pxtransform in ${existing} to enable Taro unit conversion`]
93
- };
94
- }
95
- return {
96
- warnings: [],
97
- update: {
98
- filename,
99
- content: `${postcssMarker}// Remove the generated marker above to maintain this file manually.\n${content}`
100
- }
101
- };
102
- }
103
- //# sourceMappingURL=scaffold.js.map
@@ -1,11 +0,0 @@
1
- import type { FileSystem } from './file-system';
2
- import type { ProjectModel } from './project';
3
- export interface TransformResult {
4
- /** Source files reachable from the pages, relative to the source root. */
5
- sourceFiles: string[];
6
- }
7
- /** Generated directory for global declarations that live outside the source root. */
8
- export declare const ambientDirectory = "taro-types";
9
- /** Rewrites the application sources reachable from the pages into `targetSource` (the generated `src/`). */
10
- export declare function transformSources(fileSystem: FileSystem, model: ProjectModel, targetSource: string): TransformResult;
11
- //# sourceMappingURL=transform.d.ts.map