@marko/vite 2.4.5 → 2.4.6

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,12 @@ 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
+ const fileName = id.slice(0, -query.length);
337
342
  let entryData;
338
- entrySources.set(fileName, "");
343
+ entryIds.add(fileName);
339
344
  if (isBuild) {
340
345
  const relativeFileName = import_path.default.posix.relative(root, fileName);
341
346
  const entryId = toEntryId(relativeFileName);
@@ -364,8 +369,9 @@ function markoPlugin(opts = {}) {
364
369
  basePathVar: isBuild ? basePathVar : void 0
365
370
  });
366
371
  }
367
- case browserEntryQuery: {
368
- return entrySources.get(id.slice(0, -browserEntryQuery.length));
372
+ case browserEntryQuery:
373
+ case browserQuery: {
374
+ return cachedSources.get(id.slice(0, -query.length)) || null;
369
375
  }
370
376
  }
371
377
  return virtualFiles.get(id) || null;
@@ -391,24 +397,26 @@ function markoPlugin(opts = {}) {
391
397
  if (!isMarkoFile(id)) {
392
398
  return null;
393
399
  }
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;
400
+ if (isSSR) {
401
+ if (linked) {
402
+ cachedSources.set(id, source);
403
+ if (serverManifest && entryIds.has(id)) {
404
+ serverManifest.entrySources[import_path.default.posix.relative(root, id)] = source;
405
+ }
406
+ }
407
+ if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
408
+ return createEsmWrapper(
409
+ id,
410
+ getExportIdentifiers(
411
+ (await compiler.compile(source, id, {
412
+ cache,
413
+ ast: true,
414
+ code: false,
415
+ output: "source",
416
+ sourceMaps: false
417
+ })).ast
418
+ )
419
+ );
412
420
  }
413
421
  }
414
422
  const compiled = await compiler.compile(
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,12 @@ 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
+ const fileName = id.slice(0, -query.length);
317
322
  let entryData;
318
- entrySources.set(fileName, "");
323
+ entryIds.add(fileName);
319
324
  if (isBuild) {
320
325
  const relativeFileName = path.posix.relative(root, fileName);
321
326
  const entryId = toEntryId(relativeFileName);
@@ -344,8 +349,9 @@ function markoPlugin(opts = {}) {
344
349
  basePathVar: isBuild ? basePathVar : void 0
345
350
  });
346
351
  }
347
- case browserEntryQuery: {
348
- return entrySources.get(id.slice(0, -browserEntryQuery.length));
352
+ case browserEntryQuery:
353
+ case browserQuery: {
354
+ return cachedSources.get(id.slice(0, -query.length)) || null;
349
355
  }
350
356
  }
351
357
  return virtualFiles.get(id) || null;
@@ -371,24 +377,26 @@ function markoPlugin(opts = {}) {
371
377
  if (!isMarkoFile(id)) {
372
378
  return null;
373
379
  }
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;
380
+ if (isSSR) {
381
+ if (linked) {
382
+ cachedSources.set(id, source);
383
+ if (serverManifest && entryIds.has(id)) {
384
+ serverManifest.entrySources[path.posix.relative(root, id)] = source;
385
+ }
386
+ }
387
+ if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
388
+ return createEsmWrapper(
389
+ id,
390
+ getExportIdentifiers(
391
+ (await compiler.compile(source, id, {
392
+ cache,
393
+ ast: true,
394
+ code: false,
395
+ output: "source",
396
+ sourceMaps: false
397
+ })).ast
398
+ )
399
+ );
392
400
  }
393
401
  }
394
402
  const compiled = await compiler.compile(
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.6",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {