@marko/run 0.1.8 → 0.1.10

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.
@@ -266,7 +266,7 @@ function adapter() {
266
266
  });
267
267
  },
268
268
  async startPreview(entry, options) {
269
- const { port, envFile } = options;
269
+ const { port = 3e3, envFile } = options;
270
270
  const { nodeArgs } = (0, import_parse_node_args.default)(options.args);
271
271
  const args = [...nodeArgs, entry];
272
272
  const server = await spawnServer("node", args, port, envFile);
@@ -231,7 +231,7 @@ function adapter() {
231
231
  });
232
232
  },
233
233
  async startPreview(entry, options) {
234
- const { port, envFile } = options;
234
+ const { port = 3e3, envFile } = options;
235
235
  const { nodeArgs } = parseNodeArgs(options.args);
236
236
  const args = [...nodeArgs, entry];
237
237
  const server = await spawnServer("node", args, port, envFile);
@@ -90,12 +90,17 @@ async function resolveAdapter(root, options, log) {
90
90
  const { resolvePackageData } = await import("vite");
91
91
  const pkg = resolvePackageData(".", root);
92
92
  if (pkg) {
93
- const dependecies = { ...pkg.data.dependecies, ...pkg.data.devDependencies };
93
+ const dependecies = {
94
+ ...pkg.data.dependecies,
95
+ ...pkg.data.devDependencies
96
+ };
94
97
  for (const name of Object.keys(dependecies)) {
95
98
  if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
96
99
  try {
97
100
  const module2 = await import(name);
98
- log && console.log(`Using adapter ${name} listed in your package.json dependecies`);
101
+ log && console.log(
102
+ `Using adapter ${name} listed in your package.json dependecies`
103
+ );
99
104
  return module2.default();
100
105
  } catch (err) {
101
106
  log && console.warn(`Attempt to use package '${name}' failed`, err);
@@ -1,5 +1,5 @@
1
1
  import { NotHandled, NotMatched } from "./namespace";
2
- import { GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform, HandlerTypeFn, RuntimeModule, AnyRoute, AnyContext, AnyHandler } from "./types";
2
+ import type { GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform, HandlerTypeFn, RuntimeModule, AnyRoute, AnyContext, AnyHandler } from "./types";
3
3
  declare global {
4
4
  var __marko_run__: RuntimeModule;
5
5
  namespace MarkoRun {
@@ -3,7 +3,7 @@ type OneOrMany<T> = T | T[];
3
3
  type NoParams = {};
4
4
  export interface Platform {
5
5
  }
6
- export interface Context<TRoute extends AnyRoute = AnyRoute> {
6
+ export interface Context<TRoute extends Route = AnyRoute> {
7
7
  readonly url: URL;
8
8
  readonly request: Request;
9
9
  readonly route: TRoute["path"];
@@ -12,13 +12,13 @@ export interface Context<TRoute extends AnyRoute = AnyRoute> {
12
12
  readonly platform: Platform;
13
13
  readonly serializedGlobals: Record<string, boolean>;
14
14
  }
15
- export type MultiRouteContext<TRoute extends AnyRoute> = TRoute extends any ? Context<TRoute> : never;
15
+ export type MultiRouteContext<TRoute extends Route> = TRoute extends any ? Context<TRoute> : never;
16
16
  export type ParamsObject = Record<string, string>;
17
17
  export type InputObject = Record<PropertyKey, any>;
18
18
  export type NextFunction = () => Awaitable<Response>;
19
- export type HandlerLike<TRoute extends AnyRoute = AnyRoute> = Awaitable<OneOrMany<RouteHandler<TRoute>>>;
20
- export type RouteHandler<TRoute extends AnyRoute = AnyRoute> = (context: MultiRouteContext<TRoute>, next: NextFunction) => Awaitable<Response | null | void>;
21
- export interface Route<Params extends ParamsObject, Meta, Path extends string> {
19
+ export type HandlerLike<TRoute extends Route = AnyRoute> = Awaitable<OneOrMany<RouteHandler<TRoute>>>;
20
+ export type RouteHandler<TRoute extends Route = AnyRoute> = (context: MultiRouteContext<TRoute>, next: NextFunction) => Awaitable<Response | null | void>;
21
+ export interface Route<Params extends ParamsObject = ParamsObject, Meta = unknown, Path extends string = string> {
22
22
  path: Path;
23
23
  params: Params;
24
24
  meta: Meta;
@@ -79,11 +79,11 @@ type AnyParams = 0 extends HasAppData ? ParamsObject : never;
79
79
  type AnyMeta = 0 extends HasAppData ? unknown : never;
80
80
  export type Routes = AppData extends {
81
81
  routes: infer T;
82
- } ? T : Record<string, Route<ParamsObject, unknown, string>>;
82
+ } ? T : Record<string, Route>;
83
83
  export type AnyRoute = Routes[keyof Routes];
84
84
  export type AnyContext = MultiRouteContext<AnyRoute>;
85
- export type AnyHandler<Params extends AnyParams = AnyParams, Meta extends AnyMeta = AnyMeta> = 0 extends HasAppData ? HandlerLike<Route<Params, Meta, string>> : HandlerLike<AnyRoute>;
86
- export type HandlerTypeFn<THandler extends HandlerLike = AnyHandler> = 0 extends HasAppData ? <Params extends ParamsObject = ParamsObject, Meta = unknown>(handler: HandlerLike<Route<Params, Meta, string>>) => HandlerLike<Route<Params, Meta, string>> : (handler: THandler) => THandler;
85
+ export type AnyHandler<Params extends AnyParams = AnyParams, Meta extends AnyMeta = AnyMeta> = 0 extends HasAppData ? HandlerLike<Route<Params, Meta>> : HandlerLike<AnyRoute>;
86
+ export type HandlerTypeFn<TRoute extends Route = AnyRoute> = 0 extends HasAppData ? <Params extends ParamsObject = ParamsObject, Meta = unknown>(handler: HandlerLike<Route<Params, Meta>>) => HandlerLike<Route<Params, Meta>> : (handler: HandlerLike<TRoute>) => HandlerLike<TRoute>;
87
87
  export type GetPaths = AppData extends {
88
88
  getPaths: infer T;
89
89
  } ? T : string;
@@ -987,7 +987,7 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
987
987
  Do NOT manually edit this file or your changes will be lost.
988
988
  */
989
989
  `,
990
- `import "@marko/run/namespace";`,
990
+ `import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace";`,
991
991
  `import type Run from "@marko/run";`
992
992
  );
993
993
  const headWriter = writer.branch("head");
@@ -1130,11 +1130,11 @@ function writeModuleDeclaration(writer, path3, routeType, moduleTypes) {
1130
1130
  const isMarko = path3.endsWith(".marko");
1131
1131
  writer.write(`
1132
1132
  namespace MarkoRun {
1133
- export * from "@marko/run/namespace";
1133
+ export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
1134
1134
  export type Route = ${routeType};
1135
1135
  export type Context = Run.MultiRouteContext<Route>${isMarko ? " & Marko.Global" : ""};
1136
1136
  export type Handler = Run.HandlerLike<Route>;
1137
- export const route: Run.HandlerTypeFn<Handler>;
1137
+ export const route: Run.HandlerTypeFn<Route>;
1138
1138
  }`);
1139
1139
  }
1140
1140
  writer.writeLines(`
@@ -1452,7 +1452,7 @@ function markoRun(opts = {}) {
1452
1452
  name: "marko-run-vite:pre",
1453
1453
  enforce: "pre",
1454
1454
  async config(config2, env) {
1455
- var _a, _b, _c;
1455
+ var _a, _b, _c, _d, _e, _f;
1456
1456
  const externalPluginOptions = getExternalPluginOptions(config2);
1457
1457
  if (externalPluginOptions) {
1458
1458
  opts = (0, import_vite.mergeConfig)(opts, externalPluginOptions);
@@ -1460,7 +1460,11 @@ function markoRun(opts = {}) {
1460
1460
  root = normalizePath(config2.root || process.cwd());
1461
1461
  isBuild = env.command === "build";
1462
1462
  isSSRBuild = isBuild && Boolean((_a = config2.build) == null ? void 0 : _a.ssr);
1463
- adapter = await resolveAdapter(root, opts, config2.logLevel !== "silent" && !isBuild || isSSRBuild);
1463
+ adapter = await resolveAdapter(
1464
+ root,
1465
+ opts,
1466
+ config2.logLevel !== "silent" && !isBuild || isSSRBuild
1467
+ );
1464
1468
  if (adapter) {
1465
1469
  const externalAdapterConfig = getExternalAdapterOptions(config2);
1466
1470
  if (externalAdapterConfig && adapter.configure) {
@@ -1487,6 +1491,44 @@ function markoRun(opts = {}) {
1487
1491
  typesDir = import_path2.default.join(root, ".marko-run");
1488
1492
  devEntryFile = import_path2.default.join(root, "index.html");
1489
1493
  devEntryFilePosix = normalizePath(devEntryFile);
1494
+ const assetsDir = ((_c = config2.build) == null ? void 0 : _c.assetsDir) || "assets";
1495
+ let rollupOutputOptions = (_e = (_d = config2.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output;
1496
+ if (isBuild && !isSSRBuild) {
1497
+ const defaultRollupOutputOptions = {
1498
+ assetFileNames({ name }) {
1499
+ if (name && name.indexOf("_marko-virtual_id_") < 0) {
1500
+ return `${assetsDir}/${getEntryFileName(name) || "[name]"}-[hash].[ext]`;
1501
+ }
1502
+ return `${assetsDir}/_[hash].[ext]`;
1503
+ },
1504
+ entryFileNames(info) {
1505
+ let name = getEntryFileName(info.facadeModuleId);
1506
+ if (!name) {
1507
+ for (let id of info.moduleIds) {
1508
+ name = getEntryFileName(id);
1509
+ if (name) {
1510
+ break;
1511
+ }
1512
+ }
1513
+ }
1514
+ return `${assetsDir}/${name || "[name]"}-[hash].js`;
1515
+ },
1516
+ chunkFileNames: `${assetsDir}/_[hash].js`
1517
+ };
1518
+ if (!rollupOutputOptions) {
1519
+ rollupOutputOptions = defaultRollupOutputOptions;
1520
+ } else if (!Array.isArray(rollupOutputOptions)) {
1521
+ rollupOutputOptions = {
1522
+ ...defaultRollupOutputOptions,
1523
+ ...rollupOutputOptions
1524
+ };
1525
+ } else {
1526
+ rollupOutputOptions = rollupOutputOptions.map((options) => ({
1527
+ ...defaultRollupOutputOptions,
1528
+ ...options
1529
+ }));
1530
+ }
1531
+ }
1490
1532
  let pluginConfig = {
1491
1533
  logLevel: isBuild ? "warn" : void 0,
1492
1534
  define: isBuild ? {
@@ -1496,10 +1538,13 @@ function markoRun(opts = {}) {
1496
1538
  noExternal: /@marko\/run/
1497
1539
  },
1498
1540
  build: {
1499
- emptyOutDir: isSSRBuild
1541
+ emptyOutDir: isSSRBuild,
1542
+ rollupOptions: {
1543
+ output: rollupOutputOptions
1544
+ }
1500
1545
  }
1501
1546
  };
1502
- const adapterConfig = await ((_c = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _c.call(adapter, config2));
1547
+ const adapterConfig = await ((_f = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _f.call(adapter, config2));
1503
1548
  if (adapterConfig) {
1504
1549
  pluginConfig = (0, import_vite.mergeConfig)(pluginConfig, adapterConfig);
1505
1550
  }
@@ -1619,6 +1664,15 @@ function markoRun(opts = {}) {
1619
1664
  {
1620
1665
  name: "marko-run-vite:post",
1621
1666
  enforce: "post",
1667
+ generateBundle(options, bundle) {
1668
+ if (options.sourcemap && options.sourcemap !== "inline") {
1669
+ for (const key of Object.keys(bundle)) {
1670
+ if (key.endsWith(".map") && !bundle[key.slice(0, -4)]) {
1671
+ delete bundle[key];
1672
+ }
1673
+ }
1674
+ }
1675
+ },
1622
1676
  async writeBundle(options, bundle) {
1623
1677
  var _a;
1624
1678
  if (isSSRBuild) {
@@ -1735,12 +1789,17 @@ async function resolveAdapter(root, options, log) {
1735
1789
  const { resolvePackageData } = await import("vite");
1736
1790
  const pkg = resolvePackageData(".", root);
1737
1791
  if (pkg) {
1738
- const dependecies = { ...pkg.data.dependecies, ...pkg.data.devDependencies };
1792
+ const dependecies = {
1793
+ ...pkg.data.dependecies,
1794
+ ...pkg.data.devDependencies
1795
+ };
1739
1796
  for (const name of Object.keys(dependecies)) {
1740
1797
  if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
1741
1798
  try {
1742
1799
  const module3 = await import(name);
1743
- log && console.log(`Using adapter ${name} listed in your package.json dependecies`);
1800
+ log && console.log(
1801
+ `Using adapter ${name} listed in your package.json dependecies`
1802
+ );
1744
1803
  return module3.default();
1745
1804
  } catch (err) {
1746
1805
  log && console.warn(`Attempt to use package '${name}' failed`, err);
@@ -1753,6 +1812,11 @@ async function resolveAdapter(root, options, log) {
1753
1812
  log && console.log("Using default adapter");
1754
1813
  return module2.default();
1755
1814
  }
1815
+ var markoEntryFileRegex = /__marko-run__([^_]+)__(.+)\.marko.([^.]+)$/;
1816
+ function getEntryFileName(file) {
1817
+ const match = file && markoEntryFileRegex.exec(file);
1818
+ return match ? `${match[2].replace(/__/g, "-")}` : void 0;
1819
+ }
1756
1820
 
1757
1821
  // src/vite/utils/server.ts
1758
1822
  var import_net = __toESM(require("net"), 1);
@@ -950,7 +950,7 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
950
950
  Do NOT manually edit this file or your changes will be lost.
951
951
  */
952
952
  `,
953
- `import "@marko/run/namespace";`,
953
+ `import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace";`,
954
954
  `import type Run from "@marko/run";`
955
955
  );
956
956
  const headWriter = writer.branch("head");
@@ -1093,11 +1093,11 @@ function writeModuleDeclaration(writer, path3, routeType, moduleTypes) {
1093
1093
  const isMarko = path3.endsWith(".marko");
1094
1094
  writer.write(`
1095
1095
  namespace MarkoRun {
1096
- export * from "@marko/run/namespace";
1096
+ export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
1097
1097
  export type Route = ${routeType};
1098
1098
  export type Context = Run.MultiRouteContext<Route>${isMarko ? " & Marko.Global" : ""};
1099
1099
  export type Handler = Run.HandlerLike<Route>;
1100
- export const route: Run.HandlerTypeFn<Handler>;
1100
+ export const route: Run.HandlerTypeFn<Route>;
1101
1101
  }`);
1102
1102
  }
1103
1103
  writer.writeLines(`
@@ -1414,7 +1414,7 @@ function markoRun(opts = {}) {
1414
1414
  name: "marko-run-vite:pre",
1415
1415
  enforce: "pre",
1416
1416
  async config(config2, env) {
1417
- var _a, _b, _c;
1417
+ var _a, _b, _c, _d, _e, _f;
1418
1418
  const externalPluginOptions = getExternalPluginOptions(config2);
1419
1419
  if (externalPluginOptions) {
1420
1420
  opts = mergeConfig(opts, externalPluginOptions);
@@ -1422,7 +1422,11 @@ function markoRun(opts = {}) {
1422
1422
  root = normalizePath(config2.root || process.cwd());
1423
1423
  isBuild = env.command === "build";
1424
1424
  isSSRBuild = isBuild && Boolean((_a = config2.build) == null ? void 0 : _a.ssr);
1425
- adapter = await resolveAdapter(root, opts, config2.logLevel !== "silent" && !isBuild || isSSRBuild);
1425
+ adapter = await resolveAdapter(
1426
+ root,
1427
+ opts,
1428
+ config2.logLevel !== "silent" && !isBuild || isSSRBuild
1429
+ );
1426
1430
  if (adapter) {
1427
1431
  const externalAdapterConfig = getExternalAdapterOptions(config2);
1428
1432
  if (externalAdapterConfig && adapter.configure) {
@@ -1449,6 +1453,44 @@ function markoRun(opts = {}) {
1449
1453
  typesDir = path2.join(root, ".marko-run");
1450
1454
  devEntryFile = path2.join(root, "index.html");
1451
1455
  devEntryFilePosix = normalizePath(devEntryFile);
1456
+ const assetsDir = ((_c = config2.build) == null ? void 0 : _c.assetsDir) || "assets";
1457
+ let rollupOutputOptions = (_e = (_d = config2.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output;
1458
+ if (isBuild && !isSSRBuild) {
1459
+ const defaultRollupOutputOptions = {
1460
+ assetFileNames({ name }) {
1461
+ if (name && name.indexOf("_marko-virtual_id_") < 0) {
1462
+ return `${assetsDir}/${getEntryFileName(name) || "[name]"}-[hash].[ext]`;
1463
+ }
1464
+ return `${assetsDir}/_[hash].[ext]`;
1465
+ },
1466
+ entryFileNames(info) {
1467
+ let name = getEntryFileName(info.facadeModuleId);
1468
+ if (!name) {
1469
+ for (let id of info.moduleIds) {
1470
+ name = getEntryFileName(id);
1471
+ if (name) {
1472
+ break;
1473
+ }
1474
+ }
1475
+ }
1476
+ return `${assetsDir}/${name || "[name]"}-[hash].js`;
1477
+ },
1478
+ chunkFileNames: `${assetsDir}/_[hash].js`
1479
+ };
1480
+ if (!rollupOutputOptions) {
1481
+ rollupOutputOptions = defaultRollupOutputOptions;
1482
+ } else if (!Array.isArray(rollupOutputOptions)) {
1483
+ rollupOutputOptions = {
1484
+ ...defaultRollupOutputOptions,
1485
+ ...rollupOutputOptions
1486
+ };
1487
+ } else {
1488
+ rollupOutputOptions = rollupOutputOptions.map((options) => ({
1489
+ ...defaultRollupOutputOptions,
1490
+ ...options
1491
+ }));
1492
+ }
1493
+ }
1452
1494
  let pluginConfig = {
1453
1495
  logLevel: isBuild ? "warn" : void 0,
1454
1496
  define: isBuild ? {
@@ -1458,10 +1500,13 @@ function markoRun(opts = {}) {
1458
1500
  noExternal: /@marko\/run/
1459
1501
  },
1460
1502
  build: {
1461
- emptyOutDir: isSSRBuild
1503
+ emptyOutDir: isSSRBuild,
1504
+ rollupOptions: {
1505
+ output: rollupOutputOptions
1506
+ }
1462
1507
  }
1463
1508
  };
1464
- const adapterConfig = await ((_c = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _c.call(adapter, config2));
1509
+ const adapterConfig = await ((_f = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _f.call(adapter, config2));
1465
1510
  if (adapterConfig) {
1466
1511
  pluginConfig = mergeConfig(pluginConfig, adapterConfig);
1467
1512
  }
@@ -1581,6 +1626,15 @@ function markoRun(opts = {}) {
1581
1626
  {
1582
1627
  name: "marko-run-vite:post",
1583
1628
  enforce: "post",
1629
+ generateBundle(options, bundle) {
1630
+ if (options.sourcemap && options.sourcemap !== "inline") {
1631
+ for (const key of Object.keys(bundle)) {
1632
+ if (key.endsWith(".map") && !bundle[key.slice(0, -4)]) {
1633
+ delete bundle[key];
1634
+ }
1635
+ }
1636
+ }
1637
+ },
1584
1638
  async writeBundle(options, bundle) {
1585
1639
  var _a;
1586
1640
  if (isSSRBuild) {
@@ -1697,12 +1751,17 @@ async function resolveAdapter(root, options, log) {
1697
1751
  const { resolvePackageData } = await import("vite");
1698
1752
  const pkg = resolvePackageData(".", root);
1699
1753
  if (pkg) {
1700
- const dependecies = { ...pkg.data.dependecies, ...pkg.data.devDependencies };
1754
+ const dependecies = {
1755
+ ...pkg.data.dependecies,
1756
+ ...pkg.data.devDependencies
1757
+ };
1701
1758
  for (const name of Object.keys(dependecies)) {
1702
1759
  if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
1703
1760
  try {
1704
1761
  const module2 = await import(name);
1705
- log && console.log(`Using adapter ${name} listed in your package.json dependecies`);
1762
+ log && console.log(
1763
+ `Using adapter ${name} listed in your package.json dependecies`
1764
+ );
1706
1765
  return module2.default();
1707
1766
  } catch (err) {
1708
1767
  log && console.warn(`Attempt to use package '${name}' failed`, err);
@@ -1715,6 +1774,11 @@ async function resolveAdapter(root, options, log) {
1715
1774
  log && console.log("Using default adapter");
1716
1775
  return module.default();
1717
1776
  }
1777
+ var markoEntryFileRegex = /__marko-run__([^_]+)__(.+)\.marko.([^.]+)$/;
1778
+ function getEntryFileName(file) {
1779
+ const match = file && markoEntryFileRegex.exec(file);
1780
+ return match ? `${match[2].replace(/__/g, "-")}` : void 0;
1781
+ }
1718
1782
 
1719
1783
  // src/vite/utils/server.ts
1720
1784
  import net from "net";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "The Marko application framework.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/marko-js/run/tree/main/packages/run",