@marko/vite 2.4.0 → 2.4.2

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.
@@ -9,7 +9,11 @@ ${opts.basePathVar ? `
9
9
  static if (typeof ${opts.basePathVar} !== "string") throw new Error("${opts.basePathVar} must be defined when using basePathVar.");
10
10
  static if (!${opts.basePathVar}.endsWith("/")) throw new Error("${opts.basePathVar} must end with a '/' when using basePathVar.");
11
11
  ` : ""}${opts.runtimeId ? `$ out.global.runtimeId = ${JSON.stringify(opts.runtimeId)};
12
- ` : ""}$ (out.global.___viteEntries || (out.global.___viteEntries = [])).push(${opts.entryData});
12
+ $ out.global.___viteBaseVar = ${JSON.stringify(
13
+ "$mbp_" + opts.runtimeId
14
+ )};
15
+ ` : `$ out.global.___viteBaseVar = "$mbp";
16
+ `}$ (out.global.___viteEntries || (out.global.___viteEntries = [])).push(${opts.entryData});
13
17
  <_vite${base} slot="head-prepend"/>
14
18
  <_vite${base} slot="head"/>
15
19
  <_vite${base} slot="body-prepend"/>
@@ -39,8 +39,8 @@ function serialize(basePath, nodes, parts) {
39
39
  curString = "";
40
40
  break;
41
41
  case "link":
42
- if (tag.attribs.rel === "stylesheet") {
43
- urlAttr = "href";
42
+ urlAttr = "href";
43
+ if (tag.attribs.rel === "stylesheet" || tag.attribs.rel === "modulepreload" || tag.attribs.as === "style" || tag.attribs.as === "script") {
44
44
  parts.push(curString, 0 /* AssetAttrs */);
45
45
  curString = "";
46
46
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  serialize
3
- } from "./chunk-SELVH7LO.mjs";
3
+ } from "./chunk-BV667Z5U.mjs";
4
4
 
5
5
  // src/manifest-generator.ts
6
6
  import { Parser } from "htmlparser2";
@@ -34,15 +34,13 @@ $ if (!out.global.___viteRenderAssets) {
34
34
  ? ` nonce="${out.global.cspNonce.replace(/"/g, "&#39;")}"`
35
35
  : "";
36
36
  out.global.___viteRenderAssets = renderAssets;
37
-
38
- if (input.base) {
39
- out.global.___viteBasePath = input.base;
40
- out.script(`$mbp${out.global.runtimeId ? `_${out.global.runtimeId}` : ""}=${JSON.stringify(input.base)}`);
41
- } else {
42
- out.global.___viteBasePath = import.meta.env.BASE_URL;
43
- }
37
+ out.global.___viteBasePath = input.base || import.meta.env.BASE_URL;
44
38
  }
45
39
 
46
40
  <__flush_here_and_after__>
41
+ <if(input.base && !out.global.___flushedMBP)>
42
+ $ out.global.___flushedMBP = true;
43
+ $!{`<script${out.global.___viteInjectAttrs}>${out.global.___viteBaseVar}=${JSON.stringify(input.base)}</script>`}
44
+ </if>
47
45
  $!{out.global.___viteRenderAssets(input.slot)}
48
46
  </__flush_here_and_after__>
