@build-script/package-tools 0.0.8 → 0.0.10
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/lib/commands/detect-package-change.d.ts +11 -1
- package/lib/commands/detect-package-change.d.ts.map +1 -1
- package/lib/commands/detect-package-change.js +48 -18
- package/lib/commands/detect-package-change.js.map +1 -1
- package/lib/commands/monorepo-list.d.ts +1 -1
- package/lib/commands/monorepo-list.d.ts.map +1 -1
- package/lib/commands/monorepo-list.js +4 -5
- package/lib/commands/monorepo-list.js.map +1 -1
- package/lib/commands/monorepo-publish.d.ts +4 -0
- package/lib/commands/monorepo-publish.d.ts.map +1 -1
- package/lib/commands/monorepo-publish.js +204 -88
- package/lib/commands/monorepo-publish.js.map +1 -1
- package/lib/commands/unshare-make-tarball.d.ts +19 -0
- package/lib/commands/unshare-make-tarball.d.ts.map +1 -0
- package/lib/commands/unshare-make-tarball.js +41 -0
- package/lib/commands/unshare-make-tarball.js.map +1 -0
- package/lib/commands.generated.d.ts +1 -0
- package/lib/commands.generated.d.ts.map +1 -1
- package/lib/commands.generated.js +38 -4
- package/lib/commands.generated.js.map +1 -1
- package/lib/common/cache/native.npm.d.ts +1 -0
- package/lib/common/cache/native.npm.d.ts.map +1 -1
- package/lib/common/cache/native.npm.js +8 -5
- package/lib/common/cache/native.npm.js.map +1 -1
- package/lib/common/functions/cli.d.ts +0 -1
- package/lib/common/functions/cli.d.ts.map +1 -1
- package/lib/common/functions/cli.js +0 -1
- package/lib/common/functions/cli.js.map +1 -1
- package/lib/common/package-manager/driver.abstract.d.ts +2 -2
- package/lib/common/package-manager/driver.abstract.d.ts.map +1 -1
- package/lib/common/package-manager/driver.abstract.js +10 -4
- package/lib/common/package-manager/driver.abstract.js.map +1 -1
- package/lib/common/package-manager/package-json.d.ts +1 -1
- package/lib/common/package-manager/package-json.d.ts.map +1 -1
- package/lib/common/shared-jobs/detect-change-job.d.ts +2 -1
- package/lib/common/shared-jobs/detect-change-job.d.ts.map +1 -1
- package/lib/common/shared-jobs/detect-change-job.js +7 -8
- package/lib/common/shared-jobs/detect-change-job.js.map +1 -1
- package/lib/common/taball/file-download.js +2 -2
- package/lib/common/taball/file-download.js.map +1 -1
- package/lib/common/version.generated.d.ts +1 -1
- package/lib/common/version.generated.d.ts.map +1 -1
- package/lib/common/version.generated.js +1 -1
- package/lib/common/version.generated.js.map +1 -1
- package/lib/main.d.ts.map +1 -1
- package/lib/main.js +11 -2
- package/lib/main.js.map +1 -1
- package/package.json +9 -24
- package/src/commands/detect-package-change.ts +53 -18
- package/src/commands/monorepo-list.ts +4 -5
- package/src/commands/monorepo-publish.ts +218 -103
- package/src/commands/unshare-make-tarball.ts +46 -0
- package/src/commands.generated.ts +38 -4
- package/src/common/cache/native.npm.ts +11 -6
- package/src/common/functions/cli.ts +0 -1
- package/src/common/package-manager/driver.abstract.ts +10 -5
- package/src/common/package-manager/package-json.ts +1 -1
- package/src/common/shared-jobs/detect-change-job.ts +8 -8
- package/src/common/taball/file-download.ts +2 -2
- package/src/common/version.generated.ts +1 -1
- package/src/main.ts +11 -2
- package/lib/common/functions/global-lifecycle.d.ts +0 -5
- package/lib/common/functions/global-lifecycle.d.ts.map +0 -1
- package/lib/common/functions/global-lifecycle.js +0 -34
- package/lib/common/functions/global-lifecycle.js.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/common/functions/global-lifecycle.ts +0 -40
package/lib/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAqB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEpE,MAAM,CAAC,MAAM,WAAW,GAAiB;IACxC,YAAY,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,kCAAkC,EAAE;IAC9E,YAAY,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,6BAA6B,EAAE;IACzE,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,mCAAmC,EAAE;
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAqB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,OAAO,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEpE,MAAM,CAAC,MAAM,WAAW,GAAiB;IACxC,YAAY,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,kCAAkC,EAAE;IAC9E,YAAY,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,6BAA6B,EAAE;IACzE,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,mCAAmC,EAAE;CAC9E,CAAC;AAEF,gBAAgB,CAAC,CAAC,CAAC,CAAC;AACpB,MAAM,eAAe,CAAC;IACrB,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC,WAAW;IAChC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE;CAC1C,CAAC;KACA,UAAU,CAAC,WAAW,CAAC;KACvB,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAEpC,0BAA0B;AAC1B,4BAA4B;AAC5B,+DAA+D"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@build-script/package-tools",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.10",
|
|
5
5
|
"description": "A Node.js package managing tool",
|
|
6
6
|
"bin": {
|
|
7
7
|
"package-tools": "./load.js",
|
|
@@ -21,32 +21,17 @@
|
|
|
21
21
|
"split-cmd": "^1.1.0",
|
|
22
22
|
"targz": "^1.0.1",
|
|
23
23
|
"tiny-async-pool": "^2.1.0",
|
|
24
|
-
"@build-script/monorepo-lib": "^0.0.
|
|
24
|
+
"@build-script/monorepo-lib": "^0.0.8",
|
|
25
|
+
"@idlebox/cli": "^0.0.3",
|
|
26
|
+
"@idlebox/common": "^1.5.0",
|
|
27
|
+
"@idlebox/dependency-graph": "^0.0.8",
|
|
25
28
|
"@idlebox/ensure-symlink": "^1.0.37",
|
|
26
|
-
"@idlebox/cli": "^0.0.1",
|
|
27
|
-
"@idlebox/dependency-graph": "^0.0.6",
|
|
28
|
-
"@idlebox/node": "^1.4.12",
|
|
29
|
-
"@idlebox/common": "^1.4.19",
|
|
30
29
|
"@idlebox/json-edit": "^0.0.5",
|
|
31
|
-
"@idlebox/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"@rushstack/heft": "^0.74.0",
|
|
35
|
-
"@types/cacache": "^19.0.0",
|
|
36
|
-
"@types/global-agent": "^3.0.0",
|
|
37
|
-
"@types/node": "^24.0.14",
|
|
38
|
-
"@types/npm-registry-fetch": "^8.0.8",
|
|
39
|
-
"@types/request": "^2.48.12",
|
|
40
|
-
"@types/semver": "^7.7.0",
|
|
41
|
-
"@types/targz": "^1.0.5",
|
|
42
|
-
"@types/tiny-async-pool": "^2.0.3",
|
|
43
|
-
"@types/tinycolor2": "^1.4.6",
|
|
44
|
-
"@build-script/codegen": "^1.0.7",
|
|
45
|
-
"@build-script/single-dog-asset": "^1.0.39",
|
|
46
|
-
"@internal/local-rig": "^1.0.1",
|
|
47
|
-
"@idlebox/cli-static-generator": "^0.0.1",
|
|
48
|
-
"@mpis/run": "^0.0.7"
|
|
30
|
+
"@idlebox/node": "^1.4.15",
|
|
31
|
+
"@idlebox/source-map-support": "^0.0.9",
|
|
32
|
+
"@idlebox/unshare": "^0.0.4"
|
|
49
33
|
},
|
|
34
|
+
"devDependencies": {},
|
|
50
35
|
"sideEffects": false,
|
|
51
36
|
"license": "MIT",
|
|
52
37
|
"author": "GongT <admin@gongt.me>",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createWorkspaceOrPackage } from '@build-script/monorepo-lib';
|
|
2
2
|
import { argv, CommandDefine, logger } from '@idlebox/cli';
|
|
3
|
+
import { isLinux, isPathContains, UsageError } from '@idlebox/common';
|
|
3
4
|
import { printLine } from '@idlebox/node';
|
|
4
|
-
import {
|
|
5
|
+
import { FsNodeType, unshareReadonlyFileSystem } from '@idlebox/unshare';
|
|
6
|
+
import { resolve } from 'path';
|
|
5
7
|
import { PackageManagerUsageKind } from '../common/package-manager/driver.abstract.js';
|
|
6
8
|
import { increaseVersion } from '../common/package-manager/package-json.js';
|
|
7
9
|
import { createPackageManager } from '../common/package-manager/package-manager.js';
|
|
@@ -14,16 +16,54 @@ export class Command extends CommandDefine {
|
|
|
14
16
|
protected override readonly _description = '本地运行npm pack并与npm上的最新版本对比差异';
|
|
15
17
|
protected override readonly _help = '';
|
|
16
18
|
protected override readonly _arguments = {
|
|
17
|
-
'--bump': { flag: true, description: '当发现更改时更新package.json,增加版本号0.0.1' },
|
|
19
|
+
'--bump': { usage: true, flag: true, description: '当发现更改时更新package.json,增加版本号0.0.1' },
|
|
20
|
+
'--json': { usage: true, flag: true, description: '输出JSON格式(不支持bump)' },
|
|
21
|
+
'--unshare': { flag: false, description: '[linux] 在虚拟环境中运行(不支持bump),传入参数为overlay根目录' },
|
|
18
22
|
};
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export async function main() {
|
|
22
|
-
const
|
|
26
|
+
const unshareFrom = argv.single(['--unshare']);
|
|
27
|
+
const autoInc = argv.flag(['--bump']) > 0;
|
|
28
|
+
const jsonOutput = argv.flag(['--json']) > 0 || !process.stdout.isTTY;
|
|
29
|
+
|
|
30
|
+
if (autoInc) {
|
|
31
|
+
if (jsonOutput) throw new UsageError(`--json和--dump不能同时使用`);
|
|
32
|
+
if (unshareFrom) throw new UsageError(`--unshare和--dump不能同时使用`);
|
|
33
|
+
}
|
|
23
34
|
|
|
24
35
|
const workspace = await createWorkspaceOrPackage();
|
|
25
36
|
const pm = await createPackageManager(PackageManagerUsageKind.Read, workspace);
|
|
26
37
|
|
|
38
|
+
if (unshareFrom && !process.env.DETECT_PKG_CHANGE_HAS_BEEN_UNSHARED) {
|
|
39
|
+
if (!isLinux) {
|
|
40
|
+
throw new UsageError(`--unshare 仅在Linux环境下支持`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const root = resolve(process.cwd(), unshareFrom);
|
|
44
|
+
if (!isPathContains(root, process.cwd(), true)) {
|
|
45
|
+
throw new UsageError(`--unshare 指定的目录必须是当前目录的父级或自身`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
logger.debug`unshare overlay long<${root}>`;
|
|
49
|
+
|
|
50
|
+
process.env.DETECT_PKG_CHANGE_HAS_BEEN_UNSHARED = '1';
|
|
51
|
+
process.env.NODE_OPTIONS = '1';
|
|
52
|
+
|
|
53
|
+
const cache = await pm.createCacheHandler();
|
|
54
|
+
|
|
55
|
+
unshareReadonlyFileSystem('10e25435-eae0-4c24-a3fd-ce5dee64b442', {
|
|
56
|
+
volumes: [
|
|
57
|
+
{ path: root, type: FsNodeType.volatile },
|
|
58
|
+
{ path: cache.path, type: FsNodeType.passthru },
|
|
59
|
+
],
|
|
60
|
+
verbose: logger.verbose.isEnabled,
|
|
61
|
+
// pid: true,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
throw new Error('unshare请求无法实现');
|
|
65
|
+
}
|
|
66
|
+
|
|
27
67
|
const pkgJson = await pm.loadPackageJson();
|
|
28
68
|
const { changedFiles, hasChange, remoteVersion } = await executeChangeDetect(pm, {});
|
|
29
69
|
|
|
@@ -38,22 +78,17 @@ export async function main() {
|
|
|
38
78
|
logger.log('没有检测到更改');
|
|
39
79
|
}
|
|
40
80
|
} else {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function printResult(changedFiles: string[], changed: boolean) {
|
|
47
|
-
if (process.stdout.isTTY && !isJsonOutput) {
|
|
48
|
-
if (changedFiles.length === 0) {
|
|
49
|
-
console.log('changes: no');
|
|
81
|
+
if (jsonOutput) {
|
|
82
|
+
console.log(JSON.stringify({ remoteVersion, changedFiles, changed: hasChange }));
|
|
50
83
|
} else {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
84
|
+
if (changedFiles.length === 0) {
|
|
85
|
+
console.log('changes: no');
|
|
86
|
+
} else {
|
|
87
|
+
printLine();
|
|
88
|
+
logger.log`list<${changedFiles}>`;
|
|
89
|
+
printLine();
|
|
90
|
+
console.log('changes: yes');
|
|
91
|
+
}
|
|
55
92
|
}
|
|
56
|
-
} else {
|
|
57
|
-
console.log(JSON.stringify({ changedFiles, changed }));
|
|
58
93
|
}
|
|
59
94
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { createWorkspace } from '@build-script/monorepo-lib';
|
|
2
|
-
import { argv, CommandDefine } from '@idlebox/cli';
|
|
3
|
-
import { isJsonOutput, isVerbose, pArgS } from '../common/functions/cli.js';
|
|
2
|
+
import { app, argv, CommandDefine } from '@idlebox/cli';
|
|
4
3
|
|
|
5
4
|
export class Command extends CommandDefine {
|
|
6
|
-
protected override readonly _usage =
|
|
5
|
+
protected override readonly _usage = ``;
|
|
7
6
|
protected override readonly _description = '列出所有项目目录';
|
|
8
7
|
protected override readonly _help = '';
|
|
9
8
|
protected override readonly _arguments = {
|
|
@@ -19,7 +18,7 @@ export async function main() {
|
|
|
19
18
|
|
|
20
19
|
const isRelative = argv.flag(['--relative']) > 0;
|
|
21
20
|
|
|
22
|
-
if (
|
|
21
|
+
if (argv.flag(['--json']) > 0) {
|
|
23
22
|
console.log(
|
|
24
23
|
JSON.stringify(
|
|
25
24
|
list.map((e) => {
|
|
@@ -32,7 +31,7 @@ export async function main() {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
for (const item of list) {
|
|
35
|
-
if (
|
|
34
|
+
if (app.verbose) {
|
|
36
35
|
console.log('name: %s', item.name);
|
|
37
36
|
console.log('path: %s', item.absolute);
|
|
38
37
|
console.log('relative: %s', item.relative);
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { createWorkspace, normalizePackageName, type IPackageInfo, type MonorepoWorkspace } from '@build-script/monorepo-lib';
|
|
2
|
-
import { argv, CommandDefine, CSI, logger } from '@idlebox/cli';
|
|
3
|
-
import {
|
|
4
|
-
import { Job, JobGraphBuilder } from '@idlebox/dependency-graph';
|
|
5
|
-
import { commandInPath, emptyDir, writeFileIfChange } from '@idlebox/node';
|
|
1
|
+
import { applyPublishWorkspace, createWorkspace, normalizePackageName, type IPackageInfo, type MonorepoWorkspace } from '@build-script/monorepo-lib';
|
|
2
|
+
import { app, argv, CommandDefine, CSI, logger } from '@idlebox/cli';
|
|
3
|
+
import { prettyPrintError } from '@idlebox/common';
|
|
4
|
+
import { Job, JobGraphBuilder, JobState } from '@idlebox/dependency-graph';
|
|
5
|
+
import { commandInPath, emptyDir, setExitCodeIfNot, shutdown, workingDirectory, writeFileIfChange } from '@idlebox/node';
|
|
6
|
+
import { FsNodeType, spawnReadonlyFileSystemWithCommand } from '@idlebox/unshare';
|
|
7
|
+
import { execaNode } from 'execa';
|
|
6
8
|
import { existsSync } from 'node:fs';
|
|
7
9
|
import { copyFile } from 'node:fs/promises';
|
|
8
|
-
import { resolve } from 'node:path';
|
|
10
|
+
import { dirname, relative, resolve } from 'node:path';
|
|
9
11
|
import { pArgS } from '../common/functions/cli.js';
|
|
10
|
-
import { PackageManagerUsageKind } from '../common/package-manager/driver.abstract.js';
|
|
12
|
+
import { PackageManagerUsageKind, type PackageManager } from '../common/package-manager/driver.abstract.js';
|
|
13
|
+
import { PNPM } from '../common/package-manager/driver.pnpm.js';
|
|
11
14
|
import { increaseVersion } from '../common/package-manager/package-json.js';
|
|
12
15
|
import { createPackageManager } from '../common/package-manager/package-manager.js';
|
|
13
16
|
import { clearNpmMetaCache } from '../common/shared-jobs/clear-cache.js';
|
|
@@ -21,98 +24,190 @@ export class Command extends CommandDefine {
|
|
|
21
24
|
protected override readonly _arguments = {
|
|
22
25
|
'--debug': { flag: true, description: '详细输出模式' },
|
|
23
26
|
'--dry': { flag: true, description: '仅检查修改,不发布(仍会修改version字段)' },
|
|
24
|
-
'--private': { flag:
|
|
27
|
+
'--private': { flag: true, description: '即使private=true也执行' },
|
|
28
|
+
'--concurrency': { flag: false, description: '并发数(默认5)' },
|
|
29
|
+
// '--no-unshare': { flag: true, description: '不执行unshare逻辑(在linux上默认执行)' },
|
|
25
30
|
};
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
interface IPayload {
|
|
29
|
-
readonly index: number;
|
|
30
|
-
readonly length: number;
|
|
31
|
-
readonly options: ReturnType<typeof options>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let indexDisplay = 0;
|
|
35
33
|
class BuildPackageJob extends Job<void> {
|
|
36
|
-
private readonly _onSuccess = new Emitter<void>();
|
|
37
|
-
public readonly onSuccess = this._onSuccess.event;
|
|
38
|
-
|
|
39
|
-
private readonly _onFailed = new Emitter<Error>();
|
|
40
|
-
public readonly onFailed = this._onFailed.event;
|
|
41
|
-
|
|
42
|
-
private readonly _onRunning = new Emitter<void>();
|
|
43
|
-
public readonly onRunning = this._onRunning.event;
|
|
44
|
-
|
|
45
34
|
private shouldPublish = '';
|
|
46
35
|
|
|
47
36
|
constructor(
|
|
48
37
|
name: string,
|
|
49
38
|
deps: readonly string[],
|
|
50
|
-
private readonly payload: IPayload,
|
|
51
39
|
private readonly project: IPackageInfo,
|
|
52
40
|
private readonly workspace: MonorepoWorkspace,
|
|
41
|
+
unshareExecuter: boolean,
|
|
53
42
|
) {
|
|
54
43
|
super(name, deps);
|
|
55
44
|
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const w = length.toFixed(0).length;
|
|
68
|
-
console.log(`${CSI}K📦 [${indexDisplay.toFixed(0).padStart(w)}/${length}] ${this.project.name}`);
|
|
69
|
-
console.log(this.logText.join('\n'));
|
|
70
|
-
prettyPrintError('❌pack failed', e);
|
|
71
|
-
this.logText.length = 0;
|
|
72
|
-
});
|
|
45
|
+
this.detect = unshareExecuter ? this.unsharedDetect : this.sharedDetect;
|
|
46
|
+
this.pack = unshareExecuter ? this.unsharedPack : this.sharedPack;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private readonly logText: string[] = [];
|
|
50
|
+
log(text: string) {
|
|
51
|
+
this.logText.push(text);
|
|
52
|
+
}
|
|
53
|
+
flushLog() {
|
|
54
|
+
console.log(this.logText.join('\n'));
|
|
55
|
+
this.logText.length = 0;
|
|
73
56
|
}
|
|
74
57
|
|
|
75
58
|
getPackagePath() {
|
|
76
59
|
return this.shouldPublish || undefined;
|
|
77
60
|
}
|
|
78
61
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.log(` 👀 ${changedFiles.length} 个文件有修改: ${changedFiles.slice(0, 3).join(', ')}${changedFiles.length > 3 ? ' ...' : ''}`);
|
|
89
|
-
if (hasChange) {
|
|
90
|
-
const packageJson = await pm.loadPackageJson();
|
|
91
|
-
localVersion = await increaseVersion(packageJson, remoteVersion || '0.0.0');
|
|
92
|
-
this.log(` ✍️ 已修改本地包版本: ${localVersion}`);
|
|
62
|
+
private readonly detect: typeof executeChangeDetect;
|
|
63
|
+
|
|
64
|
+
private async unsharedDetect() {
|
|
65
|
+
const exArgs = [];
|
|
66
|
+
if (app.verbose) {
|
|
67
|
+
exArgs.push('-dd');
|
|
68
|
+
} else {
|
|
69
|
+
exArgs.push('-d');
|
|
93
70
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
|
|
71
|
+
const promise = execaNode(process.argv[1], ['detect-package-change', '--unshare', this.workspace.root, ...exArgs], {
|
|
72
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
73
|
+
cwd: this.project.absolute,
|
|
74
|
+
encoding: 'utf8',
|
|
75
|
+
env: {
|
|
76
|
+
LOGGER_PREFIX: `package-change:${normalizePackageName(this.project.name, ':')}`,
|
|
77
|
+
// FORCE_COLOR: logger.colorEnabled ? '1' : '',
|
|
78
|
+
},
|
|
79
|
+
all: true,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
let result: Awaited<typeof promise>;
|
|
83
|
+
try {
|
|
84
|
+
result = await promise;
|
|
85
|
+
} catch (e: unknown) {
|
|
86
|
+
this.log(`${CSI}K${CSI}0;3;2m${(e as any).all}${CSI}0m`);
|
|
87
|
+
throw new Error(`子项目 ${this.project.name} 中运行修改检测失败(日志在上方)`);
|
|
98
88
|
}
|
|
99
89
|
|
|
100
|
-
|
|
90
|
+
try {
|
|
91
|
+
const { changedFiles, changed: hasChange, remoteVersion } = JSON.parse(result.stdout);
|
|
92
|
+
return { changedFiles, hasChange, remoteVersion };
|
|
93
|
+
} catch (e: any) {
|
|
94
|
+
this.log(result.stdout);
|
|
95
|
+
throw new Error(`子程序输出不是json: ${e.message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private async sharedDetect(pm: PackageManager) {
|
|
100
|
+
return await executeChangeDetect(pm, {});
|
|
101
|
+
}
|
|
101
102
|
|
|
102
|
-
|
|
103
|
-
this.shouldPublish = await pm.pack(tempFile);
|
|
103
|
+
private readonly pack: typeof this.sharedPack;
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
private async unsharedPack(_pm: PackageManager, tempFile: string) {
|
|
106
|
+
const exArgs = [];
|
|
107
|
+
if (app.verbose) {
|
|
108
|
+
exArgs.push('-dd');
|
|
107
109
|
} else {
|
|
108
|
-
|
|
110
|
+
exArgs.push('-d');
|
|
109
111
|
}
|
|
110
|
-
|
|
112
|
+
|
|
113
|
+
const promise = spawnReadonlyFileSystemWithCommand(
|
|
114
|
+
{
|
|
115
|
+
options: {
|
|
116
|
+
volumes: [
|
|
117
|
+
{ path: this.workspace.root, type: FsNodeType.readonly },
|
|
118
|
+
{ path: this.project.absolute, type: FsNodeType.passthru },
|
|
119
|
+
{ path: dirname(tempFile), type: FsNodeType.passthru },
|
|
120
|
+
],
|
|
121
|
+
verbose: true,
|
|
122
|
+
},
|
|
123
|
+
command: {
|
|
124
|
+
scriptFile: process.argv[1],
|
|
125
|
+
argv: ['unshare-make-tarball', '--output', tempFile, ...exArgs, '--project', this.project.name],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
stdin: 'ignore',
|
|
130
|
+
stdout: 'pipe',
|
|
131
|
+
stderr: 'pipe',
|
|
132
|
+
cwd: this.project.absolute,
|
|
133
|
+
encoding: 'utf8',
|
|
134
|
+
all: true,
|
|
135
|
+
env: {
|
|
136
|
+
LOGGER_PREFIX: `unshare-pack:${normalizePackageName(this.project.name, ':')}`,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
let result: Awaited<typeof promise>;
|
|
142
|
+
try {
|
|
143
|
+
result = await promise;
|
|
144
|
+
} catch (e: unknown) {
|
|
145
|
+
this.log(`${CSI}K${CSI}0;3;2m${(e as any).all}${CSI}0m`);
|
|
146
|
+
throw new Error(`子项目 ${this.project.name} 中运行修改检测失败(日志在上方)`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const filePath = result.stdout.trim();
|
|
150
|
+
if (!existsSync(filePath)) {
|
|
151
|
+
this.log(`${CSI}K${CSI}0;3;2m${result.all}${CSI}0m`);
|
|
152
|
+
throw new Error(`应该打包的文件不存在: ${filePath}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return filePath;
|
|
111
156
|
}
|
|
112
157
|
|
|
113
|
-
private
|
|
114
|
-
|
|
115
|
-
|
|
158
|
+
private async sharedPack(pm: PackageManager, tempFile: string) {
|
|
159
|
+
return await pm.pack(tempFile);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
protected override async _execute() {
|
|
163
|
+
this.setState(JobState.Running);
|
|
164
|
+
try {
|
|
165
|
+
this.log(` 🔍 ${CSI}38;5;14m检查包${CSI}0m`);
|
|
166
|
+
|
|
167
|
+
const pm = await createPackageManager(PackageManagerUsageKind.Write, this.workspace, this.project.absolute);
|
|
168
|
+
const { changedFiles, hasChange, remoteVersion, packageJsonDiff } = await this.detect(pm);
|
|
169
|
+
const shouldPublish = hasChange || changedFiles.length > 0;
|
|
170
|
+
let localVersion = this.project.packageJson.version;
|
|
171
|
+
|
|
172
|
+
if (process.env.CI && changedFiles.length) {
|
|
173
|
+
this.log(`::group:: 👀 ${changedFiles.length} 个文件有修改`);
|
|
174
|
+
for (const file of changedFiles) {
|
|
175
|
+
this.log(` * ${file}`);
|
|
176
|
+
if (file === 'package.json') {
|
|
177
|
+
this.log(`${packageJsonDiff}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
this.log(`::endgroup::`);
|
|
181
|
+
} else {
|
|
182
|
+
this.log(` 👀 ${changedFiles.length} 个文件有修改: ${changedFiles.slice(0, 3).join(', ')}${changedFiles.length > 3 ? ' ...' : ''}`);
|
|
183
|
+
}
|
|
184
|
+
if (hasChange) {
|
|
185
|
+
this.project.absolute;
|
|
186
|
+
const packageJson = await pm.loadPackageJson();
|
|
187
|
+
localVersion = await increaseVersion(packageJson, remoteVersion || '0.0.0');
|
|
188
|
+
this.log(` ✍️ 已修改本地包版本: ${localVersion}`);
|
|
189
|
+
}
|
|
190
|
+
if (!shouldPublish) {
|
|
191
|
+
this.log(` ✨ ${CSI}38;5;10m未发现修改${CSI}0m\n`);
|
|
192
|
+
this.setState(JobState.SuccessExited);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
this.log(` 🔄 打包文件`);
|
|
197
|
+
const tempFile = resolve(this.workspace.temp, `publish/${normalizePackageName(this.project.name)}-${localVersion}.tgz`);
|
|
198
|
+
this.shouldPublish = await this.pack(pm, tempFile);
|
|
199
|
+
this.log(` 📦 ${relative(this.workspace.root, this.shouldPublish)}`);
|
|
200
|
+
|
|
201
|
+
if (remoteVersion) {
|
|
202
|
+
this.log(` 🎈 即将发布新版本 "${localVersion}" 以更新远程版本 "${remoteVersion}"\n`);
|
|
203
|
+
} else {
|
|
204
|
+
this.log(` 🎈 即将发布初始版本 "${localVersion}"\n`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
this.setState(JobState.SuccessExited);
|
|
208
|
+
} catch (e: any) {
|
|
209
|
+
this.setState(JobState.ErrorExited, e);
|
|
210
|
+
}
|
|
116
211
|
}
|
|
117
212
|
}
|
|
118
213
|
|
|
@@ -124,18 +219,43 @@ function options() {
|
|
|
124
219
|
};
|
|
125
220
|
}
|
|
126
221
|
|
|
222
|
+
async function prepareTempFolder(temp: string, pm: PackageManager) {
|
|
223
|
+
await emptyDir(temp);
|
|
224
|
+
|
|
225
|
+
const npmrc = pm.workspace.getNpmRCPath(true);
|
|
226
|
+
if (existsSync(npmrc)) {
|
|
227
|
+
await copyFile(npmrc, resolve(temp, '.npmrc'));
|
|
228
|
+
} else {
|
|
229
|
+
logger.debug`npmrc文件不存在 (long<${npmrc}>)`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (pm instanceof PNPM) {
|
|
233
|
+
const workspaceFile = resolve(pm.workspace.root, 'pnpm-workspace.yaml');
|
|
234
|
+
await applyPublishWorkspace({
|
|
235
|
+
sourceFile: workspaceFile,
|
|
236
|
+
targetDir: temp,
|
|
237
|
+
isPublish: true,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
await writeFileIfChange(resolve(temp, 'package.json'), '{}');
|
|
242
|
+
}
|
|
243
|
+
|
|
127
244
|
export async function main() {
|
|
128
245
|
const workspace = await createWorkspace();
|
|
129
|
-
|
|
246
|
+
workingDirectory.chdir(workspace.root);
|
|
247
|
+
const zipDir = resolve(workspace.temp, 'publish');
|
|
130
248
|
|
|
131
|
-
|
|
132
|
-
await
|
|
249
|
+
await workspace.decoupleDependencies();
|
|
250
|
+
const pm = await createPackageManager(PackageManagerUsageKind.Write, workspace, zipDir);
|
|
251
|
+
await prepareTempFolder(zipDir, pm);
|
|
133
252
|
|
|
134
253
|
const projects = await workspace.listPackages();
|
|
135
254
|
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
|
|
255
|
+
let concurrency = Number.parseInt(argv.single(['--concurrency']) || '0') || 5;
|
|
256
|
+
if (app.debug) {
|
|
257
|
+
concurrency = 1;
|
|
258
|
+
logger.warn`由于设置了--debug参数,运行模式改为单线程`;
|
|
139
259
|
}
|
|
140
260
|
const builder = new JobGraphBuilder(concurrency, logger);
|
|
141
261
|
|
|
@@ -155,22 +275,25 @@ export async function main() {
|
|
|
155
275
|
});
|
|
156
276
|
|
|
157
277
|
let index = 0;
|
|
278
|
+
let indexDisplay = 0;
|
|
279
|
+
const width = shouldPublishProjects.length.toFixed(0).length;
|
|
158
280
|
for (const project of shouldPublishProjects) {
|
|
159
|
-
const job = new BuildPackageJob(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
{
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
281
|
+
const job = new BuildPackageJob(project.name, project.devDependencies, project, workspace, false);
|
|
282
|
+
|
|
283
|
+
job.onStateChange(() => {
|
|
284
|
+
if (job.isStopped()) {
|
|
285
|
+
indexDisplay++;
|
|
286
|
+
console.log(`${CSI}K📦 [${indexDisplay.toFixed(0).padStart(width)}/${shouldPublishProjects.length}] ${project.name}`);
|
|
287
|
+
job.flushLog();
|
|
288
|
+
|
|
289
|
+
const e = job.getLastError();
|
|
290
|
+
if (e) {
|
|
291
|
+
prettyPrintError(`job failed for ${project.name}`, e);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
170
294
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
job.onFailed(debugSummary);
|
|
295
|
+
if (!process.env.CI) debugSummary();
|
|
296
|
+
});
|
|
174
297
|
builder.addNode(job);
|
|
175
298
|
|
|
176
299
|
index++;
|
|
@@ -197,18 +320,9 @@ export async function main() {
|
|
|
197
320
|
|
|
198
321
|
if (opts.dryRun) {
|
|
199
322
|
console.log(`中断并退出(--dry)`);
|
|
200
|
-
|
|
323
|
+
throw shutdown(0);
|
|
201
324
|
}
|
|
202
325
|
|
|
203
|
-
const pm = await createPackageManager(PackageManagerUsageKind.Write, workspace, temp);
|
|
204
|
-
const npmrc = workspace.getNpmRCPath(true);
|
|
205
|
-
if (existsSync(npmrc)) {
|
|
206
|
-
await copyFile(npmrc, resolve(temp, '.npmrc'));
|
|
207
|
-
} else {
|
|
208
|
-
logger.warn`npmrc文件不存在 (long<${npmrc}>)`;
|
|
209
|
-
}
|
|
210
|
-
await writeFileIfChange(resolve(temp, 'package.json'), '{}');
|
|
211
|
-
|
|
212
326
|
const w = packageToPublish.length.toFixed(0).length;
|
|
213
327
|
const published: string[] = [];
|
|
214
328
|
|
|
@@ -216,7 +330,7 @@ export async function main() {
|
|
|
216
330
|
index = 1;
|
|
217
331
|
for (const { name, pack } of packageToPublish) {
|
|
218
332
|
console.log(`📦 [${index.toFixed(0).padStart(w)}/${packageToPublish.length}] ${name}`);
|
|
219
|
-
const r = await pm.uploadTarball(pack,
|
|
333
|
+
const r = await pm.uploadTarball(pack, zipDir);
|
|
220
334
|
if (r.published) {
|
|
221
335
|
console.log(` 👌 已发布新版本 ${r.version}`);
|
|
222
336
|
} else {
|
|
@@ -230,13 +344,14 @@ export async function main() {
|
|
|
230
344
|
console.log(`🎉 所有任务完成,共发布了 ${published.length} 个包`);
|
|
231
345
|
} catch (e: any) {
|
|
232
346
|
prettyPrintError(`发布过程中发生错误`, e);
|
|
233
|
-
|
|
347
|
+
setExitCodeIfNot(1);
|
|
234
348
|
} finally {
|
|
235
|
-
if (published.length > 0 && (await commandInPath('cnpm'))) {
|
|
349
|
+
if (published.length > 0 && !process.env.CI && (await commandInPath('cnpm'))) {
|
|
236
350
|
await cnpmSyncNames(published, true);
|
|
237
351
|
|
|
238
352
|
const pm = await createPackageManager(PackageManagerUsageKind.Read, workspace);
|
|
239
353
|
await clearNpmMetaCache(pm, published);
|
|
240
354
|
}
|
|
241
355
|
}
|
|
356
|
+
shutdown(0);
|
|
242
357
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createWorkspace } from '@build-script/monorepo-lib';
|
|
2
|
+
import { argv, CommandDefine, logger } from '@idlebox/cli';
|
|
3
|
+
import { UsageError } from '@idlebox/common';
|
|
4
|
+
import { PackageManagerUsageKind } from '../common/package-manager/driver.abstract.js';
|
|
5
|
+
import { createPackageManager } from '../common/package-manager/package-manager.js';
|
|
6
|
+
|
|
7
|
+
export class Command extends CommandDefine {
|
|
8
|
+
protected override readonly _usage = '运行pack命令';
|
|
9
|
+
protected override readonly _description = '';
|
|
10
|
+
protected override readonly _help = '';
|
|
11
|
+
protected override readonly _arguments = {
|
|
12
|
+
'--output': {
|
|
13
|
+
flag: false,
|
|
14
|
+
description: '输出文件路径',
|
|
15
|
+
},
|
|
16
|
+
'--project': {
|
|
17
|
+
flag: false,
|
|
18
|
+
description: '要打包的项目名称',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
public readonly isHidden = true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function main() {
|
|
25
|
+
const workspace = await createWorkspace();
|
|
26
|
+
const projectName = argv.single(['--project']);
|
|
27
|
+
if (!projectName) {
|
|
28
|
+
throw new UsageError('missing --project');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const node = await workspace.getPackage(projectName);
|
|
32
|
+
if (!node) {
|
|
33
|
+
throw new UsageError(`unknown project: ${projectName}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const output = argv.single(['--output']);
|
|
37
|
+
if (!output) {
|
|
38
|
+
throw new UsageError(`missing --output`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
logger.log`unshare builder: ${node.name}`;
|
|
42
|
+
const pm = await createPackageManager(PackageManagerUsageKind.Read, workspace, node.absolute);
|
|
43
|
+
const realOut = await pm.pack(output);
|
|
44
|
+
|
|
45
|
+
console.log(realOut);
|
|
46
|
+
}
|