@doubao-dev/taro-plugin-platform-doubao 0.10.3 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -152
- package/dist/compiler.d.ts +23 -13
- package/dist/compiler.js +44 -45
- package/dist/emit/index.d.ts +11 -0
- package/dist/emit/index.js +63 -0
- package/dist/index.js +8 -16
- package/dist/plans/host-deps.d.ts +45 -0
- package/dist/plans/host-deps.js +246 -0
- package/dist/plans/project-files.d.ts +8 -0
- package/dist/plans/project-files.js +309 -0
- package/dist/plans/pxtransform.d.ts +6 -0
- package/dist/{pxtransform.js → plans/pxtransform.js} +14 -17
- package/dist/plans/scaffold.d.ts +10 -0
- package/dist/plans/scaffold.js +114 -0
- package/dist/plans/sources/class-components.d.ts +11 -0
- package/dist/{class-components.js → plans/sources/class-components.js} +171 -59
- package/dist/plans/sources/dead-branches.d.ts +36 -0
- package/dist/plans/sources/dead-branches.js +415 -0
- package/dist/plans/sources/index.d.ts +36 -0
- package/dist/plans/sources/index.js +57 -0
- package/dist/plans/sources/styles.d.ts +7 -0
- package/dist/plans/sources/styles.js +111 -0
- package/dist/plans/sources/transform.d.ts +9 -0
- package/dist/plans/sources/transform.js +396 -0
- package/dist/plans/sources/vendor/bundle.d.ts +23 -0
- package/dist/plans/sources/vendor/bundle.js +221 -0
- package/dist/plans/sources/vendor/class-loader.d.ts +9 -0
- package/dist/plans/sources/vendor/class-loader.js +41 -0
- package/dist/plans/sources/vendor/index.d.ts +34 -0
- package/dist/plans/sources/vendor/index.js +62 -0
- package/dist/plans/sources/vendor/manifest.d.ts +43 -0
- package/dist/plans/sources/vendor/manifest.js +182 -0
- package/dist/plans/sources/vendor/output.d.ts +4 -0
- package/dist/plans/sources/vendor/output.js +68 -0
- package/dist/project/app.d.ts +3 -0
- package/dist/project/app.js +160 -0
- package/dist/project/defines.d.ts +3 -0
- package/dist/project/defines.js +89 -0
- package/dist/project/imports.d.ts +95 -0
- package/dist/project/imports.js +122 -0
- package/dist/project/index.d.ts +82 -0
- package/dist/project/index.js +182 -0
- package/dist/project/program.d.ts +15 -0
- package/dist/project/program.js +60 -0
- package/dist/project/resolver.d.ts +24 -0
- package/dist/project/resolver.js +96 -0
- package/dist/runner.d.ts +3 -2
- package/dist/runner.js +6 -4
- package/dist/shared/errors.d.ts +6 -0
- package/dist/shared/errors.js +16 -0
- package/dist/shared/layout.d.ts +32 -0
- package/dist/shared/layout.js +85 -0
- package/dist/shared/paths.d.ts +16 -0
- package/dist/shared/paths.js +83 -0
- package/dist/shared/syntax.d.ts +31 -0
- package/dist/shared/syntax.js +276 -0
- package/dist/verify.d.ts +4 -0
- package/dist/verify.js +35 -0
- package/package.json +3 -1
- package/dist/class-components.d.ts +0 -6
- package/dist/config.d.ts +0 -8
- package/dist/config.js +0 -274
- package/dist/file-system.d.ts +0 -21
- package/dist/file-system.js +0 -42
- package/dist/files.d.ts +0 -24
- package/dist/files.js +0 -256
- package/dist/platform-branches.d.ts +0 -4
- package/dist/platform-branches.js +0 -122
- package/dist/project-files.d.ts +0 -7
- package/dist/project-files.js +0 -129
- package/dist/project.d.ts +0 -48
- package/dist/project.js +0 -314
- package/dist/pxtransform.d.ts +0 -17
- package/dist/scaffold.d.ts +0 -15
- package/dist/scaffold.js +0 -103
- package/dist/transform.d.ts +0 -11
- package/dist/transform.js +0 -318
- package/dist/validate.d.ts +0 -4
- package/dist/validate.js +0 -27
- package/templates/taro.defines.ts +0 -2
|
@@ -0,0 +1,41 @@
|
|
|
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.default = classComponentLoader;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const syntax_1 = require("../../../shared/syntax");
|
|
9
|
+
const class_components_1 = require("../class-components");
|
|
10
|
+
function scriptKind(filename) {
|
|
11
|
+
if (/\.tsx$/.test(filename)) {
|
|
12
|
+
return typescript_1.default.ScriptKind.TSX;
|
|
13
|
+
}
|
|
14
|
+
// Packages may ship JSX in `.js` files, since the Kit build compiles it.
|
|
15
|
+
return /\.[cm]?ts$/.test(filename) ? typescript_1.default.ScriptKind.TS : typescript_1.default.ScriptKind.JSX;
|
|
16
|
+
}
|
|
17
|
+
function isModule(source) {
|
|
18
|
+
return source.statements.some((statement) => typescript_1.default.isImportDeclaration(statement) ||
|
|
19
|
+
typescript_1.default.isExportDeclaration(statement) ||
|
|
20
|
+
typescript_1.default.isExportAssignment(statement) ||
|
|
21
|
+
(typescript_1.default.canHaveModifiers(statement) &&
|
|
22
|
+
typescript_1.default.getModifiers(statement)?.some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.ExportKeyword)));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Rspack loader for bundled package files: applies the same class component handling as application
|
|
26
|
+
* sources, so Taro page callbacks (`componentDidShow`, `componentDidHide`) reach components in packages.
|
|
27
|
+
* Only ES classes in ES modules are recognized; classes compiled to ES5 or CommonJS are left unchanged.
|
|
28
|
+
*/
|
|
29
|
+
function classComponentLoader(content) {
|
|
30
|
+
if (!/\bclass\b/.test(content) || !/\bextends\b/.test(content)) {
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
const source = typescript_1.default.createSourceFile(this.resourcePath, content, typescript_1.default.ScriptTarget.Latest, true, scriptKind(this.resourcePath));
|
|
34
|
+
// The wrapper adds an ESM import, which a CommonJS file cannot take.
|
|
35
|
+
if (!isModule(source)) {
|
|
36
|
+
return content;
|
|
37
|
+
}
|
|
38
|
+
const wrapped = (0, class_components_1.wrapClassRenders)(source);
|
|
39
|
+
return wrapped === source ? content : syntax_1.printer.printFile(wrapped);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=class-loader.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IPluginContext } from '@tarojs/service';
|
|
2
|
+
import type { ProjectModel } from '../../../project';
|
|
3
|
+
import { type BundleOutput } from './bundle';
|
|
4
|
+
import { type VendorManifest } from './manifest';
|
|
5
|
+
export { VendorManifest, collectNamespaceUsage } from './manifest';
|
|
6
|
+
export interface VendorPackage {
|
|
7
|
+
specifier: string;
|
|
8
|
+
file: string;
|
|
9
|
+
}
|
|
10
|
+
/** An application module that a bundled package imports through a project alias. */
|
|
11
|
+
export interface SourceImport {
|
|
12
|
+
/** Importing file inside the package, relative to the project. */
|
|
13
|
+
importer: string;
|
|
14
|
+
/** Application module, relative to the source root. */
|
|
15
|
+
file: string;
|
|
16
|
+
}
|
|
17
|
+
export interface VendorBuild {
|
|
18
|
+
packages: VendorPackage[];
|
|
19
|
+
/** Application files imported back by bundled packages (absolute paths). */
|
|
20
|
+
sourceFiles: string[];
|
|
21
|
+
sourceImports: SourceImport[];
|
|
22
|
+
/** Writes the bundle and declarations into `targetSource/__vendor__`. */
|
|
23
|
+
write(targetSource: string, sourcePaths: Map<string, string>): void;
|
|
24
|
+
/** What the bundle was built from; a later build with the same key reuses it. */
|
|
25
|
+
readonly bundleKey: string;
|
|
26
|
+
readonly bundleOutput: BundleOutput;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Bundles the modules recorded in `manifest`. Type-only entries are not bundled and only get declarations.
|
|
30
|
+
* When `previous` was bundled from the same runtime entries, its bundle is reused and only the declarations
|
|
31
|
+
* follow the new manifest.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildVendor(ctx: IPluginContext, model: ProjectModel, manifest: VendorManifest, previous?: VendorBuild): Promise<VendorBuild>;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
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.collectNamespaceUsage = exports.VendorManifest = void 0;
|
|
7
|
+
exports.buildVendor = buildVendor;
|
|
8
|
+
/*
|
|
9
|
+
* Vendor pipeline: the transform records bundled packages in a `VendorManifest` (manifest), `bundle`
|
|
10
|
+
* compiles them with Rspack, and `writeVendor` emits them into `<targetSource>/__vendor__` (output).
|
|
11
|
+
*/
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
+
const paths_1 = require("../../../shared/paths");
|
|
14
|
+
const bundle_1 = require("./bundle");
|
|
15
|
+
const manifest_1 = require("./manifest");
|
|
16
|
+
const output_1 = require("./output");
|
|
17
|
+
var manifest_2 = require("./manifest");
|
|
18
|
+
Object.defineProperty(exports, "VendorManifest", { enumerable: true, get: function () { return manifest_2.VendorManifest; } });
|
|
19
|
+
Object.defineProperty(exports, "collectNamespaceUsage", { enumerable: true, get: function () { return manifest_2.collectNamespaceUsage; } });
|
|
20
|
+
/** Everything in the manifest that changes the bundle: module layout + runtime entries and exports. */
|
|
21
|
+
function bundleKey(model, entries) {
|
|
22
|
+
return JSON.stringify([
|
|
23
|
+
model.layout.vendorRuntimeChunk,
|
|
24
|
+
model.layout.vendorRequireIdentifier,
|
|
25
|
+
entries
|
|
26
|
+
.filter((entry) => entry.runtime)
|
|
27
|
+
.map(({ specifier, names, star }) => [specifier, [...names].sort(), star])
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Bundles the modules recorded in `manifest`. Type-only entries are not bundled and only get declarations.
|
|
32
|
+
* When `previous` was bundled from the same runtime entries, its bundle is reused and only the declarations
|
|
33
|
+
* follow the new manifest.
|
|
34
|
+
*/
|
|
35
|
+
async function buildVendor(ctx, model, manifest, previous) {
|
|
36
|
+
const { appPath, sourcePath } = ctx.paths;
|
|
37
|
+
const { entries } = manifest;
|
|
38
|
+
const key = bundleKey(model, entries);
|
|
39
|
+
const runtimeEntries = entries.filter((entry) => entry.runtime);
|
|
40
|
+
const bundleOutput = previous?.bundleKey === key
|
|
41
|
+
? previous.bundleOutput
|
|
42
|
+
: runtimeEntries.length
|
|
43
|
+
? await (0, bundle_1.bundle)(ctx, model, runtimeEntries)
|
|
44
|
+
: { files: new Map(), binaryAssets: new Map(), sourceImports: new Map() };
|
|
45
|
+
const { files, binaryAssets, sourceImports } = bundleOutput;
|
|
46
|
+
const sourceFiles = [...sourceImports.keys()].sort();
|
|
47
|
+
return {
|
|
48
|
+
packages: entries.map((entry) => ({
|
|
49
|
+
specifier: entry.specifier,
|
|
50
|
+
file: (0, paths_1.posixPath)((0, manifest_1.vendorFile)(entry))
|
|
51
|
+
})),
|
|
52
|
+
sourceFiles,
|
|
53
|
+
sourceImports: sourceFiles.flatMap((file) => [...(sourceImports.get(file) ?? [])].sort().map((importer) => ({
|
|
54
|
+
importer: (0, paths_1.posixPath)(node_path_1.default.relative(appPath, importer)),
|
|
55
|
+
file: (0, paths_1.posixPath)(node_path_1.default.relative(sourcePath, file))
|
|
56
|
+
}))),
|
|
57
|
+
write: (targetSource, sourcePaths) => (0, output_1.writeVendor)(targetSource, entries, files, binaryAssets, sourcePaths, model.layout.vendorRequireIdentifier),
|
|
58
|
+
bundleKey: key,
|
|
59
|
+
bundleOutput
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export interface VendorEntry {
|
|
3
|
+
specifier: string;
|
|
4
|
+
/** File name without extension inside the vendor directory. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Exports read at runtime by the application, including `default`. */
|
|
7
|
+
names: Set<string>;
|
|
8
|
+
/** Exports only used as types, through a namespace import (`ns.Type`). */
|
|
9
|
+
typeNames: Set<string>;
|
|
10
|
+
/** Exports are not statically known: `export *`, `import()` or `require()`. */
|
|
11
|
+
star: boolean;
|
|
12
|
+
/** Referenced at runtime; type-only entries only get declarations. */
|
|
13
|
+
runtime: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Module path of `entry` inside the generated `src/`. */
|
|
16
|
+
export declare function vendorFile(entry: VendorEntry): string;
|
|
17
|
+
/** An export name as written in an export clause. */
|
|
18
|
+
export declare function exportName(name: string): string;
|
|
19
|
+
/** Third-party modules imported by the application, with the exports each import reads. */
|
|
20
|
+
export declare class VendorManifest {
|
|
21
|
+
private readonly bySpecifier;
|
|
22
|
+
private readonly names;
|
|
23
|
+
get entries(): VendorEntry[];
|
|
24
|
+
/**
|
|
25
|
+
* Records the import or export `owner` of `specifier` and returns the generated module path. Value
|
|
26
|
+
* references are bundled; type references only get declarations.
|
|
27
|
+
*/
|
|
28
|
+
record(specifier: string, owner: ts.Node, namespaces: NamespaceUsage, typeOnly: boolean): string;
|
|
29
|
+
private recordValues;
|
|
30
|
+
private recordTypes;
|
|
31
|
+
private entry;
|
|
32
|
+
}
|
|
33
|
+
export interface NamespaceUsage {
|
|
34
|
+
/** Members read at runtime (`ns.member`), keyed by the local namespace name. */
|
|
35
|
+
values: Map<string, Set<string>>;
|
|
36
|
+
/** Members used as types (`ns.Type`). */
|
|
37
|
+
types: Map<string, Set<string>>;
|
|
38
|
+
/** Namespaces used as a whole value. */
|
|
39
|
+
whole: Set<string>;
|
|
40
|
+
}
|
|
41
|
+
/** Records how each namespace import of `source` is used. */
|
|
42
|
+
export declare function collectNamespaceUsage(source: ts.SourceFile, isVendor: (specifier: string) => boolean): NamespaceUsage;
|
|
43
|
+
//# sourceMappingURL=manifest.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.VendorManifest = void 0;
|
|
7
|
+
exports.vendorFile = vendorFile;
|
|
8
|
+
exports.exportName = exportName;
|
|
9
|
+
exports.collectNamespaceUsage = collectNamespaceUsage;
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
12
|
+
const errors_1 = require("../../../shared/errors");
|
|
13
|
+
const layout_1 = require("../../../shared/layout");
|
|
14
|
+
/** Module path of `entry` inside the generated `src/`. */
|
|
15
|
+
function vendorFile(entry) {
|
|
16
|
+
return node_path_1.default.join(layout_1.vendorDirectory, `${entry.name}.js`);
|
|
17
|
+
}
|
|
18
|
+
/** An export name as written in an export clause. */
|
|
19
|
+
function exportName(name) {
|
|
20
|
+
return /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name);
|
|
21
|
+
}
|
|
22
|
+
/** Third-party modules imported by the application, with the exports each import reads. */
|
|
23
|
+
class VendorManifest {
|
|
24
|
+
bySpecifier = new Map();
|
|
25
|
+
names = new Map();
|
|
26
|
+
get entries() {
|
|
27
|
+
return [...this.bySpecifier.values()];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Records the import or export `owner` of `specifier` and returns the generated module path. Value
|
|
31
|
+
* references are bundled; type references only get declarations.
|
|
32
|
+
*/
|
|
33
|
+
record(specifier, owner, namespaces, typeOnly) {
|
|
34
|
+
const entry = this.entry(specifier);
|
|
35
|
+
if (typeOnly) {
|
|
36
|
+
this.recordTypes(entry, owner);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.recordValues(entry, owner, namespaces);
|
|
40
|
+
}
|
|
41
|
+
return vendorFile(entry);
|
|
42
|
+
}
|
|
43
|
+
recordValues(entry, owner, namespaces) {
|
|
44
|
+
entry.runtime = true;
|
|
45
|
+
if (typescript_1.default.isImportDeclaration(owner)) {
|
|
46
|
+
const clause = owner.importClause;
|
|
47
|
+
if (clause?.name) {
|
|
48
|
+
entry.names.add('default');
|
|
49
|
+
}
|
|
50
|
+
const bindings = clause?.namedBindings;
|
|
51
|
+
if (bindings && typescript_1.default.isNamespaceImport(bindings)) {
|
|
52
|
+
const local = bindings.name.text;
|
|
53
|
+
for (const member of namespaces.values.get(local) ?? []) {
|
|
54
|
+
entry.names.add(member);
|
|
55
|
+
}
|
|
56
|
+
for (const member of namespaces.types.get(local) ?? []) {
|
|
57
|
+
entry.typeNames.add(member);
|
|
58
|
+
}
|
|
59
|
+
// A namespace passed around as a value can be read through any export.
|
|
60
|
+
if (namespaces.whole.has(local)) {
|
|
61
|
+
entry.star = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (bindings) {
|
|
65
|
+
for (const element of bindings.elements) {
|
|
66
|
+
if (!element.isTypeOnly) {
|
|
67
|
+
entry.names.add((element.propertyName ?? element.name).text);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (typescript_1.default.isExportDeclaration(owner)) {
|
|
73
|
+
if (owner.exportClause && typescript_1.default.isNamedExports(owner.exportClause)) {
|
|
74
|
+
for (const element of owner.exportClause.elements) {
|
|
75
|
+
if (!element.isTypeOnly) {
|
|
76
|
+
entry.names.add((element.propertyName ?? element.name).text);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
entry.star = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// `import()` and `require()` read the whole module.
|
|
86
|
+
entry.star = true;
|
|
87
|
+
entry.names.add('default');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
recordTypes(entry, owner) {
|
|
91
|
+
const bindings = typescript_1.default.isImportDeclaration(owner) ? owner.importClause?.namedBindings : undefined;
|
|
92
|
+
const elements = bindings && typescript_1.default.isNamedImports(bindings)
|
|
93
|
+
? bindings.elements
|
|
94
|
+
: typescript_1.default.isExportDeclaration(owner) && owner.exportClause && typescript_1.default.isNamedExports(owner.exportClause)
|
|
95
|
+
? owner.exportClause.elements
|
|
96
|
+
: [];
|
|
97
|
+
for (const element of elements) {
|
|
98
|
+
entry.typeNames.add((element.propertyName ?? element.name).text);
|
|
99
|
+
}
|
|
100
|
+
if (typescript_1.default.isImportDeclaration(owner) && owner.importClause?.name) {
|
|
101
|
+
entry.typeNames.add('default');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
entry(specifier) {
|
|
105
|
+
const existing = this.bySpecifier.get(specifier);
|
|
106
|
+
if (existing) {
|
|
107
|
+
return existing;
|
|
108
|
+
}
|
|
109
|
+
const name = specifier.replaceAll('/', '__').replaceAll(/[^\w@.-]/g, '_');
|
|
110
|
+
const owner = this.names.get(name);
|
|
111
|
+
if (owner) {
|
|
112
|
+
(0, errors_1.fail)(`Third-party modules ${owner} and ${specifier} map to the same vendor file`);
|
|
113
|
+
}
|
|
114
|
+
this.names.set(name, specifier);
|
|
115
|
+
const entry = {
|
|
116
|
+
specifier,
|
|
117
|
+
name,
|
|
118
|
+
names: new Set(),
|
|
119
|
+
typeNames: new Set(),
|
|
120
|
+
star: false,
|
|
121
|
+
runtime: false
|
|
122
|
+
};
|
|
123
|
+
this.bySpecifier.set(specifier, entry);
|
|
124
|
+
return entry;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.VendorManifest = VendorManifest;
|
|
128
|
+
/** Records how each namespace import of `source` is used. */
|
|
129
|
+
function collectNamespaceUsage(source, isVendor) {
|
|
130
|
+
const usage = { values: new Map(), types: new Map(), whole: new Set() };
|
|
131
|
+
const namespaces = new Set();
|
|
132
|
+
for (const statement of source.statements) {
|
|
133
|
+
const bindings = typescript_1.default.isImportDeclaration(statement) ? statement.importClause?.namedBindings : undefined;
|
|
134
|
+
if (bindings &&
|
|
135
|
+
typescript_1.default.isNamespaceImport(bindings) &&
|
|
136
|
+
typescript_1.default.isImportDeclaration(statement) &&
|
|
137
|
+
!statement.importClause?.isTypeOnly &&
|
|
138
|
+
typescript_1.default.isStringLiteral(statement.moduleSpecifier) &&
|
|
139
|
+
isVendor(statement.moduleSpecifier.text)) {
|
|
140
|
+
namespaces.add(bindings.name.text);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!namespaces.size) {
|
|
144
|
+
return usage;
|
|
145
|
+
}
|
|
146
|
+
const add = (map, root, member) => {
|
|
147
|
+
if (!typescript_1.default.isIdentifier(root) || !namespaces.has(root.text)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const names = map.get(root.text) ?? new Set();
|
|
151
|
+
names.add(member);
|
|
152
|
+
map.set(root.text, names);
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
const visit = (node) => {
|
|
156
|
+
if (typescript_1.default.isImportDeclaration(node) || typescript_1.default.isTypeQueryNode(node)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (typescript_1.default.isPropertyAccessExpression(node) && typescript_1.default.isIdentifier(node.name)) {
|
|
160
|
+
if (add(usage.values, node.expression, node.name.text)) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (typescript_1.default.isElementAccessExpression(node) && typescript_1.default.isStringLiteralLike(node.argumentExpression)) {
|
|
165
|
+
if (add(usage.values, node.expression, node.argumentExpression.text)) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (typescript_1.default.isQualifiedName(node)) {
|
|
170
|
+
if (add(usage.types, node.left, node.right.text)) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else if (typescript_1.default.isIdentifier(node) && namespaces.has(node.text)) {
|
|
175
|
+
usage.whole.add(node.text);
|
|
176
|
+
}
|
|
177
|
+
typescript_1.default.forEachChild(node, visit);
|
|
178
|
+
};
|
|
179
|
+
visit(source);
|
|
180
|
+
return usage;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type VendorEntry } from './manifest';
|
|
2
|
+
/** Writes bundled files and per-entry declarations into `targetSource/__vendor__`. */
|
|
3
|
+
export declare function writeVendor(targetSource: string, entries: VendorEntry[], files: Map<string, string>, binaryAssets: Map<string, Buffer>, sourcePaths: Map<string, string>, vendorRequireIdentifier: string): void;
|
|
4
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
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.writeVendor = writeVendor;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
const emit_1 = require("../../../emit");
|
|
10
|
+
const layout_1 = require("../../../shared/layout");
|
|
11
|
+
const paths_1 = require("../../../shared/paths");
|
|
12
|
+
const bundle_1 = require("./bundle");
|
|
13
|
+
const manifest_1 = require("./manifest");
|
|
14
|
+
/** Loose declarations, so the generated project type-checks without installing the bundled vendor package. */
|
|
15
|
+
function renderDeclaration({ names, typeNames }) {
|
|
16
|
+
const lines = [...new Set([...names, ...typeNames])]
|
|
17
|
+
.sort()
|
|
18
|
+
.flatMap((name, index) => [
|
|
19
|
+
`declare const _${index}: any;`,
|
|
20
|
+
`type _${index} = any;`,
|
|
21
|
+
`export { _${index} as ${(0, manifest_1.exportName)(name)} };`
|
|
22
|
+
]);
|
|
23
|
+
return `${lines.length ? lines.join('\n') : 'export {};'}\n`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Keeps the nested runtime distinct from the require identifier injected by the Kit's bundler (and isolated
|
|
27
|
+
* across multiple modules), and points source placeholders at the generated module, relative to `outputFile`.
|
|
28
|
+
*/
|
|
29
|
+
function finalizeVendorFile(outputFile, content, targetSource, sourcePaths, vendorRequireIdentifier) {
|
|
30
|
+
const source = typescript_1.default.createSourceFile(outputFile, content, typescript_1.default.ScriptTarget.Latest, true, typescript_1.default.ScriptKind.JSX);
|
|
31
|
+
const result = typescript_1.default.transform(source, [
|
|
32
|
+
(context) => {
|
|
33
|
+
const visit = (node) => {
|
|
34
|
+
if (typescript_1.default.isIdentifier(node) && node.text === '__webpack_require__') {
|
|
35
|
+
return typescript_1.default.factory.createIdentifier(vendorRequireIdentifier);
|
|
36
|
+
}
|
|
37
|
+
if (typescript_1.default.isStringLiteral(node) && node.text.startsWith(bundle_1.sourcePrefix)) {
|
|
38
|
+
const relative = node.text.slice(bundle_1.sourcePrefix.length);
|
|
39
|
+
const generated = node_path_1.default.join(targetSource, sourcePaths.get(relative) ?? relative);
|
|
40
|
+
return typescript_1.default.factory.createStringLiteral((0, paths_1.relativeModule)(outputFile, generated));
|
|
41
|
+
}
|
|
42
|
+
return typescript_1.default.visitEachChild(node, visit, context);
|
|
43
|
+
};
|
|
44
|
+
return (node) => typescript_1.default.visitNode(node, visit);
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
try {
|
|
48
|
+
return typescript_1.default.createPrinter({ newLine: typescript_1.default.NewLineKind.LineFeed }).printFile(result.transformed[0]);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
result.dispose();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Writes bundled files and per-entry declarations into `targetSource/__vendor__`. */
|
|
55
|
+
function writeVendor(targetSource, entries, files, binaryAssets, sourcePaths, vendorRequireIdentifier) {
|
|
56
|
+
const target = node_path_1.default.join(targetSource, layout_1.vendorDirectory);
|
|
57
|
+
for (const [relative, content] of files) {
|
|
58
|
+
const outputFile = node_path_1.default.join(target, relative);
|
|
59
|
+
(0, emit_1.writeText)(outputFile, finalizeVendorFile(outputFile, content, targetSource, sourcePaths, vendorRequireIdentifier));
|
|
60
|
+
}
|
|
61
|
+
for (const [relative, content] of binaryAssets) {
|
|
62
|
+
(0, emit_1.writeText)(node_path_1.default.join(target, relative), content);
|
|
63
|
+
}
|
|
64
|
+
for (const entry of entries) {
|
|
65
|
+
(0, emit_1.writeText)(node_path_1.default.join(target, `${entry.name}.d.ts`), renderDeclaration(entry));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1,160 @@
|
|
|
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.collectStylesheetImportsOnly = collectStylesheetImportsOnly;
|
|
7
|
+
exports.appStyles = appStyles;
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
const errors_1 = require("../shared/errors");
|
|
10
|
+
const syntax_1 = require("../shared/syntax");
|
|
11
|
+
const imports_1 = require("./imports");
|
|
12
|
+
function isErasedAppImport(statement, valueIdentifiers) {
|
|
13
|
+
if ((0, syntax_1.isTypeOnlyReference)(statement)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const clause = statement.importClause;
|
|
17
|
+
if (!clause ||
|
|
18
|
+
!typescript_1.default.isStringLiteral(statement.moduleSpecifier) ||
|
|
19
|
+
!(0, imports_1.isTypeOnlyModule)(statement.moduleSpecifier.text)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const boundNames = [];
|
|
23
|
+
if (clause.name) {
|
|
24
|
+
boundNames.push(clause.name);
|
|
25
|
+
}
|
|
26
|
+
if (clause.namedBindings) {
|
|
27
|
+
if (typescript_1.default.isNamespaceImport(clause.namedBindings)) {
|
|
28
|
+
boundNames.push(clause.namedBindings.name);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
for (const element of clause.namedBindings.elements) {
|
|
32
|
+
boundNames.push(element.name);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return boundNames.length > 0 && boundNames.every((identifier) => !valueIdentifiers.has(identifier.text));
|
|
37
|
+
}
|
|
38
|
+
function collectStylesheetImportsOnly(filename) {
|
|
39
|
+
const source = (0, syntax_1.readSource)(filename);
|
|
40
|
+
const styles = [];
|
|
41
|
+
for (const statement of source.statements) {
|
|
42
|
+
if (typescript_1.default.isImportDeclaration(statement) &&
|
|
43
|
+
!statement.importClause &&
|
|
44
|
+
typescript_1.default.isStringLiteral(statement.moduleSpecifier) &&
|
|
45
|
+
(0, imports_1.isStylesheet)(statement.moduleSpecifier.text)) {
|
|
46
|
+
styles.push(statement.moduleSpecifier.text);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return styles;
|
|
50
|
+
}
|
|
51
|
+
function appStyles(filename) {
|
|
52
|
+
const source = (0, syntax_1.readSource)(filename);
|
|
53
|
+
const valueIdentifiers = (0, syntax_1.collectValueIdentifiers)(source);
|
|
54
|
+
const styles = [];
|
|
55
|
+
let app;
|
|
56
|
+
const candidates = new Map();
|
|
57
|
+
for (const statement of source.statements) {
|
|
58
|
+
if (typescript_1.default.isFunctionDeclaration(statement) && statement.name) {
|
|
59
|
+
candidates.set(statement.name.text, statement);
|
|
60
|
+
}
|
|
61
|
+
if (typescript_1.default.isVariableStatement(statement)) {
|
|
62
|
+
for (const item of statement.declarationList.declarations) {
|
|
63
|
+
if (!typescript_1.default.isIdentifier(item.name) ||
|
|
64
|
+
!item.initializer ||
|
|
65
|
+
!(typescript_1.default.isArrowFunction(item.initializer) || typescript_1.default.isFunctionExpression(item.initializer))) {
|
|
66
|
+
(0, errors_1.fail)('Additional App initialization is unsupported');
|
|
67
|
+
}
|
|
68
|
+
candidates.set(item.name.text, item.initializer);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const statement of source.statements) {
|
|
73
|
+
if (typescript_1.default.isImportDeclaration(statement)) {
|
|
74
|
+
if (!statement.importClause &&
|
|
75
|
+
typescript_1.default.isStringLiteral(statement.moduleSpecifier) &&
|
|
76
|
+
(0, imports_1.isStylesheet)(statement.moduleSpecifier.text)) {
|
|
77
|
+
styles.push(statement.moduleSpecifier.text);
|
|
78
|
+
}
|
|
79
|
+
else if (!isErasedAppImport(statement, valueIdentifiers)) {
|
|
80
|
+
(0, errors_1.fail)(`App supports type imports and styles only: ${filename}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (typescript_1.default.isFunctionDeclaration(statement)) {
|
|
84
|
+
if (statement.modifiers?.some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.DefaultKeyword)) {
|
|
85
|
+
app = statement;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (typescript_1.default.isVariableStatement(statement)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
else if (typescript_1.default.isExportAssignment(statement)) {
|
|
92
|
+
const value = typescript_1.default.isIdentifier(statement.expression)
|
|
93
|
+
? candidates.get(statement.expression.text)
|
|
94
|
+
: statement.expression;
|
|
95
|
+
if (!statement.isExportEquals &&
|
|
96
|
+
value &&
|
|
97
|
+
(typescript_1.default.isArrowFunction(value) || typescript_1.default.isFunctionExpression(value) || typescript_1.default.isFunctionDeclaration(value))) {
|
|
98
|
+
app = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (typescript_1.default.isTypeAliasDeclaration(statement) || typescript_1.default.isInterfaceDeclaration(statement)) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
(0, errors_1.fail)(`Unsupported App statement in ${filename}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!app?.body ||
|
|
109
|
+
app.parameters.length !== 1 ||
|
|
110
|
+
app.parameters[0].dotDotDotToken ||
|
|
111
|
+
app.parameters[0].initializer ||
|
|
112
|
+
(!typescript_1.default.isObjectBindingPattern(app.parameters[0].name) && !typescript_1.default.isIdentifier(app.parameters[0].name)) ||
|
|
113
|
+
app.modifiers?.some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.AsyncKeyword) ||
|
|
114
|
+
('asteriskToken' in app && app.asteriskToken)) {
|
|
115
|
+
(0, errors_1.fail)('App must be a function receiving { children }; App providers and lifecycle hooks need explicit adaptation');
|
|
116
|
+
}
|
|
117
|
+
let body = typescript_1.default.isBlock(app.body) && app.body.statements.length === 1 && typescript_1.default.isReturnStatement(app.body.statements[0])
|
|
118
|
+
? app.body.statements[0].expression
|
|
119
|
+
: app.body;
|
|
120
|
+
while (body && typescript_1.default.isParenthesizedExpression(body)) {
|
|
121
|
+
body = body.expression;
|
|
122
|
+
}
|
|
123
|
+
if (body && typescript_1.default.isJsxFragment(body)) {
|
|
124
|
+
const meaningful = body.children.filter((child) => !(typescript_1.default.isJsxText(child) && !child.text.trim()));
|
|
125
|
+
if (meaningful.length === 1 && typescript_1.default.isJsxExpression(meaningful[0]) && !meaningful[0].dotDotDotToken) {
|
|
126
|
+
body = meaningful[0].expression;
|
|
127
|
+
while (body && typescript_1.default.isParenthesizedExpression(body)) {
|
|
128
|
+
body = body.expression;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const paramName = app.parameters[0].name;
|
|
133
|
+
let returnsChildren = false;
|
|
134
|
+
if (typescript_1.default.isObjectBindingPattern(paramName)) {
|
|
135
|
+
const children = paramName.elements.find((item) => (item.propertyName ?? item.name).getText(source) === 'children');
|
|
136
|
+
returnsChildren = Boolean(children &&
|
|
137
|
+
!children.dotDotDotToken &&
|
|
138
|
+
!children.initializer &&
|
|
139
|
+
paramName.elements.length === 1 &&
|
|
140
|
+
body &&
|
|
141
|
+
typescript_1.default.isIdentifier(body) &&
|
|
142
|
+
body.text === children.name.getText(source));
|
|
143
|
+
}
|
|
144
|
+
else if (typescript_1.default.isIdentifier(paramName)) {
|
|
145
|
+
returnsChildren = Boolean(body &&
|
|
146
|
+
typescript_1.default.isPropertyAccessExpression(body) &&
|
|
147
|
+
!body.questionDotToken &&
|
|
148
|
+
typescript_1.default.isIdentifier(body.expression) &&
|
|
149
|
+
body.expression.text === paramName.text &&
|
|
150
|
+
body.name.text === 'children');
|
|
151
|
+
}
|
|
152
|
+
if (!returnsChildren) {
|
|
153
|
+
(0, errors_1.fail)('App must return children without side effects');
|
|
154
|
+
}
|
|
155
|
+
if (candidates.size > 1) {
|
|
156
|
+
(0, errors_1.fail)('Additional App initialization is unsupported');
|
|
157
|
+
}
|
|
158
|
+
return styles;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Definitions in Taro's order: `env` as `process.env.*`, then `defineConstants`, then the platform. */
|
|
2
|
+
export declare function buildDefines(env?: Record<string, unknown>, defineConstants?: Record<string, unknown>): Record<string, string>;
|
|
3
|
+
//# sourceMappingURL=defines.d.ts.map
|