@ttsc/playground 0.14.0-dev.20260529.2 → 0.14.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/lib/src/compiler/DEFAULT_PLAYGROUND_COMPILER_OPTIONS.d.ts +4 -4
- package/lib/src/compiler/DEFAULT_PLAYGROUND_COMPILER_OPTIONS.js +4 -4
- package/lib/src/compiler/DEFAULT_TYPIA_PLUGIN_NAME.d.ts +2 -2
- package/lib/src/compiler/DEFAULT_TYPIA_PLUGIN_NAME.js +2 -2
- package/lib/src/compiler/createWorkerCompiler.js +3 -3
- package/lib/src/compiler/createWorkerCompiler.js.map +1 -1
- package/lib/src/compiler/installDependenciesIntoMemFS.d.ts +4 -4
- package/lib/src/compiler/installDependenciesIntoMemFS.js +4 -4
- package/lib/src/compiler/installTypiaSourcePack.d.ts +2 -2
- package/lib/src/compiler/installTypiaSourcePack.js +2 -2
- package/lib/src/compiler/internal/joinUnder.d.ts +4 -1
- package/lib/src/compiler/internal/joinUnder.js +4 -1
- package/lib/src/compiler/internal/joinUnder.js.map +1 -1
- package/lib/src/compiler/internal/parseLintDiagnostics.js +2 -2
- package/lib/src/compiler/internal/safeParseTypiaTransform.d.ts +3 -3
- package/lib/src/compiler/internal/safeParseTypiaTransform.js +3 -3
- package/lib/src/compiler/loadTypiaSourcePack.d.ts +4 -4
- package/lib/src/compiler/loadTypiaSourcePack.js +4 -4
- package/lib/src/compiler/pickEmittedJS.js +1 -6
- package/lib/src/compiler/pickEmittedJS.js.map +1 -1
- package/lib/src/index.d.ts +2 -2
- package/lib/src/index.js +2 -2
- package/lib/src/npm/BUILT_IN_PLAYGROUND_PACKAGES.d.ts +2 -2
- package/lib/src/npm/BUILT_IN_PLAYGROUND_PACKAGES.js +2 -2
- package/lib/src/npm/installPlaygroundDependencies.d.ts +2 -2
- package/lib/src/npm/installPlaygroundDependencies.js +2 -2
- package/lib/src/npm/internal/npmRegistry.js.map +1 -1
- package/lib/src/npm/packageNameFromSpecifier.d.ts +2 -2
- package/lib/src/npm/packageNameFromSpecifier.js +2 -2
- package/lib/src/react/createCompilerClient.d.ts +5 -5
- package/lib/src/react/createCompilerClient.js +5 -5
- package/lib/src/react/createCompilerClient.js.map +1 -1
- package/lib/src/sandbox/createSandboxRequire.d.ts +2 -2
- package/lib/src/sandbox/createSandboxRequire.js +2 -2
- package/lib/src/sandbox/loadTypiaRuntimePack.d.ts +3 -3
- package/lib/src/sandbox/loadTypiaRuntimePack.js +3 -3
- package/lib/src/structures/IBuildTsconfigOptions.d.ts +2 -2
- package/lib/src/structures/ICompilerService.d.ts +3 -2
- package/lib/src/structures/IConsoleMessage.d.ts +3 -3
- package/lib/src/structures/ICreateCompilerClientOptions.d.ts +4 -4
- package/lib/src/structures/ICreateWorkerCompilerOptions.d.ts +6 -6
- package/lib/src/structures/IInstallTypiaSourcePackOptions.d.ts +8 -5
- package/lib/src/structures/IOptionToggle.d.ts +2 -2
- package/lib/src/structures/IPlaygroundDependencyProgressPhase.d.ts +4 -1
- package/lib/src/structures/IPlaygroundExample.d.ts +3 -3
- package/lib/src/structures/IPlaygroundShellProps.d.ts +21 -15
- package/lib/src/structures/ISourceEditorProps.d.ts +4 -4
- package/lib/src/structures/ITypiaPluginConfig.d.ts +6 -6
- package/package.json +4 -4
- package/src/compiler/DEFAULT_PLAYGROUND_COMPILER_OPTIONS.ts +4 -4
- package/src/compiler/DEFAULT_TYPIA_PLUGIN_NAME.ts +2 -2
- package/src/compiler/createWorkerCompiler.ts +1 -2
- package/src/compiler/installDependenciesIntoMemFS.ts +4 -4
- package/src/compiler/installTypiaSourcePack.ts +2 -2
- package/src/compiler/internal/joinUnder.ts +4 -1
- package/src/compiler/internal/parseLintDiagnostics.ts +2 -2
- package/src/compiler/internal/safeParseTypiaTransform.ts +3 -3
- package/src/compiler/loadTypiaSourcePack.ts +4 -4
- package/src/compiler/pickEmittedJS.ts +1 -6
- package/src/index.ts +2 -2
- package/src/npm/BUILT_IN_PLAYGROUND_PACKAGES.ts +2 -2
- package/src/npm/installPlaygroundDependencies.ts +3 -3
- package/src/npm/internal/npmRegistry.ts +5 -1
- package/src/npm/packageNameFromSpecifier.ts +2 -2
- package/src/react/createCompilerClient.ts +9 -8
- package/src/sandbox/createSandboxRequire.ts +2 -2
- package/src/sandbox/loadTypiaRuntimePack.ts +3 -3
- package/src/structures/IBuildTsconfigOptions.ts +2 -2
- package/src/structures/ICompilerService.ts +3 -2
- package/src/structures/IConsoleMessage.ts +3 -3
- package/src/structures/ICreateCompilerClientOptions.ts +4 -4
- package/src/structures/ICreateWorkerCompilerOptions.ts +6 -6
- package/src/structures/IInstallTypiaSourcePackOptions.ts +8 -5
- package/src/structures/IOptionToggle.ts +2 -2
- package/src/structures/IPlaygroundDependencyProgressPhase.ts +4 -1
- package/src/structures/IPlaygroundExample.ts +3 -3
- package/src/structures/IPlaygroundShellProps.ts +21 -15
- package/src/structures/ISourceEditorProps.ts +4 -4
- package/src/structures/ITypiaPluginConfig.ts +6 -6
|
@@ -13,13 +13,13 @@ export interface ICreateWorkerCompilerOptions {
|
|
|
13
13
|
apiName: string;
|
|
14
14
|
/** In-MemFS project root. Defaults to `/work`. */
|
|
15
15
|
workDir?: string;
|
|
16
|
-
/**
|
|
16
|
+
/** Tsconfig path relative to `workDir`. Defaults to `tsconfig.json`. */
|
|
17
17
|
tsconfigPath?: string;
|
|
18
18
|
/** Entry source path relative to `workDir`. Defaults to `src/playground.ts`. */
|
|
19
19
|
entryFile?: string;
|
|
20
20
|
/**
|
|
21
|
-
* Typia integration. Pass `false` to disable. When omitted, defaults to
|
|
22
|
-
*
|
|
21
|
+
* Typia integration. Pass `false` to disable. When omitted, defaults to `{
|
|
22
|
+
* name: "typia", transformModule: "typia/lib/transform" }` — and only
|
|
23
23
|
* actually runs when the per-call `options.typia` is not `false`.
|
|
24
24
|
*/
|
|
25
25
|
typiaPlugin?: ITypiaPluginConfig | false;
|
|
@@ -27,9 +27,9 @@ export interface ICreateWorkerCompilerOptions {
|
|
|
27
27
|
lintPlugin?: ILintPluginConfig | false;
|
|
28
28
|
/**
|
|
29
29
|
* Extra entries spliced into the tsconfig's `compilerOptions`. Use to wire
|
|
30
|
-
* site-specific plugins, paths, or lib overrides. The typia plugin entry
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* site-specific plugins, paths, or lib overrides. The typia plugin entry is
|
|
31
|
+
* appended automatically when `typiaPlugin` is enabled — sites should NOT
|
|
32
|
+
* include it here.
|
|
33
33
|
*/
|
|
34
34
|
extraCompilerOptions?: Record<string, unknown>;
|
|
35
35
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@link installTypiaSourcePack} and
|
|
3
|
+
* {@link createTypiaSourcePackMount}.
|
|
4
|
+
*/
|
|
2
5
|
export interface IInstallTypiaSourcePackOptions {
|
|
3
6
|
/** URL the site serves the pre-built typia source pack from. */
|
|
4
7
|
url: string;
|
|
5
8
|
/**
|
|
6
|
-
* Where to mount the pack inside the MemFS. Defaults to
|
|
7
|
-
*
|
|
9
|
+
* Where to mount the pack inside the MemFS. Defaults to `/work/node_modules`,
|
|
10
|
+
* matching `DEFAULT_WORK_DIR + "/node_modules"`.
|
|
8
11
|
*/
|
|
9
12
|
mountRoot?: string;
|
|
10
13
|
/**
|
|
11
|
-
* Optional fetcher. Defaults to `globalThis.fetch`. Override for tests
|
|
12
|
-
*
|
|
14
|
+
* Optional fetcher. Defaults to `globalThis.fetch`. Override for tests or for
|
|
15
|
+
* sites that want their own caching strategy.
|
|
13
16
|
*/
|
|
14
17
|
fetch?: (input: string) => Promise<Response>;
|
|
15
18
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Toggle metadata the OptionsPanel renders.
|
|
3
3
|
*
|
|
4
|
-
* Sites declare these for whatever transform plugins their wasm registered;
|
|
5
|
-
*
|
|
4
|
+
* Sites declare these for whatever transform plugins their wasm registered; the
|
|
5
|
+
* panel renders one row per entry and bubbles `onChange` with the merged
|
|
6
6
|
* options object.
|
|
7
7
|
*/
|
|
8
8
|
export interface IOptionToggle {
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle phase of a single dependency install reported via the progress
|
|
3
|
+
* callback.
|
|
4
|
+
*/
|
|
2
5
|
export type IPlaygroundDependencyProgressPhase = "queued" | "resolve" | "download" | "extract" | "skip" | "error" | "done";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One pre-canned source script the playground dropdown can load. Sites
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* One pre-canned source script the playground dropdown can load. Sites provide
|
|
3
|
+
* their own list — typia's site lists `random/is/json/protobuf`, the ttsc site
|
|
4
|
+
* lists `typia/lint/mixed`.
|
|
5
5
|
*/
|
|
6
6
|
export interface IPlaygroundExample {
|
|
7
7
|
id: string;
|
|
@@ -10,7 +10,10 @@ import type { ITransformOptions } from "./ITransformOptions";
|
|
|
10
10
|
* defaults without a Provider in between.
|
|
11
11
|
*/
|
|
12
12
|
export interface IPlaygroundShellProps {
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* URL of the bundled worker script (rspack output of the site's worker
|
|
15
|
+
* entry).
|
|
16
|
+
*/
|
|
14
17
|
workerUrl: string;
|
|
15
18
|
/** Source code shown on first mount (and on Reset). */
|
|
16
19
|
defaultScript: string;
|
|
@@ -20,29 +23,32 @@ export interface IPlaygroundShellProps {
|
|
|
20
23
|
exampleGroupLabels?: Record<string, string>;
|
|
21
24
|
/** Toggles rendered in the Options modal. Defaults to typia + lint. */
|
|
22
25
|
optionToggles?: readonly IOptionToggle[];
|
|
23
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Initial values for the transform options. Defaults to `{typia: true, lint:
|
|
28
|
+
* true}`.
|
|
29
|
+
*/
|
|
24
30
|
defaultOptions?: ITransformOptions;
|
|
25
31
|
/**
|
|
26
|
-
* Static extra .d.ts entries to mount in Monaco (e.g. a pre-packed typia
|
|
27
|
-
*
|
|
32
|
+
* Static extra .d.ts entries to mount in Monaco (e.g. a pre-packed typia type
|
|
33
|
+
* pack). Merged with dependencies installed at runtime.
|
|
28
34
|
*/
|
|
29
35
|
staticEditorLibs?: Record<string, string>;
|
|
30
36
|
/**
|
|
31
|
-
* Packages the site has already pre-mounted into the wasm. These are
|
|
32
|
-
*
|
|
37
|
+
* Packages the site has already pre-mounted into the wasm. These are skipped
|
|
38
|
+
* by the runtime npm dependency installer.
|
|
33
39
|
*/
|
|
34
40
|
preinstalledPackages?: readonly string[];
|
|
35
41
|
/**
|
|
36
42
|
* Optional execute hook. When provided, the shell renders an "Execute"
|
|
37
|
-
* button; on click it calls `service.bundle(...)` to get the JS and passes
|
|
38
|
-
*
|
|
43
|
+
* button; on click it calls `service.bundle(...)` to get the JS and passes it
|
|
44
|
+
* here. The returned messages are appended to the Console pane.
|
|
39
45
|
*
|
|
40
46
|
* `sandbox.runtimeFiles` is the accumulated runtime-file map produced by
|
|
41
47
|
* every `installPlaygroundDependencies` call so far in this session
|
|
42
48
|
* (package-rooted keys like `uuid/dist/index.js`). The site's executeBundle
|
|
43
|
-
* typically merges these on top of its own typia-runtime pack and feeds
|
|
44
|
-
*
|
|
45
|
-
*
|
|
49
|
+
* typically merges these on top of its own typia-runtime pack and feeds the
|
|
50
|
+
* union to `createSandboxRequire` — without this channel the in-page Execute
|
|
51
|
+
* sandbox cannot resolve any npm dependency the user installed.
|
|
46
52
|
*
|
|
47
53
|
* When omitted, the Execute UI is hidden.
|
|
48
54
|
*/
|
|
@@ -51,14 +57,14 @@ export interface IPlaygroundShellProps {
|
|
|
51
57
|
runtimeFiles: Record<string, string>;
|
|
52
58
|
}) => Promise<void>;
|
|
53
59
|
/**
|
|
54
|
-
* Brand slot in the toolbar (left side). Renders before the Playground
|
|
55
|
-
*
|
|
60
|
+
* Brand slot in the toolbar (left side). Renders before the Playground label.
|
|
61
|
+
* Sites typically pass `<a href="/">SiteName</a>`.
|
|
56
62
|
*/
|
|
57
63
|
brand?: ReactNode;
|
|
58
64
|
/**
|
|
59
65
|
* Caption shown on the result pane when the active tab is "javascript".
|
|
60
|
-
* Defaults to `"dist/playground.js"`. Receives the current transform
|
|
61
|
-
*
|
|
66
|
+
* Defaults to `"dist/playground.js"`. Receives the current transform options
|
|
67
|
+
* so sites can append `· typia disabled` etc.
|
|
62
68
|
*/
|
|
63
69
|
resultCaption?: (options: ITransformOptions) => string;
|
|
64
70
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Props for the Monaco-based source editor. The site provides `extraLibs` —
|
|
3
|
-
* typically the typia `.d.ts` pack and any installed npm package `.d.ts`
|
|
4
|
-
*
|
|
3
|
+
* typically the typia `.d.ts` pack and any installed npm package `.d.ts` files
|
|
4
|
+
* — and the editor mounts them via
|
|
5
5
|
* `monaco.languages.typescript.typescriptDefaults.addExtraLib`.
|
|
6
6
|
*/
|
|
7
7
|
export interface ISourceEditorProps {
|
|
@@ -9,8 +9,8 @@ export interface ISourceEditorProps {
|
|
|
9
9
|
onChange: (value: string) => void;
|
|
10
10
|
/**
|
|
11
11
|
* Map of file path → declaration text. Mounted into Monaco's TypeScript
|
|
12
|
-
* extra-libs registry. Hot-replaceable: the editor disposes the previous
|
|
13
|
-
*
|
|
12
|
+
* extra-libs registry. Hot-replaceable: the editor disposes the previous libs
|
|
13
|
+
* and re-mounts when the map identity changes.
|
|
14
14
|
*/
|
|
15
15
|
extraLibs?: Record<string, string>;
|
|
16
16
|
/** Editor model URI. Defaults to `file:///src/playground.ts`. */
|
|
@@ -4,16 +4,16 @@ export interface ITypiaPluginConfig {
|
|
|
4
4
|
/** Plugin id registered with `host.Expose` (default: `"typia"`). */
|
|
5
5
|
name?: string;
|
|
6
6
|
/**
|
|
7
|
-
* Module specifier the typia transform receives via
|
|
8
|
-
*
|
|
7
|
+
* Module specifier the typia transform receives via `compilerOptions.plugins`
|
|
8
|
+
* (default: `"typia/lib/transform"`).
|
|
9
9
|
*/
|
|
10
10
|
transformModule?: string;
|
|
11
11
|
/**
|
|
12
|
-
* Optional hook to mount typia source files into the MemFS during boot.
|
|
13
|
-
*
|
|
12
|
+
* Optional hook to mount typia source files into the MemFS during boot. The
|
|
13
|
+
* site fetches its pre-built typia pack and writes it under
|
|
14
14
|
* `<workDir>/node_modules/`. `workDir` is forwarded from
|
|
15
|
-
* `createWorkerCompiler` so the mount can honor a non-default project
|
|
16
|
-
*
|
|
15
|
+
* `createWorkerCompiler` so the mount can honor a non-default project root
|
|
16
|
+
* without the site rewiring the URL.
|
|
17
17
|
*/
|
|
18
18
|
mount?: (host: IMemFSHost, workDir: string) => Promise<void>;
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttsc/playground",
|
|
3
|
-
"version": "0.14.0
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Reusable React + Web Worker scaffolding for in-browser ttsc playgrounds built on @ttsc/wasm.",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"react": "^18.0.0",
|
|
39
39
|
"react-dom": "^18.0.0",
|
|
40
40
|
"tgrid": "^1.0.3",
|
|
41
|
-
"@ttsc/wasm": "^0.14.0
|
|
41
|
+
"@ttsc/wasm": "^0.14.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@monaco-editor/react": "^4.6.0",
|
|
45
45
|
"@types/node": "^25.3.0",
|
|
46
46
|
"@types/react": "^18.3.1",
|
|
47
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
47
|
+
"@typescript/native-preview": "7.0.0-dev.20260519.1",
|
|
48
48
|
"monaco-editor": "^0.52.0",
|
|
49
49
|
"react": "^18.3.1",
|
|
50
50
|
"react-dom": "^18.3.1",
|
|
51
51
|
"rimraf": "^6.1.2",
|
|
52
52
|
"tgrid": "^1.0.3",
|
|
53
|
-
"@ttsc/wasm": "^0.14.0
|
|
53
|
+
"@ttsc/wasm": "^0.14.0"
|
|
54
54
|
},
|
|
55
55
|
"keywords": [
|
|
56
56
|
"ttsc",
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* pass these straight to `buildTsconfigJSON`; consumer code that needs a tweak
|
|
4
4
|
* spreads the constant and overrides individual fields.
|
|
5
5
|
*
|
|
6
|
-
* `target` and `module` are TypeScript's numeric enum values (99 = ESNext,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* `target` and `module` are TypeScript's numeric enum values (99 = ESNext, 199
|
|
7
|
+
* = NodeNext, …). They are spelled numerically here because the wasm doesn't
|
|
8
|
+
* run the TS configuration parser through a string→enum step before Go reads
|
|
9
|
+
* the JSON; passing the canonical numbers avoids version-drift.
|
|
10
10
|
*/
|
|
11
11
|
export const DEFAULT_PLAYGROUND_COMPILER_OPTIONS = {
|
|
12
12
|
target: 99,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Default plugin id for the typia transformer. Sites that wire a renamed
|
|
3
|
-
*
|
|
2
|
+
* Default plugin id for the typia transformer. Sites that wire a renamed typia
|
|
3
|
+
* plugin override via the `typiaPlugin.name` option of
|
|
4
4
|
* {@link createWorkerCompiler}.
|
|
5
5
|
*/
|
|
6
6
|
export const DEFAULT_TYPIA_PLUGIN_NAME = "typia";
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
// the site's chosen module shape, registers the typia/lint plugin verbs (or
|
|
6
6
|
// the site-provided overrides), and serializes every MemFS-mutating call onto
|
|
7
7
|
// a single chain so concurrent compiles never corrupt each other.
|
|
8
|
-
|
|
9
8
|
import {
|
|
10
9
|
type IBootResult,
|
|
11
10
|
type ITtscCompileResult,
|
|
@@ -16,12 +15,12 @@ import {
|
|
|
16
15
|
import type { ICompilerService } from "../structures/ICompilerService";
|
|
17
16
|
import type { ICreateWorkerCompilerOptions } from "../structures/ICreateWorkerCompilerOptions";
|
|
18
17
|
import type { ITransformOptions } from "../structures/ITransformOptions";
|
|
19
|
-
import { buildTsconfigJSON } from "./buildTsconfigJSON";
|
|
20
18
|
import { DEFAULT_ENTRY_FILE } from "./DEFAULT_ENTRY_FILE";
|
|
21
19
|
import { DEFAULT_LINT_PLUGIN_NAME } from "./DEFAULT_LINT_PLUGIN_NAME";
|
|
22
20
|
import { DEFAULT_TSCONFIG_PATH } from "./DEFAULT_TSCONFIG_PATH";
|
|
23
21
|
import { DEFAULT_TYPIA_PLUGIN_NAME } from "./DEFAULT_TYPIA_PLUGIN_NAME";
|
|
24
22
|
import { DEFAULT_WORK_DIR } from "./DEFAULT_WORK_DIR";
|
|
23
|
+
import { buildTsconfigJSON } from "./buildTsconfigJSON";
|
|
25
24
|
import { installDependenciesIntoMemFS } from "./installDependenciesIntoMemFS";
|
|
26
25
|
import { joinUnder } from "./internal/joinUnder";
|
|
27
26
|
import { parseLintDiagnostics } from "./internal/parseLintDiagnostics";
|
|
@@ -7,10 +7,10 @@ import { normalizeNodeModulePath } from "./normalizeNodeModulePath";
|
|
|
7
7
|
* Mount external npm package files into the worker's MemFS under
|
|
8
8
|
* `<workDir>/node_modules/...`.
|
|
9
9
|
*
|
|
10
|
-
* Used by `createWorkerCompiler` to implement the `installDependencies` verb
|
|
11
|
-
*
|
|
12
|
-
* `node_modules/uuid/dist/index.js`; we normalize, sanity-check, and copy
|
|
13
|
-
*
|
|
10
|
+
* Used by `createWorkerCompiler` to implement the `installDependencies` verb of
|
|
11
|
+
* `ICompilerService`. The dependency installer (UI side) feeds keys like
|
|
12
|
+
* `node_modules/uuid/dist/index.js`; we normalize, sanity-check, and copy each
|
|
13
|
+
* entry under the project root.
|
|
14
14
|
*/
|
|
15
15
|
export function installDependenciesIntoMemFS(
|
|
16
16
|
host: IMemFSHost,
|
|
@@ -5,8 +5,8 @@ import { loadTypiaSourcePack } from "./loadTypiaSourcePack";
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Mounts typia + @typia/* source trees into the in-browser MemFS so the
|
|
8
|
-
* wasm-side compiler can resolve `import typia, { tags } from "typia"`
|
|
9
|
-
*
|
|
8
|
+
* wasm-side compiler can resolve `import typia, { tags } from "typia"` against
|
|
9
|
+
* the same code the published package uses.
|
|
10
10
|
*
|
|
11
11
|
* Idempotent on the same host (re-writing the same paths is a no-op for the
|
|
12
12
|
* MemFS implementation).
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Join a relative path under a base directory, ignoring base when `rel` is
|
|
3
|
+
* absolute.
|
|
4
|
+
*/
|
|
2
5
|
export function joinUnder(base: string, rel: string): string {
|
|
3
6
|
if (rel.startsWith("/")) return rel;
|
|
4
7
|
return `${base}/${rel}`;
|
|
@@ -43,8 +43,8 @@ export function parseLintDiagnostics(
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Best-effort length of the identifier-like token starting at (`line`,
|
|
47
|
-
* in `source`. Falls back to 1 when no token is found.
|
|
46
|
+
* Best-effort length of the identifier-like token starting at (`line`,
|
|
47
|
+
* `column`) in `source`. Falls back to 1 when no token is found.
|
|
48
48
|
*/
|
|
49
49
|
function lengthOfTokenAt(
|
|
50
50
|
source: string,
|
|
@@ -5,9 +5,9 @@ export interface ITypiaTransformOutput {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Parse the typia transform plugin's stdout into the expected shape.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Parse the typia transform plugin's stdout into the expected shape. Returns
|
|
9
|
+
* null on any parse / shape mismatch — the caller treats null as "transform
|
|
10
|
+
* produced no usable output".
|
|
11
11
|
*/
|
|
12
12
|
export function safeParseTypiaTransform(
|
|
13
13
|
text: string,
|
|
@@ -3,10 +3,10 @@ import type { IInstallTypiaSourcePackOptions } from "../structures/IInstallTypia
|
|
|
3
3
|
const packCache = new Map<string, Promise<Record<string, string>>>();
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Fetch the typia source pack JSON. Cached per URL across calls. On
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Fetch the typia source pack JSON. Cached per URL across calls. On rejection
|
|
7
|
+
* the cache entry is cleared so the next call retries — otherwise a transient
|
|
8
|
+
* fetch failure during the first boot would wedge every later boot through
|
|
9
|
+
* `getBoot`'s typiaPlugin.mount path.
|
|
10
10
|
*/
|
|
11
11
|
export function loadTypiaSourcePack(
|
|
12
12
|
options: IInstallTypiaSourcePackOptions,
|
|
@@ -8,12 +8,7 @@ export function pickEmittedJS(
|
|
|
8
8
|
entryFile: string,
|
|
9
9
|
): string | null {
|
|
10
10
|
const base = entryFile.replace(/\.[cm]?tsx?$/i, ".js");
|
|
11
|
-
const candidates = [
|
|
12
|
-
`dist/${base}`,
|
|
13
|
-
`dist/src/${base}`,
|
|
14
|
-
`src/${base}`,
|
|
15
|
-
base,
|
|
16
|
-
];
|
|
11
|
+
const candidates = [`dist/${base}`, `dist/src/${base}`, `src/${base}`, base];
|
|
17
12
|
for (const key of candidates) {
|
|
18
13
|
if (output[key] !== undefined) return output[key];
|
|
19
14
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* The package is organized by concern: the `compiler/*` modules implement the
|
|
6
6
|
* worker-side `ICompilerService` contract; the `npm/*` modules install
|
|
7
7
|
* on-the-fly npm dependencies into the wasm MemFS; the `sandbox/*` modules
|
|
8
|
-
* drive an in-page `new Function` execute sandbox; the `react/*` modules
|
|
9
|
-
*
|
|
8
|
+
* drive an in-page `new Function` execute sandbox; the `react/*` modules render
|
|
9
|
+
* the shell, editor, and result panes.
|
|
10
10
|
*
|
|
11
11
|
* The package root re-exports everything; sub-path imports are not needed.
|
|
12
12
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Packages the typia source pack already mounts inside the wasm. The npm
|
|
3
|
-
* installer skips these so it doesn't try to fetch typia / @typia/* from
|
|
4
|
-
*
|
|
3
|
+
* installer skips these so it doesn't try to fetch typia / @typia/* from the
|
|
4
|
+
* registry on top of the mounted source tree.
|
|
5
5
|
*/
|
|
6
6
|
export const BUILT_IN_PLAYGROUND_PACKAGES = [
|
|
7
7
|
"typia",
|
|
@@ -4,10 +4,10 @@ import type { IPlaygroundDependencyProgressPhase } from "../structures/IPlaygrou
|
|
|
4
4
|
import { BUILT_IN_PLAYGROUND_PACKAGES } from "./BUILT_IN_PLAYGROUND_PACKAGES";
|
|
5
5
|
import {
|
|
6
6
|
DECLARATION_FILE_REGEXP,
|
|
7
|
+
type IQueueItem,
|
|
7
8
|
downloadTarball,
|
|
8
9
|
enqueuePackageDependencies,
|
|
9
10
|
fetchNpmMetadata,
|
|
10
|
-
type IQueueItem,
|
|
11
11
|
mountPackageFiles,
|
|
12
12
|
selectVersion,
|
|
13
13
|
throwIfAborted,
|
|
@@ -24,8 +24,8 @@ const DEFAULT_MAX_PACKAGES = 48;
|
|
|
24
24
|
*
|
|
25
25
|
* Transitive dependencies are followed via the resolved `package.json`'s
|
|
26
26
|
* `dependencies` and (non-optional) `peerDependencies` fields. The walk is
|
|
27
|
-
* bounded by `maxPackages` to keep a single keystroke from exhausting the
|
|
28
|
-
*
|
|
27
|
+
* bounded by `maxPackages` to keep a single keystroke from exhausting the tab's
|
|
28
|
+
* network/memory budget.
|
|
29
29
|
*/
|
|
30
30
|
export async function installPlaygroundDependencies(
|
|
31
31
|
packageNames: Iterable<string>,
|
|
@@ -207,7 +207,11 @@ export function mountPackageFiles(
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
export function enqueuePackageDependencies(
|
|
210
|
-
packageJson: {
|
|
210
|
+
packageJson: {
|
|
211
|
+
dependencies?: Record<string, string>;
|
|
212
|
+
peerDependencies?: Record<string, string>;
|
|
213
|
+
peerDependenciesMeta?: Record<string, { optional?: boolean }>;
|
|
214
|
+
},
|
|
211
215
|
enqueue: (item: IQueueItem) => void,
|
|
212
216
|
): void {
|
|
213
217
|
for (const [name, range] of Object.entries(packageJson.dependencies ?? {})) {
|
|
@@ -34,8 +34,8 @@ const BUILTIN_MODULES = new Set([
|
|
|
34
34
|
/**
|
|
35
35
|
* Extract the package name from a module specifier.
|
|
36
36
|
*
|
|
37
|
-
* Returns `null` for relative paths, hash imports, URL specifiers, and
|
|
38
|
-
*
|
|
37
|
+
* Returns `null` for relative paths, hash imports, URL specifiers, and Node
|
|
38
|
+
* built-in modules — the caller doesn't install those from npm.
|
|
39
39
|
*/
|
|
40
40
|
export function packageNameFromSpecifier(specifier: string): string | null {
|
|
41
41
|
if (
|
|
@@ -6,16 +6,17 @@ import type { ICompilerService } from "../structures/ICompilerService";
|
|
|
6
6
|
import type { ICreateCompilerClientOptions } from "../structures/ICreateCompilerClientOptions";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* UI-side singleton: connect to the playground worker over tgrid and return
|
|
10
|
-
*
|
|
9
|
+
* UI-side singleton: connect to the playground worker over tgrid and return the
|
|
10
|
+
* typed `ICompilerService` driver.
|
|
11
11
|
*
|
|
12
|
-
* The promise is cached; the first call boots, every subsequent call shares
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* The promise is cached; the first call boots, every subsequent call shares the
|
|
13
|
+
* same connection. If the boot rejects the cache is cleared so the next call
|
|
14
|
+
* retries — otherwise every retry would resolve to the same rejection.
|
|
15
15
|
*/
|
|
16
|
-
export function createCompilerClient(
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
export function createCompilerClient(options: ICreateCompilerClientOptions): {
|
|
17
|
+
connect(): Promise<ICompilerService>;
|
|
18
|
+
reset(): Promise<void>;
|
|
19
|
+
} {
|
|
19
20
|
let connectionPromise: Promise<ICompilerService> | null = null;
|
|
20
21
|
// Track the active connector AND the in-flight connector promise so
|
|
21
22
|
// reset() can dispose either one — disposing only the resolved
|
|
@@ -32,8 +32,8 @@ interface ISandboxRequireOptions {
|
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Build a sandboxed `require` function over a runtime pack. Resolves typia /
|
|
35
|
-
* `@typia/*` / randexp specifiers from the pack; throws on anything else so
|
|
36
|
-
*
|
|
35
|
+
* `@typia/*` / randexp specifiers from the pack; throws on anything else so the
|
|
36
|
+
* caller sees the unsupported dependency.
|
|
37
37
|
*/
|
|
38
38
|
export function createSandboxRequire(
|
|
39
39
|
pack: Record<string, string>,
|
|
@@ -10,9 +10,9 @@ const packCache = new Map<string, Promise<Record<string, string>>>();
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Fetches the prebuilt runtime pack once per URL. Re-entrant on the same
|
|
13
|
-
* in-flight promise. On rejection the cache entry is cleared so the next
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* in-flight promise. On rejection the cache entry is cleared so the next call
|
|
14
|
+
* retries — otherwise a transient fetch failure (CDN blip, offline at first
|
|
15
|
+
* Execute) would permanently break every later Execute attempt.
|
|
16
16
|
*/
|
|
17
17
|
export async function loadTypiaRuntimePack(
|
|
18
18
|
url: string,
|
|
@@ -10,8 +10,8 @@ export interface IBuildTsconfigOptions {
|
|
|
10
10
|
/** Source root relative to project root. Defaults to `"src"`. */
|
|
11
11
|
rootDir?: string;
|
|
12
12
|
/**
|
|
13
|
-
* Extra entries spliced into `compilerOptions`. Use for plugins, paths,
|
|
14
|
-
*
|
|
13
|
+
* Extra entries spliced into `compilerOptions`. Use for plugins, paths, lib
|
|
14
|
+
* overrides, etc.
|
|
15
15
|
*/
|
|
16
16
|
compilerOptions?: Record<string, unknown>;
|
|
17
17
|
/** Project `include` globs. Defaults to `["src"]`. */
|
|
@@ -11,7 +11,8 @@ import type { ITransformOptions } from "./ITransformOptions";
|
|
|
11
11
|
export interface ICompilerService {
|
|
12
12
|
/**
|
|
13
13
|
* Mount external npm package files into the worker's MemFS under
|
|
14
|
-
* `node_modules/`. Driven by the dependency installer in
|
|
14
|
+
* `node_modules/`. Driven by the dependency installer in
|
|
15
|
+
* `@ttsc/playground/npm`.
|
|
15
16
|
*/
|
|
16
17
|
installDependencies(
|
|
17
18
|
props: ICompilerService.IInstallDependenciesProps,
|
|
@@ -46,7 +47,7 @@ export namespace ICompilerService {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
export interface IInstallDependenciesProps {
|
|
49
|
-
/**
|
|
50
|
+
/** Node_modules-relative paths to text content. */
|
|
50
51
|
files: Record<string, string>;
|
|
51
52
|
/** Metadata for the packages whose files are in `files`. */
|
|
52
53
|
packages: IInstalledPackage[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* One captured `console.*` invocation. `value` is the argv (the spread of
|
|
3
|
-
* `console.log(...args)`), so `console.log("user:", user)` shows up as a
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* `console.log(...args)`), so `console.log("user:", user)` shows up as a single
|
|
4
|
+
* row with both pieces rendered inline, separated by a space — same as a real
|
|
5
|
+
* DevTools console.
|
|
6
6
|
*/
|
|
7
7
|
export interface IConsoleMessage {
|
|
8
8
|
type: "debug" | "dir" | "error" | "info" | "log" | "table" | "warn";
|
|
@@ -4,10 +4,10 @@ export interface ICreateCompilerClientOptions {
|
|
|
4
4
|
* URL of the bundled worker script (the site's rspack output of its
|
|
5
5
|
* `compiler/index.ts` worker entry, which calls `createWorkerCompiler`).
|
|
6
6
|
*
|
|
7
|
-
* The Worker is constructed by tgrid's `WorkerConnector` with classic-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* The Worker is constructed by tgrid's `WorkerConnector` with classic- worker
|
|
8
|
+
* semantics. A custom Worker factory hook is intentionally not exposed — the
|
|
9
|
+
* upstream tgrid v1 API only accepts a URL. File an issue if you need module
|
|
10
|
+
* workers, named workers, or custom credentials.
|
|
11
11
|
*/
|
|
12
12
|
workerUrl: string;
|
|
13
13
|
}
|
|
@@ -15,14 +15,14 @@ export interface ICreateWorkerCompilerOptions {
|
|
|
15
15
|
|
|
16
16
|
/** In-MemFS project root. Defaults to `/work`. */
|
|
17
17
|
workDir?: string;
|
|
18
|
-
/**
|
|
18
|
+
/** Tsconfig path relative to `workDir`. Defaults to `tsconfig.json`. */
|
|
19
19
|
tsconfigPath?: string;
|
|
20
20
|
/** Entry source path relative to `workDir`. Defaults to `src/playground.ts`. */
|
|
21
21
|
entryFile?: string;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Typia integration. Pass `false` to disable. When omitted, defaults to
|
|
25
|
-
*
|
|
24
|
+
* Typia integration. Pass `false` to disable. When omitted, defaults to `{
|
|
25
|
+
* name: "typia", transformModule: "typia/lib/transform" }` — and only
|
|
26
26
|
* actually runs when the per-call `options.typia` is not `false`.
|
|
27
27
|
*/
|
|
28
28
|
typiaPlugin?: ITypiaPluginConfig | false;
|
|
@@ -32,9 +32,9 @@ export interface ICreateWorkerCompilerOptions {
|
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Extra entries spliced into the tsconfig's `compilerOptions`. Use to wire
|
|
35
|
-
* site-specific plugins, paths, or lib overrides. The typia plugin entry
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* site-specific plugins, paths, or lib overrides. The typia plugin entry is
|
|
36
|
+
* appended automatically when `typiaPlugin` is enabled — sites should NOT
|
|
37
|
+
* include it here.
|
|
38
38
|
*/
|
|
39
39
|
extraCompilerOptions?: Record<string, unknown>;
|
|
40
40
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@link installTypiaSourcePack} and
|
|
3
|
+
* {@link createTypiaSourcePackMount}.
|
|
4
|
+
*/
|
|
2
5
|
export interface IInstallTypiaSourcePackOptions {
|
|
3
6
|
/** URL the site serves the pre-built typia source pack from. */
|
|
4
7
|
url: string;
|
|
5
8
|
/**
|
|
6
|
-
* Where to mount the pack inside the MemFS. Defaults to
|
|
7
|
-
*
|
|
9
|
+
* Where to mount the pack inside the MemFS. Defaults to `/work/node_modules`,
|
|
10
|
+
* matching `DEFAULT_WORK_DIR + "/node_modules"`.
|
|
8
11
|
*/
|
|
9
12
|
mountRoot?: string;
|
|
10
13
|
/**
|
|
11
|
-
* Optional fetcher. Defaults to `globalThis.fetch`. Override for tests
|
|
12
|
-
*
|
|
14
|
+
* Optional fetcher. Defaults to `globalThis.fetch`. Override for tests or for
|
|
15
|
+
* sites that want their own caching strategy.
|
|
13
16
|
*/
|
|
14
17
|
fetch?: (input: string) => Promise<Response>;
|
|
15
18
|
}
|