@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,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildDefines = buildDefines;
|
|
4
|
+
const errors_1 = require("../shared/errors");
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const prototype = Object.getPrototypeOf(value);
|
|
10
|
+
return prototype === Object.prototype || prototype === null;
|
|
11
|
+
}
|
|
12
|
+
function formatInlineDefineValue(key, value, seen) {
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
if (!value.trim()) {
|
|
15
|
+
(0, errors_1.fail)(`Invalid empty define expression for ${key}`);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === 'number') {
|
|
20
|
+
return Object.is(value, -0) ? '-0' : String(value);
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'boolean' || value === null) {
|
|
23
|
+
return String(value);
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
if (seen.has(value)) {
|
|
27
|
+
(0, errors_1.fail)(`Circular define value for ${key}`);
|
|
28
|
+
}
|
|
29
|
+
const nextSeen = new Set(seen);
|
|
30
|
+
nextSeen.add(value);
|
|
31
|
+
const elements = value.map((item) => item === undefined ? 'undefined' : formatInlineDefineValue(key, item, nextSeen));
|
|
32
|
+
return `[${elements.join(', ')}]`;
|
|
33
|
+
}
|
|
34
|
+
if (isPlainObject(value)) {
|
|
35
|
+
if (seen.has(value)) {
|
|
36
|
+
(0, errors_1.fail)(`Circular define value for ${key}`);
|
|
37
|
+
}
|
|
38
|
+
const nextSeen = new Set(seen);
|
|
39
|
+
nextSeen.add(value);
|
|
40
|
+
const properties = Object.entries(value)
|
|
41
|
+
.filter(([, subValue]) => subValue !== undefined)
|
|
42
|
+
.map(([subKey, subValue]) => `${JSON.stringify(subKey)}: ${formatInlineDefineValue(`${key}.${subKey}`, subValue, nextSeen)}`);
|
|
43
|
+
return `{${properties.join(', ')}}`;
|
|
44
|
+
}
|
|
45
|
+
(0, errors_1.fail)(`Unsupported define value for ${key}`);
|
|
46
|
+
}
|
|
47
|
+
function collectDefineEntry(defines, key, value, seen) {
|
|
48
|
+
if (value === undefined) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (isPlainObject(value)) {
|
|
52
|
+
if (seen.has(value)) {
|
|
53
|
+
(0, errors_1.fail)(`Circular define value for ${key}`);
|
|
54
|
+
}
|
|
55
|
+
const entries = Object.entries(value).filter(([, subValue]) => subValue !== undefined);
|
|
56
|
+
if (!entries.length) {
|
|
57
|
+
defines[key] = '{}';
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const nextSeen = new Set(seen);
|
|
61
|
+
nextSeen.add(value);
|
|
62
|
+
for (const [subKey, subValue] of entries) {
|
|
63
|
+
collectDefineEntry(defines, `${key}.${subKey}`, subValue, nextSeen);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
defines[key] = formatInlineDefineValue(key, value, seen);
|
|
68
|
+
}
|
|
69
|
+
/** Flattens DefinePlugin definitions into the `key → expression` form the scaffold and Rspack share. */
|
|
70
|
+
function flattenDefines(definitions) {
|
|
71
|
+
const defines = {};
|
|
72
|
+
for (const [key, value] of Object.entries(definitions)) {
|
|
73
|
+
collectDefineEntry(defines, key, value, new Set());
|
|
74
|
+
}
|
|
75
|
+
return defines;
|
|
76
|
+
}
|
|
77
|
+
/** Definitions in Taro's order: `env` as `process.env.*`, then `defineConstants`, then the platform. */
|
|
78
|
+
function buildDefines(env, defineConstants) {
|
|
79
|
+
const envDefines = Object.fromEntries(Object.entries(env ?? {}).map(([key, value]) => [
|
|
80
|
+
key.startsWith('process.env.') ? key : `process.env.${key}`,
|
|
81
|
+
value
|
|
82
|
+
]));
|
|
83
|
+
const defines = flattenDefines({ ...envDefines, ...defineConstants });
|
|
84
|
+
defines['process.env.TARO_ENV'] = JSON.stringify('doubao');
|
|
85
|
+
// Taro libraries branch on the platform family; the runtime follows mini-program semantics.
|
|
86
|
+
defines['process.env.TARO_PLATFORM'] ??= JSON.stringify('mini');
|
|
87
|
+
return defines;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=defines.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { DependencyClassifier } from '../plans/host-deps';
|
|
2
|
+
import type { LocalResolver } from './resolver';
|
|
3
|
+
export declare function isTypeOnlyModule(specifier: string): boolean;
|
|
4
|
+
/** Canonical Doubao runtime package entries targeted by Taro and React rewrites. */
|
|
5
|
+
export declare const runtimeModules: {
|
|
6
|
+
readonly taro: "@doubao-dev/taro-runtime";
|
|
7
|
+
readonly components: "@doubao-dev/taro-runtime/components";
|
|
8
|
+
readonly internal: "@doubao-dev/taro-runtime/internal";
|
|
9
|
+
readonly react: "@doubao-dev/taro-runtime/react";
|
|
10
|
+
readonly reactDom: "@doubao-dev/taro-runtime/react-dom";
|
|
11
|
+
readonly framework: "@doubao-dev/framework";
|
|
12
|
+
readonly jsxRuntime: "@doubao-dev/framework/jsx-runtime";
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Module specifiers whose `Component` / `PureComponent` exports represent React class components:
|
|
16
|
+
* raw `react`, the Taro React compatibility entry, and the Doubao native framework entry.
|
|
17
|
+
*/
|
|
18
|
+
export declare const reactComponentModules: Set<string>;
|
|
19
|
+
/** Whether `specifier` names a stylesheet. */
|
|
20
|
+
export declare function isStylesheet(specifier: string): boolean;
|
|
21
|
+
/** Whether `specifier` names a stylesheet, image or font. */
|
|
22
|
+
export declare function isAsset(specifier: string): boolean;
|
|
23
|
+
export declare function isBareSpecifier(specifier: string): boolean;
|
|
24
|
+
export declare function unsupportedModule(specifier: string, importer: string): string;
|
|
25
|
+
/** Where an import specifier leads, and therefore how application sources and the vendor bundle treat it. */
|
|
26
|
+
export type ImportTarget =
|
|
27
|
+
/**
|
|
28
|
+
* An application module or asset inside the source root, reached by a relative path, a project alias or
|
|
29
|
+
* tsconfig `paths` (for example `~/utils/format`). Sources import the generated copy; the bundle keeps it
|
|
30
|
+
* external and points at the same copy, so the application keeps a single instance.
|
|
31
|
+
*/
|
|
32
|
+
{
|
|
33
|
+
kind: 'source';
|
|
34
|
+
file: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A local file outside the source root that is not bundled, for example `../shared/util` or a global
|
|
38
|
+
* declaration file. Only declaration files may reference these (copied as ambient declarations).
|
|
39
|
+
*/
|
|
40
|
+
| {
|
|
41
|
+
kind: 'outside';
|
|
42
|
+
file: string;
|
|
43
|
+
}
|
|
44
|
+
/** A relative or absolute specifier that matches no file. */
|
|
45
|
+
| {
|
|
46
|
+
kind: 'unresolved';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A Taro or React subpath the Doubao runtime does not provide, for example `@tarojs/plugin-http`.
|
|
50
|
+
* Allowed in type positions only.
|
|
51
|
+
*/
|
|
52
|
+
| {
|
|
53
|
+
kind: 'unsupported';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A stylesheet or asset from a package, for example `some-ui/dist/index.css`. Sources keep the bare import
|
|
57
|
+
* and the output project installs the package; the bundle rejects it.
|
|
58
|
+
*/
|
|
59
|
+
| {
|
|
60
|
+
kind: 'asset';
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A package the output project provides, imported as `specifier` by sources and the bundle alike. Taro and
|
|
64
|
+
* React entries are replaced by their Doubao counterparts (`@tarojs/taro` -> `@doubao-dev/taro-runtime`);
|
|
65
|
+
* `@doubao-dev/*`, `@lynx-js/*`, and standard public npm packages keep their own specifier.
|
|
66
|
+
*/
|
|
67
|
+
| {
|
|
68
|
+
kind: 'external';
|
|
69
|
+
specifier: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A third-party or workspace-private module bundled into the generated vendor directory. `aliased` marks a
|
|
73
|
+
* project alias to a source file outside the source root (for example `@vapp/store`): the output project
|
|
74
|
+
* cannot resolve the alias, so its type references also point at the bundled declarations.
|
|
75
|
+
*/
|
|
76
|
+
| {
|
|
77
|
+
kind: 'vendor';
|
|
78
|
+
aliased: boolean;
|
|
79
|
+
};
|
|
80
|
+
export interface ImportResolver {
|
|
81
|
+
/** Classifies `specifier` and records host-package dependencies when `recordUsage` is true. */
|
|
82
|
+
resolve(specifier: string, importer: string, recordUsage?: boolean): ImportTarget;
|
|
83
|
+
/** Classifies `specifier` without recording host-package usage (for AST pre-checks). */
|
|
84
|
+
probe(specifier: string, importer: string): ImportTarget;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Shared import rules for source rewriting and the vendor bundle, so an import resolves the same way in
|
|
88
|
+
* application code and in third-party packages.
|
|
89
|
+
*/
|
|
90
|
+
export declare function createImportResolver(options: {
|
|
91
|
+
sourcePath: string;
|
|
92
|
+
resolveLocal: LocalResolver;
|
|
93
|
+
dependencyClassifier: DependencyClassifier;
|
|
94
|
+
}): ImportResolver;
|
|
95
|
+
//# sourceMappingURL=imports.d.ts.map
|
|
@@ -0,0 +1,122 @@
|
|
|
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.reactComponentModules = exports.runtimeModules = void 0;
|
|
7
|
+
exports.isTypeOnlyModule = isTypeOnlyModule;
|
|
8
|
+
exports.isStylesheet = isStylesheet;
|
|
9
|
+
exports.isAsset = isAsset;
|
|
10
|
+
exports.isBareSpecifier = isBareSpecifier;
|
|
11
|
+
exports.unsupportedModule = unsupportedModule;
|
|
12
|
+
exports.createImportResolver = createImportResolver;
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const paths_1 = require("../shared/paths");
|
|
15
|
+
function isTypeOnlyModule(specifier) {
|
|
16
|
+
return (specifier === 'react' ||
|
|
17
|
+
specifier.startsWith('react/') ||
|
|
18
|
+
specifier === 'react-dom' ||
|
|
19
|
+
specifier.startsWith('react-dom/') ||
|
|
20
|
+
specifier.startsWith('@tarojs/'));
|
|
21
|
+
}
|
|
22
|
+
/** Canonical Doubao runtime package entries targeted by Taro and React rewrites. */
|
|
23
|
+
exports.runtimeModules = {
|
|
24
|
+
taro: '@doubao-dev/taro-runtime',
|
|
25
|
+
components: '@doubao-dev/taro-runtime/components',
|
|
26
|
+
internal: '@doubao-dev/taro-runtime/internal',
|
|
27
|
+
react: '@doubao-dev/taro-runtime/react',
|
|
28
|
+
reactDom: '@doubao-dev/taro-runtime/react-dom',
|
|
29
|
+
framework: '@doubao-dev/framework',
|
|
30
|
+
jsxRuntime: '@doubao-dev/framework/jsx-runtime'
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Module specifiers whose `Component` / `PureComponent` exports represent React class components:
|
|
34
|
+
* raw `react`, the Taro React compatibility entry, and the Doubao native framework entry.
|
|
35
|
+
*/
|
|
36
|
+
exports.reactComponentModules = new Set([
|
|
37
|
+
'react',
|
|
38
|
+
exports.runtimeModules.framework,
|
|
39
|
+
exports.runtimeModules.react
|
|
40
|
+
]);
|
|
41
|
+
/** Taro and React imports go through the runtime compatibility entries. */
|
|
42
|
+
const moduleMap = {
|
|
43
|
+
'@tarojs/taro': exports.runtimeModules.taro,
|
|
44
|
+
'@tarojs/components': exports.runtimeModules.components,
|
|
45
|
+
react: exports.runtimeModules.react,
|
|
46
|
+
'react-dom': exports.runtimeModules.reactDom,
|
|
47
|
+
'react/jsx-runtime': exports.runtimeModules.jsxRuntime,
|
|
48
|
+
'react/jsx-dev-runtime': exports.runtimeModules.jsxRuntime
|
|
49
|
+
};
|
|
50
|
+
const styleExtensions = new Set(['.css', '.scss', '.sass', '.less', '.styl', '.stylus', '.pcss']);
|
|
51
|
+
const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.avif', '.bmp', '.ico'];
|
|
52
|
+
const fontExtensions = ['.woff', '.woff2', '.ttf', '.eot', '.otf'];
|
|
53
|
+
/** Stylesheets, images and fonts: the vendor build only bundles scripts. */
|
|
54
|
+
const assetExtensions = new Set([...styleExtensions, ...imageExtensions, ...fontExtensions]);
|
|
55
|
+
/** Lowercase extension of `specifier`, ignoring a webpack resource query or fragment (`?inline`, `#iefix`). */
|
|
56
|
+
function extension(specifier) {
|
|
57
|
+
return node_path_1.default.extname(specifier.replace(/[?#].*$/, '')).toLowerCase();
|
|
58
|
+
}
|
|
59
|
+
/** Whether `specifier` names a stylesheet. */
|
|
60
|
+
function isStylesheet(specifier) {
|
|
61
|
+
return styleExtensions.has(extension(specifier));
|
|
62
|
+
}
|
|
63
|
+
/** Whether `specifier` names a stylesheet, image or font. */
|
|
64
|
+
function isAsset(specifier) {
|
|
65
|
+
return assetExtensions.has(extension(specifier));
|
|
66
|
+
}
|
|
67
|
+
function isBareSpecifier(specifier) {
|
|
68
|
+
return !specifier.startsWith('.') && !specifier.startsWith('/') && !/^[a-z]:[\\/]/i.test(specifier);
|
|
69
|
+
}
|
|
70
|
+
function unsupportedModule(specifier, importer) {
|
|
71
|
+
return `${importer} imports ${specifier}, which the Doubao Taro runtime does not provide`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Shared import rules for source rewriting and the vendor bundle, so an import resolves the same way in
|
|
75
|
+
* application code and in third-party packages.
|
|
76
|
+
*/
|
|
77
|
+
function createImportResolver(options) {
|
|
78
|
+
const { sourcePath, resolveLocal, dependencyClassifier } = options;
|
|
79
|
+
function classifyImport(specifier, importer, recordUsage) {
|
|
80
|
+
const bare = isBareSpecifier(specifier);
|
|
81
|
+
const replacement = bare ? moduleMap[specifier] : undefined;
|
|
82
|
+
if (replacement) {
|
|
83
|
+
return { kind: 'external', specifier: replacement };
|
|
84
|
+
}
|
|
85
|
+
const file = resolveLocal(importer, specifier);
|
|
86
|
+
if (file) {
|
|
87
|
+
if ((0, paths_1.inside)(sourcePath, file)) {
|
|
88
|
+
return { kind: 'source', file };
|
|
89
|
+
}
|
|
90
|
+
if (bare && paths_1.sourcePattern.test(file) && !paths_1.declarationPattern.test(file)) {
|
|
91
|
+
return { kind: 'vendor', aliased: true };
|
|
92
|
+
}
|
|
93
|
+
return { kind: 'outside', file };
|
|
94
|
+
}
|
|
95
|
+
if (!bare) {
|
|
96
|
+
return { kind: 'unresolved' };
|
|
97
|
+
}
|
|
98
|
+
if (/^(?:@tarojs\/|react\/|react-dom\/)/.test(specifier)) {
|
|
99
|
+
// The Doubao runtime replaces Taro; bundling other Taro packages would pull in the Taro runtime.
|
|
100
|
+
return { kind: 'unsupported' };
|
|
101
|
+
}
|
|
102
|
+
if (isAsset(specifier)) {
|
|
103
|
+
return { kind: 'asset' };
|
|
104
|
+
}
|
|
105
|
+
if (/^(?:@doubao-dev|@lynx-js)\//.test(specifier)) {
|
|
106
|
+
return { kind: 'external', specifier };
|
|
107
|
+
}
|
|
108
|
+
if (dependencyClassifier.classify(specifier, importer, recordUsage) === 'host') {
|
|
109
|
+
return { kind: 'external', specifier };
|
|
110
|
+
}
|
|
111
|
+
return { kind: 'vendor', aliased: false };
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
resolve(specifier, importer, recordUsage = true) {
|
|
115
|
+
return classifyImport(specifier, importer, recordUsage);
|
|
116
|
+
},
|
|
117
|
+
probe(specifier, importer) {
|
|
118
|
+
return classifyImport(specifier, importer, false);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=imports.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ResolveOptions } from '@rspack/core';
|
|
2
|
+
import type { IPluginContext } from '@tarojs/service';
|
|
3
|
+
import type { Input } from 'postcss';
|
|
4
|
+
import { DependencyClassifier } from '../plans/host-deps';
|
|
5
|
+
import { type CompiledDefines } from '../plans/sources/dead-branches';
|
|
6
|
+
import { type TargetLayout } from '../shared/layout';
|
|
7
|
+
import { type ImportResolver } from './imports';
|
|
8
|
+
import { ProjectProgram } from './program';
|
|
9
|
+
import { type LocalResolver } from './resolver';
|
|
10
|
+
/** Effective configuration supplied by Taro after platform merging and modifyRunnerOpts. */
|
|
11
|
+
export interface TaroBuildConfig extends Pick<IPluginContext['initialConfig'], 'designWidth' | 'deviceRatio'> {
|
|
12
|
+
entry: {
|
|
13
|
+
app: string | string[];
|
|
14
|
+
};
|
|
15
|
+
alias?: Record<string, string | string[] | false>;
|
|
16
|
+
env?: Record<string, unknown>;
|
|
17
|
+
defineConstants?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface PxTransformOptions {
|
|
20
|
+
designWidth?: number | ((input: Input) => number);
|
|
21
|
+
deviceRatio?: Record<number, number>;
|
|
22
|
+
propList?: string[];
|
|
23
|
+
selectorBlackList?: (string | RegExp)[];
|
|
24
|
+
onePxTransform?: boolean;
|
|
25
|
+
minPixelValue?: number;
|
|
26
|
+
unitPrecision?: number;
|
|
27
|
+
mediaQuery?: boolean;
|
|
28
|
+
exclude?: (filename: string) => boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface Options {
|
|
31
|
+
/** Doubao application ID. Required in single-project mode; optional when `moduleName` is set. */
|
|
32
|
+
appId?: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
/** Export into `outputRoot/src/modules/<moduleName>/` and generate `routes.ts` for multi-project composition. */
|
|
35
|
+
moduleName?: string;
|
|
36
|
+
/** Explicitly merge standard public npm dependencies into host `package.json` (disabled by default to preserve lockfiles). */
|
|
37
|
+
syncDeps?: boolean;
|
|
38
|
+
/** Force specific npm package names to be bundled into `__vendor__` instead of delegated to host `package.json`. */
|
|
39
|
+
vendorPackages?: string[];
|
|
40
|
+
pxtransform?: boolean | PxTransformOptions;
|
|
41
|
+
doubaoConfig?: string;
|
|
42
|
+
manifest?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface PackageInfo {
|
|
45
|
+
name?: string;
|
|
46
|
+
dependencies?: Record<string, string>;
|
|
47
|
+
devDependencies?: Record<string, string>;
|
|
48
|
+
peerDependencies?: Record<string, string>;
|
|
49
|
+
}
|
|
50
|
+
/** Version recorded in the generated source report. */
|
|
51
|
+
export interface PluginInfo {
|
|
52
|
+
version: string;
|
|
53
|
+
}
|
|
54
|
+
/** Everything the later stages need to know about the input project; produced without writing anything. */
|
|
55
|
+
export interface ProjectModel {
|
|
56
|
+
options: Options;
|
|
57
|
+
layout: TargetLayout;
|
|
58
|
+
/** True when `outputPath` does not exist or is completely empty in single-project mode. */
|
|
59
|
+
autoInitializeHost: boolean;
|
|
60
|
+
appFile: string;
|
|
61
|
+
/** Optional native Doubao `app.doubao.*` entry in single-project mode. */
|
|
62
|
+
appDoubaoFile?: string;
|
|
63
|
+
appConfig: Record<string, unknown>;
|
|
64
|
+
pages: string[];
|
|
65
|
+
pageFiles: string[];
|
|
66
|
+
styles: string[];
|
|
67
|
+
ambientDeclarations: string[];
|
|
68
|
+
defines: Record<string, string>;
|
|
69
|
+
compiledDefines: CompiledDefines;
|
|
70
|
+
resolveLocal: LocalResolver;
|
|
71
|
+
/** Classifies imports the same way for application sources and the vendor bundle. */
|
|
72
|
+
imports: ImportResolver;
|
|
73
|
+
dependencyClassifier: DependencyClassifier;
|
|
74
|
+
/** Project aliases and tsconfig used by the vendor bundler. */
|
|
75
|
+
bundleResolve: ResolveOptions;
|
|
76
|
+
program: ProjectProgram;
|
|
77
|
+
packageInfo: PackageInfo;
|
|
78
|
+
pluginInfo: PluginInfo;
|
|
79
|
+
warnings: string[];
|
|
80
|
+
}
|
|
81
|
+
export declare function analyzeProject(ctx: IPluginContext, options: Options): ProjectModel;
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,182 @@
|
|
|
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.analyzeProject = analyzeProject;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const host_deps_1 = require("../plans/host-deps");
|
|
10
|
+
const dead_branches_1 = require("../plans/sources/dead-branches");
|
|
11
|
+
const errors_1 = require("../shared/errors");
|
|
12
|
+
const layout_1 = require("../shared/layout");
|
|
13
|
+
const paths_1 = require("../shared/paths");
|
|
14
|
+
const app_1 = require("./app");
|
|
15
|
+
const defines_1 = require("./defines");
|
|
16
|
+
const imports_1 = require("./imports");
|
|
17
|
+
const program_1 = require("./program");
|
|
18
|
+
const resolver_1 = require("./resolver");
|
|
19
|
+
function assertNoSymlinkInOutput(outputPath) {
|
|
20
|
+
let current = node_path_1.default.resolve(outputPath);
|
|
21
|
+
while (!node_fs_1.default.existsSync(current)) {
|
|
22
|
+
const parent = node_path_1.default.dirname(current);
|
|
23
|
+
if (parent === current) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
current = parent;
|
|
27
|
+
}
|
|
28
|
+
if (node_fs_1.default.realpathSync(current) !== current) {
|
|
29
|
+
(0, errors_1.fail)('Output cannot pass through a symbolic link');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function checkOutput(appPath, sourcePath, outputPath, layout) {
|
|
33
|
+
if ((0, paths_1.inside)(outputPath, sourcePath) || (0, paths_1.inside)(sourcePath, outputPath) || !(0, paths_1.inside)(appPath, sourcePath)) {
|
|
34
|
+
(0, errors_1.fail)('Source and output directories must be separate; output cannot contain the project source');
|
|
35
|
+
}
|
|
36
|
+
assertNoSymlinkInOutput(outputPath);
|
|
37
|
+
const outputExists = node_fs_1.default.existsSync(outputPath);
|
|
38
|
+
const outputEntries = outputExists ? node_fs_1.default.readdirSync(outputPath) : [];
|
|
39
|
+
if (!layout.moduleName && (!outputExists || outputEntries.length === 0)) {
|
|
40
|
+
return { autoInitializeHost: true };
|
|
41
|
+
}
|
|
42
|
+
if (!node_fs_1.default.existsSync(node_path_1.default.join(outputPath, 'package.json'))) {
|
|
43
|
+
const guidance = layout.moduleName
|
|
44
|
+
? 'Initialize the host Doubao project before exporting modules into it'
|
|
45
|
+
: 'Use an empty output directory for automatic scaffolding or create a Doubao project first';
|
|
46
|
+
(0, errors_1.fail)(`Output must be an existing Doubao project with a package.json: ${outputPath}. ${guidance}`);
|
|
47
|
+
}
|
|
48
|
+
// Only a previously generated target directory (`src/` or `src/modules/<moduleName>/`) may be replaced.
|
|
49
|
+
const { targetSource } = layout;
|
|
50
|
+
if (node_fs_1.default.existsSync(targetSource) && node_fs_1.default.readdirSync(targetSource).length) {
|
|
51
|
+
const markerFile = node_path_1.default.join(targetSource, layout_1.reportFile);
|
|
52
|
+
if (!node_fs_1.default.existsSync(markerFile) ||
|
|
53
|
+
JSON.parse(node_fs_1.default.readFileSync(markerFile, 'utf8')).generator !== layout_1.generator) {
|
|
54
|
+
(0, errors_1.fail)(`Refusing to overwrite an unmanaged directory: ${targetSource}. Move or remove it first`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { autoInitializeHost: false };
|
|
58
|
+
}
|
|
59
|
+
/** Global declarations the tsconfig includes outside the source root, copied so the output type-checks. */
|
|
60
|
+
function collectAmbientDeclarations(appPath, tsConfig, sourcePath, outputPath) {
|
|
61
|
+
const buildConfigDir = node_path_1.default.join(appPath, 'config');
|
|
62
|
+
const declarations = tsConfig.fileNames
|
|
63
|
+
.filter((filename) => paths_1.declarationPattern.test(filename))
|
|
64
|
+
.filter((filename) => (0, paths_1.inside)(appPath, filename) &&
|
|
65
|
+
!(0, paths_1.inside)(sourcePath, filename) &&
|
|
66
|
+
!(0, paths_1.inside)(outputPath, filename) &&
|
|
67
|
+
!(0, paths_1.inside)(buildConfigDir, filename) &&
|
|
68
|
+
!filename.split(node_path_1.default.sep).includes('node_modules') &&
|
|
69
|
+
node_fs_1.default.existsSync(filename));
|
|
70
|
+
for (const filename of declarations) {
|
|
71
|
+
if (node_fs_1.default.realpathSync(filename) !== filename) {
|
|
72
|
+
(0, errors_1.fail)(`Symbolic links in source assets are unsupported: ${filename}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [...new Set(declarations)].sort();
|
|
76
|
+
}
|
|
77
|
+
function analyzeProject(ctx, options) {
|
|
78
|
+
const { appPath, sourcePath, outputPath } = ctx.paths;
|
|
79
|
+
const layout = (0, layout_1.resolveTargetLayout)(outputPath, options.moduleName);
|
|
80
|
+
if (!layout.moduleName && !options.appId?.trim()) {
|
|
81
|
+
(0, errors_1.fail)('Configure appId in the platform plugin options');
|
|
82
|
+
}
|
|
83
|
+
const { autoInitializeHost } = checkOutput(appPath, sourcePath, outputPath, layout);
|
|
84
|
+
const config = ctx.runOpts.config;
|
|
85
|
+
const defines = (0, defines_1.buildDefines)(config.env, config.defineConstants);
|
|
86
|
+
const compiledDefines = (0, dead_branches_1.compileDefines)(defines);
|
|
87
|
+
const aliases = config.alias;
|
|
88
|
+
const tsConfig = (0, resolver_1.readTsConfig)(appPath);
|
|
89
|
+
const { resolveLocal, bundleResolve } = (0, resolver_1.createResolvers)(ctx.helper, aliases, tsConfig);
|
|
90
|
+
const packageInfo = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(appPath, 'package.json'), 'utf8'));
|
|
91
|
+
const pluginInfo = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, '..', '..', 'package.json'), 'utf8'));
|
|
92
|
+
const dependencyClassifier = new host_deps_1.DependencyClassifier({
|
|
93
|
+
appPath,
|
|
94
|
+
sourcePackageJson: packageInfo,
|
|
95
|
+
vendorPackages: options.vendorPackages,
|
|
96
|
+
customDefineKeys: compiledDefines.customKeys
|
|
97
|
+
});
|
|
98
|
+
const imports = (0, imports_1.createImportResolver)({
|
|
99
|
+
sourcePath,
|
|
100
|
+
resolveLocal,
|
|
101
|
+
dependencyClassifier
|
|
102
|
+
});
|
|
103
|
+
const appConfig = ctx.helper.readConfig(ctx.helper.resolveScriptPath(node_path_1.default.join(sourcePath, 'app.config')), {
|
|
104
|
+
alias: config.alias,
|
|
105
|
+
defineConstants: defines
|
|
106
|
+
}) ?? {};
|
|
107
|
+
const pages = appConfig.pages ?? [];
|
|
108
|
+
const pageFiles = pages.map((page) => {
|
|
109
|
+
const filename = node_path_1.default.join(sourcePath, page);
|
|
110
|
+
return (resolveLocal(filename, `${filename}.doubao`) ??
|
|
111
|
+
resolveLocal(filename, filename) ??
|
|
112
|
+
(0, errors_1.fail)(`Missing page: ${page}`));
|
|
113
|
+
});
|
|
114
|
+
const appEntry = config.entry.app;
|
|
115
|
+
const appFile = typeof appEntry === 'string' ? appEntry : appEntry[0];
|
|
116
|
+
const appProbe = node_path_1.default.join(sourcePath, 'app');
|
|
117
|
+
const candidateAppDoubao = resolveLocal(appProbe, `${appProbe}.doubao`);
|
|
118
|
+
const appDoubaoFile = !layout.moduleName ? candidateAppDoubao : undefined;
|
|
119
|
+
const warnings = [];
|
|
120
|
+
if (layout.moduleName && candidateAppDoubao) {
|
|
121
|
+
warnings.push(`Module "${layout.moduleName}" ignores ${node_path_1.default.relative(appPath, candidateAppDoubao)}; the host project owns src/app.ts`);
|
|
122
|
+
}
|
|
123
|
+
if (!appDoubaoFile && !node_fs_1.default.statSync(appFile, { throwIfNoEntry: false })?.isFile()) {
|
|
124
|
+
(0, errors_1.fail)('Missing app entry');
|
|
125
|
+
}
|
|
126
|
+
let styles = [];
|
|
127
|
+
if (appDoubaoFile) {
|
|
128
|
+
styles = (0, app_1.collectStylesheetImportsOnly)(appDoubaoFile);
|
|
129
|
+
}
|
|
130
|
+
else if (layout.moduleName) {
|
|
131
|
+
if (node_fs_1.default.statSync(appFile, { throwIfNoEntry: false })?.isFile()) {
|
|
132
|
+
try {
|
|
133
|
+
styles = (0, app_1.appStyles)(appFile);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (!(error instanceof errors_1.DoubaoPluginError)) {
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
styles = (0, app_1.collectStylesheetImportsOnly)(appFile);
|
|
140
|
+
warnings.push(`Module "${layout.moduleName}" ignores App runtime logic in ${node_path_1.default.relative(appPath, appFile)}; ` +
|
|
141
|
+
`migrate App providers or lifecycle hooks to the host project`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
styles = (0, app_1.appStyles)(appFile);
|
|
147
|
+
}
|
|
148
|
+
const ambientDeclarations = layout.moduleName
|
|
149
|
+
? []
|
|
150
|
+
: collectAmbientDeclarations(appPath, tsConfig, sourcePath, outputPath);
|
|
151
|
+
const sourceScripts = (0, paths_1.walk)(sourcePath).filter((filename) => paths_1.sourcePattern.test(filename));
|
|
152
|
+
const initialRoots = [
|
|
153
|
+
...sourceScripts,
|
|
154
|
+
...pageFiles,
|
|
155
|
+
...(appDoubaoFile ? [appDoubaoFile] : []),
|
|
156
|
+
...ambientDeclarations
|
|
157
|
+
];
|
|
158
|
+
const program = new program_1.ProjectProgram(tsConfig, initialRoots);
|
|
159
|
+
return {
|
|
160
|
+
options,
|
|
161
|
+
layout,
|
|
162
|
+
autoInitializeHost,
|
|
163
|
+
appFile,
|
|
164
|
+
appDoubaoFile,
|
|
165
|
+
appConfig,
|
|
166
|
+
pages,
|
|
167
|
+
pageFiles,
|
|
168
|
+
styles,
|
|
169
|
+
ambientDeclarations,
|
|
170
|
+
defines,
|
|
171
|
+
compiledDefines,
|
|
172
|
+
resolveLocal,
|
|
173
|
+
imports,
|
|
174
|
+
dependencyClassifier,
|
|
175
|
+
bundleResolve,
|
|
176
|
+
program,
|
|
177
|
+
packageInfo,
|
|
178
|
+
pluginInfo,
|
|
179
|
+
warnings
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import type { TsConfig } from './resolver';
|
|
3
|
+
/** Holds a `ts.Program` and `ts.TypeChecker` for semantic analysis across the Taro project. */
|
|
4
|
+
export declare class ProjectProgram {
|
|
5
|
+
private program;
|
|
6
|
+
private rootFiles;
|
|
7
|
+
private readonly compilerOptions;
|
|
8
|
+
constructor(tsConfig: TsConfig, initialRoots: string[]);
|
|
9
|
+
get checker(): ts.TypeChecker;
|
|
10
|
+
/** Ensures `filenames` belong to the `ts.Program` so their AST nodes are bound to the `TypeChecker`. */
|
|
11
|
+
ensureFiles(filenames: string[]): void;
|
|
12
|
+
/** Returns the `Program`-bound `SourceFile` when available, falling back to standalone parsing. */
|
|
13
|
+
getSourceFile(filename: string): ts.SourceFile;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=program.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
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.ProjectProgram = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
const syntax_1 = require("../shared/syntax");
|
|
10
|
+
/** Holds a `ts.Program` and `ts.TypeChecker` for semantic analysis across the Taro project. */
|
|
11
|
+
class ProjectProgram {
|
|
12
|
+
program;
|
|
13
|
+
rootFiles;
|
|
14
|
+
compilerOptions;
|
|
15
|
+
constructor(tsConfig, initialRoots) {
|
|
16
|
+
this.compilerOptions = {
|
|
17
|
+
target: typescript_1.default.ScriptTarget.Latest,
|
|
18
|
+
module: typescript_1.default.ModuleKind.ESNext,
|
|
19
|
+
moduleResolution: typescript_1.default.ModuleResolutionKind.Bundler,
|
|
20
|
+
...tsConfig.compilerOptions,
|
|
21
|
+
allowJs: true,
|
|
22
|
+
jsx: typescript_1.default.JsxEmit.Preserve,
|
|
23
|
+
noEmit: true,
|
|
24
|
+
skipLibCheck: true
|
|
25
|
+
};
|
|
26
|
+
this.rootFiles = new Set([...tsConfig.fileNames, ...initialRoots].map((filename) => node_path_1.default.resolve(filename)));
|
|
27
|
+
this.program = typescript_1.default.createProgram({
|
|
28
|
+
rootNames: [...this.rootFiles],
|
|
29
|
+
options: this.compilerOptions
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
get checker() {
|
|
33
|
+
return this.program.getTypeChecker();
|
|
34
|
+
}
|
|
35
|
+
/** Ensures `filenames` belong to the `ts.Program` so their AST nodes are bound to the `TypeChecker`. */
|
|
36
|
+
ensureFiles(filenames) {
|
|
37
|
+
const missing = filenames
|
|
38
|
+
.map((filename) => node_path_1.default.resolve(filename))
|
|
39
|
+
.filter((resolved) => !this.program.getSourceFile(resolved) && !this.rootFiles.has(resolved));
|
|
40
|
+
if (!missing.length) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
for (const file of missing) {
|
|
44
|
+
this.rootFiles.add(file);
|
|
45
|
+
}
|
|
46
|
+
this.program = typescript_1.default.createProgram({
|
|
47
|
+
rootNames: [...this.rootFiles],
|
|
48
|
+
options: this.compilerOptions,
|
|
49
|
+
oldProgram: this.program
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** Returns the `Program`-bound `SourceFile` when available, falling back to standalone parsing. */
|
|
53
|
+
getSourceFile(filename) {
|
|
54
|
+
const resolved = node_path_1.default.resolve(filename);
|
|
55
|
+
this.ensureFiles([resolved]);
|
|
56
|
+
return this.program.getSourceFile(resolved) ?? (0, syntax_1.readSource)(resolved);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.ProjectProgram = ProjectProgram;
|
|
60
|
+
//# sourceMappingURL=program.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ResolveOptions } from '@rspack/core';
|
|
2
|
+
import type { IPluginContext } from '@tarojs/service';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import type { TaroBuildConfig } from './index';
|
|
5
|
+
export interface TsConfig {
|
|
6
|
+
/** The project's `tsconfig.json`, if it lies inside the project. */
|
|
7
|
+
file?: string;
|
|
8
|
+
/** Files the configuration includes. */
|
|
9
|
+
fileNames: string[];
|
|
10
|
+
/** Parsed TypeScript compiler options for `ts.Program`. */
|
|
11
|
+
compilerOptions: ts.CompilerOptions;
|
|
12
|
+
}
|
|
13
|
+
export declare function readTsConfig(appPath: string): TsConfig;
|
|
14
|
+
/** Resolves a specifier to a file inside the project, or undefined for packages and missing files. */
|
|
15
|
+
export type LocalResolver = (from: string, specifier: string) => string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves relative paths, Taro `config.alias` (with higher priority than `tsconfig.paths`, matching Webpack 5),
|
|
18
|
+
* and `tsconfig.paths` with the native Rspack resolver.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createResolvers(helper: IPluginContext['helper'], alias: TaroBuildConfig['alias'], tsConfig: TsConfig): {
|
|
21
|
+
resolveLocal: LocalResolver;
|
|
22
|
+
bundleResolve: ResolveOptions;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=resolver.d.ts.map
|