commit-pack 1.0.16 → 1.0.18
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/README.md +1 -1
- package/bin/index.mjs +22 -7
- package/lib/index.mjs +19 -8
- package/package.json +1 -1
package/README.md
CHANGED
package/bin/index.mjs
CHANGED
|
@@ -8,28 +8,43 @@ import { execSync } from 'child_process'
|
|
|
8
8
|
import path from 'path'
|
|
9
9
|
import { fileURLToPath } from 'url'
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// 模拟 CommonJS 的 __dirname
|
|
12
12
|
const __filename = fileURLToPath(import.meta.url)
|
|
13
13
|
const __dirname = path.dirname(__filename)
|
|
14
14
|
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
// 向上查找带锁文件的根目录
|
|
16
|
+
function findProjectRootWithLockFile() {
|
|
17
|
+
let dir = __dirname
|
|
18
|
+
const lockFiles = ['bun.lockb', 'pnpm-lock.yaml', 'yarn.lock', 'package-lock.json']
|
|
19
|
+
|
|
20
|
+
while (dir !== path.dirname(dir)) {
|
|
21
|
+
for (const file of lockFiles) {
|
|
22
|
+
if (fs.existsSync(path.join(dir, file))) {
|
|
23
|
+
return dir
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
dir = path.dirname(dir)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return process.cwd() // fallback
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const projectRoot = findProjectRootWithLockFile()
|
|
33
|
+
console.log(chalk.green(`检测到项目根目录:${projectRoot}`))
|
|
18
34
|
|
|
19
|
-
// 检测包管理器
|
|
20
35
|
function detectPackageManager() {
|
|
21
36
|
if (fs.existsSync(path.join(projectRoot, 'pnpm-lock.yaml'))) {
|
|
22
37
|
return 'pnpm'
|
|
23
38
|
} else if (fs.existsSync(path.join(projectRoot, 'yarn.lock'))) {
|
|
24
39
|
return 'yarn'
|
|
25
|
-
} else if (fs.existsSync(path.join(projectRoot, 'bun.
|
|
40
|
+
} else if (fs.existsSync(path.join(projectRoot, 'bun.lock'))) {
|
|
26
41
|
return 'bun'
|
|
27
42
|
} else {
|
|
28
43
|
return 'npm'
|
|
29
44
|
}
|
|
30
45
|
}
|
|
31
46
|
|
|
32
|
-
console.log('执行 postinstall
|
|
47
|
+
console.log('执行 postinstall 脚本:bin/index.js')
|
|
33
48
|
|
|
34
49
|
const packageManager = detectPackageManager()
|
|
35
50
|
console.log(chalk.green(`检测到使用的包管理器:${packageManager}`))
|
package/lib/index.mjs
CHANGED
|
@@ -9,27 +9,38 @@ var _child_process = require("child_process");
|
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
var _url = require("url");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
//
|
|
12
|
+
// 模拟 CommonJS 的 __dirname
|
|
13
13
|
const _filename = (0, _url.fileURLToPath)(import.meta.url);
|
|
14
14
|
const _dirname = _path.default.dirname(_filename);
|
|
15
15
|
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
// 向上查找带锁文件的根目录
|
|
17
|
+
function findProjectRootWithLockFile() {
|
|
18
|
+
let dir = _dirname;
|
|
19
|
+
const lockFiles = ['bun.lockb', 'pnpm-lock.yaml', 'yarn.lock', 'package-lock.json'];
|
|
20
|
+
while (dir !== _path.default.dirname(dir)) {
|
|
21
|
+
for (const file of lockFiles) {
|
|
22
|
+
if (_fs.default.existsSync(_path.default.join(dir, file))) {
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
dir = _path.default.dirname(dir);
|
|
27
|
+
}
|
|
28
|
+
return process.cwd(); // fallback
|
|
29
|
+
}
|
|
30
|
+
const projectRoot = findProjectRootWithLockFile();
|
|
31
|
+
console.log(_chalk.default.green(`检测到项目根目录:${projectRoot}`));
|
|
21
32
|
function detectPackageManager() {
|
|
22
33
|
if (_fs.default.existsSync(_path.default.join(projectRoot, 'pnpm-lock.yaml'))) {
|
|
23
34
|
return 'pnpm';
|
|
24
35
|
} else if (_fs.default.existsSync(_path.default.join(projectRoot, 'yarn.lock'))) {
|
|
25
36
|
return 'yarn';
|
|
26
|
-
} else if (_fs.default.existsSync(_path.default.join(projectRoot, 'bun.
|
|
37
|
+
} else if (_fs.default.existsSync(_path.default.join(projectRoot, 'bun.lock'))) {
|
|
27
38
|
return 'bun';
|
|
28
39
|
} else {
|
|
29
40
|
return 'npm';
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
|
-
console.log('执行 postinstall
|
|
43
|
+
console.log('执行 postinstall 脚本:bin/index.js');
|
|
33
44
|
const packageManager = detectPackageManager();
|
|
34
45
|
console.log(_chalk.default.green(`检测到使用的包管理器:${packageManager}`));
|
|
35
46
|
const packageJsonPath = _path.default.join(projectRoot, 'package.json');
|