Skip to content

Commit f32b201

Browse files
committed
init
1 parent 613f39a commit f32b201

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
lines changed

bun.lock

Lines changed: 40 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"fs-extra": "8",
4949
"gradle-to-js": "^2.0.1",
5050
"i18next": "^24.2.2",
51+
"isomorphic-git": "^1.29.0",
5152
"isomorphic-unzip": "^1.1.5",
5253
"node-fetch": "^2.6.1",
5354
"plist": "^3.1.0",

src/utils/dep-versions.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import currentPackage from '../../package.json';
4+
5+
const packages = fs.readdirSync(path.join(__dirname, 'node_modules'));
6+
const exclude = ['.bin', '.cache'];
7+
8+
const depKeys = Object.keys(currentPackage.dependencies);
9+
const devDepKeys = Object.keys(currentPackage.devDependencies);
10+
const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])];
11+
12+
const versions = {};
13+
14+
for (const package of dedupedDeps) {
15+
try {
16+
const packageDir = path.resolve(__dirname, 'node_modules', current);
17+
const { name, version } = require(`${packageDir}/package.json`);
18+
if (depKeys.includes(name)) {
19+
return Object.assign(acc, {
20+
dependencies: Object.assign(acc.dependencies, { [name]: version }),
21+
});
22+
} else {
23+
return Object.assign(acc, {
24+
devDependencies: Object.assign(acc.devDependencies, {
25+
[name]: version,
26+
}),
27+
});
28+
}
29+
} catch (e) {
30+
// noop
31+
console.log(e);
32+
return acc;
33+
}
34+
}

src/utils/lock-checker.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const lockFiles = [
2+
'package-lock.json',
3+
'yarn.lock',
4+
'pnpm-lock.yaml',
5+
'bun.lockb',
6+
'bun.lock',
7+
];
8+
9+
const lockNotFound = `
10+
没有检测到任何 lock 文件,这可能导致依赖关系不一致而使热更异常。
11+
`;
12+
13+
const multipleLocksFound = `
14+
检测到多个锁文件(),这可能导致依赖关系不一致而使热更异常。
15+
`;
16+
17+
18+
const lockBestPractice = `
19+
关于 lock 文件的最佳实践:
20+
1. 开发团队中的所有成员应该使用相同的包管理器,维护同一份 lock 文件。
21+
2. 将 lock 文件添加到版本控制中(但不要同时提交多种不同格式的 lock 文件)。
22+
3. 代码审核时应关注 lock 文件的变化。
23+
这样可以最大限度避免因依赖关系不一致而导致的热更异常,也降低供应链攻击等安全隐患。
24+
`;

0 commit comments

Comments
 (0)