valaxy 0.22.13 → 0.22.15

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/client/App.vue CHANGED
@@ -1,4 +1,6 @@
1
1
  <script setup lang="ts">
2
+ // import it in setup/main.ts for ssg
3
+ import 'virtual:group-icons.css'
2
4
  // import { defineAsyncComponent } from 'vue'
3
5
  /**
4
6
  * @see @valaxyjs/devtools
@@ -0,0 +1,19 @@
1
+ import type { Ref } from 'vue'
2
+ import type { Router } from 'vue-router'
3
+ import type { PageData } from '../../types'
4
+ import { computed } from 'vue'
5
+
6
+ export interface ValaxyData {
7
+ page: Ref<PageData>
8
+ }
9
+
10
+ /**
11
+ * init valaxy data
12
+ */
13
+ export function initData(router: Router): ValaxyData {
14
+ return {
15
+ page: computed(() => (router.currentRoute.value as unknown as {
16
+ data: PageData
17
+ }).data),
18
+ }
19
+ }
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" setup>
2
2
  withDefaults(defineProps<{
3
- show: boolean
3
+ show?: boolean
4
4
  }>(), {
5
5
  show: false,
6
6
  })
@@ -1,9 +1,10 @@
1
- import type { PageData, PostFrontMatter } from 'valaxy/types'
1
+ import type { PostFrontMatter } from 'valaxy/types'
2
+ import type { ValaxyData } from '../app/data'
2
3
  import { isClient } from '@vueuse/core'
3
- import { computed, inject } from 'vue'
4
4
 
5
+ import { computed, inject } from 'vue'
5
6
  import { useRoute } from 'vue-router'
6
- import { useSiteConfig } from '../config'
7
+ import { dataSymbol, useSiteConfig } from '../config'
7
8
 
8
9
  /**
9
10
  * Get `route.meta.frontmatter` from your markdown file
@@ -71,9 +72,12 @@ export function useEncryptedPhotos() {
71
72
  /**
72
73
  * inject pageData
73
74
  */
