@marko/run 0.9.2 → 0.9.4

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.
@@ -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>;
@@ -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, rootDir) {
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
- return renderEntryTemplate(
283
- normalizedRelativePath(rootDir, route.templateFilePath),
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 = `"${decodePath(route.path.path)}"`;
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]) {
@@ -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";
@@ -1871,6 +1859,7 @@ function markoRun(opts = {}) {
1871
1859
  let routeData;
1872
1860
  let resolvedConfig;
1873
1861
  let typesFile;
1862
+ let runtimeInclude;
1874
1863
  const externalRoutes = /* @__PURE__ */ new Set();
1875
1864
  const seenErrors = /* @__PURE__ */ new Set();
1876
1865
  const virtualFiles = /* @__PURE__ */ new Map();
@@ -1878,6 +1867,13 @@ function markoRun(opts = {}) {
1878
1867
  routesBuild: 0,
1879
1868
  routesRender: 0
1880
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
+ }
1881
1877
  async function getExportsFromFile(context, filePath) {
1882
1878
  if (devServer) {
1883
1879
  const result2 = await devServer.transformRequest(filePath, { ssr: false });
@@ -1889,6 +1885,17 @@ function markoRun(opts = {}) {
1889
1885
  });
1890
1886
  return result.exports || [];
1891
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
+ }
1892
1899
  async function writeTypesFile(routes2) {
1893
1900
  if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
1894
1901
  root,
@@ -2001,7 +2008,10 @@ function markoRun(opts = {}) {
2001
2008
  });
2002
2009
  fs3.writeFileSync(
2003
2010
  route.templateFilePath,
2004
- renderRouteTemplate(route, root)
2011
+ renderRouteTemplate(
2012
+ route,
2013
+ await getMarkoApiForRoute(context, route)
2014
+ )
2005
2015
  );
2006
2016
  }
2007
2017
  virtualFiles.set(
@@ -2016,7 +2026,10 @@ function markoRun(opts = {}) {
2016
2026
  });
2017
2027
  fs3.writeFileSync(
2018
2028
  route.templateFilePath,
2019
- renderRouteTemplate(route, root)
2029
+ renderRouteTemplate(
2030
+ route,
2031
+ await getMarkoApiForRoute(context, route)
2032
+ )
2020
2033
  );
2021
2034
  }
2022
2035
  }
@@ -2033,7 +2046,7 @@ function markoRun(opts = {}) {
2033
2046
  renderMiddleware(routes2.middleware, root)
2034
2047
  );
2035
2048
  }
2036
- const runtimeInclude = await ((_a = adapter == null ? void 0 : adapter.runtimeInclude) == null ? void 0 : _a.call(adapter));
2049
+ runtimeInclude = await ((_a = adapter == null ? void 0 : adapter.runtimeInclude) == null ? void 0 : _a.call(adapter));
2037
2050
  virtualFiles.set(
2038
2051
  path6.posix.join(root, ROUTER_FILENAME),
2039
2052
  renderRouter(routes2, root, runtimeInclude, {
@@ -2237,10 +2250,11 @@ function markoRun(opts = {}) {
2237
2250
  const routableFileType = matchRoutableFile(
2238
2251
  path6.parse(filename).base
2239
2252
  );
2240
- if (filename.startsWith(resolvedRoutesDir) && routableFileType) {
2241
- if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware)) {
2253
+ if (filename.startsWith(resolvedRoutesDir) && routableFileType || filename === runtimeInclude) {
2254
+ if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware || filename === runtimeInclude)) {
2242
2255
  buildVirtualFilesResult = void 0;
2243
2256
  renderVirtualFilesResult = void 0;
2257
+ routeMarkoApiCache = void 0;
2244
2258
  const module = devServer.moduleGraph.getModuleById(filename);
2245
2259
  const importers = module && getImporters(module, filename);
2246
2260
  if (importers == null ? void 0 : importers.size) {
@@ -2314,8 +2328,7 @@ function markoRun(opts = {}) {
2314
2328
  await renderVirtualFiles(this);
2315
2329
  }
2316
2330
  if (virtualFiles.has(id)) {
2317
- const file = virtualFiles.get(id);
2318
- return file;
2331
+ return virtualFiles.get(id);
2319
2332
  } else if (!id.startsWith(entryFilesDirPosix) && /[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
2320
2333
  return "";
2321
2334
  }
@@ -2735,7 +2748,7 @@ function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
2735
2748
  }
2736
2749
  return void 0;
2737
2750
  }
2738
- async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
2751
+ async function getViteConfig(dir, configFile, bases = defaultConfigFileBases, fallback = path9.join(__dirname3, "default.config.mjs")) {
2739
2752
  if (configFile) {
2740
2753
  const configFilePath = path9.join(dir, configFile);
2741
2754
  if (!fs6.existsSync(configFilePath)) {
@@ -2749,7 +2762,7 @@ async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
2749
2762
  return configFile;
2750
2763
  }
2751
2764
  }
2752
- return path9.join(__dirname3, "default.config.mjs");
2765
+ return fallback;
2753
2766
  }
2754
2767
 
2755
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) {
@@ -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, rootDir: string): string;
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: string | undefined, options?: RouterOptions): string;
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>;
@@ -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, rootDir) {
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
- return renderEntryTemplate(
311
- normalizedRelativePath(rootDir, route.templateFilePath),
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 = `"${decodePath(route.path.path)}"`;
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]) {
@@ -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 import_buffer.Blob([source]).size;
1772
+ return new Blob([source]).size;
1785
1773
  }
1786
1774
  function computeChunkSize(chunk, bundle, seen = /* @__PURE__ */ new Set()) {
1787
1775
  if (chunk.type === "asset") {
@@ -1898,6 +1886,7 @@ function markoRun(opts = {}) {
1898
1886
  let routeData;
1899
1887
  let resolvedConfig;
1900
1888
  let typesFile;
1889
+ let runtimeInclude;
1901
1890
  const externalRoutes = /* @__PURE__ */ new Set();
1902
1891
  const seenErrors = /* @__PURE__ */ new Set();
1903
1892
  const virtualFiles = /* @__PURE__ */ new Map();
@@ -1905,6 +1894,13 @@ function markoRun(opts = {}) {
1905
1894
  routesBuild: 0,
1906
1895
  routesRender: 0
1907
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
+ }
1908
1904
  async function getExportsFromFile(context, filePath) {
1909
1905
  if (devServer) {
1910
1906
  const result2 = await devServer.transformRequest(filePath, { ssr: false });
@@ -1916,6 +1912,17 @@ function markoRun(opts = {}) {
1916
1912
  });
1917
1913
  return result.exports || [];
1918
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
+ }
1919
1926
  async function writeTypesFile(routes2) {
1920
1927
  if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
1921
1928
  root,
@@ -2028,7 +2035,10 @@ function markoRun(opts = {}) {
2028
2035
  });
2029
2036
  import_fs4.default.writeFileSync(
2030
2037
  route.templateFilePath,
2031
- renderRouteTemplate(route, root)
2038
+ renderRouteTemplate(
2039
+ route,
2040
+ await getMarkoApiForRoute(context, route)
2041
+ )
2032
2042
  );
2033
2043
  }
2034
2044
  virtualFiles.set(
@@ -2043,7 +2053,10 @@ function markoRun(opts = {}) {
2043
2053
  });
2044
2054
  import_fs4.default.writeFileSync(
2045
2055
  route.templateFilePath,
2046
- renderRouteTemplate(route, root)
2056
+ renderRouteTemplate(
2057
+ route,
2058
+ await getMarkoApiForRoute(context, route)
2059
+ )
2047
2060
  );
2048
2061
  }
2049
2062
  }
@@ -2060,7 +2073,7 @@ function markoRun(opts = {}) {
2060
2073
  renderMiddleware(routes2.middleware, root)
2061
2074
  );
2062
2075
  }
