@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.
@@ -256,15 +256,22 @@ function normalizedRelativePath(from, to) {
256
256
  const relativePath = normalizePath(path2.relative(from, to));
257
257
  return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
258
258
  }
259
- function renderRouteTemplate(route, rootDir) {
259
+ function renderRouteTemplate(route, markoApi) {
260
260
  if (!route.page) {
261
261
  throw new Error(`Route ${route.key} has no page to render`);
262
262
  }
263
263
  if (!route.templateFilePath) {
264
264
  throw new Error(`Route ${route.key} has no template file path`);
265
265
  }
266
- return renderEntryTemplate(
267
- normalizedRelativePath(rootDir, route.templateFilePath),
266
+ const writer = createStringWriter();
267
+ if (markoApi) {
268
+ writer.writeLines(`<!-- use ${markoApi} -->
269
+ `);
270
+ }
271
+ writer.branch("imports");
272
+ writer.writeLines("");
273
+ writeEntryTemplateTag(
274
+ writer,
268
275
  [...route.layouts, route.page].map(
269
276
  (file) => normalizedRelativePath(
270
277
  path2.dirname(route.templateFilePath),
@@ -273,16 +280,6 @@ function renderRouteTemplate(route, rootDir) {
273
280
  ),
274
281
  route.key === RoutableFileTypes.Error ? ["error"] : []
275
282
  );
276
- }
277
- function renderEntryTemplate(name, files, pageInputs = []) {
278
- if (!files.length) {
279
- throw new Error(`Invalid argument - 'files' cannot be empty`);
280
- }
281
- const writer = createStringWriter();
282
- writer.writeLines(`// ${name}`);
283
- writer.branch("imports");
284
- writer.writeLines("");
285
- writeEntryTemplateTag(writer, files, pageInputs);
286
283
  return writer.end();
287
284
  }
288
285
  function writeEntryTemplateTag(writer, [file, ...rest], pageInputs, index = 1) {
@@ -310,7 +307,6 @@ function renderRouteEntry(route, rootDir) {
310
307
  );
311
308
  }
312
309
  const writer = createStringWriter();
313
- writer.writeLines(`// ${virtualFilePrefix}${getRouteVirtualFileName(route)}`);
314
310
  const imports = writer.branch("imports");
315
311
  const runtimeImports = [];
316
312
  if (handler) {
@@ -469,7 +465,6 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
469
465
  const writer = createStringWriter();
470
466
  const hasErrorPage = Boolean(routes.special[RoutableFileTypes.Error]);
471
467
  const hasNotFoundPage = Boolean(routes.special[RoutableFileTypes.NotFound]);
472
- writer.writeLines(`// @marko/run/router`);
473
468
  const imports = writer.branch("imports");
474
469
  if (runtimeInclude) {
475
470
  imports.writeLines(`import "${normalizePath(runtimeInclude)}";`);
@@ -779,9 +774,6 @@ function renderMatch(verb, route, path7, pathIndex) {
779
774
  }
780
775
  function renderMiddleware(middleware, rootDir) {
781
776
  const writer = createStringWriter();
782
- writer.writeLines(
783
- `// ${virtualFilePrefix}/${markoRunFilePrefix}middleware.js`
784
- );
785
777
  const imports = writer.branch("imports");
786
778
  imports.writeLines(
787
779
  `import { normalize } from "${virtualFilePrefix}/runtime/internal";`
@@ -807,9 +799,6 @@ function stripTsExtension(path7) {
807
799
  }
808
800
  return path7;
809
801
  }
810
- function decodePath(path7) {
811
- return path7;
812
- }
813
802
  async function renderRouteTypeInfo(routes, outDir, adapter) {
814
803
  var _a, _b, _c, _d;
815
804
  const writer = createStringWriter();
@@ -862,7 +851,7 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
862
851
  }
863
852
  routeDefinition += " }";
864
853
  }
865
- const pathType = `"${decodePath(route.path.path)}"`;
854
+ const pathType = `"${route.path.path}"`;
866
855
  routeType += routeType ? " | " + pathType : pathType;
867
856
  routesWriter.writeLines(`${pathType}: ${routeDefinition};`);
868
857
  for (const file of [route.handler, route.page]) {
@@ -1555,7 +1544,7 @@ function createFSWalker(dir) {
1555
1544
  }
1556
1545
 
1557
1546
  // src/vite/utils/ast.ts
1558
- import * as t from "@babel/types";
1547
+ import { types as t } from "@marko/compiler";
1559
1548
  function getExportIdentifiers(astProgramNode) {
1560
1549
  const result = [];
1561
1550
  if (t.isProgram(astProgramNode)) {
@@ -1603,7 +1592,6 @@ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterCon
1603
1592
 
1604
1593
  // src/vite/utils/log.ts
1605
1594
  import zlib from "node:zlib";
1606
- import { Blob } from "buffer";
1607
1595
  import Table from "cli-table3";
1608
1596
  import format from "human-format";
1609
1597
  import kleur2 from "kleur";
@@ -1862,6 +1850,13 @@ function markoRun(opts = {}) {
1862
1850
  routesBuild: 0,
1863
1851
  routesRender: 0
1864
1852
  };
1853
+ async function loadModule(context, id) {
1854
+ if ("transformRequest" in context.environment) {
1855
+ await context.environment.transformRequest(id);
1856
+ return context.getModuleInfo(id);
1857
+ }
1858
+ return await context.load({ id });
1859
+ }
1865
1860
  async function getExportsFromFile(context, filePath) {
1866
1861
  if (devServer) {
1867
1862
  const result2 = await devServer.transformRequest(filePath, { ssr: false });
@@ -1873,6 +1868,17 @@ function markoRun(opts = {}) {
1873
1868
  });
1874
1869
  return result.exports || [];
1875
1870
  }
1871
+ let routeMarkoApiCache;
1872
+ async function getMarkoApiForRoute(context, route) {
1873
+ var _a, _b;
1874
+ routeMarkoApiCache ?? (routeMarkoApiCache = /* @__PURE__ */ new Map());
1875
+ if (!routeMarkoApiCache.has(route)) {
1876
+ const markoAPI = route.templateFilePath && ((_b = (_a = await loadModule(context, normalizePath(route.layouts[0].filePath))) == null ? void 0 : _a.meta) == null ? void 0 : _b.markoAPI);
1877
+ routeMarkoApiCache.set(route, markoAPI);
1878
+ return markoAPI;
1879
+ }
1880
+ return routeMarkoApiCache.get(route);
1881
+ }
1876
1882
  async function writeTypesFile(routes2) {
1877
1883
  if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
1878
1884
  root,
@@ -1985,7 +1991,10 @@ function markoRun(opts = {}) {
1985
1991
  });
1986
1992
  fs3.writeFileSync(
1987
1993
  route.templateFilePath,
1988
- renderRouteTemplate(route, root)
1994
+ renderRouteTemplate(
1995
+ route,
1996
+ await getMarkoApiForRoute(context, route)
1997
+ )
1989
1998
  );
1990
1999
  }
1991
2000
  virtualFiles.set(
@@ -2000,7 +2009,10 @@ function markoRun(opts = {}) {
2000
2009
  });
2001
2010
  fs3.writeFileSync(
2002
2011
  route.templateFilePath,
2003
- renderRouteTemplate(route, root)
2012
+ renderRouteTemplate(
2013
+ route,
2014
+ await getMarkoApiForRoute(context, route)
2015
+ )
2004
2016
  );
2005
2017
  }
2006
2018
  }
@@ -2225,6 +2237,7 @@ function markoRun(opts = {}) {
2225
2237
  if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware || filename === runtimeInclude)) {
2226
2238
  buildVirtualFilesResult = void 0;
2227
2239
  renderVirtualFilesResult = void 0;
2240
+ routeMarkoApiCache = void 0;
2228
2241
  const module = devServer.moduleGraph.getModuleById(filename);
2229
2242
  const importers = module && getImporters(module, filename);
2230
2243
  if (importers == null ? void 0 : importers.size) {
@@ -2298,8 +2311,7 @@ function markoRun(opts = {}) {
2298
2311
  await renderVirtualFiles(this);
2299
2312
  }
2300
2313
  if (virtualFiles.has(id)) {
2301
- const file = virtualFiles.get(id);
2302
- return file;
2314
+ return virtualFiles.get(id);
2303
2315
  } else if (!id.startsWith(entryFilesDirPosix) && /[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
2304
2316
  return "";
2305
2317
  }
@@ -2501,9 +2513,12 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
2501
2513
  windowsHide: true,
2502
2514
  env: { ...env, NODE_ENV: "development", ...process.env, PORT: `${port}` }
2503
2515
  });
2504
- const close = () => {
2516
+ const close = async () => {
2505
2517
  proc.unref();
2506
2518
  proc.kill();
2519
+ if (!await waitForExit(proc, 500)) {
2520
+ proc.kill("SIGKILL");
2521
+ }
2507
2522
  };
2508
2523
  try {
2509
2524
  await Promise.race([waitForError(proc, port), waitForServer(port, wait)]);
@@ -2551,6 +2566,15 @@ async function spawnServerWorker(module, args = [], port = 0, env, wait = true)
2551
2566
  cluster.settings.execArgv = originalArgs;
2552
2567
  }
2553
2568
  }
2569
+ async function waitForExit(proc, wait = 0) {
2570
+ if (proc.exitCode !== null) return;
2571
+ return await new Promise((resolve) => {
2572
+ proc.once("exit", resolve), proc.once("close", resolve);
2573
+ if (wait) {
2574
+ setTimeout(resolve, wait, null);
2575
+ }
2576
+ });
2577
+ }
2554
2578
  async function waitForError(proc, port) {
2555
2579
  return new Promise((_, reject) => {
2556
2580
  proc.once("error", reject);
@@ -11,4 +11,4 @@ export interface WalkOptions {
11
11
  export type Walker = (options: WalkOptions) => Promise<void>;
12
12
  export declare function createFSWalker(dir: string): Walker;
13
13
  export type TestFileTree = [string, (string | TestFileTree)[]];
14
- export declare function createTestWalker(dir: TestFileTree, root: string): Walker;
14
+ export declare function createTestWalker(dir: TestFileTree): Walker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "The Marko application framework.",
5
5
  "keywords": [
6
6
  "marko"
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@marko/run-explorer": "^2.0.1",
58
- "@marko/vite": "^5.3.3",
58
+ "@marko/vite": "^5.4.2",
59
59
  "browserslist": "^4.24.4",
60
60
  "cli-table3": "^0.6.5",
61
61
  "compression": "^1.8.0",