@ricsam/quickjs-test-utils 1.0.19 → 1.0.20

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.
@@ -43,6 +43,7 @@ __export(exports_src, {
43
43
  createTestContext: () => import_context.createTestContext,
44
44
  createFetchTestContext: () => import_fetch_context.createFetchTestContext,
45
45
  TYPE_DEFINITIONS: () => import_quickjs_types.TYPE_DEFINITIONS,
46
+ PATH_TYPES: () => import_quickjs_types.PATH_TYPES,
46
47
  FS_TYPES: () => import_quickjs_types.FS_TYPES,
47
48
  FETCH_TYPES: () => import_quickjs_types.FETCH_TYPES,
48
49
  CORE_TYPES: () => import_quickjs_types.CORE_TYPES
@@ -57,4 +58,4 @@ var import_typecheck = require("./typecheck.cjs");
57
58
  var import_quickjs_types = require("./quickjs-types.cjs");
58
59
  })
59
60
 
60
- //# debugId=2D2B04FA8DA88D0664756E2164756E21
61
+ //# debugId=BC70EFE2C1DA478164756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": [
5
- "export {\n createTestContext,\n disposeTestContext,\n useTestContext,\n type TestContext,\n} from \"./context.cjs\";\n\nexport {\n createFetchTestContext,\n disposeFetchTestContext,\n useFetchTestContext,\n type FetchTestContext,\n type CreateFetchTestContextOptions,\n} from \"./fetch-context.cjs\";\n\nexport { evalCode, evalCodeAsync } from \"./eval.cjs\";\n\nexport {\n runTestCode,\n type TestRuntime,\n type TestRunner,\n} from \"./native-input-test.cjs\";\n\nexport {\n startIntegrationServer,\n type IntegrationTestServer,\n type StartIntegrationServerOptions,\n} from \"./integration-server.cjs\";\n\nexport {\n typecheckQuickJSCode,\n formatTypecheckErrors,\n type TypecheckResult,\n type TypecheckError,\n type TypecheckOptions,\n type LibraryTypes,\n type LibraryTypeFile,\n} from \"./typecheck.cjs\";\n\nexport {\n CORE_TYPES,\n FETCH_TYPES,\n FS_TYPES,\n TYPE_DEFINITIONS,\n type TypeDefinitionKey,\n} from \"./quickjs-types.cjs\";\n\n// For fs and runtime contexts, import from subpaths:\n// import { createFsTestContext } from \"@ricsam/quickjs-test-utils/fs\";\n// import { createRuntimeTestContext } from \"@ricsam/quickjs-test-utils/runtime\";\n"
5
+ "export {\n createTestContext,\n disposeTestContext,\n useTestContext,\n type TestContext,\n} from \"./context.cjs\";\n\nexport {\n createFetchTestContext,\n disposeFetchTestContext,\n useFetchTestContext,\n type FetchTestContext,\n type CreateFetchTestContextOptions,\n} from \"./fetch-context.cjs\";\n\nexport { evalCode, evalCodeAsync } from \"./eval.cjs\";\n\nexport {\n runTestCode,\n type TestRuntime,\n type TestRunner,\n} from \"./native-input-test.cjs\";\n\nexport {\n startIntegrationServer,\n type IntegrationTestServer,\n type StartIntegrationServerOptions,\n} from \"./integration-server.cjs\";\n\nexport {\n typecheckQuickJSCode,\n formatTypecheckErrors,\n type TypecheckResult,\n type TypecheckError,\n type TypecheckOptions,\n type LibraryTypes,\n type LibraryTypeFile,\n} from \"./typecheck.cjs\";\n\nexport {\n CORE_TYPES,\n FETCH_TYPES,\n FS_TYPES,\n PATH_TYPES,\n TYPE_DEFINITIONS,\n type TypeDefinitionKey,\n} from \"./quickjs-types.cjs\";\n\n// For fs and runtime contexts, import from subpaths:\n// import { createFsTestContext } from \"@ricsam/quickjs-test-utils/fs\";\n// import { createRuntimeTestContext } from \"@ricsam/quickjs-test-utils/runtime\";\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,IALP;AAaO,IANP;AAQwC,IAAxC;AAMO,IAJP;AAUO,IAJP;AAcO,IARP;AAgBO,IANP;",
8
- "debugId": "2D2B04FA8DA88D0664756E2164756E21",
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,IALP;AAaO,IANP;AAQwC,IAAxC;AAMO,IAJP;AAUO,IAJP;AAcO,IARP;AAiBO,IAPP;",
8
+ "debugId": "BC70EFE2C1DA478164756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(exports_integration_server);
36
36
  var import_quickjs_emscripten = require("quickjs-emscripten");
