@vrowzer/vite-plugin 0.1.1 → 0.1.3

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 (27) hide show
  1. package/README.md +77 -7
  2. package/dist/ide/assets/{css.worker-CTXDGAqi.js → css.worker-B3bjHA4E.js} +12 -12
  3. package/dist/ide/assets/{html.worker-DoEWTywB.js → html.worker-CdKyo4PJ.js} +15 -15
  4. package/dist/ide/assets/json.worker-Dv30RK47.js +58 -0
  5. package/dist/ide/assets/{ts.worker-CEDDf2SQ.js → ts.worker-BMQFrgtp.js} +43 -43
  6. package/dist/ide/{cssMode-Bx4pwP7t.js → cssMode-BjT8Ilz9.js} +6 -6
  7. package/dist/ide/{handlebars-niagtI6v.js → handlebars-D8oWedcX.js} +1 -1
  8. package/dist/ide/{html-vu3rIOlL.js → html-BtI1mgAb.js} +1 -1
  9. package/dist/ide/{htmlMode-DJyFRqKm.js → htmlMode-nJv21bwP.js} +6 -6
  10. package/dist/ide/ide.js +1018 -1013
  11. package/dist/ide/{javascript-BaiNOEh_.js → javascript-CsLyoDyq.js} +1 -1
  12. package/dist/ide/{jsonMode-DLQ0j1a3.js → jsonMode-Gp85lTwz.js} +26 -25
  13. package/dist/ide/{lspLanguageFeatures-CY50NMcK.js → lspLanguageFeatures-Bh3u5Duz.js} +4 -4
  14. package/dist/ide/{mdx-DhZSVASO.js → mdx-BXUwpKml.js} +1 -1
  15. package/dist/ide/{monaco.contribution-4V6BrQ5P.js → monaco.contribution-Df9Y1epv.js} +2 -2
  16. package/dist/ide/{toggleHighContrast-DzGcs4Kw.js → toggleHighContrast-BAyJBPWB.js} +11852 -11696
  17. package/dist/ide/{tsMode-D6r_-_rM.js → tsMode-DW5hjWiU.js} +4 -4
  18. package/dist/ide/{typescript-DM2pFj0X.js → typescript-DdUYzFye.js} +1 -1
  19. package/dist/ide/{workers-DRkYqOHL.js → workers-_EnUbIXZ.js} +1 -1
  20. package/dist/ide/{xml-DrNRTdma.js → xml-YkclMbCx.js} +1 -1
  21. package/dist/ide/{yaml-ck2FlP6B.js → yaml-nzDq4-PC.js} +1 -1
  22. package/dist/index.d.mts +7 -2
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +69 -27
  25. package/dist/index.mjs.map +1 -1
  26. package/package.json +12 -12
  27. package/dist/ide/assets/json.worker-C4xqSSAJ.js +0 -58
@@ -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-DzGcs4Kw.js";
2
- import { t as o } from "./monaco.contribution-4V6BrQ5P.js";
3
- import { t as s } from "./workers-DRkYqOHL.js";
1
+ import { a as e, c as t, i as n, n as r, o as i, r as a } from "./toggleHighContrast-BAyJBPWB.js";
2
+ import { t as o } from "./monaco.contribution-Df9Y1epv.js";
3
+ import { t as s } from "./workers-_EnUbIXZ.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-CEDDf2SQ.js",
25
+ "/assets/ts.worker-BMQFrgtp.js",
26
26
  "" + import.meta.url
27
27
  ), { type: "module" }),
28
28
  label: this._modeId,
