@marko/vite 2.4.1 → 2.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.
package/dist/index.js CHANGED
@@ -61,7 +61,8 @@ const thisFile = typeof __filename === "string" ? __filename : (0, import_url.fi
61
61
  function markoPlugin(opts = {}) {
62
62
  var _a;
63
63
  let compiler;
64
- const { runtimeId, basePathVar, linked = true } = opts;
64
+ let { linked = true } = opts;
65
+ const { runtimeId, basePathVar } = opts;
65
66
  const baseConfig = {
66
67
  cache,
67
68
  runtimeId,
@@ -112,13 +113,14 @@ function markoPlugin(opts = {}) {
112
113
  let root;
113
114
  let devEntryFile;
114
115
  let devEntryFilePosix;
116
+ let isTest = false;
115
117
  let isBuild = false;
116
118
  let isSSRBuild = false;
117
119
  let devServer;
118
120
  let registeredTag = false;
119
121
  let serverManifest;
120
122
  let store;
121
- let cjsImports;
123
+ let CJSTemplates;
122
124
  let basePath = "/";
123
125
  const entrySources = /* @__PURE__ */ new Map();
124
126
  const transformWatchFiles = /* @__PURE__ */ new Map();
@@ -134,11 +136,15 @@ function markoPlugin(opts = {}) {
134
136
  root = normalizePath(config.root || process.cwd());
135
137
  devEntryFile = import_path.default.join(root, "index.html");
136
138
  devEntryFilePosix = normalizePath(devEntryFile);
139
+ isTest = env.mode === "test";
137
140
  isBuild = env.command === "build";
138
141
  isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
139
142
  store = opts.store || new import_store.FileStore(
140
143
  `marko-vite-${import_crypto.default.createHash("SHA1").update(root).digest("hex")}`
141
144
  );
145
+ if (isTest) {
146
+ linked = false;
147
+ }
142
148
  if (linked && !registeredTag) {
143
149
  const transformer = import_path.default.resolve(
144
150
  thisFile,
@@ -166,12 +172,10 @@ function markoPlugin(opts = {}) {
166
172
  if (entry) {
167
173
  const relativePath = (0, import_relative_import_path.relativeImportPath)(devEntryFile, entry);
168
174
  taglibDeps.push(relativePath);
169
- if (isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
175
+ if (isTest || isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
170
176
  optimizeTaglibDeps.push(relativePath);
171
177
  } else {
172
- (cjsImports ?? (cjsImports = /* @__PURE__ */ new Map())).set(normalizePath(entry), {
173
- template: tag.template
174
- });
178
+ (CJSTemplates ?? (CJSTemplates = /* @__PURE__ */ new Set())).add(normalizePath(entry));
175
179
  }
176
180
  }
177
181
  }
@@ -320,22 +324,6 @@ function markoPlugin(opts = {}) {
320
324
  return null;
321
325
  },
322
326
  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
327
  switch (getMarkoQuery(id)) {
340
328
  case serverEntryQuery: {
341
329
  const fileName = id.slice(0, -serverEntryQuery.length);
@@ -385,6 +373,7 @@ function markoPlugin(opts = {}) {
385
373
  );
386
374
  },
387
375
  async transform(source, id, ssr) {
376
+ const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
388
377
  const query = getMarkoQuery(id);
389
378
  if (query && !query.startsWith(virtualFileQuery)) {
390
379
  id = id.slice(0, -query.length);
@@ -392,10 +381,24 @@ function markoPlugin(opts = {}) {
392
381
  id = `${id.slice(0, -markoExt.length)}.entry.marko`;
393
382
  }
394
383
  }
395
- if (!isMarkoFile(id) || (cjsImports == null ? void 0 : cjsImports.has(id))) {
384
+ if (!isMarkoFile(id)) {
396
385
  return null;
397
386
  }
398
- if (ssr && entrySources.has(id)) {
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
+ );
400
+ }
401
+ if (isSSR && linked && entrySources.has(id)) {
399
402
  entrySources.set(id, source);
400
403
  if (serverManifest) {
401
404
  serverManifest.entrySources[import_path.default.posix.relative(root, id)] = source;
@@ -404,7 +407,7 @@ function markoPlugin(opts = {}) {
404
407
  const compiled = await compiler.compile(
405
408
  source,
406
409
  id,
407
- (typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
410
+ isSSR ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
408
411
  );
409
412
  const { map, meta } = compiled;
410
413
  let { code } = compiled;
package/dist/index.mjs CHANGED
@@ -41,7 +41,8 @@ var thisFile = typeof __filename === "string" ? __filename : fileURLToPath(impor
41
41
  function markoPlugin(opts = {}) {
42
42
  var _a;
43
43
  let compiler;
44
- const { runtimeId, basePathVar, linked = true } = opts;
44
+ let { linked = true } = opts;
45
+ const { runtimeId, basePathVar } = opts;
45
46
  const baseConfig = {
46
47
  cache,
47
48
  runtimeId,
@@ -92,13 +93,14 @@ function markoPlugin(opts = {}) {
92
93
  let root;
93
94
  let devEntryFile;
94
95
  let devEntryFilePosix;
96
+ let isTest = false;
95
97
  let isBuild = false;
96
98
  let isSSRBuild = false;
97
99
  let devServer;
98
100
  let registeredTag = false;
99
101
  let serverManifest;
100
102
  let store;
101
- let cjsImports;
103
+ let CJSTemplates;
102
104
  let basePath = "/";
103
105
  const entrySources = /* @__PURE__ */ new Map();
104
106
  const transformWatchFiles = /* @__PURE__ */ new Map();
@@ -114,11 +116,15 @@ function markoPlugin(opts = {}) {
114
116
  root = normalizePath(config.root || process.cwd());
115
117
  devEntryFile = path.join(root, "index.html");
116
118
  devEntryFilePosix = normalizePath(devEntryFile);
119
+ isTest = env.mode === "test";
117
120
  isBuild = env.command === "build";
118
121
  isSSRBuild = isBuild && linked && Boolean(config.build.ssr);
119
122
  store = opts.store || new FileStore(
120
123
  `marko-vite-${crypto.createHash("SHA1").update(root).digest("hex")}`
121
124
  );
125
+ if (isTest) {
126
+ linked = false;
127
+ }
122
128
  if (linked && !registeredTag) {
123
129
  const transformer = path.resolve(
124
130
  thisFile,
@@ -146,12 +152,10 @@ function markoPlugin(opts = {}) {
146
152
  if (entry) {
147
153
  const relativePath = relativeImportPath(devEntryFile, entry);
148
154
  taglibDeps.push(relativePath);
149
- if (isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
155
+ if (isTest || isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
150
156
  optimizeTaglibDeps.push(relativePath);
151
157
  } else {
152
- (cjsImports ?? (cjsImports = /* @__PURE__ */ new Map())).set(normalizePath(entry), {
153
- template: tag.template
154
- });
158
+ (CJSTemplates ?? (CJSTemplates = /* @__PURE__ */ new Set())).add(normalizePath(entry));
155
159
  }
156
160
  }
157
161
  }
@@ -300,22 +304,6 @@ function markoPlugin(opts = {}) {
300
304
  return null;
301
305
  },
302
306
  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
307
  switch (getMarkoQuery(id)) {
320
308
  case serverEntryQuery: {
321
309
  const fileName = id.slice(0, -serverEntryQuery.length);
@@ -365,6 +353,7 @@ function markoPlugin(opts = {}) {
365
353
  );
366
354
  },
367
355
  async transform(source, id, ssr) {
356
+ const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
368
357
  const query = getMarkoQuery(id);
369
358
  if (query && !query.startsWith(virtualFileQuery)) {
370
359
  id = id.slice(0, -query.length);
@@ -372,10 +361,24 @@ function markoPlugin(opts = {}) {
372
361
  id = `${id.slice(0, -markoExt.length)}.entry.marko`;
373
362
  }
374
363
  }
375
- if (!isMarkoFile(id) || (cjsImports == null ? void 0 : cjsImports.has(id))) {
364
+ if (!isMarkoFile(id)) {
376
365
  return null;
377
366
  }
378
- if (ssr && entrySources.has(id)) {
367
+ if (CJSTemplates == null ? void 0 : CJSTemplates.has(id)) {
368
+ return createEsmWrapper(
369
+ id,
370
+ getExportIdentifiers(
371
+ (await compiler.compile(source, id, {
372
+ cache,
373
+ ast: true,
374
+ code: false,
375
+ output: "source",
376
+ sourceMaps: false
377
+ })).ast
378
+ )
379
+ );
380
+ }
381
+ if (isSSR && linked && entrySources.has(id)) {
379
382
  entrySources.set(id, source);
380
383
  if (serverManifest) {
381
384
  serverManifest.entrySources[path.posix.relative(root, id)] = source;
@@ -384,7 +387,7 @@ function markoPlugin(opts = {}) {
384
387
  const compiled = await compiler.compile(
385
388
  source,
386
389
  id,
387
- (typeof ssr === "object" ? ssr.ssr : ssr) ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
390
+ isSSR ? ssrConfig : query === browserEntryQuery ? hydrateConfig : domConfig
388
391
  );
389
392
  const { map, meta } = compiled;
390
393
  let { code } = compiled;
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.1",
4
+ "version": "2.4.3",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {