@vrowzer/vite-plugin 0.0.0 → 0.1.0

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.
Files changed (37) hide show
  1. package/dist/ide/assets/{css.worker-uWEFNxvl.js → css.worker-CTXDGAqi.js} +14 -14
  2. package/dist/ide/assets/{html.worker-1tLoAl5Z.js → html.worker-DoEWTywB.js} +15 -15
  3. package/dist/ide/assets/json.worker-C4xqSSAJ.js +58 -0
  4. package/dist/ide/assets/{ts.worker-BFpNHPy5.js → ts.worker-CEDDf2SQ.js} +121 -106
  5. package/dist/ide/{cssMode-B5DtFEwy.js → cssMode-Bx4pwP7t.js} +4 -4
  6. package/dist/ide/{handlebars-BcqMM6pa.js → handlebars-niagtI6v.js} +1 -1
  7. package/dist/ide/{html-CxO5OaJl.js → html-vu3rIOlL.js} +1 -1
  8. package/dist/ide/{htmlMode-DxpUG2jm.js → htmlMode-DJyFRqKm.js} +4 -4
  9. package/dist/ide/ide.css +1 -1
  10. package/dist/ide/ide.js +1764 -1700
  11. package/dist/ide/{javascript-CvtLx4_Z.js → javascript-BaiNOEh_.js} +1 -2
  12. package/dist/ide/{jsonMode-LVtiYWKr.js → jsonMode-DLQ0j1a3.js} +4 -4
  13. package/dist/ide/{lspLanguageFeatures-BDyekQt2.js → lspLanguageFeatures-CY50NMcK.js} +1 -1
  14. package/dist/ide/{mdx-Sun87_nd.js → mdx-DhZSVASO.js} +1 -1
  15. package/dist/ide/{monaco.contribution-DVj8eGe_.js → monaco.contribution-4V6BrQ5P.js} +2 -2
  16. package/dist/ide/{toggleHighContrast-DI4ZeqFk.js → toggleHighContrast-DzGcs4Kw.js} +16604 -16528
  17. package/dist/ide/{tsMode-BKTkt1bt.js → tsMode-D6r_-_rM.js} +5 -5
  18. package/dist/ide/{typescript-CHC4VYBW.js → typescript-DM2pFj0X.js} +1 -1
  19. package/dist/ide/{workers-IG_hD8Jy.js → workers-DRkYqOHL.js} +1 -1
  20. package/dist/ide/{xml-C0QFzMaz.js → xml-DrNRTdma.js} +3 -3
  21. package/dist/ide/{yaml-o-RP7lYY.js → yaml-ck2FlP6B.js} +1 -1
  22. package/dist/index.d.mts +0 -2
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +231 -116
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/manifest-generate.d.mts.map +1 -1
  27. package/dist/manifest-generate.mjs +10 -11
  28. package/dist/manifest-generate.mjs.map +1 -1
  29. package/package.json +18 -17
  30. package/dist/ide/assets/json.worker-CL3sVQd6.js +0 -58
  31. /package/dist/ide/{css-CPSW8DVZ.js → css-jRa-sq2v.js} +0 -0
  32. /package/dist/ide/{graphql-BteLL2CG.js → graphql-BfD0A3oq.js} +0 -0
  33. /package/dist/ide/{less-BubkcFWW.js → less-BpXfi39Z.js} +0 -0
  34. /package/dist/ide/{markdown-DPB5N4OB.js → markdown-C_jeeMr1.js} +0 -0
  35. /package/dist/ide/{pug-BONHZNEg.js → pug-DThx5NHO.js} +0 -0
  36. /package/dist/ide/{scss-0r6NeK1P.js → scss-CAhEnFoL.js} +0 -0
  37. /package/dist/ide/{shell-Vh_eZpea.js → shell-DZxOw2Ds.js} +0 -0
@@ -1,6 +1,6 @@
1
- import { a as e, c as t, i as n, n as r, o as i, r as a } from "./toggleHighContrast-DI4ZeqFk.js";
2
- import { t as o } from "./monaco.contribution-DVj8eGe_.js";
3
- import { t as s } from "./workers-IG_hD8Jy.js";
1
+ import { a as e, c as t, i as n, n as r, o as i, r as a } from "./toggleHighContrast-DzGcs4Kw.js";
2
+ import { t as o } from "./monaco.contribution-4V6BrQ5P.js";
3
+ import { t as s } from "./workers-DRkYqOHL.js";
4
4
  //#region ../../node_modules/.pnpm/monaco-editor@0.55.1/node_modules/monaco-editor/esm/vs/language/typescript/workerManager.js