2063
- const runtimeInclude = await ((_a = adapter == null ? void 0 : adapter.runtimeInclude) == null ? void 0 : _a.call(adapter));
2076
+ runtimeInclude = await ((_a = adapter == null ? void 0 : adapter.runtimeInclude) == null ? void 0 : _a.call(adapter));
2064
2077
  virtualFiles.set(
2065
2078
  import_path6.default.posix.join(root, ROUTER_FILENAME),
2066
2079
  renderRouter(routes2, root, runtimeInclude, {
@@ -2264,10 +2277,11 @@ function markoRun(opts = {}) {
2264
2277
  const routableFileType = matchRoutableFile(
2265
2278
  import_path6.default.parse(filename).base
2266
2279
  );
2267
- if (filename.startsWith(resolvedRoutesDir) && routableFileType) {
2268
- if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware)) {
2280
+ if (filename.startsWith(resolvedRoutesDir) && routableFileType || filename === runtimeInclude) {
2281
+ if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware || filename === runtimeInclude)) {
2269
2282
  buildVirtualFilesResult = void 0;
2270
2283
  renderVirtualFilesResult = void 0;
2284
+ routeMarkoApiCache = void 0;
2271
2285
  const module2 = devServer.moduleGraph.getModuleById(filename);
2272
2286
  const importers = module2 && getImporters(module2, filename);
2273
2287
  if (importers == null ? void 0 : importers.size) {
@@ -2341,8 +2355,7 @@ function markoRun(opts = {}) {
2341
2355
  await renderVirtualFiles(this);
2342
2356
  }
2343
2357
  if (virtualFiles.has(id)) {
2344
- const file = virtualFiles.get(id);
2345
- return file;
2358
+ return virtualFiles.get(id);
2346
2359
  } else if (!id.startsWith(entryFilesDirPosix) && /[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
2347
2360
  return "";
2348
2361
  }
@@ -2544,9 +2557,12 @@ async function spawnServer(cmd, args = [], port = 0, env, cwd = process.cwd(), w
2544
2557
  windowsHide: true,
2545
2558
  env: { ...env, NODE_ENV: "development", ...process.env, PORT: `${port}` }
2546
2559
  });
2547
- const close = () => {
2560
+ const close = async () => {
2548
2561
  proc.unref();
2549
2562
  proc.kill();
2563
+ if (!await waitForExit(proc, 500)) {
2564
+ proc.kill("SIGKILL");
2565
+ }
2550
2566
  };
2551
2567
  try {
2552
2568
  await Promise.race([waitForError(proc, port), waitForServer(port, wait)]);
@@ -2594,6 +2610,15 @@ async function spawnServerWorker(module2, args = [], port = 0, env, wait = true)
2594
2610
  import_cluster.default.settings.execArgv = originalArgs;
2595
2611
  }
2596
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
+ }
2597
2622
  async function waitForError(proc, port) {
2598
2623
  return new Promise((_, reject) => {
2599
2624
  proc.once("error", reject);