Skip to content

Commit

Permalink
fix bin
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Dec 8, 2024
1 parent 815eb45 commit 74f08a4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"port"
],
"bin": {
"detect": "bin/detect-port.cjs",
"detect-port": "bin/detect-port.cjs"
"detect": "dist/commonjs/bin/detect-port.js",
"detect-port": "dist/commonjs//detect-port.js"
},
"main": "./dist/commonjs/index.js",
"files": [
Expand Down Expand Up @@ -37,10 +37,12 @@
"typescript": "^5.2.2"
},
"scripts": {
"test": "npm run lint -- --fix && egg-bin test",
"pretest": "npm run lint -- --fix && npm run prepublishOnly",
"test": "egg-bin test",
"lint": "eslint src test --ext ts",
"ci": "npm run lint && npm run cov && npm run prepublishOnly",
"prepublishOnly": "tshy && tshy-after",
"precov": "npm run prepublishOnly",
"cov": "egg-bin cov"
},
"engines": {
Expand Down
11 changes: 5 additions & 6 deletions bin/detect-port.cjs → src/bin/detect-port.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/usr/bin/env node

const path = require('node:path');
const { readFileSync } = require('node:fs');
const { detectPort } = require('../');
import path from 'node:path';
import { readFileSync } from 'node:fs';
import detectPort from '../detect-port.js';

const pkgFile = path.join(__dirname, '../package.json');
const pkgFile = path.join(__dirname, '../../../package.json');
const pkg = JSON.parse(readFileSync(pkgFile, 'utf-8'));

const args = process.argv.slice(2);
let arg_0 = args[0];

if (arg_0 && [ '-v', '--version' ].includes(arg_0.toLowerCase())) {
console.log(pkg.version);

process.exit(0);
}

const removeByValue = (arr, val) => {
const removeByValue = (arr: string[], val: string) => {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === val) {
arr.splice(i, 1);
Expand Down
4 changes: 2 additions & 2 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const __dirname = path.dirname(__filename);
const pkgFile = path.join(__dirname, '../package.json');
const pkg = JSON.parse(readFileSync(pkgFile, 'utf-8'));

describe.skip('test/cli.test.ts', async () => {
const binFile = path.join(__dirname, '../bin/detect-port.cjs');
describe('test/cli.test.ts', async () => {
const binFile = path.join(__dirname, '../dist/commonjs/bin/detect-port.js');

it('should show version', async () => {
let res = await execaNode(binFile, [ '-v' ]);
Expand Down
7 changes: 3 additions & 4 deletions test/detect-port.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,17 @@ describe('test/detect-port.test.ts', () => {
assert.equal(realPort, 24001);
});

it('work with listening next port 24001 because 24000 was listened to ' + ip(), async () => {
it('work with listening next port 24001 because 24000 was listened', async () => {
const port = 24000;
const realPort = await detectPort(port);

assert(realPort === 24001);
assert.equal(realPort, 24001);
});

it('work with listening next port 28081 because 28080 was listened to 0.0.0.0:28080', async () => {
const port = 28080;
const realPort = await detectPort(port);

assert(realPort === 28081);
assert.equal(realPort, 28081);
});

it('work with listening random port when try port hit maxPort', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/wait-port.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('test/wait-port.test.ts', () => {
try {
const port = 9093;
await waitPort(port, { retries: 3, retryInterval: 100 });
} catch (err:any) {
} catch (err: any) {
assert.equal(err.message, 'retries exceeded');
}
});
Expand Down

0 comments on commit 74f08a4

Please sign in to comment.