@marko/run 0.2.4 → 0.2.6

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.
@@ -1624,6 +1624,7 @@ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterCon
1624
1624
  // src/vite/plugin.ts
1625
1625
  var import_url2 = require("url");
1626
1626
  var __dirname = import_path2.default.dirname((0, import_url2.fileURLToPath)(__importMetaURL));
1627
+ var PLUGIN_NAME_PREFIX = "marko-run-vite";
1627
1628
  var POSIX_SEP = "/";
1628
1629
  var WINDOWS_SEP = "\\";
1629
1630
  var normalizePath = import_path2.default.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
@@ -1726,7 +1727,7 @@ function markoRun(opts = {}) {
1726
1727
  });
1727
1728
  return [
1728
1729
  {
1729
- name: "marko-run-vite:pre",
1730
+ name: `${PLUGIN_NAME_PREFIX}:pre`,
1730
1731
  enforce: "pre",
1731
1732
  async config(config2, env) {
1732
1733
  var _a, _b, _c, _d, _e, _f;
@@ -1949,7 +1950,7 @@ function markoRun(opts = {}) {
1949
1950
  },
1950
1951
  ...(0, import_vite2.default)(markoVitePluginOptions),
1951
1952
  {
1952
- name: "marko-run-vite:post",
1953
+ name: `${PLUGIN_NAME_PREFIX}:post`,
1953
1954
  enforce: "post",
1954
1955
  generateBundle(options, bundle) {
1955
1956
  if (options.sourcemap && options.sourcemap !== "inline") {
@@ -2078,9 +2079,8 @@ async function getPackageData(dir) {
2078
2079
  return null;
2079
2080
  }
2080
2081
  async function resolveAdapter(root, options, log) {
2081
- const { adapter } = options;
2082
- if (adapter !== void 0) {
2083
- return adapter;
2082
+ if (options && options.adapter !== void 0) {
2083
+ return options.adapter;
2084
2084
  }
2085
2085
  const pkg = await getPackageData(root);
2086
2086
  if (pkg) {
@@ -2196,11 +2196,14 @@ async function getConnection(port) {
2196
2196
  async function isPortInUse(port) {
2197
2197
  return Boolean(await getConnection(port));
2198
2198
  }
2199
- async function getAvailablePort() {
2199
+ async function getAvailablePort(port) {
2200
+ if (port && !await isPortInUse(port)) {
2201
+ return port;
2202
+ }
2200
2203
  return new Promise((resolve) => {
2201
2204
  const server = import_net.default.createServer().listen(0, () => {
2202
- const { port } = server.address();
2203
- server.close(() => resolve(port));
2205
+ const { port: port2 } = server.address();
2206
+ server.close(() => resolve(port2));
2204
2207
  });
2205
2208
  });
2206
2209
  }
@@ -1584,6 +1584,7 @@ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterCon
1584
1584
  // src/vite/plugin.ts
1585
1585
  import { fileURLToPath } from "url";
1586
1586
  var __dirname = path2.dirname(fileURLToPath(import.meta.url));
1587
+ var PLUGIN_NAME_PREFIX = "marko-run-vite";
1587
1588
  var POSIX_SEP = "/";
1588
1589
  var WINDOWS_SEP = "\\";
1589
1590
  var normalizePath = path2.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
@@ -1686,7 +1687,7 @@ function markoRun(opts = {}) {
1686
1687
  });
1687
1688
  return [
1688
1689
  {
1689
- name: "marko-run-vite:pre",
1690
+ name: `${PLUGIN_NAME_PREFIX}:pre`,
1690
1691
  enforce: "pre",
1691
1692
  async config(config2, env) {
1692
1693
  var _a, _b, _c, _d, _e, _f;
@@ -1909,7 +1910,7 @@ function markoRun(opts = {}) {
1909
1910
  },
1910
1911
  ...markoVitePlugin(markoVitePluginOptions),
1911
1912
  {
1912
- name: "marko-run-vite:post",
1913
+ name: `${PLUGIN_NAME_PREFIX}:post`,
1913
1914
  enforce: "post",
1914
1915
  generateBundle(options, bundle) {
1915
1916
  if (options.sourcemap && options.sourcemap !== "inline") {
@@ -2038,9 +2039,8 @@ async function getPackageData(dir) {
2038
2039
  return null;
2039
2040
  }
2040
2041
  async function resolveAdapter(root, options, log) {
2041
- const { adapter } = options;
2042
- if (adapter !== void 0) {
2043
- return adapter;
2042
+ if (options && options.adapter !== void 0) {
2043
+ return options.adapter;
2044
2044
  }
2045
2045
  const pkg = await getPackageData(root);
2046
2046
  if (pkg) {
@@ -2156,11 +2156,14 @@ async function getConnection(port) {
2156
2156
  async function isPortInUse(port) {
2157
2157
  return Boolean(await getConnection(port));
2158
2158
  }
2159
- async function getAvailablePort() {
2159
+ async function getAvailablePort(port) {
2160
+ if (port && !await isPortInUse(port)) {
2161
+ return port;
2162
+ }
2160
2163
  return new Promise((resolve) => {
2161
2164
  const server = net.createServer().listen(0, () => {
2162
- const { port } = server.address();
2163
- server.close(() => resolve(port));
2165
+ const { port: port2 } = server.address();
2166
+ server.close(() => resolve(port2));
2164
2167
  });
2165
2168
  });
2166
2169
  }
@@ -1,5 +1,6 @@
1
- import type { Plugin } from "vite";
1
+ import type { Plugin, ResolvedConfig } from "vite";
2
2
  import type { Options, Adapter, PackageData } from "./types";
3
3
  export default function markoRun(opts?: Options): Plugin[];
4
4
  export declare function getPackageData(dir: string): Promise<PackageData | null>;
5
- export declare function resolveAdapter(root: string, options: Options, log?: boolean): Promise<Adapter | null>;
5
+ export declare function resolveAdapter(root: string, options?: Options, log?: boolean): Promise<Adapter | null>;
6
+ export declare function isPluginIncluded(config: ResolvedConfig): boolean;
@@ -17,4 +17,4 @@ export declare function waitForServer(port: number, wait?: number): Promise<Sock
17
17
  export declare function waitForWorker(worker: Worker, port: number): Promise<void>;
18
18
  export declare function getConnection(port: number): Promise<Socket | null>;
19
19
  export declare function isPortInUse(port: number): Promise<boolean>;
20
- export declare function getAvailablePort(): Promise<number>;
20
+ export declare function getAvailablePort(port?: number): Promise<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "The Marko application framework.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/marko-js/run/tree/main/packages/run",
@@ -112,7 +112,7 @@
112
112
  "typescript": "^4.7.4"
113
113
  },
114
114
  "dependencies": {
115
- "@marko/vite": "^2.4.8",
115
+ "@marko/vite": "^3",
116
116
  "cli-table3": "^0.6.3",
117
117
  "compression": "^1.7.4",
118
118
  "dotenv": "^16.0.3",