@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.
- 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,246 @@
|
|
|
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.DependencyClassifier = void 0;
|
|
7
|
+
exports.extractPackageName = extractPackageName;
|
|
8
|
+
exports.planHostDependencies = planHostDependencies;
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_module_1 = require("node:module");
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const semver_1 = __importDefault(require("semver"));
|
|
13
|
+
const errors_1 = require("../shared/errors");
|
|
14
|
+
const nodeBuiltinNames = new Set([
|
|
15
|
+
...node_module_1.builtinModules,
|
|
16
|
+
...node_module_1.builtinModules.map((name) => name.replace(/^node:/, ''))
|
|
17
|
+
]);
|
|
18
|
+
const ignoredScanDirs = new Set([
|
|
19
|
+
'node_modules',
|
|
20
|
+
'test',
|
|
21
|
+
'tests',
|
|
22
|
+
'__tests__',
|
|
23
|
+
'docs',
|
|
24
|
+
'examples',
|
|
25
|
+
'coverage'
|
|
26
|
+
]);
|
|
27
|
+
function isRegistrySemverRange(spec) {
|
|
28
|
+
const trimmed = spec?.trim();
|
|
29
|
+
return Boolean(trimmed &&
|
|
30
|
+
!/^(?:workspace:|catalog:|file:|link:|portal:|patch:|npm:|jsr:|git(?:\+[a-z]+)?:|git@|ssh:|https?:|github:)/i.test(trimmed) &&
|
|
31
|
+
semver_1.default.validRange(trimmed));
|
|
32
|
+
}
|
|
33
|
+
function rangesCompatible(a, b) {
|
|
34
|
+
return (a.trim() === b.trim() ||
|
|
35
|
+
Boolean(semver_1.default.validRange(a) && semver_1.default.validRange(b) && semver_1.default.intersects(a, b, { includePrerelease: true })));
|
|
36
|
+
}
|
|
37
|
+
function selectPreferredRange(existingRange, incomingRange) {
|
|
38
|
+
const minExisting = semver_1.default.minVersion(existingRange);
|
|
39
|
+
const minIncoming = semver_1.default.minVersion(incomingRange);
|
|
40
|
+
return minExisting && minIncoming && semver_1.default.gt(minIncoming, minExisting) ? incomingRange : existingRange;
|
|
41
|
+
}
|
|
42
|
+
/** Extracts the npm package name (`@scope/pkg` or `pkg`) from a bare module specifier. */
|
|
43
|
+
function extractPackageName(specifier) {
|
|
44
|
+
const clean = specifier.replace(/[?#].*$/, '');
|
|
45
|
+
if (clean.startsWith('@')) {
|
|
46
|
+
const parts = clean.split('/');
|
|
47
|
+
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : clean;
|
|
48
|
+
}
|
|
49
|
+
return clean.split('/')[0];
|
|
50
|
+
}
|
|
51
|
+
function readJsonSafe(filename) {
|
|
52
|
+
try {
|
|
53
|
+
return node_fs_1.default.existsSync(filename)
|
|
54
|
+
? JSON.parse(node_fs_1.default.readFileSync(filename, 'utf8'))
|
|
55
|
+
: undefined;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function findPackageDirectory(packageName, startDir) {
|
|
62
|
+
for (let current = startDir;;) {
|
|
63
|
+
const candidate = node_path_1.default.join(current, 'node_modules', ...packageName.split('/'));
|
|
64
|
+
if (node_fs_1.default.existsSync(node_path_1.default.join(candidate, 'package.json'))) {
|
|
65
|
+
return candidate;
|
|
66
|
+
}
|
|
67
|
+
const parent = node_path_1.default.dirname(current);
|
|
68
|
+
if (parent === current) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
current = parent;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function collectPackageScriptFiles(pkgDir) {
|
|
75
|
+
const files = [];
|
|
76
|
+
const queue = [pkgDir];
|
|
77
|
+
while (queue.length) {
|
|
78
|
+
const dir = queue.shift();
|
|
79
|
+
let entries;
|
|
80
|
+
try {
|
|
81
|
+
entries = node_fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
if (entry.name.startsWith('.') || ignoredScanDirs.has(entry.name)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const full = node_path_1.default.join(dir, entry.name);
|
|
91
|
+
if (entry.isDirectory()) {
|
|
92
|
+
queue.push(full);
|
|
93
|
+
}
|
|
94
|
+
else if (/\.[cm]?[jt]sx?$/.test(entry.name) && !/\.d\.[cm]?ts$/.test(entry.name)) {
|
|
95
|
+
files.push(full);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return files;
|
|
100
|
+
}
|
|
101
|
+
class DependencyClassifier {
|
|
102
|
+
vendorOverrides;
|
|
103
|
+
directDependencies;
|
|
104
|
+
pkgDecisionCache = new Map();
|
|
105
|
+
recordedHostPackages = new Map();
|
|
106
|
+
constructor(options) {
|
|
107
|
+
this.vendorOverrides = new Set(options.vendorPackages ?? []);
|
|
108
|
+
this.directDependencies = new Map(Object.entries(options.sourcePackageJson.dependencies ?? {}));
|
|
109
|
+
}
|
|
110
|
+
get hostPackages() {
|
|
111
|
+
return [...this.recordedHostPackages.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
112
|
+
}
|
|
113
|
+
classify(specifier, importer, recordUsage = true) {
|
|
114
|
+
const pkgName = extractPackageName(specifier);
|
|
115
|
+
if (this.vendorOverrides.has(pkgName) || nodeBuiltinNames.has(pkgName) || specifier.startsWith('node:')) {
|
|
116
|
+
return 'vendor';
|
|
117
|
+
}
|
|
118
|
+
const declaredSpec = this.directDependencies.get(pkgName);
|
|
119
|
+
if (!isRegistrySemverRange(declaredSpec)) {
|
|
120
|
+
return 'vendor';
|
|
121
|
+
}
|
|
122
|
+
const startDir = node_fs_1.default.existsSync(importer) ? node_path_1.default.dirname(importer) : importer;
|
|
123
|
+
const pkgDir = findPackageDirectory(pkgName, startDir);
|
|
124
|
+
if (!pkgDir || this.requiresVendorBundling(pkgDir, new Set()).needed) {
|
|
125
|
+
return 'vendor';
|
|
126
|
+
}
|
|
127
|
+
if (recordUsage && !this.recordedHostPackages.has(pkgName)) {
|
|
128
|
+
this.recordedHostPackages.set(pkgName, { name: pkgName, range: declaredSpec });
|
|
129
|
+
}
|
|
130
|
+
return 'host';
|
|
131
|
+
}
|
|
132
|
+
requiresVendorBundling(pkgDir, visiting) {
|
|
133
|
+
let realDir;
|
|
134
|
+
try {
|
|
135
|
+
realDir = node_fs_1.default.realpathSync(pkgDir);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return { needed: true, hitCycle: false };
|
|
139
|
+
}
|
|
140
|
+
const cached = this.pkgDecisionCache.get(realDir);
|
|
141
|
+
if (cached !== undefined) {
|
|
142
|
+
return { needed: cached, hitCycle: false };
|
|
143
|
+
}
|
|
144
|
+
if (visiting.has(realDir)) {
|
|
145
|
+
return { needed: false, hitCycle: true };
|
|
146
|
+
}
|
|
147
|
+
const nextVisiting = new Set(visiting).add(realDir);
|
|
148
|
+
const finish = (needed, hitCycle = false) => {
|
|
149
|
+
if (needed || !hitCycle) {
|
|
150
|
+
this.pkgDecisionCache.set(realDir, needed);
|
|
151
|
+
}
|
|
152
|
+
return { needed, hitCycle };
|
|
153
|
+
};
|
|
154
|
+
if (!realDir.split(node_path_1.default.sep).includes('node_modules')) {
|
|
155
|
+
return finish(true);
|
|
156
|
+
}
|
|
157
|
+
const manifest = readJsonSafe(node_path_1.default.join(realDir, 'package.json'));
|
|
158
|
+
if (!manifest ||
|
|
159
|
+
manifest.name?.startsWith('@tarojs/') ||
|
|
160
|
+
[manifest.module, manifest.main].some((entry) => typeof entry === 'string' && /\.[jt]sx$/i.test(entry))) {
|
|
161
|
+
return finish(true);
|
|
162
|
+
}
|
|
163
|
+
const depNames = new Set(Object.keys(manifest.dependencies ?? {}));
|
|
164
|
+
for (const [peerName, peerRange] of Object.entries(manifest.peerDependencies ?? {})) {
|
|
165
|
+
if (!manifest.peerDependenciesMeta?.[peerName]?.optional && peerRange) {
|
|
166
|
+
depNames.add(peerName);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (const scriptFile of collectPackageScriptFiles(realDir)) {
|
|
170
|
+
if (/\.[jt]sx$/i.test(scriptFile)) {
|
|
171
|
+
return finish(true);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
let hitCycle = false;
|
|
175
|
+
for (const depName of depNames) {
|
|
176
|
+
if (depName === 'react' || depName === 'react-dom' || depName.startsWith('@doubao-dev/')) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const childDir = findPackageDirectory(depName, realDir);
|
|
180
|
+
if (childDir) {
|
|
181
|
+
const child = this.requiresVendorBundling(childDir, nextVisiting);
|
|
182
|
+
if (child.needed) {
|
|
183
|
+
return finish(true);
|
|
184
|
+
}
|
|
185
|
+
hitCycle ||= child.hitCycle;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return finish(false, hitCycle);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.DependencyClassifier = DependencyClassifier;
|
|
192
|
+
function planHostDependencies(options) {
|
|
193
|
+
const { appPath, outputPath, requirements, syncDeps, autoInitializedHost } = options;
|
|
194
|
+
const pkgFile = node_path_1.default.join(outputPath, 'package.json');
|
|
195
|
+
if (!requirements.length || autoInitializedHost || !node_fs_1.default.existsSync(pkgFile)) {
|
|
196
|
+
return { warnings: [], commit() { } };
|
|
197
|
+
}
|
|
198
|
+
const hostPkg = JSON.parse(node_fs_1.default.readFileSync(pkgFile, 'utf8'));
|
|
199
|
+
const existingDeps = { ...(hostPkg.dependencies ?? {}) };
|
|
200
|
+
const existingDevDeps = hostPkg.devDependencies ?? {};
|
|
201
|
+
const missingSpecs = [];
|
|
202
|
+
let mutated = false;
|
|
203
|
+
for (const { name, range } of requirements) {
|
|
204
|
+
const currentRange = existingDeps[name] ?? existingDevDeps[name];
|
|
205
|
+
if (!currentRange) {
|
|
206
|
+
if (syncDeps) {
|
|
207
|
+
existingDeps[name] = range;
|
|
208
|
+
mutated = true;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
missingSpecs.push(/[\s^~><=|*]/.test(range) ? `${name}@'${range}'` : `${name}@${range}`);
|
|
212
|
+
}
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (!isRegistrySemverRange(currentRange) || !isRegistrySemverRange(range)) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!rangesCompatible(currentRange, range)) {
|
|
219
|
+
(0, errors_1.fail)(`Dependency version conflict for "${name}": host package.json has "${currentRange}", ` +
|
|
220
|
+
`but Taro project requires "${range}". Align the version or add "${name}" to vendorPackages`);
|
|
221
|
+
}
|
|
222
|
+
if (syncDeps && existingDeps[name] && isRegistrySemverRange(existingDeps[name])) {
|
|
223
|
+
const preferred = selectPreferredRange(existingDeps[name], range);
|
|
224
|
+
if (preferred !== existingDeps[name]) {
|
|
225
|
+
existingDeps[name] = preferred;
|
|
226
|
+
mutated = true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const relOut = node_path_1.default.relative(appPath, outputPath) || '.';
|
|
231
|
+
return {
|
|
232
|
+
warnings: missingSpecs.length
|
|
233
|
+
? [
|
|
234
|
+
`Missing dependencies in ${relOut}/package.json (lockfile preserved): ` +
|
|
235
|
+
`run \`pnpm --dir ${relOut} add ${missingSpecs.join(' ')}\` or set \`syncDeps: true\``
|
|
236
|
+
]
|
|
237
|
+
: [],
|
|
238
|
+
commit() {
|
|
239
|
+
if (syncDeps && mutated) {
|
|
240
|
+
const dependencies = Object.fromEntries(Object.entries(existingDeps).sort(([a], [b]) => a.localeCompare(b)));
|
|
241
|
+
node_fs_1.default.writeFileSync(pkgFile, `${JSON.stringify({ ...hostPkg, dependencies }, null, 2)}\n`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=host-deps.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IPluginContext } from '@tarojs/service';
|
|
2
|
+
import type { ProjectModel } from '../project';
|
|
3
|
+
import { type HostPackageRequirement } from './host-deps';
|
|
4
|
+
export declare function planProjectFiles(ctx: IPluginContext, model: ProjectModel, hostPackages: HostPackageRequirement[]): {
|
|
5
|
+
warnings: string[];
|
|
6
|
+
commit(): void;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=project-files.d.ts.map
|
|
@@ -0,0 +1,309 @@
|
|
|
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_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_os_1 = require("node:os");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
11
|
+
const emit_1 = require("../emit");
|
|
12
|
+
const imports_1 = require("../project/imports");
|
|
13
|
+
const errors_1 = require("../shared/errors");
|
|
14
|
+
const layout_1 = require("../shared/layout");
|
|
15
|
+
const paths_1 = require("../shared/paths");
|
|
16
|
+
const syntax_1 = require("../shared/syntax");
|
|
17
|
+
const host_deps_1 = require("./host-deps");
|
|
18
|
+
const pxtransform_1 = require("./pxtransform");
|
|
19
|
+
const configName = 'doubao.config.ts';
|
|
20
|
+
const manifestName = 'manifest.yaml';
|
|
21
|
+
const templateRoot = node_path_1.default.join(__dirname, '..', '..', 'templates');
|
|
22
|
+
const configExtensions = ['.ts', '.mts', '.js', '.mjs'];
|
|
23
|
+
function resolveInput({ appPath, outputPath }, option, name) {
|
|
24
|
+
const filename = node_path_1.default.resolve(appPath, option ?? name);
|
|
25
|
+
if (!node_fs_1.default.existsSync(filename)) {
|
|
26
|
+
if (option !== undefined) {
|
|
27
|
+
(0, errors_1.fail)(`Missing project file: ${filename}`);
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const resolved = node_fs_1.default.realpathSync(filename);
|
|
32
|
+
if ((0, paths_1.inside)(outputPath, resolved)) {
|
|
33
|
+
(0, errors_1.fail)(`Project file must be outside the output project: ${filename}`);
|
|
34
|
+
}
|
|
35
|
+
return resolved;
|
|
36
|
+
}
|
|
37
|
+
function checkDestination(filename) {
|
|
38
|
+
if (node_fs_1.default.existsSync(filename) && node_fs_1.default.realpathSync(filename) !== filename) {
|
|
39
|
+
(0, errors_1.fail)(`Cannot write through a symbolic link: ${filename}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function assertStandaloneSourceConfig(sourceFile) {
|
|
43
|
+
const parsed = (0, syntax_1.readSource)(sourceFile);
|
|
44
|
+
const visit = (node) => {
|
|
45
|
+
const literal = (0, syntax_1.moduleName)(node);
|
|
46
|
+
if (literal?.text.startsWith('.')) {
|
|
47
|
+
(0, errors_1.fail)(`Source ${node_path_1.default.basename(sourceFile)} cannot use relative import "${literal.text}"`);
|
|
48
|
+
}
|
|
49
|
+
typescript_1.default.forEachChild(node, visit);
|
|
50
|
+
};
|
|
51
|
+
typescript_1.default.forEachChild(parsed, visit);
|
|
52
|
+
}
|
|
53
|
+
function buildBaseDoubaoConfig(defines) {
|
|
54
|
+
return {
|
|
55
|
+
taro: true,
|
|
56
|
+
source: { define: defines }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function renderDefaultDoubaoConfig(defines) {
|
|
60
|
+
return `${layout_1.generatedMarker}import { defineConfig } from '${imports_1.runtimeModules.framework}/config';
|
|
61
|
+
|
|
62
|
+
export default defineConfig(${JSON.stringify(buildBaseDoubaoConfig(defines), null, 2)});
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
function renderScaffoldPackageJson(model, hostPackages) {
|
|
66
|
+
const sdkVersion = `^${model.pluginInfo.version}`;
|
|
67
|
+
const dependencies = Object.fromEntries(Object.entries({
|
|
68
|
+
[imports_1.runtimeModules.framework]: sdkVersion,
|
|
69
|
+
[imports_1.runtimeModules.taro]: sdkVersion,
|
|
70
|
+
...Object.fromEntries(hostPackages.map(({ name, range }) => [name, range]))
|
|
71
|
+
}).sort(([a], [b]) => a.localeCompare(b)));
|
|
72
|
+
const devDependencies = Object.fromEntries(Object.entries({
|
|
73
|
+
'@doubao-dev/kit': sdkVersion,
|
|
74
|
+
'@tarojs/components': '4.1.9',
|
|
75
|
+
'@tarojs/taro': '4.1.9',
|
|
76
|
+
'@types/react': '^18.3.0',
|
|
77
|
+
...(model.options.pxtransform ? { 'postcss-pxtransform': '4.1.9' } : {}),
|
|
78
|
+
typescript: '^5.8.0'
|
|
79
|
+
}).sort(([a], [b]) => a.localeCompare(b)));
|
|
80
|
+
const pkgName = (model.options.name ?? model.packageInfo.name ?? model.options.appId ?? 'doubao-app')
|
|
81
|
+
.toLowerCase()
|
|
82
|
+
.replaceAll(/[^a-z0-9._-]/g, '-')
|
|
83
|
+
.replace(/^[._-]+|[._-]+$/g, '') || 'doubao-app';
|
|
84
|
+
return `${JSON.stringify({
|
|
85
|
+
name: `${pkgName}-doubao`,
|
|
86
|
+
private: true,
|
|
87
|
+
type: 'module',
|
|
88
|
+
scripts: { build: 'doubao build', dev: 'doubao dev', typecheck: 'tsc --noEmit' },
|
|
89
|
+
dependencies,
|
|
90
|
+
devDependencies
|
|
91
|
+
}, null, 2)}\n`;
|
|
92
|
+
}
|
|
93
|
+
function renderScaffoldTsConfig() {
|
|
94
|
+
return `${JSON.stringify({
|
|
95
|
+
compilerOptions: {
|
|
96
|
+
target: 'ES2022',
|
|
97
|
+
module: 'ESNext',
|
|
98
|
+
moduleResolution: 'Bundler',
|
|
99
|
+
jsx: 'react-jsx',
|
|
100
|
+
jsxImportSource: imports_1.runtimeModules.framework,
|
|
101
|
+
strict: true,
|
|
102
|
+
skipLibCheck: true,
|
|
103
|
+
esModuleInterop: true,
|
|
104
|
+
resolveJsonModule: true,
|
|
105
|
+
lib: ['ES2022', 'DOM'],
|
|
106
|
+
types: [`${imports_1.runtimeModules.framework}/types`],
|
|
107
|
+
noEmit: true
|
|
108
|
+
},
|
|
109
|
+
include: ['src']
|
|
110
|
+
}, null, 2)}\n`;
|
|
111
|
+
}
|
|
112
|
+
function configImport(importerExt, stem, fileExt) {
|
|
113
|
+
const ext = importerExt === '.mjs' || importerExt === '.mts'
|
|
114
|
+
? fileExt === '.mts'
|
|
115
|
+
? '.mjs'
|
|
116
|
+
: fileExt === '.ts'
|
|
117
|
+
? '.js'
|
|
118
|
+
: fileExt
|
|
119
|
+
: fileExt === '.ts'
|
|
120
|
+
? ''
|
|
121
|
+
: fileExt === '.mts'
|
|
122
|
+
? '.mjs'
|
|
123
|
+
: fileExt;
|
|
124
|
+
return JSON.stringify(`./${stem}${ext}`);
|
|
125
|
+
}
|
|
126
|
+
function planStandaloneConfig(filename, source, defines) {
|
|
127
|
+
const outputPath = node_path_1.default.dirname(filename);
|
|
128
|
+
const targetExt = node_path_1.default.extname(filename);
|
|
129
|
+
const isTyped = targetExt === '.ts' || targetExt === '.mts';
|
|
130
|
+
const baseFile = node_path_1.default.join(outputPath, `doubao.config.local${targetExt}`);
|
|
131
|
+
const copiedCandidates = configExtensions.map((ext) => node_path_1.default.join(outputPath, `doubao.config.source${ext}`));
|
|
132
|
+
const previous = node_fs_1.default.existsSync(filename) ? node_fs_1.default.readFileSync(filename, 'utf8') : undefined;
|
|
133
|
+
const managed = previous?.startsWith(layout_1.generatedMarker);
|
|
134
|
+
if (source || managed) {
|
|
135
|
+
[filename, baseFile, ...copiedCandidates].forEach(checkDestination);
|
|
136
|
+
}
|
|
137
|
+
if (!source) {
|
|
138
|
+
return managed
|
|
139
|
+
? () => {
|
|
140
|
+
copiedCandidates.forEach((f) => node_fs_1.default.existsSync(f) && node_fs_1.default.unlinkSync(f));
|
|
141
|
+
if (node_fs_1.default.existsSync(baseFile)) {
|
|
142
|
+
(0, emit_1.writeText)(filename, node_fs_1.default.readFileSync(baseFile, 'utf8'));
|
|
143
|
+
node_fs_1.default.unlinkSync(baseFile);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
(0, emit_1.writeText)(filename, renderDefaultDoubaoConfig(defines));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
: undefined;
|
|
150
|
+
}
|
|
151
|
+
assertStandaloneSourceConfig(source);
|
|
152
|
+
const srcExt = node_path_1.default.extname(source);
|
|
153
|
+
const transpile = !isTyped && (srcExt === '.ts' || srcExt === '.mts');
|
|
154
|
+
const copiedExt = transpile
|
|
155
|
+
? targetExt
|
|
156
|
+
: isTyped && srcExt === '.ts' && targetExt === '.mts'
|
|
157
|
+
? '.mts'
|
|
158
|
+
: srcExt;
|
|
159
|
+
const copiedFile = node_path_1.default.join(outputPath, `doubao.config.source${copiedExt}`);
|
|
160
|
+
const rawSource = node_fs_1.default.readFileSync(source, 'utf8');
|
|
161
|
+
const sourceBody = transpile
|
|
162
|
+
? typescript_1.default.transpileModule(rawSource, {
|
|
163
|
+
compilerOptions: { target: typescript_1.default.ScriptTarget.ES2022, module: typescript_1.default.ModuleKind.ESNext }
|
|
164
|
+
}).outputText
|
|
165
|
+
: rawSource;
|
|
166
|
+
if (previous !== undefined &&
|
|
167
|
+
!managed &&
|
|
168
|
+
node_fs_1.default.existsSync(baseFile) &&
|
|
169
|
+
node_fs_1.default.readFileSync(baseFile, 'utf8') !== previous) {
|
|
170
|
+
(0, errors_1.fail)(`Cannot preserve the target config because ${baseFile} already exists`);
|
|
171
|
+
}
|
|
172
|
+
const hasBase = (previous !== undefined && !managed) || node_fs_1.default.existsSync(baseFile);
|
|
173
|
+
const rec = isTyped ? ': Record<string, unknown>' : '';
|
|
174
|
+
const unk = isTyped ? ': unknown' : '';
|
|
175
|
+
const pred = isTyped ? ': value is Record<string, unknown>' : '';
|
|
176
|
+
const content = `${layout_1.generatedMarker}import sourceConfig from ${configImport(targetExt, 'doubao.config.source', copiedExt)};
|
|
177
|
+
${hasBase ? `import targetConfig from ${configImport(targetExt, 'doubao.config.local', targetExt)};` : 'const targetConfig = {};'}
|
|
178
|
+
|
|
179
|
+
function mergeConfig(target${rec}, source${rec})${rec} {
|
|
180
|
+
const merged = { ...target };
|
|
181
|
+
for (const [key, value] of Object.entries(source)) {
|
|
182
|
+
const existing = Object.hasOwn(merged, key) ? merged[key] : undefined;
|
|
183
|
+
Object.defineProperty(merged, key, {
|
|
184
|
+
value: isPlainObject(existing) && isPlainObject(value) ? mergeConfig(existing, value) : value,
|
|
185
|
+
enumerable: true,
|
|
186
|
+
configurable: true,
|
|
187
|
+
writable: true
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return merged;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function isPlainObject(value${unk})${pred} {
|
|
194
|
+
return value !== null && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export default mergeConfig(${JSON.stringify(buildBaseDoubaoConfig(defines))}, mergeConfig(targetConfig, sourceConfig));
|
|
198
|
+
`;
|
|
199
|
+
return () => {
|
|
200
|
+
copiedCandidates.forEach((f) => f !== copiedFile && node_fs_1.default.existsSync(f) && node_fs_1.default.unlinkSync(f));
|
|
201
|
+
if (previous !== undefined && !managed) {
|
|
202
|
+
(0, emit_1.writeText)(baseFile, previous);
|
|
203
|
+
}
|
|
204
|
+
(0, emit_1.writeText)(copiedFile, `${layout_1.generatedMarker}${sourceBody}`);
|
|
205
|
+
(0, emit_1.writeText)(filename, content);
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function planProjectFiles(ctx, model, hostPackages) {
|
|
209
|
+
const { appPath, outputPath } = ctx.paths;
|
|
210
|
+
const hostDepsPlan = (0, host_deps_1.planHostDependencies)({
|
|
211
|
+
appPath,
|
|
212
|
+
outputPath,
|
|
213
|
+
requirements: hostPackages,
|
|
214
|
+
syncDeps: model.options.syncDeps,
|
|
215
|
+
autoInitializedHost: model.autoInitializeHost
|
|
216
|
+
});
|
|
217
|
+
if (model.layout.moduleName) {
|
|
218
|
+
const hostTaroEnv = node_path_1.default.join(model.layout.hostSource, 'taro-env.d.ts');
|
|
219
|
+
return {
|
|
220
|
+
warnings: [...hostDepsPlan.warnings],
|
|
221
|
+
commit() {
|
|
222
|
+
if (!node_fs_1.default.existsSync(hostTaroEnv)) {
|
|
223
|
+
const envTemplate = node_fs_1.default.readFileSync(node_path_1.default.join(templateRoot, 'taro-env.d.ts'), 'utf8');
|
|
224
|
+
(0, emit_1.writeText)(hostTaroEnv, `${layout_1.generatedMarker}${envTemplate}`);
|
|
225
|
+
}
|
|
226
|
+
hostDepsPlan.commit();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const config = resolveInput(ctx.paths, model.options.doubaoConfig, configName);
|
|
231
|
+
const manifest = resolveInput(ctx.paths, model.options.manifest, manifestName);
|
|
232
|
+
const targetConfig = configExtensions
|
|
233
|
+
.map((extension) => node_path_1.default.join(outputPath, `doubao.config${extension}`))
|
|
234
|
+
.find((filename) => node_fs_1.default.existsSync(filename)) ?? node_path_1.default.join(outputPath, configName);
|
|
235
|
+
const writeConfig = planStandaloneConfig(targetConfig, config, model.defines);
|
|
236
|
+
const targetManifest = node_path_1.default.join(outputPath, manifestName);
|
|
237
|
+
if (manifest) {
|
|
238
|
+
checkDestination(targetManifest);
|
|
239
|
+
}
|
|
240
|
+
const manifestText = manifest && node_fs_1.default.readFileSync(manifest, 'utf8');
|
|
241
|
+
const postcss = model.options.pxtransform
|
|
242
|
+
? postcssUpdate(outputPath, (0, pxtransform_1.renderPostcssConfig)(ctx, model.options))
|
|
243
|
+
: undefined;
|
|
244
|
+
const warnings = [...(postcss?.warnings ?? []), ...hostDepsPlan.warnings];
|
|
245
|
+
if (model.autoInitializeHost) {
|
|
246
|
+
const relOut = node_path_1.default.relative(appPath, outputPath) || '.';
|
|
247
|
+
warnings.push(`Initialized Doubao project in ${relOut}; run \`pnpm --dir ${relOut} install\` before dev/build`);
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
warnings,
|
|
251
|
+
commit() {
|
|
252
|
+
if (model.autoInitializeHost) {
|
|
253
|
+
(0, emit_1.writeText)(node_path_1.default.join(outputPath, 'package.json'), renderScaffoldPackageJson(model, hostPackages));
|
|
254
|
+
(0, emit_1.writeText)(node_path_1.default.join(outputPath, 'tsconfig.json'), renderScaffoldTsConfig());
|
|
255
|
+
(0, emit_1.writeText)(node_path_1.default.join(outputPath, '.gitignore'), 'node_modules\ndist\n.rspeedy\n');
|
|
256
|
+
if (!writeConfig) {
|
|
257
|
+
(0, emit_1.writeText)(node_path_1.default.join(outputPath, configName), renderDefaultDoubaoConfig(model.defines));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (postcss?.update) {
|
|
261
|
+
(0, emit_1.writeText)(postcss.update.filename, postcss.update.content);
|
|
262
|
+
}
|
|
263
|
+
writeConfig?.();
|
|
264
|
+
if (manifestText !== undefined) {
|
|
265
|
+
(0, emit_1.writeText)(targetManifest, manifestText);
|
|
266
|
+
}
|
|
267
|
+
hostDepsPlan.commit();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const legacyPostcssConfig = `module.exports = require('./src/${layout_1.setupDirectory}/postcss.cjs');\n`;
|
|
272
|
+
function postcssUpdate(outputPath, content) {
|
|
273
|
+
const filename = node_path_1.default.join(outputPath, 'postcss.config.cjs');
|
|
274
|
+
const previous = node_fs_1.default.existsSync(filename) ? node_fs_1.default.readFileSync(filename, 'utf8') : '';
|
|
275
|
+
const owned = previous.startsWith(layout_1.generatedMarker) || previous === legacyPostcssConfig;
|
|
276
|
+
const extensions = ['ts', 'cts', 'mts', 'js', 'cjs', 'mjs'];
|
|
277
|
+
const names = [
|
|
278
|
+
'.postcssrc',
|
|
279
|
+
...['json', 'yaml', 'yml', ...extensions].map((extension) => `.postcssrc.${extension}`),
|
|
280
|
+
...extensions.map((extension) => `postcss.config.${extension}`)
|
|
281
|
+
];
|
|
282
|
+
let existing;
|
|
283
|
+
for (let directory = outputPath;; directory = node_path_1.default.dirname(directory)) {
|
|
284
|
+
const packageFile = node_path_1.default.join(directory, 'package.json');
|
|
285
|
+
const packageInfo = node_fs_1.default.existsSync(packageFile)
|
|
286
|
+
? JSON.parse(node_fs_1.default.readFileSync(packageFile, 'utf8'))
|
|
287
|
+
: undefined;
|
|
288
|
+
existing = packageInfo?.postcss
|
|
289
|
+
? packageFile
|
|
290
|
+
: names
|
|
291
|
+
.map((name) => node_path_1.default.join(directory, name))
|
|
292
|
+
.find((name) => node_fs_1.default.existsSync(name) && node_fs_1.default.readFileSync(name, 'utf8').trim());
|
|
293
|
+
if (existing || directory === (0, node_os_1.homedir)() || directory === node_path_1.default.dirname(directory)) {
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (existing && !(existing === filename && owned)) {
|
|
298
|
+
return { warnings: [`Configure postcss-pxtransform in ${existing} to enable Taro unit conversion`] };
|
|
299
|
+
}
|
|
300
|
+
checkDestination(filename);
|
|
301
|
+
return {
|
|
302
|
+
warnings: [],
|
|
303
|
+
update: {
|
|
304
|
+
filename,
|
|
305
|
+
content: `${layout_1.generatedMarker}// Remove the generated marker above to maintain this file manually.\n${content}`
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=project-files.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IPluginContext } from '@tarojs/service';
|
|
2
|
+
import type { Options } from '../project';
|
|
3
|
+
/** PostCSS runs in the output project, after its stylesheet preprocessors. */
|
|
4
|
+
export declare function renderPostcssConfig(ctx: IPluginContext, options: Options): string;
|
|
5
|
+
export declare function renderPxTransformSetup(ctx: IPluginContext, options: Options): string;
|
|
6
|
+
//# sourceMappingURL=pxtransform.d.ts.map
|
|
@@ -2,33 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderPostcssConfig = renderPostcssConfig;
|
|
4
4
|
exports.renderPxTransformSetup = renderPxTransformSetup;
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const imports_1 = require("../project/imports");
|
|
6
|
+
const errors_1 = require("../shared/errors");
|
|
7
|
+
function resolvePxTransform(ctx, options) {
|
|
8
|
+
const taroConfig = ctx.runOpts?.config ?? ctx.initialConfig;
|
|
7
9
|
const overrides = options.pxtransform || {};
|
|
8
10
|
const config = overrides === true ? {} : overrides;
|
|
9
|
-
const designWidth = config.designWidth ??
|
|
11
|
+
const designWidth = config.designWidth ?? taroConfig.designWidth ?? 750;
|
|
10
12
|
const deviceRatio = {
|
|
13
|
+
...ctx.helper.DEVICE_RATIO,
|
|
11
14
|
375: 2,
|
|
12
|
-
|
|
13
|
-
750: 1,
|
|
14
|
-
828: 1.81 / 2,
|
|
15
|
-
...options.deviceRatio,
|
|
15
|
+
...taroConfig.deviceRatio,
|
|
16
16
|
...config.deviceRatio
|
|
17
17
|
};
|
|
18
18
|
return { config, designWidth, deviceRatio };
|
|
19
19
|
}
|
|
20
20
|
/** PostCSS runs in the output project, after its stylesheet preprocessors. */
|
|
21
|
-
function renderPostcssConfig(options) {
|
|
22
|
-
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const { config, designWidth, deviceRatio } = resolvePxTransform(options);
|
|
21
|
+
function renderPostcssConfig(ctx, options) {
|
|
22
|
+
const { config, designWidth, deviceRatio } = resolvePxTransform(ctx, options);
|
|
26
23
|
if (typeof designWidth === 'function' || config.exclude) {
|
|
27
|
-
(0,
|
|
24
|
+
(0, errors_1.fail)('Configure function options directly in the output PostCSS config and disable pxtransform in the exporter');
|
|
28
25
|
}
|
|
29
26
|
const ratio = deviceRatio[designWidth];
|
|
30
27
|
if (!Number.isFinite(designWidth) || designWidth <= 0 || !Number.isFinite(ratio) || ratio <= 0) {
|
|
31
|
-
(0,
|
|
28
|
+
(0, errors_1.fail)(`Configure a positive deviceRatio for designWidth ${designWidth}`);
|
|
32
29
|
}
|
|
33
30
|
const { selectorBlackList = [], ...settings } = config;
|
|
34
31
|
const blacklist = selectorBlackList.map((item) => item instanceof RegExp ? item.toString() : JSON.stringify(item));
|
|
@@ -43,10 +40,10 @@ module.exports = {
|
|
|
43
40
|
};
|
|
44
41
|
`;
|
|
45
42
|
}
|
|
46
|
-
function renderPxTransformSetup(options) {
|
|
47
|
-
const { designWidth, deviceRatio } = resolvePxTransform(options);
|
|
43
|
+
function renderPxTransformSetup(ctx, options) {
|
|
44
|
+
const { designWidth, deviceRatio } = resolvePxTransform(ctx, options);
|
|
48
45
|
const ratio = typeof designWidth === 'number' ? deviceRatio[designWidth] : undefined;
|
|
49
|
-
return `import { __configurePxTransform } from '
|
|
46
|
+
return `import { __configurePxTransform } from '${imports_1.runtimeModules.taro}';
|
|
50
47
|
__configurePxTransform(${JSON.stringify(ratio ?? null)});
|
|
51
48
|
`;
|
|
52
49
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProjectModel } from '../project';
|
|
2
|
+
/**
|
|
3
|
+
* Single-project mode: emits `app.ts` (unless `app.doubao.*` provided), `app.config.ts` and `taro-env.d.ts`.
|
|
4
|
+
* Module mode (`moduleName`): checks cross-module route uniqueness and emits `<moduleRoot>/routes.ts`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function planScaffold(model: ProjectModel): {
|
|
7
|
+
warnings: string[];
|
|
8
|
+
writeSource(stagingDirectory: string): void;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=scaffold.d.ts.map
|