ttsc 0.5.0 → 0.6.0-dev.20250430
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 +1 -1
- package/go.mod +1 -1
- package/go.sum +2 -2
- package/lib/api.d.ts +15 -67
- package/lib/api.js +14 -3
- package/lib/api.js.map +1 -1
- package/lib/cli.js.map +1 -1
- package/lib/native.d.ts +8 -20
- package/lib/native.js.map +1 -1
- package/lib/platform.d.ts +7 -25
- package/lib/platform.js.map +1 -1
- package/lib/plugin.d.ts +13 -41
- package/lib/plugin.js +2 -2
- package/lib/plugin.js.map +1 -1
- package/lib/project.d.ts +11 -29
- package/lib/project.js.map +1 -1
- package/lib/runner/cli.js.map +1 -1
- package/lib/runner/register.d.ts +6 -13
- package/lib/runner/register.js.map +1 -1
- package/lib/source-build.d.ts +11 -22
- package/lib/source-build.js +25 -1
- package/lib/source-build.js.map +1 -1
- package/lib/structures/ITtscBuildOptions.d.ts +14 -0
- package/lib/structures/ITtscBuildOptions.js +3 -0
- package/lib/structures/ITtscBuildOptions.js.map +1 -0
- package/lib/structures/ITtscBuildResult.d.ts +6 -0
- package/lib/structures/ITtscBuildResult.js +3 -0
- package/lib/structures/ITtscBuildResult.js.map +1 -0
- package/lib/structures/ITtscBuildSourcePluginOptions.d.ts +8 -0
- package/lib/structures/ITtscBuildSourcePluginOptions.js +3 -0
- package/lib/structures/ITtscBuildSourcePluginOptions.js.map +1 -0
- package/lib/structures/ITtscCacheKeyInput.d.ts +7 -0
- package/lib/structures/ITtscCacheKeyInput.js +3 -0
- package/lib/structures/ITtscCacheKeyInput.js.map +1 -0
- package/lib/structures/ITtscCheckOptions.d.ts +2 -0
- package/lib/structures/ITtscCheckOptions.js +3 -0
- package/lib/structures/ITtscCheckOptions.js.map +1 -0
- package/lib/structures/ITtscCommonOptions.d.ts +22 -0
- package/lib/structures/ITtscCommonOptions.js +3 -0
- package/lib/structures/ITtscCommonOptions.js.map +1 -0
- package/lib/structures/ITtscLoadPluginsOptions.d.ts +8 -0
- package/lib/structures/ITtscLoadPluginsOptions.js +3 -0
- package/lib/structures/ITtscLoadPluginsOptions.js.map +1 -0
- package/lib/structures/ITtscLoadedNativePlugin.d.ts +7 -0
- package/lib/structures/ITtscLoadedNativePlugin.js +3 -0
- package/lib/structures/ITtscLoadedNativePlugin.js.map +1 -0
- package/lib/structures/ITtscLoadedPlugins.d.ts +11 -0
- package/lib/structures/ITtscLoadedPlugins.js +3 -0
- package/lib/structures/ITtscLoadedPlugins.js.map +1 -0
- package/lib/structures/ITtscNativeBackend.d.ts +10 -0
- package/lib/structures/ITtscNativeBackend.js +3 -0
- package/lib/structures/ITtscNativeBackend.js.map +1 -0
- package/lib/structures/ITtscNativePluginContractVersion.d.ts +1 -0
- package/lib/structures/ITtscNativePluginContractVersion.js +3 -0
- package/lib/structures/ITtscNativePluginContractVersion.js.map +1 -0
- package/lib/structures/ITtscNativePluginShape.d.ts +8 -0
- package/lib/structures/ITtscNativePluginShape.js +3 -0
- package/lib/structures/ITtscNativePluginShape.js.map +1 -0
- package/lib/structures/ITtscNativeRewriteMode.d.ts +1 -0
- package/lib/structures/ITtscNativeRewriteMode.js +3 -0
- package/lib/structures/ITtscNativeRewriteMode.js.map +1 -0
- package/lib/structures/ITtscNativeSource.d.ts +4 -0
- package/lib/structures/ITtscNativeSource.js +3 -0
- package/lib/structures/ITtscNativeSource.js.map +1 -0
- package/lib/structures/ITtscParsedProjectConfig.d.ts +9 -0
- package/lib/structures/ITtscParsedProjectConfig.js +3 -0
- package/lib/structures/ITtscParsedProjectConfig.js.map +1 -0
- package/lib/structures/ITtscPlugin.d.ts +10 -0
- package/lib/structures/ITtscPlugin.js +3 -0
- package/lib/structures/ITtscPlugin.js.map +1 -0
- package/lib/structures/ITtscPluginFactory.d.ts +4 -0
- package/lib/structures/ITtscPluginFactory.js +3 -0
- package/lib/structures/ITtscPluginFactory.js.map +1 -0
- package/lib/structures/ITtscPluginFactoryContext.d.ts +8 -0
- package/lib/structures/ITtscPluginFactoryContext.js +3 -0
- package/lib/structures/ITtscPluginFactoryContext.js.map +1 -0
- package/lib/structures/ITtscPluginModule.d.ts +3 -0
- package/lib/structures/ITtscPluginModule.js +3 -0
- package/lib/structures/ITtscPluginModule.js.map +1 -0
- package/lib/structures/ITtscPreparedExecution.d.ts +5 -0
- package/lib/structures/ITtscPreparedExecution.js +3 -0
- package/lib/structures/ITtscPreparedExecution.js.map +1 -0
- package/lib/structures/ITtscProjectLocatorOptions.d.ts +5 -0
- package/lib/structures/ITtscProjectLocatorOptions.js +3 -0
- package/lib/structures/ITtscProjectLocatorOptions.js.map +1 -0
- package/lib/structures/ITtscProjectPluginConfig.d.ts +5 -0
- package/lib/structures/ITtscProjectPluginConfig.js +3 -0
- package/lib/structures/ITtscProjectPluginConfig.js.map +1 -0
- package/lib/structures/ITtscRegisterOptions.d.ts +6 -0
- package/lib/structures/ITtscRegisterOptions.js +3 -0
- package/lib/structures/ITtscRegisterOptions.js.map +1 -0
- package/lib/structures/ITtscResolveGoBinaryOptions.d.ts +7 -0
- package/lib/structures/ITtscResolveGoBinaryOptions.js +3 -0
- package/lib/structures/ITtscResolveGoBinaryOptions.js.map +1 -0
- package/lib/structures/ITtscResolveOptions.d.ts +20 -0
- package/lib/structures/ITtscResolveOptions.js +3 -0
- package/lib/structures/ITtscResolveOptions.js.map +1 -0
- package/lib/structures/ITtscResolvedTsgo.d.ts +8 -0
- package/lib/structures/ITtscResolvedTsgo.js +3 -0
- package/lib/structures/ITtscResolvedTsgo.js.map +1 -0
- package/lib/structures/ITtscTransformOptions.d.ts +12 -0
- package/lib/structures/ITtscTransformOptions.js +3 -0
- package/lib/structures/ITtscTransformOptions.js.map +1 -0
- package/lib/structures/ITtscTsgoResolveOptions.d.ts +14 -0
- package/lib/structures/ITtscTsgoResolveOptions.js +3 -0
- package/lib/structures/ITtscTsgoResolveOptions.js.map +1 -0
- package/lib/tsgo.d.ts +6 -24
- package/lib/tsgo.js.map +1 -1
- package/package.json +10 -10
- package/shim/ast/go.mod +1 -1
- package/shim/ast/lint.go +2 -0
- package/shim/bundled/go.mod +1 -1
- package/shim/checker/go.mod +1 -1
- package/shim/compiler/go.mod +1 -1
- package/shim/core/go.mod +1 -1
- package/shim/diagnosticwriter/go.mod +1 -1
- package/shim/parser/go.mod +1 -1
- package/shim/scanner/go.mod +1 -1
- package/shim/tsoptions/go.mod +1 -1
- package/shim/tspath/go.mod +1 -1
- package/shim/vfs/cachedvfs/go.mod +1 -1
- package/shim/vfs/go.mod +1 -1
- package/shim/vfs/osvfs/go.mod +1 -1
- package/src/api.ts +108 -155
- package/src/cli.ts +10 -10
- package/src/native.ts +9 -23
- package/src/platform.ts +10 -27
- package/src/plugin.ts +37 -74
- package/src/project.ts +18 -37
- package/src/runner/cli.ts +5 -5
- package/src/runner/register.ts +32 -43
- package/src/source-build.ts +45 -25
- package/src/structures/ITtscBuildOptions.ts +19 -0
- package/src/structures/ITtscBuildResult.ts +6 -0
- package/src/structures/ITtscBuildSourcePluginOptions.ts +9 -0
- package/src/structures/ITtscCacheKeyInput.ts +7 -0
- package/src/structures/ITtscCheckOptions.ts +3 -0
- package/src/structures/ITtscCommonOptions.ts +23 -0
- package/src/structures/ITtscLoadPluginsOptions.ts +9 -0
- package/src/structures/ITtscLoadedNativePlugin.ts +8 -0
- package/src/structures/ITtscLoadedPlugins.ts +12 -0
- package/src/structures/ITtscNativeBackend.ts +11 -0
- package/src/structures/ITtscNativePluginContractVersion.ts +1 -0
- package/src/structures/ITtscNativePluginShape.ts +9 -0
- package/src/structures/ITtscNativeRewriteMode.ts +1 -0
- package/src/structures/ITtscNativeSource.ts +4 -0
- package/src/structures/ITtscParsedProjectConfig.ts +10 -0
- package/src/structures/ITtscPlugin.ts +11 -0
- package/src/structures/ITtscPluginFactory.ts +7 -0
- package/src/structures/ITtscPluginFactoryContext.ts +9 -0
- package/src/structures/ITtscPluginModule.ts +4 -0
- package/src/structures/ITtscPreparedExecution.ts +5 -0
- package/src/structures/ITtscProjectLocatorOptions.ts +5 -0
- package/src/structures/ITtscProjectPluginConfig.ts +5 -0
- package/src/structures/ITtscRegisterOptions.ts +7 -0
- package/src/structures/ITtscResolveGoBinaryOptions.ts +7 -0
- package/src/structures/ITtscResolveOptions.ts +20 -0
- package/src/structures/ITtscResolvedTsgo.ts +8 -0
- package/src/structures/ITtscTransformOptions.ts +13 -0
- package/src/structures/ITtscTsgoResolveOptions.ts +14 -0
- package/src/tsgo.ts +6 -24
- package/test/source-build.test.ts +13 -0
package/src/source-build.ts
CHANGED
|
@@ -4,17 +4,13 @@ import * as fs from "node:fs";
|
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type { ITtscBuildSourcePluginOptions } from "./structures/ITtscBuildSourcePluginOptions";
|
|
8
|
+
import type { ITtscResolveGoBinaryOptions } from "./structures/ITtscResolveGoBinaryOptions";
|
|
8
9
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
pluginName: string;
|
|
12
|
-
baseDir: string;
|
|
13
|
-
ttscVersion: string;
|
|
14
|
-
tsgoVersion: string;
|
|
15
|
-
}
|
|
10
|
+
export type { ITtscBuildSourcePluginOptions } from "./structures/ITtscBuildSourcePluginOptions";
|
|
11
|
+
export type { ITtscResolveGoBinaryOptions } from "./structures/ITtscResolveGoBinaryOptions";
|
|
16
12
|
|
|
17
|
-
export function buildSourcePlugin(opts:
|
|
13
|
+
export function buildSourcePlugin(opts: ITtscBuildSourcePluginOptions): string {
|
|
18
14
|
const dir = path.isAbsolute(opts.source.dir)
|
|
19
15
|
? opts.source.dir
|
|
20
16
|
: path.resolve(opts.baseDir, opts.source.dir);
|
|
@@ -81,10 +77,42 @@ function writeGoWork(scratchDir: string, useDirs: readonly string[]): void {
|
|
|
81
77
|
for (const dir of useDirs) {
|
|
82
78
|
useLines.push(`\t${dir.replace(/\\/g, "/")}`);
|
|
83
79
|
}
|
|
84
|
-
const
|
|
80
|
+
const replaceLines = sourceBuildWorkspaceReplacements(useDirs);
|
|
81
|
+
const replaceBlock =
|
|
82
|
+
replaceLines.length === 0 ? "" : `\n\n${replaceLines.join("\n")}\n`;
|
|
83
|
+
const goWork = `go 1.26\n\nuse (\n${useLines.join("\n")}\n)${replaceBlock}`;
|
|
85
84
|
fs.writeFileSync(path.join(scratchDir, "go.work"), goWork, "utf8");
|
|
86
85
|
}
|
|
87
86
|
|
|
87
|
+
export function sourceBuildWorkspaceReplacements(
|
|
88
|
+
useDirs: readonly string[],
|
|
89
|
+
): string[] {
|
|
90
|
+
const ttscRoot = useDirs.find((dir) =>
|
|
91
|
+
hasModulePath(dir, "github.com/samchon/ttsc/packages/ttsc"),
|
|
92
|
+
);
|
|
93
|
+
if (!ttscRoot) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
return [
|
|
97
|
+
`replace github.com/samchon/ttsc/packages/ttsc v0.0.0 => ${ttscRoot.replace(/\\/g, "/")}`,
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function hasModulePath(dir: string, modulePath: string): boolean {
|
|
102
|
+
try {
|
|
103
|
+
const goMod = fs.readFileSync(path.join(dir, "go.mod"), "utf8");
|
|
104
|
+
return new RegExp(`^module\\s+${escapeRegExp(modulePath)}\\s*$`, "m").test(
|
|
105
|
+
goMod,
|
|
106
|
+
);
|
|
107
|
+
} catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function escapeRegExp(value: string): string {
|
|
113
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
114
|
+
}
|
|
115
|
+
|
|
88
116
|
function runGoBuild(
|
|
89
117
|
cwd: string,
|
|
90
118
|
entry: string,
|
|
@@ -178,20 +206,12 @@ function walkToolFiles(dir: string): string[] {
|
|
|
178
206
|
return out;
|
|
179
207
|
}
|
|
180
208
|
|
|
181
|
-
export
|
|
182
|
-
arch?: string;
|
|
183
|
-
env?: NodeJS.ProcessEnv;
|
|
184
|
-
localGoLookup?: () => string | null;
|
|
185
|
-
platform?: NodeJS.Platform;
|
|
186
|
-
resolver?: (request: string) => string;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function goBinaryName(opts: ResolveGoBinaryOptions = {}): string {
|
|
209
|
+
export function goBinaryName(opts: ITtscResolveGoBinaryOptions = {}): string {
|
|
190
210
|
return (opts.platform ?? process.platform) === "win32" ? "go.exe" : "go";
|
|
191
211
|
}
|
|
192
212
|
|
|
193
213
|
export function bundledGoPackageRequest(
|
|
194
|
-
opts:
|
|
214
|
+
opts: ITtscResolveGoBinaryOptions = {},
|
|
195
215
|
): string {
|
|
196
216
|
return `@ttsc/${goPlatformKey(opts)}/bin/go/bin/${goBinaryName(opts)}`;
|
|
197
217
|
}
|
|
@@ -280,7 +300,7 @@ function resolveGoBinary(): string {
|
|
|
280
300
|
}
|
|
281
301
|
|
|
282
302
|
export function resolveGoCompiler(
|
|
283
|
-
opts:
|
|
303
|
+
opts: ITtscResolveGoBinaryOptions = {},
|
|
284
304
|
): string {
|
|
285
305
|
const env = opts.env ?? process.env;
|
|
286
306
|
const explicit = env.TTSC_GO_BINARY;
|
|
@@ -306,7 +326,7 @@ export function resolveGoCompiler(
|
|
|
306
326
|
return "go";
|
|
307
327
|
}
|
|
308
328
|
|
|
309
|
-
function defaultLocalGoBinaryPath(opts:
|
|
329
|
+
function defaultLocalGoBinaryPath(opts: ITtscResolveGoBinaryOptions): string | null {
|
|
310
330
|
const candidate = path.resolve(
|
|
311
331
|
__dirname,
|
|
312
332
|
"..",
|
|
@@ -318,18 +338,18 @@ function defaultLocalGoBinaryPath(opts: ResolveGoBinaryOptions): string | null {
|
|
|
318
338
|
return fs.existsSync(candidate) ? candidate : null;
|
|
319
339
|
}
|
|
320
340
|
|
|
321
|
-
function goPlatformKey(opts:
|
|
341
|
+
function goPlatformKey(opts: ITtscResolveGoBinaryOptions = {}): string {
|
|
322
342
|
return `${opts.platform ?? process.platform}-${opts.arch ?? process.arch}`;
|
|
323
343
|
}
|
|
324
344
|
|
|
325
|
-
interface
|
|
345
|
+
interface ITtscSourceBuildCacheKeyInput {
|
|
326
346
|
dir: string;
|
|
327
347
|
entry: string;
|
|
328
348
|
ttscVersion: string;
|
|
329
349
|
tsgoVersion: string;
|
|
330
350
|
}
|
|
331
351
|
|
|
332
|
-
export function computeCacheKey(inputs:
|
|
352
|
+
export function computeCacheKey(inputs: ITtscSourceBuildCacheKeyInput): string {
|
|
333
353
|
const hash = crypto.createHash("sha256");
|
|
334
354
|
hash.update(`ttsc=${inputs.ttscVersion}\n`);
|
|
335
355
|
hash.update(`tsgo=${inputs.tsgoVersion}\n`);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ITtscCommonOptions } from "./ITtscCommonOptions";
|
|
2
|
+
|
|
3
|
+
export interface ITtscBuildOptions extends ITtscCommonOptions {
|
|
4
|
+
/** Path to tsconfig.json. Default: `tsconfig.json`. */
|
|
5
|
+
tsconfig?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Emit override. `true` forces emit, `false` forces noEmit, `undefined`
|
|
8
|
+
* follows tsconfig.
|
|
9
|
+
*/
|
|
10
|
+
emit?: boolean;
|
|
11
|
+
/** Override compilerOptions.outDir for this invocation. */
|
|
12
|
+
outDir?: string;
|
|
13
|
+
/** Suppress the per-call summary banner. Default: `true`. */
|
|
14
|
+
quiet?: boolean;
|
|
15
|
+
/** @internal Caller already ran diagnostics and accepts responsibility. */
|
|
16
|
+
skipDiagnosticsCheck?: boolean;
|
|
17
|
+
/** @internal Force `tsgo --listEmittedFiles` for caller-side output discovery. */
|
|
18
|
+
forceListEmittedFiles?: boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
|
|
2
|
+
import type { ITtscResolveOptions } from "./ITtscResolveOptions";
|
|
3
|
+
|
|
4
|
+
export interface ITtscCommonOptions extends ITtscResolveOptions {
|
|
5
|
+
/** Absolute path to an already-resolved tsgo binary. Skips package resolution. */
|
|
6
|
+
binary?: string;
|
|
7
|
+
/** Working directory passed to the child process. */
|
|
8
|
+
cwd?: string;
|
|
9
|
+
/** Extra environment variables; merged onto `process.env`. */
|
|
10
|
+
env?: NodeJS.ProcessEnv;
|
|
11
|
+
/**
|
|
12
|
+
* Override project plugin loading. `false` disables tsconfig plugins; an
|
|
13
|
+
* array replaces the tsconfig `compilerOptions.plugins` list.
|
|
14
|
+
*/
|
|
15
|
+
plugins?: readonly ITtscProjectPluginConfig[] | false;
|
|
16
|
+
/**
|
|
17
|
+
* Override the native rewrite backend. Defaults to the loaded plugin mode.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Prefer plugin-declared `native.mode`; this override is for
|
|
20
|
+
* low-level tests and migration probes.
|
|
21
|
+
*/
|
|
22
|
+
rewriteMode?: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ITtscNativeBackend } from "./ITtscNativeBackend";
|
|
2
|
+
import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
|
|
3
|
+
|
|
4
|
+
export interface ITtscLoadedNativePlugin {
|
|
5
|
+
backend: ITtscNativeBackend;
|
|
6
|
+
config: ITtscProjectPluginConfig;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ITtscLoadedNativePlugin } from "./ITtscLoadedNativePlugin";
|
|
2
|
+
import type { ITtscParsedProjectConfig } from "./ITtscParsedProjectConfig";
|
|
3
|
+
import type { ITtscPlugin } from "./ITtscPlugin";
|
|
4
|
+
|
|
5
|
+
export interface ITtscLoadedPlugins {
|
|
6
|
+
compatibilityFallback: boolean;
|
|
7
|
+
nativeBinary: string | null;
|
|
8
|
+
nativeBinaries: string[];
|
|
9
|
+
nativePlugins: ITtscLoadedNativePlugin[];
|
|
10
|
+
plugins: ITtscPlugin[];
|
|
11
|
+
project: ITtscParsedProjectConfig;
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ITtscNativePluginContractVersion } from "./ITtscNativePluginContractVersion";
|
|
2
|
+
import type { ITtscNativeRewriteMode } from "./ITtscNativeRewriteMode";
|
|
3
|
+
import type { ITtscNativeSource } from "./ITtscNativeSource";
|
|
4
|
+
|
|
5
|
+
export interface ITtscNativeBackend {
|
|
6
|
+
mode: ITtscNativeRewriteMode;
|
|
7
|
+
binary?: string;
|
|
8
|
+
source?: ITtscNativeSource;
|
|
9
|
+
contractVersion?: ITtscNativePluginContractVersion;
|
|
10
|
+
capabilities?: readonly string[];
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ITtscNativePluginContractVersion = 1;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ITtscNativeBackend } from "./ITtscNativeBackend";
|
|
2
|
+
import type { ITtscNativeRewriteMode } from "./ITtscNativeRewriteMode";
|
|
3
|
+
|
|
4
|
+
export interface ITtscNativePluginShape {
|
|
5
|
+
name: string;
|
|
6
|
+
native?: ITtscNativeBackend;
|
|
7
|
+
nativeMode?: ITtscNativeRewriteMode;
|
|
8
|
+
nativeBinary?: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ITtscNativeRewriteMode = string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
|
|
2
|
+
|
|
3
|
+
export interface ITtscParsedProjectConfig {
|
|
4
|
+
compilerOptions: {
|
|
5
|
+
outDir?: string;
|
|
6
|
+
plugins: ITtscProjectPluginConfig[];
|
|
7
|
+
} & Record<string, unknown>;
|
|
8
|
+
path: string;
|
|
9
|
+
root: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ITtscNativeBackend } from "./ITtscNativeBackend";
|
|
2
|
+
import type { ITtscNativeRewriteMode } from "./ITtscNativeRewriteMode";
|
|
3
|
+
|
|
4
|
+
export interface ITtscPlugin {
|
|
5
|
+
name: string;
|
|
6
|
+
native?: ITtscNativeBackend;
|
|
7
|
+
/** @deprecated Use `native.mode` instead. */
|
|
8
|
+
nativeMode?: ITtscNativeRewriteMode;
|
|
9
|
+
/** @deprecated Use `native.binary` instead. */
|
|
10
|
+
nativeBinary?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ITtscPlugin } from "./ITtscPlugin";
|
|
2
|
+
import type { ITtscPluginFactoryContext } from "./ITtscPluginFactoryContext";
|
|
3
|
+
import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
|
|
4
|
+
|
|
5
|
+
export type ITtscPluginFactory<T = ITtscProjectPluginConfig> = (
|
|
6
|
+
context: ITtscPluginFactoryContext<T>,
|
|
7
|
+
) => ITtscPlugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ITtscResolveOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Override `require.resolve` for testing. Takes a module request string and
|
|
4
|
+
* returns an absolute path (or throws).
|
|
5
|
+
*/
|
|
6
|
+
resolver?: (request: string) => string;
|
|
7
|
+
/** Override `process.platform` for testing. */
|
|
8
|
+
platform?: NodeJS.Platform;
|
|
9
|
+
/** Override `process.arch` for testing. */
|
|
10
|
+
arch?: string;
|
|
11
|
+
/** Override `process.env` for testing. */
|
|
12
|
+
env?: NodeJS.ProcessEnv;
|
|
13
|
+
/**
|
|
14
|
+
* Override the package-local scan used for the local `native/ttsc-native`
|
|
15
|
+
* fallback. Returns an absolute path if present, else null.
|
|
16
|
+
*/
|
|
17
|
+
localBinaryLookup?: () => string | null;
|
|
18
|
+
/** Override the module directory used to resolve the package-local binary. */
|
|
19
|
+
moduleDir?: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ITtscCommonOptions } from "./ITtscCommonOptions";
|
|
2
|
+
|
|
3
|
+
export interface ITtscTransformOptions extends ITtscCommonOptions {
|
|
4
|
+
/** Path to the .ts file to transform. Absolute or `cwd`-relative. */
|
|
5
|
+
file: string;
|
|
6
|
+
/** Path to the tsconfig owning `file`. Default: `tsconfig.json`. */
|
|
7
|
+
tsconfig?: string;
|
|
8
|
+
/**
|
|
9
|
+
* When provided, the binary writes JS directly to this path instead of piping
|
|
10
|
+
* stdout. Useful when the emitted text is large.
|
|
11
|
+
*/
|
|
12
|
+
out?: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ITtscTsgoResolveOptions {
|
|
2
|
+
/** Absolute path to an explicit tsgo-compatible binary. */
|
|
3
|
+
binary?: string;
|
|
4
|
+
/** Project directory used for node_modules resolution. */
|
|
5
|
+
cwd?: string;
|
|
6
|
+
/** Environment variables used for explicit binary overrides. */
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
/** Override process.platform for tests. */
|
|
9
|
+
platform?: NodeJS.Platform;
|
|
10
|
+
/** Override process.arch for tests. */
|
|
11
|
+
arch?: string;
|
|
12
|
+
/** Override package resolution for tests. */
|
|
13
|
+
resolver?: (request: string) => string;
|
|
14
|
+
}
|
package/src/tsgo.ts
CHANGED
|
@@ -2,39 +2,21 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
binary?: string;
|
|
8
|
-
/** Project directory used for node_modules resolution. */
|
|
9
|
-
cwd?: string;
|
|
10
|
-
/** Environment variables used for explicit binary overrides. */
|
|
11
|
-
env?: NodeJS.ProcessEnv;
|
|
12
|
-
/** Override process.platform for tests. */
|
|
13
|
-
platform?: NodeJS.Platform;
|
|
14
|
-
/** Override process.arch for tests. */
|
|
15
|
-
arch?: string;
|
|
16
|
-
/** Override package resolution for tests. */
|
|
17
|
-
resolver?: (request: string) => string;
|
|
18
|
-
}
|
|
5
|
+
import type { ITtscResolvedTsgo } from "./structures/ITtscResolvedTsgo";
|
|
6
|
+
import type { ITtscTsgoResolveOptions } from "./structures/ITtscTsgoResolveOptions";
|
|
19
7
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
gitHead?: string;
|
|
23
|
-
packageJson: string;
|
|
24
|
-
packageRoot: string;
|
|
25
|
-
platformPackageJson?: string;
|
|
26
|
-
version: string;
|
|
27
|
-
}
|
|
8
|
+
export type { ITtscResolvedTsgo } from "./structures/ITtscResolvedTsgo";
|
|
9
|
+
export type { ITtscTsgoResolveOptions } from "./structures/ITtscTsgoResolveOptions";
|
|
28
10
|
|
|
29
11
|
export function nativePreviewPlatformPackage(
|
|
30
|
-
opts:
|
|
12
|
+
opts: ITtscTsgoResolveOptions = {},
|
|
31
13
|
): string {
|
|
32
14
|
return `@typescript/native-preview-${opts.platform ?? process.platform}-${
|
|
33
15
|
opts.arch ?? process.arch
|
|
34
16
|
}`;
|
|
35
17
|
}
|
|
36
18
|
|
|
37
|
-
export function resolveTsgo(opts:
|
|
19
|
+
export function resolveTsgo(opts: ITtscTsgoResolveOptions = {}): ITtscResolvedTsgo {
|
|
38
20
|
const env = opts.env ?? process.env;
|
|
39
21
|
const explicit = opts.binary ?? env.TTSC_TSGO_BINARY;
|
|
40
22
|
if (explicit) {
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
resolveDefaultPluginCacheRoot,
|
|
13
13
|
resolveGoCompiler,
|
|
14
14
|
resolvePluginCacheRoot,
|
|
15
|
+
sourceBuildWorkspaceReplacements,
|
|
15
16
|
} = require("../src/source-build.ts");
|
|
16
17
|
|
|
17
18
|
function withTempSourceDir(files: Record<string, string>): string {
|
|
@@ -149,6 +150,18 @@ test("bundled Go package request follows platform package layout", () => {
|
|
|
149
150
|
);
|
|
150
151
|
});
|
|
151
152
|
|
|
153
|
+
test("sourceBuildWorkspaceReplacements pins the ttsc module for source plugins", () => {
|
|
154
|
+
const ttscRoot = withTempSourceDir({
|
|
155
|
+
"go.mod": "module github.com/samchon/ttsc/packages/ttsc\n\ngo 1.26\n",
|
|
156
|
+
});
|
|
157
|
+
const otherRoot = withTempSourceDir({
|
|
158
|
+
"go.mod": "module example.com/other\n\ngo 1.26\n",
|
|
159
|
+
});
|
|
160
|
+
assert.deepEqual(sourceBuildWorkspaceReplacements([otherRoot, ttscRoot]), [
|
|
161
|
+
`replace github.com/samchon/ttsc/packages/ttsc v0.0.0 => ${ttscRoot.replace(/\\/g, "/")}`,
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
|
|
152
165
|
test("resolvePluginCacheRoot prefers project node_modules cache", () => {
|
|
153
166
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-local-cache-"));
|
|
154
167
|
fs.mkdirSync(path.join(root, "node_modules"));
|