@marko/vite 4.1.20 → 5.0.1

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.
@@ -1,6 +1,6 @@
1
1
  import type * as vite from "vite";
2
- import type * as Compiler from "@marko/compiler";
2
+ import * as compiler from "@marko/compiler";
3
3
  type ESBuildOptions = Exclude<vite.DepOptimizationConfig["esbuildOptions"], undefined>;
4
4
  type ESBuildPlugin = Exclude<ESBuildOptions["plugins"], undefined>[number];
5
- export default function esbuildPlugin(compiler: typeof Compiler, config: Compiler.Config): ESBuildPlugin;
5
+ export default function esbuildPlugin(config: compiler.Config): ESBuildPlugin;
6
6
  export {};
package/dist/index.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  import type * as vite from "vite";
2
- import type * as Compiler from "@marko/compiler";
2
+ import * as compiler from "@marko/compiler";
3
3
  export declare namespace API {
4
4
  type getMarkoAssetCodeForEntry = (id: string) => string | void;
5
5
  }
6
6
  export interface Options {
7
7
  linked?: boolean;
8
- compiler?: string;
9
8
  runtimeId?: string;
10
9
  translator?: string;
11
10
  basePathVar?: string;
12
- babelConfig?: Compiler.Config["babelConfig"];
11
+ babelConfig?: compiler.Config["babelConfig"];
13
12
  }
14
13
  export default function markoPlugin(opts?: Options): vite.Plugin[];
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
+ import * as compiler2 from "@marko/compiler";
2
3
  import fs4 from "fs";
3
4
  import path6 from "path";
4
5
  import crypto from "crypto";
