ttsc 0.12.3 → 0.13.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/cmd/platform/main.go +9 -0
- package/cmd/ttsc/api_compile.go +122 -101
- package/cmd/ttsc/api_compile_branches_test.go +55 -57
- package/cmd/ttsc/api_transform.go +67 -49
- package/cmd/ttsc/api_transform_branches_test.go +30 -32
- package/cmd/ttsc/build.go +141 -108
- package/cmd/ttsc/build_branches_test.go +95 -97
- package/cmd/ttsc/filter.go +70 -0
- package/cmd/ttsc/filter_strips_unknown_forwarded_flag_test.go +61 -0
- package/cmd/ttsc/flags_gen.go +30 -0
- package/cmd/ttsc/helpers_test.go +39 -28
- package/cmd/ttsc/main.go +111 -104
- package/cmd/ttsc/main_alias_branches_test.go +21 -23
- package/cmd/ttscserver/main.go +96 -90
- package/cmd/ttscserver/run_lsp_prefers_tsgo_flag_test.go +22 -22
- package/cmd/ttscserver/run_lsp_reports_server_error_test.go +22 -22
- package/cmd/ttscserver/run_lsp_uses_tsgo_environment_test.go +23 -23
- package/cmd/utility-host/main.go +30 -23
- package/driver/lsp.go +53 -7
- package/driver/plugins.go +88 -72
- package/driver/program.go +464 -340
- package/driver/rewrite.go +477 -380
- package/internal/lspserver/lsp_envelope.go +64 -64
- package/internal/lspserver/lsp_frame.go +60 -60
- package/internal/lspserver/lsp_plugin.go +57 -57
- package/internal/lspserver/lsp_proxy.go +265 -251
- package/internal/lspserver/lsp_server.go +155 -144
- package/lib/TtscCompiler.d.ts +7 -0
- package/lib/TtscCompiler.js +7 -0
- package/lib/TtscCompiler.js.map +1 -1
- package/lib/compiler/internal/buildNativeCompiler.d.ts +11 -1
- package/lib/compiler/internal/buildNativeCompiler.js +23 -3
- package/lib/compiler/internal/buildNativeCompiler.js.map +1 -1
- package/lib/compiler/internal/compileProjectInMemory.d.ts +9 -0
- package/lib/compiler/internal/compileProjectInMemory.js +36 -21
- package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
- package/lib/compiler/internal/paths.d.ts +27 -0
- package/lib/compiler/internal/paths.js +70 -0
- package/lib/compiler/internal/paths.js.map +1 -0
- package/lib/compiler/internal/project/readProjectConfig.d.ts +9 -1
- package/lib/compiler/internal/project/readProjectConfig.js +80 -1
- package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
- package/lib/compiler/internal/project/resolveProjectConfig.d.ts +13 -1
- package/lib/compiler/internal/project/resolveProjectConfig.js +42 -1
- package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -1
- package/lib/compiler/internal/resolveBinary.d.ts +9 -1
- package/lib/compiler/internal/resolveBinary.js +17 -1
- package/lib/compiler/internal/resolveBinary.js.map +1 -1
- package/lib/compiler/internal/resolveEmittedJavaScript.d.ts +16 -1
- package/lib/compiler/internal/resolveEmittedJavaScript.js +42 -10
- package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
- package/lib/compiler/internal/resolveTsgo.d.ts +21 -1
- package/lib/compiler/internal/resolveTsgo.js +23 -1
- package/lib/compiler/internal/resolveTsgo.js.map +1 -1
- package/lib/compiler/internal/runBuild.d.ts +24 -4
- package/lib/compiler/internal/runBuild.js +355 -93
- package/lib/compiler/internal/runBuild.js.map +1 -1
- package/lib/compiler/internal/runSingleFileEmit.d.ts +10 -1
- package/lib/compiler/internal/runSingleFileEmit.js +14 -1
- package/lib/compiler/internal/runSingleFileEmit.js.map +1 -1
- package/lib/compiler/internal/sharedHostHelpers.d.ts +5 -0
- package/lib/compiler/internal/sharedHostHelpers.js +6 -2
- package/lib/compiler/internal/sharedHostHelpers.js.map +1 -1
- package/lib/compiler/internal/spawnNative.d.ts +21 -0
- package/lib/compiler/internal/spawnNative.js +59 -0
- package/lib/compiler/internal/spawnNative.js.map +1 -0
- package/lib/compiler/internal/transformProjectInMemory.d.ts +15 -1
- package/lib/compiler/internal/transformProjectInMemory.js +57 -61
- package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
- package/lib/flags/parser.d.ts +63 -0
- package/lib/flags/parser.js +254 -0
- package/lib/flags/parser.js.map +1 -0
- package/lib/flags/schema.d.ts +147 -0
- package/lib/flags/schema.js +405 -0
- package/lib/flags/schema.js.map +1 -0
- package/lib/launcher/internal/getCompilerVersionText.js +7 -0
- package/lib/launcher/internal/getCompilerVersionText.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.js +35 -0
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/resolveCacheDir.d.ts +9 -0
- package/lib/launcher/internal/resolveCacheDir.js +22 -0
- package/lib/launcher/internal/resolveCacheDir.js.map +1 -0
- package/lib/launcher/internal/resolveTtscserverBinary.js +2 -0
- package/lib/launcher/internal/resolveTtscserverBinary.js.map +1 -1
- package/lib/launcher/internal/runTtsc.d.ts +10 -0
- package/lib/launcher/internal/runTtsc.js +90 -153
- package/lib/launcher/internal/runTtsc.js.map +1 -1
- package/lib/launcher/internal/runTtscserver.js +10 -35
- package/lib/launcher/internal/runTtscserver.js.map +1 -1
- package/lib/launcher/internal/runTtsx.d.ts +8 -0
- package/lib/launcher/internal/runTtsx.js +137 -79
- package/lib/launcher/internal/runTtsx.js.map +1 -1
- package/lib/plugin/internal/buildSourcePlugin.d.ts +38 -0
- package/lib/plugin/internal/buildSourcePlugin.js +40 -17
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
- package/lib/plugin/internal/loadProjectPlugins.d.ts +26 -0
- package/lib/plugin/internal/loadProjectPlugins.js +90 -41
- package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
- package/lib/structures/ITtscCompilerTransformation.d.ts +15 -2
- package/lib/structures/ITtscPlugin.d.ts +24 -0
- package/lib/structures/ITtscPluginCapabilities.d.ts +29 -0
- package/lib/structures/ITtscPluginCapabilities.js +3 -0
- package/lib/structures/ITtscPluginCapabilities.js.map +1 -0
- package/lib/structures/index.d.ts +1 -0
- package/lib/structures/index.js +1 -0
- package/lib/structures/index.js.map +1 -1
- package/lib/structures/internal/ITtscLoadedNativePlugin.d.ts +5 -0
- package/lib/structures/internal/TtscCommonOptions.d.ts +19 -0
- package/lib/structures/internal/TtscSingleFileEmitOptions.d.ts +0 -2
- package/package.json +9 -9
- package/shim/ast/shim.go +24 -0
- package/shim/checker/shim.go +35 -0
- package/shim/core/shim.go +17 -0
- package/shim/diagnosticwriter/shim.go +4 -0
- package/shim/lsp/shim.go +3 -3
- package/shim/printer/shim.go +20 -0
- package/src/TtscCompiler.ts +7 -0
- package/src/compiler/internal/buildNativeCompiler.ts +23 -3
- package/src/compiler/internal/compileProjectInMemory.ts +34 -25
- package/src/compiler/internal/paths.ts +68 -0
- package/src/compiler/internal/project/readProjectConfig.ts +86 -1
- package/src/compiler/internal/project/resolveProjectConfig.ts +44 -1
- package/src/compiler/internal/resolveBinary.ts +17 -1
- package/src/compiler/internal/resolveEmittedJavaScript.ts +43 -12
- package/src/compiler/internal/resolveTsgo.ts +29 -1
- package/src/compiler/internal/runBuild.ts +398 -112
- package/src/compiler/internal/runSingleFileEmit.ts +14 -1
- package/src/compiler/internal/sharedHostHelpers.ts +7 -7
- package/src/compiler/internal/spawnNative.ts +64 -0
- package/src/compiler/internal/transformProjectInMemory.ts +47 -67
- package/src/flags/parser.ts +367 -0
- package/src/flags/schema.ts +570 -0
- package/src/launcher/internal/getCompilerVersionText.ts +7 -0
- package/src/launcher/internal/prepareExecution.ts +35 -0
- package/src/launcher/internal/resolveCacheDir.ts +19 -0
- package/src/launcher/internal/resolveTtscserverBinary.ts +2 -0
- package/src/launcher/internal/runTtsc.ts +97 -143
- package/src/launcher/internal/runTtscserver.ts +9 -1
- package/src/launcher/internal/runTtsx.ts +149 -82
- package/src/plugin/internal/buildSourcePlugin.ts +40 -14
- package/src/plugin/internal/loadProjectPlugins.ts +116 -45
- package/src/structures/ITtscCompilerTransformation.ts +15 -2
- package/src/structures/ITtscPlugin.ts +26 -1
- package/src/structures/ITtscPluginCapabilities.ts +29 -0
- package/src/structures/index.ts +1 -0
- package/src/structures/internal/ITtscLoadedNativePlugin.ts +5 -0
- package/src/structures/internal/TtscCommonOptions.ts +19 -0
- package/src/structures/internal/TtscSingleFileEmitOptions.ts +0 -2
- package/tools/gen_shims/main.go +43 -8
- package/utility/flags_gen.go +30 -0
- package/utility/host.go +304 -245
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walk up the directory tree from `__dirname` until a directory that contains
|
|
3
|
+
* both `package.json` and `go.mod` is found. This is the `packages/ttsc` root
|
|
4
|
+
* and must be passed to `buildNativeCompiler` so it can locate `cmd/ttsc`.
|
|
5
|
+
*
|
|
6
|
+
* Uses `fs.realpathSync.native` when available to resolve symlinks identically
|
|
7
|
+
* to the Go toolchain's own path resolution.
|
|
8
|
+
*
|
|
9
|
+
* Throws when the root cannot be found (i.e. the package is not in a Go
|
|
10
|
+
* workspace), which would indicate a broken installation.
|
|
11
|
+
*/
|
|
12
|
+
export declare function packageRootDir(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Walk up the directory tree from `from` looking for a `go.mod` file. Stops
|
|
15
|
+
* after `maxDepth` hops so callers can bound the search to a known
|
|
16
|
+
* neighbourhood of the plugin source directory.
|
|
17
|
+
*
|
|
18
|
+
* Returns the absolute path to the first `go.mod` found, or `null` when no
|
|
19
|
+
* `go.mod` exists within the depth limit or filesystem root is reached first.
|
|
20
|
+
*/
|
|
21
|
+
export declare function findNearestGoMod(from: string, maxDepth: number): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Return `true` when a relative path escapes its base directory — i.e. starts
|
|
24
|
+
* with `..` or is an absolute path. Used by callers that need to guard against
|
|
25
|
+
* path traversal before building output keys or spawning subprocesses.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isOutsideRelativePath(relative: string): boolean;
|
|
@@ -0,0 +1,70 @@
|
|
|
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.packageRootDir = packageRootDir;
|
|
7
|
+
exports.findNearestGoMod = findNearestGoMod;
|
|
8
|
+
exports.isOutsideRelativePath = isOutsideRelativePath;
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
/**
|
|
12
|
+
* Walk up the directory tree from `__dirname` until a directory that contains
|
|
13
|
+
* both `package.json` and `go.mod` is found. This is the `packages/ttsc` root
|
|
14
|
+
* and must be passed to `buildNativeCompiler` so it can locate `cmd/ttsc`.
|
|
15
|
+
*
|
|
16
|
+
* Uses `fs.realpathSync.native` when available to resolve symlinks identically
|
|
17
|
+
* to the Go toolchain's own path resolution.
|
|
18
|
+
*
|
|
19
|
+
* Throws when the root cannot be found (i.e. the package is not in a Go
|
|
20
|
+
* workspace), which would indicate a broken installation.
|
|
21
|
+
*/
|
|
22
|
+
function packageRootDir() {
|
|
23
|
+
let current = node_path_1.default.resolve(__dirname);
|
|
24
|
+
while (true) {
|
|
25
|
+
if (node_fs_1.default.existsSync(node_path_1.default.join(current, "package.json")) &&
|
|
26
|
+
node_fs_1.default.existsSync(node_path_1.default.join(current, "go.mod"))) {
|
|
27
|
+
return node_fs_1.default.realpathSync.native?.(current) ?? node_fs_1.default.realpathSync(current);
|
|
28
|
+
}
|
|
29
|
+
const parent = node_path_1.default.dirname(current);
|
|
30
|
+
if (parent === current) {
|
|
31
|
+
throw new Error("ttsc: package root not found for native compiler build");
|
|
32
|
+
}
|
|
33
|
+
current = parent;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Walk up the directory tree from `from` looking for a `go.mod` file. Stops
|
|
38
|
+
* after `maxDepth` hops so callers can bound the search to a known
|
|
39
|
+
* neighbourhood of the plugin source directory.
|
|
40
|
+
*
|
|
41
|
+
* Returns the absolute path to the first `go.mod` found, or `null` when no
|
|
42
|
+
* `go.mod` exists within the depth limit or filesystem root is reached first.
|
|
43
|
+
*/
|
|
44
|
+
function findNearestGoMod(from, maxDepth) {
|
|
45
|
+
let current = node_path_1.default.resolve(from);
|
|
46
|
+
let depth = 0;
|
|
47
|
+
while (true) {
|
|
48
|
+
const candidate = node_path_1.default.join(current, "go.mod");
|
|
49
|
+
if (node_fs_1.default.existsSync(candidate))
|
|
50
|
+
return candidate;
|
|
51
|
+
if (depth >= maxDepth)
|
|
52
|
+
return null;
|
|
53
|
+
const parent = node_path_1.default.dirname(current);
|
|
54
|
+
if (parent === current)
|
|
55
|
+
return null;
|
|
56
|
+
current = parent;
|
|
57
|
+
depth += 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Return `true` when a relative path escapes its base directory — i.e. starts
|
|
62
|
+
* with `..` or is an absolute path. Used by callers that need to guard against
|
|
63
|
+
* path traversal before building output keys or spawning subprocesses.
|
|
64
|
+
*/
|
|
65
|
+
function isOutsideRelativePath(relative) {
|
|
66
|
+
return (relative === ".." ||
|
|
67
|
+
relative.startsWith(`..${node_path_1.default.sep}`) ||
|
|
68
|
+
node_path_1.default.isAbsolute(relative));
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../../src/compiler/internal/paths.ts"],"names":[],"mappings":";;;;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B;;;;;;;;;;GAUG;AACH;IACE,IAAI,OAAO,GAAG,mBAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,IAAI,EAAE,CAAC;QACZ,IACE,iBAAE,CAAC,UAAU,CAAC,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YACjD,iBAAE,CAAC,UAAU,CAAC,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,EAC3C,C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/internal/ITtscParsedProjectConfig";
|
|
2
2
|
import type { ITtscProjectLocatorOptions } from "../../../structures/internal/ITtscProjectLocatorOptions";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Read and resolve the project config subset used by ttsc.
|
|
5
|
+
*
|
|
6
|
+
* Follows `extends` chains (including arrays) and merges compiler options with
|
|
7
|
+
* later configs taking precedence. Path-typed options (`baseUrl`,
|
|
8
|
+
* `declarationDir`, `rootDir`) are resolved relative to the config that
|
|
9
|
+
* declares them. The `outDir` is resolved to an absolute path. Plugins are
|
|
10
|
+
* inherited from the nearest ancestor that declares them.
|
|
11
|
+
*/
|
|
4
12
|
export declare function readProjectConfig(opts?: ITtscProjectLocatorOptions): ITtscParsedProjectConfig;
|
|
@@ -8,8 +8,20 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
8
8
|
const node_module_1 = require("node:module");
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const resolveProjectConfig_1 = require("./resolveProjectConfig");
|
|
11
|
+
/**
|
|
12
|
+
* Compiler option keys whose values are file-system paths that must be resolved
|
|
13
|
+
* relative to the tsconfig that declares them, not the project root.
|
|
14
|
+
*/
|
|
11
15
|
const PATH_OPTIONS = new Set(["baseUrl", "declarationDir", "rootDir"]);
|
|
12
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Read and resolve the project config subset used by ttsc.
|
|
18
|
+
*
|
|
19
|
+
* Follows `extends` chains (including arrays) and merges compiler options with
|
|
20
|
+
* later configs taking precedence. Path-typed options (`baseUrl`,
|
|
21
|
+
* `declarationDir`, `rootDir`) are resolved relative to the config that
|
|
22
|
+
* declares them. The `outDir` is resolved to an absolute path. Plugins are
|
|
23
|
+
* inherited from the nearest ancestor that declares them.
|
|
24
|
+
*/
|
|
13
25
|
function readProjectConfig(opts = {}) {
|
|
14
26
|
const tsconfig = (0, resolveProjectConfig_1.resolveProjectConfig)(opts);
|
|
15
27
|
const root = opts.projectRoot
|
|
@@ -27,9 +39,17 @@ function readProjectConfig(opts = {}) {
|
|
|
27
39
|
root,
|
|
28
40
|
};
|
|
29
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Type guard: accept any non-null object as a plugin config entry. This is
|
|
44
|
+
* intentionally loose because the shape is validated later by plugin loaders.
|
|
45
|
+
*/
|
|
30
46
|
function isProjectPluginConfig(value) {
|
|
31
47
|
return typeof value === "object" && value !== null;
|
|
32
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolve symlinks on `location`, returning the original path when
|
|
51
|
+
* `realpathSync` fails (e.g. when the file does not yet exist).
|
|
52
|
+
*/
|
|
33
53
|
function resolveRealPath(location) {
|
|
34
54
|
try {
|
|
35
55
|
return node_fs_1.default.realpathSync(location);
|
|
@@ -38,9 +58,17 @@ function resolveRealPath(location) {
|
|
|
38
58
|
return location;
|
|
39
59
|
}
|
|
40
60
|
}
|
|
61
|
+
/** Resolve `target` against `cwd` when it is not already absolute. */
|
|
41
62
|
function resolveAbsolutePath(cwd, target) {
|
|
42
63
|
return node_path_1.default.isAbsolute(target) ? target : node_path_1.default.resolve(cwd, target);
|
|
43
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Recursively read and merge `compilerOptions` from `tsconfig` and all configs
|
|
67
|
+
* in its `extends` chain. `seen` tracks canonical paths to detect circular
|
|
68
|
+
* `extends` references; the current config is removed from `seen` in the
|
|
69
|
+
* `finally` block so sibling-referenced configs can be visited again via a
|
|
70
|
+
* different parent.
|
|
71
|
+
*/
|
|
44
72
|
function readResolvedCompilerOptions(tsconfig, seen = new Set()) {
|
|
45
73
|
const canonical = resolveRealPath(tsconfig);
|
|
46
74
|
if (seen.has(canonical)) {
|
|
@@ -85,6 +113,16 @@ function readResolvedCompilerOptions(tsconfig, seen = new Set()) {
|
|
|
85
113
|
seen.delete(canonical);
|
|
86
114
|
}
|
|
87
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolve the base compiler options from the `extends` field of a tsconfig.
|
|
118
|
+
*
|
|
119
|
+
* - String: a single base config; options are returned directly.
|
|
120
|
+
* - Array: multiple base configs merged left-to-right (later entries win).
|
|
121
|
+
* - Absent / non-string non-array: returns empty options.
|
|
122
|
+
*
|
|
123
|
+
* Plugin inheritance: when the current config in an array chain explicitly
|
|
124
|
+
* declares `plugins`, subsequent configs in the array do not override them.
|
|
125
|
+
*/
|
|
88
126
|
function resolveBaseCompilerOptions(tsconfig, extended, seen) {
|
|
89
127
|
if (typeof extended === "string") {
|
|
90
128
|
return readResolvedCompilerOptions(resolveExtendsConfig(tsconfig, extended), seen);
|
|
@@ -129,6 +167,10 @@ function resolveBaseCompilerOptions(tsconfig, extended, seen) {
|
|
|
129
167
|
}
|
|
130
168
|
return merged;
|
|
131
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Resolve path-typed compiler options to absolute paths using the directory of
|
|
172
|
+
* the tsconfig that declared each option (`baseDirs`).
|
|
173
|
+
*/
|
|
132
174
|
function resolvePathOptions(options, baseDirs) {
|
|
133
175
|
const resolved = { ...options };
|
|
134
176
|
for (const key of PATH_OPTIONS) {
|
|
@@ -140,6 +182,16 @@ function resolvePathOptions(options, baseDirs) {
|
|
|
140
182
|
}
|
|
141
183
|
return resolved;
|
|
142
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Resolve an `extends` specifier to an absolute path using the same rules as
|
|
187
|
+
* TypeScript's config resolution:
|
|
188
|
+
*
|
|
189
|
+
* - Absolute path: used directly.
|
|
190
|
+
* - Relative specifier (`./`, `../`, `.`, `..`): resolved against the declaring
|
|
191
|
+
* tsconfig's directory with fallback extension candidates.
|
|
192
|
+
* - Bare package specifier: resolved through Node's module resolver (the resolver
|
|
193
|
+
* also tries appending `.json` when the first attempt fails).
|
|
194
|
+
*/
|
|
143
195
|
function resolveExtendsConfig(tsconfig, specifier) {
|
|
144
196
|
const baseDir = node_path_1.default.dirname(tsconfig);
|
|
145
197
|
if (node_path_1.default.isAbsolute(specifier)) {
|
|
@@ -156,6 +208,10 @@ function resolveExtendsConfig(tsconfig, specifier) {
|
|
|
156
208
|
return resolveRealPath(resolver.resolve(`${specifier}.json`));
|
|
157
209
|
}
|
|
158
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Given an on-disk location, try the path as-is, with `.json` appended, and as
|
|
213
|
+
* a directory containing `tsconfig.json`. Returns the first match or throws.
|
|
214
|
+
*/
|
|
159
215
|
function resolveExistingExtendsPath(location) {
|
|
160
216
|
const candidates = new Set([
|
|
161
217
|
location,
|
|
@@ -169,6 +225,10 @@ function resolveExistingExtendsPath(location) {
|
|
|
169
225
|
}
|
|
170
226
|
throw new Error(`ttsc: extended tsconfig not found: ${location}`);
|
|
171
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Return true when `specifier` is a relative path reference: `.`, `..`, or a
|
|
230
|
+
* string starting with `./`, `../`, `.\\`, or `..\\`.
|
|
231
|
+
*/
|
|
172
232
|
function isRelativeSpecifier(specifier) {
|
|
173
233
|
return (specifier === "." ||
|
|
174
234
|
specifier === ".." ||
|
|
@@ -177,9 +237,18 @@ function isRelativeSpecifier(specifier) {
|
|
|
177
237
|
specifier.startsWith(".\\") ||
|
|
178
238
|
specifier.startsWith("..\\"));
|
|
179
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Parse a JSONC (JSON with Comments) string by stripping comments and trailing
|
|
242
|
+
* commas before handing off to `JSON.parse`.
|
|
243
|
+
*/
|
|
180
244
|
function parseJsonc(input) {
|
|
181
245
|
return JSON.parse(stripTrailingCommas(stripComments(input)));
|
|
182
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Remove `//` line comments and `/* block comments *\/` from a JSONC string.
|
|
249
|
+
* Correctly handles strings that contain comment-like character sequences by
|
|
250
|
+
* tracking string boundaries and escape characters.
|
|
251
|
+
*/
|
|
183
252
|
function stripComments(input) {
|
|
184
253
|
let output = "";
|
|
185
254
|
let inBlockComment = false;
|
|
@@ -238,6 +307,11 @@ function stripComments(input) {
|
|
|
238
307
|
}
|
|
239
308
|
return output;
|
|
240
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Remove trailing commas before `}` or `]` from a JSON string (after comments
|
|
312
|
+
* have already been stripped). Handles string boundaries and escape characters
|
|
313
|
+
* to avoid removing commas inside string values.
|
|
314
|
+
*/
|
|
241
315
|
function stripTrailingCommas(input) {
|
|
242
316
|
let output = "";
|
|
243
317
|
let inString = false;
|
|
@@ -275,6 +349,11 @@ function stripTrailingCommas(input) {
|
|
|
275
349
|
}
|
|
276
350
|
return output;
|
|
277
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Return the first non-whitespace character at or after position `from` in
|
|
354
|
+
* `input`, or `undefined` when only whitespace remains. Used by
|
|
355
|
+
* `stripTrailingCommas` to detect whether a comma is trailing.
|
|
356
|
+
*/
|
|
278
357
|
function nextNonWhitespace(input, from) {
|
|
279
358
|
for (let i = from; i < input.length; i += 1) {
|
|
280
359
|
const current = input[i];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readProjectConfig.js","sourceRoot":"","sources":["../../../../src/compiler/internal/project/readProjectConfig.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,6CAA4C;AAC5C,0DAA6B;AAK7B,iEAA8D;AAE9D,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"readProjectConfig.js","sourceRoot":"","sources":["../../../../src/compiler/internal/project/readProjectConfig.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,6CAA4C;AAC5C,0DAA6B;AAK7B,iEAA8D;AAE9D;;;GAGG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC;AAiBvE;;;;;;;;GAQG;AACH,2BACE,IAAI,GAA+B,EAAE;IAErC,MAAM,QAAQ,GAAG,IAAA,2CAAoB,E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ocatorOptions";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the tsconfig/jsconfig that owns a ttsc invocation.
|
|
4
|
+
*
|
|
5
|
+
* Resolution order:
|
|
6
|
+
*
|
|
7
|
+
* 1. `opts.tsconfig` — resolved absolute and checked for existence.
|
|
8
|
+
* 2. `opts.file` — the nearest ancestor config that contains the file is found by
|
|
9
|
+
* walking up from the file's directory.
|
|
10
|
+
* 3. `opts.cwd` — the nearest ancestor config walking up from cwd.
|
|
11
|
+
*
|
|
12
|
+
* Always returns a real (symlink-resolved) absolute path. Throws when no config
|
|
13
|
+
* is found or the explicitly supplied path does not exist.
|
|
14
|
+
*/
|
|
3
15
|
export declare function resolveProjectConfig(opts?: ITtscProjectLocatorOptions): string;
|
|
@@ -6,7 +6,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.resolveProjectConfig = resolveProjectConfig;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the tsconfig/jsconfig that owns a ttsc invocation.
|
|
11
|
+
*
|
|
12
|
+
* Resolution order:
|
|
13
|
+
*
|
|
14
|
+
* 1. `opts.tsconfig` — resolved absolute and checked for existence.
|
|
15
|
+
* 2. `opts.file` — the nearest ancestor config that contains the file is found by
|
|
16
|
+
* walking up from the file's directory.
|
|
17
|
+
* 3. `opts.cwd` — the nearest ancestor config walking up from cwd.
|
|
18
|
+
*
|
|
19
|
+
* Always returns a real (symlink-resolved) absolute path. Throws when no config
|
|
20
|
+
* is found or the explicitly supplied path does not exist.
|
|
21
|
+
*/
|
|
10
22
|
function resolveProjectConfig(opts = {}) {
|
|
11
23
|
const cwd = node_path_1.default.resolve(opts.cwd ?? process.cwd());
|
|
12
24
|
if (opts.tsconfig) {
|
|
@@ -14,6 +26,24 @@ function resolveProjectConfig(opts = {}) {
|
|
|
14
26
|
if (!node_fs_1.default.existsSync(resolved)) {
|
|
15
27
|
throw new Error(`ttsc: tsconfig not found: ${resolved}`);
|
|
16
28
|
}
|
|
29
|
+
// `-p <directory>` is the documented tsgo shorthand for the
|
|
30
|
+
// directory that contains a `tsconfig.json`. Mirror that — without
|
|
31
|
+
// this branch a forwarded `--tsconfig=sub` would feed the directory
|
|
32
|
+
// path into `readResolvedCompilerOptions`, which calls
|
|
33
|
+
// `fs.readFileSync` and throws `EISDIR` (the RCA's predicted
|
|
34
|
+
// RC-3 §5 #2 bug, pinned by
|
|
35
|
+
// `test_ttsc_dash_p_directory_path_is_accepted`).
|
|
36
|
+
if (isDirectory(resolved)) {
|
|
37
|
+
const tsconfigInDir = node_path_1.default.join(resolved, "tsconfig.json");
|
|
38
|
+
if (node_fs_1.default.existsSync(tsconfigInDir)) {
|
|
39
|
+
return resolveRealPath(tsconfigInDir);
|
|
40
|
+
}
|
|
41
|
+
const jsconfigInDir = node_path_1.default.join(resolved, "jsconfig.json");
|
|
42
|
+
if (node_fs_1.default.existsSync(jsconfigInDir)) {
|
|
43
|
+
return resolveRealPath(jsconfigInDir);
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`ttsc: directory has no tsconfig.json / jsconfig.json: ${resolved}`);
|
|
46
|
+
}
|
|
17
47
|
return resolveRealPath(resolved);
|
|
18
48
|
}
|
|
19
49
|
const start = opts.file
|
|
@@ -26,9 +56,14 @@ function resolveProjectConfig(opts = {}) {
|
|
|
26
56
|
}
|
|
27
57
|
return resolveRealPath(found);
|
|
28
58
|
}
|
|
59
|
+
/** Resolve `target` against `cwd` when it is not already absolute. */
|
|
29
60
|
function resolveAbsolutePath(cwd, target) {
|
|
30
61
|
return node_path_1.default.isAbsolute(target) ? target : node_path_1.default.resolve(cwd, target);
|
|
31
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve symlinks on `location`, returning the original path when
|
|
65
|
+
* `realpathSync` fails (e.g. when the file does not yet exist).
|
|
66
|
+
*/
|
|
32
67
|
function resolveRealPath(location) {
|
|
33
68
|
try {
|
|
34
69
|
return node_fs_1.default.realpathSync(location);
|
|
@@ -37,6 +72,11 @@ function resolveRealPath(location) {
|
|
|
37
72
|
return location;
|
|
38
73
|
}
|
|
39
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Walk up the directory tree from `from`, returning the first directory that
|
|
77
|
+
* contains a file whose name is in `names`. Returns `null` when the filesystem
|
|
78
|
+
* root is reached without finding a match.
|
|
79
|
+
*/
|
|
40
80
|
function findUp(from, names) {
|
|
41
81
|
let current = node_path_1.default.resolve(from);
|
|
42
82
|
while (true) {
|
|
@@ -53,6 +93,7 @@ function findUp(from, names) {
|
|
|
53
93
|
current = parent;
|
|
54
94
|
}
|
|
55
95
|
}
|
|
96
|
+
/** Return true when `location` exists and is a directory. */
|
|
56
97
|
function isDirectory(location) {
|
|
57
98
|
try {
|
|
58
99
|
return node_fs_1.default.statSync(location).isDirectory();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveProjectConfig.js","sourceRoot":"","sources":["../../../../src/compiler/internal/project/resolveProjectConfig.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAI7B
|
|
1
|
+
{"version":3,"file":"resolveProjectConfig.js","sourceRoot":"","sources":["../../../../src/compiler/internal/project/resolveProjectConfig.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAI7B;;;;;;;;;;;;GAYG;AACH,8BACE,IAAI,GAA+B,EAAE;IAErC,MAAM,GAAG,GAAG,mBAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACpD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,CAAC,iBAAE,CAAC,UAAU,CAAC,QAAQ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CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the ttsc helper binary path, or null when unavailable.
|
|
3
|
+
*
|
|
4
|
+
* Resolution order:
|
|
5
|
+
*
|
|
6
|
+
* 1. `TTSC_BINARY` env var — must be an absolute path when set.
|
|
7
|
+
* 2. The per-platform npm package `@ttsc/<platform>-<arch>/bin/ttsc[.exe]`.
|
|
8
|
+
* 3. A `ttsc-native[.exe]` sibling of this package's root (dev/CI layout).
|
|
9
|
+
*/
|
|
2
10
|
export declare function resolveBinary(opts?: {
|
|
3
11
|
env?: NodeJS.ProcessEnv;
|
|
4
12
|
}): string | null;
|
|
@@ -6,7 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.resolveBinary = resolveBinary;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the ttsc helper binary path, or null when unavailable.
|
|
11
|
+
*
|
|
12
|
+
* Resolution order:
|
|
13
|
+
*
|
|
14
|
+
* 1. `TTSC_BINARY` env var — must be an absolute path when set.
|
|
15
|
+
* 2. The per-platform npm package `@ttsc/<platform>-<arch>/bin/ttsc[.exe]`.
|
|
16
|
+
* 3. A `ttsc-native[.exe]` sibling of this package's root (dev/CI layout).
|
|
17
|
+
*/
|
|
10
18
|
function resolveBinary(opts = {}) {
|
|
11
19
|
const env = opts.env ?? process.env;
|
|
12
20
|
if (env.TTSC_BINARY && node_path_1.default.isAbsolute(env.TTSC_BINARY)) {
|
|
@@ -23,11 +31,19 @@ function resolveBinary(opts = {}) {
|
|
|
23
31
|
return local;
|
|
24
32
|
return null;
|
|
25
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Return the path to the dev-layout `ttsc-native[.exe]` binary adjacent to the
|
|
36
|
+
* package root, or null when the file does not exist.
|
|
37
|
+
*/
|
|
26
38
|
function defaultLocalBinaryPath() {
|
|
27
39
|
const root = packageRootDir();
|
|
28
40
|
const candidate = node_path_1.default.resolve(root, "..", "native", process.platform === "win32" ? "ttsc-native.exe" : "ttsc-native");
|
|
29
41
|
return node_fs_1.default.existsSync(candidate) ? candidate : null;
|
|
30
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Return the real, absolute path of the `packages/ttsc` package root by walking
|
|
45
|
+
* two levels up from `__dirname` (which lives in `src/compiler/internal`).
|
|
46
|
+
*/
|
|
31
47
|
function packageRootDir() {
|
|
32
48
|
const moduleDir = node_path_1.default.resolve(__dirname, "..", "..");
|
|
33
49
|
return node_fs_1.default.realpathSync.native?.(moduleDir) ?? node_fs_1.default.realpathSync(moduleDir);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBinary.js","sourceRoot":"","sources":["../../../src/compiler/internal/resolveBinary.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B
|
|
1
|
+
{"version":3,"file":"resolveBinary.js","sourceRoot":"","sources":["../../../src/compiler/internal/resolveBinary.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B;;;;;;;;GAQG;AACH,uBACE,IAAI,GAAgC,EAAE;IAEtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACpC,IAAI,GAAG,CAAC,WAAW,IAAI,mBAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QACxD,OAAO,GAAG,CAAC,WAAW,CAAC;IACzB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,OAAO,CACpB,SAAS,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,QAAQ,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CACtG,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,kBAAkB;IACpB,CAAC;IAED,MAAM,KAAK,GAAG,sBAAsB,EAAE,CAAC;IACvC,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IAExB,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAS,sBAAsB;IAC7B,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,mBAAI,CAAC,OAAO,CAC5B,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,aAAa,CACjE,CAAC;IACF,OAAO,iBAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc;IACrB,MAAM,SAAS,GAAG,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACtD,OAAO,iBAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,iBAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Locate the JavaScript file emitted for a TypeScript source file.
|
|
3
|
+
*
|
|
4
|
+
* Resolution strategy:
|
|
5
|
+
*
|
|
6
|
+
* 1. Try to derive the exact output path by mirroring the source's relative
|
|
7
|
+
* position inside `projectRoot` into `outDir`, applying the correct JS
|
|
8
|
+
* extension (`.js` / `.mjs` / `.cjs`). Use this path if it exists on disk.
|
|
9
|
+
* 2. Fall back to scoring each candidate in `emittedFiles` (or a recursive
|
|
10
|
+
* directory scan of `outDir`) by the number of trailing path-stem segments
|
|
11
|
+
* shared with the source file name, and pick the highest-scoring existing
|
|
12
|
+
* file.
|
|
13
|
+
*
|
|
14
|
+
* Returns `null` when no matching output file is found on disk.
|
|
15
|
+
*/
|
|
2
16
|
export declare function resolveEmittedJavaScript(options: {
|
|
17
|
+
/** Pre-computed list of emitted paths; when absent `outDir` is scanned. */
|
|
3
18
|
emittedFiles?: readonly string[];
|
|
4
19
|
outDir: string;
|
|
5
20
|
projectRoot: string;
|
|
@@ -6,7 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.resolveEmittedJavaScript = resolveEmittedJavaScript;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
|
|
9
|
+
const paths_1 = require("./paths");
|
|
10
|
+
/**
|
|
11
|
+
* Locate the JavaScript file emitted for a TypeScript source file.
|
|
12
|
+
*
|
|
13
|
+
* Resolution strategy:
|
|
14
|
+
*
|
|
15
|
+
* 1. Try to derive the exact output path by mirroring the source's relative
|
|
16
|
+
* position inside `projectRoot` into `outDir`, applying the correct JS
|
|
17
|
+
* extension (`.js` / `.mjs` / `.cjs`). Use this path if it exists on disk.
|
|
18
|
+
* 2. Fall back to scoring each candidate in `emittedFiles` (or a recursive
|
|
19
|
+
* directory scan of `outDir`) by the number of trailing path-stem segments
|
|
20
|
+
* shared with the source file name, and pick the highest-scoring existing
|
|
21
|
+
* file.
|
|
22
|
+
*
|
|
23
|
+
* Returns `null` when no matching output file is found on disk.
|
|
24
|
+
*/
|
|
10
25
|
function resolveEmittedJavaScript(options) {
|
|
11
26
|
const exact = resolveExactEmittedFile(options.outDir, options.projectRoot, options.sourceFile);
|
|
12
27
|
if (exact && node_fs_1.default.existsSync(exact)) {
|
|
@@ -26,14 +41,24 @@ function resolveEmittedJavaScript(options) {
|
|
|
26
41
|
}
|
|
27
42
|
return best && node_fs_1.default.existsSync(best) ? best : null;
|
|
28
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Derive the exact output path for `sourceFile` by mirroring its position
|
|
46
|
+
* relative to `projectRoot` into `outDir`. Returns `null` when the source is
|
|
47
|
+
* not inside the project root or when the path cannot be determined.
|
|
48
|
+
*/
|
|
29
49
|
function resolveExactEmittedFile(outDir, projectRoot, sourceFile) {
|
|
30
50
|
const relative = node_path_1.default.relative(projectRoot, sourceFile);
|
|
31
|
-
if (relative === "" || isOutsideRelativePath(relative)) {
|
|
51
|
+
if (relative === "" || (0, paths_1.isOutsideRelativePath)(relative)) {
|
|
32
52
|
return null;
|
|
33
53
|
}
|
|
34
54
|
return node_path_1.default.resolve(outDir, relative.slice(0, relative.length - node_path_1.default.extname(relative).length) +
|
|
35
55
|
emittedJavaScriptExtension(sourceFile));
|
|
36
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Recursively enumerate every JavaScript output file under `root`. Uses an
|
|
59
|
+
* explicit stack instead of recursion to avoid call-stack overflow on deep
|
|
60
|
+
* directory trees. Non-existent roots are silently skipped.
|
|
61
|
+
*/
|
|
37
62
|
function listJavaScriptFiles(root) {
|
|
38
63
|
const out = [];
|
|
39
64
|
const stack = [root];
|
|
@@ -53,15 +78,22 @@ function listJavaScriptFiles(root) {
|
|
|
53
78
|
}
|
|
54
79
|
return out;
|
|
55
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Count the number of consecutive trailing path-stem segments that `outPath`
|
|
83
|
+
* and `srcPath` share when both are stripped of their extensions and normalised
|
|
84
|
+
* to forward slashes.
|
|
85
|
+
*
|
|
86
|
+
* Example: `dist/lib/foo.js` vs `src/lib/foo.ts` → 2 (`lib`, `foo`).
|
|
87
|
+
*/
|
|
56
88
|
function sharedSourceStemSegments(outPath, srcPath) {
|
|
57
|
-
const
|
|
89
|
+
const stripExtAndSplit = (location) => {
|
|
58
90
|
const normalized = location.replace(/\\/g, "/");
|
|
59
91
|
return normalized
|
|
60
92
|
.slice(0, normalized.length - node_path_1.default.extname(normalized).length)
|
|
61
93
|
.split("/");
|
|
62
94
|
};
|
|
63
|
-
const a =
|
|
64
|
-
const b =
|
|
95
|
+
const a = stripExtAndSplit(outPath);
|
|
96
|
+
const b = stripExtAndSplit(srcPath);
|
|
65
97
|
const count = Math.min(a.length, b.length);
|
|
66
98
|
let shared = 0;
|
|
67
99
|
for (let i = 1; i <= count; i += 1) {
|
|
@@ -71,11 +103,10 @@ function sharedSourceStemSegments(outPath, srcPath) {
|
|
|
71
103
|
}
|
|
72
104
|
return shared;
|
|
73
105
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
106
|
+
/**
|
|
107
|
+
* Map a TypeScript source extension to its JavaScript output counterpart.
|
|
108
|
+
* `.mts` → `.mjs`, `.cts` → `.cjs`, everything else → `.js`.
|
|
109
|
+
*/
|
|
79
110
|
function emittedJavaScriptExtension(filename) {
|
|
80
111
|
switch (node_path_1.default.extname(filename).toLowerCase()) {
|
|
81
112
|
case ".mts":
|
|
@@ -86,6 +117,7 @@ function emittedJavaScriptExtension(filename) {
|
|
|
86
117
|
return ".js";
|
|
87
118
|
}
|
|
88
119
|
}
|
|
120
|
+
/** Return true when `filename` has a `.js`, `.mjs`, or `.cjs` extension. */
|
|
89
121
|
function isJavaScriptOutput(filename) {
|
|
90
122
|
return /\.(?:[cm]?js)$/i.test(filename);
|
|
91
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveEmittedJavaScript.js","sourceRoot":"","sources":["../../../src/compiler/internal/resolveEmittedJavaScript.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B,
|
|
1
|
+
{"version":3,"file":"resolveEmittedJavaScript.js","sourceRoot":"","sources":["../../../src/compiler/internal/resolveEmittedJavaScript.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B,mCAAgD;AAEhD;;;;;;;;;;;;;;GAcG;AAC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