Skip to content

Commit

Permalink
Refactor: don't look for binaries using fs & walk (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Sep 21, 2024
1 parent c73553f commit 99e0e1c
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 200 deletions.
23 changes: 1 addition & 22 deletions packages/chdman-darwin-arm64/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath: string, fileName: string): string | undefined {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}

const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}

return undefined;
}

export default scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'chdman',
);
export default path.join(url.fileURLToPath(new URL('.', import.meta.url)), 'chdman');
5 changes: 2 additions & 3 deletions packages/chdman-darwin-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"type": "module",
"files": [
"dist",
"!**/*.tsbuildinfo",
"chdman"
"!**/*.tsbuildinfo"
],
"main": "dist/index.js",
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsc --build --verbose",
"build": "tsc --build --verbose && cp chdman* dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "npm run build && cp -f ../../LICENSE ../../README.md ./",
Expand Down
23 changes: 1 addition & 22 deletions packages/chdman-darwin-x64/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath: string, fileName: string): string | undefined {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}

const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}

return undefined;
}

export default scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'chdman',
);
export default path.join(url.fileURLToPath(new URL('.', import.meta.url)), 'chdman');
5 changes: 2 additions & 3 deletions packages/chdman-darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"type": "module",
"files": [
"dist",
"!**/*.tsbuildinfo",
"chdman"
"!**/*.tsbuildinfo"
],
"main": "dist/index.js",
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsc --build --verbose",
"build": "tsc --build --verbose && cp chdman* dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "npm run build && cp -f ../../LICENSE ../../README.md ./",
Expand Down
23 changes: 1 addition & 22 deletions packages/chdman-linux-arm/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath: string, fileName: string): string | undefined {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}

const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}

return undefined;
}

export default scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'chdman',
);
export default path.join(url.fileURLToPath(new URL('.', import.meta.url)), 'chdman');
5 changes: 2 additions & 3 deletions packages/chdman-linux-arm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"type": "module",
"files": [
"dist",
"!**/*.tsbuildinfo",
"chdman"
"!**/*.tsbuildinfo"
],
"main": "dist/index.js",
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsc --build --verbose",
"build": "tsc --build --verbose && cp chdman* dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "npm run build && cp -f ../../LICENSE ../../README.md ./",
Expand Down
23 changes: 1 addition & 22 deletions packages/chdman-linux-arm64/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath: string, fileName: string): string | undefined {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}

const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}

return undefined;
}

export default scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'chdman',
);
export default path.join(url.fileURLToPath(new URL('.', import.meta.url)), 'chdman');
5 changes: 2 additions & 3 deletions packages/chdman-linux-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"type": "module",
"files": [
"dist",
"!**/*.tsbuildinfo",
"chdman"
"!**/*.tsbuildinfo"
],
"main": "dist/index.js",
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsc --build --verbose",
"build": "tsc --build --verbose && cp chdman* dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "npm run build && cp -f ../../LICENSE ../../README.md ./",
Expand Down
23 changes: 1 addition & 22 deletions packages/chdman-linux-ia32/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath: string, fileName: string): string | undefined {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}

const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}

return undefined;
}

export default scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'chdman',
);
export default path.join(url.fileURLToPath(new URL('.', import.meta.url)), 'chdman');
5 changes: 2 additions & 3 deletions packages/chdman-linux-ia32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"type": "module",
"files": [
"dist",
"!**/*.tsbuildinfo",
"chdman"
"!**/*.tsbuildinfo"
],
"main": "dist/index.js",
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsc --build --verbose",
"build": "tsc --build --verbose && cp chdman* dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "npm run build && cp -f ../../LICENSE ../../README.md ./",
Expand Down
23 changes: 1 addition & 22 deletions packages/chdman-linux-x64/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath: string, fileName: string): string | undefined {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}

const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}

return undefined;
}

export default scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'chdman',
);
export default path.join(url.fileURLToPath(new URL('.', import.meta.url)), 'chdman');
5 changes: 2 additions & 3 deletions packages/chdman-linux-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"type": "module",
"files": [
"dist",
"!**/*.tsbuildinfo",
"chdman"
"!**/*.tsbuildinfo"
],
"main": "dist/index.js",
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsc --build --verbose",
"build": "tsc --build --verbose && cp chdman* dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "npm run build && cp -f ../../LICENSE ../../README.md ./",
Expand Down
23 changes: 1 addition & 22 deletions packages/chdman-win32-ia32/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath: string, fileName: string): string | undefined {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}

const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}

return undefined;
}

export default scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'chdman.exe',
);
export default path.join(url.fileURLToPath(new URL('.', import.meta.url)), 'chdman.exe');
5 changes: 2 additions & 3 deletions packages/chdman-win32-ia32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"type": "module",
"files": [
"dist",
"!**/*.tsbuildinfo",
"chdman.exe"
"!**/*.tsbuildinfo"
],
"main": "dist/index.js",
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsc --build --verbose",
"build": "tsc --build --verbose && cp chdman* dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "npm run build && cp -f ../../LICENSE ../../README.md ./",
Expand Down
23 changes: 1 addition & 22 deletions packages/chdman-win32-x64/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

/**
* Search for a {@link fileName} in {@link filePath} or any of its parent directories.
*/
function scanUpPathForFile(filePath: string, fileName: string): string | undefined {
const fullPath = path.join(filePath, fileName);
if (fs.existsSync(fullPath)) {
return fullPath;
}

const parentPath = path.dirname(filePath);
if (parentPath !== filePath) {
return scanUpPathForFile(path.dirname(filePath), fileName);
}

return undefined;
}

export default scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'chdman.exe',
);
export default path.join(url.fileURLToPath(new URL('.', import.meta.url)), 'chdman.exe');
5 changes: 2 additions & 3 deletions packages/chdman-win32-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"type": "module",
"files": [
"dist",
"!**/*.tsbuildinfo",
"chdman.exe"
"!**/*.tsbuildinfo"
],
"main": "dist/index.js",
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsc --build --verbose",
"build": "tsc --build --verbose && cp chdman* dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "npm run build && cp -f ../../LICENSE ../../README.md ./",
Expand Down

0 comments on commit 99e0e1c

Please sign in to comment.