@marko/run 0.5.16 → 0.6.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/.tsbuildinfo +1 -1
- package/dist/adapter/index.cjs +71 -193
- package/dist/adapter/index.js +71 -193
- package/dist/adapter/middleware.cjs +70 -202
- package/dist/adapter/middleware.js +70 -192
- package/dist/cli/index.mjs +42 -41
- package/dist/runtime/internal.cjs +1 -1
- package/dist/runtime/internal.js +1 -1
- package/dist/runtime/types.d.ts +1 -8
- package/dist/vite/index.cjs +42 -41
- package/dist/vite/index.js +42 -41
- package/package.json +12 -13
- package/dist/adapter/polyfill.d.ts +0 -11
package/dist/cli/index.mjs
CHANGED
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
// src/vite/plugin.ts
|
|
26
26
|
import markoVitePlugin from "@marko/vite";
|
|
27
27
|
import browserslist from "browserslist";
|
|
28
|
-
import { createHash } from "crypto";
|
|
29
28
|
import createDebug from "debug";
|
|
30
29
|
import { resolveToEsbuildTarget } from "esbuild-plugin-browserslist";
|
|
31
30
|
import fs3 from "fs";
|
|
@@ -1200,12 +1199,13 @@ var _VDir = class _VDir {
|
|
|
1200
1199
|
}
|
|
1201
1200
|
addDir(path6, segment) {
|
|
1202
1201
|
const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
|
|
1203
|
-
|
|
1202
|
+
const key = segment.type === "$" ? segment.raw : segment.name;
|
|
1203
|
+
if (!map.has(key)) {
|
|
1204
1204
|
const dir = new _VDir(this, segment, path6);
|
|
1205
|
-
map.set(
|
|
1205
|
+
map.set(key, dir);
|
|
1206
1206
|
return dir;
|
|
1207
1207
|
}
|
|
1208
|
-
return map.get(
|
|
1208
|
+
return map.get(key);
|
|
1209
1209
|
}
|
|
1210
1210
|
addFile(file) {
|
|
1211
1211
|
if (!this.files) {
|
|
@@ -1245,17 +1245,18 @@ var _VDir = class _VDir {
|
|
|
1245
1245
|
}
|
|
1246
1246
|
static addPaths(roots, paths) {
|
|
1247
1247
|
const dirs = [];
|
|
1248
|
-
const unique = /* @__PURE__ */ new
|
|
1248
|
+
const unique = /* @__PURE__ */ new Map();
|
|
1249
1249
|
for (const root of roots) {
|
|
1250
1250
|
for (const path6 of paths) {
|
|
1251
1251
|
let dir = root;
|
|
1252
1252
|
for (const segment of path6.segments) {
|
|
1253
1253
|
dir = dir.addDir(path6, segment);
|
|
1254
1254
|
}
|
|
1255
|
-
|
|
1255
|
+
const existing = unique.get(dir.path);
|
|
1256
|
+
if (existing) {
|
|
1256
1257
|
const sources = /* @__PURE__ */ new Set();
|
|
1257
1258
|
let sourcePath = "";
|
|
1258
|
-
for (const { source } of
|
|
1259
|
+
for (const { source } of existing) {
|
|
1259
1260
|
if (source && !sources.has(source.source)) {
|
|
1260
1261
|
sources.add(source.source);
|
|
1261
1262
|
sourcePath += source.source + "/";
|
|
@@ -1265,7 +1266,7 @@ var _VDir = class _VDir {
|
|
|
1265
1266
|
`Ambiguous directory structure: '${sourcePath}${path6.source}' defines '${dir.path}' multiple times.`
|
|
1266
1267
|
);
|
|
1267
1268
|
} else {
|
|
1268
|
-
unique.
|
|
1269
|
+
unique.set(dir.path, dir);
|
|
1269
1270
|
dirs.push(dir);
|
|
1270
1271
|
}
|
|
1271
1272
|
}
|
|
@@ -1408,10 +1409,10 @@ async function buildRoutes(sources) {
|
|
|
1408
1409
|
const route = routes[existing.index];
|
|
1409
1410
|
const existingFiles = [route.handler, route.page].filter(Boolean).map((f) => f.filePath);
|
|
1410
1411
|
const currentFiles = [handler, page].filter(Boolean).map((f) => f.filePath);
|
|
1411
|
-
throw new Error(`Duplicate routes for path '${path6.
|
|
1412
|
-
${existingFiles.join(" and ")} via '${existing.dir.
|
|
1412
|
+
throw new Error(`Duplicate routes for path '${path6.id}' were defined. A route established by:
|
|
1413
|
+
${existingFiles.join(" and ")} via '${existing.dir.fullPath}'
|
|
1413
1414
|
collides with
|
|
1414
|
-
${currentFiles.join(" and ")} via '${dir.
|
|
1415
|
+
${currentFiles.join(" and ")} via '${dir.fullPath}'
|
|
1415
1416
|
`);
|
|
1416
1417
|
}
|
|
1417
1418
|
uniqueRoutes.set(path6.id, { dir, index: routes.length });
|
|
@@ -1779,6 +1780,8 @@ function markoRun(opts = {}) {
|
|
|
1779
1780
|
let { routesDir, adapter, ...markoVitePluginOptions } = opts;
|
|
1780
1781
|
let store;
|
|
1781
1782
|
let root;
|
|
1783
|
+
let shouldEmptyOutDir = false;
|
|
1784
|
+
let outputDir;
|
|
1782
1785
|
let resolvedRoutesDir;
|
|
1783
1786
|
let entryFilesDir;
|
|
1784
1787
|
let entryFilesDirPosix;
|
|
@@ -1962,7 +1965,7 @@ function markoRun(opts = {}) {
|
|
|
1962
1965
|
name: `${PLUGIN_NAME_PREFIX}:pre`,
|
|
1963
1966
|
enforce: "pre",
|
|
1964
1967
|
async config(config2, env) {
|
|
1965
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1968
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1966
1969
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
1967
1970
|
if (externalPluginOptions) {
|
|
1968
1971
|
opts = mergeConfig(opts, externalPluginOptions);
|
|
@@ -1993,11 +1996,8 @@ function markoRun(opts = {}) {
|
|
|
1993
1996
|
markoVitePluginOptions.runtimeId = opts.runtimeId;
|
|
1994
1997
|
markoVitePluginOptions.basePathVar = opts.basePathVar;
|
|
1995
1998
|
resolvedRoutesDir = path4.resolve(root, routesDir);
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
".marko",
|
|
1999
|
-
createHash("shake256", { outputLength: 4 }).update(root).digest("hex")
|
|
2000
|
-
);
|
|
1999
|
+
outputDir = path4.join(root, ((_d = config2.build) == null ? void 0 : _d.outDir) || "dist");
|
|
2000
|
+
entryFilesDir = path4.join(outputDir, ".marko-run");
|
|
2001
2001
|
entryFilesDirPosix = normalizePath(entryFilesDir);
|
|
2002
2002
|
relativeEntryFilesDirPosix = normalizePath(
|
|
2003
2003
|
path4.relative(root, entryFilesDir)
|
|
@@ -2005,9 +2005,9 @@ function markoRun(opts = {}) {
|
|
|
2005
2005
|
typesDir = path4.join(root, ".marko-run");
|
|
2006
2006
|
devEntryFile = path4.join(root, "index.html");
|
|
2007
2007
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
2008
|
-
let outDir = ((
|
|
2009
|
-
const assetsDir = ((
|
|
2010
|
-
let rollupOutputOptions = (
|
|
2008
|
+
let outDir = ((_e = config2.build) == null ? void 0 : _e.outDir) || "dist";
|
|
2009
|
+
const assetsDir = ((_f = config2.build) == null ? void 0 : _f.assetsDir) || "assets";
|
|
2010
|
+
let rollupOutputOptions = (_h = (_g = config2.build) == null ? void 0 : _g.rollupOptions) == null ? void 0 : _h.output;
|
|
2011
2011
|
if (isBuild) {
|
|
2012
2012
|
if (!isSSRBuild) {
|
|
2013
2013
|
outDir = path4.join(outDir, CLIENT_OUT_DIR);
|
|
@@ -2047,9 +2047,10 @@ function markoRun(opts = {}) {
|
|
|
2047
2047
|
}));
|
|
2048
2048
|
}
|
|
2049
2049
|
}
|
|
2050
|
-
const browserslistTarget = isBuild && !((
|
|
2050
|
+
const browserslistTarget = isBuild && !((_i = config2.build) == null ? void 0 : _i.target) ? browserslist(void 0, {
|
|
2051
2051
|
path: root
|
|
2052
2052
|
}) : void 0;
|
|
2053
|
+
shouldEmptyOutDir = ((_j = config2.build) == null ? void 0 : _j.emptyOutDir) ?? true;
|
|
2053
2054
|
let pluginConfig = {
|
|
2054
2055
|
logLevel: isBuild ? "warn" : void 0,
|
|
2055
2056
|
define: isBuild ? {
|
|
@@ -2067,18 +2068,17 @@ function markoRun(opts = {}) {
|
|
|
2067
2068
|
target: (browserslistTarget == null ? void 0 : browserslistTarget.length) ? resolveToEsbuildTarget(browserslistTarget, {
|
|
2068
2069
|
printUnknownTargets: false
|
|
2069
2070
|
}) : void 0,
|
|
2070
|
-
emptyOutDir: isSSRBuild,
|
|
2071
|
-
// Avoid server & client deleting files from each other.
|
|
2072
2071
|
copyPublicDir: !isSSRBuild,
|
|
2073
2072
|
ssrEmitAssets: false,
|
|
2073
|
+
emptyOutDir: false,
|
|
2074
2074
|
rollupOptions: {
|
|
2075
2075
|
output: rollupOutputOptions
|
|
2076
2076
|
},
|
|
2077
2077
|
modulePreload: { polyfill: false },
|
|
2078
|
-
sourcemap: ((
|
|
2078
|
+
sourcemap: ((_k = config2.build) == null ? void 0 : _k.sourcemap) ?? (isBuild && !isSSRBuild)
|
|
2079
2079
|
},
|
|
2080
2080
|
optimizeDeps: {
|
|
2081
|
-
entries: !((
|
|
2081
|
+
entries: !((_l = config2.optimizeDeps) == null ? void 0 : _l.entries) ? [
|
|
2082
2082
|
"src/pages/**/*+{page,layout}.marko",
|
|
2083
2083
|
"!**/__snapshots__/**",
|
|
2084
2084
|
`!**/__tests__/**`,
|
|
@@ -2166,6 +2166,11 @@ function markoRun(opts = {}) {
|
|
|
2166
2166
|
}).unwatch(typesDir + "/*");
|
|
2167
2167
|
},
|
|
2168
2168
|
async buildStart(_options) {
|
|
2169
|
+
if (isSSRBuild && shouldEmptyOutDir) {
|
|
2170
|
+
if (fs3.existsSync(outputDir)) {
|
|
2171
|
+
fs3.rmSync(outputDir, { recursive: true });
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2169
2174
|
if (isBuild && !isSSRBuild) {
|
|
2170
2175
|
try {
|
|
2171
2176
|
routeData = await store.read();
|
|
@@ -2270,13 +2275,18 @@ function markoRun(opts = {}) {
|
|
|
2270
2275
|
}
|
|
2271
2276
|
},
|
|
2272
2277
|
async closeBundle() {
|
|
2273
|
-
if (isBuild && !isSSRBuild
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2278
|
+
if (isBuild && !isSSRBuild) {
|
|
2279
|
+
if (fs3.existsSync(entryFilesDir)) {
|
|
2280
|
+
fs3.rmSync(entryFilesDir, { recursive: true });
|
|
2281
|
+
}
|
|
2282
|
+
if ((adapter == null ? void 0 : adapter.buildEnd) && routes) {
|
|
2283
|
+
await adapter.buildEnd(
|
|
2284
|
+
resolvedConfig,
|
|
2285
|
+
routes.list,
|
|
2286
|
+
routeData.builtEntries,
|
|
2287
|
+
routeData.sourceEntries
|
|
2288
|
+
);
|
|
2289
|
+
}
|
|
2280
2290
|
}
|
|
2281
2291
|
}
|
|
2282
2292
|
}
|
|
@@ -2368,15 +2378,6 @@ function getImporters(module, fileName, seen = /* @__PURE__ */ new Set()) {
|
|
|
2368
2378
|
}
|
|
2369
2379
|
return seen;
|
|
2370
2380
|
}
|
|
2371
|
-
function getModulesDir(root, dir = __dirname) {
|
|
2372
|
-
if (dir.startsWith(root)) {
|
|
2373
|
-
const index = dir.indexOf("node_modules");
|
|
2374
|
-
if (index >= 0) {
|
|
2375
|
-
return dir.slice(0, index + 12);
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
return path4.join(root, "node_modules");
|
|
2379
|
-
}
|
|
2380
2381
|
var defaultConfigPlugin = {
|
|
2381
2382
|
name: `${PLUGIN_NAME_PREFIX}:defaults`,
|
|
2382
2383
|
enforce: "pre",
|
|
@@ -89,7 +89,7 @@ function createContext(route, request, platform, url = new URL(request.url)) {
|
|
|
89
89
|
}
|
|
90
90
|
async function call(handler, next, context) {
|
|
91
91
|
let response;
|
|
92
|
-
if (process.env.NODE_ENV
|
|
92
|
+
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") {
|
|
93
93
|
let nextCallCount = 0;
|
|
94
94
|
let didThrow = false;
|
|
95
95
|
try {
|
package/dist/runtime/internal.js
CHANGED
|
@@ -47,7 +47,7 @@ function createContext(route, request, platform, url = new URL(request.url)) {
|
|
|
47
47
|
}
|
|
48
48
|
async function call(handler, next, context) {
|
|
49
49
|
let response;
|
|
50
|
-
if (process.env.NODE_ENV
|
|
50
|
+
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") {
|
|
51
51
|
let nextCallCount = 0;
|
|
52
52
|
let didThrow = false;
|
|
53
53
|
try {
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
export type Awaitable<T> = Promise<T> | T;
|
|
2
2
|
type OneOrMany<T> = T | T[];
|
|
3
3
|
type NoParams = {};
|
|
4
|
-
type AllKeys<T> = T extends T ? keyof T : never;
|
|
5
4
|
type Simplify<T> = T extends unknown ? {
|
|
6
5
|
[K in keyof T]: T[K];
|
|
7
6
|
} : never;
|
|
8
|
-
type SuperSet<T, U extends T> = Simplify<T & {
|
|
9
|
-
[K in AllKeys<U> as K extends keyof T ? never : K]: undefined;
|
|
10
|
-
}>;
|
|
11
|
-
type SuperSets<T, U extends T, K extends keyof T> = Omit<T, K> & {
|
|
12
|
-
[P in K]: SuperSet<T[P], U[P]>;
|
|
13
|
-
};
|
|
14
7
|
export interface Platform {
|
|
15
8
|
}
|
|
16
9
|
export interface Context<TRoute extends Route = AnyRoute> {
|
|
@@ -22,7 +15,7 @@ export interface Context<TRoute extends Route = AnyRoute> {
|
|
|
22
15
|
readonly platform: Platform;
|
|
23
16
|
readonly serializedGlobals: Record<string, boolean>;
|
|
24
17
|
}
|
|
25
|
-
export type MultiRouteContext<TRoute extends Route
|
|
18
|
+
export type MultiRouteContext<TRoute extends Route> = TRoute extends any ? Context<Simplify<TRoute>> : never;
|
|
26
19
|
export type ParamsObject = Record<string, string>;
|
|
27
20
|
export type InputObject = Record<PropertyKey, any>;
|
|
28
21
|
export type NextFunction = () => Awaitable<Response>;
|
package/dist/vite/index.cjs
CHANGED
|
@@ -57,7 +57,6 @@ var __importMetaURL = (0, import_url.pathToFileURL)(__filename);
|
|
|
57
57
|
// src/vite/plugin.ts
|
|
58
58
|
var import_vite = __toESM(require("@marko/vite"), 1);
|
|
59
59
|
var import_browserslist = __toESM(require("browserslist"), 1);
|
|
60
|
-
var import_crypto = require("crypto");
|
|
61
60
|
var import_debug = __toESM(require("debug"), 1);
|
|
62
61
|
var import_esbuild_plugin_browserslist = require("esbuild-plugin-browserslist");
|
|
63
62
|
var import_fs3 = __toESM(require("fs"), 1);
|
|
@@ -1232,12 +1231,13 @@ var _VDir = class _VDir {
|
|
|
1232
1231
|
}
|
|
1233
1232
|
addDir(path5, segment) {
|
|
1234
1233
|
const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
|
|
1235
|
-
|
|
1234
|
+
const key = segment.type === "$" ? segment.raw : segment.name;
|
|
1235
|
+
if (!map.has(key)) {
|
|
1236
1236
|
const dir = new _VDir(this, segment, path5);
|
|
1237
|
-
map.set(
|
|
1237
|
+
map.set(key, dir);
|
|
1238
1238
|
return dir;
|
|
1239
1239
|
}
|
|
1240
|
-
return map.get(
|
|
1240
|
+
return map.get(key);
|
|
1241
1241
|
}
|
|
1242
1242
|
addFile(file) {
|
|
1243
1243
|
if (!this.files) {
|
|
@@ -1277,17 +1277,18 @@ var _VDir = class _VDir {
|
|
|
1277
1277
|
}
|
|
1278
1278
|
static addPaths(roots, paths) {
|
|
1279
1279
|
const dirs = [];
|
|
1280
|
-
const unique = /* @__PURE__ */ new
|
|
1280
|
+
const unique = /* @__PURE__ */ new Map();
|
|
1281
1281
|
for (const root of roots) {
|
|
1282
1282
|
for (const path5 of paths) {
|
|
1283
1283
|
let dir = root;
|
|
1284
1284
|
for (const segment of path5.segments) {
|
|
1285
1285
|
dir = dir.addDir(path5, segment);
|
|
1286
1286
|
}
|
|
1287
|
-
|
|
1287
|
+
const existing = unique.get(dir.path);
|
|
1288
|
+
if (existing) {
|
|
1288
1289
|
const sources = /* @__PURE__ */ new Set();
|
|
1289
1290
|
let sourcePath = "";
|
|
1290
|
-
for (const { source } of
|
|
1291
|
+
for (const { source } of existing) {
|
|
1291
1292
|
if (source && !sources.has(source.source)) {
|
|
1292
1293
|
sources.add(source.source);
|
|
1293
1294
|
sourcePath += source.source + "/";
|
|
@@ -1297,7 +1298,7 @@ var _VDir = class _VDir {
|
|
|
1297
1298
|
`Ambiguous directory structure: '${sourcePath}${path5.source}' defines '${dir.path}' multiple times.`
|
|
1298
1299
|
);
|
|
1299
1300
|
} else {
|
|
1300
|
-
unique.
|
|
1301
|
+
unique.set(dir.path, dir);
|
|
1301
1302
|
dirs.push(dir);
|
|
1302
1303
|
}
|
|
1303
1304
|
}
|
|
@@ -1440,10 +1441,10 @@ async function buildRoutes(sources) {
|
|
|
1440
1441
|
const route = routes[existing.index];
|
|
1441
1442
|
const existingFiles = [route.handler, route.page].filter(Boolean).map((f) => f.filePath);
|
|
1442
1443
|
const currentFiles = [handler, page].filter(Boolean).map((f) => f.filePath);
|
|
1443
|
-
throw new Error(`Duplicate routes for path '${path5.
|
|
1444
|
-
${existingFiles.join(" and ")} via '${existing.dir.
|
|
1444
|
+
throw new Error(`Duplicate routes for path '${path5.id}' were defined. A route established by:
|
|
1445
|
+
${existingFiles.join(" and ")} via '${existing.dir.fullPath}'
|
|
1445
1446
|
collides with
|
|
1446
|
-
${currentFiles.join(" and ")} via '${dir.
|
|
1447
|
+
${currentFiles.join(" and ")} via '${dir.fullPath}'
|
|
1447
1448
|
`);
|
|
1448
1449
|
}
|
|
1449
1450
|
uniqueRoutes.set(path5.id, { dir, index: routes.length });
|
|
@@ -1810,6 +1811,8 @@ function markoRun(opts = {}) {
|
|
|
1810
1811
|
let { routesDir, adapter, ...markoVitePluginOptions } = opts;
|
|
1811
1812
|
let store;
|
|
1812
1813
|
let root;
|
|
1814
|
+
let shouldEmptyOutDir = false;
|
|
1815
|
+
let outputDir;
|
|
1813
1816
|
let resolvedRoutesDir;
|
|
1814
1817
|
let entryFilesDir;
|
|
1815
1818
|
let entryFilesDirPosix;
|
|
@@ -1993,7 +1996,7 @@ function markoRun(opts = {}) {
|
|
|
1993
1996
|
name: `${PLUGIN_NAME_PREFIX}:pre`,
|
|
1994
1997
|
enforce: "pre",
|
|
1995
1998
|
async config(config2, env) {
|
|
1996
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1999
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1997
2000
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
1998
2001
|
if (externalPluginOptions) {
|
|
1999
2002
|
opts = (0, import_vite2.mergeConfig)(opts, externalPluginOptions);
|
|
@@ -2024,11 +2027,8 @@ function markoRun(opts = {}) {
|
|
|
2024
2027
|
markoVitePluginOptions.runtimeId = opts.runtimeId;
|
|
2025
2028
|
markoVitePluginOptions.basePathVar = opts.basePathVar;
|
|
2026
2029
|
resolvedRoutesDir = import_path4.default.resolve(root, routesDir);
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
".marko",
|
|
2030
|
-
(0, import_crypto.createHash)("shake256", { outputLength: 4 }).update(root).digest("hex")
|
|
2031
|
-
);
|
|
2030
|
+
outputDir = import_path4.default.join(root, ((_d = config2.build) == null ? void 0 : _d.outDir) || "dist");
|
|
2031
|
+
entryFilesDir = import_path4.default.join(outputDir, ".marko-run");
|
|
2032
2032
|
entryFilesDirPosix = normalizePath(entryFilesDir);
|
|
2033
2033
|
relativeEntryFilesDirPosix = normalizePath(
|
|
2034
2034
|
import_path4.default.relative(root, entryFilesDir)
|
|
@@ -2036,9 +2036,9 @@ function markoRun(opts = {}) {
|
|
|
2036
2036
|
typesDir = import_path4.default.join(root, ".marko-run");
|
|
2037
2037
|
devEntryFile = import_path4.default.join(root, "index.html");
|
|
2038
2038
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
2039
|
-
let outDir = ((
|
|
2040
|
-
const assetsDir = ((
|
|
2041
|
-
let rollupOutputOptions = (
|
|
2039
|
+
let outDir = ((_e = config2.build) == null ? void 0 : _e.outDir) || "dist";
|
|
2040
|
+
const assetsDir = ((_f = config2.build) == null ? void 0 : _f.assetsDir) || "assets";
|
|
2041
|
+
let rollupOutputOptions = (_h = (_g = config2.build) == null ? void 0 : _g.rollupOptions) == null ? void 0 : _h.output;
|
|
2042
2042
|
if (isBuild) {
|
|
2043
2043
|
if (!isSSRBuild) {
|
|
2044
2044
|
outDir = import_path4.default.join(outDir, CLIENT_OUT_DIR);
|
|
@@ -2078,9 +2078,10 @@ function markoRun(opts = {}) {
|
|
|
2078
2078
|
}));
|
|
2079
2079
|
}
|
|
2080
2080
|
}
|
|
2081
|
-
const browserslistTarget = isBuild && !((
|
|
2081
|
+
const browserslistTarget = isBuild && !((_i = config2.build) == null ? void 0 : _i.target) ? (0, import_browserslist.default)(void 0, {
|
|
2082
2082
|
path: root
|
|
2083
2083
|
}) : void 0;
|
|
2084
|
+
shouldEmptyOutDir = ((_j = config2.build) == null ? void 0 : _j.emptyOutDir) ?? true;
|
|
2084
2085
|
let pluginConfig = {
|
|
2085
2086
|
logLevel: isBuild ? "warn" : void 0,
|
|
2086
2087
|
define: isBuild ? {
|
|
@@ -2098,18 +2099,17 @@ function markoRun(opts = {}) {
|
|
|
2098
2099
|
target: (browserslistTarget == null ? void 0 : browserslistTarget.length) ? (0, import_esbuild_plugin_browserslist.resolveToEsbuildTarget)(browserslistTarget, {
|
|
2099
2100
|
printUnknownTargets: false
|
|
2100
2101
|
}) : void 0,
|
|
2101
|
-
emptyOutDir: isSSRBuild,
|
|
2102
|
-
// Avoid server & client deleting files from each other.
|
|
2103
2102
|
copyPublicDir: !isSSRBuild,
|
|
2104
2103
|
ssrEmitAssets: false,
|
|
2104
|
+
emptyOutDir: false,
|
|
2105
2105
|
rollupOptions: {
|
|
2106
2106
|
output: rollupOutputOptions
|
|
2107
2107
|
},
|
|
2108
2108
|
modulePreload: { polyfill: false },
|
|
2109
|
-
sourcemap: ((
|
|
2109
|
+
sourcemap: ((_k = config2.build) == null ? void 0 : _k.sourcemap) ?? (isBuild && !isSSRBuild)
|
|
2110
2110
|
},
|
|
2111
2111
|
optimizeDeps: {
|
|
2112
|
-
entries: !((
|
|
2112
|
+
entries: !((_l = config2.optimizeDeps) == null ? void 0 : _l.entries) ? [
|
|
2113
2113
|
"src/pages/**/*+{page,layout}.marko",
|
|
2114
2114
|
"!**/__snapshots__/**",
|
|
2115
2115
|
`!**/__tests__/**`,
|
|
@@ -2197,6 +2197,11 @@ function markoRun(opts = {}) {
|
|
|
2197
2197
|
}).unwatch(typesDir + "/*");
|
|
2198
2198
|
},
|
|
2199
2199
|
async buildStart(_options) {
|
|
2200
|
+
if (isSSRBuild && shouldEmptyOutDir) {
|
|
2201
|
+
if (import_fs3.default.existsSync(outputDir)) {
|
|
2202
|
+
import_fs3.default.rmSync(outputDir, { recursive: true });
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2200
2205
|
if (isBuild && !isSSRBuild) {
|
|
2201
2206
|
try {
|
|
2202
2207
|
routeData = await store.read();
|
|
@@ -2301,13 +2306,18 @@ function markoRun(opts = {}) {
|
|
|
2301
2306
|
}
|
|
2302
2307
|
},
|
|
2303
2308
|
async closeBundle() {
|
|
2304
|
-
if (isBuild && !isSSRBuild
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2309
|
+
if (isBuild && !isSSRBuild) {
|
|
2310
|
+
if (import_fs3.default.existsSync(entryFilesDir)) {
|
|
2311
|
+
import_fs3.default.rmSync(entryFilesDir, { recursive: true });
|
|
2312
|
+
}
|
|
2313
|
+
if ((adapter == null ? void 0 : adapter.buildEnd) && routes) {
|
|
2314
|
+
await adapter.buildEnd(
|
|
2315
|
+
resolvedConfig,
|
|
2316
|
+
routes.list,
|
|
2317
|
+
routeData.builtEntries,
|
|
2318
|
+
routeData.sourceEntries
|
|
2319
|
+
);
|
|
2320
|
+
}
|
|
2311
2321
|
}
|
|
2312
2322
|
}
|
|
2313
2323
|
}
|
|
@@ -2394,15 +2404,6 @@ function getImporters(module2, fileName, seen = /* @__PURE__ */ new Set()) {
|
|
|
2394
2404
|
}
|
|
2395
2405
|
return seen;
|
|
2396
2406
|
}
|
|
2397
|
-
function getModulesDir(root, dir = __dirname) {
|
|
2398
|
-
if (dir.startsWith(root)) {
|
|
2399
|
-
const index = dir.indexOf("node_modules");
|
|
2400
|
-
if (index >= 0) {
|
|
2401
|
-
return dir.slice(0, index + 12);
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
return import_path4.default.join(root, "node_modules");
|
|
2405
|
-
}
|
|
2406
2407
|
var defaultConfigPlugin = {
|
|
2407
2408
|
name: `${PLUGIN_NAME_PREFIX}:defaults`,
|
|
2408
2409
|
enforce: "pre",
|
package/dist/vite/index.js
CHANGED
|
@@ -12,7 +12,6 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
12
12
|
// src/vite/plugin.ts
|
|
13
13
|
import markoVitePlugin from "@marko/vite";
|
|
14
14
|
import browserslist from "browserslist";
|
|
15
|
-
import { createHash } from "crypto";
|
|
16
15
|
import createDebug from "debug";
|
|
17
16
|
import { resolveToEsbuildTarget } from "esbuild-plugin-browserslist";
|
|
18
17
|
import fs3 from "fs";
|
|
@@ -1187,12 +1186,13 @@ var _VDir = class _VDir {
|
|
|
1187
1186
|
}
|
|
1188
1187
|
addDir(path5, segment) {
|
|
1189
1188
|
const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
|
|
1190
|
-
|
|
1189
|
+
const key = segment.type === "$" ? segment.raw : segment.name;
|
|
1190
|
+
if (!map.has(key)) {
|
|
1191
1191
|
const dir = new _VDir(this, segment, path5);
|
|
1192
|
-
map.set(
|
|
1192
|
+
map.set(key, dir);
|
|
1193
1193
|
return dir;
|
|
1194
1194
|
}
|
|
1195
|
-
return map.get(
|
|
1195
|
+
return map.get(key);
|
|
1196
1196
|
}
|
|
1197
1197
|
addFile(file) {
|
|
1198
1198
|
if (!this.files) {
|
|
@@ -1232,17 +1232,18 @@ var _VDir = class _VDir {
|
|
|
1232
1232
|
}
|
|
1233
1233
|
static addPaths(roots, paths) {
|
|
1234
1234
|
const dirs = [];
|
|
1235
|
-
const unique = /* @__PURE__ */ new
|
|
1235
|
+
const unique = /* @__PURE__ */ new Map();
|
|
1236
1236
|
for (const root of roots) {
|
|
1237
1237
|
for (const path5 of paths) {
|
|
1238
1238
|
let dir = root;
|
|
1239
1239
|
for (const segment of path5.segments) {
|
|
1240
1240
|
dir = dir.addDir(path5, segment);
|
|
1241
1241
|
}
|
|
1242
|
-
|
|
1242
|
+
const existing = unique.get(dir.path);
|
|
1243
|
+
if (existing) {
|
|
1243
1244
|
const sources = /* @__PURE__ */ new Set();
|
|
1244
1245
|
let sourcePath = "";
|
|
1245
|
-
for (const { source } of
|
|
1246
|
+
for (const { source } of existing) {
|
|
1246
1247
|
if (source && !sources.has(source.source)) {
|
|
1247
1248
|
sources.add(source.source);
|
|
1248
1249
|
sourcePath += source.source + "/";
|
|
@@ -1252,7 +1253,7 @@ var _VDir = class _VDir {
|
|
|
1252
1253
|
`Ambiguous directory structure: '${sourcePath}${path5.source}' defines '${dir.path}' multiple times.`
|
|
1253
1254
|
);
|
|
1254
1255
|
} else {
|
|
1255
|
-
unique.
|
|
1256
|
+
unique.set(dir.path, dir);
|
|
1256
1257
|
dirs.push(dir);
|
|
1257
1258
|
}
|
|
1258
1259
|
}
|
|
@@ -1395,10 +1396,10 @@ async function buildRoutes(sources) {
|
|
|
1395
1396
|
const route = routes[existing.index];
|
|
1396
1397
|
const existingFiles = [route.handler, route.page].filter(Boolean).map((f) => f.filePath);
|
|
1397
1398
|
const currentFiles = [handler, page].filter(Boolean).map((f) => f.filePath);
|
|
1398
|
-
throw new Error(`Duplicate routes for path '${path5.
|
|
1399
|
-
${existingFiles.join(" and ")} via '${existing.dir.
|
|
1399
|
+
throw new Error(`Duplicate routes for path '${path5.id}' were defined. A route established by:
|
|
1400
|
+
${existingFiles.join(" and ")} via '${existing.dir.fullPath}'
|
|
1400
1401
|
collides with
|
|
1401
|
-
${currentFiles.join(" and ")} via '${dir.
|
|
1402
|
+
${currentFiles.join(" and ")} via '${dir.fullPath}'
|
|
1402
1403
|
`);
|
|
1403
1404
|
}
|
|
1404
1405
|
uniqueRoutes.set(path5.id, { dir, index: routes.length });
|
|
@@ -1765,6 +1766,8 @@ function markoRun(opts = {}) {
|
|
|
1765
1766
|
let { routesDir, adapter, ...markoVitePluginOptions } = opts;
|
|
1766
1767
|
let store;
|
|
1767
1768
|
let root;
|
|
1769
|
+
let shouldEmptyOutDir = false;
|
|
1770
|
+
let outputDir;
|
|
1768
1771
|
let resolvedRoutesDir;
|
|
1769
1772
|
let entryFilesDir;
|
|
1770
1773
|
let entryFilesDirPosix;
|
|
@@ -1948,7 +1951,7 @@ function markoRun(opts = {}) {
|
|
|
1948
1951
|
name: `${PLUGIN_NAME_PREFIX}:pre`,
|
|
1949
1952
|
enforce: "pre",
|
|
1950
1953
|
async config(config2, env) {
|
|
1951
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1954
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1952
1955
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
1953
1956
|
if (externalPluginOptions) {
|
|
1954
1957
|
opts = mergeConfig(opts, externalPluginOptions);
|
|
@@ -1979,11 +1982,8 @@ function markoRun(opts = {}) {
|
|
|
1979
1982
|
markoVitePluginOptions.runtimeId = opts.runtimeId;
|
|
1980
1983
|
markoVitePluginOptions.basePathVar = opts.basePathVar;
|
|
1981
1984
|
resolvedRoutesDir = path4.resolve(root, routesDir);
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
".marko",
|
|
1985
|
-
createHash("shake256", { outputLength: 4 }).update(root).digest("hex")
|
|
1986
|
-
);
|
|
1985
|
+
outputDir = path4.join(root, ((_d = config2.build) == null ? void 0 : _d.outDir) || "dist");
|
|
1986
|
+
entryFilesDir = path4.join(outputDir, ".marko-run");
|
|
1987
1987
|
entryFilesDirPosix = normalizePath(entryFilesDir);
|
|
1988
1988
|
relativeEntryFilesDirPosix = normalizePath(
|
|
1989
1989
|
path4.relative(root, entryFilesDir)
|
|
@@ -1991,9 +1991,9 @@ function markoRun(opts = {}) {
|
|
|
1991
1991
|
typesDir = path4.join(root, ".marko-run");
|
|
1992
1992
|
devEntryFile = path4.join(root, "index.html");
|
|
1993
1993
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
1994
|
-
let outDir = ((
|
|
1995
|
-
const assetsDir = ((
|
|
1996
|
-
let rollupOutputOptions = (
|
|
1994
|
+
let outDir = ((_e = config2.build) == null ? void 0 : _e.outDir) || "dist";
|
|
1995
|
+
const assetsDir = ((_f = config2.build) == null ? void 0 : _f.assetsDir) || "assets";
|
|
1996
|
+
let rollupOutputOptions = (_h = (_g = config2.build) == null ? void 0 : _g.rollupOptions) == null ? void 0 : _h.output;
|
|
1997
1997
|
if (isBuild) {
|
|
1998
1998
|
if (!isSSRBuild) {
|
|
1999
1999
|
outDir = path4.join(outDir, CLIENT_OUT_DIR);
|
|
@@ -2033,9 +2033,10 @@ function markoRun(opts = {}) {
|
|
|
2033
2033
|
}));
|
|
2034
2034
|
}
|
|
2035
2035
|
}
|
|
2036
|
-
const browserslistTarget = isBuild && !((
|
|
2036
|
+
const browserslistTarget = isBuild && !((_i = config2.build) == null ? void 0 : _i.target) ? browserslist(void 0, {
|
|
2037
2037
|
path: root
|
|
2038
2038
|
}) : void 0;
|
|
2039
|
+
shouldEmptyOutDir = ((_j = config2.build) == null ? void 0 : _j.emptyOutDir) ?? true;
|
|
2039
2040
|
let pluginConfig = {
|
|
2040
2041
|
logLevel: isBuild ? "warn" : void 0,
|
|
2041
2042
|
define: isBuild ? {
|
|
@@ -2053,18 +2054,17 @@ function markoRun(opts = {}) {
|
|
|
2053
2054
|
target: (browserslistTarget == null ? void 0 : browserslistTarget.length) ? resolveToEsbuildTarget(browserslistTarget, {
|
|
2054
2055
|
printUnknownTargets: false
|
|
2055
2056
|
}) : void 0,
|
|
2056
|
-
emptyOutDir: isSSRBuild,
|
|
2057
|
-
// Avoid server & client deleting files from each other.
|
|
2058
2057
|
copyPublicDir: !isSSRBuild,
|
|
2059
2058
|
ssrEmitAssets: false,
|
|
2059
|
+
emptyOutDir: false,
|
|
2060
2060
|
rollupOptions: {
|
|
2061
2061
|
output: rollupOutputOptions
|
|
2062
2062
|
},
|
|
2063
2063
|
modulePreload: { polyfill: false },
|
|
2064
|
-
sourcemap: ((
|
|
2064
|
+
sourcemap: ((_k = config2.build) == null ? void 0 : _k.sourcemap) ?? (isBuild && !isSSRBuild)
|
|
2065
2065
|
},
|
|
2066
2066
|
optimizeDeps: {
|
|
2067
|
-
entries: !((
|
|
2067
|
+
entries: !((_l = config2.optimizeDeps) == null ? void 0 : _l.entries) ? [
|
|
2068
2068
|
"src/pages/**/*+{page,layout}.marko",
|
|
2069
2069
|
"!**/__snapshots__/**",
|
|
2070
2070
|
`!**/__tests__/**`,
|
|
@@ -2152,6 +2152,11 @@ function markoRun(opts = {}) {
|
|
|
2152
2152
|
}).unwatch(typesDir + "/*");
|
|
2153
2153
|
},
|
|
2154
2154
|
async buildStart(_options) {
|
|
2155
|
+
if (isSSRBuild && shouldEmptyOutDir) {
|
|
2156
|
+
if (fs3.existsSync(outputDir)) {
|
|
2157
|
+
fs3.rmSync(outputDir, { recursive: true });
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2155
2160
|
if (isBuild && !isSSRBuild) {
|
|
2156
2161
|
try {
|
|
2157
2162
|
routeData = await store.read();
|
|
@@ -2256,13 +2261,18 @@ function markoRun(opts = {}) {
|
|
|
2256
2261
|
}
|
|
2257
2262
|
},
|
|
2258
2263
|
async closeBundle() {
|
|
2259
|
-
if (isBuild && !isSSRBuild
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2264
|
+
if (isBuild && !isSSRBuild) {
|
|
2265
|
+
if (fs3.existsSync(entryFilesDir)) {
|
|
2266
|
+
fs3.rmSync(entryFilesDir, { recursive: true });
|
|
2267
|
+
}
|
|
2268
|
+
if ((adapter == null ? void 0 : adapter.buildEnd) && routes) {
|
|
2269
|
+
await adapter.buildEnd(
|
|
2270
|
+
resolvedConfig,
|
|
2271
|
+
routes.list,
|
|
2272
|
+
routeData.builtEntries,
|
|
2273
|
+
routeData.sourceEntries
|
|
2274
|
+
);
|
|
2275
|
+
}
|
|
2266
2276
|
}
|
|
2267
2277
|
}
|
|
2268
2278
|
}
|
|
@@ -2349,15 +2359,6 @@ function getImporters(module, fileName, seen = /* @__PURE__ */ new Set()) {
|
|
|
2349
2359
|
}
|
|
2350
2360
|
return seen;
|
|
2351
2361
|
}
|
|
2352
|
-
function getModulesDir(root, dir = __dirname) {
|
|
2353
|
-
if (dir.startsWith(root)) {
|
|
2354
|
-
const index = dir.indexOf("node_modules");
|
|
2355
|
-
if (index >= 0) {
|
|
2356
|
-
return dir.slice(0, index + 12);
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
return path4.join(root, "node_modules");
|
|
2360
|
-
}
|
|
2361
2362
|
var defaultConfigPlugin = {
|
|
2362
2363
|
name: `${PLUGIN_NAME_PREFIX}:defaults`,
|
|
2363
2364
|
enforce: "pre",
|