@@ -106,41 +107,41 @@ function renderAssets(slot) {
106
107
 
107
108
  // src/server-entry-template.ts
108
109
  var server_entry_template_default = async (opts) => {
110
+ const addAssetsCall = `addAssets($global, [${opts.entryData.join(",")}])`;
109
111
  const fileNameStr = JSON.stringify(`./${path.basename(opts.fileName)}`);
110
112
  return `import template from ${fileNameStr};
111
113
  export * from ${fileNameStr};
112
114
  import { addAssets } from "${renderAssetsRuntimeId}";
113
115
 
114
- $ const g = out.global;
115
- $ const writeSync = addAssets(g, [${opts.entryData.join(",")}]);
116
+ ${opts.tagsAPI ? `<const/writeSync=${addAssetsCall}/>` : `$ const writeSync = ${addAssetsCall};`}
116
117
 
117
118
  <if(writeSync)>
118
119
  $!{
119
- g.___viteRenderAssets("head-prepend") +
120
- g.___viteRenderAssets("head") +
121
- g.___viteRenderAssets("body-prepend")
120
+ $global.___viteRenderAssets("head-prepend") +
121
+ $global.___viteRenderAssets("head") +
122
+ $global.___viteRenderAssets("body-prepend")
122
123
  }
123
124
  </>
124
125
  <else>
125
126
  <__flush_here_and_after__>
126
127
  $!{
127
- g.___viteRenderAssets("head-prepend") +
128
- g.___viteRenderAssets("head") +
129
- g.___viteRenderAssets("body-prepend")
128
+ $global.___viteRenderAssets("head-prepend") +
129
+ $global.___viteRenderAssets("head") +
130
+ $global.___viteRenderAssets("body-prepend")
130
131
  }
131
132
  </__flush_here_and_after__>
132
133
  </>
133
134
 
134
- <\${template} ...input/>
135
+ <\${template} ...input/>${opts.tagsAPI ? "" : `
135
136
  <init-components/>
136
- <await-reorderer/>
137
+ <await-reorderer/>`}
137
138
 
138
139
  <if(writeSync)>
139
- $!{g.___viteRenderAssets("body")}
140
+ $!{$global.___viteRenderAssets("body")}
140
141
  </>
141
142
  <else>
142
143
  <__flush_here_and_after__>
143
- $!{g.___viteRenderAssets("body")}
144
+ $!{$global.___viteRenderAssets("body")}
144
145
  </__flush_here_and_after__>
145
146
  </>
146
147
  `;
@@ -356,8 +357,9 @@ function isElement(node) {
356
357
  // src/esbuild-plugin.ts
357
358
  import fs from "fs";
358
359
  import path2 from "path";
360
+ import * as compiler from "@marko/compiler";
359
361
  var markoErrorRegExp = /^(.+?)(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
360
- function esbuildPlugin(compiler, config) {
362
+ function esbuildPlugin(config) {
361
363
  return {
362
364
  name: "marko",
363
365
  async setup(build) {
@@ -533,24 +535,45 @@ function plugin(options) {
533
535
  namespaceId = s.local;
534
536
  }
535
537
  }
536
- namespaceId ||= path7.scope.generateUidIdentifier(
537
- defaultImportId?.name || path7.node.source.value
538
+ const rawImport = path7.scope.generateUidIdentifier(
539
+ namespaceId?.name || defaultImportId?.name || path7.node.source.value
538
540
  );
539
- path7.node.specifiers = [t.importDefaultSpecifier(namespaceId)];
541
+ path7.node.specifiers = [t.importNamespaceSpecifier(rawImport)];
540
542
  if (defaultImportId) {
541
543
  path7.insertAfter(
542
544
  t.variableDeclaration("const", [
543
545
  t.variableDeclarator(
544
- defaultImportId,
546
+ t.objectPattern([
547
+ t.objectProperty(t.identifier("default"), defaultImportId)
548
+ ]),
545
549
  t.conditionalExpression(
546
550
  t.optionalMemberExpression(
547
- namespaceId,
551
+ t.memberExpression(rawImport, t.identifier("default")),
548
552
  t.identifier("__esModule"),
549
553
  false,
550
554
  true
551
555
  ),
552
- t.memberExpression(namespaceId, t.identifier("default")),
553
- namespaceId
556
+ t.memberExpression(rawImport, t.identifier("default")),
557
+ rawImport
558
+ )
559
+ )
560
+ ])
561
+ );
562
+ }
563
+ if (namespaceId) {
564
+ path7.insertAfter(
565
+ t.variableDeclaration("const", [
566
+ t.variableDeclarator(
567
+ namespaceId,
568
+ t.conditionalExpression(
569
+ t.optionalMemberExpression(
570
+ rawImport,
571
+ t.identifier("__esModule"),
572
+ false,
573
+ true
574
+ ),
575
+ rawImport,
576
+ t.memberExpression(rawImport, t.identifier("default"))
554
577
  )
555
578
  )
556
579
  ])
@@ -570,7 +593,16 @@ function plugin(options) {
570
593
  )
571
594
  )
572
595
  ),
573
- namespaceId
596
+ t.conditionalExpression(
597
+ t.optionalMemberExpression(
598
+ rawImport,
599
+ t.identifier("__esModule"),
600
+ false,
601
+ true
602
+ ),
603
+ rawImport,
604
+ t.memberExpression(rawImport, t.identifier("default"))
605
+ )
574
606
  )
575
607
  ])
576
608
  );
@@ -593,7 +625,7 @@ function renderAssetsCall(t3, slot) {
593
625
  return t3.markoPlaceholder(
594
626
  t3.callExpression(
595
627
  t3.memberExpression(
596
- t3.memberExpression(t3.identifier("out"), t3.identifier("global")),
628
+ t3.identifier("$global"),
597
629
  t3.identifier("___viteRenderAssets")
598
630
  ),
599
631
  [t3.stringLiteral(slot)]
@@ -773,7 +805,6 @@ var babelCaller = {
773
805
  var registeredTagLib = false;
774
806
  var cjsToEsm;
775
807
  function markoPlugin(opts = {}) {
776
- let compiler;
777
808
  let { linked = true } = opts;
778
809
  let runtimeId;
779
810
  let basePathVar;
@@ -806,6 +837,9 @@ function markoPlugin(opts = {}) {
806
837
  let serverManifest;
807
838
  let basePath = "/";
808
839
  let getMarkoAssetFns;
840
+ const tagsAPI = !/^@marko\/translator-(?:default|interop-class-tags)$/.test(
841
+ opts.translator || compiler2.globalConfig?.translator || "@marko/translator-default"
842
+ );
809
843
  const entryIds = /* @__PURE__ */ new Set();
810
844
  const cachedSources = /* @__PURE__ */ new Map();
811
845
  const transformWatchFiles = /* @__PURE__ */ new Map();
@@ -825,7 +859,6 @@ function markoPlugin(opts = {}) {
825
859
  } else {
826
860
  process.env.MARKO_DEBUG = optimize ? "false" : "true";
827
861
  }
828
- compiler ??= await import(opts.compiler || "@marko/compiler");
829
862
  runtimeId = opts.runtimeId;
830
863
  basePathVar = opts.basePathVar;
831
864
  if ("BASE_URL" in process.env && config.base == null) {
@@ -874,7 +907,7 @@ function markoPlugin(opts = {}) {
874
907
  resolveVirtualDependency,
875
908
  output: "hydrate"
876
909
  };
877
- compiler.configure(baseConfig);
910
+ compiler2.configure(baseConfig);
878
911
  root = normalizePath(config.root || process.cwd());
879
912
  devEntryFile = path6.join(root, "index.html");
880
913
  devEntryFilePosix = normalizePath(devEntryFile);
@@ -901,7 +934,7 @@ function markoPlugin(opts = {}) {
901
934
  }
902
935
  if (!registeredTagLib) {
903
936
  registeredTagLib = true;
904
- compiler.taglib.register("@marko/vite", {
937
+ compiler2.taglib.register("@marko/vite", {
905
938
  transform: glob_import_transform_default,
906
939
  "<head>": { transformer: render_assets_transform_default },
907
940
  "<body>": { transformer: render_assets_transform_default },
@@ -917,13 +950,13 @@ function markoPlugin(opts = {}) {
917
950
  `!**/coverage/**`
918
951
  ];
919
952
  }
920
- const domDeps = compiler.getRuntimeEntryFiles("dom", opts.translator);
953
+ const domDeps = compiler2.getRuntimeEntryFiles("dom", opts.translator);
921
954
  optimizeDeps.include = optimizeDeps.include ? [...optimizeDeps.include, ...domDeps] : domDeps;
922
955
  const optimizeExtensions = optimizeDeps.extensions ??= [];
923
956
  optimizeExtensions.push(".marko");
924
957
  const esbuildOptions = optimizeDeps.esbuildOptions ??= {};
925
958
  const esbuildPlugins = esbuildOptions.plugins ??= [];
926
- esbuildPlugins.push(esbuildPlugin(compiler, baseConfig));
959
+ esbuildPlugins.push(esbuildPlugin(baseConfig));
927
960
  const ssr = config.ssr ??= {};
928
961
  const { noExternal } = ssr;
929
962
  if (noExternal !== true) {
@@ -1042,7 +1075,7 @@ function markoPlugin(opts = {}) {
1042
1075
  });
1043
1076
  },
1044
1077
  handleHotUpdate(ctx) {
1045
- compiler.taglib.clearCaches();
1078
+ compiler2.taglib.clearCaches();
1046
1079
  baseConfig.cache.clear();
1047
1080
  for (const [, cache2] of configsByFileSystem) {
1048
1081
  cache2.clear();
@@ -1191,7 +1224,8 @@ function markoPlugin(opts = {}) {
1191
1224
  fileName,
1192
1225
  entryData,
1193
1226
  runtimeId,
1194
- basePathVar: isBuild ? basePathVar : void 0
1227
+ basePathVar: isBuild ? basePathVar : void 0,
1228
+ tagsAPI
1195
1229
  });
1196
1230
  }
1197
1231
  }
@@ -1224,7 +1258,7 @@ function markoPlugin(opts = {}) {
1224
1258
  }
1225
1259
  if (!query && isCJSModule(id)) {
1226
1260
  if (isBuild) {
1227
- const { code: code2, map: map2, meta: meta2 } = await compiler.compile(
1261
+ const { code: code2, map: map2, meta: meta2 } = await compiler2.compile(
1228
1262
  source,
1229
1263
  id,
1230
1264
  getConfigForFileSystem(info, ssrCjsConfig)
@@ -1237,7 +1271,7 @@ function markoPlugin(opts = {}) {
1237
1271
  }
1238
1272
  }
1239
1273
  }
1240
- const compiled = await compiler.compile(
1274
+ const compiled = await compiler2.compile(
1241
1275
  source,
1242
1276
  id,
1243
1277
  getConfigForFileSystem(
@@ -3,5 +3,6 @@ declare const _default: (opts: {
3
3
  entryData: string[];
4
4
  runtimeId?: string;
5
5
  basePathVar?: string;
6
+ tagsAPI?: boolean;
6
7
  }) => Promise<string>;
7
8
  export default _default;
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.1.20",
4
+ "version": "5.0.1",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {
@@ -16,37 +16,37 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@changesets/changelog-github": "^0.5.0",
19
- "@changesets/cli": "^2.27.5",
20
- "@marko/compiler": "^5.37.0",
19
+ "@changesets/cli": "^2.27.9",
20
+ "@marko/compiler": "^5.37.26",
21
21
  "@marko/fixture-snapshots": "^2.2.1",
22
22
  "@marko/testing-library": "^6.2.0",
23
23
  "@types/babel__core": "^7.20.5",
24
- "@types/jsdom": "^21.1.6",
25
- "@types/mocha": "^10.0.6",
26
- "@types/node": "^20.12.12",
24
+ "@types/jsdom": "^21.1.7",
25
+ "@types/mocha": "^10.0.9",
26
+ "@types/node": "^22.9.0",
27
27
  "@types/resolve": "^1.20.6",
28
28
  "@types/serve-handler": "^6.1.4",
29
29
  "@typescript-eslint/eslint-plugin": "^7.11.0",
30
30
  "@typescript-eslint/parser": "^7.11.0",
31
31
  "cross-env": "^7.0.3",
32
- "esbuild": "^0.21.4",
32
+ "esbuild": "^0.24.0",
33
33
  "eslint": "^8.57.0",
34
34
  "eslint-config-prettier": "^9.1.0",
35
35
  "fixpack": "^4.0.0",
36
- "husky": "^9.0.11",
37
- "jsdom": "^24.1.0",
36
+ "husky": "^9.1.7",
37
+ "jsdom": "^25.0.1",
38
38
  "less": "^4.2.0",
39
- "lint-staged": "^15.2.5",
40
- "marko": "^5.35.0",
41
- "mocha": "^10.4.0",
39
+ "lint-staged": "^15.2.10",
40
+ "marko": "^5.35.35",
41
+ "mocha": "^10.8.2",
42
42
  "mocha-snap": "^5.0.0",
43
- "nyc": "^15.1.0",
44
- "playwright": "^1.44.1",
45
- "prettier": "^3.2.5",
46
- "serve-handler": "^6.1.5",
47
- "tsx": "^4.11.0",
48
- "typescript": "^5.4.5",
49
- "vite": "^5.2.12"
43
+ "nyc": "^17.1.0",
44
+ "playwright": "^1.49.0",
45
+ "prettier": "^3.3.3",
46
+ "serve-handler": "^6.1.6",
47
+ "tsx": "^4.19.2",
48
+ "typescript": "^5.6.3",
49
+ "vite": "^5.4.11"
50
50
  },
51
51
  "files": [
52
52
  "dist",