@marko/vite 2.4.5 → 2.4.7

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/dist/index.js CHANGED
@@ -52,6 +52,7 @@ const queryReg = /\?marko-.+$/;
52
52
  const browserEntryQuery = "?marko-browser-entry";
53
53
  const serverEntryQuery = "?marko-server-entry";
54
54
  const virtualFileQuery = "?marko-virtual";
55
+ const browserQuery = "?marko-browser";
55
56
  const manifestFileName = "manifest.json";
56
57
  const markoExt = ".marko";
57
58
  const htmlExt = ".html";
@@ -94,7 +95,8 @@ function markoPlugin(opts = {}) {
94
95
  let store;
95
96
  let CJSTemplates;
96
97
  let basePath = "/";
97
- const entrySources = /* @__PURE__ */ new Map();
98
+ const entryIds = /* @__PURE__ */ new Set();
99
+ const cachedSources = /* @__PURE__ */ new Map();
98
100
  const transformWatchFiles = /* @__PURE__ */ new Map();
99
101
  const transformOptionalFiles = /* @__PURE__ */ new Map();
100
102
  return [
@@ -238,8 +240,9 @@ function markoPlugin(opts = {}) {
238
240
  ssrConfig.hot = domConfig.hot = true;
239
241
  devServer = _server;
240
242
  devServer.watcher.on("all", (type, filename) => {
243
+ cachedSources.delete(filename);
241
244
  if (type === "unlink") {
242
- entrySources.delete(filename);
245
+ entryIds.delete(filename);
243
246
  transformWatchFiles.delete(filename);
244
247
  transformOptionalFiles.delete(filename);
245
248
  }
@@ -274,10 +277,9 @@ function markoPlugin(opts = {}) {
274
277
  );
275
278
  inputOptions.input = toHTMLEntries(root, serverManifest.entries);
276
279
  for (const entry in serverManifest.entrySources) {
277
- entrySources.set(
278
- normalizePath(import_path.default.resolve(root, entry)),
279
- serverManifest.entrySources[entry]
280
- );
280
+ const id = normalizePath(import_path.default.resolve(root, entry));
281
+ entryIds.add(id);
282
+ cachedSources.set(id, serverManifest.entrySources[entry]);
281
283
  }
282
284
  } catch (err) {
283
285
  this.error(
@@ -302,6 +304,8 @@ function markoPlugin(opts = {}) {
302
304
  importeeQuery = serverEntryQuery;
303
305
  } else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a = this.getModuleInfo(importer)) == null ? void 0 : _a.isEntry)) {
304
306
  importeeQuery = browserEntryQuery;
307
+ } else if (linked && !ssr && !importeeQuery && isMarkoFile(importee)) {
308
+ importeeQuery = browserQuery;
305
309
  }
306
310
  if (importeeQuery) {
307
311
  const resolved = importee[0] === "." ? {
@@ -331,11 +335,29 @@ function markoPlugin(opts = {}) {
331
335
  return null;
332
336
  },
333
337
  async load(id) {
334
- switch (getMarkoQuery(id)) {
338
+ const query = getMarkoQuery(id);
339
+ switch (query) {
335
340
  case serverEntryQuery: {
336
- const fileName = id.slice(0, -serverEntryQuery.length);
341
+ entryIds.add(id.slice(0, -query.length));
342
+ return null;
343
+ }
344
+ case browserEntryQuery:
345
+ case browserQuery: {
346
+ return cachedSources.get(id.slice(0, -query.length)) || null;
347
+ }
348
+ }
349
+ return virtualFiles.get(id) || null;
350
+ },
351
+ async transform(source, id, ssr) {
352
+ const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
353
+ const query = getMarkoQuery(id);
354
+ if (query && !query.startsWith(virtualFileQuery)) {
355
+ id = id.slice(0, -query.length);
356
+ if (query === serverEntryQuery) {
357
+ const fileName = id;
337
358
  let entryData;
338
- entrySources.set(fileName, "");
359
+ id = `${id.slice(0, -markoExt.length)}.entry.marko`;
360
+ cachedSources.set(fileName, source);
339
361
  if (isBuild) {
340
362
  const relativeFileName = import_path.default.posix.relative(root, fileName);
341
363
  const entryId = toEntryId(relativeFileName);
@@ -352,63 +374,44 @@ function markoPlugin(opts = {}) {
352
374
  basePath,
353
375
  await devServer.transformIndexHtml(
354
376
  "/",
355
- (0, import_manifest_generator.generateInputDoc)(posixFileNameToURL(fileName, root))
377
+ (0, import_manifest_generator.generateInputDoc)(
378
+ posixFileNameToURL(fileName, root) + browserEntryQuery
379
+ )
356
380
  )
357
381
  )
358
382
  );
359
383
  }
360
- return (0, import_server_entry_template.default)({
384
+ source = await (0, import_server_entry_template.default)({
361
385
  fileName,
362
386
  entryData,
363
387
  runtimeId,
364
388
  basePathVar: isBuild ? basePathVar : void 0
365
389
  });
366
390
  }
367
- case browserEntryQuery: {
368
- return entrySources.get(id.slice(0, -browserEntryQuery.length));
369
- }
370
- }
371
- return virtualFiles.get(id) || null;
372
- },
373
- async transformIndexHtml(html) {
374
- if (isBuild) {
375
- return html;
376
- }
377
- return html.replace(
378
- /(src\s*=\s*(['"])(?:(?!\2).)*\.marko)(?:\?((?:(?!\2).)*))?\2/gim,
379
- (_, prefix, quote, query) => prefix + browserEntryQuery + (query ? "&" + query : "") + quote
380
- );
381
- },
382
- async transform(source, id, ssr) {
383
- const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
384
- const query = getMarkoQuery(id);
385
- if (query && !query.startsWith(virtualFileQuery)) {
386
- id = id.slice(0, -query.length);
387
- if (query === serverEntryQuery) {
388
- id = `${id.slice(0, -markoExt.length)}.entry.marko`;
389
- }
390
391
  }
391
392
  if (!isMarkoFile(id)) {
392
393
  return null;
393
394
  }
394
- if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
395
- return createEsmWrapper(
396
- id,
397
- getExportIdentifiers(
398
- (await compiler.compile(source, id, {
399
- cache,
400
- ast: true,
401
- code: false,
402
- output: "source",
403
- sourceMaps: false
404
- })).ast
405
- )
406
- );
407
- }
408
- if (isSSR && linked && entrySources.has(id)) {
409
- entrySources.set(id, source);
410
- if (serverManifest) {
411
- serverManifest.entrySources[import_path.default.posix.relative(root, id)] = source;
395
+ if (isSSR) {
396
+ if (linked) {
397
+ cachedSources.set(id, source);
398
+ if (serverManifest && entryIds.has(id)) {
399
+ serverManifest.entrySources[import_path.default.posix.relative(root, id)] = source;
400
+ }
401
+ }
402
+ if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
403
+ return createEsmWrapper(
404
+ id,
405
+ getExportIdentifiers(
406
+ (await compiler.compile(source, id, {
407
+ cache,
408
+ ast: true,
409
+ code: false,
410
+ output: "source",
411
+ sourceMaps: false
412
+ })).ast
413
+ )
414
+ );
412
415
  }
413
416
  }
414
417
  const compiled = await compiler.compile(
@@ -525,7 +528,7 @@ function toHTMLEntries(root, serverEntries) {
525
528
  const markoFile = import_path.default.posix.join(root, serverEntries[id]);
526
529
  const htmlFile = markoFile + htmlExt;
527
530
  virtualFiles.set(htmlFile, {
528
- code: (0, import_manifest_generator.generateInputDoc)(markoFile)
531
+ code: (0, import_manifest_generator.generateInputDoc)(markoFile + browserEntryQuery)
529
532
  });
530
533
  result.push(htmlFile);
531
534
  }
package/dist/index.mjs CHANGED
@@ -32,6 +32,7 @@ var queryReg = /\?marko-.+$/;
32
32
  var browserEntryQuery = "?marko-browser-entry";
33
33
  var serverEntryQuery = "?marko-server-entry";
34
34
  var virtualFileQuery = "?marko-virtual";
35
+ var browserQuery = "?marko-browser";
35
36
  var manifestFileName = "manifest.json";
36
37
  var markoExt = ".marko";
37
38
  var htmlExt = ".html";
@@ -74,7 +75,8 @@ function markoPlugin(opts = {}) {
74
75
  let store;
75
76
  let CJSTemplates;
76
77
  let basePath = "/";
77
- const entrySources = /* @__PURE__ */ new Map();
78
+ const entryIds = /* @__PURE__ */ new Set();
79
+ const cachedSources = /* @__PURE__ */ new Map();
78
80
  const transformWatchFiles = /* @__PURE__ */ new Map();
79
81
  const transformOptionalFiles = /* @__PURE__ */ new Map();
80
82
  return [
@@ -218,8 +220,9 @@ function markoPlugin(opts = {}) {
218
220
  ssrConfig.hot = domConfig.hot = true;
219
221
  devServer = _server;
220
222
  devServer.watcher.on("all", (type, filename) => {
223
+ cachedSources.delete(filename);
221
224
  if (type === "unlink") {
222
- entrySources.delete(filename);
225
+ entryIds.delete(filename);
223
226
  transformWatchFiles.delete(filename);
224
227
  transformOptionalFiles.delete(filename);
225
228
  }
@@ -254,10 +257,9 @@ function markoPlugin(opts = {}) {
254
257
  );
255
258
  inputOptions.input = toHTMLEntries(root, serverManifest.entries);
256
259
  for (const entry in serverManifest.entrySources) {
257
- entrySources.set(
258
- normalizePath(path.resolve(root, entry)),
259
- serverManifest.entrySources[entry]
260
- );
260
+ const id = normalizePath(path.resolve(root, entry));
261
+ entryIds.add(id);
262
+ cachedSources.set(id, serverManifest.entrySources[entry]);
261
263
  }
262
264
  } catch (err) {
263
265
  this.error(
@@ -282,6 +284,8 @@ function markoPlugin(opts = {}) {
282
284
  importeeQuery = serverEntryQuery;
283
285
  } else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a = this.getModuleInfo(importer)) == null ? void 0 : _a.isEntry)) {
284
286
  importeeQuery = browserEntryQuery;
287
+ } else if (linked && !ssr && !importeeQuery && isMarkoFile(importee)) {
288
+ importeeQuery = browserQuery;
285
289
  }
286
290
  if (importeeQuery) {
287
291
  const resolved = importee[0] === "." ? {
@@ -311,11 +315,29 @@ function markoPlugin(opts = {}) {
311
315
  return null;
312
316
  },
313
317
  async load(id) {
314
- switch (getMarkoQuery(id)) {
318
+ const query = getMarkoQuery(id);
319
+ switch (query) {
315
320
  case serverEntryQuery: {
316
- const fileName = id.slice(0, -serverEntryQuery.length);
321
+ entryIds.add(id.slice(0, -query.length));
322
+ return null;
323
+ }
324
+ case browserEntryQuery:
325
+ case browserQuery: {
326
+ return cachedSources.get(id.slice(0, -query.length)) || null;
327
+ }
328
+ }
329
+ return virtualFiles.get(id) || null;
330
+ },
331
+ async transform(source, id, ssr) {
332
+ const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
333
+ const query = getMarkoQuery(id);
334
+ if (query && !query.startsWith(virtualFileQuery)) {
335
+ id = id.slice(0, -query.length);
336
+ if (query === serverEntryQuery) {
337
+ const fileName = id;
317
338
  let entryData;
318
- entrySources.set(fileName, "");
339
+ id = `${id.slice(0, -markoExt.length)}.entry.marko`;
340
+ cachedSources.set(fileName, source);
319
341
  if (isBuild) {
320
342
  const relativeFileName = path.posix.relative(root, fileName);
321
343
  const entryId = toEntryId(relativeFileName);
@@ -332,63 +354,44 @@ function markoPlugin(opts = {}) {
332
354
  basePath,
333
355
  await devServer.transformIndexHtml(
334
356
  "/",
335
- generateInputDoc(posixFileNameToURL(fileName, root))
357
+ generateInputDoc(
358
+ posixFileNameToURL(fileName, root) + browserEntryQuery
359
+ )
336
360
  )
337
361
  )
338
362
  );
339
363
  }
340
- return server_entry_template_default({
364
+ source = await server_entry_template_default({
341
365
  fileName,
342
366
  entryData,
343
367
  runtimeId,
344
368
  basePathVar: isBuild ? basePathVar : void 0
345
369
  });
346
370
  }
347
- case browserEntryQuery: {
348
- return entrySources.get(id.slice(0, -browserEntryQuery.length));
349
- }
350
- }
351
- return virtualFiles.get(id) || null;
352
- },
353
- async transformIndexHtml(html) {
354
- if (isBuild) {
355
- return html;
356
- }
357
- return html.replace(
358
- /(src\s*=\s*(['"])(?:(?!\2).)*\.marko)(?:\?((?:(?!\2).)*))?\2/gim,
359
- (_, prefix, quote, query) => prefix + browserEntryQuery + (query ? "&" + query : "") + quote
360
- );
361
- },
362
- async transform(source, id, ssr) {
363
- const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
364
- const query = getMarkoQuery(id);
365
- if (query && !query.startsWith(virtualFileQuery)) {
366
- id = id.slice(0, -query.length);
367
- if (query === serverEntryQuery) {
368
- id = `${id.slice(0, -markoExt.length)}.entry.marko`;
369
- }
370
371
  }
371
372
  if (!isMarkoFile(id)) {
372
373
  return null;
373
374
  }
374
- if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
375
- return createEsmWrapper(
376
- id,
377
- getExportIdentifiers(
378
- (await compiler.compile(source, id, {
379
- cache,
380
- ast: true,
381
- code: false,
382
- output: "source",
383
- sourceMaps: false
384
- })).ast
385
- )
386
- );
387
- }
388
- if (isSSR && linked && entrySources.has(id)) {
389
- entrySources.set(id, source);
390
- if (serverManifest) {
391
- serverManifest.entrySources[path.posix.relative(root, id)] = source;
375
+ if (isSSR) {
376
+ if (linked) {
377
+ cachedSources.set(id, source);
378
+ if (serverManifest && entryIds.has(id)) {
379
+ serverManifest.entrySources[path.posix.relative(root, id)] = source;
380
+ }
381
+ }
382
+ if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
383
+ return createEsmWrapper(
384
+ id,
385
+ getExportIdentifiers(
386
+ (await compiler.compile(source, id, {
387
+ cache,
388
+ ast: true,
389
+ code: false,
390
+ output: "source",
391
+ sourceMaps: false
392
+ })).ast
393
+ )
394
+ );
392
395
  }
393
396
  }
394
397
  const compiled = await compiler.compile(
@@ -505,7 +508,7 @@ function toHTMLEntries(root, serverEntries) {
505
508
  const markoFile = path.posix.join(root, serverEntries[id]);
506
509
  const htmlFile = markoFile + htmlExt;
507
510
  virtualFiles.set(htmlFile, {
508
- code: generateInputDoc(markoFile)
511
+ code: generateInputDoc(markoFile + browserEntryQuery)
509
512
  });
510
513
  result.push(htmlFile);
511
514
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
3
  "description": "A Marko plugin for Vite",
4
- "version": "2.4.5",
4
+ "version": "2.4.7",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {