@marko/vite 5.4.1 → 5.4.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 (2) hide show
  1. package/dist/index.mjs +43 -37
  2. package/package.json +28 -28
package/dist/index.mjs CHANGED
@@ -750,7 +750,9 @@ import path5 from "path";
750
750
  var server_entry_template_default = async (opts) => {
751
751
  const fileNameStr = JSON.stringify(`./${path5.basename(opts.fileName)}`);
752
752
  if (opts.tagsAPI) {
753
- return `import Template from ${fileNameStr};
753
+ return `
754
+ <!-- use tags -->
755
+ import Template from ${fileNameStr};
754
756
  export * from ${fileNameStr};
755
757
  import { addAssets, getPrepend, getAppend } from "${renderAssetsRuntimeId}";
756
758
  static function flush($global, html) {
@@ -765,17 +767,19 @@ static function setFlush($global) {
765
767
  -- $!{writeSync && getAppend($global)}
766
768
  `;
767
769
  }
768
- return `import template from ${fileNameStr};
770
+ return `
771
+ <!-- use class -->
772
+ import Template from ${fileNameStr};
769
773
  export * from ${fileNameStr};
770
774
  import { addAssets, getPrepend, getAppend } from "${renderAssetsRuntimeId}";
771
775
  <if(addAssets($global, [${opts.entryData.join(",")}]))>
772
776
  $!{getPrepend($global)}
773
- <\${template} ...input/>
777
+ <Template ...input/>
774
778
  $!{getAppend($global)}
775
779
  </>
776
780
  <else>
777
781
  <__flush_here_and_after__>$!{getPrepend($global)}</>
778
- <\${template} ...input/>
782
+ <Template ...input/>
779
783
  <init-components/>
780
784
  <await-reorderer/>
781
785
  <__flush_here_and_after__>$!{getAppend($global)}</>
@@ -792,6 +796,7 @@ var virtualFiles = /* @__PURE__ */ new Map();
792
796
  var extReg = /\.[^.]+$/;
793
797
  var queryReg = /\?marko-[^?]+$/;
794
798
  var importTagReg2 = /^<([^>]+)>$/;
799
+ var optionalWatchFileReg = /[\\/](?:([^\\/]+)\.)?(?:marko-tag.json|(?:style|component|component-browser)\.\w+)$/;
795
800
  var noClientAssetsRuntimeId = "\0no_client_bundles.mjs";
796
801
  var browserEntryQuery = "?marko-browser-entry";
797
802
  var serverEntryQuery = "?marko-server-entry";
@@ -857,29 +862,31 @@ function markoPlugin(opts = {}) {
857
862
  const entryIds = /* @__PURE__ */ new Set();
858
863
  const cachedSources = /* @__PURE__ */ new Map();
859
864
  const transformWatchFiles = /* @__PURE__ */ new Map();
860
- const transformOptionalFiles = /* @__PURE__ */ new Map();
861
865
  const store = new ReadOncePersistedStore(
862
866
  `vite-marko${runtimeId ? `-${runtimeId}` : ""}`
863
867
  );
864
868
  const isTagsApi = /* @__PURE__ */ (() => {
865
- let tagsAPI;
866
- return () => {
867
- if (tagsAPI === void 0) {
869
+ let defaultIsTagsAPI;
870
+ return (api) => {
871
+ if (api) {
872
+ return api === "tags";
873
+ }
874
+ if (defaultIsTagsAPI === void 0) {
868
875
  const translatorPackage = opts.translator || compiler2.globalConfig?.translator || "marko/translator";
869
876
  if (/^@marko\/translator-(?:default|interop-class-tags)$/.test(
870
877
  translatorPackage
871
878
  )) {
872
- tagsAPI = false;
879
+ defaultIsTagsAPI = false;
873
880
  } else {
874
881
  try {
875
882
  const require2 = createRequire(import.meta.url);
876
- tagsAPI = require2(translatorPackage).preferAPI !== "class";
883
+ defaultIsTagsAPI = require2(translatorPackage).preferAPI !== "class";
877
884
  } catch {
878
- tagsAPI = true;
885
+ defaultIsTagsAPI = true;
879
886
  }
880
887
  }
881
888
  }
882
- return tagsAPI;
889
+ return defaultIsTagsAPI;
883
890
  };
884
891
  })();
885
892
  return [
@@ -1163,17 +1170,18 @@ function markoPlugin(opts = {}) {
1163
1170
  if (type === "unlink") {
1164
1171
  entryIds.delete(fileName);
1165
1172
  transformWatchFiles.delete(fileName);
1166
- transformOptionalFiles.delete(fileName);
1167
1173
  }
1168
1174
  for (const [id, files] of transformWatchFiles) {
1169
1175
  if (anyMatch(files, fileName)) {
1170
1176
  devServer.watcher.emit("change", id);
1171
1177
  }
1172
1178
  }
1173
- if (type === "add" || type === "unlink") {
1174
- for (const [id, files] of transformOptionalFiles) {
1175
- if (anyMatch(files, fileName)) {
1176
- devServer.watcher.emit("change", id);
1179
+ if (type === "unlink" || type === "add") {
1180
+ const optionalMatch = optionalWatchFileReg.exec(fileName);
1181
+ if (optionalMatch) {
1182
+ const markoFile = fileName.slice(0, optionalMatch.index + 1) + (optionalMatch[1] || "index") + ".marko";
1183
+ if (transformWatchFiles.has(markoFile)) {
1184
+ devServer.watcher.emit("change", markoFile);
1177
1185
  }
1178
1186
  }
1179
1187
  }
@@ -1320,7 +1328,7 @@ function markoPlugin(opts = {}) {
1320
1328
  return cachedSources.get(id.slice(0, -query.length)) || null;
1321
1329
  }
1322
1330
  default:
1323
- return virtualFiles.get(id) || cacheDir && fs4.promises.readFile(
1331
+ return virtualFiles.get(id) || cachedSources.get(id) || cacheDir && fs4.promises.readFile(
1324
1332
  virtualPathToCacheFile(id, root, cacheDir),
1325
1333
  "utf8"
1326
1334
  ).then((code) => {
@@ -1331,7 +1339,7 @@ function markoPlugin(opts = {}) {
1331
1339
  });
1332
1340
  }
1333
1341
  }
1334
- return virtualFiles.get(id) || null;
1342
+ return virtualFiles.get(id) || cachedSources.get(id) || null;
1335
1343
  },
1336
1344
  async transform(source, rawId, ssr) {
1337
1345
  let id = stripViteQueries(rawId);
@@ -1385,7 +1393,9 @@ function markoPlugin(opts = {}) {
1385
1393
  entryData,
1386
1394
  runtimeId,
1387
1395
  basePathVar: isBuild ? basePathVar : void 0,
1388
- tagsAPI: isTagsApi()
1396
+ tagsAPI: isTagsApi(
1397
+ ("transformRequest" in this.environment ? (await this.environment.transformRequest(fileName), this.getModuleInfo(fileName)) : await this.load({ id: fileName }))?.meta.markoAPI
1398
+ )
1389
1399
  });
1390
1400
  }
1391
1401
  }
@@ -1426,7 +1436,11 @@ function markoPlugin(opts = {}) {
1426
1436
  return {
1427
1437
  code: code2,
1428
1438
  map: stripSourceRoot(map),
1429
- meta: { arcSourceCode: source, arcScanIds: meta2.analyzedTags }
1439
+ meta: {
1440
+ markoAPI: meta2.api,
1441
+ arcSourceCode: source,
1442
+ arcScanIds: meta2.analyzedTags
1443
+ }
1430
1444
  };
1431
1445
  }
1432
1446
  }
@@ -1441,28 +1455,25 @@ function markoPlugin(opts = {}) {
1441
1455
  );
1442
1456
  const { meta } = compiled;
1443
1457
  let { code } = compiled;
1444
- if (!isTest && query !== browserEntryQuery && devServer && !isTagsApi()) {
1458
+ if (!isTest && query !== browserEntryQuery && devServer && !isTagsApi(meta.api)) {
1445
1459
  code += `
1446
1460
  if (import.meta.hot) import.meta.hot.accept(() => {});`;
1447
1461
  }
1448
1462
  if (devServer) {
1449
- const templateName = getPosixBasenameWithoutExt(id);
1450
- const optionalFilePrefix = path6.dirname(id) + path6.sep + (templateName === "index" ? "" : `${templateName}.`);
1463
+ transformWatchFiles.set(id, meta.watchFiles);
1464
+ } else {
1451
1465
  for (const file of meta.watchFiles) {
1452
1466
  this.addWatchFile(file);
1453
1467
  }
1454
- transformOptionalFiles.set(id, [
1455
- `${optionalFilePrefix}style.*`,
1456
- `${optionalFilePrefix}component.*`,
1457
- `${optionalFilePrefix}component-browser.*`,
1458
- `${optionalFilePrefix}marko-tag.json`
1459
- ]);
1460
- transformWatchFiles.set(id, meta.watchFiles);
1461
1468
  }
1462
1469
  return {
1463
1470
  code,
1464
1471
  map: stripSourceRoot(compiled.map),
1465
- meta: isBuild ? { arcSourceCode: source, arcScanIds: meta.analyzedTags } : void 0
1472
+ meta: isBuild ? {
1473
+ markoAPI: meta.api,
1474
+ arcSourceCode: source,
1475
+ arcScanIds: meta.analyzedTags
1476
+ } : { markoAPI: meta.api }
1466
1477
  };
1467
1478
  }
1468
1479
  },
@@ -1600,11 +1611,6 @@ function virtualPathToCacheFile(virtualPath, root, cacheDir) {
1600
1611
  normalizePath(path6.relative(root, virtualPath)).replace(/[\\/]+/g, "_")
1601
1612
  );
1602
1613
  }
1603
- function getPosixBasenameWithoutExt(file) {
1604
- const baseStart = file.lastIndexOf(POSIX_SEP) + 1;
1605
- const extStart = file.indexOf(".", baseStart + 1);
1606
- return file.slice(baseStart, extStart);
1607
- }
1608
1614
  function createDeferredPromise() {
1609
1615
  let resolve;
1610
1616
  let reject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
- "version": "5.4.1",
3
+ "version": "5.4.3",
4
4
  "description": "A Marko plugin for Vite",
5
5
  "keywords": [
6
6
  "loader",
@@ -41,53 +41,53 @@
41
41
  "version": "changeset version && npm i --package-lock-only"
42
42
  },
43
43
  "dependencies": {
44
- "@chialab/cjs-to-esm": "^0.18.0",
44
+ "@chialab/cjs-to-esm": "^0.19.0",
45
45
  "anymatch": "^3.1.3",
46
46
  "domelementtype": "^2.3.0",
47
47
  "domhandler": "^5.0.3",
48
48
  "fast-glob": "^3.3.3",
49
49
  "htmlparser2": "^10.0.0",
50
50
  "relative-import-path": "^1.0.0",
51
- "resolve": "^1.22.10",
51
+ "resolve": "^1.22.11",
52
52
  "resolve.exports": "^2.0.3"
53
53
  },
54
54
  "devDependencies": {
55
- "@changesets/changelog-github": "^0.5.1",
56
- "@changesets/cli": "^2.29.5",
57
- "@eslint/js": "^9.31.0",
58
- "@marko/compiler": "^5.39.29",
55
+ "@changesets/changelog-github": "^0.5.2",
56
+ "@changesets/cli": "^2.29.8",
57
+ "@eslint/js": "^9.39.1",
58
+ "@marko/compiler": "^5.39.45",
59
59
  "@marko/fixture-snapshots": "^2.2.1",
60
- "@marko/testing-library": "^6.3.1",
60
+ "@marko/testing-library": "^6.4.1",
61
61
  "@types/babel__core": "^7.20.5",
62
62
  "@types/diff": "^8.0.0",
63
- "@types/jsdom": "^21.1.7",
63
+ "@types/jsdom": "^27.0.0",
64
64
  "@types/mocha": "^10.0.10",
65
- "@types/node": "^24.0.14",
65
+ "@types/node": "^25.0.1",
66
66
  "@types/resolve": "^1.20.6",
67
67
  "@types/serve-handler": "^6.1.4",
68
- "cross-env": "^7.0.3",
68
+ "cross-env": "^10.1.0",
69
69
  "diff": "^8.0.2",
70
- "esbuild": "^0.25.6",
71
- "eslint": "^9.31.0",
72
- "eslint-formatter-unix": "^8.40.0",
70
+ "esbuild": "^0.27.1",
71
+ "eslint": "^9.39.1",
72
+ "eslint-formatter-unix": "^9.0.1",
73
73
  "eslint-plugin-simple-import-sort": "^12.1.1",
74
- "globals": "^16.3.0",
74
+ "globals": "^16.5.0",
75
75
  "husky": "^9.1.7",
76
- "jsdom": "^26.1.0",
77
- "less": "^4.3.0",
78
- "lint-staged": "^16.1.2",
79
- "marko": "^5.37.41",
80
- "mocha": "^11.7.1",
81
- "mocha-snap": "^5.0.0",
76
+ "jsdom": "^27.3.0",
77
+ "less": "^4.4.2",
78
+ "lint-staged": "^16.2.7",
79
+ "marko": "^5.38.2",
80
+ "mocha": "^11.7.5",
81
+ "mocha-snap": "^5.0.1",
82
82
  "nyc": "^17.1.0",
83
- "playwright": "^1.54.1",
84
- "prettier": "^3.6.2",
85
- "prettier-plugin-packagejson": "^2.5.18",
83
+ "playwright": "^1.57.0",
84
+ "prettier": "^3.7.4",
85
+ "prettier-plugin-packagejson": "^2.5.20",
86
86
  "serve-handler": "^6.1.6",
87
- "tsx": "^4.20.3",
88
- "typescript": "^5.8.3",
89
- "typescript-eslint": "^8.37.0",
90
- "vite": "^7.1.10"
87
+ "tsx": "^4.21.0",
88
+ "typescript": "^5.9.3",
89
+ "typescript-eslint": "^8.49.0",
90
+ "vite": "^7.2.7"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "@marko/compiler": "^5",