@warlock.js/core 4.1.4 → 4.1.5

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.
@@ -26,7 +26,7 @@ import { Worker } from "worker_threads";
26
26
  */
27
27
  function createWorker(workerPath, baseUrl, options) {
28
28
  const isDevServerCore = env("DEV_SERVER_CORE");
29
- const workerFilePath = fileURLToPath(new URL(`${workerPath}${isDevServerCore ? ".ts" : ".js"}`, baseUrl));
29
+ const workerFilePath = fileURLToPath(new URL(`${workerPath}${isDevServerCore ? ".ts" : ".mjs"}`, baseUrl));
30
30
  const workerOptions = { ...options };
31
31
  if (isDevServerCore) workerOptions.execArgv = [
32
32
  ...options?.execArgv || [],
@@ -1 +1 @@
1
- {"version":3,"file":"create-worker.mjs","names":[],"sources":["../../../../../../@warlock.js/core/src/dev-server/create-worker.ts"],"sourcesContent":["import { env } from \"@mongez/dotenv\";\nimport { fileURLToPath } from \"url\";\nimport { Worker, type WorkerOptions } from \"worker_threads\";\n\n/**\n * Options for creating a health check worker\n */\nexport type CreateWorkerOptions = WorkerOptions & {\n /**\n * Worker data to pass to the worker thread\n */\n workerData?: Record<string, unknown>;\n};\n\n/**\n * Create a worker that works in both dev (TypeScript) and production (JavaScript) environments.\n *\n * In development mode (DEV_SERVER_CORE env set), workers are loaded with tsx\n * to support TypeScript execution. In production, compiled .js files are used.\n *\n * @param workerPath - Relative path to worker file WITHOUT extension (e.g., \"./workers/ts-health.worker\")\n * @param baseUrl - The import.meta.url of the calling module (used to resolve relative paths)\n * @param options - Additional worker options\n * @returns A new Worker instance\n *\n * @example\n * ```typescript\n * // In FilesHealthcareManager\n * const worker = createWorker(\n * \"./workers/ts-health.worker\",\n * import.meta.url,\n * { workerData: { cwd: process.cwd() } }\n * );\n * ```\n */\nexport function createWorker(\n workerPath: string,\n baseUrl: string,\n options?: CreateWorkerOptions,\n): Worker {\n const isDevServerCore = env(\"DEV_SERVER_CORE\");\n\n // In dev: .ts file with tsx loader\n // In prod: .js file (compiled)\n const extension = isDevServerCore ? \".ts\" : \".js\";\n const workerUrl = new URL(`${workerPath}${extension}`, baseUrl);\n const workerFilePath = fileURLToPath(workerUrl);\n\n const workerOptions: WorkerOptions = {\n ...options,\n };\n\n // Add tsx loader for TypeScript in dev environment\n if (isDevServerCore) {\n workerOptions.execArgv = [...(options?.execArgv || []), \"--import\", \"tsx/esm\"];\n }\n\n return new Worker(workerFilePath, workerOptions);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,aACd,YACA,SACA,SACQ;CACR,MAAM,kBAAkB,IAAI,iBAAiB;CAM7C,MAAM,iBAAiB,cAAc,IADf,IAAI,GAAG,aADX,kBAAkB,QAAQ,SACW,OACV,CAAC;CAE9C,MAAM,gBAA+B,EACnC,GAAG,QACL;CAGA,IAAI,iBACF,cAAc,WAAW;EAAC,GAAI,SAAS,YAAY,CAAC;EAAI;EAAY;CAAS;CAG/E,OAAO,IAAI,OAAO,gBAAgB,aAAa;AACjD"}
1
+ {"version":3,"file":"create-worker.mjs","names":[],"sources":["../../../../../../@warlock.js/core/src/dev-server/create-worker.ts"],"sourcesContent":["import { env } from \"@mongez/dotenv\";\nimport { fileURLToPath } from \"url\";\nimport { Worker, type WorkerOptions } from \"worker_threads\";\n\n/**\n * Options for creating a health check worker\n */\nexport type CreateWorkerOptions = WorkerOptions & {\n /**\n * Worker data to pass to the worker thread\n */\n workerData?: Record<string, unknown>;\n};\n\n/**\n * Create a worker that works in both dev (TypeScript) and production (JavaScript) environments.\n *\n * In development mode (DEV_SERVER_CORE env set), workers are loaded with tsx\n * to support TypeScript execution. In production, compiled .js files are used.\n *\n * @param workerPath - Relative path to worker file WITHOUT extension (e.g., \"./workers/ts-health.worker\")\n * @param baseUrl - The import.meta.url of the calling module (used to resolve relative paths)\n * @param options - Additional worker options\n * @returns A new Worker instance\n *\n * @example\n * ```typescript\n * // In FilesHealthcareManager\n * const worker = createWorker(\n * \"./workers/ts-health.worker\",\n * import.meta.url,\n * { workerData: { cwd: process.cwd() } }\n * );\n * ```\n */\nexport function createWorker(\n workerPath: string,\n baseUrl: string,\n options?: CreateWorkerOptions,\n): Worker {\n const isDevServerCore = env(\"DEV_SERVER_CORE\");\n\n // In dev (running core from source): .ts file with tsx loader.\n // When published, core ships ESM modules with the .mjs extension (preserveModules).\n const extension = isDevServerCore ? \".ts\" : \".mjs\";\n const workerUrl = new URL(`${workerPath}${extension}`, baseUrl);\n const workerFilePath = fileURLToPath(workerUrl);\n\n const workerOptions: WorkerOptions = {\n ...options,\n };\n\n // Add tsx loader for TypeScript in dev environment\n if (isDevServerCore) {\n workerOptions.execArgv = [...(options?.execArgv || []), \"--import\", \"tsx/esm\"];\n }\n\n return new Worker(workerFilePath, workerOptions);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,aACd,YACA,SACA,SACQ;CACR,MAAM,kBAAkB,IAAI,iBAAiB;CAM7C,MAAM,iBAAiB,cAAc,IADf,IAAI,GAAG,aADX,kBAAkB,QAAQ,UACW,OACV,CAAC;CAE9C,MAAM,gBAA+B,EACnC,GAAG,QACL;CAGA,IAAI,iBACF,cAAc,WAAW;EAAC,GAAI,SAAS,YAAY,CAAC;EAAI;EAAY;CAAS;CAG/E,OAAO,IAAI,OAAO,gBAAgB,aAAa;AACjD"}
@@ -1,4 +1,5 @@
1
1
  import { register } from "node:module";
2
+ import { env } from "@mongez/dotenv";
2
3
  import { putFileAsync } from "@warlock.js/fs";
3
4
  import path from "node:path";
4
5
  import { build } from "esbuild";
@@ -40,8 +41,9 @@ import { MessageChannel } from "node:worker_threads";
40
41
  */
41
42
  async function registerLoader(transpile) {
42
43
  const { port1, port2 } = new MessageChannel();
44
+ const hookThreadExtension = env("DEV_SERVER_CORE") ? ".ts" : ".mjs";
43
45
  const bundledCode = (await build({
44
- entryPoints: [path.join(path.dirname(fileURLToPath(import.meta.url)), "hook-thread.ts")],
46
+ entryPoints: [path.join(path.dirname(fileURLToPath(import.meta.url)), `hook-thread${hookThreadExtension}`)],
45
47
  bundle: true,
46
48
  format: "esm",
47
49
  write: false,
@@ -1 +1 @@
1
- {"version":3,"file":"register-loader.mjs","names":[],"sources":["../../../../../../../@warlock.js/core/src/dev-server/loader/register-loader.ts"],"sourcesContent":["import { putFileAsync } from \"@warlock.js/fs\";\nimport { build } from \"esbuild\";\nimport { register } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { type MessagePort, MessageChannel } from \"node:worker_threads\";\nimport type { TranspileInit } from \"./load-hook.js\";\n\n/**\n * Bundle, write, and register the ESM loader hook.\n *\n * **Why bundle?**\n * `module.register()` runs the hook file in a fresh Node.js worker thread that\n * has no tsx hook of its own. The hook source is TypeScript, so we must produce\n * a plain ESM bundle before registering. esbuild inline-bundles all three hook\n * modules (`hook-thread`, `resolve-hook`, `load-hook`, `version-registry`)\n * into a single `.mjs` file written to `.warlock/`. External npm packages\n * (`esbuild`, `node:*`) are kept external — the hook thread can resolve those\n * from `node_modules` normally.\n *\n * **Why a file and not a `data:` URL?**\n * Some Node versions have issues resolving `import.meta.url` inside `data:`\n * modules. A real file under `.warlock/` is simpler and debuggable.\n *\n * **Timing**\n * Called from `FilesOrchestrator.init()` before any user `src/` module is\n * dynamically imported. `module.register()` takes effect for all subsequent\n * `import()` calls, which is exactly the window we need.\n *\n * @param transpile - Transpile-cache config to ship into the hook worker,\n * or `null` to keep the hook in tsx-passthrough mode.\n *\n * @returns The main-thread side of the MessageChannel. Callers post\n * `{ type: \"bump\", absolutePath }` messages on it to invalidate modules.\n *\n * @example\n * const port = await registerLoader(transpileInit);\n * // Later, when a file changes:\n * port.postMessage({ type: \"bump\", absolutePath: \"/abs/path/to/user.model.ts\" });\n */\nexport async function registerLoader(\n transpile: TranspileInit,\n): Promise<MessagePort> {\n const { port1, port2 } = new MessageChannel();\n\n const hookThreadPath = path.join(path.dirname(fileURLToPath(import.meta.url)), \"hook-thread.ts\");\n\n const bundleResult = await build({\n entryPoints: [hookThreadPath],\n bundle: true,\n format: \"esm\",\n write: false,\n platform: \"node\",\n target: \"node20\",\n // Keep npm packages and Node built-ins external — the hook thread resolves\n // them normally from node_modules at runtime.\n packages: \"external\",\n });\n\n const bundledCode = bundleResult.outputFiles[0].text;\n // Caller (filesOrchestrator.init) guarantees .warlock/ exists before this runs.\n const hookBundlePath = path.join(process.cwd(), \".warlock\", \"loader-hook.mjs\");\n await putFileAsync(hookBundlePath, bundledCode);\n\n const srcRoot = path.join(process.cwd(), \"src\");\n\n // No tsx registration: our hook owns resolution (own-resolver) and the\n // transpile of every `.ts`/`.tsx` (esbuild, in the load hook). The chain\n // is simply [our hook] → [Node default] for non-TS (npm/.js, node:).\n // In this monorepo tsx is still the *launcher* (`tsx start.ts`) so its\n // loader is present anyway, but it is never consulted for TypeScript —\n // our hook short-circuits first. A released `node bin/warlock.js` has no\n // tsx at all and relies entirely on this hook.\n\n register(pathToFileURL(hookBundlePath).href, import.meta.url, {\n data: { port: port2, srcRoot, transpile },\n transferList: [port2],\n });\n\n return port1;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,eAAsB,eACpB,WACsB;CACtB,MAAM,EAAE,OAAO,UAAU,IAAI,eAAe;CAgB5C,MAAM,eAAc,MAZO,MAAM;EAC/B,aAAa,CAHQ,KAAK,KAAK,KAAK,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC,GAAG,gBAGlD,CAAC;EAC5B,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,UAAU;EACV,QAAQ;EAGR,UAAU;CACZ,CAAC,GAEgC,YAAY,GAAG;CAEhD,MAAM,iBAAiB,KAAK,KAAK,QAAQ,IAAI,GAAG,YAAY,iBAAiB;CAC7E,MAAM,aAAa,gBAAgB,WAAW;CAE9C,MAAM,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,KAAK;CAU9C,SAAS,cAAc,cAAc,EAAE,MAAM,OAAO,KAAK,KAAK;EAC5D,MAAM;GAAE,MAAM;GAAO;GAAS;EAAU;EACxC,cAAc,CAAC,KAAK;CACtB,CAAC;CAED,OAAO;AACT"}
1
+ {"version":3,"file":"register-loader.mjs","names":[],"sources":["../../../../../../../@warlock.js/core/src/dev-server/loader/register-loader.ts"],"sourcesContent":["import { env } from \"@mongez/dotenv\";\nimport { putFileAsync } from \"@warlock.js/fs\";\nimport { build } from \"esbuild\";\nimport { register } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { type MessagePort, MessageChannel } from \"node:worker_threads\";\nimport type { TranspileInit } from \"./load-hook.js\";\n\n/**\n * Bundle, write, and register the ESM loader hook.\n *\n * **Why bundle?**\n * `module.register()` runs the hook file in a fresh Node.js worker thread that\n * has no tsx hook of its own. The hook source is TypeScript, so we must produce\n * a plain ESM bundle before registering. esbuild inline-bundles all three hook\n * modules (`hook-thread`, `resolve-hook`, `load-hook`, `version-registry`)\n * into a single `.mjs` file written to `.warlock/`. External npm packages\n * (`esbuild`, `node:*`) are kept external — the hook thread can resolve those\n * from `node_modules` normally.\n *\n * **Why a file and not a `data:` URL?**\n * Some Node versions have issues resolving `import.meta.url` inside `data:`\n * modules. A real file under `.warlock/` is simpler and debuggable.\n *\n * **Timing**\n * Called from `FilesOrchestrator.init()` before any user `src/` module is\n * dynamically imported. `module.register()` takes effect for all subsequent\n * `import()` calls, which is exactly the window we need.\n *\n * @param transpile - Transpile-cache config to ship into the hook worker,\n * or `null` to keep the hook in tsx-passthrough mode.\n *\n * @returns The main-thread side of the MessageChannel. Callers post\n * `{ type: \"bump\", absolutePath }` messages on it to invalidate modules.\n *\n * @example\n * const port = await registerLoader(transpileInit);\n * // Later, when a file changes:\n * port.postMessage({ type: \"bump\", absolutePath: \"/abs/path/to/user.model.ts\" });\n */\nexport async function registerLoader(\n transpile: TranspileInit,\n): Promise<MessagePort> {\n const { port1, port2 } = new MessageChannel();\n\n // Running core from source → hook-thread.ts; published core ships .mjs.\n const hookThreadExtension = env(\"DEV_SERVER_CORE\") ? \".ts\" : \".mjs\";\n const hookThreadPath = path.join(\n path.dirname(fileURLToPath(import.meta.url)),\n `hook-thread${hookThreadExtension}`,\n );\n\n const bundleResult = await build({\n entryPoints: [hookThreadPath],\n bundle: true,\n format: \"esm\",\n write: false,\n platform: \"node\",\n target: \"node20\",\n // Keep npm packages and Node built-ins external — the hook thread resolves\n // them normally from node_modules at runtime.\n packages: \"external\",\n });\n\n const bundledCode = bundleResult.outputFiles[0].text;\n // Caller (filesOrchestrator.init) guarantees .warlock/ exists before this runs.\n const hookBundlePath = path.join(process.cwd(), \".warlock\", \"loader-hook.mjs\");\n await putFileAsync(hookBundlePath, bundledCode);\n\n const srcRoot = path.join(process.cwd(), \"src\");\n\n // No tsx registration: our hook owns resolution (own-resolver) and the\n // transpile of every `.ts`/`.tsx` (esbuild, in the load hook). The chain\n // is simply [our hook] → [Node default] for non-TS (npm/.js, node:).\n // In this monorepo tsx is still the *launcher* (`tsx start.ts`) so its\n // loader is present anyway, but it is never consulted for TypeScript —\n // our hook short-circuits first. A released `node bin/warlock.js` has no\n // tsx at all and relies entirely on this hook.\n\n register(pathToFileURL(hookBundlePath).href, import.meta.url, {\n data: { port: port2, srcRoot, transpile },\n transferList: [port2],\n });\n\n return port1;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,eAAsB,eACpB,WACsB;CACtB,MAAM,EAAE,OAAO,UAAU,IAAI,eAAe;CAG5C,MAAM,sBAAsB,IAAI,iBAAiB,IAAI,QAAQ;CAkB7D,MAAM,eAAc,MAZO,MAAM;EAC/B,aAAa,CANQ,KAAK,KAC1B,KAAK,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC,GAC3C,cAAc,qBAIa,CAAC;EAC5B,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,UAAU;EACV,QAAQ;EAGR,UAAU;CACZ,CAAC,GAEgC,YAAY,GAAG;CAEhD,MAAM,iBAAiB,KAAK,KAAK,QAAQ,IAAI,GAAG,YAAY,iBAAiB;CAC7E,MAAM,aAAa,gBAAgB,WAAW;CAE9C,MAAM,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,KAAK;CAU9C,SAAS,cAAc,cAAc,EAAE,MAAM,OAAO,KAAK,KAAK;EAC5D,MAAM;GAAE,MAAM;GAAO;GAAS;EAAU;EACxC,cAAc,CAAC,KAAK;CACtB,CAAC;CAED,OAAO;AACT"}
package/package.json CHANGED
@@ -36,13 +36,13 @@
36
36
  "@mongez/slug": "^1.0.7",
37
37
  "@mongez/supportive-is": "^2.1.3",
38
38
  "@mongez/time-wizard": "^1.0.6",
39
- "@warlock.js/auth": "4.1.4",
40
- "@warlock.js/cache": "4.1.4",
41
- "@warlock.js/cascade": "4.1.4",
42
- "@warlock.js/context": "4.1.4",
43
- "@warlock.js/logger": "4.1.4",
44
- "@warlock.js/seal": "4.1.4",
45
- "@warlock.js/fs": "4.1.4",
39
+ "@warlock.js/auth": "4.1.5",
40
+ "@warlock.js/cache": "4.1.5",
41
+ "@warlock.js/cascade": "4.1.5",
42
+ "@warlock.js/context": "4.1.5",
43
+ "@warlock.js/logger": "4.1.5",
44
+ "@warlock.js/seal": "4.1.5",
45
+ "@warlock.js/fs": "4.1.5",
46
46
  "chokidar": "^5.0.0",
47
47
  "dayjs": "^1.11.19",
48
48
  "es-module-lexer": "^2.0.0",
@@ -68,12 +68,12 @@
68
68
  "react": "^19.2.3",
69
69
  "react-dom": "^19.2.3",
70
70
  "@react-email/render": "^2.0.5",
71
- "@warlock.js/herald": "4.1.4"
71
+ "@warlock.js/herald": "4.1.5"
72
72
  },
73
73
  "bin": {
74
74
  "warlock": "bin/warlock.js"
75
75
  },
76
- "version": "4.1.4",
76
+ "version": "4.1.5",
77
77
  "type": "module",
78
78
  "main": "./esm/index.mjs",
79
79
  "module": "./esm/index.mjs",