package/dist/index.js CHANGED
@@ -112,13 +112,14 @@ function markoPlugin(opts = {}) {
112
112
  let root;
113
113
  let devEntryFile;
114
114
  let devEntryFilePosix;
115
+ let isTest = false;
115
116
  let isBuild = false;
116
117
  let isSSRBuild = false;
117
118
  let devServer;
118
119
  let registeredTag = false;
119
120
  let serverManifest;
120
121
  let store;
121
- let cjsImports;
122
+ let CJSTemplates;
122
123
  let basePath = "/";
123
124
  const entrySources = /* @__PURE__ */ new Map();
124
125
  const transformWatchFiles = /* @__PURE__ */ new Map();
@@ -134,6 +135,7 @@ function markoPlugin(opts = {}) {
134
135
  root = normalizePath(config.root || process.cwd());
135
136
  devEntryFile = import_path.default.join(root, "index.html");
136
137
  devEntryFilePosix = normalizePath(devEntryFile);
138
+ isTest = env.mode === "test";
137
139
  isBuild = env.command === "build";
138
140
  isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
139
141
  store = opts.store || new import_store.FileStore(
@@ -166,12 +168,10 @@ function markoPlugin(opts = {}) {
166
168
  if (entry) {
167
169
  const relativePath = (0, import_relative_import_path.relativeImportPath)(devEntryFile, entry);
168
170
  taglibDeps.push(relativePath);
169
- if (isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
171
+ if (isTest || isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
170
172
  optimizeTaglibDeps.push(relativePath);
171
173
  } else {
172
- (cjsImports ?? (cjsImports = /* @__PURE__ */ new Map())).set(normalizePath(entry), {
173
- template: tag.template
174
- });
174
+ (CJSTemplates ?? (CJSTemplates = /* @__PURE__ */ new Set())).add(normalizePath(entry));
175
175
  }
176
176
  }
177
177
  }
@@ -320,22 +320,6 @@ function markoPlugin(opts = {}) {
320
320
  return null;
321
321
  },
322
322
  async load(id) {
323
- if (cjsImports == null ? void 0 : cjsImports.has(id)) {
324
- const tag = cjsImports.get(id);
325
- if (!tag.esmWrapper) {
326
- const { ast } = await compiler.compileFile(tag.template, {
327
- output: "source",
328
- ast: true,
329
- sourceMaps: false,
330
- code: false
331
- });
332
- tag.esmWrapper = await createEsmWrapper(
333
- id,
334
- getExportIdentifiers(ast)
335
- );
336
- }
337
- return tag.esmWrapper;
338
- }
339
323
  switch (getMarkoQuery(id)) {
340
324
  case serverEntryQuery: {
341
325
  const fileName = id.slice(0, -serverEntryQuery.length);
@@ -385,6 +369,7 @@ function markoPlugin(opts = {}) {
385
369
  );
386
370
  },
387
371
  async transform(source, id, ssr) {
372
+ const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
388
373
  const query = getMarkoQuery(id);
389
374
  if (query && !query.startsWith(virtualFileQuery)) {
390
375
  id = id.slice(0, -query.length);
@@ -392,10 +377,24 @@ function markoPlugin(opts = {}) {
392
377
  id = `${id.slice(0, -markoExt.length)}.entry.marko`;
393
378
  }
394
379
  }
395
- if (!isMarkoFile(id) || (cjsImports == null ? void 0 : cjsImports.has(id))) {
380
+ if (!isMarkoFile(id)) {
396
381
  return null;
397
382
  }
398
- if (ssr && entrySources.has(id)) {
383
+ if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
384
+ return createEsmWrapper(
385
+ id,
386
+ getExportIdentifiers(
387
+ (await compiler.compile(source, id, {
388
+ cache,
389
+ ast: true,
390
+ code: false,
391
+ output: "source",
392
+ sourceMaps: false
393
+ })).ast
394
+ )
395
+ );
396
+ }
397
+ if (isSSR && linked && entrySources.has(id)) {
399
398
  entrySources.set(id, source);
400
399
  if (serverManifest) {
401
400
  serverManifest.entrySources[import_path.default.posix.relative(root, id)] = source;
@@ -404,7 +403,7 @@ function markoPlugin(opts = {}) {
404
403
  const compiled = await compiler.compile(
405
404
  source,
406
405
  id,
407
- (typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
406
+ isSSR ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
408
407
  );
409
408
  const { map, meta } = compiled;
410
409
  let { code } = compiled;
package/dist/index.mjs CHANGED
@@ -4,11 +4,11 @@ import {
4
4
  import {
5
5
  generateDocManifest,
6
6
  generateInputDoc
7
- } from "./chunk-FHYNYHDA.mjs";
8
- import "./chunk-SELVH7LO.mjs";
7
+ } from "./chunk-ZCKVZIQN.mjs";
8
+ import "./chunk-BV667Z5U.mjs";
9
9
  import {
10
10
  server_entry_template_default
11
- } from "./chunk-U7T7RXXE.mjs";
11
+ } from "./chunk-6IJ5UJ3N.mjs";
12
12
  import "./chunk-KIYHBIE6.mjs";
13
13
  import {
14
14
  MemoryStore
@@ -92,13 +92,14 @@ function markoPlugin(opts = {}) {
92
92
  let root;
93
93
  let devEntryFile;
94
94
  let devEntryFilePosix;
95
+ let isTest = false;
95
96
  let isBuild = false;
96
97
  let isSSRBuild = false;
97
98
  let devServer;
98
99
  let registeredTag = false;
99
100
  let serverManifest;
100
101
  let store;
101
- let cjsImports;
102
+ let CJSTemplates;
102
103
  let basePath = "/";
103
104
  const entrySources = /* @__PURE__ */ new Map();
104
105
  const transformWatchFiles = /* @__PURE__ */ new Map();
@@ -114,6 +115,7 @@ function markoPlugin(opts = {}) {
114
115
  root = normalizePath(config.root || process.cwd());
115
116
  devEntryFile = path.join(root, "index.html");
116
117
  devEntryFilePosix = normalizePath(devEntryFile);
118
+ isTest = env.mode === "test";
117
119
  isBuild = env.command === "build";
118
120
  isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
119
121
  store = opts.store || new FileStore(
@@ -146,12 +148,10 @@ function markoPlugin(opts = {}) {
146
148
  if (entry) {
147
149
  const relativePath = relativeImportPath(devEntryFile, entry);
148
150
  taglibDeps.push(relativePath);
149
- if (isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
151
+ if (isTest || isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
150
152
  optimizeTaglibDeps.push(relativePath);
151
153
  } else {
152
- (cjsImports ?? (cjsImports = /* @__PURE__ */ new Map())).set(normalizePath(entry), {
153
- template: tag.template
154
- });
154
+ (CJSTemplates ?? (CJSTemplates = /* @__PURE__ */ new Set())).add(normalizePath(entry));
155
155
  }
156
156
  }
157
157
  }
@@ -300,22 +300,6 @@ function markoPlugin(opts = {}) {
300
300
  return null;
301
301
  },
302
302
  async load(id) {
303
- if (cjsImports == null ? void 0 : cjsImports.has(id)) {
304
- const tag = cjsImports.get(id);
305
- if (!tag.esmWrapper) {
306
- const { ast } = await compiler.compileFile(tag.template, {
307
- output: "source",
308
- ast: true,
309
- sourceMaps: false,
310
- code: false
311
- });
312
- tag.esmWrapper = await createEsmWrapper(
313
- id,
314
- getExportIdentifiers(ast)
315
- );
316
- }
317
- return tag.esmWrapper;
318
- }
319
303
  switch (getMarkoQuery(id)) {
320
304
  case serverEntryQuery: {
321
305
  const fileName = id.slice(0, -serverEntryQuery.length);
@@ -365,6 +349,7 @@ function markoPlugin(opts = {}) {
365
349
  );
366
350
  },
367
351
  async transform(source, id, ssr) {
352
+ const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
368
353
  const query = getMarkoQuery(id);
369
354
  if (query && !query.startsWith(virtualFileQuery)) {
370
355
  id = id.slice(0, -query.length);
@@ -372,10 +357,24 @@ function markoPlugin(opts = {}) {
372
357
  id = `${id.slice(0, -markoExt.length)}.entry.marko`;
373
358
  }
374
359
  }
375
- if (!isMarkoFile(id) || (cjsImports == null ? void 0 : cjsImports.has(id))) {
360
+ if (!isMarkoFile(id)) {
376
361
  return null;
377
362
  }
378
- if (ssr && entrySources.has(id)) {
363
+ if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
364
+ return createEsmWrapper(
365
+ id,
366
+ getExportIdentifiers(
367
+ (await compiler.compile(source, id, {
368
+ cache,
369
+ ast: true,
370
+ code: false,
371
+ output: "source",
372
+ sourceMaps: false
373
+ })).ast
374
+ )
375
+ );
376
+ }
377
+ if (isSSR && linked && entrySources.has(id)) {
379
378
  entrySources.set(id, source);
380
379
  if (serverManifest) {
381
380
  serverManifest.entrySources[path.posix.relative(root, id)] = source;
@@ -384,7 +383,7 @@ function markoPlugin(opts = {}) {
384
383
  const compiled = await compiler.compile(
385
384
  source,
386
385
  id,
387
- (typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
386
+ isSSR ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
388
387
  );
389
388
  const { map, meta } = compiled;
390
389
  let { code } = compiled;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  generateDocManifest,
3
3
  generateInputDoc
4
- } from "./chunk-FHYNYHDA.mjs";
5
- import "./chunk-SELVH7LO.mjs";
4
+ } from "./chunk-ZCKVZIQN.mjs";
5
+ import "./chunk-BV667Z5U.mjs";
6
6
  export {
7
7
  generateDocManifest,
8
8
  generateInputDoc
@@ -66,8 +66,8 @@ function serialize(basePath, nodes, parts) {
66
66
  curString = "";
67
67
  break;
68
68
  case "link":
69
- if (tag.attribs.rel === "stylesheet") {
70
- urlAttr = "href";
69
+ urlAttr = "href";
70
+ if (tag.attribs.rel === "stylesheet" || tag.attribs.rel === "modulepreload" || tag.attribs.as === "style" || tag.attribs.as === "script") {
71
71
  parts.push(curString, 0 /* AssetAttrs */);
72
72
  curString = "";
73
73
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  serialize
3
- } from "./chunk-SELVH7LO.mjs";
3
+ } from "./chunk-BV667Z5U.mjs";
4
4
  export {
5
5
  serialize as default
6
6
  };
@@ -41,7 +41,11 @@ ${opts.basePathVar ? `
41
41
  static if (typeof ${opts.basePathVar} !== "string") throw new Error("${opts.basePathVar} must be defined when using basePathVar.");
42
42
  static if (!${opts.basePathVar}.endsWith("/")) throw new Error("${opts.basePathVar} must end with a '/' when using basePathVar.");
43
43
  ` : ""}${opts.runtimeId ? `$ out.global.runtimeId = ${JSON.stringify(opts.runtimeId)};
44
- ` : ""}$ (out.global.___viteEntries || (out.global.___viteEntries = [])).push(${opts.entryData});
44
+ $ out.global.___viteBaseVar = ${JSON.stringify(
45
+ "$mbp_" + opts.runtimeId
46
+ )};
47
+ ` : `$ out.global.___viteBaseVar = "$mbp";
48
+ `}$ (out.global.___viteEntries || (out.global.___viteEntries = [])).push(${opts.entryData});
45
49
  <_vite${base} slot="head-prepend"/>
46
50
  <_vite${base} slot="head"/>
47
51
  <_vite${base} slot="body-prepend"/>
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  server_entry_template_default
3
- } from "./chunk-U7T7RXXE.mjs";
3
+ } from "./chunk-6IJ5UJ3N.mjs";
4
4
  export {
5
5
  server_entry_template_default as default
6
6
  };
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.0",
4
+ "version": "2.4.2",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {
@@ -34,7 +34,7 @@
34
34
  "lint-staged": "^13.1.0",
35
35
  "marko": "^5.22.0",
36
36
  "mocha": "^10.2.0",
37
- "mocha-snap": "^4.3.0",
37
+ "mocha-snap": "^5.0.0",
38
38
  "nyc": "^15.1.0",
39
39
  "playwright": "^1.29.1",
40
40
  "prettier": "^2.8.1",