@marko/vite 3.0.0 → 3.1.0
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/{chunk-KRSZ5IRT.mjs → chunk-HR4PYNIR.mjs} +19 -16
- package/dist/esbuild-plugin.d.ts +5 -2
- package/dist/esbuild-plugin.js +19 -18
- package/dist/esbuild-plugin.mjs +1 -1
- package/dist/index.d.ts +1 -12
- package/dist/index.js +121 -117
- package/dist/index.mjs +119 -117
- package/dist/render-assets-transform.js +0 -2
- package/dist/serializer.js +0 -2
- package/dist/server-entry-template.js +0 -2
- package/dist/store/file-store.js +0 -2
- package/dist/store/memory-store.js +0 -2
- package/package.json +25 -26
|
@@ -6,31 +6,34 @@ function esbuildPlugin(compiler, config) {
|
|
|
6
6
|
return {
|
|
7
7
|
name: "marko",
|
|
8
8
|
async setup(build) {
|
|
9
|
+
var _a;
|
|
9
10
|
const { platform = "browser" } = build.initialOptions;
|
|
11
|
+
const isScan = (_a = build.initialOptions.plugins) == null ? void 0 : _a.some(
|
|
12
|
+
(v) => v.name === "vite:dep-scan"
|
|
13
|
+
);
|
|
10
14
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
11
15
|
const finalConfig = {
|
|
12
16
|
...config,
|
|
13
|
-
output: platform === "browser" ? "dom" : "html",
|
|
17
|
+
output: isScan ? "hydrate" : platform === "browser" ? "dom" : "html",
|
|
14
18
|
resolveVirtualDependency(from, dep) {
|
|
15
19
|
virtualFiles.set(path.join(from, "..", dep.virtualPath), dep);
|
|
16
20
|
return dep.virtualPath;
|
|
17
21
|
}
|
|
18
22
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(args)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
23
|
+
build.onResolve({ filter: /\.marko\./ }, (args) => {
|
|
24
|
+
return {
|
|
25
|
+
namespace: "marko:virtual",
|
|
26
|
+
path: path.resolve(args.resolveDir, args.path)
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
build.onLoad(
|
|
30
|
+
{ filter: /\.marko\./, namespace: "marko:virtual" },
|
|
31
|
+
(args) => ({
|
|
32
|
+
contents: virtualFiles.get(args.path).code,
|
|
33
|
+
loader: path.extname(args.path).slice(1),
|
|
34
|
+
external: isScan
|
|
35
|
+
})
|
|
36
|
+
);
|
|
34
37
|
build.onLoad({ filter: /\.marko$/ }, async (args) => {
|
|
35
38
|
try {
|
|
36
39
|
const { code, meta } = await compiler.compileFile(
|
package/dist/esbuild-plugin.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type * as
|
|
1
|
+
import type * as vite from "vite";
|
|
2
2
|
import type * as Compiler from "@marko/compiler";
|
|
3
|
-
|
|
3
|
+
type ESBuildOptions = Exclude<vite.DepOptimizationConfig["esbuildOptions"], undefined>;
|
|
4
|
+
type ESBuildPlugin = Exclude<ESBuildOptions["plugins"], undefined>[number];
|
|
5
|
+
export default function esbuildPlugin(compiler: typeof Compiler, config: Compiler.Config): ESBuildPlugin;
|
|
6
|
+
export {};
|
package/dist/esbuild-plugin.js
CHANGED
|
@@ -38,31 +38,34 @@ function esbuildPlugin(compiler, config) {
|
|
|
38
38
|
return {
|
|
39
39
|
name: "marko",
|
|
40
40
|
async setup(build) {
|
|
41
|
+
var _a;
|
|
41
42
|
const { platform = "browser" } = build.initialOptions;
|
|
43
|
+
const isScan = (_a = build.initialOptions.plugins) == null ? void 0 : _a.some(
|
|
44
|
+
(v) => v.name === "vite:dep-scan"
|
|
45
|
+
);
|
|
42
46
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
43
47
|
const finalConfig = {
|
|
44
48
|
...config,
|
|
45
|
-
output: platform === "browser" ? "dom" : "html",
|
|
49
|
+
output: isScan ? "hydrate" : platform === "browser" ? "dom" : "html",
|
|
46
50
|
resolveVirtualDependency(from, dep) {
|
|
47
51
|
virtualFiles.set(import_path.default.join(from, "..", dep.virtualPath), dep);
|
|
48
52
|
return dep.virtualPath;
|
|
49
53
|
}
|
|
50
54
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
(args)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
55
|
+
build.onResolve({ filter: /\.marko\./ }, (args) => {
|
|
56
|
+
return {
|
|
57
|
+
namespace: "marko:virtual",
|
|
58
|
+
path: import_path.default.resolve(args.resolveDir, args.path)
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
build.onLoad(
|
|
62
|
+
{ filter: /\.marko\./, namespace: "marko:virtual" },
|
|
63
|
+
(args) => ({
|
|
64
|
+
contents: virtualFiles.get(args.path).code,
|
|
65
|
+
loader: import_path.default.extname(args.path).slice(1),
|
|
66
|
+
external: isScan
|
|
67
|
+
})
|
|
68
|
+
);
|
|
66
69
|
build.onLoad({ filter: /\.marko$/ }, async (args) => {
|
|
67
70
|
try {
|
|
68
71
|
const { code, meta } = await compiler.compileFile(
|
|
@@ -108,5 +111,3 @@ function esbuildPlugin(compiler, config) {
|
|
|
108
111
|
}
|
|
109
112
|
};
|
|
110
113
|
}
|
|
111
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
-
0 && (module.exports = {});
|
package/dist/esbuild-plugin.mjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import type * as vite from "vite";
|
|
2
2
|
import type * as Compiler from "@marko/compiler";
|
|
3
|
-
import { BuildStore } from "./store";
|
|
3
|
+
import { type BuildStore } from "./store";
|
|
4
4
|
export * from "./store";
|
|
5
5
|
export type { BuildStore } from "./store";
|
|
6
|
-
declare module "@marko/babel-utils" {
|
|
7
|
-
interface Taglib {
|
|
8
|
-
id: string;
|
|
9
|
-
dirname: string;
|
|
10
|
-
path: string;
|
|
11
|
-
tags: TagDefinition[];
|
|
12
|
-
}
|
|
13
|
-
interface TaglibLookup {
|
|
14
|
-
taglibsById: Record<string, Taglib>;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
6
|
export interface Options {
|
|
18
7
|
linked?: boolean;
|
|
19
8
|
compiler?: string;
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,6 @@ var import_path = __toESM(require("path"));
|
|
|
37
37
|
var import_crypto = __toESM(require("crypto"));
|
|
38
38
|
var import_anymatch = __toESM(require("anymatch"));
|
|
39
39
|
var import_url = require("url");
|
|
40
|
-
var import_relative_import_path = require("relative-import-path");
|
|
41
40
|
var import_server_entry_template = __toESM(require("./server-entry-template"));
|
|
42
41
|
var import_manifest_generator = require("./manifest-generator");
|
|
43
42
|
var import_esbuild_plugin = __toESM(require("./esbuild-plugin"));
|
|
@@ -66,6 +65,7 @@ const babelCaller = {
|
|
|
66
65
|
supportsTopLevelAwait: true,
|
|
67
66
|
supportsExportNamespaceFrom: true
|
|
68
67
|
};
|
|
68
|
+
let registeredTag = false;
|
|
69
69
|
function markoPlugin(opts = {}) {
|
|
70
70
|
let compiler;
|
|
71
71
|
let { linked = true } = opts;
|
|
@@ -97,10 +97,8 @@ function markoPlugin(opts = {}) {
|
|
|
97
97
|
let isBuild = false;
|
|
98
98
|
let isSSRBuild = false;
|
|
99
99
|
let devServer;
|
|
100
|
-
let registeredTag = false;
|
|
101
100
|
let serverManifest;
|
|
102
101
|
let store;
|
|
103
|
-
let CJSTemplates;
|
|
104
102
|
let basePath = "/";
|
|
105
103
|
const entryIds = /* @__PURE__ */ new Set();
|
|
106
104
|
const cachedSources = /* @__PURE__ */ new Map();
|
|
@@ -112,7 +110,7 @@ function markoPlugin(opts = {}) {
|
|
|
112
110
|
enforce: "pre",
|
|
113
111
|
// Must be pre to allow us to resolve assets before vite.
|
|
114
112
|
async config(config, env) {
|
|
115
|
-
var _a, _b;
|
|
113
|
+
var _a, _b, _c, _d, _e;
|
|
116
114
|
compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
|
|
117
115
|
runtimeId = opts.runtimeId;
|
|
118
116
|
basePathVar = opts.basePathVar;
|
|
@@ -165,8 +163,15 @@ function markoPlugin(opts = {}) {
|
|
|
165
163
|
);
|
|
166
164
|
if (isTest) {
|
|
167
165
|
linked = false;
|
|
166
|
+
if ((_b = (_a = config.test) == null ? void 0 : _a.environment) == null ? void 0 : _b.includes(
|
|
167
|
+
"dom"
|
|
168
|
+
)) {
|
|
169
|
+
config.resolve ?? (config.resolve = {});
|
|
170
|
+
(_c = config.resolve).conditions ?? (_c.conditions = []);
|
|
171
|
+
config.resolve.conditions.push("browser");
|
|
172
|
+
}
|
|
168
173
|
}
|
|
169
|
-
if (
|
|
174
|
+
if (!registeredTag) {
|
|
170
175
|
const transformer = import_path.default.resolve(
|
|
171
176
|
thisFile,
|
|
172
177
|
"../render-assets-transform"
|
|
@@ -180,49 +185,33 @@ function markoPlugin(opts = {}) {
|
|
|
180
185
|
"<body>": { transformer }
|
|
181
186
|
});
|
|
182
187
|
}
|
|
183
|
-
const lookup = compiler.taglib.buildLookup(root);
|
|
184
|
-
const taglibDeps = [];
|
|
185
|
-
const optimizeTaglibDeps = [];
|
|
186
|
-
for (const name in lookup.taglibsById) {
|
|
187
|
-
const taglib = lookup.taglibsById[name];
|
|
188
|
-
if (!/^marko-(.+-)?core$/.test(taglib.id) && /[\\/]node_modules[\\/]/.test(taglib.dirname)) {
|
|
189
|
-
let isEsm;
|
|
190
|
-
for (const tagName in taglib.tags) {
|
|
191
|
-
const tag = taglib.tags[tagName];
|
|
192
|
-
const entry = tag.template || tag.renderer;
|
|
193
|
-
if (entry) {
|
|
194
|
-
const relativePath = (0, import_relative_import_path.relativeImportPath)(devEntryFile, entry);
|
|
195
|
-
taglibDeps.push(relativePath);
|
|
196
|
-
if (isTest || isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
|
|
197
|
-
optimizeTaglibDeps.push(relativePath);
|
|
198
|
-
} else {
|
|
199
|
-
(CJSTemplates ?? (CJSTemplates = /* @__PURE__ */ new Set())).add(normalizePath(entry));
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
188
|
const optimizeDeps = config.optimizeDeps ?? (config.optimizeDeps = {});
|
|
206
|
-
optimizeDeps.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
189
|
+
optimizeDeps.entries ?? (optimizeDeps.entries = [
|
|
190
|
+
"**/*.marko",
|
|
191
|
+
"!**/__snapshots__/**",
|
|
192
|
+
`!**/__tests__/**`,
|
|
193
|
+
`!**/coverage/**`
|
|
194
|
+
]);
|
|
195
|
+
const domDeps = compiler.getRuntimeEntryFiles("dom", opts.translator);
|
|
196
|
+
optimizeDeps.include = optimizeDeps.include ? [...optimizeDeps.include, ...domDeps] : domDeps;
|
|
214
197
|
const optimizeExtensions = optimizeDeps.extensions ?? (optimizeDeps.extensions = []);
|
|
215
198
|
optimizeExtensions.push(".marko");
|
|
216
199
|
const esbuildOptions = optimizeDeps.esbuildOptions ?? (optimizeDeps.esbuildOptions = {});
|
|
217
200
|
const esbuildPlugins = esbuildOptions.plugins ?? (esbuildOptions.plugins = []);
|
|
218
201
|
esbuildPlugins.push((0, import_esbuild_plugin.default)(compiler, baseConfig));
|
|
219
202
|
const ssr = config.ssr ?? (config.ssr = {});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
)
|
|
225
|
-
|
|
203
|
+
let { noExternal } = ssr;
|
|
204
|
+
if (noExternal !== true) {
|
|
205
|
+
const noExternalReg = /\.marko$/;
|
|
206
|
+
if (noExternal) {
|
|
207
|
+
if (Array.isArray(noExternal)) {
|
|
208
|
+
noExternal.push(noExternalReg);
|
|
209
|
+
} else {
|
|
210
|
+
noExternal = [noExternal, noExternalReg];
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
noExternal = noExternalReg;
|
|
214
|
+
}
|
|
226
215
|
}
|
|
227
216
|
if (basePathVar) {
|
|
228
217
|
config.experimental ?? (config.experimental = {});
|
|
@@ -231,7 +220,7 @@ function markoPlugin(opts = {}) {
|
|
|
231
220
|
"Cannot use @marko/vite `basePathVar` with Vite's `renderBuiltUrl` option."
|
|
232
221
|
);
|
|
233
222
|
}
|
|
234
|
-
const assetsDir = ((
|
|
223
|
+
const assetsDir = ((_e = (_d = config.build) == null ? void 0 : _d.assetsDir) == null ? void 0 : _e.replace(/[/\\]$/, "")) ?? "assets";
|
|
235
224
|
const assetsDirLen = assetsDir.length;
|
|
236
225
|
const assetsDirEnd = assetsDirLen + 1;
|
|
237
226
|
const trimAssertsDir = (fileName) => {
|
|
@@ -324,13 +313,15 @@ function markoPlugin(opts = {}) {
|
|
|
324
313
|
let importeeQuery = getMarkoQuery(importee);
|
|
325
314
|
if (importeeQuery) {
|
|
326
315
|
importee = importee.slice(0, -importeeQuery.length);
|
|
327
|
-
} else if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
importeeQuery
|
|
316
|
+
} else if (!importOpts.scan) {
|
|
317
|
+
if (ssr && linked && importer && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
318
|
+
isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
|
|
319
|
+
importeeQuery = serverEntryQuery;
|
|
320
|
+
} else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a = this.getModuleInfo(importer)) == null ? void 0 : _a.isEntry)) {
|
|
321
|
+
importeeQuery = browserEntryQuery;
|
|
322
|
+
} else if (linked && !ssr && !importeeQuery && isMarkoFile(importee)) {
|
|
323
|
+
importeeQuery = browserQuery;
|
|
324
|
+
}
|
|
334
325
|
}
|
|
335
326
|
if (importeeQuery) {
|
|
336
327
|
const resolved = importee[0] === "." ? {
|
|
@@ -359,7 +350,8 @@ function markoPlugin(opts = {}) {
|
|
|
359
350
|
}
|
|
360
351
|
return null;
|
|
361
352
|
},
|
|
362
|
-
async load(
|
|
353
|
+
async load(rawId) {
|
|
354
|
+
const id = stripVersionAndTimeStamp(rawId);
|
|
363
355
|
const query = getMarkoQuery(id);
|
|
364
356
|
switch (query) {
|
|
365
357
|
case serverEntryQuery: {
|
|
@@ -373,7 +365,8 @@ function markoPlugin(opts = {}) {
|
|
|
373
365
|
}
|
|
374
366
|
return virtualFiles.get(id) || null;
|
|
375
367
|
},
|
|
376
|
-
async transform(source,
|
|
368
|
+
async transform(source, rawId, ssr) {
|
|
369
|
+
let id = stripVersionAndTimeStamp(rawId);
|
|
377
370
|
const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
|
|
378
371
|
const query = getMarkoQuery(id);
|
|
379
372
|
if (query && !query.startsWith(virtualFileQuery)) {
|
|
@@ -422,19 +415,71 @@ function markoPlugin(opts = {}) {
|
|
|
422
415
|
if (linked) {
|
|
423
416
|
cachedSources.set(id, source);
|
|
424
417
|
}
|
|
425
|
-
if (
|
|
426
|
-
|
|
427
|
-
id,
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
418
|
+
if (!query) {
|
|
419
|
+
if (/[\\/]node_modules[\\/]/.test(id) && getModuleType(id) === "cjs") {
|
|
420
|
+
const { ast } = await compiler.compile(source, id, {
|
|
421
|
+
cache,
|
|
422
|
+
ast: true,
|
|
423
|
+
code: false,
|
|
424
|
+
output: "source",
|
|
425
|
+
sourceMaps: false
|
|
426
|
+
});
|
|
427
|
+
let namedExports = "";
|
|
428
|
+
let code2 = `import { createRequire } from "module";
|
|
429
|
+
`;
|
|
430
|
+
code2 += `import "@marko/compiler/register.js";
|
|
431
|
+
`;
|
|
432
|
+
code2 += `const mod = createRequire(import.meta.url)(${JSON.stringify(
|
|
433
|
+
id
|
|
434
|
+
)});
|
|
435
|
+
`;
|
|
436
|
+
for (const child of ast.program.body) {
|
|
437
|
+
switch (child.type) {
|
|
438
|
+
case "ExportAllDeclaration":
|
|
439
|
+
code2 += `export * from ${JSON.stringify(
|
|
440
|
+
child.source.value
|
|
441
|
+
)};
|
|
442
|
+
`;
|
|
443
|
+
break;
|
|
444
|
+
case "ExportNamedDeclaration":
|
|
445
|
+
if (child.specifiers) {
|
|
446
|
+
for (const specifier of child.specifiers) {
|
|
447
|
+
if (specifier.exported.type === "Identifier") {
|
|
448
|
+
namedExports += `${specifier.exported.name},`;
|
|
449
|
+
} else {
|
|
450
|
+
namedExports += `mod[${JSON.stringify(
|
|
451
|
+
specifier.exported.value
|
|
452
|
+
)}] as ${specifier.exported.value},`;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (child.declaration) {
|
|
457
|
+
if ("id" in child.declaration && child.declaration.id) {
|
|
458
|
+
if (child.declaration.id.type === "Identifier") {
|
|
459
|
+
namedExports += `${child.declaration.id.name},`;
|
|
460
|
+
} else {
|
|
461
|
+
namedExports += `mod[${JSON.stringify(
|
|
462
|
+
child.declaration.id.value
|
|
463
|
+
)}] as ${child.declaration.id.value},`;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if ("declarations" in child.declaration) {
|
|
467
|
+
for (const declaration of child.declaration.declarations) {
|
|
468
|
+
if (declaration.id.type === "Identifier") {
|
|
469
|
+
namedExports += `${declaration.id.name},`;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
code2 += `export const { ${namedExports} } = mod;
|
|
478
|
+
`;
|
|
479
|
+
code2 += `export default mod.default;
|
|
480
|
+
`;
|
|
481
|
+
return code2;
|
|
482
|
+
}
|
|
438
483
|
}
|
|
439
484
|
}
|
|
440
485
|
const compiled = await compiler.compile(
|
|
@@ -630,58 +675,17 @@ function getModuleType(file) {
|
|
|
630
675
|
}
|
|
631
676
|
return "esm";
|
|
632
677
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
if (
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
let namedExports;
|
|
643
|
-
for (const name of exports) {
|
|
644
|
-
if (name === "default") {
|
|
645
|
-
code += "export default mod.default;\n";
|
|
646
|
-
} else if (namedExports) {
|
|
647
|
-
namedExports += `, ${name}`;
|
|
648
|
-
} else {
|
|
649
|
-
namedExports = name;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
if (namedExports) {
|
|
653
|
-
code += `export const { ${namedExports} } = mod;
|
|
654
|
-
`;
|
|
655
|
-
}
|
|
656
|
-
return code;
|
|
657
|
-
}
|
|
658
|
-
function getExportIdentifiers(ast) {
|
|
659
|
-
const exports = /* @__PURE__ */ new Set();
|
|
660
|
-
for (const node of ast.program.body) {
|
|
661
|
-
switch (node.type) {
|
|
662
|
-
case "ExportDefaultDeclaration":
|
|
663
|
-
case "MarkoTag":
|
|
664
|
-
exports.add("default");
|
|
665
|
-
break;
|
|
666
|
-
case "ExportNamedDeclaration":
|
|
667
|
-
if (node.declaration) {
|
|
668
|
-
for (const declarator of node.declaration.declarations) {
|
|
669
|
-
exports.add(declarator.id.name);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
for (const specifier of node.specifiers) {
|
|
673
|
-
if (specifier.type !== "ExportSpecifier") {
|
|
674
|
-
exports.add(specifier.exported.name);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
break;
|
|
678
|
-
case "ExportAllDeclaration":
|
|
679
|
-
throw new Error(
|
|
680
|
-
'Re-exporting using `export * from "..."` is not supported.'
|
|
681
|
-
);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
return exports;
|
|
678
|
+
function stripVersionAndTimeStamp(id) {
|
|
679
|
+
const queryStart = id.indexOf("?");
|
|
680
|
+
if (queryStart === -1)
|
|
681
|
+
return id;
|
|
682
|
+
const url = id.slice(0, queryStart);
|
|
683
|
+
const query = id.slice(queryStart + 1).replace(/(?:^|[&])[vt]=[^&]/g, "");
|
|
684
|
+
if (query)
|
|
685
|
+
return `${url}?${query}`;
|
|
686
|
+
return url;
|
|
685
687
|
}
|
|
686
688
|
// Annotate the CommonJS export names for ESM import in node:
|
|
687
|
-
0 && (module.exports = {
|
|
689
|
+
0 && (module.exports = {
|
|
690
|
+
...require("./store")
|
|
691
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
esbuildPlugin
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HR4PYNIR.mjs";
|
|
4
4
|
import {
|
|
5
5
|
generateDocManifest,
|
|
6
6
|
generateInputDoc
|
|
@@ -23,7 +23,6 @@ import path from "path";
|
|
|
23
23
|
import crypto from "crypto";
|
|
24
24
|
import anyMatch from "anymatch";
|
|
25
25
|
import { pathToFileURL, fileURLToPath } from "url";
|
|
26
|
-
import { relativeImportPath } from "relative-import-path";
|
|
27
26
|
var POSIX_SEP = "/";
|
|
28
27
|
var WINDOWS_SEP = "\\";
|
|
29
28
|
var normalizePath = path.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
@@ -46,6 +45,7 @@ var babelCaller = {
|
|
|
46
45
|
supportsTopLevelAwait: true,
|
|
47
46
|
supportsExportNamespaceFrom: true
|
|
48
47
|
};
|
|
48
|
+
var registeredTag = false;
|
|
49
49
|
function markoPlugin(opts = {}) {
|
|
50
50
|
let compiler;
|
|
51
51
|
let { linked = true } = opts;
|
|
@@ -77,10 +77,8 @@ function markoPlugin(opts = {}) {
|
|
|
77
77
|
let isBuild = false;
|
|
78
78
|
let isSSRBuild = false;
|
|
79
79
|
let devServer;
|
|
80
|
-
let registeredTag = false;
|
|
81
80
|
let serverManifest;
|
|
82
81
|
let store;
|
|
83
|
-
let CJSTemplates;
|
|
84
82
|
let basePath = "/";
|
|
85
83
|
const entryIds = /* @__PURE__ */ new Set();
|
|
86
84
|
const cachedSources = /* @__PURE__ */ new Map();
|
|
@@ -92,7 +90,7 @@ function markoPlugin(opts = {}) {
|
|
|
92
90
|
enforce: "pre",
|
|
93
91
|
// Must be pre to allow us to resolve assets before vite.
|
|
94
92
|
async config(config, env) {
|
|
95
|
-
var _a, _b;
|
|
93
|
+
var _a, _b, _c, _d, _e;
|
|
96
94
|
compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
|
|
97
95
|
runtimeId = opts.runtimeId;
|
|
98
96
|
basePathVar = opts.basePathVar;
|
|
@@ -145,8 +143,15 @@ function markoPlugin(opts = {}) {
|
|
|
145
143
|
);
|
|
146
144
|
if (isTest) {
|
|
147
145
|
linked = false;
|
|
146
|
+
if ((_b = (_a = config.test) == null ? void 0 : _a.environment) == null ? void 0 : _b.includes(
|
|
147
|
+
"dom"
|
|
148
|
+
)) {
|
|
149
|
+
config.resolve ?? (config.resolve = {});
|
|
150
|
+
(_c = config.resolve).conditions ?? (_c.conditions = []);
|
|
151
|
+
config.resolve.conditions.push("browser");
|
|
152
|
+
}
|
|
148
153
|
}
|
|
149
|
-
if (
|
|
154
|
+
if (!registeredTag) {
|
|
150
155
|
const transformer = path.resolve(
|
|
151
156
|
thisFile,
|
|
152
157
|
"../render-assets-transform"
|
|
@@ -160,49 +165,33 @@ function markoPlugin(opts = {}) {
|
|
|
160
165
|
"<body>": { transformer }
|
|
161
166
|
});
|
|
162
167
|
}
|
|
163
|
-
const lookup = compiler.taglib.buildLookup(root);
|
|
164
|
-
const taglibDeps = [];
|
|
165
|
-
const optimizeTaglibDeps = [];
|
|
166
|
-
for (const name in lookup.taglibsById) {
|
|
167
|
-
const taglib = lookup.taglibsById[name];
|
|
168
|
-
if (!/^marko-(.+-)?core$/.test(taglib.id) && /[\\/]node_modules[\\/]/.test(taglib.dirname)) {
|
|
169
|
-
let isEsm;
|
|
170
|
-
for (const tagName in taglib.tags) {
|
|
171
|
-
const tag = taglib.tags[tagName];
|
|
172
|
-
const entry = tag.template || tag.renderer;
|
|
173
|
-
if (entry) {
|
|
174
|
-
const relativePath = relativeImportPath(devEntryFile, entry);
|
|
175
|
-
taglibDeps.push(relativePath);
|
|
176
|
-
if (isTest || isBuild || (isEsm ?? (isEsm = getModuleType(taglib.path) === "esm"))) {
|
|
177
|
-
optimizeTaglibDeps.push(relativePath);
|
|
178
|
-
} else {
|
|
179
|
-
(CJSTemplates ?? (CJSTemplates = /* @__PURE__ */ new Set())).add(normalizePath(entry));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
168
|
const optimizeDeps = config.optimizeDeps ?? (config.optimizeDeps = {});
|
|
186
|
-
optimizeDeps.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
169
|
+
optimizeDeps.entries ?? (optimizeDeps.entries = [
|
|
170
|
+
"**/*.marko",
|
|
171
|
+
"!**/__snapshots__/**",
|
|
172
|
+
`!**/__tests__/**`,
|
|
173
|
+
`!**/coverage/**`
|
|
174
|
+
]);
|
|
175
|
+
const domDeps = compiler.getRuntimeEntryFiles("dom", opts.translator);
|
|
176
|
+
optimizeDeps.include = optimizeDeps.include ? [...optimizeDeps.include, ...domDeps] : domDeps;
|
|
194
177
|
const optimizeExtensions = optimizeDeps.extensions ?? (optimizeDeps.extensions = []);
|
|
195
178
|
optimizeExtensions.push(".marko");
|
|
196
179
|
const esbuildOptions = optimizeDeps.esbuildOptions ?? (optimizeDeps.esbuildOptions = {});
|
|
197
180
|
const esbuildPlugins = esbuildOptions.plugins ?? (esbuildOptions.plugins = []);
|
|
198
181
|
esbuildPlugins.push(esbuildPlugin(compiler, baseConfig));
|
|
199
182
|
const ssr = config.ssr ?? (config.ssr = {});
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
)
|
|
205
|
-
|
|
183
|
+
let { noExternal } = ssr;
|
|
184
|
+
if (noExternal !== true) {
|
|
185
|
+
const noExternalReg = /\.marko$/;
|
|
186
|
+
if (noExternal) {
|
|
187
|
+
if (Array.isArray(noExternal)) {
|
|
188
|
+
noExternal.push(noExternalReg);
|
|
189
|
+
} else {
|
|
190
|
+
noExternal = [noExternal, noExternalReg];
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
noExternal = noExternalReg;
|
|
194
|
+
}
|
|
206
195
|
}
|
|
207
196
|
if (basePathVar) {
|
|
208
197
|
config.experimental ?? (config.experimental = {});
|
|
@@ -211,7 +200,7 @@ function markoPlugin(opts = {}) {
|
|
|
211
200
|
"Cannot use @marko/vite `basePathVar` with Vite's `renderBuiltUrl` option."
|
|
212
201
|
);
|
|
213
202
|
}
|
|
214
|
-
const assetsDir = ((
|
|
203
|
+
const assetsDir = ((_e = (_d = config.build) == null ? void 0 : _d.assetsDir) == null ? void 0 : _e.replace(/[/\\]$/, "")) ?? "assets";
|
|
215
204
|
const assetsDirLen = assetsDir.length;
|
|
216
205
|
const assetsDirEnd = assetsDirLen + 1;
|
|
217
206
|
const trimAssertsDir = (fileName) => {
|
|
@@ -304,13 +293,15 @@ function markoPlugin(opts = {}) {
|
|
|
304
293
|
let importeeQuery = getMarkoQuery(importee);
|
|
305
294
|
if (importeeQuery) {
|
|
306
295
|
importee = importee.slice(0, -importeeQuery.length);
|
|
307
|
-
} else if (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
importeeQuery
|
|
296
|
+
} else if (!importOpts.scan) {
|
|
297
|
+
if (ssr && linked && importer && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
298
|
+
isMarkoFile(importee) && !isMarkoFile(importer.replace(queryReg, ""))) {
|
|
299
|
+
importeeQuery = serverEntryQuery;
|
|
300
|
+
} else if (!ssr && isBuild && importer && isMarkoFile(importee) && ((_a = this.getModuleInfo(importer)) == null ? void 0 : _a.isEntry)) {
|
|
301
|
+
importeeQuery = browserEntryQuery;
|
|
302
|
+
} else if (linked && !ssr && !importeeQuery && isMarkoFile(importee)) {
|
|
303
|
+
importeeQuery = browserQuery;
|
|
304
|
+
}
|
|
314
305
|
}
|
|
315
306
|
if (importeeQuery) {
|
|
316
307
|
const resolved = importee[0] === "." ? {
|
|
@@ -339,7 +330,8 @@ function markoPlugin(opts = {}) {
|
|
|
339
330
|
}
|
|
340
331
|
return null;
|
|
341
332
|
},
|
|
342
|
-
async load(
|
|
333
|
+
async load(rawId) {
|
|
334
|
+
const id = stripVersionAndTimeStamp(rawId);
|
|
343
335
|
const query = getMarkoQuery(id);
|
|
344
336
|
switch (query) {
|
|
345
337
|
case serverEntryQuery: {
|
|
@@ -353,7 +345,8 @@ function markoPlugin(opts = {}) {
|
|
|
353
345
|
}
|
|
354
346
|
return virtualFiles.get(id) || null;
|
|
355
347
|
},
|
|
356
|
-
async transform(source,
|
|
348
|
+
async transform(source, rawId, ssr) {
|
|
349
|
+
let id = stripVersionAndTimeStamp(rawId);
|
|
357
350
|
const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
|
|
358
351
|
const query = getMarkoQuery(id);
|
|
359
352
|
if (query && !query.startsWith(virtualFileQuery)) {
|
|
@@ -402,19 +395,71 @@ function markoPlugin(opts = {}) {
|
|
|
402
395
|
if (linked) {
|
|
403
396
|
cachedSources.set(id, source);
|
|
404
397
|
}
|
|
405
|
-
if (
|
|
406
|
-
|
|
407
|
-
id,
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
398
|
+
if (!query) {
|
|
399
|
+
if (/[\\/]node_modules[\\/]/.test(id) && getModuleType(id) === "cjs") {
|
|
400
|
+
const { ast } = await compiler.compile(source, id, {
|
|
401
|
+
cache,
|
|
402
|
+
ast: true,
|
|
403
|
+
code: false,
|
|
404
|
+
output: "source",
|
|
405
|
+
sourceMaps: false
|
|
406
|
+
});
|
|
407
|
+
let namedExports = "";
|
|
408
|
+
let code2 = `import { createRequire } from "module";
|
|
409
|
+
`;
|
|
410
|
+
code2 += `import "@marko/compiler/register.js";
|
|
411
|
+
`;
|
|
412
|
+
code2 += `const mod = createRequire(import.meta.url)(${JSON.stringify(
|
|
413
|
+
id
|
|
414
|
+
)});
|
|
415
|
+
`;
|
|
416
|
+
for (const child of ast.program.body) {
|
|
417
|
+
switch (child.type) {
|
|
418
|
+
case "ExportAllDeclaration":
|
|
419
|
+
code2 += `export * from ${JSON.stringify(
|
|
420
|
+
child.source.value
|
|
421
|
+
)};
|
|
422
|
+
`;
|
|
423
|
+
break;
|
|
424
|
+
case "ExportNamedDeclaration":
|
|
425
|
+
if (child.specifiers) {
|
|
426
|
+
for (const specifier of child.specifiers) {
|
|
427
|
+
if (specifier.exported.type === "Identifier") {
|
|
428
|
+
namedExports += `${specifier.exported.name},`;
|
|
429
|
+
} else {
|
|
430
|
+
namedExports += `mod[${JSON.stringify(
|
|
431
|
+
specifier.exported.value
|
|
432
|
+
)}] as ${specifier.exported.value},`;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (child.declaration) {
|
|
437
|
+
if ("id" in child.declaration && child.declaration.id) {
|
|
438
|
+
if (child.declaration.id.type === "Identifier") {
|
|
439
|
+
namedExports += `${child.declaration.id.name},`;
|
|
440
|
+
} else {
|
|
441
|
+
namedExports += `mod[${JSON.stringify(
|
|
442
|
+
child.declaration.id.value
|
|
443
|
+
)}] as ${child.declaration.id.value},`;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if ("declarations" in child.declaration) {
|
|
447
|
+
for (const declaration of child.declaration.declarations) {
|
|
448
|
+
if (declaration.id.type === "Identifier") {
|
|
449
|
+
namedExports += `${declaration.id.name},`;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
code2 += `export const { ${namedExports} } = mod;
|
|
458
|
+
`;
|
|
459
|
+
code2 += `export default mod.default;
|
|
460
|
+
`;
|
|
461
|
+
return code2;
|
|
462
|
+
}
|
|
418
463
|
}
|
|
419
464
|
}
|
|
420
465
|
const compiled = await compiler.compile(
|
|
@@ -610,58 +655,15 @@ function getModuleType(file) {
|
|
|
610
655
|
}
|
|
611
656
|
return "esm";
|
|
612
657
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
if (
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
let namedExports;
|
|
623
|
-
for (const name of exports) {
|
|
624
|
-
if (name === "default") {
|
|
625
|
-
code += "export default mod.default;\n";
|
|
626
|
-
} else if (namedExports) {
|
|
627
|
-
namedExports += `, ${name}`;
|
|
628
|
-
} else {
|
|
629
|
-
namedExports = name;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
if (namedExports) {
|
|
633
|
-
code += `export const { ${namedExports} } = mod;
|
|
634
|
-
`;
|
|
635
|
-
}
|
|
636
|
-
return code;
|
|
637
|
-
}
|
|
638
|
-
function getExportIdentifiers(ast) {
|
|
639
|
-
const exports = /* @__PURE__ */ new Set();
|
|
640
|
-
for (const node of ast.program.body) {
|
|
641
|
-
switch (node.type) {
|
|
642
|
-
case "ExportDefaultDeclaration":
|
|
643
|
-
case "MarkoTag":
|
|
644
|
-
exports.add("default");
|
|
645
|
-
break;
|
|
646
|
-
case "ExportNamedDeclaration":
|
|
647
|
-
if (node.declaration) {
|
|
648
|
-
for (const declarator of node.declaration.declarations) {
|
|
649
|
-
exports.add(declarator.id.name);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
for (const specifier of node.specifiers) {
|
|
653
|
-
if (specifier.type !== "ExportSpecifier") {
|
|
654
|
-
exports.add(specifier.exported.name);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
break;
|
|
658
|
-
case "ExportAllDeclaration":
|
|
659
|
-
throw new Error(
|
|
660
|
-
'Re-exporting using `export * from "..."` is not supported.'
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
return exports;
|
|
658
|
+
function stripVersionAndTimeStamp(id) {
|
|
659
|
+
const queryStart = id.indexOf("?");
|
|
660
|
+
if (queryStart === -1)
|
|
661
|
+
return id;
|
|
662
|
+
const url = id.slice(0, queryStart);
|
|
663
|
+
const query = id.slice(queryStart + 1).replace(/(?:^|[&])[vt]=[^&]/g, "");
|
|
664
|
+
if (query)
|
|
665
|
+
return `${url}?${query}`;
|
|
666
|
+
return url;
|
|
665
667
|
}
|
|
666
668
|
export {
|
|
667
669
|
FileStore,
|
package/dist/serializer.js
CHANGED
package/dist/store/file-store.js
CHANGED
package/package.json
CHANGED
|
@@ -1,47 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/vite",
|
|
3
3
|
"description": "A Marko plugin for Vite",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"author": "Dylan Piercey <dpiercey@ebay.com>",
|
|
6
6
|
"bugs": "https://github.com/marko-js/vite/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"anymatch": "^3.1.3",
|
|
9
9
|
"domelementtype": "^2.3.0",
|
|
10
10
|
"domhandler": "^5.0.3",
|
|
11
|
-
"htmlparser2": "^
|
|
12
|
-
"relative-import-path": "^1.0.0"
|
|
11
|
+
"htmlparser2": "^9.0.0"
|
|
13
12
|
},
|
|
14
13
|
"devDependencies": {
|
|
15
14
|
"@changesets/changelog-github": "^0.4.8",
|
|
16
|
-
"@changesets/cli": "^2.26.
|
|
17
|
-
"@marko/compiler": "^5.
|
|
18
|
-
"@marko/fixture-snapshots": "^2.1
|
|
19
|
-
"@marko/testing-library": "^6.1.
|
|
20
|
-
"@types/jsdom": "^
|
|
21
|
-
"@types/mocha": "^10.0.
|
|
22
|
-
"@types/node": "^
|
|
23
|
-
"@types/serve-handler": "^6.1.
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
25
|
-
"@typescript-eslint/parser": "^
|
|
15
|
+
"@changesets/cli": "^2.26.2",
|
|
16
|
+
"@marko/compiler": "^5.33.2",
|
|
17
|
+
"@marko/fixture-snapshots": "^2.2.1",
|
|
18
|
+
"@marko/testing-library": "^6.1.4",
|
|
19
|
+
"@types/jsdom": "^21.1.3",
|
|
20
|
+
"@types/mocha": "^10.0.2",
|
|
21
|
+
"@types/node": "^20.8.2",
|
|
22
|
+
"@types/serve-handler": "^6.1.2",
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
24
|
+
"@typescript-eslint/parser": "^6.7.4",
|
|
26
25
|
"cross-env": "^7.0.3",
|
|
27
|
-
"esbuild": "^0.
|
|
28
|
-
"eslint": "^8.
|
|
29
|
-
"eslint-config-prettier": "^
|
|
30
|
-
"fast-glob": "^3.
|
|
26
|
+
"esbuild": "^0.19.4",
|
|
27
|
+
"eslint": "^8.50.0",
|
|
28
|
+
"eslint-config-prettier": "^9.0.0",
|
|
29
|
+
"fast-glob": "^3.3.1",
|
|
31
30
|
"fixpack": "^4.0.0",
|
|
32
31
|
"husky": "^8.0.3",
|
|
33
|
-
"jsdom": "^
|
|
34
|
-
"lint-staged": "^
|
|
35
|
-
"marko": "^5.
|
|
32
|
+
"jsdom": "^22.1.0",
|
|
33
|
+
"lint-staged": "^14.0.1",
|
|
34
|
+
"marko": "^5.31.11",
|
|
36
35
|
"mocha": "^10.2.0",
|
|
37
36
|
"mocha-snap": "^5.0.0",
|
|
38
37
|
"nyc": "^15.1.0",
|
|
39
|
-
"playwright": "^1.
|
|
40
|
-
"prettier": "^2.8.
|
|
38
|
+
"playwright": "^1.38.1",
|
|
39
|
+
"prettier": "^2.8.8",
|
|
41
40
|
"serve-handler": "^6.1.5",
|
|
42
|
-
"tsx": "^3.
|
|
43
|
-
"typescript": "^
|
|
44
|
-
"vite": "^4.
|
|
41
|
+
"tsx": "^3.13.0",
|
|
42
|
+
"typescript": "^5.2.2",
|
|
43
|
+
"vite": "^4.4.11"
|
|
45
44
|
},
|
|
46
45
|
"exports": {
|
|
47
46
|
".": {
|
|
@@ -69,7 +68,7 @@
|
|
|
69
68
|
"module": "./dist/index.mjs",
|
|
70
69
|
"peerDependencies": {
|
|
71
70
|
"@marko/compiler": "^5",
|
|
72
|
-
"vite": "^2 || ^3 || ^4"
|
|
71
|
+
"vite": "^2 || ^3 || ^4 || ^5"
|
|
73
72
|
},
|
|
74
73
|
"repository": {
|
|
75
74
|
"type": "git",
|