5
5
  var c = class {
6
6
  constructor(e, t) {
@@ -22,7 +22,7 @@ var c = class {
22
22
  moduleId: "vs/language/typescript/tsWorker",
23
23
  createWorker: () => new Worker(new URL(
24
24
  /* @vite-ignore */
25
- "/assets/ts.worker-BFpNHPy5.js",
25
+ "/assets/ts.worker-CEDDf2SQ.js",
26
26
  "" + import.meta.url
27
27
  ), { type: "module" }),
28
28
  label: this._modeId,
@@ -75,7 +75,7 @@ var f = class {
75
75
  this._worker = e, this._libFiles = {}, this._hasFetchedLibFiles = !1, this._fetchLibFilesPromise = null;
76
76
  }
77
77
  isLibFile(e) {
78
- return e && e.path.indexOf("/lib.") === 0 ? !!l[e.path.slice(1)] : !1;
78
+ return e ? e.path.indexOf("/lib.") === 0 && !!l[e.path.slice(1)] : !1;
79
79
  }
80
80
  getOrCreateModel(t) {
81
81
  let n = e.parse(t), r = i.getModel(n);
@@ -1,4 +1,4 @@
1
- import { c as e } from "./toggleHighContrast-DI4ZeqFk.js";
1
+ import { c as e } from "./toggleHighContrast-DzGcs4Kw.js";
2
2
  //#region ../../node_modules/.pnpm/monaco-editor@0.55.1/node_modules/monaco-editor/esm/vs/basic-languages/typescript/typescript.js
3
3
  var t = {
4
4
  wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
@@ -1,4 +1,4 @@
1
- import { o as e } from "./toggleHighContrast-DI4ZeqFk.js";
1
+ import { o as e } from "./toggleHighContrast-DzGcs4Kw.js";
2
2
  //#region ../../node_modules/.pnpm/monaco-editor@0.55.1/node_modules/monaco-editor/esm/vs/common/workers.js
3
3
  function t(e, t) {
4
4
  let n = globalThis.MonacoEnvironment;
@@ -1,4 +1,4 @@
1
- import { c as e } from "./toggleHighContrast-DI4ZeqFk.js";
1
+ import { c as e } from "./toggleHighContrast-DzGcs4Kw.js";
2
2
  //#region ../../node_modules/.pnpm/monaco-editor@0.55.1/node_modules/monaco-editor/esm/vs/basic-languages/xml/xml.js
3
3
  var t = {
4
4
  comments: { blockComment: ["<!--", "-->"] },
@@ -32,11 +32,11 @@ var t = {
32
32
  }
33
33
  ],
34
34
  onEnterRules: [{
35
- beforeText: RegExp("<([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$", "i"),
35
+ beforeText: /* @__PURE__ */ RegExp("<([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$", "i"),
36
36
  afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>$/i,
37
37
  action: { indentAction: e.IndentAction.IndentOutdent }
38
38
  }, {
39
- beforeText: RegExp("<(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$", "i"),
39
+ beforeText: /* @__PURE__ */ RegExp("<(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$", "i"),
40
40
  action: { indentAction: e.IndentAction.Indent }
41
41
  }]
42
42
  }, n = {
@@ -1,4 +1,4 @@
1
- import { c as e } from "./toggleHighContrast-DI4ZeqFk.js";
1
+ import { c as e } from "./toggleHighContrast-DzGcs4Kw.js";
2
2
  //#region ../../node_modules/.pnpm/monaco-editor@0.55.1/node_modules/monaco-editor/esm/vs/basic-languages/yaml/yaml.js
3
3
  var t = {
4
4
  comments: { lineComment: "#" },
package/dist/index.d.mts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { GenerateManifestLog, GenerateManifestOptions, ManifestResult, generateManifest } from "./manifest-generate.mjs";
2
2
  import { Plugin } from "vite";
3
-
4
3
  //#region src/options.d.ts
5
-
6
4
  /**
7
5
  * vite-plugin-vrowzer options
8
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/options.ts","../src/manifest.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAaA;AAKiB,UALA,KAAA,CAKA;EAwBA,IAAA,EAAA,MAAA,GA5BA,MA4BiB;EAQjB,WAAA,EAAA,MAAA;AAqBjB;AAkBa,UAvEI,sBAAA,CAuEJ;EAuCS;;;;;;ACxFtB;;;;ECRgB;;;;;;;;;;;;UFUC,iBAAA;;;;;;;UAQA,0BAAA;;;;;;;;;kBASC;;;;;;;;;;;UAYD,cAAA;;;;;;;;;;;;;;;;;;aAkBJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAuCS;;;;;iBAIL;;;;AAA0B,iBC5F3B,eAAA,CAAA,CD4F2B,EC5FR,MD4FQ;;;AAlF1B,iBElBD,OAAA,CFkBC,OASC,CATyB,EElBV,cF2Bf,CAAA,EE3BqC,MF2BpB,EAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/options.ts","../src/manifest.ts","../src/index.ts"],"mappings":";;;;;;;;UAaiB;EACf,eAAe;EACf;;UAGe;;;;;;;;;;EAUf;;;;;EAKA;;;;;;EAMA;;UAGe;;;;;EAKf;;UAGe;;;;;;;;;EASf,gBAAgB;;;;;;;;;EAShB;;UAGe;;;;;;;;;;;;;;EAcf;;;;EAIA,WAAW;;;;;;EAMX;;;;;;EAMA;;;;;;EAMA;;;;;;;;;;;;EAYA;;;;;;;;;EASA;IAAY,QAAQ;;;;;EAIpB,eAAe;;;;iBC5FD,mBAAmB;;;iBCJnB,QAAQ,UAAS,iBAAsB"}
package/dist/index.mjs CHANGED
@@ -3,17 +3,15 @@ import { createRequire } from "node:module";
3
3
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
4
4
  import path, { dirname, extname, join, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
- import inject from "@rollup/plugin-inject";
6
+ import * as injectModule from "@rollup/plugin-inject";
7
7
  import ServiceWorker from "@vrowzer/unplugin-service-worker/vite";
8
8
  import { createDebug } from "obug";
9
- import { minifySync, parseSync } from "rolldown/experimental";
9
+ import { minifySync, parseSync } from "rolldown/utils";
10
10
  import { rolldown } from "rolldown";
11
11
  import { createBirpc } from "birpc";
12
12
  import { WebSocketServer } from "ws";
13
-
14
- //#region rolldown:runtime
15
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
16
-
13
+ //#region \0rolldown/runtime.js
14
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
17
15
  //#endregion
18
16
  //#region src/auto-manifest.ts
19
17
  /**
@@ -32,7 +30,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
32
30
  */
33
31
  const debug$8 = createDebug("vite-plugin-vrowzer:auto-manifest");
34
32
  const VIRTUAL_MODULE_ID = "virtual:vrowzer-manifest";
35
- const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
33
+ const RESOLVED_VIRTUAL_MODULE_ID = "\0virtual:vrowzer-manifest";
36
34
  const CACHE_DIR_NAME = ".vrowzer-manifest";
37
35
  const MANIFEST_FILENAME = "manifest.json";
38
36
  const HASH_FILENAME = "_hash";
@@ -42,7 +40,7 @@ const LOCKFILE_NAMES = [
42
40
  "yarn.lock",
43
41
  "bun.lock"
44
42
  ];
45
- const MINIFIABLE_EXTENSIONS$1 = new Set([
43
+ const MINIFIABLE_EXTENSIONS$1 = /* @__PURE__ */ new Set([
46
44
  ".js",
47
45
  ".mjs",
48
46
  ".cjs"
@@ -190,7 +188,6 @@ function autoManifestPlugin(manifestOptions) {
190
188
  }
191
189
  };
192
190
  }
193
-
194
191
  //#endregion
195
192
  //#region src/alias.ts
196
193
  /**
@@ -241,7 +238,6 @@ function resolveAliases(extra) {
241
238
  if (extra) Object.assign(aliases, extra);
242
239
  return aliases;
243
240
  }
244
-
245
241
  //#endregion
246
242
  //#region src/env.ts
247
243
  /**
@@ -255,7 +251,7 @@ function resolveAliases(extra) {
255
251
  * @license MIT
256
252
  */
257
253
  const debug$7 = createDebug("vite-plugin-vrowzer:env");
258
- const picocolorsBrowser = resolve(dirname(createRequire(import.meta.url).resolve("picocolors")), "picocolors.browser.js");
254
+ const picocolorsBrowser = resolve(dirname(fileURLToPath(import.meta.resolve("picocolors"))), "picocolors.browser.js");
259
255
  function envPlugin(_options) {
260
256
  return {
261
257
  name: "vrowzer:env",
@@ -291,7 +287,6 @@ function envPlugin(_options) {
291
287
  }
292
288
  };
293
289
  }
294
-
295
290
  //#endregion
296
291
  //#region src/ide.ts
297
292
  /**
@@ -363,12 +358,12 @@ function generateIdeHtml(base, cssFile) {
363
358
  </html>`;
364
359
  }
365
360
  function findAvailablePort(preferredPort) {
366
- return new Promise((resolve$1, reject) => {
361
+ return new Promise((resolve, reject) => {
367
362
  const { createServer } = __require("node:net");
368
363
  const server = createServer();
369
364
  const port = preferredPort ?? 7900;
370
365
  server.listen(port, () => {
371
- server.close(() => resolve$1(port));
366
+ server.close(() => resolve(port));
372
367
  });
373
368
  server.on("error", () => {
374
369
  server.close();
@@ -376,7 +371,7 @@ function findAvailablePort(preferredPort) {
376
371
  next.listen(0, () => {
377
372
  const addr = next.address();
378
373
  const p = typeof addr === "object" && addr ? addr.port : 0;
379
- next.close(() => resolve$1(p));
374
+ next.close(() => resolve(p));
380
375
  });
381
376
  next.on("error", reject);
382
377
  });
@@ -434,8 +429,8 @@ function idePlugin(options) {
434
429
  debug$6("birpc WebSocket server listening on port", rpcPort);
435
430
  wss.on("connection", (ws) => {
436
431
  debug$6("IDE client connected");
437
- const rpc = createBirpc({ async writeFile(path$1, content) {
438
- const absPath = resolve(sourceDir, path$1.startsWith("/") ? path$1.slice(1) : path$1);
432
+ const rpc = createBirpc({ async writeFile(path, content) {
433
+ const absPath = resolve(sourceDir, path.startsWith("/") ? path.slice(1) : path);
439
434
  debug$6("writeFile:", absPath);
440
435
  writeFileSync(absPath, content, "utf-8");
441
436
  } }, {
@@ -490,7 +485,8 @@ function idePlugin(options) {
490
485
  const assetName = url.slice(`${IDE_BASE}/dist/`.length);
491
486
  const assetPath = join(ideDistDir, assetName);
492
487
  if (existsSync(assetPath)) {
493
- const mime = MIME_TYPES[extname(assetName)] || "application/octet-stream";
488
+ const ext = extname(assetName);
489
+ const mime = MIME_TYPES[ext] || "application/octet-stream";
494
490
  debug$6("serving IDE asset:", assetName);
495
491
  res.writeHead(200, {
496
492
  "Content-Type": mime,
@@ -507,7 +503,6 @@ function idePlugin(options) {
507
503
  }
508
504
  };
509
505
  }
510
-
511
506
  //#endregion
512
507
  //#region src/extract.ts
513
508
  /**
@@ -555,7 +550,7 @@ function isViteImport(source) {
555
550
  * 5. Remove Vrowzer() calls
556
551
  * 6. Generate Worker config source
557
552
  */
558
- function extractWorkerConfig(source, configPath, _options = {}) {
553
+ function extractWorkerConfig(source, configPath, options = {}) {
559
554
  const unsupported = [];
560
555
  const ast = parseSync(configPath, source).program;
561
556
  const imports = collectImports(ast);
@@ -591,7 +586,6 @@ function extractWorkerConfig(source, configPath, _options = {}) {
591
586
  } else if (expr.type === "ConditionalExpression" || expr.type === "LogicalExpression") unsupported.push(`conditional plugin: ${source.slice(expr.start, expr.end)}`);
592
587
  else unsupported.push(`non-call plugin: ${source.slice(expr.start, expr.end)}`);
593
588
  }
594
- if (unsupported.length > 0) debug$5("unsupported patterns", unsupported);
595
589
  const workerPlugins = pluginCalls.filter((p) => {
596
590
  if (!p.importSource) return true;
597
591
  return !isWorkerExcludedImport(p.importSource);
@@ -652,11 +646,123 @@ function extractWorkerConfig(source, configPath, _options = {}) {
652
646
  }
653
647
  }
654
648
  }
649
+ const forwardedProps = extractForwardedProperties(source, configObj);
650
+ extractInputProperties(source, configObj, forwardedProps, unsupported);
651
+ const forwardedServerProps = [];
652
+ if (options.serverOrigin !== void 0) forwardedServerProps.push(`origin: ${JSON.stringify(options.serverOrigin)}`);
653
+ if (options.serverForwardConsole !== void 0) forwardedServerProps.push(`forwardConsole: ${JSON.stringify(options.serverForwardConsole)}`);
654
+ if (forwardedServerProps.length > 0) forwardedProps.set("server", `{ ${forwardedServerProps.join(", ")} }`);
655
+ if (unsupported.length > 0) debug$5("unsupported patterns", unsupported);
655
656
  return {
656
- code: generateWorkerSource(source, ast, imports, workerPlugins, neededImportSources, neededLocalNames),
657
+ code: generateWorkerSource(source, ast, imports, workerPlugins, neededImportSources, neededLocalNames, forwardedProps),
657
658
  unsupported
658
659
  };
659
660
  }
661
+ /**
662
+ * Config properties that should be forwarded to Worker config.
663
+ * These are extracted as raw source code from the config object.
664
+ */
665
+ const FORWARDED_PROPERTIES = ["define", "html"];
666
+ function extractForwardedProperties(source, configObj) {
667
+ const props = /* @__PURE__ */ new Map();
668
+ for (const p of configObj.properties) {
669
+ if (p.type !== "Property") continue;
670
+ const key = p.key.type === "Identifier" ? p.key.name : null;
671
+ if (key && FORWARDED_PROPERTIES.includes(key)) props.set(key, source.slice(p.value.start, p.value.end));
672
+ }
673
+ return props;
674
+ }
675
+ function extractInputProperties(source, configObj, forwardedProps, unsupported) {
676
+ let hasUnknownTopLevelInput = false;
677
+ for (const property of configObj.properties) if (property.type === "SpreadElement") {
678
+ unsupported.push(`config spread element: ${source.slice(property.start, property.end)}`);
679
+ hasUnknownTopLevelInput = true;
680
+ } else if (property.type === "Property" && property.computed) {
681
+ unsupported.push(`computed config key: ${source.slice(property.start, property.end)}`);
682
+ hasUnknownTopLevelInput = true;
683
+ }
684
+ if (hasUnknownTopLevelInput) return;
685
+ const inputProp = findObjectProperty(configObj, "input");
686
+ if (inputProp) if (isStaticInputOption(inputProp.value)) forwardedProps.set("input", source.slice(inputProp.value.start, inputProp.value.end));
687
+ else unsupported.push(`input is not an inline string, array, or record: ${source.slice(inputProp.value.start, inputProp.value.end)}`);
688
+ const environmentsProp = findObjectProperty(configObj, "environments");
689
+ if (!environmentsProp) return;
690
+ const environmentsValue = unwrapStaticExpression(environmentsProp.value);
691
+ if (environmentsValue.type !== "ObjectExpression") {
692
+ unsupported.push(`environments is not an inline object: ${source.slice(environmentsProp.value.start, environmentsProp.value.end)}`);
693
+ return;
694
+ }
695
+ const entries = [];
696
+ let hasUnknownEnvironment = false;
697
+ for (const environmentProp of environmentsValue.properties) {
698
+ if (environmentProp.type === "SpreadElement") {
699
+ unsupported.push(`environment spread element: ${source.slice(environmentProp.start, environmentProp.end)}`);
700
+ hasUnknownEnvironment = true;
701
+ continue;
702
+ }
703
+ if (environmentProp.type !== "Property") continue;
704
+ const environmentName = getStaticPropertyName(environmentProp);
705
+ if (environmentName === null) {
706
+ unsupported.push(`computed environment key: ${source.slice(environmentProp.start, environmentProp.end)}`);
707
+ hasUnknownEnvironment = true;
708
+ continue;
709
+ }
710
+ const environmentValue = unwrapStaticExpression(environmentProp.value);
711
+ if (environmentValue.type !== "ObjectExpression") {
712
+ unsupported.push(`environment ${JSON.stringify(environmentName)} is not an inline object: ${source.slice(environmentProp.value.start, environmentProp.value.end)}`);
713
+ continue;
714
+ }
715
+ let hasUnknownEnvironmentInput = false;
716
+ for (const property of environmentValue.properties) if (property.type === "SpreadElement") {
717
+ unsupported.push(`environment ${JSON.stringify(environmentName)} spread element: ${source.slice(property.start, property.end)}`);
718
+ hasUnknownEnvironmentInput = true;
719
+ } else if (property.type === "Property" && property.computed) {
720
+ unsupported.push(`environment ${JSON.stringify(environmentName)} has a computed key: ${source.slice(property.start, property.end)}`);
721
+ hasUnknownEnvironmentInput = true;
722
+ }
723
+ if (hasUnknownEnvironmentInput) continue;
724
+ const input = findObjectProperty(environmentValue, "input");
725
+ if (!input) continue;
726
+ if (!isStaticInputOption(input.value)) {
727
+ unsupported.push(`environment ${JSON.stringify(environmentName)} input is not an inline string, array, or record: ${source.slice(input.value.start, input.value.end)}`);
728
+ continue;
729
+ }
730
+ entries.push(`${JSON.stringify(environmentName)}: { input: ${source.slice(input.value.start, input.value.end)} }`);
731
+ }
732
+ if (entries.length > 0 && !hasUnknownEnvironment) forwardedProps.set("environments", `{ ${entries.join(", ")} }`);
733
+ }
734
+ function findObjectProperty(object, name) {
735
+ for (let index = object.properties.length - 1; index >= 0; index--) {
736
+ const property = object.properties[index];
737
+ if (!property || property.type !== "Property") continue;
738
+ if (!property.computed && getPropertyName(property) === name) return property;
739
+ }
740
+ }
741
+ function getStaticPropertyName(property) {
742
+ if (property.computed) return null;
743
+ return getPropertyName(property);
744
+ }
745
+ function getPropertyName(property) {
746
+ if (property.key.type === "Identifier") return property.key.name;
747
+ if (property.key.type === "Literal" && typeof property.key.value === "string") return property.key.value;
748
+ return null;
749
+ }
750
+ function unwrapStaticExpression(expression) {
751
+ let current = expression;
752
+ while (current.expression && (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression")) current = current.expression;
753
+ return current;
754
+ }
755
+ function isStaticInputOption(expression) {
756
+ const value = unwrapStaticExpression(expression);
757
+ if (isStaticString(value)) return true;
758
+ if (value.type === "ArrayExpression") return value.elements.every((element) => element !== null && element.type !== "SpreadElement" && isStaticString(element));
759
+ if (value.type === "ObjectExpression") return value.properties.every((property) => property.type === "Property" && !property.computed && isStaticString(property.value));
760
+ return false;
761
+ }
762
+ function isStaticString(expression) {
763
+ const value = unwrapStaticExpression(expression);
764
+ return value.type === "Literal" && typeof value.value === "string" || value.type === "TemplateLiteral" && value.expressions.length === 0;
765
+ }
660
766
  function collectImports(ast) {
661
767
  const imports = [];
662
768
  for (const node of ast.body) {
@@ -714,7 +820,7 @@ function analyzeCallExpression(call, imports) {
714
820
  hasArgs: call.arguments.length > 0
715
821
  };
716
822
  }
717
- function generateWorkerSource(source, ast, imports, plugins, neededImportSources, neededLocalNames) {
823
+ function generateWorkerSource(source, ast, imports, plugins, neededImportSources, neededLocalNames, forwardedProps = /* @__PURE__ */ new Map()) {
718
824
  const lines = [];
719
825
  const emittedSources = /* @__PURE__ */ new Set();
720
826
  for (const imp of imports) {
@@ -785,14 +891,14 @@ function generateWorkerSource(source, ast, imports, plugins, neededImportSources
785
891
  const callSource = source.slice(plugin.start, plugin.end);
786
892
  lines.push(` ${callSource},`);
787
893
  }
788
- lines.push(" ]");
894
+ lines.push(" ],");
895
+ for (const [key, value] of forwardedProps) lines.push(` ${key}: ${value},`);
789
896
  lines.push("}");
790
897
  return lines.join("\n");
791
898
  }
792
899
  function generateFallbackCode() {
793
900
  return "export default { plugins: [] }";
794
901
  }
795
-
796
902
  //#endregion
797
903
  //#region src/options.ts
798
904
  /**
@@ -828,7 +934,6 @@ function resolveOptions(options) {
828
934
  resolve: options.resolve
829
935
  };
830
936
  }
831
-
832
937
  //#endregion
833
938
  //#region src/prebundle.ts
834
939
  /**
@@ -1028,7 +1133,6 @@ function inlineCreateRequirePlugin() {
1028
1133
  }
1029
1134
  };
1030
1135
  }
1031
-
1032
1136
  //#endregion
1033
1137
  //#region src/rolldown.ts
1034
1138
  /**
@@ -1050,6 +1154,10 @@ function rolldownPlugin(_options) {
1050
1154
  configResolved(config) {
1051
1155
  resolvedOutDir = path.resolve(config.root, config.build.outDir);
1052
1156
  },
1157
+ /**
1158
+ * Copy rolldown WASM binary and sub-worker for production builds.
1159
+ * Both the chunk and WASM/worker files end up in dist/assets/.
1160
+ */
1053
1161
  writeBundle() {
1054
1162
  const assetsDir = path.resolve(resolvedOutDir, "assets");
1055
1163
  debug$3("copy-rolldown-wasm: assetsDir ", assetsDir);
@@ -1062,7 +1170,6 @@ function rolldownPlugin(_options) {
1062
1170
  }
1063
1171
  };
1064
1172
  }
1065
-
1066
1173
  //#endregion
1067
1174
  //#region src/server.ts
1068
1175
  /**
@@ -1115,19 +1222,21 @@ function normalizeBasePath(basePath) {
1115
1222
  if (basePath.endsWith("/")) return basePath.slice(0, -1);
1116
1223
  else return basePath;
1117
1224
  }
1118
-
1119
1225
  //#endregion
1120
1226
  //#region src/virtual.ts
1121
- function generateWebWorkerEntry(configPath, resolve$1) {
1227
+ /**
1228
+ * @author kazuya kawaguchi (a.k.a. kazupon)
1229
+ * @license MIT
1230
+ */
1231
+ function generateWebWorkerEntry(configPath, resolve) {
1122
1232
  return `
1123
1233
  import { initWebWorker } from 'vrowzer/web-worker-core'
1124
1234
  import config from '${configPath}'
1125
1235
  const resolved = config.default ?? config
1126
- ${resolve$1 ? `\nconst workerResolve = ${JSON.stringify(resolve$1)}\nObject.assign(resolved, { resolve: workerResolve })` : ""}
1236
+ ${resolve ? `\nconst workerResolve = ${JSON.stringify(resolve)}\nObject.assign(resolved, { resolve: workerResolve })` : ""}
1127
1237
  initWebWorker(resolved)
1128
1238
  `;
1129
1239
  }
1130
-
1131
1240
  //#endregion
1132
1241
  //#region src/manifest.ts
1133
1242
  /**
@@ -1145,7 +1254,7 @@ initWebWorker(resolved)
1145
1254
  * @author kazuya kawaguchi (a.k.a. kazupon)
1146
1255
  * @license MIT
1147
1256
  */
1148
- const MINIFIABLE_EXTENSIONS = new Set([
1257
+ const MINIFIABLE_EXTENSIONS = /* @__PURE__ */ new Set([
1149
1258
  ".js",
1150
1259
  ".mjs",
1151
1260
  ".cjs"
@@ -1187,8 +1296,8 @@ function VrowzerManifest() {
1187
1296
  for (const [virtualPath, relPath] of Object.entries(files)) try {
1188
1297
  let content = readFileSync(resolve(manifestDir, relPath), "utf-8");
1189
1298
  if (minify && MINIFIABLE_EXTENSIONS.has(extname(virtualPath))) {
1190
- const result$1 = minifySync(virtualPath, content);
1191
- if (result$1.code) content = result$1.code;
1299
+ const result = minifySync(virtualPath, content);
1300
+ if (result.code) content = result.code;
1192
1301
  }
1193
1302
  resolved[virtualPath] = content;
1194
1303
  } catch (e) {
@@ -1212,7 +1321,6 @@ function VrowzerManifest() {
1212
1321
  }
1213
1322
  };
1214
1323
  }
1215
-
1216
1324
  //#endregion
1217
1325
  //#region src/index.ts
1218
1326
  /**
@@ -1225,6 +1333,7 @@ function VrowzerManifest() {
1225
1333
  * @license MIT
1226
1334
  */
1227
1335
  const debug = createDebug("vite-plugin-vrowzer:index");
1336
+ const inject = injectModule.default;
1228
1337
  function Vrowzer(options = {}) {
1229
1338
  const resolvedOptions = resolveOptions(options);
1230
1339
  const root = process.cwd();
@@ -1238,98 +1347,104 @@ function Vrowzer(options = {}) {
1238
1347
  map: null
1239
1348
  };
1240
1349
  }
1241
- const plugins = [
1242
- {
1243
- name: "vrowzer:config",
1244
- resolveId(id) {
1245
- if (id.startsWith("@vrowzer/")) try {
1246
- return fileURLToPath(import.meta.resolve(id));
1247
- } catch {}
1248
- },
1249
- config() {
1250
- const workerPlugins = [
1251
- {
1252
- name: "vrowzer:worker-resolve",
1253
- resolveId(id) {
1254
- if (id.startsWith("@vrowzer/")) try {
1255
- return fileURLToPath(import.meta.resolve(id));
1256
- } catch {}
1257
- }
1258
- },
1259
- {
1260
- name: "vrowzer:worker-process-inject",
1261
- options(inputOptions) {
1262
- inputOptions.transform ??= {};
1263
- inputOptions.transform.inject = {
1264
- ...inputOptions.transform.inject,
1265
- process: "@vrowzer/node-polyfill/process"
1266
- };
1267
- }
1268
- },
1269
- {
1270
- name: "vrowzer:web-worker-config-inject",
1271
- transform: workerEntryTransform
1350
+ const vrowzerConfigPlugin = {
1351
+ name: "vrowzer:config",
1352
+ resolveId(id) {
1353
+ if (id.startsWith("@vrowzer/")) try {
1354
+ return fileURLToPath(import.meta.resolve(id));
1355
+ } catch {}
1356
+ },
1357
+ config() {
1358
+ const workerPlugins = [
1359
+ {
1360
+ name: "vrowzer:worker-resolve",
1361
+ resolveId(id) {
1362
+ if (id.startsWith("@vrowzer/")) try {
1363
+ return fileURLToPath(import.meta.resolve(id));
1364
+ } catch {}
1272
1365
  }
1273
- ];
1274
- return {
1275
- resolve: { alias: [{
1276
- find: /^vite$/,
1277
- replacement: "@vrowzer/vite-dev-server/vite"
1278
- }] },
1279
- worker: { plugins: () => workerPlugins }
1280
- };
1281
- },
1282
- async configResolved(config) {
1283
- isBuild = config.command === "build";
1284
- const viteConfigPath = config.configFile;
1285
- if (!viteConfigPath) {
1286
- debug("no vite.config.ts found, skipping extraction");
1287
- return;
1288
- }
1289
- debug("extracting worker config from:", viteConfigPath);
1290
- cleanOutputDir(config.root);
1291
- const configDir = dirname(viteConfigPath);
1292
- const { code: workerSource, unsupported } = extractWorkerConfig(readFileSync(viteConfigPath, "utf-8"), viteConfigPath);
1293
- if (unsupported.length > 0) debug("unsupported patterns found:", unsupported);
1294
- debug("generated worker source:\n", workerSource);
1295
- bundledConfigPath = await prebundleWorkerConfig({
1296
- workerSource,
1297
- root: config.root,
1298
- configDir
1299
- });
1300
- debug("bundled config path:", bundledConfigPath);
1301
- },
1302
- closeBundle() {
1303
- if (isBuild && bundledConfigPath) {
1304
- cleanOutputDir(root);
1305
- debug("cleaned up prebundle output after build");
1366
+ },
1367
+ {
1368
+ name: "vrowzer:worker-process-inject",
1369
+ options(inputOptions) {
1370
+ inputOptions.transform ??= {};
1371
+ inputOptions.transform.inject = {
1372
+ ...inputOptions.transform.inject,
1373
+ process: "@vrowzer/node-polyfill/process"
1374
+ };
1375
+ }
1376
+ },
1377
+ {
1378
+ name: "vrowzer:web-worker-config-inject",
1379
+ transform: workerEntryTransform
1306
1380
  }
1307
- },
1308
- transform(code, id) {
1309
- return workerEntryTransform(code, id);
1381
+ ];
1382
+ return {
1383
+ resolve: { alias: [{
1384
+ find: /^vite$/,
1385
+ replacement: "@vrowzer/vite-dev-server/vite"
1386
+ }] },
1387
+ worker: { plugins: () => workerPlugins }
1388
+ };
1389
+ },
1390
+ async configResolved(config) {
1391
+ isBuild = config.command === "build";
1392
+ const viteConfigPath = config.configFile;
1393
+ if (!viteConfigPath) {
1394
+ debug("no vite.config.ts found, skipping extraction");
1395
+ return;
1310
1396
  }
1397
+ debug("extracting worker config from:", viteConfigPath);
1398
+ cleanOutputDir(config.root);
1399
+ const configDir = dirname(viteConfigPath);
1400
+ const { code: workerSource, unsupported } = extractWorkerConfig(readFileSync(viteConfigPath, "utf-8"), viteConfigPath, {
1401
+ serverOrigin: config.server.origin,
1402
+ serverForwardConsole: config.server.forwardConsole
1403
+ });
1404
+ if (unsupported.length > 0) debug("unsupported patterns found:", unsupported);
1405
+ debug("generated worker source:\n", workerSource);
1406
+ bundledConfigPath = await prebundleWorkerConfig({
1407
+ workerSource,
1408
+ root: config.root,
1409
+ configDir
1410
+ });
1411
+ debug("bundled config path:", bundledConfigPath);
1311
1412
  },
1312
- serverMiddlewarePlugin(resolvedOptions),
1313
- {
1314
- ...inject({
1315
- process: "@vrowzer/node-polyfill/process",
1316
- exclude: [/node_modules\/\.vite\//, /node_modules\/\.vrowzer\//]
1317
- }),
1318
- apply: "serve"
1413
+ closeBundle() {
1414
+ if (isBuild && bundledConfigPath) {
1415
+ cleanOutputDir(root);
1416
+ debug("cleaned up prebundle output after build");
1417
+ }
1319
1418
  },
1419
+ transform(code, id) {
1420
+ return workerEntryTransform(code, id);
1421
+ }
1422
+ };
1423
+ const processInjectPlugin = {
1424
+ ...inject({
1425
+ process: "@vrowzer/node-polyfill/process",
1426
+ exclude: [/node_modules\/\.vite\//, /node_modules\/\.vrowzer\//]
1427
+ }),
1428
+ apply: "serve"
1429
+ };
1430
+ const serviceWorkerPlugin = ServiceWorker({
1431
+ serviceWorkerAllowed: "/",
1432
+ format: "esm",
1433
+ ...resolvedOptions.serviceWorkerEntry ? { entry: resolvedOptions.serviceWorkerEntry } : {}
1434
+ });
1435
+ const plugins = [
1436
+ vrowzerConfigPlugin,
1437
+ serverMiddlewarePlugin(resolvedOptions),
1438
+ processInjectPlugin,
1320
1439
  envPlugin(resolvedOptions),
1321
1440
  rolldownPlugin(resolvedOptions),
1322
- ServiceWorker({
1323
- serviceWorkerAllowed: "/",
1324
- format: "esm",
1325
- ...resolvedOptions.serviceWorkerEntry ? { entry: resolvedOptions.serviceWorkerEntry } : {}
1326
- })
1441
+ serviceWorkerPlugin
1327
1442
  ];
1328
1443
  if (resolvedOptions.auto) plugins.unshift(autoManifestPlugin(resolvedOptions.manifest));
1329
1444
  if (resolvedOptions.ide.enabled) plugins.push(idePlugin(resolvedOptions));
1330
1445
  return plugins;
1331
1446
  }
1332
-
1333
1447
  //#endregion
1334
1448
  export { Vrowzer, VrowzerManifest, generateManifest };
1449
+
1335
1450
  //# sourceMappingURL=index.mjs.map