@marko/run 0.9.3 → 0.9.5
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 +19 -8
- package/dist/adapter/index.js +19 -8
- package/dist/adapter/utils.d.ts +1 -1
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/index.mjs +42 -30
- package/dist/runtime/internal.cjs +2 -2
- package/dist/runtime/internal.js +2 -2
- package/dist/vite/codegen/index.d.ts +2 -2
- package/dist/vite/index.cjs +61 -37
- package/dist/vite/index.js +53 -29
- package/dist/vite/routes/walk.d.ts +1 -1
- package/package.json +2 -2
package/dist/adapter/utils.d.ts
CHANGED
package/dist/cli/commands.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare const defaultConfigFileExts: string[];
|
|
|
5
5
|
export declare function preview(entry: string | undefined, distEntry: string | undefined, cwd: string, configFile: string, port?: number, outDir?: string, envFile?: string, args?: string[]): Promise<SpawnedServer>;
|
|
6
6
|
export declare function dev(entry: string | undefined, cwd: string, configFile: string, port?: number, envFile?: string, args?: string[]): Promise<SpawnedServer>;
|
|
7
7
|
export declare function build(entry: string | undefined, cwd: string, configFile: string, outDir?: string, envFile?: string): Promise<void>;
|
|
8
|
-
export declare function getViteConfig(dir: string, configFile?: string, bases?: string[]): Promise<string>;
|
|
8
|
+
export declare function getViteConfig(dir: string, configFile?: string, bases?: string[], fallback?: string): Promise<string>;
|
package/dist/cli/index.mjs
CHANGED
|
@@ -272,15 +272,22 @@ function normalizedRelativePath(from, to) {
|
|
|
272
272
|
const relativePath = normalizePath(path2.relative(from, to));
|
|
273
273
|
return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
|
|
274
274
|
}
|
|
275
|
-
function renderRouteTemplate(route,
|
|
275
|
+
function renderRouteTemplate(route, markoApi) {
|
|
276
276
|
if (!route.page) {
|
|
277
277
|
throw new Error(`Route ${route.key} has no page to render`);
|
|
278
278
|
}
|
|
279
279
|
if (!route.templateFilePath) {
|
|
280
280
|
throw new Error(`Route ${route.key} has no template file path`);
|
|
281
281
|
}
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
const writer = createStringWriter();
|
|
283
|
+
if (markoApi) {
|
|
284
|
+
writer.writeLines(`<!-- use ${markoApi} -->
|
|
285
|
+
`);
|
|
286
|
+
}
|
|
287
|
+
writer.branch("imports");
|
|
288
|
+
writer.writeLines("");
|
|
289
|
+
writeEntryTemplateTag(
|
|
290
|
+
writer,
|
|
284
291
|
[...route.layouts, route.page].map(
|
|
285
292
|
(file) => normalizedRelativePath(
|
|
286
293
|
path2.dirname(route.templateFilePath),
|
|
@@ -289,16 +296,6 @@ function renderRouteTemplate(route, rootDir) {
|
|
|
289
296
|
),
|
|
290
297
|
route.key === RoutableFileTypes.Error ? ["error"] : []
|
|
291
298
|
);
|
|
292
|
-
}
|
|
293
|
-
function renderEntryTemplate(name, files, pageInputs = []) {
|
|
294
|
-
if (!files.length) {
|
|
295
|
-
throw new Error(`Invalid argument - 'files' cannot be empty`);
|
|
296
|
-
}
|
|
297
|
-
const writer = createStringWriter();
|
|
298
|
-
writer.writeLines(`// ${name}`);
|
|
299
|
-
writer.branch("imports");
|
|
300
|
-
writer.writeLines("");
|
|
301
|
-
writeEntryTemplateTag(writer, files, pageInputs);
|
|
302
299
|
return writer.end();
|
|
303
300
|
}
|
|
304
301
|
function writeEntryTemplateTag(writer, [file, ...rest], pageInputs, index = 1) {
|
|
@@ -326,7 +323,6 @@ function renderRouteEntry(route, rootDir) {
|
|
|
326
323
|
);
|
|
327
324
|
}
|
|
328
325
|
const writer = createStringWriter();
|
|
329
|
-
writer.writeLines(`// ${virtualFilePrefix}${getRouteVirtualFileName(route)}`);
|
|
330
326
|
const imports = writer.branch("imports");
|
|
331
327
|
const runtimeImports = [];
|
|
332
328
|
if (handler) {
|
|
@@ -485,7 +481,6 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
485
481
|
const writer = createStringWriter();
|
|
486
482
|
const hasErrorPage = Boolean(routes.special[RoutableFileTypes.Error]);
|
|
487
483
|
const hasNotFoundPage = Boolean(routes.special[RoutableFileTypes.NotFound]);
|
|
488
|
-
writer.writeLines(`// @marko/run/router`);
|
|
489
484
|
const imports = writer.branch("imports");
|
|
490
485
|
if (runtimeInclude) {
|
|
491
486
|
imports.writeLines(`import "${normalizePath(runtimeInclude)}";`);
|
|
@@ -795,9 +790,6 @@ function renderMatch(verb, route, path10, pathIndex) {
|
|
|
795
790
|
}
|
|
796
791
|
function renderMiddleware(middleware, rootDir) {
|
|
797
792
|
const writer = createStringWriter();
|
|
798
|
-
writer.writeLines(
|
|
799
|
-
`// ${virtualFilePrefix}/${markoRunFilePrefix}middleware.js`
|
|
800
|
-
);
|
|
801
793
|
const imports = writer.branch("imports");
|
|
802
794
|
imports.writeLines(
|
|
803
795
|
`import { normalize } from "${virtualFilePrefix}/runtime/internal";`
|
|
@@ -823,9 +815,6 @@ function stripTsExtension(path10) {
|
|
|
823
815
|
}
|
|
824
816
|
return path10;
|
|
825
817
|
}
|
|
826
|
-
function decodePath(path10) {
|
|
827
|
-
return path10;
|
|
828
|
-
}
|
|
829
818
|
async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
830
819
|
var _a, _b, _c, _d;
|
|
831
820
|
const writer = createStringWriter();
|
|
@@ -878,7 +867,7 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
|
878
867
|
}
|
|
879
868
|
routeDefinition += " }";
|
|
880
869
|
}
|
|
881
|
-
const pathType = `"${
|
|
870
|
+
const pathType = `"${route.path.path}"`;
|
|
882
871
|
routeType += routeType ? " | " + pathType : pathType;
|
|
883
872
|
routesWriter.writeLines(`${pathType}: ${routeDefinition};`);
|
|
884
873
|
for (const file of [route.handler, route.page]) {
|
|
@@ -1571,7 +1560,7 @@ function createFSWalker(dir) {
|
|
|
1571
1560
|
}
|
|
1572
1561
|
|
|
1573
1562
|
// src/vite/utils/ast.ts
|
|
1574
|
-
import
|
|
1563
|
+
import { types as t } from "@marko/compiler";
|
|
1575
1564
|
function getExportIdentifiers(astProgramNode) {
|
|
1576
1565
|
const result = [];
|
|
1577
1566
|
if (t.isProgram(astProgramNode)) {
|
|
@@ -1620,7 +1609,6 @@ var setExternalAdapterOptions = (viteConfig, value) => setConfig(viteConfig, Ada
|
|
|
1620
1609
|
|
|
1621
1610
|
// src/vite/utils/log.ts
|
|
1622
1611
|
import zlib from "node:zlib";
|
|
1623
|
-
import { Blob } from "buffer";
|
|
1624
1612
|
import Table from "cli-table3";
|
|
1625
1613
|
import format from "human-format";
|
|
1626
1614
|
import kleur2 from "kleur";
|
|
@@ -1879,6 +1867,13 @@ function markoRun(opts = {}) {
|
|
|
1879
1867
|
routesBuild: 0,
|
|
1880
1868
|
routesRender: 0
|
|
1881
1869
|
};
|
|
1870
|
+
async function loadModule(context, id) {
|
|
1871
|
+
if ("transformRequest" in context.environment) {
|
|
1872
|
+
await context.environment.transformRequest(id);
|
|
1873
|
+
return context.getModuleInfo(id);
|
|
1874
|
+
}
|
|
1875
|
+
return await context.load({ id });
|
|
1876
|
+
}
|
|
1882
1877
|
async function getExportsFromFile(context, filePath) {
|
|
1883
1878
|
if (devServer) {
|
|
1884
1879
|
const result2 = await devServer.transformRequest(filePath, { ssr: false });
|
|
@@ -1890,6 +1885,17 @@ function markoRun(opts = {}) {
|
|
|
1890
1885
|
});
|
|
1891
1886
|
return result.exports || [];
|
|
1892
1887
|
}
|
|
1888
|
+
let routeMarkoApiCache;
|
|
1889
|
+
async function getMarkoApiForRoute(context, route) {
|
|
1890
|
+
var _a, _b;
|
|
1891
|
+
routeMarkoApiCache ?? (routeMarkoApiCache = /* @__PURE__ */ new Map());
|
|
1892
|
+
if (!routeMarkoApiCache.has(route)) {
|
|
1893
|
+
const markoAPI = route.templateFilePath && ((_b = (_a = await loadModule(context, normalizePath(route.layouts[0].filePath))) == null ? void 0 : _a.meta) == null ? void 0 : _b.markoAPI);
|
|
1894
|
+
routeMarkoApiCache.set(route, markoAPI);
|
|
1895
|
+
return markoAPI;
|
|
1896
|
+
}
|
|
1897
|
+
return routeMarkoApiCache.get(route);
|
|
1898
|
+
}
|
|
1893
1899
|
async function writeTypesFile(routes2) {
|
|
1894
1900
|
if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
|
|
1895
1901
|
root,
|
|
@@ -2002,7 +2008,10 @@ function markoRun(opts = {}) {
|
|
|
2002
2008
|
});
|
|
2003
2009
|
fs3.writeFileSync(
|
|
2004
2010
|
route.templateFilePath,
|
|
2005
|
-
renderRouteTemplate(
|
|
2011
|
+
renderRouteTemplate(
|
|
2012
|
+
route,
|
|
2013
|
+
await getMarkoApiForRoute(context, route)
|
|
2014
|
+
)
|
|
2006
2015
|
);
|
|
2007
2016
|
}
|
|
2008
2017
|
virtualFiles.set(
|
|
@@ -2017,7 +2026,10 @@ function markoRun(opts = {}) {
|
|
|
2017
2026
|
});
|
|
2018
2027
|
fs3.writeFileSync(
|
|
2019
2028
|
route.templateFilePath,
|
|
2020
|
-
renderRouteTemplate(
|
|
2029
|
+
renderRouteTemplate(
|
|
2030
|
+
route,
|
|
2031
|
+
await getMarkoApiForRoute(context, route)
|
|
2032
|
+
)
|
|
2021
2033
|
);
|
|
2022
2034
|
}
|
|
2023
2035
|
}
|
|
@@ -2242,6 +2254,7 @@ function markoRun(opts = {}) {
|
|
|
2242
2254
|
if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware || filename === runtimeInclude)) {
|
|
2243
2255
|
buildVirtualFilesResult = void 0;
|
|
2244
2256
|
renderVirtualFilesResult = void 0;
|
|
2257
|
+
routeMarkoApiCache = void 0;
|
|
2245
2258
|
const module = devServer.moduleGraph.getModuleById(filename);
|
|
2246
2259
|
const importers = module && getImporters(module, filename);
|
|
2247
2260
|
if (importers == null ? void 0 : importers.size) {
|
|
@@ -2315,8 +2328,7 @@ function markoRun(opts = {}) {
|
|
|
2315
2328
|
await renderVirtualFiles(this);
|
|
2316
2329
|
}
|
|
2317
2330
|
if (virtualFiles.has(id)) {
|
|
2318
|
-
|
|
2319
|
-
return file;
|
|
2331
|
+
return virtualFiles.get(id);
|
|
2320
2332
|
} else if (!id.startsWith(entryFilesDirPosix) && /[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
|
|
2321
2333
|
return "";
|
|
2322
2334
|
}
|
|
@@ -2736,7 +2748,7 @@ function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
|
|
|
2736
2748
|
}
|
|
2737
2749
|
return void 0;
|
|
2738
2750
|
}
|
|
2739
|
-
async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
|
|
2751
|
+
async function getViteConfig(dir, configFile, bases = defaultConfigFileBases, fallback = path9.join(__dirname3, "default.config.mjs")) {
|
|
2740
2752
|
if (configFile) {
|
|
2741
2753
|
const configFilePath = path9.join(dir, configFile);
|
|
2742
2754
|
if (!fs6.existsSync(configFilePath)) {
|
|
@@ -2750,7 +2762,7 @@ async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
|
|
|
2750
2762
|
return configFile;
|
|
2751
2763
|
}
|
|
2752
2764
|
}
|
|
2753
|
-
return
|
|
2765
|
+
return fallback;
|
|
2754
2766
|
}
|
|
2755
2767
|
|
|
2756
2768
|
// src/cli/index.ts
|
|
@@ -206,9 +206,9 @@ function compose(handlers) {
|
|
|
206
206
|
}
|
|
207
207
|
return (context, next) => {
|
|
208
208
|
let i = 0;
|
|
209
|
-
return function nextHandler() {
|
|
209
|
+
return (function nextHandler() {
|
|
210
210
|
return i < len ? call(handlers[i++], nextHandler, context) : next();
|
|
211
|
-
}();
|
|
211
|
+
})();
|
|
212
212
|
};
|
|
213
213
|
}
|
|
214
214
|
function normalize(obj) {
|
package/dist/runtime/internal.js
CHANGED
|
@@ -165,9 +165,9 @@ function compose(handlers) {
|
|
|
165
165
|
}
|
|
166
166
|
return (context, next) => {
|
|
167
167
|
let i = 0;
|
|
168
|
-
return function nextHandler() {
|
|
168
|
+
return (function nextHandler() {
|
|
169
169
|
return i < len ? call(handlers[i++], nextHandler, context) : next();
|
|
170
|
-
}();
|
|
170
|
+
})();
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
function normalize(obj) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Adapter, BuiltRoutes, RoutableFile, Route, RouterOptions } from "../types";
|
|
2
|
-
export declare function renderRouteTemplate(route: Route,
|
|
2
|
+
export declare function renderRouteTemplate(route: Route, markoApi?: string): string;
|
|
3
3
|
export declare function renderRouteEntry(route: Route, rootDir: string): string;
|
|
4
|
-
export declare function renderRouter(routes: BuiltRoutes, rootDir: string, runtimeInclude
|
|
4
|
+
export declare function renderRouter(routes: BuiltRoutes, rootDir: string, runtimeInclude?: string, options?: RouterOptions): string;
|
|
5
5
|
export declare function renderMiddleware(middleware: RoutableFile[], rootDir: string): string;
|
|
6
6
|
export declare function renderRouteTypeInfo(routes: BuiltRoutes, outDir: string, adapter?: Adapter | null): Promise<string>;
|
package/dist/vite/index.cjs
CHANGED
|
@@ -300,15 +300,22 @@ function normalizedRelativePath(from, to) {
|
|
|
300
300
|
const relativePath = normalizePath(import_path2.default.relative(from, to));
|
|
301
301
|
return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
|
|
302
302
|
}
|
|
303
|
-
function renderRouteTemplate(route,
|
|
303
|
+
function renderRouteTemplate(route, markoApi) {
|
|
304
304
|
if (!route.page) {
|
|
305
305
|
throw new Error(`Route ${route.key} has no page to render`);
|
|
306
306
|
}
|
|
307
307
|
if (!route.templateFilePath) {
|
|
308
308
|
throw new Error(`Route ${route.key} has no template file path`);
|
|
309
309
|
}
|
|
310
|
-
|
|
311
|
-
|
|
310
|
+
const writer = createStringWriter();
|
|
311
|
+
if (markoApi) {
|
|
312
|
+
writer.writeLines(`<!-- use ${markoApi} -->
|
|
313
|
+
`);
|
|
314
|
+
}
|
|
315
|
+
writer.branch("imports");
|
|
316
|
+
writer.writeLines("");
|
|
317
|
+
writeEntryTemplateTag(
|
|
318
|
+
writer,
|
|
312
319
|
[...route.layouts, route.page].map(
|
|
313
320
|
(file) => normalizedRelativePath(
|
|
314
321
|
import_path2.default.dirname(route.templateFilePath),
|
|
@@ -317,16 +324,6 @@ function renderRouteTemplate(route, rootDir) {
|
|
|
317
324
|
),
|
|
318
325
|
route.key === RoutableFileTypes.Error ? ["error"] : []
|
|
319
326
|
);
|
|
320
|
-
}
|
|
321
|
-
function renderEntryTemplate(name, files, pageInputs = []) {
|
|
322
|
-
if (!files.length) {
|
|
323
|
-
throw new Error(`Invalid argument - 'files' cannot be empty`);
|
|
324
|
-
}
|
|
325
|
-
const writer = createStringWriter();
|
|
326
|
-
writer.writeLines(`// ${name}`);
|
|
327
|
-
writer.branch("imports");
|
|
328
|
-
writer.writeLines("");
|
|
329
|
-
writeEntryTemplateTag(writer, files, pageInputs);
|
|
330
327
|
return writer.end();
|
|
331
328
|
}
|
|
332
329
|
function writeEntryTemplateTag(writer, [file, ...rest], pageInputs, index = 1) {
|
|
@@ -354,7 +351,6 @@ function renderRouteEntry(route, rootDir) {
|
|
|
354
351
|
);
|
|
355
352
|
}
|
|
356
353
|
const writer = createStringWriter();
|
|
357
|
-
writer.writeLines(`// ${virtualFilePrefix}${getRouteVirtualFileName(route)}`);
|
|
358
354
|
const imports = writer.branch("imports");
|
|
359
355
|
const runtimeImports = [];
|
|
360
356
|
if (handler) {
|
|
@@ -513,7 +509,6 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
513
509
|
const writer = createStringWriter();
|
|
514
510
|
const hasErrorPage = Boolean(routes.special[RoutableFileTypes.Error]);
|
|
515
511
|
const hasNotFoundPage = Boolean(routes.special[RoutableFileTypes.NotFound]);
|
|
516
|
-
writer.writeLines(`// @marko/run/router`);
|
|
517
512
|
const imports = writer.branch("imports");
|
|
518
513
|
if (runtimeInclude) {
|
|
519
514
|
imports.writeLines(`import "${normalizePath(runtimeInclude)}";`);
|
|
@@ -823,9 +818,6 @@ function renderMatch(verb, route, path7, pathIndex) {
|
|
|
823
818
|
}
|
|
824
819
|
function renderMiddleware(middleware, rootDir) {
|
|
825
820
|
const writer = createStringWriter();
|
|
826
|
-
writer.writeLines(
|
|
827
|
-
`// ${virtualFilePrefix}/${markoRunFilePrefix}middleware.js`
|
|
828
|
-
);
|
|
829
821
|
const imports = writer.branch("imports");
|
|
830
822
|
imports.writeLines(
|
|
831
823
|
`import { normalize } from "${virtualFilePrefix}/runtime/internal";`
|
|
@@ -851,9 +843,6 @@ function stripTsExtension(path7) {
|
|
|
851
843
|
}
|
|
852
844
|
return path7;
|
|
853
845
|
}
|
|
854
|
-
function decodePath(path7) {
|
|
855
|
-
return path7;
|
|
856
|
-
}
|
|
857
846
|
async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
858
847
|
var _a, _b, _c, _d;
|
|
859
848
|
const writer = createStringWriter();
|
|
@@ -906,7 +895,7 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
|
906
895
|
}
|
|
907
896
|
routeDefinition += " }";
|
|
908
897
|
}
|
|
909
|
-
const pathType = `"${
|
|
898
|
+
const pathType = `"${route.path.path}"`;
|
|
910
899
|
routeType += routeType ? " | " + pathType : pathType;
|
|
911
900
|
routesWriter.writeLines(`${pathType}: ${routeDefinition};`);
|
|
912
901
|
for (const file of [route.handler, route.page]) {
|
|
@@ -1599,31 +1588,31 @@ function createFSWalker(dir) {
|
|
|
1599
1588
|
}
|
|
1600
1589
|
|
|
1601
1590
|
// src/vite/utils/ast.ts
|
|
1602
|
-
var
|
|
1591
|
+
var import_compiler = require("@marko/compiler");
|
|
1603
1592
|
function getExportIdentifiers(astProgramNode) {
|
|
1604
1593
|
const result = [];
|
|
1605
|
-
if (
|
|
1594
|
+
if (import_compiler.types.isProgram(astProgramNode)) {
|
|
1606
1595
|
for (const node of astProgramNode.body) {
|
|
1607
|
-
if (
|
|
1596
|
+
if (import_compiler.types.isExportNamedDeclaration(node)) {
|
|
1608
1597
|
const { declaration, specifiers } = node;
|
|
1609
1598
|
if (declaration) {
|
|
1610
|
-
if (
|
|
1599
|
+
if (import_compiler.types.isFunctionDeclaration(declaration) && declaration.id) {
|
|
1611
1600
|
result.push(declaration.id.name);
|
|
1612
|
-
} else if (
|
|
1601
|
+
} else if (import_compiler.types.isVariableDeclaration(declaration)) {
|
|
1613
1602
|
for (const declarator of declaration.declarations) {
|
|
1614
|
-
if (
|
|
1603
|
+
if (import_compiler.types.isIdentifier(declarator.id)) {
|
|
1615
1604
|
result.push(declarator.id.name);
|
|
1616
1605
|
}
|
|
1617
1606
|
}
|
|
1618
1607
|
}
|
|
1619
1608
|
} else if (specifiers) {
|
|
1620
1609
|
for (const specifier of specifiers) {
|
|
1621
|
-
if (
|
|
1610
|
+
if (import_compiler.types.isExportSpecifier(specifier) && import_compiler.types.isIdentifier(specifier.exported)) {
|
|
1622
1611
|
result.push(specifier.exported.name);
|
|
1623
1612
|
}
|
|
1624
1613
|
}
|
|
1625
1614
|
}
|
|
1626
|
-
} else if (
|
|
1615
|
+
} else if (import_compiler.types.isExportDefaultDeclaration(node)) {
|
|
1627
1616
|
result.push("default");
|
|
1628
1617
|
}
|
|
1629
1618
|
}
|
|
@@ -1647,7 +1636,6 @@ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterCon
|
|
|
1647
1636
|
|
|
1648
1637
|
// src/vite/utils/log.ts
|
|
1649
1638
|
var import_node_zlib = __toESM(require("node:zlib"), 1);
|
|
1650
|
-
var import_buffer = require("buffer");
|
|
1651
1639
|
var import_cli_table3 = __toESM(require("cli-table3"), 1);
|
|
1652
1640
|
var import_human_format = __toESM(require("human-format"), 1);
|
|
1653
1641
|
var import_kleur2 = __toESM(require("kleur"), 1);
|
|
@@ -1781,7 +1769,7 @@ function gzipSize(source) {
|
|
|
1781
1769
|
return import_node_zlib.default.gzipSync(source, { level: 9 }).length;
|
|
1782
1770
|
}
|
|
1783
1771
|
function byteSize(source) {
|
|
1784
|
-
return new
|
|
1772
|
+
return new Blob([source]).size;
|
|
1785
1773
|
}
|
|
1786
1774
|
function computeChunkSize(chunk, bundle, seen = /* @__PURE__ */ new Set()) {
|
|
1787
1775
|
if (chunk.type === "asset") {
|
|
@@ -1906,6 +1894,13 @@ function markoRun(opts = {}) {
|
|
|
1906
1894
|
routesBuild: 0,
|
|
1907
1895
|
routesRender: 0
|
|
1908
1896
|
};
|
|
1897
|
+
async function loadModule(context, id) {
|
|
1898
|
+
if ("transformRequest" in context.environment) {
|
|
1899
|
+
await context.environment.transformRequest(id);
|
|
1900
|
+
return context.getModuleInfo(id);
|
|
1901
|
+
}
|
|
1902
|
+
return await context.load({ id });
|
|
1903
|
+
}
|
|
1909
1904
|
async function getExportsFromFile(context, filePath) {
|
|
1910
1905
|
if (devServer) {
|
|
1911
1906
|
const result2 = await devServer.transformRequest(filePath, { ssr: false });
|
|
@@ -1917,6 +1912,17 @@ function markoRun(opts = {}) {
|
|
|
1917
1912
|
});
|
|
1918
1913
|
return result.exports || [];
|
|
1919
1914
|
}
|
|
1915
|
+
let routeMarkoApiCache;
|
|
1916
|
+
async function getMarkoApiForRoute(context, route) {
|
|
1917
|
+
var _a, _b;
|
|
1918
|
+
routeMarkoApiCache ?? (routeMarkoApiCache = /* @__PURE__ */ new Map());
|
|
1919
|
+
if (!routeMarkoApiCache.has(route)) {
|
|
1920
|
+
const markoAPI = route.templateFilePath && ((_b = (_a = await loadModule(context, normalizePath(route.layouts[0].filePath))) == null ? void 0 : _a.meta) == null ? void 0 : _b.markoAPI);
|
|
1921
|
+
routeMarkoApiCache.set(route, markoAPI);
|
|
1922
|
+
return markoAPI;
|
|
1923
|
+
}
|
|
1924
|
+
return routeMarkoApiCache.get(route);
|
|
1925
|
+
}
|
|
1920
1926
|
async function writeTypesFile(routes2) {
|
|
1921
1927
|
if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
|
|
1922
1928
|
root,
|
|
@@ -2029,7 +2035,10 @@ function markoRun(opts = {}) {
|
|
|
2029
2035
|
});
|
|
2030
2036
|
import_fs4.default.writeFileSync(
|
|
2031
2037
|
route.templateFilePath,
|
|
2032
|
-
renderRouteTemplate(
|
|
2038
|
+
renderRouteTemplate(
|
|
2039
|
+
route,
|
|
2040
|
+
await getMarkoApiForRoute(context, route)
|
|
2041
|
+
)
|
|
2033
2042
|
);
|
|
2034
2043
|
}
|
|
2035
2044
|
virtualFiles.set(
|
|
@@ -2044,7 +2053,10 @@ function markoRun(opts = {}) {
|
|
|
2044
2053
|
});
|
|
2045
2054
|
import_fs4.default.writeFileSync(
|
|
2046
2055
|
route.templateFilePath,
|
|
2047
|
-
renderRouteTemplate(
|
|
2056
|
+
renderRouteTemplate(
|
|
2057
|
+
route,
|
|
2058
|
+
await getMarkoApiForRoute(context, route)
|
|
2059
|
+
)
|
|
2048
2060
|
);
|
|
2049
2061
|
}
|
|
2050
2062
|
}
|
|
@@ -2269,6 +2281,7 @@ function markoRun(opts = {}) {
|
|
|
2269
2281
|
if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware || filename === runtimeInclude)) {
|
|
2270
2282
|
buildVirtualFilesResult = void 0;
|
|
2271
2283
|
renderVirtualFilesResult = void 0;
|
|
2284
|
+
routeMarkoApiCache = void 0;
|
|
2272
2285
|
const module2 = devServer.moduleGraph.getModuleById(filename);
|
|
2273
2286
|
const importers = module2 && getImporters(module2, filename);
|
|
2274
2287
|
if (importers == null ? void 0 : importers.size) {
|
|
@@ -2342,8 +2355,7 @@ function markoRun(opts = {}) {
|
|
|
2342
2355
|
await renderVirtualFiles(this);
|
|
2343
2356
|
}
|
|
2344
2357
|
if (virtualFiles.has(id)) {
|
|
2345
|
-
|
|
2346
|
-
return file;
|
|
2358
|
+
return virtualFiles.get(id);
|
|
2347
2359
|
} else if (!id.startsWith(entryFilesDirPosix) && /[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
|
|
2348
2360
|
return "";
|
|
2349
2361
|
}
|
|
@@ -2545,9 +2557,12 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
|
|
|
2545
2557
|
windowsHide: true,
|
|
2546
2558
|
env: { ...env, NODE_ENV: "development", ...process.env, PORT: `${port}` }
|
|
2547
2559
|
});
|
|
2548
|
-
const close = () => {
|
|
2560
|
+
const close = async () => {
|
|
2549
2561
|
proc.unref();
|
|
2550
2562
|
proc.kill();
|
|
2563
|
+
if (!await waitForExit(proc, 500)) {
|
|
2564
|
+
proc.kill("SIGKILL");
|
|
2565
|
+
}
|
|
2551
2566
|
};
|
|
2552
2567
|
try {
|
|
2553
2568
|
await Promise.race([waitForError(proc, port), waitForServer(port, wait)]);
|
|
@@ -2595,6 +2610,15 @@ async function spawnServerWorker(module2, args = [], port = 0, env, wait = true)
|
|
|
2595
2610
|
import_cluster.default.settings.execArgv = originalArgs;
|
|
2596
2611
|
}
|
|
2597
2612
|
}
|
|
2613
|
+
async function waitForExit(proc, wait = 0) {
|
|
2614
|
+
if (proc.exitCode !== null) return;
|
|
2615
|
+
return await new Promise((resolve) => {
|
|
2616
|
+
proc.once("exit", resolve), proc.once("close", resolve);
|
|
2617
|
+
if (wait) {
|
|
2618
|
+
setTimeout(resolve, wait, null);
|
|
2619
|
+
}
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2598
2622
|
async function waitForError(proc, port) {
|
|
2599
2623
|
return new Promise((_, reject) => {
|
|
2600
2624
|
proc.once("error", reject);
|