@b12k/porto 0.9.0 → 0.10.0

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.
package/dist/config.js CHANGED
@@ -1,15 +1,13 @@
1
- import { access, realpath } from "node:fs/promises";
1
+ import { cosmiconfig } from "cosmiconfig";
2
+ import { realpath } from "node:fs/promises";
2
3
  import node_path from "node:path";
3
4
  import { z } from "zod";
4
5
  import package_0 from "../package.json" with {
5
6
  type: "json"
6
7
  };
7
8
  import { PortoError } from "./error.js";
8
- import { checkIsFileMissing } from "./files.js";
9
- import { loadConfigFile } from "./load-config.js";
10
- import { HOOKS_SCHEMA, OPTIONS_SCHEMA, parseOptions } from "./schemas.js";
9
+ import { HOOKS_SCHEMA, OPTIONS_SCHEMA, OUTPUT_OPTIONS_SCHEMA } from "./schemas.js";
11
10
  import { VARS_SCHEMA } from "./vars.js";
12
- const DEFAULT_ENV_FILE = '.env';
13
11
  const CONFIG_FILES = [
14
12
  'porto.config.ts',
15
13
  'porto.config.js'
@@ -17,39 +15,29 @@ const CONFIG_FILES = [
17
15
  const CONFIG_SCHEMA = z.strictObject({
18
16
  ...OPTIONS_SCHEMA.shape,
19
17
  ...HOOKS_SCHEMA.shape,
20
- env: z.boolean(),
21
- envFile: z.string().min(1),
22
- jsonFile: z.union([
23
- z.literal(false),
24
- z.string().min(1)
25
- ]),
26
- silent: z.boolean(),
18
+ ...OUTPUT_OPTIONS_SCHEMA.shape,
27
19
  vars: VARS_SCHEMA
28
20
  }).partial();
29
21
  const libraryName = 'porto';
30
22
  const { name: config_name, version } = package_0;
23
+ function applyReserveDefaults(settings, range) {
24
+ const size = settings.size ?? range.portsPerSlot;
25
+ const start = settings.start ?? range.startPort;
26
+ if (start + size - 1 > 65535) throw new PortoError('optionsInvalid', 'size: size must fit in the TCP port range.');
27
+ return {
28
+ ...settings,
29
+ env: settings.env ?? false,
30
+ envFile: settings.envFile ?? '.env',
31
+ idleTtlMinutes: settings.idleTtlMinutes ?? 60,
32
+ jsonFile: settings.jsonFile ?? false,
33
+ silent: settings.silent ?? false,
34
+ size,
35
+ start
36
+ };
37
+ }
31
38
  function defineConfig(config) {
32
39
  return config;
33
40
  }
34
- async function fetchConfigPath(candidates) {
35
- let configPath;
36
- for (const filePath of candidates)try {
37
- await access(filePath);
38
- configPath = filePath;
39
- break;
40
- } catch (error) {
41
- if (!checkIsFileMissing(error)) throw error;
42
- }
43
- return configPath;
44
- }
45
- function getConfigPaths(directoryPath, worktreePath) {
46
- const filePaths = [];
47
- for(let currentPath = directoryPath;; currentPath = node_path.dirname(currentPath)){
48
- filePaths.push(...CONFIG_FILES.map((fileName)=>node_path.join(currentPath, fileName)));
49
- if (currentPath === worktreePath) return filePaths;
50
- if (node_path.dirname(currentPath) === currentPath) throw new PortoError('configInvalid', 'Cannot find the checkout root.');
51
- }
52
- }
53
41
  function parseConfig(config) {
54
42
  const result = CONFIG_SCHEMA.safeParse(config);
55
43
  if (!result.success) {
@@ -59,45 +47,32 @@ function parseConfig(config) {
59
47
  });
60
48
  }
61
49
  const settings = result.data;
62
- return {
63
- ...settings,
64
- ...void 0 !== settings.envFile && void 0 === settings.env ? {
65
- env: true
66
- } : {}
67
- };
68
- }
69
- function applyReserveDefaults(settings) {
70
- return {
71
- ...settings,
72
- ...parseOptions(settings),
73
- env: settings.env ?? false,
74
- envFile: settings.envFile ?? DEFAULT_ENV_FILE,
75
- jsonFile: settings.jsonFile ?? false,
76
- silent: settings.silent ?? false
77
- };
78
- }
79
- function resolveConfigPaths(config, filePath) {
80
- const directoryPath = node_path.dirname(filePath);
81
- for (const key of [
82
- 'envFile',
83
- 'jsonFile'
84
- ]){
85
- const configuredPath = config[key];
86
- if ('string' == typeof configuredPath) config[key] = node_path.resolve(directoryPath, configuredPath);
87
- }
88
- return config;
50
+ if (void 0 !== settings.envFile) settings.env ??= true;
51
+ return settings;
89
52
  }
90
- async function fetchConfig(worktree) {
91
- const candidates = getConfigPaths(await realpath(process.cwd()), worktree);
92
- const filePath = await fetchConfigPath(candidates);
93
- if (!filePath) return parseConfig({});
53
+ async function fetchConfig(worktreePath) {
54
+ let result;
94
55
  try {
95
- const config = await loadConfigFile(filePath);
96
- return resolveConfigPaths(parseConfig(config), filePath);
56
+ result = await cosmiconfig(libraryName, {
57
+ searchPlaces: CONFIG_FILES,
58
+ stopDir: worktreePath
59
+ }).search(await realpath(process.cwd()));
97
60
  } catch (error) {
98
- throw new PortoError('configInvalid', `${filePath}: ${error instanceof Error ? error.message : String(error)}`, {
61
+ throw new PortoError('configInvalid', error instanceof Error ? error.message : String(error), {
99
62
  cause: error
100
63
  });
101
64
  }
65
+ if (!result) return {};
66
+ const config = result.config;
67
+ const settings = parseConfig(config && 'object' == typeof config && 1 === Object.keys(config).length && 'default' in config ? config.default : config);
68
+ const directoryPath = node_path.dirname(result.filepath);
69
+ for (const key of [
70
+ 'envFile',
71
+ 'jsonFile'
72
+ ]){
73
+ const configuredPath = settings[key];
74
+ if ('string' == typeof configuredPath) settings[key] = node_path.resolve(directoryPath, configuredPath);
75
+ }
76
+ return settings;
102
77
  }
103
- export { DEFAULT_ENV_FILE, applyReserveDefaults, config_name as name, defineConfig, fetchConfig, libraryName, parseConfig, version };
78
+ export { applyReserveDefaults, config_name as name, defineConfig, fetchConfig, libraryName, parseConfig, version };
package/dist/errors.d.ts CHANGED
@@ -1,8 +1,4 @@
1
1
  export declare const ERRORS_BY_KEY: {
2
- readonly blockUnavailable: {
3
- readonly instruction: 'Release unused blocks or choose another range.';
4
- readonly message: 'No free port block remains in the TCP port range.';
5
- };
6
2
  readonly configInvalid: {
7
3
  readonly instruction: 'Check porto.config.ts or porto.config.js.';
8
4
  readonly message: 'Invalid Porto configuration.';
@@ -16,11 +12,11 @@ export declare const ERRORS_BY_KEY: {
16
12
  readonly message: 'Lifecycle hook failed.';
17
13
  };
18
14
  readonly mappingInvalid: {
19
- readonly instruction: 'Use unique variable names, valid callbacks, and a block large enough for all entries.';
15
+ readonly instruction: 'Use unique variable names, valid callbacks, and a slot large enough for all entries.';
20
16
  readonly message: 'Invalid variables.';
21
17
  };
22
18
  readonly offsetInvalid: {
23
- readonly instruction: 'Choose an integer offset inside the block.';
19
+ readonly instruction: 'Choose an integer offset inside the slot.';
24
20
  readonly message: 'Invalid port offset.';
25
21
  };
26
22
  readonly optionsInvalid: {
@@ -31,13 +27,29 @@ export declare const ERRORS_BY_KEY: {
31
27
  readonly instruction: 'Stop the services using these ports and try again.';
32
28
  readonly message: 'Cannot release reservations while ports are in use.';
33
29
  };
30
+ readonly rangeMismatch: {
31
+ readonly instruction: 'Use the repository start and size, or release all slots before changing them.';
32
+ readonly message: 'Port range settings differ from the repository registry.';
33
+ };
34
34
  readonly registryInvalid: {
35
35
  readonly instruction: 'Restore or repair the reservation file before continuing.';
36
36
  readonly message: 'Cannot read reservation.';
37
37
  };
38
38
  readonly reservationNotFound: {
39
- readonly instruction: 'Run porto reserve first.';
40
- readonly message: 'No reservation for the current worktree.';
39
+ readonly instruction: 'Run porto show --all to list slots or porto reserve to reserve one.';
40
+ readonly message: 'No matching port slot.';
41
+ };
42
+ readonly slotIndexInvalid: {
43
+ readonly instruction: 'Choose a non-negative integer slot index.';
44
+ readonly message: 'Invalid slot index.';
45
+ };
46
+ readonly slotSelectionInvalid: {
47
+ readonly instruction: 'Use a slot number or --all.';
48
+ readonly message: 'Cannot combine a slot number with --all.';
49
+ };
50
+ readonly slotUnavailable: {
51
+ readonly instruction: 'Release unused slots or choose another range.';
52
+ readonly message: 'No free port slot remains in the TCP port range.';
41
53
  };
42
54
  readonly worktreeNotFound: {
43
55
  readonly instruction: 'Run Porto inside a regular Git checkout or linked worktree.';
package/dist/errors.js CHANGED
@@ -1,8 +1,4 @@
1
1
  const ERRORS_BY_KEY = {
2
- blockUnavailable: {
3
- instruction: 'Release unused blocks or choose another range.',
4
- message: 'No free port block remains in the TCP port range.'
5
- },
6
2
  configInvalid: {
7
3
  instruction: 'Check porto.config.ts or porto.config.js.',
8
4
  message: 'Invalid Porto configuration.'
@@ -16,11 +12,11 @@ const ERRORS_BY_KEY = {
16
12
  message: 'Lifecycle hook failed.'
17
13
  },
18
14
  mappingInvalid: {
19
- instruction: 'Use unique variable names, valid callbacks, and a block large enough for all entries.',
15
+ instruction: 'Use unique variable names, valid callbacks, and a slot large enough for all entries.',
20
16
  message: 'Invalid variables.'
21
17
  },
22
18
  offsetInvalid: {
23
- instruction: 'Choose an integer offset inside the block.',
19
+ instruction: 'Choose an integer offset inside the slot.',
24
20
  message: 'Invalid port offset.'
25
21
  },
26
22
  optionsInvalid: {
@@ -31,13 +27,29 @@ const ERRORS_BY_KEY = {
31
27
  instruction: 'Stop the services using these ports and try again.',
32
28
  message: 'Cannot release reservations while ports are in use.'
33
29
  },
30
+ rangeMismatch: {
31
+ instruction: 'Use the repository start and size, or release all slots before changing them.',
32
+ message: 'Port range settings differ from the repository registry.'
33
+ },
34
34
  registryInvalid: {
35
35
  instruction: 'Restore or repair the reservation file before continuing.',
36
36
  message: 'Cannot read reservation.'
37
37
  },
38
38
  reservationNotFound: {
39
- instruction: 'Run porto reserve first.',
40
- message: 'No reservation for the current worktree.'
39
+ instruction: 'Run porto show --all to list slots or porto reserve to reserve one.',
40
+ message: 'No matching port slot.'
41
+ },
42
+ slotIndexInvalid: {
43
+ instruction: 'Choose a non-negative integer slot index.',
44
+ message: 'Invalid slot index.'
45
+ },
46
+ slotSelectionInvalid: {
47
+ instruction: 'Use a slot number or --all.',
48
+ message: 'Cannot combine a slot number with --all.'
49
+ },
50
+ slotUnavailable: {
51
+ instruction: 'Release unused slots or choose another range.',
52
+ message: 'No free port slot remains in the TCP port range.'
41
53
  },
42
54
  worktreeNotFound: {
43
55
  instruction: 'Run Porto inside a regular Git checkout or linked worktree.',
package/dist/git.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare function fetchGitContext(): Promise<{
2
2
  commonDirectory: string;
3
- worktree: string;
4
3
  worktreeId: string;
4
+ worktreePath: string;
5
5
  }>;
6
6
  declare function listWorktreePaths(commonDirectory: string): Promise<Map<string, string>>;
7
7
  export { fetchGitContext, listWorktreePaths };
package/dist/git.js CHANGED
@@ -17,17 +17,17 @@ async function fetchGitContext() {
17
17
  '--git-common-dir',
18
18
  '--absolute-git-dir'
19
19
  ]);
20
- const [worktreePath, commonPath, gitPath] = stdout.split(/\r?\n/u);
21
- if (!worktreePath || !commonPath || !gitPath) throw new Error('Missing Git paths.');
22
- const [worktree, commonDirectory, gitDirectory] = await Promise.all([
23
- realpath(worktreePath),
20
+ const [rootPath, commonPath, gitPath] = stdout.split(/\r?\n/u);
21
+ if (!rootPath || !commonPath || !gitPath) throw new Error('Missing Git paths.');
22
+ const [worktreePath, commonDirectory, gitDirectory] = await Promise.all([
23
+ realpath(rootPath),
24
24
  realpath(commonPath),
25
25
  realpath(gitPath)
26
26
  ]);
27
27
  return {
28
28
  commonDirectory,
29
- worktree,
30
- worktreeId: getWorktreeId(commonDirectory, gitDirectory)
29
+ worktreeId: getWorktreeId(commonDirectory, gitDirectory),
30
+ worktreePath
31
31
  };
32
32
  } catch (error) {
33
33
  throw new PortoError('worktreeNotFound', void 0, {
@@ -35,10 +35,10 @@ async function fetchGitContext() {
35
35
  });
36
36
  }
37
37
  }
38
- async function fetchLinkedWorktreeId(commonDirectory, worktree) {
39
- const gitLink = await readFile(node_path.join(worktree, '.git'), 'utf8');
38
+ async function fetchLinkedWorktreeId(commonDirectory, worktreePath) {
39
+ const gitLink = await readFile(node_path.join(worktreePath, '.git'), 'utf8');
40
40
  const gitPath = /^gitdir: (?<gitPath>.+)\r?\n?$/u.exec(gitLink)?.groups?.['gitPath'];
41
- return gitPath && getWorktreeId(commonDirectory, await realpath(node_path.resolve(worktree, gitPath)));
41
+ return gitPath && getWorktreeId(commonDirectory, await realpath(node_path.resolve(worktreePath, gitPath)));
42
42
  }
43
43
  async function listWorktreePaths(commonDirectory) {
44
44
  const { stdout } = await execFileAsync('git', [
@@ -52,9 +52,9 @@ async function listWorktreePaths(commonDirectory) {
52
52
  const [location, ...flags] = entry.split('\0');
53
53
  if (!location?.startsWith('worktree ') || flags.some((flag)=>'bare' === flag || flag.startsWith('prunable '))) return;
54
54
  try {
55
- const worktree = await realpath(location.slice(9));
56
- const worktreeId = 0 === index ? '.' : await fetchLinkedWorktreeId(commonDirectory, worktree);
57
- if (worktreeId) worktreePathsById.set(worktreeId, worktree);
55
+ const worktreePath = await realpath(location.slice(9));
56
+ const worktreeId = 0 === index ? '.' : await fetchLinkedWorktreeId(commonDirectory, worktreePath);
57
+ if (worktreeId) worktreePathsById.set(worktreeId, worktreePath);
58
58
  } catch (error) {
59
59
  if (!checkIsFileMissing(error)) throw error;
60
60
  }
package/dist/index.d.ts CHANGED
@@ -1,45 +1,120 @@
1
1
  import type { ReservationRecord } from './registry.js';
2
- import { buildBlock } from './ports.js';
3
- type PortBlock = ReturnType<typeof buildBlock>;
2
+ import { buildSlot } from './ports.js';
3
+ type PortSlot = ReturnType<typeof buildSlot<ReservationRecord>>;
4
4
  type ReservationStats = Omit<ReservationRecord, 'worktreeId'> & {
5
- end: number;
5
+ index: number;
6
6
  isExpired: boolean;
7
7
  };
8
- declare function cleanup(): Promise<{
9
- end: number;
8
+ declare function cleanupSlots(): Promise<({
9
+ env: boolean;
10
+ envFile: string;
11
+ jsonFile: string | false;
12
+ silent: boolean;
13
+ expiresAt: string | null;
14
+ firstPort: number;
15
+ host?: string | undefined;
16
+ idleTtlMinutes: number;
17
+ keep: boolean;
18
+ lastPort: number;
19
+ lastUsedAt: string;
20
+ ports: number[];
21
+ vars: {
22
+ PORTO_SLOT: number;
23
+ };
24
+ worktreeId: string;
25
+ worktreePath: string;
26
+ } & {
10
27
  getPort(offset?: number): number;
11
28
  index: number;
12
- start: number;
13
- }[]>;
14
- declare function current(): Promise<{
15
- end: number;
16
- getPort(offset?: number): number;
29
+ })[]>;
30
+ declare function getAllSlots(): Promise<{
17
31
  index: number;
18
- start: number;
32
+ isExpired: boolean;
33
+ worktreePath: string;
34
+ env: boolean;
35
+ envFile: string;
36
+ jsonFile: string | false;
37
+ silent: boolean;
38
+ expiresAt: string | null;
39
+ firstPort: number;
40
+ host?: string | undefined;
41
+ idleTtlMinutes: number;
42
+ keep: boolean;
43
+ lastPort: number;
44
+ lastUsedAt: string;
45
+ ports: number[];
46
+ vars: {
47
+ PORTO_SLOT: number;
48
+ };
19
49
  }[]>;
20
- declare function release(): Promise<({
21
- end: number;
50
+ declare function getSlot(slotIndex?: number): Promise<({
51
+ env: boolean;
52
+ envFile: string;
53
+ jsonFile: string | false;
54
+ silent: boolean;
55
+ expiresAt: string | null;
56
+ firstPort: number;
57
+ host?: string | undefined;
58
+ idleTtlMinutes: number;
59
+ keep: boolean;
60
+ lastPort: number;
61
+ lastUsedAt: string;
62
+ ports: number[];
63
+ vars: {
64
+ PORTO_SLOT: number;
65
+ };
66
+ worktreeId: string;
67
+ worktreePath: string;
68
+ } & {
22
69
  getPort(offset?: number): number;
23
70
  index: number;
24
- start: number;
25
- } & {
71
+ }) | undefined>;
72
+ declare function releaseAllSlots(): Promise<({
73
+ env: boolean;
74
+ envFile: string;
75
+ jsonFile: string | false;
76
+ silent: boolean;
77
+ expiresAt: string | null;
78
+ firstPort: number;
79
+ host?: string | undefined;
80
+ idleTtlMinutes: number;
81
+ keep: boolean;
82
+ lastPort: number;
83
+ lastUsedAt: string;
26
84
  ports: number[];
27
- })[]>;
28
- declare function stats(): Promise<{
85
+ vars: {
86
+ PORTO_SLOT: number;
87
+ };
88
+ worktreeId: string;
89
+ worktreePath: string;
90
+ } & {
91
+ getPort(offset?: number): number;
29
92
  index: number;
30
- lastUsedAt: string;
31
- ports: Array<number>;
32
- end: number;
33
- isExpired: boolean;
34
- start: number;
35
- worktree: string;
93
+ })[]>;
94
+ declare function releaseSlot(slotIndex?: number): Promise<({
95
+ env: boolean;
96
+ envFile: string;
97
+ jsonFile: string | false;
98
+ silent: boolean;
99
+ expiresAt: string | null;
100
+ firstPort: number;
36
101
  host?: string | undefined;
37
102
  idleTtlMinutes: number;
38
103
  keep: boolean;
39
- size: number;
40
- }[]>;
41
- export { cleanup, current, release, stats };
42
- export type { PortBlock, ReservationStats };
104
+ lastPort: number;
105
+ lastUsedAt: string;
106
+ ports: number[];
107
+ vars: {
108
+ PORTO_SLOT: number;
109
+ };
110
+ worktreeId: string;
111
+ worktreePath: string;
112
+ } & {
113
+ getPort(offset?: number): number;
114
+ index: number;
115
+ }) | undefined>;
116
+ export { cleanupSlots, getAllSlots, getSlot, releaseAllSlots, releaseSlot };
117
+ export type { PortSlot, ReservationStats };
43
118
  export { BusyPortsError } from './busy-ports-error.js';
44
119
  export { defineConfig } from './config.js';
45
120
  export type { PortoConfig } from './config.js';
package/dist/index.js CHANGED
@@ -1,57 +1,58 @@
1
- import { remove, sortBy } from "es-toolkit";
2
- import { BusyPortsError } from "./busy-ports-error.js";
1
+ import { PortoError } from "./error.js";
3
2
  import { fetchGitContext, listWorktreePaths } from "./git.js";
4
- import { buildBlock, listBusyPorts } from "./ports.js";
3
+ import { buildSlot } from "./ports.js";
5
4
  import { updateRegistry } from "./registry.js";
6
- import { checkIsExpired, removeExpiredRecords, reserve } from "./reserve.js";
7
- async function cleanup() {
5
+ import { checkIsExpired, releaseRecord, removeExpiredRecords, reserve } from "./reserve.js";
6
+ async function cleanupSlots() {
8
7
  const { commonDirectory } = await fetchGitContext();
9
- return updateRegistry(commonDirectory, (records)=>removeExpiredRecords(records, Date.now()));
8
+ return updateRegistry(commonDirectory, (registry)=>removeExpiredRecords(registry, Date.now()));
10
9
  }
11
- async function current() {
12
- const { commonDirectory, worktreeId } = await fetchGitContext();
13
- return updateRegistry(commonDirectory, (records)=>records.filter((record)=>record.worktreeId === worktreeId).map((record)=>buildBlock(record)));
10
+ async function getAllSlots() {
11
+ const { commonDirectory } = await fetchGitContext();
12
+ const worktreePathsById = await listWorktreePaths(commonDirectory);
13
+ return updateRegistry(commonDirectory, ({ slots })=>{
14
+ const now = Date.now();
15
+ return slots.flatMap((record, index)=>{
16
+ if (null === record) return [];
17
+ const { worktreeId, ...settings } = record;
18
+ const worktreePath = worktreePathsById.get(worktreeId) ?? record.worktreePath;
19
+ return [
20
+ {
21
+ ...settings,
22
+ index,
23
+ isExpired: checkIsExpired(record, now),
24
+ worktreePath
25
+ }
26
+ ];
27
+ });
28
+ });
14
29
  }
15
- async function release() {
30
+ async function getSlot(slotIndex) {
31
+ if (void 0 !== slotIndex && (!Number.isSafeInteger(slotIndex) || slotIndex < 0)) throw new PortoError('slotIndexInvalid');
16
32
  const { commonDirectory, worktreeId } = await fetchGitContext();
17
- return updateRegistry(commonDirectory, async (records)=>{
18
- const currentRecords = records.filter((record)=>record.worktreeId === worktreeId);
19
- const portsByRecord = await Promise.all(currentRecords.map(async (record)=>{
20
- const block = buildBlock(record);
21
- const ports = await listBusyPorts(block.start, block.end, {
22
- host: record.host
23
- });
24
- return ports.map((port)=>({
25
- block: block.index,
26
- port
27
- }));
28
- }));
29
- const busyPorts = portsByRecord.flat();
30
- if (busyPorts.length > 0) throw new BusyPortsError(busyPorts);
31
- remove(records, (record)=>record.worktreeId === worktreeId);
32
- return currentRecords.map((record)=>Object.assign(buildBlock(record), {
33
- ports: record.ports
34
- }));
33
+ return updateRegistry(commonDirectory, ({ slots })=>{
34
+ const index = slotIndex ?? slots.findIndex((record)=>record?.worktreeId === worktreeId);
35
+ const record = slots[index];
36
+ return record ? buildSlot(record, index) : void 0;
35
37
  });
36
38
  }
37
- async function stats() {
39
+ async function releaseAllSlots() {
38
40
  const { commonDirectory } = await fetchGitContext();
39
- const worktreePathsById = await listWorktreePaths(commonDirectory);
40
- return updateRegistry(commonDirectory, (records)=>sortBy(records.map(({ worktreeId, ...record })=>{
41
- const { end, start } = buildBlock(record);
42
- const worktree = worktreePathsById.get(worktreeId) ?? record.worktree;
43
- return {
44
- ...record,
45
- end,
46
- isExpired: checkIsExpired(record, Date.now()),
47
- start,
48
- worktree
49
- };
50
- }), [
51
- 'start',
52
- 'worktree'
53
- ]));
41
+ return updateRegistry(commonDirectory, async (registry)=>{
42
+ const releasedSlots = [];
43
+ for (const [index, record] of registry.slots.entries())if (null !== record) releasedSlots.push(await releaseRecord(registry, index, record));
44
+ return releasedSlots;
45
+ });
46
+ }
47
+ async function releaseSlot(slotIndex) {
48
+ if (void 0 !== slotIndex && (!Number.isSafeInteger(slotIndex) || slotIndex < 0)) throw new PortoError('slotIndexInvalid');
49
+ const { commonDirectory, worktreeId } = await fetchGitContext();
50
+ return updateRegistry(commonDirectory, (registry)=>{
51
+ const index = slotIndex ?? registry.slots.findIndex((record)=>record?.worktreeId === worktreeId);
52
+ const record = registry.slots[index];
53
+ return record ? releaseRecord(registry, index, record) : void 0;
54
+ });
54
55
  }
56
+ export { BusyPortsError } from "./busy-ports-error.js";
55
57
  export { defineConfig } from "./config.js";
56
- export { PortoError } from "./error.js";
57
- export { BusyPortsError, cleanup, current, release, reserve, stats };
58
+ export { PortoError, cleanupSlots, getAllSlots, getSlot, releaseAllSlots, releaseSlot, reserve };
package/dist/output.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { PortBlock, ReservationStats } from './index.js';
1
+ import type { PortSlot, ReservationStats } from './index.js';
2
2
  type Environment = Record<string, number | string>;
3
3
  declare function fetchExportPaths(settings: {
4
4
  env: boolean;
@@ -9,10 +9,10 @@ declare function fetchExportPaths(settings: {
9
9
  jsonPath: string | undefined;
10
10
  }>;
11
11
  declare function formatEnvironment(environment: Environment): string;
12
- declare function formatReserveOutput(block: PortBlock, environment: Environment | undefined, isJson: boolean): string;
12
+ declare function formatReserveOutput(slot: PortSlot, environment: Environment | undefined, isJson: boolean): string;
13
13
  declare function formatTable(headers: Array<string>, rows: Array<Array<string>>): string;
14
14
  declare function formatStatsTable(reservations: Array<ReservationStats>): string;
15
15
  declare function updateEnvironmentFile(filePath: string, environment: Environment, commonDirectory?: string): Promise<void>;
16
- declare function writeReserveJsonFile(filePath: string, block: PortBlock, environment: Environment | undefined): Promise<void>;
16
+ declare function writeReserveJsonFile(filePath: string, slot: PortSlot, environment: Environment | undefined): Promise<void>;
17
17
  export { fetchExportPaths, formatEnvironment, formatReserveOutput, formatStatsTable, formatTable, updateEnvironmentFile, writeReserveJsonFile, };
18
18
  export type { Environment };