@nitwel/sandbox 1.0.4 → 1.0.5

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/cli.js CHANGED
@@ -16,8 +16,7 @@ program
16
16
  .option('--docker.suffix <suffix>', 'Adds a suffix to the docker project. Can be used to ensure uniqueness')
17
17
  .option('-e, --extras <extras>', 'Enable redis,maildev,saml or other extras')
18
18
  .option('--silent', 'Silence all logs except for errors')
19
- .option('-i, --instances <instances>', 'Horizontally scale directus to a given number of instances', '1')
20
- .option('--killPorts', 'Forcefully kills all processes that occupy ports that the api would use');
19
+ .option('-i, --instances <instances>', 'Horizontally scale directus to a given number of instances', '1');
21
20
  program.parse();
22
21
  const options = program.opts();
23
22
  const sb = await sandbox(program.args[0], {
package/dist/sandbox.d.ts CHANGED
@@ -40,8 +40,6 @@ export type Options = {
40
40
  schema: string | undefined;
41
41
  /** Start the api with debugger */
42
42
  inspect: boolean;
43
- /** Forcefully kills all processes that occupy ports that the api would use */
44
- killPorts: boolean;
45
43
  /** Enable redis,maildev,saml or other extras */
46
44
  extras: {
47
45
  /** Used for caching, forced to true if instances > 1 */
package/dist/sandbox.js CHANGED
@@ -30,7 +30,6 @@ async function getOptions(options) {
30
30
  schema: undefined,
31
31
  silent: false,
32
32
  export: false,
33
- killPorts: false,
34
33
  extras: {
35
34
  redis: false,
36
35
  maildev: false,
package/dist/steps/api.js CHANGED
@@ -4,8 +4,7 @@ import {} from '../config.js';
4
4
  import {} from '../logger.js';
5
5
  import { apiFolder } from '../sandbox.js';
6
6
  import chalk from 'chalk';
7
- import { portToPid } from 'pid-port';
8
- import { createInterface } from 'readline/promises';
7
+ import { detect } from 'detect-port';
9
8
  export async function buildDirectus(opts, logger, onRebuild) {
10
9
  const start = performance.now();
11
10
  logger.info('Rebuilding Directus');
@@ -71,33 +70,11 @@ export async function startDirectus(opts, env, logger) {
71
70
  const apiCount = Math.max(1, Number(opts.instances));
72
71
  const apiPorts = [...Array(apiCount).keys()].flatMap((i) => Number(env.PORT) + i * (opts.inspect ? 2 : 1));
73
72
  const allPorts = apiPorts.flatMap((port) => (opts.inspect ? [port, port + 1] : [port]));
74
- const occupiedPorts = (await Promise.allSettled(allPorts.map((port) => portToPid(port))))
73
+ const occupiedPorts = (await Promise.allSettled(allPorts.map((port) => detect(port))))
75
74
  .map((result, i) => (result.status === 'fulfilled' ? [result.value, allPorts[i]] : undefined))
76
- .filter((val) => val);
77
- let killPorts;
78
- for (const [pid, port] of occupiedPorts) {
79
- logger.warn(`Port ${port} is occupied by pid ${pid}`);
80
- }
81
- if (opts.killPorts) {
82
- killPorts = true;
83
- }
84
- else {
85
- if (occupiedPorts.length > 0) {
86
- const rl = createInterface({ input: process.stdin, output: process.stdout });
87
- const result = (await rl.question('Would you like to kill all occupying processes? (Y/N) ')).toLowerCase();
88
- killPorts = result === 'y' || result === 'yes';
89
- }
90
- }
91
- if (killPorts) {
92
- for (const [pid] of occupiedPorts) {
93
- try {
94
- process.kill(pid, 'SIGKILL');
95
- logger.info(`Killed process ${pid}`);
96
- }
97
- catch (err) {
98
- logger.error(`Failed to kill process ${pid}: ${err.message}`);
99
- }
100
- }
75
+ .filter((val) => val && val[0] !== val[1]);
76
+ for (const [port] of occupiedPorts) {
77
+ logger.warn(`Port ${port} is already occupied`);
101
78
  }
102
79
  return await Promise.all(apiPorts.map((port) => {
103
80
  const newLogger = apiCount > 1 ? logger.addGroup(`API ${port}`) : logger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitwel/sandbox",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Toolkit for spinning up directus test environments",
5
5
  "homepage": "https://directus.io",
6
6
  "exports": {
@@ -20,7 +20,7 @@
20
20
  "author": "Nils Twelker (nils@directus.io)",
21
21
  "license": "MIT",
22
22
  "private": false,
23
- "devDependencies": {
23
+ "dependencies": {
24
24
  "@directus/tsconfig": "3.0.0",
25
25
  "@directus/utils": "13.0.9",
26
26
  "@types/lodash-es": "4.17.12",
@@ -28,9 +28,9 @@
28
28
  "chalk": "5.4.1",
29
29
  "commander": "14.0.0",
30
30
  "copyfiles": "2.4.1",
31
+ "detect-port": "2.1.0",
31
32
  "get-port": "7.1.0",
32
33
  "lodash-es": "4.17.21",
33
- "pid-port": "1.0.2",
34
34
  "tsdown": "0.14.2",
35
35
  "tsx": "4.20.3",
36
36
  "typedoc": "0.28.12",