@build-script/package-tools 0.0.27 → 0.0.28
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/monorepo-publish.d.ts.map +1 -1
- package/lib/commands/monorepo-publish.js +31 -15
- package/lib/commands/monorepo-publish.js.map +1 -1
- package/lib/common/cache/native.npm.d.ts +4 -1
- package/lib/common/cache/native.npm.d.ts.map +1 -1
- package/lib/common/cache/native.npm.js +13 -10
- package/lib/common/cache/native.npm.js.map +1 -1
- package/lib/common/git/git.d.ts +3 -1
- package/lib/common/git/git.d.ts.map +1 -1
- package/lib/common/git/git.js +12 -10
- package/lib/common/git/git.js.map +1 -1
- package/lib/common/package-manager/driver.abstract.d.ts +3 -1
- package/lib/common/package-manager/driver.abstract.d.ts.map +1 -1
- package/lib/common/package-manager/driver.abstract.js +16 -14
- package/lib/common/package-manager/driver.abstract.js.map +1 -1
- package/lib/common/package-manager/package-manager.d.ts +2 -1
- package/lib/common/package-manager/package-manager.d.ts.map +1 -1
- package/lib/common/package-manager/package-manager.js +4 -3
- package/lib/common/package-manager/package-manager.js.map +1 -1
- package/lib/common/package-manager/proxy.d.ts +3 -2
- package/lib/common/package-manager/proxy.d.ts.map +1 -1
- package/lib/common/package-manager/proxy.js +6 -6
- package/lib/common/package-manager/proxy.js.map +1 -1
- package/lib/common/shared-jobs/detect-change-job.d.ts.map +1 -1
- package/lib/common/shared-jobs/detect-change-job.js +12 -13
- package/lib/common/shared-jobs/detect-change-job.js.map +1 -1
- package/lib/common/taball/decompress.d.ts +2 -1
- package/lib/common/taball/decompress.d.ts.map +1 -1
- package/lib/common/taball/decompress.js +2 -2
- package/lib/common/taball/decompress.js.map +1 -1
- package/lib/common/taball/file-download.d.ts +8 -1
- package/lib/common/taball/file-download.d.ts.map +1 -1
- package/lib/common/taball/file-download.js +107 -97
- package/lib/common/taball/file-download.js.map +1 -1
- package/lib/common/temp-work-folder.d.ts +3 -1
- package/lib/common/temp-work-folder.d.ts.map +1 -1
- package/lib/common/temp-work-folder.js +9 -7
- package/lib/common/temp-work-folder.js.map +1 -1
- package/lib/common/version.generated.d.ts +1 -1
- package/lib/common/version.generated.js +1 -1
- package/package.json +11 -12
- package/src/commands/monorepo-publish.ts +33 -15
- package/src/common/cache/native.npm.ts +13 -10
- package/src/common/git/git.ts +13 -10
- package/src/common/package-manager/driver.abstract.ts +14 -13
- package/src/common/package-manager/package-manager.ts +10 -4
- package/src/common/package-manager/proxy.ts +6 -6
- package/src/common/shared-jobs/detect-change-job.ts +13 -13
- package/src/common/taball/decompress.ts +2 -2
- package/src/common/taball/file-download.ts +113 -105
- package/src/common/temp-work-folder.ts +7 -6
- package/src/common/version.generated.ts +1 -1
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* https://github.com/GongT/baobao
|
|
11
11
|
*
|
|
12
12
|
******************************************************************************/
|
|
13
|
-
export const self_package_version = "0.0.
|
|
13
|
+
export const self_package_version = "0.0.28";
|
|
14
14
|
export const self_package_name = "@build-script/package-tools";
|
|
15
15
|
export const self_package_repository = "https://github.com/GongT/baobao";
|
|
16
16
|
//# sourceMappingURL=version.generated.js.map
|
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.28",
|
|
5
5
|
"description": "A Node.js package managing tool",
|
|
6
6
|
"bin": {
|
|
7
7
|
"package-tools": "./bins/load.devel.js",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"targz": "^1.0.1",
|
|
23
23
|
"tiny-async-pool": "^2.1.0",
|
|
24
24
|
"yaml": "^2.8.2",
|
|
25
|
-
"@build-script/monorepo-lib": "^0.0.
|
|
26
|
-
"@idlebox/
|
|
27
|
-
"@idlebox/
|
|
28
|
-
"@idlebox/
|
|
25
|
+
"@build-script/monorepo-lib": "^0.0.26",
|
|
26
|
+
"@idlebox/common": "^1.5.24",
|
|
27
|
+
"@idlebox/dependency-graph": "^0.0.23",
|
|
28
|
+
"@idlebox/ensure-symlink": "^1.0.41",
|
|
29
29
|
"@idlebox/json-edit": "^0.0.15",
|
|
30
|
-
"@idlebox/node": "^1.4.
|
|
30
|
+
"@idlebox/node": "^1.4.32",
|
|
31
|
+
"@idlebox/cli": "^0.0.16",
|
|
31
32
|
"@idlebox/source-map-support": "^0.0.21",
|
|
32
|
-
"@idlebox/
|
|
33
|
-
"@idlebox/unshare": "^0.0.13"
|
|
34
|
-
"@idlebox/terminal-control": "^0.0.4"
|
|
33
|
+
"@idlebox/terminal-control": "^0.0.5",
|
|
34
|
+
"@idlebox/unshare": "^0.0.13"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/cacache": "^20.0.1",
|
|
@@ -43,9 +43,8 @@
|
|
|
43
43
|
"@types/targz": "^1.0.5",
|
|
44
44
|
"@types/tiny-async-pool": "^2.0.3",
|
|
45
45
|
"@types/tinycolor2": "^1.4.6",
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@mpis/run": "^0.0.26",
|
|
46
|
+
"@idlebox/cli-static-generator": "^0.0.16",
|
|
47
|
+
"@build-script/codegen": "^1.0.24",
|
|
49
48
|
"@build-script/baseline-rig": "latest"
|
|
50
49
|
},
|
|
51
50
|
"sideEffects": false,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { applyPublishWorkspace, createWorkspace, normalizePackageName, type IPackageInfo, type MonorepoWorkspace } from '@build-script/monorepo-lib';
|
|
2
|
-
import { app, argv, CommandDefine, logger } from '@idlebox/cli';
|
|
2
|
+
import { app, argv, CommandDefine, createLogger, logger, NodejsOutput, type IMyLogger } from '@idlebox/cli';
|
|
3
3
|
import { prettyPrintError } from '@idlebox/common';
|
|
4
4
|
import { Job, JobGraphBuilder, JobState } from '@idlebox/dependency-graph';
|
|
5
5
|
import { loadJsonFile, writeJsonFileBack } from '@idlebox/json-edit';
|
|
6
|
-
import { commandInPath, emptyDir, setExitCodeIfNot, shutdown, workingDirectory, writeFileIfChange } from '@idlebox/node';
|
|
6
|
+
import { CollectingStream, commandInPath, emptyDir, setExitCodeIfNot, shutdown, workingDirectory, writeFileIfChange } from '@idlebox/node';
|
|
7
7
|
import { CSI } from '@idlebox/terminal-control/constants';
|
|
8
8
|
import { FsNodeType, spawnReadonlyFileSystemWithCommand } from '@idlebox/unshare';
|
|
9
9
|
import { execaNode } from 'execa';
|
|
@@ -35,6 +35,8 @@ export class Command extends CommandDefine {
|
|
|
35
35
|
class BuildPackageJob extends Job<void> {
|
|
36
36
|
private shouldPublish = '';
|
|
37
37
|
public initialVersion = true;
|
|
38
|
+
public override readonly logger: IMyLogger;
|
|
39
|
+
private readonly collector;
|
|
38
40
|
|
|
39
41
|
constructor(
|
|
40
42
|
name: string,
|
|
@@ -45,17 +47,28 @@ class BuildPackageJob extends Job<void> {
|
|
|
45
47
|
) {
|
|
46
48
|
super(name, deps);
|
|
47
49
|
|
|
50
|
+
const collector = new CollectingStream();
|
|
51
|
+
const stream = new NodejsOutput({
|
|
52
|
+
stream: collector,
|
|
53
|
+
colorEnabled: logger.colorEnabled,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
this.collector = collector;
|
|
57
|
+
this.logger = createLogger('pub', { colors: false, console: stream });
|
|
58
|
+
|
|
48
59
|
this.detect = unshareExecuter ? this.unsharedDetect : this.sharedDetect;
|
|
49
60
|
this.pack = unshareExecuter ? this.unsharedPack : this.sharedPack;
|
|
50
61
|
}
|
|
51
62
|
|
|
52
|
-
private readonly logText: string[] = [];
|
|
53
|
-
log(text: string) {
|
|
54
|
-
this.logText.push(text);
|
|
55
|
-
}
|
|
56
63
|
flushLog() {
|
|
57
|
-
|
|
58
|
-
this.
|
|
64
|
+
const output = this.collector.getOutput();
|
|
65
|
+
this.collector.clear();
|
|
66
|
+
return output;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
log(message: string) {
|
|
70
|
+
// biome-ignore lint/style/useTemplate: too simple
|
|
71
|
+
this.collector.write(message + '\n');
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
getPackagePath() {
|
|
@@ -167,7 +180,7 @@ class BuildPackageJob extends Job<void> {
|
|
|
167
180
|
try {
|
|
168
181
|
this.log(` 🔍 ${CSI}38;5;14m检查包${CSI}0m`);
|
|
169
182
|
|
|
170
|
-
const pm = await createPackageManager(PackageManagerUsageKind.Write, this.workspace, this.project.absolute);
|
|
183
|
+
const pm = await createPackageManager(PackageManagerUsageKind.Write, this.workspace, this.project.absolute, this.logger);
|
|
171
184
|
const { changedFiles, hasChange, remoteVersion, packageJsonDiff } = await this.detect(pm);
|
|
172
185
|
const shouldPublish = hasChange || changedFiles.length > 0;
|
|
173
186
|
let localVersion = this.project.packageJson.version;
|
|
@@ -259,10 +272,15 @@ export async function main() {
|
|
|
259
272
|
|
|
260
273
|
const projects = await workspace.listPackages();
|
|
261
274
|
|
|
262
|
-
let concurrency = Number.parseInt(argv.single(['--concurrency']) || '
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
275
|
+
let concurrency = Number.parseInt(argv.single(['--concurrency']) || '-1', 10);
|
|
276
|
+
if (concurrency <= 0) {
|
|
277
|
+
if (app.debug) {
|
|
278
|
+
concurrency = 1;
|
|
279
|
+
logger.warn`由于设置了--debug参数,运行模式默认为单线程,设置 --concurrency 参数可改变此设置`;
|
|
280
|
+
} else {
|
|
281
|
+
concurrency = process.env.CI ? 10 : 3;
|
|
282
|
+
logger.info`使用默认并发数 ${concurrency}`;
|
|
283
|
+
}
|
|
266
284
|
}
|
|
267
285
|
const builder = new JobGraphBuilder(concurrency, logger);
|
|
268
286
|
|
|
@@ -290,8 +308,8 @@ export async function main() {
|
|
|
290
308
|
job.onStateChange(() => {
|
|
291
309
|
if (job.isStopped()) {
|
|
292
310
|
indexDisplay++;
|
|
293
|
-
|
|
294
|
-
|
|
311
|
+
const output = job.flushLog();
|
|
312
|
+
process.stderr.write(`\n${CSI}K📦 [${indexDisplay.toFixed(0).padStart(width)}/${shouldPublishProjects.length}] ${project.name}\n${output}\n`);
|
|
295
313
|
|
|
296
314
|
const e = job.getLastError();
|
|
297
315
|
if (e) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger } from '@idlebox/cli';
|
|
1
|
+
import { logger as defaultLogger, type IMyLogger } from '@idlebox/cli';
|
|
2
2
|
import { sleep, type IPackageJson } from '@idlebox/common';
|
|
3
3
|
import { get as cacheGet, rm as cacheRm } from 'cacache';
|
|
4
4
|
import { rm } from 'node:fs/promises';
|
|
@@ -8,7 +8,7 @@ import { json as npmFetchJson } from 'npm-registry-fetch';
|
|
|
8
8
|
import { DEFAULT_NPM_REGISTRY } from '../package-manager/constant.js';
|
|
9
9
|
import type { IPackageManager } from '../package-manager/package-manager.js';
|
|
10
10
|
import { getProxyValue } from '../package-manager/proxy.js';
|
|
11
|
-
import {
|
|
11
|
+
import { FileDownloader } from '../taball/file-download.js';
|
|
12
12
|
import { self_package_name, self_package_repository, self_package_version } from '../version.generated.js';
|
|
13
13
|
import { escapePackageNameToFilename } from './escape-package-path.js';
|
|
14
14
|
|
|
@@ -44,17 +44,18 @@ export class NpmCacheHandler {
|
|
|
44
44
|
private readonly pm: IPackageManager,
|
|
45
45
|
private readonly registry: string,
|
|
46
46
|
public readonly path: string,
|
|
47
|
+
public readonly logger = defaultLogger,
|
|
47
48
|
) {
|
|
48
49
|
this.cache_path = resolve(path, '_cacache');
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
deleteMetadata(name: string) {
|
|
52
|
-
return deleteNpmCache(this.cache_path, name, this.registry);
|
|
53
|
+
return deleteNpmCache(this.cache_path, name, this.registry, this.logger);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
async fetchMetadata(name: string, cacheMode = CacheMode.Normal) {
|
|
56
57
|
const registry = await this.pm.getNpmRegistry();
|
|
57
|
-
return fetchNpmWithCache(this.cache_path, name, registry, { mode: cacheMode });
|
|
58
|
+
return fetchNpmWithCache(this.cache_path, name, registry, { mode: cacheMode, logger: this.logger });
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
async fetchVersion(name: string, distTag = 'latest', cacheMode = CacheMode.Normal) {
|
|
@@ -64,7 +65,7 @@ export class NpmCacheHandler {
|
|
|
64
65
|
}
|
|
65
66
|
const version = getVersion(json, distTag);
|
|
66
67
|
if (!version) {
|
|
67
|
-
logger.warn(` ! 找不到版本信息(${name}@${distTag})`);
|
|
68
|
+
this.logger.warn(` ! 找不到版本信息(${name}@${distTag})`);
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
71
|
return version;
|
|
@@ -80,7 +81,7 @@ export class NpmCacheHandler {
|
|
|
80
81
|
if (!r) {
|
|
81
82
|
throw new Error(`无此版本: ${name} = ${distTag}`);
|
|
82
83
|
}
|
|
83
|
-
return await
|
|
84
|
+
return await new FileDownloader(this.logger).download(r.dist.tarball, this.getTarballFile(name, distTag));
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
public deleteTarball(name: string, distTag: string) {
|
|
@@ -110,16 +111,18 @@ export enum CacheMode {
|
|
|
110
111
|
interface IMyOpts {
|
|
111
112
|
mode?: CacheMode;
|
|
112
113
|
maxRetry?: number;
|
|
114
|
+
logger?: IMyLogger;
|
|
113
115
|
}
|
|
114
116
|
const defOpt: Required<IMyOpts> = {
|
|
115
117
|
mode: CacheMode.Normal,
|
|
116
118
|
maxRetry: 3,
|
|
119
|
+
logger: defaultLogger,
|
|
117
120
|
};
|
|
118
121
|
|
|
119
122
|
export async function fetchNpmWithCache(path: string, name: string, registry: string, _options?: IMyOpts) {
|
|
120
|
-
logger
|
|
123
|
+
const { logger, ...options }: Required<IMyOpts> = Object.assign({}, defOpt, _options);
|
|
121
124
|
|
|
122
|
-
|
|
125
|
+
logger.debug(` * npm-registry-fetch: ${registry} :: ${name}`);
|
|
123
126
|
|
|
124
127
|
let _try_cnt = 0;
|
|
125
128
|
let retry = options.maxRetry;
|
|
@@ -130,7 +133,7 @@ export async function fetchNpmWithCache(path: string, name: string, registry: st
|
|
|
130
133
|
_try_cnt++;
|
|
131
134
|
retry--;
|
|
132
135
|
try {
|
|
133
|
-
const proxy = getProxyValue(registry);
|
|
136
|
+
const proxy = getProxyValue(registry, logger);
|
|
134
137
|
json = (await npmFetchJson(name, {
|
|
135
138
|
cache: path,
|
|
136
139
|
registry: registry,
|
|
@@ -172,7 +175,7 @@ export async function fetchNpmWithCache(path: string, name: string, registry: st
|
|
|
172
175
|
return json;
|
|
173
176
|
}
|
|
174
177
|
|
|
175
|
-
async function deleteNpmCache(path: string, name: string, registry?: string) {
|
|
178
|
+
async function deleteNpmCache(path: string, name: string, registry?: string, logger: IMyLogger = defaultLogger) {
|
|
176
179
|
const require = createRequire(import.meta.url);
|
|
177
180
|
const cacheKey = require('make-fetch-happen/lib/cache/key.js');
|
|
178
181
|
const registries = new Set([DEFAULT_NPM_REGISTRY, 'https://registry.npmmirror.com/']);
|
package/src/common/git/git.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger } from '@idlebox/cli';
|
|
1
|
+
import { logger as defaultLogger, type IMyLogger } from '@idlebox/cli';
|
|
2
2
|
import { commandInPath, execLazyError, exists } from '@idlebox/node';
|
|
3
3
|
import { rm } from 'node:fs/promises';
|
|
4
4
|
import { resolve } from 'node:path';
|
|
@@ -12,38 +12,41 @@ export async function requireGitInPath() {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export class GitWorkingTree {
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(
|
|
16
|
+
public readonly path: string,
|
|
17
|
+
public readonly logger: IMyLogger = defaultLogger,
|
|
18
|
+
) {}
|
|
16
19
|
|
|
17
20
|
protected _exec(cmds: string[]) {
|
|
18
21
|
return execLazyError('git', cmds, { cwd: this.path, verbose: isVerbose });
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
async init() {
|
|
22
|
-
logger.debug('初始化git工作区: %s', this.path);
|
|
25
|
+
this.logger.debug('初始化git工作区: %s', this.path);
|
|
23
26
|
const gitDir = resolve(this.path, '.git');
|
|
24
27
|
if (await exists(gitDir)) {
|
|
25
|
-
logger.debug(' - 删除已有.git文件夹');
|
|
28
|
+
this.logger.debug(' - 删除已有.git文件夹');
|
|
26
29
|
await rm(gitDir, { recursive: true, force: true });
|
|
27
30
|
}
|
|
28
31
|
await this._exec(['init']);
|
|
29
32
|
await this._exec(['add', '.']);
|
|
30
33
|
await this._exec(['commit', '-m', 'Init']);
|
|
31
|
-
logger.debug('(初始化完成)');
|
|
34
|
+
this.logger.debug('(初始化完成)');
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
async commitChanges() {
|
|
35
|
-
logger.debug('检测文件更改:');
|
|
38
|
+
this.logger.debug('检测文件更改:');
|
|
36
39
|
|
|
37
40
|
const { stdout: testOut } = await this._exec(['status']);
|
|
38
41
|
const statusOut = testOut.toString().trim();
|
|
39
42
|
if (statusOut.includes('nothing to commit, working tree clean')) {
|
|
40
|
-
logger.debug(' git工作区状态: 干净');
|
|
43
|
+
this.logger.debug(' git工作区状态: 干净');
|
|
41
44
|
return [];
|
|
42
45
|
}
|
|
43
46
|
// if (isDebugMode) {
|
|
44
47
|
// await execa('git', ['diff'], { cwd: this.path, stdio: ['ignore', 2, 2] });
|
|
45
48
|
// }
|
|
46
|
-
logger.debug(' git工作区状态: 有修改');
|
|
49
|
+
this.logger.debug(' git工作区状态: 有修改');
|
|
47
50
|
|
|
48
51
|
await this._exec(['add', '.']);
|
|
49
52
|
await this._exec(['commit', '-m', 'DetectChangedFiles']);
|
|
@@ -61,7 +64,7 @@ export class GitWorkingTree {
|
|
|
61
64
|
}
|
|
62
65
|
const files = lines.slice(titleLine + 1);
|
|
63
66
|
|
|
64
|
-
logger.debug(' 文件更改: %d 个 (%s%s)', files.length, files.slice(0, 5).join(', '), files.length > 5 ? ' ...' : '');
|
|
67
|
+
this.logger.debug(' 文件更改: %d 个 (%s%s)', files.length, files.slice(0, 5).join(', '), files.length > 5 ? ' ...' : '');
|
|
65
68
|
|
|
66
69
|
return files.map((item) => {
|
|
67
70
|
return item.replace('Would remove ', '');
|
|
@@ -70,7 +73,7 @@ export class GitWorkingTree {
|
|
|
70
73
|
|
|
71
74
|
async fileDiff(file: string) {
|
|
72
75
|
const { stdout } = await this._exec(['diff', '--color=never', '-U0', `HEAD~1`, file]);
|
|
73
|
-
logger.verbose(stdout.trimEnd());
|
|
76
|
+
this.logger.verbose(stdout.trimEnd());
|
|
74
77
|
const lines = stdout.toString().trim().split('\n').slice(4);
|
|
75
78
|
|
|
76
79
|
let diff = formatChangeSideBySide('Published', 'Local');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WorkspaceBase } from '@build-script/monorepo-lib';
|
|
2
|
-
import { logger } from '@idlebox/cli';
|
|
2
|
+
import { logger as defaultLogger, type IMyLogger } from '@idlebox/cli';
|
|
3
3
|
import { ensureLinkTarget } from '@idlebox/ensure-symlink';
|
|
4
4
|
import { execLazyError, exists, writeFileIfChange } from '@idlebox/node';
|
|
5
5
|
import { execa } from 'execa';
|
|
@@ -31,8 +31,9 @@ export abstract class PackageManager {
|
|
|
31
31
|
public readonly usageKind: PackageManagerUsageKind,
|
|
32
32
|
public readonly workspace: WorkspaceBase,
|
|
33
33
|
subdir = process.cwd(),
|
|
34
|
+
public readonly logger: IMyLogger = defaultLogger,
|
|
34
35
|
) {
|
|
35
|
-
this.configTemp = new TempWorkingFolder(this.workspace, 'package-manager', true);
|
|
36
|
+
this.configTemp = new TempWorkingFolder(this.workspace, 'package-manager', logger, true);
|
|
36
37
|
this.projectPath = resolve(workspace.root, subdir);
|
|
37
38
|
if (!this.projectPath.startsWith(workspace.root)) {
|
|
38
39
|
throw new Error(`project "${this.projectPath}" is outside the workspace root`);
|
|
@@ -45,15 +46,15 @@ export abstract class PackageManager {
|
|
|
45
46
|
|
|
46
47
|
public async pack(saveAs: string) {
|
|
47
48
|
const pkg = await this.loadPackageJson();
|
|
48
|
-
logger.log`打包项目 (${pkg.publishConfig?.['packCommand'] ? 'custom' : 'default'}): relative<${this.projectPath}> -> relative<${saveAs}>`;
|
|
49
|
+
this.logger.log`打包项目 (${pkg.publishConfig?.['packCommand'] ? 'custom' : 'default'}): relative<${this.projectPath}> -> relative<${saveAs}>`;
|
|
49
50
|
if (pkg.publishConfig?.['packCommand']) {
|
|
50
51
|
const cmds = typeof pkg.publishConfig['packCommand'] === 'string' ? splitCmd(pkg.publishConfig['packCommand']) : pkg.publishConfig['packCommand'];
|
|
51
52
|
|
|
52
53
|
if (!Array.isArray(cmds)) {
|
|
53
|
-
logger.fatal`publishConfig.packCommand必须是字符串或字符串数组, 但实际是: ${typeof pkg.publishConfig['packCommand']}`;
|
|
54
|
+
this.logger.fatal`publishConfig.packCommand必须是字符串或字符串数组, 但实际是: ${typeof pkg.publishConfig['packCommand']}`;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
logger.verbose` - 自定义打包命令: ${Array.from(cmds)}`;
|
|
57
|
+
this.logger.verbose` - 自定义打包命令: ${Array.from(cmds)}`;
|
|
57
58
|
|
|
58
59
|
const [cmd, ...args] = cmds;
|
|
59
60
|
await execLazyError(cmd, [...args, '--out', saveAs], {
|
|
@@ -110,25 +111,25 @@ export abstract class PackageManager {
|
|
|
110
111
|
const scope = await this.getScope();
|
|
111
112
|
if (scope) {
|
|
112
113
|
const { stdout } = await this._execGetOut(cwd, ['config', 'get', `${scope}:${key}`], true, binary);
|
|
113
|
-
logger.debug('$ %s config get %s:%s -> %s (cwd: %s)', binary, scope, key, stdout, cwd);
|
|
114
|
+
this.logger.debug('$ %s config get %s:%s -> %s (cwd: %s)', binary, scope, key, stdout, cwd);
|
|
114
115
|
if (`${stdout}` !== 'undefined') {
|
|
115
116
|
return stdout;
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
const { stdout } = await this._execGetOut(cwd, ['config', 'get', key], true, binary);
|
|
119
|
-
logger.debug('$ %s config get %s -> %s (cwd: %s)', binary, key, stdout, cwd);
|
|
120
|
+
this.logger.debug('$ %s config get %s -> %s (cwd: %s)', binary, key, stdout, cwd);
|
|
120
121
|
return stdout === 'undefined' ? undefined : stdout;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
protected abstract _uploadTarball(pack: string, cwd: string): Promise<IUploadResult>;
|
|
124
125
|
public async uploadTarball(pack: string, cwd: string = this.projectPath) {
|
|
125
|
-
logger.debug(`上传压缩包: ${pack}`);
|
|
126
|
+
this.logger.debug(`上传压缩包: ${pack}`);
|
|
126
127
|
try {
|
|
127
128
|
const r = await this._uploadTarball(pack, cwd);
|
|
128
|
-
logger.debug` 发布成功: ${r.name} @ ${r.version} [${r.published}]`;
|
|
129
|
+
this.logger.debug` 发布成功: ${r.name} @ ${r.version} [${r.published}]`;
|
|
129
130
|
return r;
|
|
130
131
|
} catch (e: any) {
|
|
131
|
-
logger.debug` tarball发布失败`;
|
|
132
|
+
this.logger.debug` tarball发布失败`;
|
|
132
133
|
throw e;
|
|
133
134
|
}
|
|
134
135
|
}
|
|
@@ -161,14 +162,14 @@ export abstract class PackageManager {
|
|
|
161
162
|
if (!this._cachedReg) {
|
|
162
163
|
switch (registryInput) {
|
|
163
164
|
case 'detect':
|
|
164
|
-
logger.debug(`检测registry地址: ${registryInput}`);
|
|
165
|
+
this.logger.debug(`检测registry地址: ${registryInput}`);
|
|
165
166
|
this._cachedReg = await this.getConfig('registry');
|
|
166
167
|
break;
|
|
167
168
|
default:
|
|
168
169
|
if (!registryInput.startsWith('https://')) {
|
|
169
170
|
throw new Error(`不支持的--registry协议: ${registryInput}`);
|
|
170
171
|
}
|
|
171
|
-
logger.debug('使用命令行提供的registry地址 (%s)', registryInput);
|
|
172
|
+
this.logger.debug('使用命令行提供的registry地址 (%s)', registryInput);
|
|
172
173
|
this._cachedReg = registryInput;
|
|
173
174
|
}
|
|
174
175
|
}
|
|
@@ -183,7 +184,7 @@ export abstract class PackageManager {
|
|
|
183
184
|
const path = await this.getConfig('cache');
|
|
184
185
|
if (!path) throw new Error('npm config get cache返回为空');
|
|
185
186
|
|
|
186
|
-
this._cache_handler = new NpmCacheHandler(this, registry, path);
|
|
187
|
+
this._cache_handler = new NpmCacheHandler(this, registry, path, this.logger);
|
|
187
188
|
}
|
|
188
189
|
return this._cache_handler;
|
|
189
190
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { WorkspaceBase } from '@build-script/monorepo-lib';
|
|
2
|
+
import { logger as defaultLogger, type IMyLogger } from '@idlebox/cli';
|
|
2
3
|
import { commandInPath, PathEnvironment } from '@idlebox/node';
|
|
3
4
|
import type { PackageManager, PackageManagerUsageKind } from './driver.abstract.js';
|
|
4
5
|
import { NPM } from './driver.npm.js';
|
|
@@ -7,13 +8,18 @@ import { reconfigureProxyWithNpmrc } from './proxy.js';
|
|
|
7
8
|
|
|
8
9
|
export type IPackageManager = PackageManager;
|
|
9
10
|
|
|
10
|
-
type PackageManagerConstructor = new (usage: PackageManagerUsageKind, workspace: WorkspaceBase, subdir?: string) => IPackageManager;
|
|
11
|
+
type PackageManagerConstructor = new (usage: PackageManagerUsageKind, workspace: WorkspaceBase, subdir?: string, logger?: IMyLogger) => IPackageManager;
|
|
11
12
|
|
|
12
13
|
let pmCls: PackageManagerConstructor | undefined;
|
|
13
14
|
|
|
14
|
-
export async function createPackageManager(
|
|
15
|
+
export async function createPackageManager(
|
|
16
|
+
usage: PackageManagerUsageKind,
|
|
17
|
+
workspace: WorkspaceBase,
|
|
18
|
+
subdir?: string,
|
|
19
|
+
logger: IMyLogger = defaultLogger,
|
|
20
|
+
): Promise<IPackageManager> {
|
|
15
21
|
if (pmCls) {
|
|
16
|
-
return new pmCls(usage, workspace, subdir);
|
|
22
|
+
return new pmCls(usage, workspace, subdir, logger);
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
const supports: Record<string, PackageManagerConstructor> = { pnpm: PNPM, npm: NPM };
|
|
@@ -22,7 +28,7 @@ export async function createPackageManager(usage: PackageManagerUsageKind, works
|
|
|
22
28
|
continue;
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
const pm = new Cls(usage, workspace, subdir);
|
|
31
|
+
const pm = new Cls(usage, workspace, subdir, logger);
|
|
26
32
|
|
|
27
33
|
await reconfigureProxyWithNpmrc(pm);
|
|
28
34
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { logger as defaultLogger, type IMyLogger } from '@idlebox/cli';
|
|
1
2
|
import { escapeRegExp } from '@idlebox/common';
|
|
2
|
-
import { logger } from '@idlebox/cli';
|
|
3
3
|
import { getEnvironment } from '@idlebox/node';
|
|
4
4
|
import type { IPackageManager } from './package-manager.js';
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ function makeRe(str: string) {
|
|
|
13
13
|
return new RegExp(`^${reTxt}$`, 'i');
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function getProxyValue(url: string) {
|
|
16
|
+
export function getProxyValue(url: string, logger: IMyLogger = defaultLogger): string {
|
|
17
17
|
const proxyValue = process.env.http_proxy;
|
|
18
18
|
if (!proxyValue) {
|
|
19
19
|
return '';
|
|
@@ -65,21 +65,21 @@ export function getProxyValue(url: string) {
|
|
|
65
65
|
export async function reconfigureProxyWithNpmrc(pm: IPackageManager) {
|
|
66
66
|
if (proxy_override_by_env) return;
|
|
67
67
|
|
|
68
|
-
logger.debug('通过npm设置代理服务器:');
|
|
68
|
+
pm.logger.debug('通过npm设置代理服务器:');
|
|
69
69
|
const p = await pm.getConfig('proxy');
|
|
70
70
|
const np = await pm.getConfig('noproxy');
|
|
71
71
|
|
|
72
72
|
if (p) {
|
|
73
|
-
logger.debug(` * proxy server = ${p}`);
|
|
73
|
+
pm.logger.debug(` * proxy server = ${p}`);
|
|
74
74
|
}
|
|
75
75
|
if (np) {
|
|
76
|
-
logger.debug(` * no_proxy = ${np}`);
|
|
76
|
+
pm.logger.debug(` * no_proxy = ${np}`);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
applyEnv(p || '', np || '');
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export function configureProxyFromEnvironment() {
|
|
82
|
+
export function configureProxyFromEnvironment(logger: IMyLogger = defaultLogger) {
|
|
83
83
|
// bootstrap({
|
|
84
84
|
// environmentVariableNamespace: '',
|
|
85
85
|
// forceGlobalAgent: true,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { logger } from '@idlebox/cli';
|
|
2
1
|
import { PathEnvironment } from '@idlebox/node';
|
|
3
2
|
import { resolve } from 'node:path';
|
|
4
3
|
import { gt } from 'semver';
|
|
@@ -21,7 +20,8 @@ interface IDetectOptions {
|
|
|
21
20
|
|
|
22
21
|
export async function executeChangeDetect(pm: IPackageManager, options: IDetectOptions = {}): Promise<IResult> {
|
|
23
22
|
const packageJson = await pm.loadPackageJson();
|
|
24
|
-
|
|
23
|
+
|
|
24
|
+
pm.logger.debug('修改检测 | 包名: %s', packageJson.name);
|
|
25
25
|
if (!packageJson.name) {
|
|
26
26
|
throw new Error(`${pm.projectPath}/package.json 中缺少 name 字段`);
|
|
27
27
|
}
|
|
@@ -38,16 +38,16 @@ export async function executeChangeDetect(pm: IPackageManager, options: IDetectO
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (packageJson.private && !options.forcePrivate) {
|
|
41
|
-
logger.debug('检测到私有包,禁止运行');
|
|
41
|
+
pm.logger.debug('检测到私有包,禁止运行');
|
|
42
42
|
return { changedFiles: [], hasChange: false };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const remotePackage = await cache.fetchVersion(packageJson.name, distTagInput);
|
|
46
|
-
logger.debug(' -> npm 远程版本 = %s', remotePackage?.version);
|
|
47
|
-
logger.debug(' -> package.json 本地版本 = %s', packageJson.version);
|
|
46
|
+
pm.logger.debug(' -> npm 远程版本 = %s', remotePackage?.version);
|
|
47
|
+
pm.logger.debug(' -> package.json 本地版本 = %s', packageJson.version);
|
|
48
48
|
|
|
49
49
|
if (!remotePackage || gt(packageJson.version, remotePackage.version)) {
|
|
50
|
-
logger.debug('本地版本 (%s) 已经大于远程版本 (%s),无需进一步检测', packageJson.version, remotePackage?.version);
|
|
50
|
+
pm.logger.debug('本地版本 (%s) 已经大于远程版本 (%s),无需进一步检测', packageJson.version, remotePackage?.version);
|
|
51
51
|
return {
|
|
52
52
|
changedFiles: ['package.json'],
|
|
53
53
|
hasChange: false,
|
|
@@ -55,33 +55,33 @@ export async function executeChangeDetect(pm: IPackageManager, options: IDetectO
|
|
|
55
55
|
packageJsonDiff: `短路检测: "version" 本地为 ${packageJson.version}, 远程版本为 ${remotePackage?.version}`,
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
logger.debug('本地版本 (%s) 小于或等于远程版本 (%s),尝试检测更改...', packageJson.version, remotePackage.version);
|
|
58
|
+
pm.logger.debug('本地版本 (%s) 小于或等于远程版本 (%s),尝试检测更改...', packageJson.version, remotePackage.version);
|
|
59
59
|
|
|
60
60
|
const tarball = await cache.downloadTarball(packageJson.name, distTagInput);
|
|
61
61
|
|
|
62
|
-
const tempFolder = new TempWorkingFolder(pm.workspace, 'package-change-detect');
|
|
62
|
+
const tempFolder = new TempWorkingFolder(pm.workspace, 'package-change-detect', pm.logger);
|
|
63
63
|
const workingRoot = tempFolder.resolve('working');
|
|
64
64
|
await workingRoot.unpack(tarball);
|
|
65
65
|
await makePackageJsonOrderConsistence(workingRoot.path);
|
|
66
66
|
|
|
67
|
-
const gitrepo = new GitWorkingTree(workingRoot.path);
|
|
67
|
+
const gitrepo = new GitWorkingTree(workingRoot.path, pm.logger);
|
|
68
68
|
await gitrepo.init();
|
|
69
69
|
|
|
70
70
|
const pack = await pm.pack(tempFolder.joinpath('local-pack.tgz'));
|
|
71
|
-
logger.verbose(' --> %s', pack);
|
|
71
|
+
pm.logger.verbose(' --> %s', pack);
|
|
72
72
|
|
|
73
73
|
await workingRoot.unpack(pack);
|
|
74
|
-
logger.verbose(' unpacked successfully');
|
|
74
|
+
pm.logger.verbose(' unpacked successfully');
|
|
75
75
|
|
|
76
76
|
await makePackageJsonOrderConsistence(workingRoot.path);
|
|
77
77
|
|
|
78
78
|
const changedFiles = await gitrepo.commitChanges();
|
|
79
|
-
logger.verbose` changed files: list<${changedFiles}>`;
|
|
79
|
+
pm.logger.verbose` changed files: list<${changedFiles}>`;
|
|
80
80
|
|
|
81
81
|
let packageJsonDiff = '';
|
|
82
82
|
if (changedFiles.includes('package.json')) {
|
|
83
83
|
packageJsonDiff = await gitrepo.fileDiff('package.json');
|
|
84
|
-
logger.debug(` - package.json 文件的修改:\n${packageJsonDiff}`);
|
|
84
|
+
pm.logger.debug(` - package.json 文件的修改:\n${packageJsonDiff}`);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return { changedFiles, hasChange: changedFiles.length > 0, remoteVersion: remotePackage.version, packageJsonDiff };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { logger as defaultLogger, type IMyLogger } from '@idlebox/cli';
|
|
1
2
|
import { convertCatchedError } from '@idlebox/common';
|
|
2
|
-
import { logger } from '@idlebox/cli';
|
|
3
3
|
import { existsSync, unlinkSync } from 'node:fs';
|
|
4
4
|
import tgz from 'targz';
|
|
5
5
|
|
|
6
6
|
const packageFolder = /^package\//;
|
|
7
7
|
|
|
8
|
-
export async function decompressPack(src: string, dest: string) {
|
|
8
|
+
export async function decompressPack(src: string, dest: string, logger: IMyLogger = defaultLogger) {
|
|
9
9
|
logger.debug(`解压文件: ${src}\n\u3000\u3000目录: ${dest}`);
|
|
10
10
|
await new Promise<void>((resolve, reject) => {
|
|
11
11
|
if (!existsSync(src)) {
|