@marko/vite 4.0.0 → 4.0.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.
Files changed (2) hide show
  1. package/dist/index.mjs +64 -19
  2. package/package.json +8 -8
package/dist/index.mjs CHANGED
@@ -11,9 +11,9 @@ import path from "path";
11
11
  // src/render-assets-runtime.ts
12
12
  var renderAssetsRuntimeId = "\0marko-render-assets.mjs";
13
13
  function getRenderAssetsRuntime(opts) {
14
- return `${!opts.basePathVar ? "const base = import.meta.env.BASE_URL;" : `const base = globalThis.${opts.basePathVar};
14
+ return `${opts.basePathVar && opts.isBuild ? `const base = globalThis.${opts.basePathVar};
15
15
  if (typeof base !== "string") throw new Error("${opts.basePathVar} must be defined when using basePathVar.");
16
- if (!base.endsWith("/")) throw new Error("${opts.basePathVar} must end with a '/' when using basePathVar.");`}
16
+ if (!base.endsWith("/")) throw new Error("${opts.basePathVar} must end with a '/' when using basePathVar.");` : "const base = import.meta.env.BASE_URL;"}
17
17
  export function addAssets(g, newEntries) {
18
18
  const entries = g.___viteEntries;
19
19
  if (entries) {
@@ -24,7 +24,7 @@ export function addAssets(g, newEntries) {
24
24
  g.___viteInjectAttrs = g.cspNonce
25
25
  ? \` nonce="\${g.cspNonce.replace(/"/g, "'")}"\`
26
26
  : "";
27
- ${opts.runtimeId ? `$ g.runtimeId = ${JSON.stringify(opts.runtimeId)};` : ""}
27
+ ${opts.runtimeId ? `g.runtimeId = ${JSON.stringify(opts.runtimeId)};` : ""}
28
28
  }
29
29
  }
30
30
 
@@ -600,6 +600,7 @@ var browserQuery = "?marko-browser";
600
600
  var markoExt = ".marko";
601
601
  var htmlExt = ".html";
602
602
  var resolveOpts = { skipSelf: true };
603
+ var configsByFileSystem = /* @__PURE__ */ new Map();
603
604
  var cache = /* @__PURE__ */ new Map();
604
605
  var babelCaller = {
605
606
  name: "@marko/vite",
@@ -616,7 +617,8 @@ function markoPlugin(opts = {}) {
616
617
  let basePathVar;
617
618
  let baseConfig;
618
619
  let ssrConfig;
619
- let ssrCjsConfig;
620
+ let ssrCjsBuildConfig;
621
+ let ssrCjsServeConfig;
620
622
  let domConfig;
621
623
  let hydrateConfig;
622
624
  const resolveVirtualDependency = (from, dep) => {
@@ -664,6 +666,7 @@ function markoPlugin(opts = {}) {
664
666
  runtimeId,
665
667
  sourceMaps: true,
666
668
  writeVersionComment: false,
669
+ optimize: env.mode === "production",
667
670
  babelConfig: opts.babelConfig ? {
668
671
  ...opts.babelConfig,
669
672
  caller: opts.babelConfig.caller ? {
@@ -686,6 +689,12 @@ function markoPlugin(opts = {}) {
686
689
  resolveVirtualDependency,
687
690
  output: "html"
688
691
  };
692
+ ssrCjsServeConfig = {
693
+ ...ssrConfig,
694
+ ast: true,
695
+ code: false,
696
+ sourceMaps: false
697
+ };
689
698
  domConfig = {
690
699
  ...baseConfig,
691
700
  resolveVirtualDependency,
@@ -789,7 +798,7 @@ function markoPlugin(opts = {}) {
789
798
  },
790
799
  configResolved(config) {
791
800
  basePath = config.base;
792
- ssrCjsConfig = {
801
+ ssrCjsBuildConfig = {
793
802
  ...ssrConfig,
794
803
  //modules: 'cjs'
795
804
  babelConfig: {
@@ -841,6 +850,9 @@ function markoPlugin(opts = {}) {
841
850
  handleHotUpdate(ctx) {
842
851
  compiler.taglib.clearCaches();
843
852
  baseConfig.cache.clear();
853
+ for (const [, cache2] of configsByFileSystem) {
854
+ cache2.clear();
855
+ }
844
856
  for (const mod of ctx.modules) {
845
857
  if (mod.id && virtualFiles.has(mod.id)) {
846
858
  virtualFiles.set(mod.id, createDeferredPromise());
@@ -878,12 +890,12 @@ function markoPlugin(opts = {}) {
878
890
  if (importeeQuery) {
879
891
  importee = importee.slice(0, -importeeQuery.length);
880
892
  } else if (!importOpts.scan) {
881
- if (ssr && linked && importer && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
893
+ if (ssr && linked && importer && importer[0] !== "\0" && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
882
894
  isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
883
895
  importeeQuery = serverEntryQuery;
884
896
  } else if (!ssr && isBuild && importer && isMarkoFile(importee) && this.getModuleInfo(importer)?.isEntry) {
885
897
  importeeQuery = browserEntryQuery;
886
- } else if (linked && !ssr && !importeeQuery && isMarkoFile(importee)) {
898
+ } else if (!isBuild && linked && !ssr && !importeeQuery && isMarkoFile(importee)) {
887
899
  importeeQuery = browserQuery;
888
900
  }
889
901
  }
@@ -934,6 +946,10 @@ function markoPlugin(opts = {}) {
934
946
  },
935
947
  async transform(source, rawId, ssr) {
936
948
  let id = stripVersionAndTimeStamp(rawId);
949
+ const info = isBuild ? this.getModuleInfo(id) : void 0;
950
+ if (info?.meta.arcSourceId) {
951
+ id = info.meta.arcSourceId;
952
+ }
937
953
  const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
938
954
  const query = getMarkoQuery(id);
939
955
  if (query && !query.startsWith(virtualFileQuery)) {
@@ -993,20 +1009,22 @@ function markoPlugin(opts = {}) {
993
1009
  }
994
1010
  if (!query && isCJSModule(id)) {
995
1011
  if (isBuild) {
996
- const { code: code2, map: map2 } = await compiler.compile(
1012
+ const { code: code2, map: map2, meta: meta2 } = await compiler.compile(
997
1013
  source,
998
1014
  id,
999
- ssrCjsConfig
1015
+ getConfigForFileSystem(info, ssrCjsBuildConfig)
1000
1016
  );
1001
- return { code: code2, map: map2, meta: { source } };
1017
+ return {
1018
+ code: code2,
1019
+ map: map2,
1020
+ meta: { arcSourceCode: source, arcScanIds: meta2.analyzedTags }
1021
+ };
1002
1022
  } else {
1003
- const { ast } = await compiler.compile(source, id, {
1004
- cache,
1005
- ast: true,
1006
- code: false,
1007
- output: "source",
1008
- sourceMaps: false
1009
- });
1023
+ const { ast } = await compiler.compile(
1024
+ source,
1025
+ id,
1026
+ ssrCjsServeConfig
1027
+ );
1010
1028
  let namedExports = "";
1011
1029
  let code2 = `import { createRequire } from "module";
1012
1030
  `;
@@ -1068,7 +1086,10 @@ function markoPlugin(opts = {}) {
1068
1086
  const compiled = await compiler.compile(
1069
1087
  source,
1070
1088
  id,
1071
- isSSR ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
1089
+ getConfigForFileSystem(
1090
+ info,
1091
+ isSSR ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
1092
+ )
1072
1093
  );
1073
1094
  const { map, meta } = compiled;
1074
1095
  let { code } = compiled;
@@ -1090,7 +1111,11 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
1090
1111
  ]);
1091
1112
  transformWatchFiles.set(id, meta.watchFiles);
1092
1113
  }
1093
- return { code, map, meta: isBuild ? { source } : void 0 };
1114
+ return {
1115
+ code,
1116
+ map,
1117
+ meta: isBuild ? { arcSourceCode: source, arcScanIds: meta.analyzedTags } : void 0
1118
+ };
1094
1119
  }
1095
1120
  },
1096
1121
  {
@@ -1238,6 +1263,26 @@ function stripVersionAndTimeStamp(id) {
1238
1263
  return `${url}?${query}`;
1239
1264
  return url;
1240
1265
  }
1266
+ function getConfigForFileSystem(info, config) {
1267
+ const fileSystem = info?.meta.arcFS;
1268
+ if (!fileSystem)
1269
+ return config;
1270
+ let configsForFileSystem = configsByFileSystem.get(fileSystem);
1271
+ if (!configsForFileSystem) {
1272
+ configsForFileSystem = /* @__PURE__ */ new Map();
1273
+ configsByFileSystem.set(fileSystem, configsForFileSystem);
1274
+ }
1275
+ let configForFileSystem = configsForFileSystem.get(config);
1276
+ if (!configForFileSystem) {
1277
+ configForFileSystem = {
1278
+ ...config,
1279
+ fileSystem,
1280
+ cache: configsForFileSystem
1281
+ };
1282
+ configsForFileSystem.set(config, configForFileSystem);
1283
+ }
1284
+ return configForFileSystem;
1285
+ }
1241
1286
  export {
1242
1287
  markoPlugin as default
1243
1288
  };
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": "4.0.0",
4
+ "version": "4.0.2",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {
@@ -15,7 +15,7 @@
15
15
  "devDependencies": {
16
16
  "@changesets/changelog-github": "^0.4.8",
17
17
  "@changesets/cli": "^2.26.2",
18
- "@marko/compiler": "^5.33.7",
18
+ "@marko/compiler": "^5.33.8",
19
19
  "@marko/fixture-snapshots": "^2.2.1",
20
20
  "@marko/testing-library": "^6.1.4",
21
21
  "@types/babel__core": "^7.20.4",
@@ -24,8 +24,8 @@
24
24
  "@types/node": "^20.9.0",
25
25
  "@types/resolve": "^1.20.5",
26
26
  "@types/serve-handler": "^6.1.4",
27
- "@typescript-eslint/eslint-plugin": "^6.10.0",
28
- "@typescript-eslint/parser": "^6.10.0",
27
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
28
+ "@typescript-eslint/parser": "^6.11.0",
29
29
  "cross-env": "^7.0.3",
30
30
  "esbuild": "^0.19.5",
31
31
  "eslint": "^8.53.0",
@@ -33,15 +33,15 @@
33
33
  "fixpack": "^4.0.0",
34
34
  "husky": "^8.0.3",
35
35
  "jsdom": "^22.1.0",
36
- "lint-staged": "^15.0.2",
37
- "marko": "^5.31.17",
36
+ "lint-staged": "^15.1.0",
37
+ "marko": "^5.31.18",
38
38
  "mocha": "^10.2.0",
39
39
  "mocha-snap": "^5.0.0",
40
40
  "nyc": "^15.1.0",
41
41
  "playwright": "^1.39.0",
42
- "prettier": "^3.0.3",
42
+ "prettier": "^3.1.0",
43
43
  "serve-handler": "^6.1.5",
44
- "tsx": "^4.1.0",
44
+ "tsx": "^4.1.2",
45
45
  "typescript": "^5.2.2",
46
46
  "vite": "^5.0.0-beta.17"
47
47
  },