37
37
  var import_quickjs_fetch = require("@ricsam/quickjs-fetch");
38
38
  var import_quickjs_core = require("@ricsam/quickjs-core");
39
+ var import_quickjs_fs = require("@ricsam/quickjs-fs");
39
40
  var import_quickjs_console = require("@ricsam/quickjs-console");
40
41
  async function startIntegrationServer(quickJSCode, options) {
41
42
  const QuickJS = await import_quickjs_emscripten.getQuickJS();
@@ -47,6 +48,7 @@ async function startIntegrationServer(quickJSCode, options) {
47
48
  onFetch: options?.onFetch
48
49
  });
49
50
  const consoleHandle = options?.consoleHandlers ? import_quickjs_console.setupConsole(context, { handlers: options.consoleHandlers, coreHandle }) : undefined;
51
+ const fsHandle = options?.fs ? import_quickjs_fs.setupFs(context, { coreHandle, getDirectory: options.fs.getDirectory }) : undefined;
50
52
  const wsConnections = new Map;
51
53
  fetchHandle.onWebSocketCommand((cmd) => {
52
54
  const ws = wsConnections.get(cmd.connectionId);
@@ -121,6 +123,7 @@ async function startIntegrationServer(quickJSCode, options) {
121
123
  runtime,
122
124
  coreHandle,
123
125
  consoleHandle,
126
+ fsHandle,
124
127
  async stop() {
125
128
  for (const ws of wsConnections.values()) {
126
129
  ws.close(1000, "Server stopping");
@@ -128,6 +131,7 @@ async function startIntegrationServer(quickJSCode, options) {
128
131
  wsConnections.clear();
129
132
  server.stop(true);
130
133
  fetchHandle.dispose();
134
+ fsHandle?.dispose();
131
135
  consoleHandle?.dispose();
132
136
  coreHandle.dispose();
133
137
  context.dispose();
@@ -137,4 +141,4 @@ async function startIntegrationServer(quickJSCode, options) {
137
141
  }
138
142
  })
139
143
 
140
- //# debugId=815B5672C4B716AE64756E2164756E21
144
+ //# debugId=1371FDAEA518718564756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/integration-server.ts"],
4
4
  "sourcesContent": [
5
- "import { getQuickJS, type QuickJSContext, type QuickJSRuntime } from \"quickjs-emscripten\";\nimport { setupFetch, type FetchHandle, type WebSocketCommand, type SetupFetchOptions } from \"@ricsam/quickjs-fetch\";\nimport { setupCore, type CoreHandle } from \"@ricsam/quickjs-core\";\nimport type { Server, ServerWebSocket } from \"bun\";\nimport { setupConsole, type ConsoleOutputHandler, type ConsoleHandle } from \"@ricsam/quickjs-console\";\n\ninterface WsData {\n connectionId: string;\n}\n\nexport interface IntegrationTestServer {\n baseURL: string;\n wsURL: string;\n port: number;\n fetchHandle: FetchHandle;\n context: QuickJSContext;\n runtime: QuickJSRuntime;\n coreHandle: CoreHandle;\n consoleHandle?: ConsoleHandle;\n stop(): Promise<void>;\n}\n\nexport interface StartIntegrationServerOptions {\n /** Handler for outbound fetch() calls from QuickJS */\n onFetch?: SetupFetchOptions[\"onFetch\"];\n /** Handlers for console output from QuickJS */\n consoleHandlers?: ConsoleOutputHandler;\n}\n\n/**\n * Start a real HTTP server that dispatches requests to a QuickJS serve() handler.\n *\n * @param quickJSCode - JavaScript code to run in QuickJS, should call serve()\n * @param options - Optional configuration\n * @returns Server info including baseURL, wsURL, and stop function\n *\n * @example\n * const server = await startIntegrationServer(`\n * serve({\n * fetch(request) {\n * return new Response(\"Hello!\");\n * }\n * });\n * `);\n *\n * const response = await fetch(\\`\\${server.baseURL}/test\\`);\n * expect(await response.text()).toBe(\"Hello!\");\n *\n * await server.stop();\n */\nexport async function startIntegrationServer(\n quickJSCode: string,\n options?: StartIntegrationServerOptions\n): Promise<IntegrationTestServer> {\n const QuickJS = await getQuickJS();\n const runtime = QuickJS.newRuntime();\n const context = runtime.newContext();\n\n // Setup core and fetch APIs\n const coreHandle = setupCore(context);\n const fetchHandle = setupFetch(context, {\n coreHandle,\n onFetch: options?.onFetch,\n });\n\n // Setup console if handlers provided\n const consoleHandle = options?.consoleHandlers\n ? setupConsole(context, { handlers: options.consoleHandlers, coreHandle })\n : undefined;\n\n // Track WebSocket connections\n const wsConnections = new Map<string, ServerWebSocket<WsData>>();\n\n // Handle outgoing WebSocket commands from QuickJS\n fetchHandle.onWebSocketCommand((cmd: WebSocketCommand) => {\n const ws = wsConnections.get(cmd.connectionId);\n if (!ws) return;\n\n if (cmd.type === \"message\") {\n ws.send(cmd.data);\n } else if (cmd.type === \"close\") {\n ws.close(cmd.code, cmd.reason);\n }\n });\n\n // Run the user's QuickJS code\n const result = context.evalCode(quickJSCode);\n if (result.error) {\n const error = context.dump(result.error);\n result.error.dispose();\n fetchHandle.dispose();\n coreHandle.dispose();\n context.dispose();\n runtime.dispose();\n throw new Error(`Failed to evaluate QuickJS code: ${JSON.stringify(error)}`);\n }\n result.value.dispose();\n\n // Start Bun server with port 0 for dynamic assignment\n const server: Server<WsData> = Bun.serve<WsData>({\n port: 0,\n async fetch(req, server) {\n try {\n // Dispatch to QuickJS handler\n const response = await fetchHandle.dispatchRequest(req);\n\n // Check if QuickJS requested a WebSocket upgrade\n const upgrade = fetchHandle.getUpgradeRequest();\n if (upgrade?.requested) {\n // The connectionId is generated by QuickJS in server.upgrade()\n // User data is stored in QuickJS registry - we just pass the connectionId\n const success = server.upgrade(req, {\n data: { connectionId: upgrade.connectionId },\n });\n if (success) {\n return undefined;\n }\n return new Response(\"WebSocket upgrade failed\", { status: 500 });\n }\n\n return response;\n } catch (error) {\n console.error(\"Integration test request failed:\", error);\n return new Response(\"Internal Server Error\", { status: 500 });\n }\n },\n websocket: {\n open(ws) {\n const { connectionId } = ws.data;\n wsConnections.set(connectionId, ws);\n // User data is looked up from QuickJS registry using connectionId\n fetchHandle.dispatchWebSocketOpen(connectionId);\n },\n message(ws, message) {\n const msg = typeof message === \"string\" ? message : message.buffer;\n fetchHandle.dispatchWebSocketMessage(ws.data.connectionId, msg as string | ArrayBuffer);\n },\n close(ws, code, reason) {\n fetchHandle.dispatchWebSocketClose(ws.data.connectionId, code, reason);\n wsConnections.delete(ws.data.connectionId);\n },\n },\n });\n\n const port = server.port;\n if (port === undefined) {\n throw new Error(\"Server failed to get port\");\n }\n const baseURL = `http://localhost:${port}`;\n const wsURL = `ws://localhost:${port}`;\n\n return {\n baseURL,\n wsURL,\n port,\n fetchHandle,\n context,\n runtime,\n coreHandle,\n consoleHandle,\n async stop() {\n // Close all WebSocket connections\n for (const ws of wsConnections.values()) {\n ws.close(1000, \"Server stopping\");\n }\n wsConnections.clear();\n\n // Stop the server\n server.stop(true);\n\n // Dispose QuickJS resources\n fetchHandle.dispose();\n consoleHandle?.dispose();\n coreHandle.dispose();\n context.dispose();\n runtime.dispose();\n },\n };\n}\n"
5
+ "import { getQuickJS, type QuickJSContext, type QuickJSRuntime } from \"quickjs-emscripten\";\nimport { setupFetch, type FetchHandle, type WebSocketCommand, type SetupFetchOptions } from \"@ricsam/quickjs-fetch\";\nimport { setupCore, type CoreHandle } from \"@ricsam/quickjs-core\";\nimport { setupFs, type FsHandle, type HostDirectoryHandle } from \"@ricsam/quickjs-fs\";\nimport type { Server, ServerWebSocket } from \"bun\";\nimport { setupConsole, type ConsoleOutputHandler, type ConsoleHandle } from \"@ricsam/quickjs-console\";\n\ninterface WsData {\n connectionId: string;\n}\n\nexport interface IntegrationTestServer {\n baseURL: string;\n wsURL: string;\n port: number;\n fetchHandle: FetchHandle;\n context: QuickJSContext;\n runtime: QuickJSRuntime;\n coreHandle: CoreHandle;\n consoleHandle?: ConsoleHandle;\n fsHandle?: FsHandle;\n stop(): Promise<void>;\n}\n\nexport interface StartIntegrationServerOptions {\n /** Handler for outbound fetch() calls from QuickJS */\n onFetch?: SetupFetchOptions[\"onFetch\"];\n /** Handlers for console output from QuickJS */\n consoleHandlers?: ConsoleOutputHandler;\n /** File system configuration for QuickJS */\n fs?: {\n /** Returns a directory handle for the given path */\n getDirectory: (path: string) => Promise<HostDirectoryHandle>;\n };\n}\n\n/**\n * Start a real HTTP server that dispatches requests to a QuickJS serve() handler.\n *\n * @param quickJSCode - JavaScript code to run in QuickJS, should call serve()\n * @param options - Optional configuration\n * @returns Server info including baseURL, wsURL, and stop function\n *\n * @example\n * const server = await startIntegrationServer(`\n * serve({\n * fetch(request) {\n * return new Response(\"Hello!\");\n * }\n * });\n * `);\n *\n * const response = await fetch(\\`\\${server.baseURL}/test\\`);\n * expect(await response.text()).toBe(\"Hello!\");\n *\n * await server.stop();\n */\nexport async function startIntegrationServer(\n quickJSCode: string,\n options?: StartIntegrationServerOptions\n): Promise<IntegrationTestServer> {\n const QuickJS = await getQuickJS();\n const runtime = QuickJS.newRuntime();\n const context = runtime.newContext();\n\n // Setup core and fetch APIs\n const coreHandle = setupCore(context);\n const fetchHandle = setupFetch(context, {\n coreHandle,\n onFetch: options?.onFetch,\n });\n\n // Setup console if handlers provided\n const consoleHandle = options?.consoleHandlers\n ? setupConsole(context, { handlers: options.consoleHandlers, coreHandle })\n : undefined;\n\n // Setup fs if configured\n const fsHandle = options?.fs\n ? setupFs(context, { coreHandle, getDirectory: options.fs.getDirectory })\n : undefined;\n\n // Track WebSocket connections\n const wsConnections = new Map<string, ServerWebSocket<WsData>>();\n\n // Handle outgoing WebSocket commands from QuickJS\n fetchHandle.onWebSocketCommand((cmd: WebSocketCommand) => {\n const ws = wsConnections.get(cmd.connectionId);\n if (!ws) return;\n\n if (cmd.type === \"message\") {\n ws.send(cmd.data);\n } else if (cmd.type === \"close\") {\n ws.close(cmd.code, cmd.reason);\n }\n });\n\n // Run the user's QuickJS code\n const result = context.evalCode(quickJSCode);\n if (result.error) {\n const error = context.dump(result.error);\n result.error.dispose();\n fetchHandle.dispose();\n coreHandle.dispose();\n context.dispose();\n runtime.dispose();\n throw new Error(`Failed to evaluate QuickJS code: ${JSON.stringify(error)}`);\n }\n result.value.dispose();\n\n // Start Bun server with port 0 for dynamic assignment\n const server: Server<WsData> = Bun.serve<WsData>({\n port: 0,\n async fetch(req, server) {\n try {\n // Dispatch to QuickJS handler\n const response = await fetchHandle.dispatchRequest(req);\n\n // Check if QuickJS requested a WebSocket upgrade\n const upgrade = fetchHandle.getUpgradeRequest();\n if (upgrade?.requested) {\n // The connectionId is generated by QuickJS in server.upgrade()\n // User data is stored in QuickJS registry - we just pass the connectionId\n const success = server.upgrade(req, {\n data: { connectionId: upgrade.connectionId },\n });\n if (success) {\n return undefined;\n }\n return new Response(\"WebSocket upgrade failed\", { status: 500 });\n }\n\n return response;\n } catch (error) {\n console.error(\"Integration test request failed:\", error);\n return new Response(\"Internal Server Error\", { status: 500 });\n }\n },\n websocket: {\n open(ws) {\n const { connectionId } = ws.data;\n wsConnections.set(connectionId, ws);\n // User data is looked up from QuickJS registry using connectionId\n fetchHandle.dispatchWebSocketOpen(connectionId);\n },\n message(ws, message) {\n const msg = typeof message === \"string\" ? message : message.buffer;\n fetchHandle.dispatchWebSocketMessage(ws.data.connectionId, msg as string | ArrayBuffer);\n },\n close(ws, code, reason) {\n fetchHandle.dispatchWebSocketClose(ws.data.connectionId, code, reason);\n wsConnections.delete(ws.data.connectionId);\n },\n },\n });\n\n const port = server.port;\n if (port === undefined) {\n throw new Error(\"Server failed to get port\");\n }\n const baseURL = `http://localhost:${port}`;\n const wsURL = `ws://localhost:${port}`;\n\n return {\n baseURL,\n wsURL,\n port,\n fetchHandle,\n context,\n runtime,\n coreHandle,\n consoleHandle,\n fsHandle,\n async stop() {\n // Close all WebSocket connections\n for (const ws of wsConnections.values()) {\n ws.close(1000, \"Server stopping\");\n }\n wsConnections.clear();\n\n // Stop the server\n server.stop(true);\n\n // Dispose QuickJS resources\n fetchHandle.dispose();\n fsHandle?.dispose();\n consoleHandle?.dispose();\n coreHandle.dispose();\n context.dispose();\n runtime.dispose();\n },\n };\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAqE,IAArE;AAC4F,IAA5F;AAC2C,IAA3C;AAE4E,IAA5E;AA8CA,eAAsB,sBAAsB,CAC1C,aACA,SACgC;AAAA,EAChC,MAAM,UAAU,MAAM,qCAA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WAAW,UAAU,QAAQ;AAAA,QAC5D,YAAY,yBAAyB,GAAG,KAAK,cAAc,GAA2B;AAAA;AAAA,MAExF,KAAK,CAAC,IAAI,MAAM,QAAQ;AAAA,QACtB,YAAY,uBAAuB,GAAG,KAAK,cAAc,MAAM,MAAM;AAAA,QACrE,cAAc,OAAO,GAAG,KAAK,YAAY;AAAA;AAAA,IAE7C;AAAA,EACF,CAAC;AAAA,EAED,MAAM,OAAO,OAAO;AAAA,EACpB,IAAI,SAAS,WAAW;AAAA,IACtB,MAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AAAA,EACA,MAAM,UAAU,oBAAoB;AAAA,EACpC,MAAM,QAAQ,kBAAkB;AAAA,EAEhC,OAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,SACM,KAAI,GAAG;AAAA,MAEX,WAAW,MAAM,cAAc,OAAO,GAAG;AAAA,QACvC,GAAG,MAAM,MAAM,iBAAiB;AAAA,MAClC;AAAA,MACA,cAAc,MAAM;AAAA,MAGpB,OAAO,KAAK,IAAI;AAAA,MAGhB,YAAY,QAAQ;AAAA,MACpB,UAAU,QAAQ;AAAA,MAClB,eAAe,QAAQ;AAAA,MACvB,WAAW,QAAQ;AAAA,MACnB,QAAQ,QAAQ;AAAA,MAChB,QAAQ,QAAQ;AAAA;AAAA,EAEpB;AAAA;",
8
+ "debugId": "1371FDAEA518718564756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-test-utils",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "type": "commonjs"
5
5
  }
@@ -33,6 +33,7 @@ __export(exports_quickjs_types, {
33
33
  TYPE_DEFINITIONS: () => TYPE_DEFINITIONS,
34
34
  TIMERS_TYPES: () => TIMERS_TYPES,
35
35
  TEST_ENV_TYPES: () => TEST_ENV_TYPES,
36
+ PATH_TYPES: () => PATH_TYPES,
36
37
  FS_TYPES: () => FS_TYPES,
37
38
  FETCH_TYPES: () => FETCH_TYPES,
38
39
  ENCODING_TYPES: () => ENCODING_TYPES,
@@ -1457,6 +1458,205 @@ declare global {
1457
1458
  const crypto: Crypto;
1458
1459
  }
1459
1460
  `;
1461
+ var PATH_TYPES = `/**
1462
+ * QuickJS Global Type Definitions for @ricsam/quickjs-path
1463
+ *
1464
+ * These types define the globals injected by setupPath() into a QuickJS context.
1465
+ * Use these types to typecheck user code that will run inside QuickJS.
1466
+ *
1467
+ * @example
1468
+ * // Typecheck QuickJS code with path operations
1469
+ * const joined = path.join('/foo', 'bar', 'baz');
1470
+ * const resolved = path.resolve('relative/path');
1471
+ * const cwd = path.cwd();
1472
+ */
1473
+
1474
+ export {};
1475
+
1476
+ declare global {
1477
+ /**
1478
+ * Parsed path object returned by path.parse().
1479
+ */
1480
+ interface ParsedPath {
1481
+ /** The root of the path (e.g., "/" for absolute paths, "" for relative) */
1482
+ root: string;
1483
+ /** The directory portion of the path */
1484
+ dir: string;
1485
+ /** The file name including extension */
1486
+ base: string;
1487
+ /** The file extension (e.g., ".txt") */
1488
+ ext: string;
1489
+ /** The file name without extension */
1490
+ name: string;
1491
+ }
1492
+
1493
+ /**
1494
+ * Input object for path.format().
1495
+ */
1496
+ interface FormatInputPathObject {
1497
+ root?: string;
1498
+ dir?: string;
1499
+ base?: string;
1500
+ ext?: string;
1501
+ name?: string;
1502
+ }
1503
+
1504
+ /**
1505
+ * Path utilities for POSIX paths.
1506
+ * @see https://nodejs.org/api/path.html
1507
+ */
1508
+ namespace path {
1509
+ /**
1510
+ * Join path segments with the platform-specific separator.
1511
+ *
1512
+ * @param paths - Path segments to join
1513
+ * @returns The joined path, normalized
1514
+ *
1515
+ * @example
1516
+ * path.join('/foo', 'bar', 'baz'); // "/foo/bar/baz"
1517
+ * path.join('foo', 'bar', '..', 'baz'); // "foo/baz"
1518
+ */
1519
+ function join(...paths: string[]): string;
1520
+
1521
+ /**
1522
+ * Normalize a path, resolving '..' and '.' segments.
1523
+ *
1524
+ * @param p - The path to normalize
1525
+ * @returns The normalized path
1526
+ *
1527
+ * @example
1528
+ * path.normalize('/foo/bar/../baz'); // "/foo/baz"
1529
+ * path.normalize('/foo//bar'); // "/foo/bar"
1530
+ */
1531
+ function normalize(p: string): string;
1532
+
1533
+ /**
1534
+ * Get the last portion of a path (the file name).
1535
+ *
1536
+ * @param p - The path
1537
+ * @param ext - Optional extension to remove from the result
1538
+ * @returns The base name of the path
1539
+ *
1540
+ * @example
1541
+ * path.basename('/foo/bar/baz.txt'); // "baz.txt"
1542
+ * path.basename('/foo/bar/baz.txt', '.txt'); // "baz"
1543
+ */
1544
+ function basename(p: string, ext?: string): string;
1545
+
1546
+ /**
1547
+ * Get the directory name of a path.
1548
+ *
1549
+ * @param p - The path
1550
+ * @returns The directory portion of the path
1551
+ *
1552
+ * @example
1553
+ * path.dirname('/foo/bar/baz.txt'); // "/foo/bar"
1554
+ * path.dirname('/foo'); // "/"
1555
+ */
1556
+ function dirname(p: string): string;
1557
+
1558
+ /**
1559
+ * Get the extension of a path.
1560
+ *
1561
+ * @param p - The path
1562
+ * @returns The extension including the dot, or empty string
1563
+ *
1564
+ * @example
1565
+ * path.extname('file.txt'); // ".txt"
1566
+ * path.extname('file.tar.gz'); // ".gz"
1567
+ * path.extname('.bashrc'); // ""
1568
+ */
1569
+ function extname(p: string): string;
1570
+
1571
+ /**
1572
+ * Check if a path is absolute.
1573
+ *
1574
+ * @param p - The path to check
1575
+ * @returns True if the path is absolute
1576
+ *
1577
+ * @example
1578
+ * path.isAbsolute('/foo/bar'); // true
1579
+ * path.isAbsolute('foo/bar'); // false
1580
+ */
1581
+ function isAbsolute(p: string): boolean;
1582
+
1583
+ /**
1584
+ * Parse a path into its components.
1585
+ *
1586
+ * @param p - The path to parse
1587
+ * @returns An object with root, dir, base, ext, and name properties
1588
+ *
1589
+ * @example
1590
+ * path.parse('/foo/bar/baz.txt');
1591
+ * // { root: "/", dir: "/foo/bar", base: "baz.txt", ext: ".txt", name: "baz" }
1592
+ */
1593
+ function parse(p: string): ParsedPath;
1594
+
1595
+ /**
1596
+ * Build a path from an object.
1597
+ *
1598
+ * @param pathObject - Object with path components
1599
+ * @returns The formatted path string
1600
+ *
1601
+ * @example
1602
+ * path.format({ dir: '/foo/bar', base: 'baz.txt' }); // "/foo/bar/baz.txt"
1603
+ * path.format({ root: '/', name: 'file', ext: '.txt' }); // "/file.txt"
1604
+ */
1605
+ function format(pathObject: FormatInputPathObject): string;
1606
+
1607
+ /**
1608
+ * Resolve a sequence of paths to an absolute path.
1609
+ * Processes paths from right to left, prepending each until an absolute path is formed.
1610
+ * Uses the configured working directory for relative paths.
1611
+ *
1612
+ * @param paths - Path segments to resolve
1613
+ * @returns The resolved absolute path
1614
+ *
1615
+ * @example
1616
+ * // With cwd set to "/home/user"
1617
+ * path.resolve('foo/bar'); // "/home/user/foo/bar"
1618
+ * path.resolve('/foo', 'bar'); // "/foo/bar"
1619
+ * path.resolve('/foo', '/bar', 'baz'); // "/bar/baz"
1620
+ */
1621
+ function resolve(...paths: string[]): string;
1622
+
1623
+ /**
1624
+ * Compute the relative path from one path to another.
1625
+ *
1626
+ * @param from - The source path
1627
+ * @param to - The destination path
1628
+ * @returns The relative path from 'from' to 'to'
1629
+ *
1630
+ * @example
1631
+ * path.relative('/foo/bar', '/foo/baz'); // "../baz"
1632
+ * path.relative('/foo', '/foo/bar/baz'); // "bar/baz"
1633
+ */
1634
+ function relative(from: string, to: string): string;
1635
+
1636
+ /**
1637
+ * Get the configured working directory.
1638
+ *
1639
+ * @returns The current working directory
1640
+ *
1641
+ * @example
1642
+ * path.cwd(); // "/home/user" (or whatever was configured)
1643
+ */
1644
+ function cwd(): string;
1645
+
1646
+ /**
1647
+ * The platform-specific path segment separator.
1648
+ * Always "/" for POSIX paths.
1649
+ */
1650
+ const sep: string;
1651
+
1652
+ /**
1653
+ * The platform-specific path delimiter.
1654
+ * Always ":" for POSIX paths.
1655
+ */
1656
+ const delimiter: string;
1657
+ }
1658
+ }
1659
+ `;
1460
1660
  var TIMERS_TYPES = `/**
1461
1661
  * QuickJS Global Type Definitions for @ricsam/quickjs-timers
1462
1662
  *
@@ -1545,9 +1745,10 @@ var TYPE_DEFINITIONS = {
1545
1745
  encoding: ENCODING_TYPES,
1546
1746
  fetch: FETCH_TYPES,
1547
1747
  fs: FS_TYPES,
1748
+ path: PATH_TYPES,
1548
1749
  testEnvironment: TEST_ENV_TYPES,
1549
1750
  timers: TIMERS_TYPES
1550
1751
  };
1551
1752
  })
1552
1753
 
1553
- //# debugId=0BC014EC5A81951964756E2164756E21
1754
+ //# debugId=2521770EC7AD006C64756E2164756E21