74
- export function useData(): PageData {
75
- const value = inject<PageData>('pageData', {} as any)
76
- return value
75
+ export function useData(): ValaxyData {
76
+ const data = inject(dataSymbol, {} as any)
77
+ if (!data) {
78
+ throw new Error('Valaxy data not properly injected in app')
79
+ }
80
+ return data
77
81
  }
78
82
 
79
83
  /**
package/client/config.ts CHANGED
@@ -5,10 +5,11 @@
5
5
  import type { DefaultTheme, ValaxyConfig } from 'valaxy/types'
6
6
 
7
7
  import type { ComputedRef, InjectionKey } from 'vue'
8
+ import type { ValaxyData } from './app/data'
8
9
  import { computed, inject, readonly, shallowRef } from 'vue'
10
+
9
11
  // @ts-expect-error virtual module @valaxyjs/config
10
12
  import valaxyConfig from '/@valaxyjs/config'
11
-
12
13
  // @ts-expect-error virtual module @valaxyjs/context
13
14
  import valaxyContext from '/@valaxyjs/context'
14
15
 
@@ -28,6 +29,8 @@ interface ValaxyContext {
28
29
  export const valaxyConfigSymbol: InjectionKey<ComputedRef<ValaxyConfig>> = Symbol('valaxy:config')
29
30
  export const valaxyConfigRef = shallowRef<ValaxyConfig>(parse<ValaxyConfig>(valaxyConfig))
30
31
 
32
+ export const dataSymbol: InjectionKey<ValaxyData> = Symbol('ValaxyData')
33
+
31
34
  export const valaxyContextRef = shallowRef<ValaxyContext>(parse<ValaxyContext>(valaxyContext))
32
35
 
33
36
  valaxyConfigRef.value = parse<ValaxyConfig>(valaxyConfig)
package/client/main.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ViteSSGContext } from 'vite-ssg'
2
2
  import { DataLoaderPlugin } from 'unplugin-vue-router/data-loaders'
3
- import { initValaxyConfig, valaxyConfigSymbol } from 'valaxy'
3
+ import { dataSymbol, initValaxyConfig, valaxyConfigSymbol } from 'valaxy'
4
4
  import { setupLayouts } from 'virtual:generated-layouts'
5
5
  import { ViteSSG } from 'vite-ssg'
6
6
 
@@ -8,13 +8,18 @@ import { routes } from 'vue-router/auto-routes'
8
8
  // import App from '/@valaxyjs/App.vue'
9
9
  import App from './App.vue'
10
10
 
11
+ import { initData } from './app/data'
11
12
  import AppLink from './components/AppLink.vue'
13
+
12
14
  import setupMain from './setup/main'
13
15
 
14
16
  import { setupValaxyDevTools } from './utils/dev'
15
-
16
- // generate user styles
17
+ /**
18
+ * user styles
19
+ * virtual module
20
+ */
17
21
  import '#valaxy/styles'
22
+ import 'uno.css'
18
23
 
19
24
  const valaxyConfig = initValaxyConfig()
20
25
 
@@ -71,6 +76,9 @@ export const createApp = ViteSSG(
71
76
  // app-level provide
72
77
  const { app, router } = ctx
73
78
 
79
+ const data = initData(router)
80
+ app.provide(dataSymbol, data)
81
+
74
82
  // Register the plugin before the router
75
83
  app.use(DataLoaderPlugin, { router })
76
84
 
@@ -0,0 +1,426 @@
1
+ import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url);
2
+ import {
3
+ __dirname,
4
+ __require
5
+ } from "./chunk-UO3OS4ER.js";
6
+
7
+ // ../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
8
+ function __rest(s, e) {
9
+ var t = {};
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
11
+ t[p] = s[p];
12
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
13
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
14
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
15
+ t[p[i]] = s[p[i]];
16
+ }
17
+ return t;
18
+ }
19
+ function __awaiter(thisArg, _arguments, P, generator) {
20
+ function adopt(value) {
21
+ return value instanceof P ? value : new P(function(resolve) {
22
+ resolve(value);
23
+ });
24
+ }
25
+ return new (P || (P = Promise))(function(resolve, reject) {
26
+ function fulfilled(value) {
27
+ try {
28
+ step(generator.next(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ }
33
+ function rejected(value) {
34
+ try {
35
+ step(generator["throw"](value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ }
40
+ function step(result) {
41
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
42
+ }
43
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
44
+ });
45
+ }
46
+
47
+ // ../../node_modules/.pnpm/synckit@0.9.2/node_modules/synckit/lib/index.js
48
+ import { createHash } from "node:crypto";
49
+ import fs2 from "node:fs";
50
+ import module from "node:module";
51
+ import path2 from "node:path";
52
+ import { fileURLToPath, pathToFileURL } from "node:url";
53
+ import { MessageChannel, Worker, parentPort, receiveMessageOnPort, workerData } from "node:worker_threads";
54
+
55
+ // ../../node_modules/.pnpm/@pkgr+core@0.1.1/node_modules/@pkgr/core/lib/constants.js
56
+ import { createRequire } from "node:module";
57
+ var CWD = process.cwd();
58
+ var cjsRequire = typeof __require === "undefined" ? createRequire(import.meta.url) : __require;
59
+ var EXTENSIONS = [".ts", ".tsx", ...Object.keys(cjsRequire.extensions)];
60
+
61
+ // ../../node_modules/.pnpm/@pkgr+core@0.1.1/node_modules/@pkgr/core/lib/helpers.js
62
+ import fs from "node:fs";
63
+ import path from "node:path";
64
+ var tryPkg = (pkg) => {
65
+ try {
66
+ return cjsRequire.resolve(pkg);
67
+ } catch (_a) {
68
+ }
69
+ };
70
+ var isPkgAvailable = (pkg) => !!tryPkg(pkg);
71
+ var tryFile = (filePath, includeDir = false) => {
72
+ if (typeof filePath === "string") {
73
+ return fs.existsSync(filePath) && (includeDir || fs.statSync(filePath).isFile()) ? filePath : "";
74
+ }
75
+ for (const file of filePath !== null && filePath !== void 0 ? filePath : []) {
76
+ if (tryFile(file, includeDir)) {
77
+ return file;
78
+ }
79
+ }
80
+ return "";
81
+ };
82
+ var tryExtensions = (filepath, extensions = EXTENSIONS) => {
83
+ const ext = [...extensions, ""].find((ext2) => tryFile(filepath + ext2));
84
+ return ext == null ? "" : filepath + ext;
85
+ };
86
+ var findUp = (searchEntry, searchFileOrIncludeDir, includeDir) => {
87
+ console.assert(path.isAbsolute(searchEntry));
88
+ if (!tryFile(searchEntry, true) || searchEntry !== CWD && !searchEntry.startsWith(CWD + path.sep)) {
89
+ return "";
90
+ }
91
+ searchEntry = path.resolve(fs.statSync(searchEntry).isDirectory() ? searchEntry : path.resolve(searchEntry, ".."));
92
+ const isSearchFile = typeof searchFileOrIncludeDir === "string";
93
+ const searchFile = isSearchFile ? searchFileOrIncludeDir : "package.json";
94
+ do {
95
+ const searched = tryFile(path.resolve(searchEntry, searchFile), isSearchFile && includeDir);
96
+ if (searched) {
97
+ return searched;
98
+ }
99
+ searchEntry = path.resolve(searchEntry, "..");
100
+ } while (searchEntry === CWD || searchEntry.startsWith(CWD + path.sep));
101
+ return "";
102
+ };
103
+
104
+ // ../../node_modules/.pnpm/synckit@0.9.2/node_modules/synckit/lib/index.js
105
+ var INT32_BYTES = 4;
106
+ var TsRunner = {
107
+ TsNode: "ts-node",
108
+ EsbuildRegister: "esbuild-register",
109
+ EsbuildRunner: "esbuild-runner",
110
+ SWC: "swc",
111
+ TSX: "tsx"
112
+ };
113
+ var { NODE_OPTIONS, SYNCKIT_EXEC_ARGV, SYNCKIT_GLOBAL_SHIMS, SYNCKIT_TIMEOUT, SYNCKIT_TS_RUNNER } = process.env;
114
+ var IS_NODE_20 = Number(process.versions.node.split(".")[0]) >= 20;
115
+ var DEFAULT_TIMEOUT = SYNCKIT_TIMEOUT ? +SYNCKIT_TIMEOUT : void 0;
116
+ var DEFAULT_EXEC_ARGV = (SYNCKIT_EXEC_ARGV === null || SYNCKIT_EXEC_ARGV === void 0 ? void 0 : SYNCKIT_EXEC_ARGV.split(",")) || [];
117
+ var DEFAULT_TS_RUNNER = SYNCKIT_TS_RUNNER;
118
+ var DEFAULT_GLOBAL_SHIMS = ["1", "true"].includes(SYNCKIT_GLOBAL_SHIMS);
119
+ var DEFAULT_GLOBAL_SHIMS_PRESET = [
120
+ {
121
+ moduleName: "node-fetch",
122
+ globalName: "fetch"
123
+ },
124
+ {
125
+ moduleName: "node:perf_hooks",
126
+ globalName: "performance",
127
+ named: "performance"
128
+ }
129
+ ];
130
+ var MTS_SUPPORTED_NODE_VERSION = 16;
131
+ var syncFnCache;
132
+ function extractProperties(object) {
133
+ if (object && typeof object === "object") {
134
+ const properties = {};
135
+ for (const key in object) {
136
+ properties[key] = object[key];
137
+ }
138
+ return properties;
139
+ }
140
+ }
141
+ function createSyncFn(workerPath, timeoutOrOptions) {
142
+ syncFnCache !== null && syncFnCache !== void 0 ? syncFnCache : syncFnCache = /* @__PURE__ */ new Map();
143
+ const cachedSyncFn = syncFnCache.get(workerPath);
144
+ if (cachedSyncFn) {
145
+ return cachedSyncFn;
146
+ }
147
+ if (!path2.isAbsolute(workerPath)) {
148
+ throw new Error("`workerPath` must be absolute");
149
+ }
150
+ const syncFn = startWorkerThread(workerPath, typeof timeoutOrOptions === "number" ? { timeout: timeoutOrOptions } : timeoutOrOptions);
151
+ syncFnCache.set(workerPath, syncFn);
152
+ return syncFn;
153
+ }
154
+ var cjsRequire2 = typeof __require === "undefined" ? module.createRequire(import.meta.url) : __require;
155
+ var dataUrl = (code) => new URL(`data:text/javascript,${encodeURIComponent(code)}`);
156
+ var isFile = (path3) => {
157
+ var _a;
158
+ try {
159
+ return !!((_a = fs2.statSync(path3, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile());
160
+ } catch (_b) {
161
+ return false;
162
+ }
163
+ };
164
+ var setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
165
+ let ext = path2.extname(workerPath);
166
+ if (!/[/\\]node_modules[/\\]/.test(workerPath) && (!ext || /^\.[cm]?js$/.test(ext))) {
167
+ const workPathWithoutExt = ext ? workerPath.slice(0, -ext.length) : workerPath;
168
+ let extensions;
169
+ switch (ext) {
170
+ case ".cjs": {
171
+ extensions = [".cts", ".cjs"];
172
+ break;
173
+ }
174
+ case ".mjs": {
175
+ extensions = [".mts", ".mjs"];
176
+ break;
177
+ }
178
+ default: {
179
+ extensions = [".ts", ".js"];
180
+ break;
181
+ }
182
+ }
183
+ const found = tryExtensions(workPathWithoutExt, extensions);
184
+ let differentExt;
185
+ if (found && (!ext || (differentExt = found !== workPathWithoutExt))) {
186
+ workerPath = found;
187
+ if (differentExt) {
188
+ ext = path2.extname(workerPath);
189
+ }
190
+ }
191
+ }
192
+ const isTs = /\.[cm]?ts$/.test(workerPath);
193
+ let jsUseEsm = workerPath.endsWith(".mjs");
194
+ let tsUseEsm = workerPath.endsWith(".mts");
195
+ if (isTs) {
196
+ if (!tsUseEsm) {
197
+ const pkg = findUp(workerPath);
198
+ if (pkg) {
199
+ tsUseEsm = cjsRequire2(pkg).type === "module";
200
+ }
201
+ }
202
+ if (tsRunner == null && isPkgAvailable(TsRunner.TsNode)) {
203
+ tsRunner = TsRunner.TsNode;
204
+ }
205
+ switch (tsRunner) {
206
+ case TsRunner.TsNode: {
207
+ if (tsUseEsm) {
208
+ if (!execArgv.includes("--loader")) {
209
+ execArgv = ["--loader", `${TsRunner.TsNode}/esm`, ...execArgv];
210
+ }
211
+ } else if (!execArgv.includes("-r")) {
212
+ execArgv = ["-r", `${TsRunner.TsNode}/register`, ...execArgv];
213
+ }
214
+ break;
215
+ }
216
+ case TsRunner.EsbuildRegister: {
217
+ if (!execArgv.includes("-r")) {
218
+ execArgv = ["-r", TsRunner.EsbuildRegister, ...execArgv];
219
+ }
220
+ break;
221
+ }
222
+ case TsRunner.EsbuildRunner: {
223
+ if (!execArgv.includes("-r")) {
224
+ execArgv = ["-r", `${TsRunner.EsbuildRunner}/register`, ...execArgv];
225
+ }
226
+ break;
227
+ }
228
+ case TsRunner.SWC: {
229
+ if (!execArgv.includes("-r")) {
230
+ execArgv = ["-r", `@${TsRunner.SWC}-node/register`, ...execArgv];
231
+ }
232
+ break;
233
+ }
234
+ case TsRunner.TSX: {
235
+ if (!execArgv.includes("--loader")) {
236
+ execArgv = ["--loader", TsRunner.TSX, ...execArgv];
237
+ }
238
+ break;
239
+ }
240
+ default: {
241
+ throw new Error(`Unknown ts runner: ${String(tsRunner)}`);
242
+ }
243
+ }
244
+ } else if (!jsUseEsm) {
245
+ const pkg = findUp(workerPath);
246
+ if (pkg) {
247
+ jsUseEsm = cjsRequire2(pkg).type === "module";
248
+ }
249
+ }
250
+ let resolvedPnpLoaderPath;
251
+ if (process.versions.pnp) {
252
+ const nodeOptions = NODE_OPTIONS === null || NODE_OPTIONS === void 0 ? void 0 : NODE_OPTIONS.split(/\s+/);
253
+ let pnpApiPath;
254
+ try {
255
+ pnpApiPath = cjsRequire2.resolve("pnpapi");
256
+ } catch (_a) {
257
+ }
258
+ if (pnpApiPath && !(nodeOptions === null || nodeOptions === void 0 ? void 0 : nodeOptions.some((option, index) => ["-r", "--require"].includes(option) && pnpApiPath === cjsRequire2.resolve(nodeOptions[index + 1]))) && !execArgv.includes(pnpApiPath)) {
259
+ execArgv = ["-r", pnpApiPath, ...execArgv];
260
+ const pnpLoaderPath = path2.resolve(pnpApiPath, "../.pnp.loader.mjs");
261
+ if (isFile(pnpLoaderPath)) {
262
+ resolvedPnpLoaderPath = pathToFileURL(pnpLoaderPath).toString();
263
+ if (!IS_NODE_20) {
264
+ execArgv = [
265
+ "--experimental-loader",
266
+ resolvedPnpLoaderPath,
267
+ ...execArgv
268
+ ];
269
+ }
270
+ }
271
+ }
272
+ }
273
+ return {
274
+ ext,
275
+ isTs,
276
+ jsUseEsm,
277
+ tsRunner,
278
+ tsUseEsm,
279
+ workerPath,
280
+ pnpLoaderPath: resolvedPnpLoaderPath,
281
+ execArgv
282
+ };
283
+ };
284
+ var md5Hash = (text) => createHash("md5").update(text).digest("hex");
285
+ var encodeImportModule = (moduleNameOrGlobalShim, type = "import") => {
286
+ const { moduleName, globalName, named, conditional } = typeof moduleNameOrGlobalShim === "string" ? { moduleName: moduleNameOrGlobalShim } : moduleNameOrGlobalShim;
287
+ const importStatement = type === "import" ? `import${globalName ? " " + (named === null ? "* as " + globalName : (named === null || named === void 0 ? void 0 : named.trim()) ? `{${named}}` : globalName) + " from" : ""} '${path2.isAbsolute(moduleName) ? String(pathToFileURL(moduleName)) : moduleName}'` : `${globalName ? "const " + ((named === null || named === void 0 ? void 0 : named.trim()) ? `{${named}}` : globalName) + "=" : ""}require('${moduleName.replace(/\\/g, "\\\\")}')`;
288
+ if (!globalName) {
289
+ return importStatement;
290
+ }
291
+ const overrideStatement = `globalThis.${globalName}=${(named === null || named === void 0 ? void 0 : named.trim()) ? named : globalName}`;
292
+ return importStatement + (conditional === false ? `;${overrideStatement}` : `;if(!globalThis.${globalName})${overrideStatement}`);
293
+ };
294
+ var _generateGlobals = (globalShims, type) => globalShims.reduce((acc, shim) => `${acc}${acc ? ";" : ""}${encodeImportModule(shim, type)}`, "");
295
+ var globalsCache;
296
+ var tmpdir;
297
+ var _dirname = typeof __dirname === "undefined" ? path2.dirname(fileURLToPath(import.meta.url)) : __dirname;
298
+ var sharedBuffer;
299
+ var sharedBufferView;
300
+ var generateGlobals = (workerPath, globalShims, type = "import") => {
301
+ globalsCache !== null && globalsCache !== void 0 ? globalsCache : globalsCache = /* @__PURE__ */ new Map();
302
+ const cached = globalsCache.get(workerPath);
303
+ if (cached) {
304
+ const [content2, filepath2] = cached;
305
+ if (type === "require" && !filepath2 || type === "import" && filepath2 && isFile(filepath2)) {
306
+ return content2;
307
+ }
308
+ }
309
+ const globals = _generateGlobals(globalShims, type);
310
+ let content = globals;
311
+ let filepath;
312
+ if (type === "import") {
313
+ if (!tmpdir) {
314
+ tmpdir = path2.resolve(findUp(_dirname), "../node_modules/.synckit");
315
+ }
316
+ fs2.mkdirSync(tmpdir, { recursive: true });
317
+ filepath = path2.resolve(tmpdir, md5Hash(workerPath) + ".mjs");
318
+ content = encodeImportModule(filepath);
319
+ fs2.writeFileSync(filepath, globals);
320
+ }
321
+ globalsCache.set(workerPath, [content, filepath]);
322
+ return content;
323
+ };
324
+ function startWorkerThread(workerPath, { timeout = DEFAULT_TIMEOUT, execArgv = DEFAULT_EXEC_ARGV, tsRunner = DEFAULT_TS_RUNNER, transferList = [], globalShims = DEFAULT_GLOBAL_SHIMS } = {}) {
325
+ const { port1: mainPort, port2: workerPort } = new MessageChannel();
326
+ const { isTs, ext, jsUseEsm, tsUseEsm, tsRunner: finalTsRunner, workerPath: finalWorkerPath, pnpLoaderPath, execArgv: finalExecArgv } = setupTsRunner(workerPath, { execArgv, tsRunner });
327
+ const workerPathUrl = pathToFileURL(finalWorkerPath);
328
+ if (/\.[cm]ts$/.test(finalWorkerPath)) {
329
+ const isTsxSupported = !tsUseEsm || Number.parseFloat(process.versions.node) >= MTS_SUPPORTED_NODE_VERSION;
330
+ if (!finalTsRunner) {
331
+ throw new Error("No ts runner specified, ts worker path is not supported");
332
+ } else if ([
333
+ TsRunner.EsbuildRegister,
334
+ TsRunner.EsbuildRunner,
335
+ TsRunner.SWC,
336
+ ...isTsxSupported ? [] : [TsRunner.TSX]
337
+ ].includes(finalTsRunner)) {
338
+ throw new Error(`${finalTsRunner} is not supported for ${ext} files yet` + (isTsxSupported ? ", you can try [tsx](https://github.com/esbuild-kit/tsx) instead" : ""));
339
+ }
340
+ }
341
+ const finalGlobalShims = (globalShims === true ? DEFAULT_GLOBAL_SHIMS_PRESET : Array.isArray(globalShims) ? globalShims : []).filter(({ moduleName }) => isPkgAvailable(moduleName));
342
+ sharedBufferView !== null && sharedBufferView !== void 0 ? sharedBufferView : sharedBufferView = new Int32Array(sharedBuffer !== null && sharedBuffer !== void 0 ? sharedBuffer : sharedBuffer = new SharedArrayBuffer(INT32_BYTES), 0, 1);
343
+ const useGlobals = finalGlobalShims.length > 0;
344
+ const useEval = isTs ? !tsUseEsm : !jsUseEsm && useGlobals;
345
+ const worker = new Worker(jsUseEsm && useGlobals || tsUseEsm && finalTsRunner === TsRunner.TsNode ? dataUrl(`${generateGlobals(finalWorkerPath, finalGlobalShims)};import '${String(workerPathUrl)}'`) : useEval ? `${generateGlobals(finalWorkerPath, finalGlobalShims, "require")};${encodeImportModule(finalWorkerPath, "require")}` : workerPathUrl, {
346
+ eval: useEval,
347
+ workerData: { sharedBuffer, workerPort, pnpLoaderPath },
348
+ transferList: [workerPort, ...transferList],
349
+ execArgv: finalExecArgv
350
+ });
351
+ let nextID = 0;
352
+ const receiveMessageWithId = (port, expectedId, waitingTimeout) => {
353
+ const start = Date.now();
354
+ const status = Atomics.wait(sharedBufferView, 0, 0, waitingTimeout);
355
+ Atomics.store(sharedBufferView, 0, 0);
356
+ if (!["ok", "not-equal"].includes(status)) {
357
+ const abortMsg = {
358
+ id: expectedId,
359
+ cmd: "abort"
360
+ };
361
+ port.postMessage(abortMsg);
362
+ throw new Error("Internal error: Atomics.wait() failed: " + status);
363
+ }
364
+ const _a = receiveMessageOnPort(mainPort).message, { id } = _a, message = __rest(_a, ["id"]);
365
+ if (id < expectedId) {
366
+ const waitingTime = Date.now() - start;
367
+ return receiveMessageWithId(port, expectedId, waitingTimeout ? waitingTimeout - waitingTime : void 0);
368
+ }
369
+ if (expectedId !== id) {
370
+ throw new Error(`Internal error: Expected id ${expectedId} but got id ${id}`);
371
+ }
372
+ return Object.assign({ id }, message);
373
+ };
374
+ const syncFn = (...args) => {
375
+ const id = nextID++;
376
+ const msg = { id, args };
377
+ worker.postMessage(msg);
378
+ const { result, error, properties } = receiveMessageWithId(mainPort, id, timeout);
379
+ if (error) {
380
+ throw Object.assign(error, properties);
381
+ }
382
+ return result;
383
+ };
384
+ worker.unref();
385
+ return syncFn;
386
+ }
387
+ function runAsWorker(fn) {
388
+ if (!workerData) {
389
+ return;
390
+ }
391
+ const { workerPort, sharedBuffer: sharedBuffer2, pnpLoaderPath } = workerData;
392
+ if (pnpLoaderPath && IS_NODE_20) {
393
+ module.register(pnpLoaderPath);
394
+ }
395
+ const sharedBufferView2 = new Int32Array(sharedBuffer2, 0, 1);
396
+ parentPort.on("message", ({ id, args }) => {
397
+ ;
398
+ (() => __awaiter(this, void 0, void 0, function* () {
399
+ let isAborted = false;
400
+ const handleAbortMessage = (msg2) => {
401
+ if (msg2.id === id && msg2.cmd === "abort") {
402
+ isAborted = true;
403
+ }
404
+ };
405
+ workerPort.on("message", handleAbortMessage);
406
+ let msg;
407
+ try {
408
+ msg = { id, result: yield fn(...args) };
409
+ } catch (error) {
410
+ msg = { id, error, properties: extractProperties(error) };
411
+ }
412
+ workerPort.off("message", handleAbortMessage);
413
+ if (isAborted) {
414
+ return;
415
+ }
416
+ workerPort.postMessage(msg);
417
+ Atomics.add(sharedBufferView2, 0, 1);
418
+ Atomics.notify(sharedBufferView2, 0);
419
+ }))();
420
+ });
421
+ }
422
+
423
+ export {
424
+ createSyncFn,
425
+ runAsWorker
426
+ };