Skip to content

Commit 02913b2

Browse files
committed
update: add deno.lock
1 parent 1e7bbb7 commit 02913b2

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
// Import Node.js Dependencies
22
import fs from "node:fs";
3-
import path from "node:path";
43

5-
export const LOCK_FILES = {
6-
npm: "package-lock.json",
7-
bun: "bun.lockb",
8-
yarn: "yarn.lock",
9-
pnpm: "pnpm-lock.yaml"
10-
};
4+
export const LOCK_FILES = [
5+
["npm", "package-lock.json"],
6+
["bun", "bun.lockb"],
7+
["pnpm", "pnpm-lock.yaml"],
8+
["yarn", "yarn.lock"],
9+
["deno", "deno.lock"]
10+
];
1111

1212
export function scanLockFiles(dirPath: string): null | object {
13-
const result: { [k: string]: string; } = {};
14-
for (const [k, v] of Object.entries(LOCK_FILES)) {
15-
const filePath = path.join(dirPath, v);
16-
if (fs.existsSync(filePath)) {
17-
result[k] = filePath;
18-
}
13+
const dir = fs.readdirSync(dirPath);
14+
if (dir.length === 0) {
15+
return null;
1916
}
2017

21-
const isEmpty = Object.keys(result).length === 0;
18+
const result: [string, string][] = [];
19+
for (const [k, v] of LOCK_FILES) {
20+
if (dir.includes(v)) {
21+
result.push([k, v]);
22+
}
23+
}
2224

23-
return isEmpty ? null : result;
25+
return result.length === 0 ? null : result;
2426
}

workspaces/mama/test/scan-lockfiles.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import { scanLockFiles, LOCK_FILES } from "../src/index.ts";
1010

1111
describe("scanLockFiles", () => {
1212
test("should scan lock files", () => {
13-
const output: typeof LOCK_FILES = {} as typeof LOCK_FILES;
13+
const output: [string, string][] = [];
1414
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "/"));
1515

16-
for (const [k, v] of Object.entries(LOCK_FILES)) {
16+
for (const [k, v] of LOCK_FILES) {
1717
const filepath = path.join(tmpDir, v);
1818

1919
fs.writeFileSync(filepath, "");
20-
output[k as keyof typeof LOCK_FILES] = filepath;
20+
output.push([k, v]);
2121
}
2222

2323
assert.deepEqual(scanLockFiles(tmpDir), output);

0 commit comments

Comments
 (0)