@secure-exec/typescript 0.2.1-rc.1 → 0.3.0-rc.2

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 CHANGED
@@ -1,7 +1,50 @@
1
- # Secure Exec
1
+ # @secure-exec/typescript
2
2
 
3
- Secure Node.js execution without a sandbox. V8 isolate-based code execution with full Node.js and npm compatibility.
3
+ Run the TypeScript compiler **inside the secure-exec sandbox**. The compiler is
4
+ projected into the VM and every compile and type-check happens in the guest, so
5
+ untrusted TypeScript never executes (or compiles) on the host.
4
6
 
5
- - [Website](https://secureexec.dev)
6
- - [Documentation](https://secureexec.dev/docs)
7
- - [GitHub](https://github.com/rivet-dev/secure-exec)
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @secure-exec/typescript secure-exec
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { createTypeScriptTools } from "@secure-exec/typescript";
17
+
18
+ const tools = createTypeScriptTools();
19
+
20
+ // Compile TypeScript to JavaScript inside the sandbox.
21
+ const compiled = await tools.compileSource({
22
+ sourceText: "const answer: number = 42;\nconsole.log(answer);",
23
+ compilerOptions: { module: "ESNext", target: "ES2022" },
24
+ });
25
+ console.log(compiled.outputText);
26
+
27
+ // Type-check inside the sandbox and get structured diagnostics back.
28
+ const checked = await tools.typecheckSource({
29
+ sourceText: `const total: number = "not a number";`,
30
+ });
31
+ console.log(checked.success, checked.diagnostics);
32
+ ```
33
+
34
+ ## API
35
+
36
+ `createTypeScriptTools(options?)` returns:
37
+
38
+ - `compileSource({ sourceText, filePath?, cwd?, configFilePath?, compilerOptions? })`
39
+ -> `{ success, diagnostics, outputText, sourceMapText }`
40
+ - `typecheckSource({ sourceText, ... })` -> `{ success, diagnostics }`
41
+ - `compileProject({ cwd?, configFilePath? })`
42
+ -> `{ success, diagnostics, emitSkipped, emittedFiles }`
43
+ - `typecheckProject({ cwd?, configFilePath? })` -> `{ success, diagnostics }`
44
+
45
+ Each diagnostic is `{ code, category, message, filePath?, line?, column? }`.
46
+
47
+ Seed extra files into the VM with the `files` option, or project host
48
+ directories with the `mounts` option, to compile whole projects.
49
+
50
+ See the [documentation](https://secureexec.dev/docs) for details.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,16 @@
1
- import type { NodeRuntimeDriverFactory } from "secure-exec";
2
- import type { SystemDriver } from "@secure-exec/core";
1
+ /**
2
+ * @secure-exec/typescript — run the TypeScript compiler inside the sandbox.
3
+ *
4
+ * The TypeScript compiler (`typescript.js`) is projected into the VM's virtual
5
+ * filesystem and the compile/type-check program is executed in-guest through
6
+ * the `secure-exec` `NodeRuntime`. The compiler never runs on the host: every
7
+ * `createSourceFile`/`createProgram`/`emit` call happens inside the kernel
8
+ * isolation boundary, over the VM's filesystem.
9
+ */
10
+ import type { HostDirectoryMount, NodeRuntimeCreateOptions } from "secure-exec";
11
+ /** VM permission policy, as accepted by `NodeRuntime.create`. */
12
+ export type Permissions = NonNullable<NodeRuntimeCreateOptions["permissions"]>;
13
+ /** A single TypeScript diagnostic, normalized for host consumption. */
3
14
  export interface TypeScriptDiagnostic {
4
15
  code: number;
5
16
  category: "error" | "warning" | "suggestion" | "message";
@@ -8,41 +19,79 @@ export interface TypeScriptDiagnostic {
8
19
  line?: number;
9
20
  column?: number;
10
21
  }
22
+ /** Result of a type-check (no emit). */
11
23
  export interface TypeCheckResult {
12
24
  success: boolean;
13
25
  diagnostics: TypeScriptDiagnostic[];
14
26
  }
27
+ /** Result of compiling a project (emit to the VM filesystem). */
15
28
  export interface ProjectCompileResult extends TypeCheckResult {
16
29
  emitSkipped: boolean;
17
30
  emittedFiles: string[];
18
31
  }
32
+ /** Result of compiling a single source string (emit returned in-memory). */
19
33
  export interface SourceCompileResult extends TypeCheckResult {
20
34
  outputText?: string;
21
35
  sourceMapText?: string;
22
36
  }
37
+ /** Options for the project-oriented tools. */
23
38
  export interface ProjectCompilerOptions {
39
+ /** Working directory inside the VM. Defaults to `/root`. */
24
40
  cwd?: string;
41
+ /** Explicit path to a `tsconfig.json` inside the VM. */
25
42
  configFilePath?: string;
26
43
  }
44
+ /** Options for the single-source tools. */
27
45
  export interface SourceCompilerOptions {
46
+ /** TypeScript source text to compile or type-check. */
28
47
  sourceText: string;
48
+ /** Virtual path the source should appear at. Defaults to a temp `.ts` file. */
29
49
  filePath?: string;
50
+ /** Working directory inside the VM. Defaults to `/root`. */
30
51
  cwd?: string;
52
+ /** Optional `tsconfig.json` whose `compilerOptions` are applied. */
31
53
  configFilePath?: string;
54
+ /** Inline compiler options (esbuild/tsc JSON spelling). */
32
55
  compilerOptions?: Record<string, unknown>;
33
56
  }
57
+ /** Options for {@link createTypeScriptTools}. */
34
58
  export interface TypeScriptToolsOptions {
35
- systemDriver: SystemDriver;
36
- runtimeDriverFactory: NodeRuntimeDriverFactory;
37
- memoryLimit?: number;
38
- cpuTimeLimitMs?: number;
39
- compilerSpecifier?: string;
59
+ /**
60
+ * Host directory of the `typescript` npm package to project into the VM.
61
+ * Defaults to the `typescript` package resolved from this package. The
62
+ * directory is mounted (read lazily) into the VM; the compiler never runs
63
+ * on the host.
64
+ */
65
+ compilerPackageDir?: string;
66
+ /**
67
+ * Guest path the `typescript` package is mounted at. Defaults to
68
+ * `/root/node_modules/typescript` so it resolves as the `typescript`
69
+ * package inside the VM.
70
+ */
71
+ compilerGuestDir?: string;
72
+ /** Extra files to seed into the VM (e.g. a `tsconfig.json` or sources). */
73
+ files?: Record<string, string | Uint8Array>;
74
+ /** Extra host directories to project into the VM, Docker-style. */
75
+ mounts?: HostDirectoryMount[];
76
+ /** Permission policy forwarded to the VM. */
77
+ permissions?: Permissions;
78
+ /** Environment variables visible to the guest compiler. */
79
+ env?: Record<string, string>;
40
80
  }
41
- type CompilerTools = {
81
+ /** The in-sandbox TypeScript tools returned by {@link createTypeScriptTools}. */
82
+ export interface TypeScriptTools {
83
+ /** Type-check a `tsconfig.json` project inside the VM. */
42
84
  typecheckProject(options?: ProjectCompilerOptions): Promise<TypeCheckResult>;
85
+ /** Compile a `tsconfig.json` project, emitting into the VM filesystem. */
43
86
  compileProject(options?: ProjectCompilerOptions): Promise<ProjectCompileResult>;
87
+ /** Type-check a single TypeScript source string inside the VM. */
44
88
  typecheckSource(options: SourceCompilerOptions): Promise<TypeCheckResult>;
89
+ /** Compile a single TypeScript source string, returning the emitted JS. */
45
90
  compileSource(options: SourceCompilerOptions): Promise<SourceCompileResult>;
46
- };
47
- export declare function createTypeScriptTools(options: TypeScriptToolsOptions): CompilerTools;
48
- export {};
91
+ }
92
+ /**
93
+ * Create a set of TypeScript tools whose compiler runs entirely inside the
94
+ * secure-exec sandbox. The compiler bundle is read from the host and projected
95
+ * into the VM filesystem; all compilation happens in-guest.
96
+ */
97
+ export declare function createTypeScriptTools(options?: TypeScriptToolsOptions): TypeScriptTools;
package/dist/index.js CHANGED
@@ -1,58 +1,85 @@
1
+ /**
2
+ * @secure-exec/typescript — run the TypeScript compiler inside the sandbox.
3
+ *
4
+ * The TypeScript compiler (`typescript.js`) is projected into the VM's virtual
5
+ * filesystem and the compile/type-check program is executed in-guest through
6
+ * the `secure-exec` `NodeRuntime`. The compiler never runs on the host: every
7
+ * `createSourceFile`/`createProgram`/`emit` call happens inside the kernel
8
+ * isolation boundary, over the VM's filesystem.
9
+ */
10
+ import { createRequire } from "node:module";
11
+ import { dirname } from "node:path";
1
12
  import { NodeRuntime } from "secure-exec";
2
- const DEFAULT_COMPILER_RUNTIME_MEMORY_LIMIT = 512;
3
- const COMPILER_RUNTIME_FILE_PATH = "/root/__secure_exec_typescript_compiler__.js";
4
- const DEFAULT_COMPILER_SPECIFIER = "/root/node_modules/typescript/lib/typescript.js";
5
- export function createTypeScriptTools(options) {
13
+ const DEFAULT_COMPILER_GUEST_DIR = "/root/node_modules/typescript";
14
+ function resolveCompilerPackageDir(explicit) {
15
+ if (explicit) {
16
+ return explicit;
17
+ }
18
+ const require = createRequire(import.meta.url);
19
+ // `lib/typescript.js` is the full compiler bundle; its grandparent is the
20
+ // `typescript` package directory (containing package.json + lib/).
21
+ return dirname(dirname(require.resolve("typescript/lib/typescript.js")));
22
+ }
23
+ /**
24
+ * Create a set of TypeScript tools whose compiler runs entirely inside the
25
+ * secure-exec sandbox. The compiler bundle is read from the host and projected
26
+ * into the VM filesystem; all compilation happens in-guest.
27
+ */
28
+ export function createTypeScriptTools(options = {}) {
29
+ const compilerPackageDir = resolveCompilerPackageDir(options.compilerPackageDir);
30
+ const compilerGuestDir = options.compilerGuestDir ?? DEFAULT_COMPILER_GUEST_DIR;
31
+ const compilerGuestPath = `${compilerGuestDir}/lib/typescript.js`;
32
+ const compilerMount = {
33
+ guestPath: compilerGuestDir,
34
+ hostPath: compilerPackageDir,
35
+ readOnly: true,
36
+ };
37
+ const run = (request) => runCompilerRequest(request, compilerGuestPath, options, compilerMount);
6
38
  return {
7
- typecheckProject: async (requestOptions = {}) => runCompilerRequest(options, {
39
+ typecheckProject: (requestOptions = {}) => run({
8
40
  kind: "typecheckProject",
9
- compilerSpecifier: options.compilerSpecifier ?? DEFAULT_COMPILER_SPECIFIER,
10
41
  options: requestOptions,
11
42
  }),
12
- compileProject: async (requestOptions = {}) => runCompilerRequest(options, {
43
+ compileProject: (requestOptions = {}) => run({
13
44
  kind: "compileProject",
14
- compilerSpecifier: options.compilerSpecifier ?? DEFAULT_COMPILER_SPECIFIER,
15
45
  options: requestOptions,
16
46
  }),
17
- typecheckSource: async (requestOptions) => runCompilerRequest(options, {
18
- kind: "typecheckSource",
19
- compilerSpecifier: options.compilerSpecifier ?? DEFAULT_COMPILER_SPECIFIER,
20
- options: requestOptions,
21
- }),
22
- compileSource: async (requestOptions) => runCompilerRequest(options, {
47
+ typecheckSource: (requestOptions) => run({ kind: "typecheckSource", options: requestOptions }),
48
+ compileSource: (requestOptions) => run({
23
49
  kind: "compileSource",
24
- compilerSpecifier: options.compilerSpecifier ?? DEFAULT_COMPILER_SPECIFIER,
25
50
  options: requestOptions,
26
51
  }),
27
52
  };
28
53
  }
29
- async function runCompilerRequest(options, request) {
30
- const runtime = new NodeRuntime({
31
- systemDriver: options.systemDriver,
32
- runtimeDriverFactory: options.runtimeDriverFactory,
33
- memoryLimit: options.memoryLimit ?? DEFAULT_COMPILER_RUNTIME_MEMORY_LIMIT,
34
- cpuTimeLimitMs: options.cpuTimeLimitMs,
35
- });
54
+ async function runCompilerRequest(request, compilerGuestPath, toolsOptions, compilerMount) {
55
+ const createOptions = {
56
+ files: toolsOptions.files,
57
+ mounts: [compilerMount, ...(toolsOptions.mounts ?? [])],
58
+ permissions: toolsOptions.permissions,
59
+ env: toolsOptions.env,
60
+ };
61
+ const rt = await NodeRuntime.create(createOptions);
36
62
  try {
37
- const result = await runtime.run(buildCompilerRuntimeSource(request), COMPILER_RUNTIME_FILE_PATH);
38
- if (result.code === 0 && result.exports) {
39
- return result.exports;
63
+ const guestSource = buildCompilerGuestSource(request, compilerGuestPath);
64
+ const result = await rt.run(guestSource);
65
+ if (result.exitCode === 0 && result.value !== undefined) {
66
+ return result.value;
40
67
  }
41
- return createFailureResult(request.kind, result.errorMessage);
68
+ return createFailureResult(request.kind, result.stderr.trim() || `compiler exited with code ${result.exitCode}`);
42
69
  }
43
70
  catch (error) {
44
71
  const message = error instanceof Error ? error.message : String(error);
45
72
  return createFailureResult(request.kind, message);
46
73
  }
47
74
  finally {
48
- runtime.dispose();
75
+ await rt.dispose();
49
76
  }
50
77
  }
51
78
  function createFailureResult(kind, errorMessage) {
52
79
  const diagnostic = {
53
80
  code: 0,
54
81
  category: "error",
55
- message: normalizeCompilerFailureMessage(errorMessage),
82
+ message: errorMessage || "TypeScript compiler failed",
56
83
  };
57
84
  if (kind === "compileProject") {
58
85
  return {
@@ -62,57 +89,33 @@ function createFailureResult(kind, errorMessage) {
62
89
  emittedFiles: [],
63
90
  };
64
91
  }
65
- if (kind === "compileSource") {
66
- return {
67
- success: false,
68
- diagnostics: [diagnostic],
69
- };
70
- }
71
- return {
72
- success: false,
73
- diagnostics: [diagnostic],
74
- };
75
- }
76
- function normalizeCompilerFailureMessage(errorMessage) {
77
- const message = (errorMessage ?? "TypeScript compiler failed").trim();
78
- if (/memory limit/i.test(message)) {
79
- return "TypeScript compiler exceeded sandbox memory limit";
80
- }
81
- if (/cpu time limit exceeded|timed out/i.test(message)) {
82
- return "TypeScript compiler exceeded sandbox CPU time limit";
83
- }
84
- return message;
92
+ return { success: false, diagnostics: [diagnostic] };
85
93
  }
86
- function buildCompilerRuntimeSource(request) {
87
- return `module.exports = (${compilerRuntimeMain.toString()})(${JSON.stringify(request)});`;
94
+ /**
95
+ * Build the guest ES module that loads the projected compiler and runs the
96
+ * requested compile/type-check entirely inside the VM, then hands the result
97
+ * back to the host via `__return`.
98
+ */
99
+ function buildCompilerGuestSource(request, compilerGuestPath) {
100
+ return [
101
+ `import { createRequire } from "node:module";`,
102
+ `import fs from "node:fs";`,
103
+ `import path from "node:path";`,
104
+ `const require = createRequire(${JSON.stringify(compilerGuestPath)});`,
105
+ `const ts = require(${JSON.stringify(compilerGuestPath)});`,
106
+ `const request = ${JSON.stringify(request)};`,
107
+ `const result = (${compilerGuestMain.toString()})(ts, fs, path, request);`,
108
+ `globalThis.__return(result);`,
109
+ ].join("\n");
88
110
  }
89
- function compilerRuntimeMain(request) {
90
- const fs = require("node:fs");
91
- const path = require("node:path");
92
- const ts = loadCompiler(request.compilerSpecifier);
93
- function loadCompiler(compilerSpecifier) {
94
- const candidates = new Set([compilerSpecifier]);
95
- if (compilerSpecifier === "typescript") {
96
- candidates.add("/root/node_modules/typescript/lib/typescript.js");
97
- }
98
- if (compilerSpecifier === "/root/node_modules/typescript/lib/typescript.js") {
99
- candidates.add("typescript");
100
- }
101
- let lastError;
102
- for (const candidate of candidates) {
103
- try {
104
- return require(candidate);
105
- }
106
- catch (error) {
107
- lastError = error;
108
- }
109
- }
110
- throw lastError instanceof Error
111
- ? lastError
112
- : new Error(`Cannot load TypeScript compiler from '${compilerSpecifier}'`);
113
- }
111
+ // NOTE: This function is serialized with `.toString()` and executed INSIDE the
112
+ // VM. It must be self-contained: it may only reference its parameters and the
113
+ // in-guest globals. Do not capture host-side variables.
114
+ function compilerGuestMain(ts, fs, path, request) {
114
115
  function toDiagnostic(diagnostic) {
115
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n").trim();
116
+ const message = ts
117
+ .flattenDiagnosticMessageText(diagnostic.messageText, "\n")
118
+ .trim();
116
119
  const result = {
117
120
  code: diagnostic.code,
118
121
  category: toDiagnosticCategory(diagnostic.category),
@@ -135,7 +138,6 @@ function compilerRuntimeMain(request) {
135
138
  return "suggestion";
136
139
  case ts.DiagnosticCategory.Message:
137
140
  return "message";
138
- case ts.DiagnosticCategory.Error:
139
141
  default:
140
142
  return "error";
141
143
  }
@@ -165,16 +167,10 @@ function compilerRuntimeMain(request) {
165
167
  }
166
168
  const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);
167
169
  if (configFile.error) {
168
- return {
169
- parsed: null,
170
- diagnostics: [toDiagnostic(configFile.error)],
171
- };
170
+ return { parsed: null, diagnostics: [toDiagnostic(configFile.error)] };
172
171
  }
173
172
  const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configFilePath), overrideCompilerOptions, configFilePath);
174
- return {
175
- parsed,
176
- diagnostics: parsed.errors.map(toDiagnostic),
177
- };
173
+ return { parsed, diagnostics: parsed.errors.map(toDiagnostic) };
178
174
  }
179
175
  function createSourceProgram(options, overrideCompilerOptions = {}) {
180
176
  const cwd = path.resolve(options.cwd ?? "/root");
@@ -186,51 +182,32 @@ function compilerRuntimeMain(request) {
186
182
  return {
187
183
  filePath,
188
184
  program: null,
189
- host: null,
190
185
  diagnostics: projectCompilerOptions.diagnostics,
191
186
  };
192
187
  }
193
188
  const compilerOptions = {
194
189
  target: ts.ScriptTarget.ES2022,
195
- module: ts.ModuleKind.CommonJS,
190
+ module: ts.ModuleKind.ESNext,
196
191
  ...projectCompilerOptions.parsed?.options,
197
192
  ...convertCompilerOptions(options.compilerOptions, cwd),
198
193
  ...overrideCompilerOptions,
199
194
  };
200
195
  const host = ts.createCompilerHost(compilerOptions);
201
- const normalizedFilePath = ts.sys.useCaseSensitiveFileNames
202
- ? filePath
203
- : filePath.toLowerCase();
196
+ const normalize = (candidate) => ts.sys.useCaseSensitiveFileNames ? candidate : candidate.toLowerCase();
197
+ const normalizedFilePath = normalize(filePath);
204
198
  const defaultGetSourceFile = host.getSourceFile.bind(host);
205
199
  const defaultReadFile = host.readFile.bind(host);
206
200
  const defaultFileExists = host.fileExists.bind(host);
207
- host.fileExists = (candidatePath) => {
208
- const normalizedCandidate = ts.sys.useCaseSensitiveFileNames
209
- ? candidatePath
210
- : candidatePath.toLowerCase();
211
- return normalizedCandidate === normalizedFilePath || defaultFileExists(candidatePath);
212
- };
213
- host.readFile = (candidatePath) => {
214
- const normalizedCandidate = ts.sys.useCaseSensitiveFileNames
215
- ? candidatePath
216
- : candidatePath.toLowerCase();
217
- if (normalizedCandidate === normalizedFilePath) {
218
- return options.sourceText;
219
- }
220
- return defaultReadFile(candidatePath);
221
- };
222
- host.getSourceFile = (candidatePath, languageVersion, onError, shouldCreateNewSourceFile) => {
223
- const normalizedCandidate = ts.sys.useCaseSensitiveFileNames
224
- ? candidatePath
225
- : candidatePath.toLowerCase();
226
- if (normalizedCandidate === normalizedFilePath) {
227
- return ts.createSourceFile(candidatePath, options.sourceText, languageVersion, true);
228
- }
229
- return defaultGetSourceFile(candidatePath, languageVersion, onError, shouldCreateNewSourceFile);
230
- };
201
+ host.fileExists = (candidate) => normalize(candidate) === normalizedFilePath ||
202
+ defaultFileExists(candidate);
203
+ host.readFile = (candidate) => normalize(candidate) === normalizedFilePath
204
+ ? options.sourceText
205
+ : defaultReadFile(candidate);
206
+ host.getSourceFile = (candidate, languageVersion, onError, shouldCreate) => normalize(candidate) === normalizedFilePath
207
+ ? ts.createSourceFile(candidate, options.sourceText, languageVersion, true)
208
+ : defaultGetSourceFile(candidate, languageVersion, onError, shouldCreate);
231
209
  return {
232
210
  filePath,
233
- host,
234
211
  program: ts.createProgram([filePath], compilerOptions, host),
235
212
  diagnostics: [],
236
213
  };
@@ -241,26 +218,20 @@ function compilerRuntimeMain(request) {
241
218
  noEmit: true,
242
219
  });
243
220
  if (!parsed) {
244
- return {
245
- success: false,
246
- diagnostics,
247
- };
221
+ return { success: false, diagnostics };
248
222
  }
249
223
  const program = ts.createProgram({
250
224
  rootNames: parsed.fileNames,
251
225
  options: parsed.options,
252
226
  projectReferences: parsed.projectReferences,
253
227
  });
254
- const combinedDiagnostics = ts
228
+ const combined = ts
255
229
  .sortAndDeduplicateDiagnostics([
256
230
  ...parsed.errors,
257
231
  ...ts.getPreEmitDiagnostics(program),
258
232
  ])
259
233
  .map(toDiagnostic);
260
- return {
261
- success: !hasErrors(combinedDiagnostics),
262
- diagnostics: combinedDiagnostics,
263
- };
234
+ return { success: !hasErrors(combined), diagnostics: combined };
264
235
  }
265
236
  case "compileProject": {
266
237
  const { parsed, diagnostics } = resolveProjectConfig(request.options);
@@ -283,7 +254,7 @@ function compilerRuntimeMain(request) {
283
254
  fs.writeFileSync(fileName, text, "utf8");
284
255
  emittedFiles.push(fileName.replace(/\\/g, "/"));
285
256
  });
286
- const combinedDiagnostics = ts
257
+ const combined = ts
287
258
  .sortAndDeduplicateDiagnostics([
288
259
  ...parsed.errors,
289
260
  ...ts.getPreEmitDiagnostics(program),
@@ -291,8 +262,8 @@ function compilerRuntimeMain(request) {
291
262
  ])
292
263
  .map(toDiagnostic);
293
264
  return {
294
- success: !hasErrors(combinedDiagnostics),
295
- diagnostics: combinedDiagnostics,
265
+ success: !hasErrors(combined),
266
+ diagnostics: combined,
296
267
  emitSkipped: emitResult.emitSkipped,
297
268
  emittedFiles,
298
269
  };
@@ -302,26 +273,17 @@ function compilerRuntimeMain(request) {
302
273
  noEmit: true,
303
274
  });
304
275
  if (!program) {
305
- return {
306
- success: false,
307
- diagnostics,
308
- };
276
+ return { success: false, diagnostics };
309
277
  }
310
- const combinedDiagnostics = ts
278
+ const combined = ts
311
279
  .sortAndDeduplicateDiagnostics(ts.getPreEmitDiagnostics(program))
312
280
  .map(toDiagnostic);
313
- return {
314
- success: !hasErrors(combinedDiagnostics),
315
- diagnostics: combinedDiagnostics,
316
- };
281
+ return { success: !hasErrors(combined), diagnostics: combined };
317
282
  }
318
283
  case "compileSource": {
319
284
  const { program, diagnostics } = createSourceProgram(request.options);
320
285
  if (!program) {
321
- return {
322
- success: false,
323
- diagnostics,
324
- };
286
+ return { success: false, diagnostics };
325
287
  }
326
288
  let outputText;
327
289
  let sourceMapText;
@@ -330,21 +292,20 @@ function compilerRuntimeMain(request) {
330
292
  fileName.endsWith(".mjs") ||
331
293
  fileName.endsWith(".cjs")) {
332
294
  outputText = text;
333
- return;
334
295
  }
335
- if (fileName.endsWith(".map")) {
296
+ else if (fileName.endsWith(".map")) {
336
297
  sourceMapText = text;
337
298
  }
338
299
  });
339
- const combinedDiagnostics = ts
300
+ const combined = ts
340
301
  .sortAndDeduplicateDiagnostics([
341
302
  ...ts.getPreEmitDiagnostics(program),
342
303
  ...emitResult.diagnostics,
343
304
  ])
344
305
  .map(toDiagnostic);
345
306
  return {
346
- success: !hasErrors(combinedDiagnostics),
347
- diagnostics: combinedDiagnostics,
307
+ success: !hasErrors(combined),
308
+ diagnostics: combined,
348
309
  outputText,
349
310
  sourceMapText,
350
311
  };
package/package.json CHANGED
@@ -1,37 +1,36 @@
1
1
  {
2
- "name": "@secure-exec/typescript",
3
- "version": "0.2.1-rc.1",
4
- "type": "module",
5
- "license": "Apache-2.0",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "files": [
9
- "dist",
10
- "README.md"
11
- ],
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/rivet-dev/secure-exec.git",
15
- "directory": "packages/typescript"
16
- },
17
- "exports": {
18
- ".": {
19
- "import": "./dist/index.js",
20
- "types": "./dist/index.d.ts"
21
- }
22
- },
23
- "dependencies": {
24
- "typescript": "^5.9.3",
25
- "@secure-exec/core": "0.2.1-rc.1",
26
- "secure-exec": "0.2.1-rc.1"
27
- },
28
- "devDependencies": {
29
- "@types/node": "^22.10.2",
30
- "vitest": "^2.1.8"
31
- },
32
- "scripts": {
33
- "check-types": "tsc --noEmit",
34
- "build": "tsc",
35
- "test": "vitest run"
36
- }
37
- }
2
+ "name": "@secure-exec/typescript",
3
+ "version": "0.3.0-rc.2",
4
+ "type": "module",
5
+ "license": "Apache-2.0",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/rivet-dev/secure-exec.git",
15
+ "directory": "packages/typescript"
16
+ },
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "default": "./dist/index.js"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "build": "tsc",
26
+ "check-types": "tsc --noEmit"
27
+ },
28
+ "dependencies": {
29
+ "@secure-exec/core": "0.3.0-rc.2",
30
+ "secure-exec": "0.3.0-rc.2",
31
+ "typescript": "^5.9.3"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^22.10.2"
35
+ }
36
+ }
package/LICENSE DELETED
@@ -1,191 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to the Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by the Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding any notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- Copyright 2025 Rivet Gaming, Inc.
180
-
181
- Licensed under the Apache License, Version 2.0 (the "License");
182
- you may not use this file except in compliance with the License.
183
- You may obtain a copy of the License at
184
-
185
- http://www.apache.org/licenses/LICENSE-2.0
186
-
187
- Unless required by applicable law or agreed to in writing, software
188
- distributed under the License is distributed on an "AS IS" BASIS,
189
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
- See the License for the specific language governing permissions and
191
- limitations under the License.