@staticbolt/core 1.0.0-beta.3 → 1.0.0-beta.31

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.
@@ -0,0 +1,15 @@
1
+ import { DeferredPass } from "@staticbolt/core";
2
+ //#region src/plugins/write-files/deferred-worker.d.ts
3
+ /** A written file and the pass a plugin handed over instead of running. */
4
+ interface DeferredJob {
5
+ /** Absolute path of the file to run the pass over, in place. */
6
+ path: string;
7
+ pass: DeferredPass;
8
+ }
9
+ /** Sent back once the file is done, whether or not the pass went through. A worker is only ever given one job at a time. */
10
+ interface DeferredJobResult {
11
+ error?: string;
12
+ }
13
+ //#endregion
14
+ export { DeferredJob, DeferredJobResult };
15
+ //# sourceMappingURL=deferred-worker.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deferred-worker.d.mts","names":[],"sources":["../../../src/plugins/write-files/deferred-worker.ts"],"mappings":";;;UAMiB;;EAEf;EAEA,MAAM;;;UAIS;EACf"}
@@ -0,0 +1,35 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { parentPort } from "node:worker_threads";
3
+
4
+ //#region src/plugins/write-files/deferred-worker.ts
5
+ /** Passes are looked up once and kept: a worker is handed the same kind of file over and over. */
6
+ const handlers = /* @__PURE__ */ new Map();
7
+ async function resolveHandler({ module, export: exportName }) {
8
+ const key = `${module}#${exportName}`;
9
+ const cached = handlers.get(key);
10
+ if (cached) return cached;
11
+ const handler = (await import(module))[exportName];
12
+ if (typeof handler !== "function") throw new TypeError(`"${module}" does not export "${exportName}"`);
13
+ handlers.set(key, handler);
14
+ return handler;
15
+ }
16
+ /** Reads the file, runs the pass the plugin named over its contents, and writes the result back over it. */
17
+ async function applyPass({ path, pass }) {
18
+ const handler = await resolveHandler(pass);
19
+ const code = readFileSync(path, "utf8");
20
+ writeFileSync(path, await handler(code, pass.payload), "utf8");
21
+ }
22
+ const port = parentPort;
23
+ if (port) port.on("message", async (job) => {
24
+ const result = {};
25
+ try {
26
+ await applyPass(job);
27
+ } catch (error) {
28
+ result.error = error instanceof Error ? error.message : String(error);
29
+ }
30
+ port.postMessage(result);
31
+ });
32
+
33
+ //#endregion
34
+ export { };
35
+ //# sourceMappingURL=deferred-worker.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deferred-worker.mjs","names":[],"sources":["../../../src/plugins/write-files/deferred-worker.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from \"node:fs\";\nimport { parentPort } from \"node:worker_threads\";\n\nimport type { DeferredPass, DeferredPassHandler } from \"@staticbolt/core\";\n\n/** A written file and the pass a plugin handed over instead of running. */\nexport interface DeferredJob {\n /** Absolute path of the file to run the pass over, in place. */\n path: string;\n\n pass: DeferredPass;\n}\n\n/** Sent back once the file is done, whether or not the pass went through. A worker is only ever given one job at a time. */\nexport interface DeferredJobResult {\n error?: string;\n}\n\n/** Passes are looked up once and kept: a worker is handed the same kind of file over and over. */\nconst handlers = new Map<string, DeferredPassHandler<unknown>>();\n\nasync function resolveHandler({ module, export: exportName }: DeferredPass): Promise<DeferredPassHandler<unknown>> {\n const key = `${module}#${exportName}`;\n\n const cached = handlers.get(key);\n if (cached) {\n return cached;\n }\n\n const namespace = (await import(module)) as Record<string, unknown>;\n const handler = namespace[exportName];\n\n if (typeof handler !== \"function\") {\n throw new TypeError(`\"${module}\" does not export \"${exportName}\"`);\n }\n\n handlers.set(key, handler as DeferredPassHandler<unknown>);\n\n return handler as DeferredPassHandler<unknown>;\n}\n\n/** Reads the file, runs the pass the plugin named over its contents, and writes the result back over it. */\nasync function applyPass({ path, pass }: DeferredJob): Promise<void> {\n const handler = await resolveHandler(pass);\n const code = readFileSync(path, \"utf8\");\n\n writeFileSync(path, await handler(code, pass.payload), \"utf8\");\n}\n\nconst port = parentPort;\n\nif (port) {\n port.on(\"message\", async (job: DeferredJob) => {\n const result: DeferredJobResult = {};\n\n try {\n await applyPass(job);\n } catch (error) {\n result.error = error instanceof Error ? error.message : String(error);\n }\n\n port.postMessage(result);\n });\n}\n"],"mappings":";;;;;AAmBA,MAAM,2BAAW,IAAI,IAA0C;AAE/D,eAAe,eAAe,EAAE,QAAQ,QAAQ,cAAmE;CACjH,MAAM,MAAM,GAAG,OAAO,GAAG;CAEzB,MAAM,SAAS,SAAS,IAAI,GAAG;CAC/B,IAAI,QACF,OAAO;CAIT,MAAM,WAAU,MADS,OAAO,QACP,CAAC;CAE1B,IAAI,OAAO,YAAY,YACrB,MAAM,IAAI,UAAU,IAAI,OAAO,qBAAqB,WAAW,EAAE;CAGnE,SAAS,IAAI,KAAK,OAAuC;CAEzD,OAAO;AACT;;AAGA,eAAe,UAAU,EAAE,MAAM,QAAoC;CACnE,MAAM,UAAU,MAAM,eAAe,IAAI;CACzC,MAAM,OAAO,aAAa,MAAM,MAAM;CAEtC,cAAc,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO,GAAG,MAAM;AAC/D;AAEA,MAAM,OAAO;AAEb,IAAI,MACF,KAAK,GAAG,WAAW,OAAO,QAAqB;CAC7C,MAAM,SAA4B,CAAC;CAEnC,IAAI;EACF,MAAM,UAAU,GAAG;CACrB,SAAS,OAAO;EACd,OAAO,QAAQ,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CACtE;CAEA,KAAK,YAAY,MAAM;AACzB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region \0rolldown/runtime.js
4
+ var __defProp = Object.defineProperty;
5
+ var __exportAll = (all, no_symbols) => {
6
+ let target = {};
7
+ for (var name in all) {
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ }
13
+ if (!no_symbols) {
14
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
15
+ }
16
+ return target;
17
+ };
18
+
19
+ //#endregion
20
+ export { __exportAll as t };