@marko/run 0.1.9 → 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);
@@ -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);
@@ -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.9",
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",