@@ -1,4 +1,4 @@
1
- import { c as e } from "./toggleHighContrast-DzGcs4Kw.js";
1
+ import { c as e } from "./toggleHighContrast-BAyJBPWB.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-DzGcs4Kw.js";
1
+ import { o as e } from "./toggleHighContrast-BAyJBPWB.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-DzGcs4Kw.js";
1
+ import { c as e } from "./toggleHighContrast-BAyJBPWB.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: ["<!--", "-->"] },
@@ -1,4 +1,4 @@
1
- import { c as e } from "./toggleHighContrast-DzGcs4Kw.js";
1
+ import { c as e } from "./toggleHighContrast-BAyJBPWB.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
@@ -81,20 +81,25 @@ interface VrowzerOptions {
81
81
  manifest?: VrowzerManifestOptions;
82
82
  /**
83
83
  * The base path for the preview system location, which is used to serve the preview files via service worker of Vrowzer.
84
+ * This is the source of truth for both the application and Service Worker bundles.
84
85
  *
85
86
  * @default '/__preview__/'
86
87
  */
87
88
  basePath?: string;
88
89
  /**
89
- * The scope for the service worker of Vrowzer, which determines the range of URLs that the service worker will control.
90
+ * The scope for the service worker of Vrowzer, which determines the range of URLs that
91
+ * the service worker will control and the `Service-Worker-Allowed` response header.
92
+ * The value is injected into the Vrowzer runtime, so its corresponding option can be
93
+ * omitted. This registration scope is independent of the preview `basePath`.
90
94
  *
91
95
  * @default '/' (the entire origin)
92
96
  */
93
97
  serviceWorkerScope?: string;
94
98
  /**
95
99
  * The version of the service worker for Vrowzer, which can be used to manage updates and cache invalidation for the preview system.
100
+ * This is the source of truth for both the application and Service Worker bundles.
96
101
  *
97
- * @default 'SERVICE_WORKER_VERSION'
102
+ * @default 'vrowzer-v1'
98
103
  */
99
104
  serviceWorkerVersion?: string;
100
105
  /**
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/options.ts","../src/manifest.ts","../src/index.ts"],"mappings":";;;;;;;;UAgBiB;EACf,eAAe;EACf;;UAGe;;;;;;;;;;EAUf;;;;;EAKA;;;;;;EAMA;;UAGe;;;;;EAKf;;UAGe;;;;;;;;;EASf,gBAAgB;;;;;;;;;EAShB;;UAGe;;;;;;;;;;;;;;EAcf;;;;EAIA,WAAW;;;;;;;EAOX;;;;;;;;;EASA;;;;;;;EAOA;;;;;;;;;;;;EAYA;;;;;;;;;EASA;IAAY,QAAQ;;;;;EAIpB,eAAe;;;;iBCpGD,mBAAmB;;;iBCJnB,QAAQ,UAAS,iBAAsB"}
package/dist/index.mjs CHANGED
@@ -30,7 +30,7 @@ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
30
30
  */
31
31
  const debug$8 = createDebug("vite-plugin-vrowzer:auto-manifest");
32
32
  const VIRTUAL_MODULE_ID = "virtual:vrowzer-manifest";
33
- const RESOLVED_VIRTUAL_MODULE_ID = "\0virtual:vrowzer-manifest";
33
+ const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
34
34
  const CACHE_DIR_NAME = ".vrowzer-manifest";
35
35
  const MANIFEST_FILENAME = "manifest.json";
36
36
  const HASH_FILENAME = "_hash";
@@ -251,8 +251,14 @@ function resolveAliases(extra) {
251
251
  * @license MIT
252
252
  */
253
253
  const debug$7 = createDebug("vite-plugin-vrowzer:env");
254
+ const VROWZER_PREVIEW_BASE_PATH_DEFINE = "__VROWZER_INTERNAL_PREVIEW_BASE_PATH__";
255
+ const VROWZER_SERVICE_WORKER_SCOPE_DEFINE = "__VROWZER_INTERNAL_SERVICE_WORKER_SCOPE__";
256
+ const VROWZER_SERVICE_WORKER_VERSION_DEFINE = "__VROWZER_INTERNAL_SERVICE_WORKER_VERSION__";
254
257
  const picocolorsBrowser = resolve(dirname(fileURLToPath(import.meta.resolve("picocolors"))), "picocolors.browser.js");
255
- function envPlugin(_options) {
258
+ function envPlugin(options) {
259
+ const serializedBasePath = JSON.stringify(options.basePath);
260
+ const serializedServiceWorkerScope = JSON.stringify(options.serviceWorkerScope);
261
+ const serializedServiceWorkerVersion = JSON.stringify(options.serviceWorkerVersion);
256
262
  return {
257
263
  name: "vrowzer:env",
258
264
  options(inputOptions) {
@@ -265,7 +271,12 @@ function envPlugin(_options) {
265
271
  },
266
272
  config(_config, _env) {
267
273
  return {
268
- define: { "import.meta.env.DEBUG": JSON.stringify(process.env.DEBUG || "") },
274
+ define: {
275
+ "import.meta.env.DEBUG": JSON.stringify(process.env.DEBUG || ""),
276
+ [VROWZER_PREVIEW_BASE_PATH_DEFINE]: serializedBasePath,
277
+ [VROWZER_SERVICE_WORKER_SCOPE_DEFINE]: serializedServiceWorkerScope,
278
+ [VROWZER_SERVICE_WORKER_VERSION_DEFINE]: serializedServiceWorkerVersion
279
+ },
269
280
  resolve: { alias: resolveAliases({
270
281
  "node:process": "@vrowzer/node-polyfill/process",
271
282
  "process/": "@vrowzer/node-polyfill/process",
@@ -274,16 +285,24 @@ function envPlugin(_options) {
274
285
  }) },
275
286
  worker: { format: "es" },
276
287
  server: { headers: {
277
- "Service-Worker-Allowed": "/",
288
+ "Service-Worker-Allowed": options.serviceWorkerScope,
278
289
  "Cross-Origin-Opener-Policy": "same-origin",
279
290
  "Cross-Origin-Embedder-Policy": "credentialless"
280
291
  } },
281
292
  preview: { headers: {
282
- "Service-Worker-Allowed": "/",
293
+ "Service-Worker-Allowed": options.serviceWorkerScope,
283
294
  "Cross-Origin-Opener-Policy": "same-origin",
284
295
  "Cross-Origin-Embedder-Policy": "credentialless"
285
296
  } }
286
297
  };
298
+ },
299
+ configResolved(config) {
300
+ const resolvedBasePath = config.define?.[VROWZER_PREVIEW_BASE_PATH_DEFINE];
301
+ if (resolvedBasePath !== serializedBasePath) throw new Error(`Vrowzer reserved define ${VROWZER_PREVIEW_BASE_PATH_DEFINE} must be ${serializedBasePath}, received ${JSON.stringify(resolvedBasePath)}`);
302
+ const resolvedServiceWorkerScope = config.define?.[VROWZER_SERVICE_WORKER_SCOPE_DEFINE];
303
+ if (resolvedServiceWorkerScope !== serializedServiceWorkerScope) throw new Error(`Vrowzer reserved define ${VROWZER_SERVICE_WORKER_SCOPE_DEFINE} must be ${serializedServiceWorkerScope}, received ${JSON.stringify(resolvedServiceWorkerScope)}`);
304
+ const resolvedServiceWorkerVersion = config.define?.[VROWZER_SERVICE_WORKER_VERSION_DEFINE];
305
+ if (resolvedServiceWorkerVersion !== serializedServiceWorkerVersion) throw new Error(`Vrowzer reserved define ${VROWZER_SERVICE_WORKER_VERSION_DEFINE} must be ${serializedServiceWorkerVersion}, received ${JSON.stringify(resolvedServiceWorkerVersion)}`);
287
306
  }
288
307
  };
289
308
  }
@@ -683,8 +702,10 @@ function extractInputProperties(source, configObj, forwardedProps, unsupported)
683
702
  }
684
703
  if (hasUnknownTopLevelInput) return;
685
704
  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)}`);
705
+ if (inputProp) {
706
+ if (isStaticInputOption(inputProp.value)) forwardedProps.set("input", source.slice(inputProp.value.start, inputProp.value.end));
707
+ else unsupported.push(`input is not an inline string, array, or record: ${source.slice(inputProp.value.start, inputProp.value.end)}`);
708
+ }
688
709
  const environmentsProp = findObjectProperty(configObj, "environments");
689
710
  if (!environmentsProp) return;
690
711
  const environmentsValue = unwrapStaticExpression(environmentsProp.value);
@@ -910,6 +931,8 @@ function generateFallbackCode() {
910
931
  * @author kazuya kawaguchi (a.k.a. kazupon)
911
932
  * @license MIT
912
933
  */
934
+ const DEFAULT_BASE_PATH = "/__preview__/";
935
+ const DEFAULT_SERVICE_WORKER_VERSION = "vrowzer-v1";
913
936
  function resolveDefaultServiceWorkerEntry() {
914
937
  try {
915
938
  return fileURLToPath(import.meta.resolve("vrowzer/service-worker"));
@@ -917,6 +940,12 @@ function resolveDefaultServiceWorkerEntry() {
917
940
  return "";
918
941
  }
919
942
  }
943
+ function normalizeBasePath(basePath) {
944
+ if (basePath.length === 0 || !basePath.startsWith("/") || basePath.startsWith("//") || basePath.includes("?") || basePath.includes("#")) throw new TypeError(`Vrowzer basePath must be a non-root absolute pathname without a query or hash, received ${JSON.stringify(basePath)}`);
945
+ const pathname = basePath.replace(/\/+$/, "");
946
+ if (pathname.length === 0) throw new TypeError("Vrowzer basePath must not be the origin root \"/\"");
947
+ return `${pathname}/`;
948
+ }
920
949
  function resolveOptions(options) {
921
950
  const ide = options.experimental?.ide;
922
951
  return {
@@ -927,9 +956,9 @@ function resolveOptions(options) {
927
956
  port: typeof ide === "object" ? ide.port : void 0,
928
957
  devtools: options.experimental?.devtools ?? false
929
958
  },
930
- basePath: options.basePath ?? "/__preview__/",
959
+ basePath: normalizeBasePath(options.basePath ?? DEFAULT_BASE_PATH),
931
960
  serviceWorkerScope: options.serviceWorkerScope ?? "/",
932
- serviceWorkerVersion: options.serviceWorkerVersion ?? "SERVICE_WORKER_VERSION",
961
+ serviceWorkerVersion: options.serviceWorkerVersion ?? DEFAULT_SERVICE_WORKER_VERSION,
933
962
  serviceWorkerEntry: options.serviceWorkerEntry ?? resolveDefaultServiceWorkerEntry(),
934
963
  resolve: options.resolve
935
964
  };
@@ -1117,7 +1146,8 @@ function inlineCreateRequirePlugin() {
1117
1146
  const result = code.replace(RE, (match, specifier) => {
1118
1147
  if (!specifier.endsWith(".json")) return match;
1119
1148
  try {
1120
- const content = readFileSync(createRequire(id).resolve(specifier), "utf-8");
1149
+ const resolvedPath = createRequire(id).resolve(specifier);
1150
+ const content = readFileSync(resolvedPath, "utf-8");
1121
1151
  modified = true;
1122
1152
  debug$4("inlineCreateRequire: inlined", specifier, "from", id);
1123
1153
  return JSON.stringify(JSON.parse(content));
@@ -1145,28 +1175,41 @@ function inlineCreateRequirePlugin() {
1145
1175
  * @license MIT
1146
1176
  */
1147
1177
  const debug$3 = createDebug("vite-plugin-vrowzer:rolldown");
1178
+ function rewriteRolldownAssetUrls(code) {
1179
+ return code.replace(/(["'])\.\.\/(rolldown-(?:binding\.wasm32-wasi\.wasm|worker\.js)\?__vrowzer_internal_asset=rolldown)\1/g, "$1./$2$1");
1180
+ }
1181
+ function renderRolldownAssetChunk(code) {
1182
+ const rewritten = rewriteRolldownAssetUrls(code);
1183
+ return rewritten === code ? null : rewritten;
1184
+ }
1185
+ function rolldownWorkerAssetPlugin() {
1186
+ return {
1187
+ name: "vrowzer:worker-rolldown-assets",
1188
+ renderChunk: renderRolldownAssetChunk
1189
+ };
1190
+ }
1148
1191
  const rolldownDistDir = path.resolve(path.dirname(fileURLToPath(import.meta.resolve("@vrowzer/rolldown/package.json"))), "dist");
1149
1192
  debug$3("rolldownDistDir ", rolldownDistDir);
1150
1193
  function rolldownPlugin(_options) {
1151
- let resolvedOutDir = "";
1194
+ let resolvedAssetsDir = "";
1152
1195
  return {
1153
1196
  name: "vrowzer:rolldown",
1154
1197
  configResolved(config) {
1155
- resolvedOutDir = path.resolve(config.root, config.build.outDir);
1198
+ resolvedAssetsDir = path.resolve(config.root, config.build.outDir, config.build.assetsDir);
1156
1199
  },
1200
+ renderChunk: renderRolldownAssetChunk,
1157
1201
  /**
1158
1202
  * Copy rolldown WASM binary and sub-worker for production builds.
1159
- * Both the chunk and WASM/worker files end up in dist/assets/.
1203
+ * The worker chunks and these files share the configured assets directory.
1160
1204
  */
1161
1205
  writeBundle() {
1162
- const assetsDir = path.resolve(resolvedOutDir, "assets");
1163
- debug$3("copy-rolldown-wasm: assetsDir ", assetsDir);
1206
+ debug$3("copy-rolldown-wasm: assetsDir ", resolvedAssetsDir);
1164
1207
  const wasmSrc = path.resolve(rolldownDistDir, "rolldown-binding.wasm32-wasi.wasm");
1165
1208
  debug$3("copy-rolldown-wasm: wasmSrc ", wasmSrc);
1166
1209
  const workerSrc = path.resolve(rolldownDistDir, "worker.js");
1167
1210
  debug$3("copy-rolldown-wasm: workerSrc ", workerSrc);
1168
- if (existsSync(wasmSrc)) copyFileSync(wasmSrc, path.resolve(assetsDir, "rolldown-binding.wasm32-wasi.wasm"));
1169
- if (existsSync(workerSrc)) copyFileSync(workerSrc, path.resolve(assetsDir, "rolldown-worker.js"));
1211
+ if (existsSync(wasmSrc)) copyFileSync(wasmSrc, path.resolve(resolvedAssetsDir, "rolldown-binding.wasm32-wasi.wasm"));
1212
+ if (existsSync(workerSrc)) copyFileSync(workerSrc, path.resolve(resolvedAssetsDir, "rolldown-worker.js"));
1170
1213
  }
1171
1214
  };
1172
1215
  }
@@ -1189,10 +1232,12 @@ const debug$2 = createDebug("vite-plugin-vrowzer:server");
1189
1232
  * preview requests bypass service worker and hit Vite directly.
1190
1233
  * Without this guard, Vite returns the main page HTML, causing recursive display.
1191
1234
  */
1192
- function previewGuardMiddleware(previewBase = "/__preview__") {
1235
+ function previewGuardMiddleware(previewBase) {
1236
+ const previewRoot = previewBase.slice(0, -1);
1193
1237
  return (req, res, next) => {
1194
1238
  debug$2("previewGuardMiddleware: previewBase ", previewBase, " req.url ", req.url);
1195
- if (req.url?.startsWith(previewBase)) {
1239
+ const pathname = req.url ? new URL(req.url, "http://localhost").pathname : void 0;
1240
+ if (pathname === previewRoot || pathname?.startsWith(previewBase)) {
1196
1241
  res.writeHead(503, {
1197
1242
  "Content-Type": "text/html",
1198
1243
  "Retry-After": "1"
@@ -1206,7 +1251,7 @@ function previewGuardMiddleware(previewBase = "/__preview__") {
1206
1251
  };
1207
1252
  }
1208
1253
  function serverMiddlewarePlugin(options) {
1209
- const middleware = previewGuardMiddleware(normalizeBasePath(options.basePath));
1254
+ const middleware = previewGuardMiddleware(options.basePath);
1210
1255
  return {
1211
1256
  name: "vrowzer:server-middleware",
1212
1257
  configureServer(server) {
@@ -1217,11 +1262,6 @@ function serverMiddlewarePlugin(options) {
1217
1262
  }
1218
1263
  };
1219
1264
  }
1220
- function normalizeBasePath(basePath) {
1221
- debug$2("normalizeBasePath: basePath ", basePath);
1222
- if (basePath.endsWith("/")) return basePath.slice(0, -1);
1223
- else return basePath;
1224
- }
1225
1265
  //#endregion
1226
1266
  //#region src/virtual.ts
1227
1267
  /**
@@ -1377,9 +1417,11 @@ function Vrowzer(options = {}) {
1377
1417
  {
1378
1418
  name: "vrowzer:web-worker-config-inject",
1379
1419
  transform: workerEntryTransform
1380
- }
1420
+ },
1421
+ rolldownWorkerAssetPlugin()
1381
1422
  ];
1382
1423
  return {
1424
+ optimizeDeps: { exclude: ["@vrowzer/vite-dev-server"] },
1383
1425
  resolve: { alias: [{
1384
1426
  find: /^vite$/,
1385
1427
  replacement: "@vrowzer/vite-dev-server/vite"
@@ -1428,7 +1470,7 @@ function Vrowzer(options = {}) {
1428
1470
  apply: "serve"
1429
1471
  };
1430
1472
  const serviceWorkerPlugin = ServiceWorker({
1431
- serviceWorkerAllowed: "/",
1473
+ serviceWorkerAllowed: resolvedOptions.serviceWorkerScope,
1432
1474
  format: "esm",
1433
1475
  ...resolvedOptions.serviceWorkerEntry ? { entry: resolvedOptions.serviceWorkerEntry } : {}
1434
1476
  });