@doubao-dev/taro-plugin-platform-doubao 0.10.3 → 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,96 @@
|
|
|
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.readTsConfig = readTsConfig;
|
|
7
|
+
exports.createResolvers = createResolvers;
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const core_1 = require("@rspack/core");
|
|
10
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
11
|
+
const paths_1 = require("../shared/paths");
|
|
12
|
+
function readTsConfig(appPath) {
|
|
13
|
+
const found = typescript_1.default.findConfigFile(appPath, (filename) => typescript_1.default.sys.fileExists(filename));
|
|
14
|
+
const file = found && (0, paths_1.inside)(appPath, found) ? found : undefined;
|
|
15
|
+
if (!file) {
|
|
16
|
+
return { fileNames: [], compilerOptions: {} };
|
|
17
|
+
}
|
|
18
|
+
const parsed = typescript_1.default.parseJsonConfigFileContent(typescript_1.default.readConfigFile(file, (filename) => typescript_1.default.sys.readFile(filename)).config, typescript_1.default.sys, node_path_1.default.dirname(file));
|
|
19
|
+
return { file, fileNames: parsed.fileNames, compilerOptions: parsed.options };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolves relative paths, Taro `config.alias` (with higher priority than `tsconfig.paths`, matching Webpack 5),
|
|
23
|
+
* and `tsconfig.paths` with the native Rspack resolver.
|
|
24
|
+
*/
|
|
25
|
+
function createResolvers(helper, alias, tsConfig) {
|
|
26
|
+
const bundleResolve = {
|
|
27
|
+
alias,
|
|
28
|
+
...(tsConfig.file ? { tsConfig: tsConfig.file } : {}),
|
|
29
|
+
mainFields: helper.defaultMainFields,
|
|
30
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.json'],
|
|
31
|
+
mainFiles: ['index'],
|
|
32
|
+
fallback: { fs: false, path: false }
|
|
33
|
+
};
|
|
34
|
+
const sharedOptions = {
|
|
35
|
+
symlinks: false,
|
|
36
|
+
mainFields: helper.defaultMainFields,
|
|
37
|
+
extensions: [...helper.SCRIPT_EXT, '.mts', '.cts', '.mjs', '.cjs', '.json', '.d.ts', '.d.mts', '.d.cts']
|
|
38
|
+
};
|
|
39
|
+
// 1. Taro `config.alias` + relative paths (no `tsconfig.paths`, no `node_modules`) so explicit `alias` wins.
|
|
40
|
+
const aliasWithoutPackages = new core_1.experiments.resolver.ResolverFactory({
|
|
41
|
+
...sharedOptions,
|
|
42
|
+
alias,
|
|
43
|
+
modules: []
|
|
44
|
+
});
|
|
45
|
+
// 2. Fallback to `tsconfig.paths` when `config.alias` did not match.
|
|
46
|
+
const tsConfigWithoutPackages = tsConfig.file
|
|
47
|
+
? new core_1.experiments.resolver.ResolverFactory({
|
|
48
|
+
...sharedOptions,
|
|
49
|
+
tsconfig: { configFile: tsConfig.file },
|
|
50
|
+
modules: []
|
|
51
|
+
})
|
|
52
|
+
: undefined;
|
|
53
|
+
// 3. Detect explicit package-to-package or package-subpath `config.alias` entries into `node_modules`.
|
|
54
|
+
const aliasWithPackages = alias
|
|
55
|
+
? new core_1.experiments.resolver.ResolverFactory({
|
|
56
|
+
...sharedOptions,
|
|
57
|
+
alias
|
|
58
|
+
})
|
|
59
|
+
: undefined;
|
|
60
|
+
const plainPackages = alias
|
|
61
|
+
? new core_1.experiments.resolver.ResolverFactory({
|
|
62
|
+
...sharedOptions
|
|
63
|
+
})
|
|
64
|
+
: undefined;
|
|
65
|
+
const resolveLocal = (from, specifier) => {
|
|
66
|
+
const directory = node_path_1.default.dirname(from);
|
|
67
|
+
const viaAlias = aliasWithoutPackages.sync(directory, specifier).path;
|
|
68
|
+
if (viaAlias) {
|
|
69
|
+
return viaAlias;
|
|
70
|
+
}
|
|
71
|
+
// If `specifier` explicitly matched a `config.alias` prefix (e.g. `~` -> `.doubao-input/src`) and failed to
|
|
72
|
+
// resolve there, do NOT fall back to a stale `tsconfig.paths` entry pointing outside `sourceRoot`.
|
|
73
|
+
const matchedExplicitAlias = alias &&
|
|
74
|
+
Object.keys(alias).some((key) => {
|
|
75
|
+
const cleanKey = key.endsWith('$') ? key.slice(0, -1) : key;
|
|
76
|
+
return key.endsWith('$')
|
|
77
|
+
? specifier === cleanKey
|
|
78
|
+
: specifier === cleanKey || specifier.startsWith(`${cleanKey}/`);
|
|
79
|
+
});
|
|
80
|
+
if (!matchedExplicitAlias && tsConfigWithoutPackages) {
|
|
81
|
+
const viaTsConfig = tsConfigWithoutPackages.sync(directory, specifier).path;
|
|
82
|
+
if (viaTsConfig) {
|
|
83
|
+
return viaTsConfig;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (aliasWithPackages && plainPackages) {
|
|
87
|
+
const aliasedPkg = aliasWithPackages.sync(directory, specifier).path;
|
|
88
|
+
if (aliasedPkg && plainPackages.sync(directory, specifier).path !== aliasedPkg) {
|
|
89
|
+
return aliasedPkg;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
};
|
|
94
|
+
return { resolveLocal, bundleResolve };
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=resolver.js.map
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
1
|
+
import { type IPluginContext } from '@tarojs/service';
|
|
2
|
+
import { type Options } from './compiler';
|
|
3
|
+
export declare function runSourceExport(ctx: IPluginContext, options: Options): Promise<void>;
|
|
3
4
|
//# sourceMappingURL=runner.d.ts.map
|
package/dist/runner.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runSourceExport = runSourceExport;
|
|
4
4
|
const compiler_1 = require("./compiler");
|
|
5
|
-
function runSourceExport(options) {
|
|
6
|
-
const report = (0, compiler_1.generateProject)(options);
|
|
7
|
-
|
|
5
|
+
async function runSourceExport(ctx, options) {
|
|
6
|
+
const report = await (0, compiler_1.generateProject)(ctx, options);
|
|
7
|
+
const scopePrefix = report.moduleName ? `[doubao:${report.moduleName}]` : '[doubao]';
|
|
8
|
+
console.log(`${scopePrefix} Generated ${report.pages.length} pages, ${report.sourceFiles.length} source files, ` +
|
|
9
|
+
`${report.assetFiles.length} assets, ${report.vendor.length} bundled packages`);
|
|
8
10
|
for (const warning of report.warnings) {
|
|
9
|
-
console.warn(
|
|
11
|
+
console.warn(`${scopePrefix} ${warning}`);
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DoubaoPluginError = void 0;
|
|
4
|
+
exports.fail = fail;
|
|
5
|
+
class DoubaoPluginError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`[doubao] ${message}`);
|
|
8
|
+
this.name = 'DoubaoPluginError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.DoubaoPluginError = DoubaoPluginError;
|
|
12
|
+
/** Fails generation with a message for the user. */
|
|
13
|
+
function fail(message) {
|
|
14
|
+
throw new DoubaoPluginError(message);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const generator = "@doubao-dev/taro-plugin-platform-doubao";
|
|
2
|
+
/** Generation report in the generated target directory; its `generator` field marks it as replaceable. */
|
|
3
|
+
export declare const reportFile = ".doubao-generated.json";
|
|
4
|
+
/** First line of generated project files outside `src/`; removing it hands the file over to the user. */
|
|
5
|
+
export declare const generatedMarker = "// Generated by @doubao-dev/taro-plugin-platform-doubao.\n";
|
|
6
|
+
/** Directory under `src/` holding isolated multi-project exports (`src/modules/<moduleName>/`). */
|
|
7
|
+
export declare const modulesDirectory = "modules";
|
|
8
|
+
/** Generated directory for bundled third-party packages. */
|
|
9
|
+
export declare const vendorDirectory = "__vendor__";
|
|
10
|
+
/** Generated directory for runtime setup imported before each page. */
|
|
11
|
+
export declare const setupDirectory = "__taro_compat__";
|
|
12
|
+
/** Generated directory for global declarations that live outside the source root. */
|
|
13
|
+
export declare const ambientDirectory = "taro-types";
|
|
14
|
+
/** Directories under the generated source directory that the source root cannot contain. */
|
|
15
|
+
export declare const reservedDirectories: ReadonlyArray<[name: string, purpose: string]>;
|
|
16
|
+
export interface TargetLayout {
|
|
17
|
+
moduleName?: string;
|
|
18
|
+
/** Always `<outputPath>/src`. */
|
|
19
|
+
hostSource: string;
|
|
20
|
+
/** `<outputPath>/src` in single-project mode; `<outputPath>/src/modules/<moduleName>` in module mode. */
|
|
21
|
+
targetSource: string;
|
|
22
|
+
/** Prefix prepended to page entries relative to `src/` (e.g. `modules/shop/` or `''`). */
|
|
23
|
+
entryPrefix: string;
|
|
24
|
+
/** Unique runtime chunk name inside `__vendor__/chunks/` so multi-module vendors never clash. */
|
|
25
|
+
vendorRuntimeChunk: string;
|
|
26
|
+
/** Unique require identifier inside emitted vendor bundles. */
|
|
27
|
+
vendorRequireIdentifier: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function normalizeModuleName(raw: string | undefined): string | undefined;
|
|
30
|
+
export declare function encodeModuleIdentifier(moduleName: string): string;
|
|
31
|
+
export declare function resolveTargetLayout(outputPath: string, rawModuleName?: string): TargetLayout;
|
|
32
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
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.reservedDirectories = exports.ambientDirectory = exports.setupDirectory = exports.vendorDirectory = exports.modulesDirectory = exports.generatedMarker = exports.reportFile = exports.generator = void 0;
|
|
7
|
+
exports.normalizeModuleName = normalizeModuleName;
|
|
8
|
+
exports.encodeModuleIdentifier = encodeModuleIdentifier;
|
|
9
|
+
exports.resolveTargetLayout = resolveTargetLayout;
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const errors_1 = require("./errors");
|
|
12
|
+
/*
|
|
13
|
+
* Layout of the generated output: the reserved names inside the generated `src/` (or module directory)
|
|
14
|
+
* and the markers that tell generated files apart from user-owned ones. Every stage reads these names from here.
|
|
15
|
+
*/
|
|
16
|
+
exports.generator = '@doubao-dev/taro-plugin-platform-doubao';
|
|
17
|
+
/** Generation report in the generated target directory; its `generator` field marks it as replaceable. */
|
|
18
|
+
exports.reportFile = '.doubao-generated.json';
|
|
19
|
+
/** First line of generated project files outside `src/`; removing it hands the file over to the user. */
|
|
20
|
+
exports.generatedMarker = `// Generated by ${exports.generator}.\n`;
|
|
21
|
+
/** Directory under `src/` holding isolated multi-project exports (`src/modules/<moduleName>/`). */
|
|
22
|
+
exports.modulesDirectory = 'modules';
|
|
23
|
+
/** Generated directory for bundled third-party packages. */
|
|
24
|
+
exports.vendorDirectory = '__vendor__';
|
|
25
|
+
/** Generated directory for runtime setup imported before each page. */
|
|
26
|
+
exports.setupDirectory = '__taro_compat__';
|
|
27
|
+
/** Generated directory for global declarations that live outside the source root. */
|
|
28
|
+
exports.ambientDirectory = 'taro-types';
|
|
29
|
+
/** Directories under the generated source directory that the source root cannot contain. */
|
|
30
|
+
exports.reservedDirectories = [
|
|
31
|
+
[exports.ambientDirectory, 'generated declarations'],
|
|
32
|
+
[exports.setupDirectory, 'generated setup'],
|
|
33
|
+
[exports.vendorDirectory, 'bundled packages']
|
|
34
|
+
];
|
|
35
|
+
const reservedModuleNames = new Set([
|
|
36
|
+
'pages',
|
|
37
|
+
'widgets',
|
|
38
|
+
'tools',
|
|
39
|
+
'auth',
|
|
40
|
+
'mcp-ui',
|
|
41
|
+
exports.modulesDirectory,
|
|
42
|
+
exports.ambientDirectory,
|
|
43
|
+
exports.setupDirectory,
|
|
44
|
+
exports.vendorDirectory
|
|
45
|
+
]);
|
|
46
|
+
function normalizeModuleName(raw) {
|
|
47
|
+
if (raw === undefined) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const trimmed = raw.trim();
|
|
51
|
+
if (!trimmed) {
|
|
52
|
+
(0, errors_1.fail)('moduleName cannot be empty when specified');
|
|
53
|
+
}
|
|
54
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(trimmed) || reservedModuleNames.has(trimmed)) {
|
|
55
|
+
(0, errors_1.fail)(`Invalid moduleName "${trimmed}"; use letters, digits, ".", "_" or "-", and avoid reserved directory names`);
|
|
56
|
+
}
|
|
57
|
+
return trimmed;
|
|
58
|
+
}
|
|
59
|
+
function encodeModuleIdentifier(moduleName) {
|
|
60
|
+
// `$` is disallowed in `moduleName` (`[A-Za-z0-9._-]`), so `$h` (`-`) and `$d` (`.`) are injective.
|
|
61
|
+
return moduleName.replaceAll('-', '$h').replaceAll('.', '$d');
|
|
62
|
+
}
|
|
63
|
+
function resolveTargetLayout(outputPath, rawModuleName) {
|
|
64
|
+
const moduleName = normalizeModuleName(rawModuleName);
|
|
65
|
+
const hostSource = node_path_1.default.join(outputPath, 'src');
|
|
66
|
+
if (!moduleName) {
|
|
67
|
+
return {
|
|
68
|
+
hostSource,
|
|
69
|
+
targetSource: hostSource,
|
|
70
|
+
entryPrefix: '',
|
|
71
|
+
vendorRuntimeChunk: 'runtime~vendor',
|
|
72
|
+
vendorRequireIdentifier: '__doubao_vendor_require__'
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const safeId = encodeModuleIdentifier(moduleName);
|
|
76
|
+
return {
|
|
77
|
+
moduleName,
|
|
78
|
+
hostSource,
|
|
79
|
+
targetSource: node_path_1.default.join(hostSource, exports.modulesDirectory, moduleName),
|
|
80
|
+
entryPrefix: `${exports.modulesDirectory}/${moduleName}/`,
|
|
81
|
+
vendorRuntimeChunk: `runtime~vendor~${safeId}`,
|
|
82
|
+
vendorRequireIdentifier: `__doubao_vendor_require_${safeId}__`
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IPluginContext } from '@tarojs/service';
|
|
2
|
+
export declare const sourcePattern: RegExp;
|
|
3
|
+
export declare const typeScriptPattern: RegExp;
|
|
4
|
+
export declare const declarationPattern: RegExp;
|
|
5
|
+
/** Keep Taro's platform resolution while including module scripts and declarations in the source graph. */
|
|
6
|
+
export declare function resolveSource(helper: IPluginContext['helper'], filename: string): string;
|
|
7
|
+
export declare function inside(root: string, filename: string): boolean;
|
|
8
|
+
export declare function walk(root: string): string[];
|
|
9
|
+
export declare function relativeImport(from: string, to: string): string;
|
|
10
|
+
/** POSIX form of a relative path, as used in module specifiers and reports. */
|
|
11
|
+
export declare function posixPath(relative: string): string;
|
|
12
|
+
/** Relative path for non-source assets such as styles, keeping the extension. */
|
|
13
|
+
export declare function relativeAsset(from: string, to: string): string;
|
|
14
|
+
/** Relative specifier from `from` to the local module `to`: scripts drop their extension, assets keep it. */
|
|
15
|
+
export declare function relativeModule(from: string, to: string): string;
|
|
16
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
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.declarationPattern = exports.typeScriptPattern = exports.sourcePattern = void 0;
|
|
7
|
+
exports.resolveSource = resolveSource;
|
|
8
|
+
exports.inside = inside;
|
|
9
|
+
exports.walk = walk;
|
|
10
|
+
exports.relativeImport = relativeImport;
|
|
11
|
+
exports.posixPath = posixPath;
|
|
12
|
+
exports.relativeAsset = relativeAsset;
|
|
13
|
+
exports.relativeModule = relativeModule;
|
|
14
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
15
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
16
|
+
const errors_1 = require("./errors");
|
|
17
|
+
/*
|
|
18
|
+
* Path arithmetic shared by the stages: which files are sources, containment, and the relative module
|
|
19
|
+
* specifiers written into generated code.
|
|
20
|
+
*/
|
|
21
|
+
exports.sourcePattern = /\.[cm]?[jt]sx?$/;
|
|
22
|
+
exports.typeScriptPattern = /\.[cm]?tsx?$/;
|
|
23
|
+
exports.declarationPattern = /\.d\.[cm]?ts$/;
|
|
24
|
+
/** Keep Taro's platform resolution while including module scripts and declarations in the source graph. */
|
|
25
|
+
function resolveSource(helper, filename) {
|
|
26
|
+
return helper.resolveMainFilePath(filename, [
|
|
27
|
+
...helper.SCRIPT_EXT,
|
|
28
|
+
'.mts',
|
|
29
|
+
'.cts',
|
|
30
|
+
'.mjs',
|
|
31
|
+
'.cjs',
|
|
32
|
+
'.json',
|
|
33
|
+
'.d.ts',
|
|
34
|
+
'.d.mts',
|
|
35
|
+
'.d.cts'
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
function inside(root, filename) {
|
|
39
|
+
const relative = node_path_1.default.relative(root, filename);
|
|
40
|
+
return (relative === '' ||
|
|
41
|
+
(!relative.startsWith(`..${node_path_1.default.sep}`) && relative !== '..' && !node_path_1.default.isAbsolute(relative)));
|
|
42
|
+
}
|
|
43
|
+
function walk(root) {
|
|
44
|
+
return node_fs_1.default.readdirSync(root, { withFileTypes: true }).flatMap((entry) => {
|
|
45
|
+
if (['node_modules', '.git'].includes(entry.name)) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const filename = node_path_1.default.join(root, entry.name);
|
|
49
|
+
if (entry.isSymbolicLink()) {
|
|
50
|
+
(0, errors_1.fail)(`Symbolic links in source assets are unsupported: ${filename}`);
|
|
51
|
+
}
|
|
52
|
+
return entry.isDirectory() ? walk(filename) : [filename];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function relativeImport(from, to) {
|
|
56
|
+
let relative = node_path_1.default.relative(node_path_1.default.dirname(from), to).split(node_path_1.default.sep).join('/');
|
|
57
|
+
if (/(?:\.d)?\.m[jt]s$/.test(relative)) {
|
|
58
|
+
relative = relative.replace(/(?:\.d)?\.m[jt]s$/, '.mjs');
|
|
59
|
+
}
|
|
60
|
+
else if (/(?:\.d)?\.c[jt]s$/.test(relative)) {
|
|
61
|
+
relative = relative.replace(/(?:\.d)?\.c[jt]s$/, '.cjs');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
relative = relative.replace(/(?:\.d)?\.[jt]sx?$/, '');
|
|
65
|
+
}
|
|
66
|
+
if (!relative.startsWith('.')) {
|
|
67
|
+
relative = `./${relative}`;
|
|
68
|
+
}
|
|
69
|
+
return relative;
|
|
70
|
+
}
|
|
71
|
+
/** POSIX form of a relative path, as used in module specifiers and reports. */
|
|
72
|
+
function posixPath(relative) {
|
|
73
|
+
return relative.split(node_path_1.default.sep).join('/');
|
|
74
|
+
}
|
|
75
|
+
/** Relative path for non-source assets such as styles, keeping the extension. */
|
|
76
|
+
function relativeAsset(from, to) {
|
|
77
|
+
return posixPath(node_path_1.default.relative(node_path_1.default.dirname(from), to)).replace(/^(?!\.)/, './');
|
|
78
|
+
}
|
|
79
|
+
/** Relative specifier from `from` to the local module `to`: scripts drop their extension, assets keep it. */
|
|
80
|
+
function relativeModule(from, to) {
|
|
81
|
+
return exports.sourcePattern.test(to) ? relativeImport(from, to) : relativeAsset(from, to);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export declare const printer: ts.Printer;
|
|
3
|
+
export declare function readSource(filename: string): ts.SourceFile;
|
|
4
|
+
export declare function moduleName(node: ts.Node): ts.StringLiteral | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* True when the reference is erased at compile time: `import type`, `export type`, `import('x').T`, or an
|
|
7
|
+
* import whose named bindings are all inline `type` specifiers.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isTypeOnlyReference(node: ts.Node): boolean;
|
|
10
|
+
export interface LiveSymbolUsage {
|
|
11
|
+
/** Top-level import local binding names confirmed by `TypeChecker` to be referenced in live value positions. */
|
|
12
|
+
valueImportNames: Set<string>;
|
|
13
|
+
/** Top-level namespace/default identifiers used as the root of a `QualifiedName` (`React.FC`, `Taro.General`). */
|
|
14
|
+
qualifiedTypeRoots: Set<string>;
|
|
15
|
+
/** All identifier names referenced in live (non-dead) AST nodes outside `ImportDeclaration`s. */
|
|
16
|
+
liveReferencedNames: Set<string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Stage 2 semantic collection on the original `ts.SourceFile` (skipping `deadNodes`):
|
|
20
|
+
* Uses `ts.TypeChecker` when available so local variables shadowing an import name are never mistaken for
|
|
21
|
+
* runtime uses of that import, and `typeof ImportedValue` (`TypeQueryNode`) is accurately classified.
|
|
22
|
+
*/
|
|
23
|
+
export declare function collectLiveSymbolUsage(source: ts.SourceFile, checker?: ts.TypeChecker, deadNodes?: Set<ts.Node>): LiveSymbolUsage;
|
|
24
|
+
export declare function collectValueIdentifiers(source: ts.SourceFile): Set<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Strips ambient global `declare const/let/var <KEY>` declarations for constants that have already been
|
|
27
|
+
* AST-inlined via `defineConstants`, preventing multi-module global `.d.ts` redeclaration errors.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sanitizeAmbientDeclaration(source: ts.SourceFile, inlinedIdentifierKeys: Set<string>): ts.SourceFile;
|
|
30
|
+
export declare function rewrite(source: ts.SourceFile, replace: (literal: ts.StringLiteral, owner: ts.Node) => string): string;
|
|
31
|
+
//# sourceMappingURL=syntax.d.ts.map
|