@build-script/package-tools 0.0.3 → 0.0.5
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/command-file-map.generated.d.ts +2 -1
- package/lib/command-file-map.generated.d.ts.map +1 -1
- package/lib/command-file-map.generated.js +2 -1
- package/lib/command-file-map.generated.js.map +1 -1
- package/lib/commands/detect-package-change.d.ts.map +1 -1
- package/lib/commands/detect-package-change.js +3 -1
- package/lib/commands/detect-package-change.js.map +1 -1
- package/lib/commands/monorepo-bump-version.d.ts.map +1 -1
- package/lib/commands/monorepo-bump-version.js +13 -23
- package/lib/commands/monorepo-bump-version.js.map +1 -1
- package/lib/commands/monorepo-cnpm-sync.d.ts.map +1 -1
- package/lib/commands/monorepo-cnpm-sync.js +12 -2
- package/lib/commands/monorepo-cnpm-sync.js.map +1 -1
- package/lib/commands/monorepo-invalid.d.ts.map +1 -1
- package/lib/commands/monorepo-invalid.js +4 -2
- package/lib/commands/monorepo-invalid.js.map +1 -1
- package/lib/commands/monorepo-link-binaries.d.ts +22 -0
- package/lib/commands/monorepo-link-binaries.d.ts.map +1 -0
- package/lib/commands/monorepo-link-binaries.js +146 -0
- package/lib/commands/monorepo-link-binaries.js.map +1 -0
- package/lib/commands/monorepo-publish.d.ts.map +1 -1
- package/lib/commands/monorepo-publish.js +45 -36
- package/lib/commands/monorepo-publish.js.map +1 -1
- package/lib/commands/monorepo-tsconfig.d.ts.map +1 -1
- package/lib/commands/monorepo-tsconfig.js.map +1 -1
- package/lib/commands/monorepo-upgrade.d.ts.map +1 -1
- package/lib/commands/monorepo-upgrade.js +4 -2
- package/lib/commands/monorepo-upgrade.js.map +1 -1
- package/lib/commands/run-if-version-mismatch.d.ts.map +1 -1
- package/lib/commands/run-if-version-mismatch.js +6 -4
- package/lib/commands/run-if-version-mismatch.js.map +1 -1
- package/lib/commands/test.d.ts.map +1 -1
- package/lib/commands/test.js +3 -1
- package/lib/commands/test.js.map +1 -1
- package/lib/common/cache/native.npm.js +2 -2
- package/lib/common/cache/native.npm.js.map +1 -1
- package/lib/common/functions/cli.d.ts +4 -1
- package/lib/common/functions/cli.d.ts.map +1 -1
- package/lib/common/functions/cli.js +3 -3
- package/lib/common/functions/cli.js.map +1 -1
- package/lib/common/git/git.d.ts +1 -0
- package/lib/common/git/git.d.ts.map +1 -1
- package/lib/common/git/git.js +38 -0
- package/lib/common/git/git.js.map +1 -1
- package/lib/common/package-manager/driver.abstract.d.ts +3 -3
- package/lib/common/package-manager/driver.abstract.d.ts.map +1 -1
- package/lib/common/package-manager/driver.abstract.js +2 -4
- package/lib/common/package-manager/driver.abstract.js.map +1 -1
- package/lib/common/package-manager/driver.pnpm.d.ts.map +1 -1
- package/lib/common/package-manager/driver.pnpm.js +6 -3
- package/lib/common/package-manager/driver.pnpm.js.map +1 -1
- package/lib/common/package-manager/functions.d.ts.map +1 -1
- package/lib/common/package-manager/functions.js.map +1 -1
- package/lib/common/package-manager/package-manager.d.ts +2 -2
- package/lib/common/package-manager/package-manager.d.ts.map +1 -1
- package/lib/common/package-manager/package-manager.js +0 -3
- package/lib/common/package-manager/package-manager.js.map +1 -1
- package/lib/common/package-manager/proxy.js +1 -1
- package/lib/common/package-manager/proxy.js.map +1 -1
- package/lib/common/shared-jobs/clear-cache.d.ts +3 -0
- package/lib/common/shared-jobs/clear-cache.d.ts.map +1 -0
- package/lib/common/shared-jobs/clear-cache.js +14 -0
- package/lib/common/shared-jobs/clear-cache.js.map +1 -0
- package/lib/common/shared-jobs/cnpm-sync.d.ts +0 -2
- package/lib/common/shared-jobs/cnpm-sync.d.ts.map +1 -1
- package/lib/common/shared-jobs/cnpm-sync.js +1 -22
- package/lib/common/shared-jobs/cnpm-sync.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 +6 -0
- package/lib/common/shared-jobs/detect-change-job.js.map +1 -1
- package/lib/common/taball/decompress.d.ts.map +1 -1
- package/lib/common/taball/decompress.js +4 -1
- package/lib/common/taball/decompress.js.map +1 -1
- package/lib/common/taball/file-download.js +2 -7
- package/lib/common/taball/file-download.js.map +1 -1
- package/lib/common/temp-work-folder.d.ts +2 -2
- package/lib/common/temp-work-folder.d.ts.map +1 -1
- package/lib/common/temp-work-folder.js.map +1 -1
- package/lib/common/version.generated.d.ts +2 -2
- package/lib/common/version.generated.js +2 -2
- package/lib/main.js +1 -1
- package/lib/main.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/command-file-map.generated.ts +2 -1
- package/src/command-file-map.generator.ts +2 -2
- package/src/commands/detect-package-change.ts +3 -1
- package/src/commands/monorepo-bump-version.ts +17 -28
- package/src/commands/monorepo-cnpm-sync.ts +14 -2
- package/src/commands/monorepo-invalid.ts +4 -2
- package/src/commands/monorepo-link-binaries.ts +168 -0
- package/src/commands/monorepo-publish.ts +58 -54
- package/src/commands/monorepo-tsconfig.ts +1 -2
- package/src/commands/monorepo-upgrade.ts +4 -3
- package/src/commands/run-if-version-mismatch.ts +7 -7
- package/src/commands/test.ts +3 -1
- package/src/common/cache/native.npm.ts +2 -2
- package/src/common/functions/cli.ts +6 -3
- package/src/common/git/git.ts +44 -6
- package/src/common/package-manager/driver.abstract.ts +4 -7
- package/src/common/package-manager/driver.pnpm.ts +8 -3
- package/src/common/package-manager/functions.ts +2 -12
- package/src/common/package-manager/package-manager.ts +3 -13
- package/src/common/package-manager/proxy.ts +1 -1
- package/src/common/shared-jobs/clear-cache.ts +14 -0
- package/src/common/shared-jobs/cnpm-sync.ts +1 -25
- package/src/common/shared-jobs/detect-change-job.ts +7 -0
- package/src/common/taball/decompress.ts +3 -1
- package/src/common/taball/file-download.ts +4 -15
- package/src/common/temp-work-folder.ts +2 -2
- package/src/common/version.generated.ts +2 -2
- package/src/common/version.generator.ts +1 -1
- package/src/main.ts +2 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { createWorkspace, type IPackageInfo } from '@build-script/monorepo-lib';
|
|
2
2
|
import { loadJsonFile, writeJsonFileBack } from '@idlebox/json-edit';
|
|
3
3
|
import { logger } from '@idlebox/logger';
|
|
4
4
|
import { resolve } from 'node:path';
|
|
@@ -17,8 +17,9 @@ export async function main() {
|
|
|
17
17
|
const dryRun = argv.flag('--dry') > 0;
|
|
18
18
|
const skipUpdate = argv.flag('--skip-update') > 0;
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
const
|
|
20
|
+
const workspace = await createWorkspace();
|
|
21
|
+
const packageManager = await createPackageManager(PackageManagerUsageKind.Read, workspace);
|
|
22
|
+
const projects = await workspace.listPackages();
|
|
22
23
|
|
|
23
24
|
logger.log('Collecting local project versions:');
|
|
24
25
|
const alldeps: Record<string, string> = {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createWorkspace } from '@build-script/monorepo-lib';
|
|
1
2
|
import type { IArgsReaderApi } from '@idlebox/args';
|
|
2
3
|
import { logger } from '@idlebox/logger';
|
|
3
4
|
import { checkChildProcessResult } from '@idlebox/node';
|
|
@@ -29,17 +30,16 @@ export async function main(argv: IArgsReaderApi) {
|
|
|
29
30
|
|
|
30
31
|
const commands = argv.unused();
|
|
31
32
|
if (commands.length === 0 || !process.argv.includes('--')) {
|
|
32
|
-
logger.error(
|
|
33
|
-
'参数中必须包含"--",并且后面跟随要运行的命令。\n 示例: run-if-version-mismatch --quiet -- pnpm publish',
|
|
34
|
-
);
|
|
33
|
+
logger.error('参数中必须包含"--",并且后面跟随要运行的命令。\n 示例: run-if-version-mismatch --quiet -- pnpm publish');
|
|
35
34
|
return 22;
|
|
36
35
|
}
|
|
37
36
|
logger.debug('即将运行命令: %s', commands.join(' '));
|
|
38
37
|
|
|
39
|
-
const
|
|
38
|
+
const workspace = await createWorkspace();
|
|
39
|
+
const packageManager = await createPackageManager(PackageManagerUsageKind.Read, workspace);
|
|
40
40
|
|
|
41
|
-
const
|
|
42
|
-
logger.log('工作目录: %s',
|
|
41
|
+
const packageInfo = await workspace.getNearestPackage(process.cwd());
|
|
42
|
+
logger.log('工作目录: %s', packageInfo.name);
|
|
43
43
|
|
|
44
44
|
const packageJson = await packageManager.loadPackageJson();
|
|
45
45
|
logger.log('包名: %s', packageJson.name);
|
|
@@ -62,7 +62,7 @@ export async function main(argv: IArgsReaderApi) {
|
|
|
62
62
|
|
|
63
63
|
logger.log('本地版本 (%s) !== 远程版本 (%s),开始执行命令!', packageJson.version, rversion);
|
|
64
64
|
const r = await execa(commands[0], commands.slice(1), {
|
|
65
|
-
cwd:
|
|
65
|
+
cwd: packageInfo.absolute,
|
|
66
66
|
stdout: 'inherit',
|
|
67
67
|
stderr: 'inherit',
|
|
68
68
|
});
|
package/src/commands/test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createSimpleProject } from '@build-script/monorepo-lib';
|
|
1
2
|
import { CommandDefine } from '../common/functions/cli.js';
|
|
2
3
|
import { PackageManagerUsageKind } from '../common/package-manager/driver.abstract.js';
|
|
3
4
|
import { createPackageManager } from '../common/package-manager/package-manager.js';
|
|
@@ -10,7 +11,8 @@ export class Command extends CommandDefine {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export async function main() {
|
|
13
|
-
const
|
|
14
|
+
const w = await createSimpleProject();
|
|
15
|
+
const pm = await createPackageManager(PackageManagerUsageKind.Read, w);
|
|
14
16
|
const cache = await pm.createCacheHandler();
|
|
15
17
|
|
|
16
18
|
const r = await cache.downloadTarball('react-dom', 'latest');
|
|
@@ -117,13 +117,13 @@ export async function fetchNpmWithCache(path: string, name: string, registry: st
|
|
|
117
117
|
|
|
118
118
|
const options: Required<IMyOpts> = Object.assign({}, defOpt, _options);
|
|
119
119
|
|
|
120
|
-
let
|
|
120
|
+
let _try_cnt = 0;
|
|
121
121
|
let retry = options.maxRetry;
|
|
122
122
|
let retry_timeout = 500;
|
|
123
123
|
let json: IRegistryMetadata | undefined;
|
|
124
124
|
|
|
125
125
|
while (true) {
|
|
126
|
-
|
|
126
|
+
_try_cnt++;
|
|
127
127
|
retry--;
|
|
128
128
|
try {
|
|
129
129
|
const proxy = getProxyValue(registry);
|
|
@@ -15,6 +15,9 @@ function die(msg: string) {
|
|
|
15
15
|
export const argv = createArgsReader(process.argv.slice(2));
|
|
16
16
|
|
|
17
17
|
type ArgDefine = {
|
|
18
|
+
/**
|
|
19
|
+
* 为false时在后面加一个 <value>
|
|
20
|
+
*/
|
|
18
21
|
flag: boolean;
|
|
19
22
|
description: string;
|
|
20
23
|
};
|
|
@@ -74,16 +77,16 @@ export abstract class CommandDefine {
|
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
export const isVerbose = argv.flag('--verbose') > 0;
|
|
78
80
|
export const isQuiet = argv.flag(['--silent', '-s', '--quiet']) > 0;
|
|
79
81
|
export const isJsonOutput = argv.flag('--json') > 0;
|
|
80
82
|
export const isHelp = argv.flag(['--help', '-h']) > 0;
|
|
81
83
|
export const distTagInput = argv.single('--dist-tag') || 'latest';
|
|
82
84
|
export const registryInput = argv.single('--registry') || 'detect';
|
|
83
|
-
export const isDebugMode = argv.flag('--debug') > 0;
|
|
85
|
+
export const isDebugMode = argv.flag(['--debug', '-d']) > 0;
|
|
86
|
+
export const isVerbose = argv.flag(['--debug', '-d']) > 1;
|
|
84
87
|
|
|
85
88
|
if (isVerbose && isQuiet) {
|
|
86
|
-
die(
|
|
89
|
+
die(`不能同时使用 --debug 和 --quiet: ${process.argv}`);
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
export function pArgS(s: string) {
|
package/src/common/git/git.ts
CHANGED
|
@@ -61,15 +61,53 @@ export class GitWorkingTree {
|
|
|
61
61
|
}
|
|
62
62
|
const files = lines.slice(titleLine + 1);
|
|
63
63
|
|
|
64
|
-
logger.debug(
|
|
65
|
-
' 文件更改: %d 个 (%s%s)',
|
|
66
|
-
files.length,
|
|
67
|
-
files.slice(0, 5).join(', '),
|
|
68
|
-
files.length > 5 ? ' ...' : '',
|
|
69
|
-
);
|
|
64
|
+
logger.debug(' 文件更改: %d 个 (%s%s)', files.length, files.slice(0, 5).join(', '), files.length > 5 ? ' ...' : '');
|
|
70
65
|
|
|
71
66
|
return files.map((item) => {
|
|
72
67
|
return item.replace('Would remove ', '');
|
|
73
68
|
});
|
|
74
69
|
}
|
|
70
|
+
|
|
71
|
+
async fileDiff(file: string) {
|
|
72
|
+
const { stdout } = await this._exec(['diff', '--color=never', '-U0', `HEAD~1`, file]);
|
|
73
|
+
logger.verbose(stdout.trimEnd());
|
|
74
|
+
const lines = stdout.toString().trim().split('\n').slice(4);
|
|
75
|
+
|
|
76
|
+
let diff = formatChangeSideBySide('Published', 'Local');
|
|
77
|
+
let last_change = { old: '', new: '' };
|
|
78
|
+
for (const line of lines) {
|
|
79
|
+
if (line.startsWith('@@ ')) {
|
|
80
|
+
diff += formatChangeSideBySide(last_change.old, last_change.new);
|
|
81
|
+
last_change = { old: '', new: '' };
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (line.startsWith('+')) {
|
|
86
|
+
last_change.new += `${line.slice(1)}\n`;
|
|
87
|
+
} else if (line.startsWith('-')) {
|
|
88
|
+
last_change.old += `${line.slice(1)}\n`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
diff += formatChangeSideBySide(last_change.old, last_change.new);
|
|
92
|
+
return diff.trim();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function formatChangeSideBySide(oldText: string, newText: string): string {
|
|
97
|
+
if (!oldText && !newText) {
|
|
98
|
+
return '';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const oldLines = oldText.split('\n').map((l) => l.replaceAll('\t', ' '));
|
|
102
|
+
const newLines = newText.split('\n').map((l) => l.replaceAll('\t', ' '));
|
|
103
|
+
|
|
104
|
+
const maxLines = Math.max(oldLines.length, newLines.length);
|
|
105
|
+
const formattedLines: string[] = [];
|
|
106
|
+
for (let i = 0; i < maxLines; i++) {
|
|
107
|
+
const oldLine = oldLines[i] || '';
|
|
108
|
+
const newLine = newLines[i] || '';
|
|
109
|
+
const formattedLine = `${oldLine.padEnd(40, ' ')} | ${newLine}`;
|
|
110
|
+
formattedLines.push(formattedLine);
|
|
111
|
+
}
|
|
112
|
+
return `${formattedLines.join('\n')}\n`;
|
|
75
113
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { MonorepoWorkspace } from '@build-script/monorepo-lib';
|
|
2
1
|
import { ensureLinkTarget } from '@idlebox/ensure-symlink';
|
|
3
2
|
import { logger } from '@idlebox/logger';
|
|
4
3
|
import { execLazyError, exists, writeFileIfChange } from '@idlebox/node';
|
|
5
4
|
import { execa } from 'execa';
|
|
6
5
|
import { dirname, resolve } from 'node:path';
|
|
7
6
|
import { split as splitCmd } from 'split-cmd';
|
|
7
|
+
import type { WorkspaceBase } from '@build-script/monorepo-lib';
|
|
8
8
|
import { NpmCacheHandler } from '../cache/native.npm.js';
|
|
9
9
|
import { registryInput } from '../functions/cli.js';
|
|
10
10
|
import { TempWorkingFolder } from '../temp-work-folder.js';
|
|
@@ -29,7 +29,7 @@ export abstract class PackageManager {
|
|
|
29
29
|
|
|
30
30
|
constructor(
|
|
31
31
|
public readonly usageKind: PackageManagerUsageKind,
|
|
32
|
-
public readonly workspace:
|
|
32
|
+
public readonly workspace: WorkspaceBase,
|
|
33
33
|
subdir = process.cwd(),
|
|
34
34
|
) {
|
|
35
35
|
this.configTemp = new TempWorkingFolder(this.workspace, 'package-manager', true);
|
|
@@ -48,10 +48,7 @@ export abstract class PackageManager {
|
|
|
48
48
|
|
|
49
49
|
const pkg = await this.loadPackageJson();
|
|
50
50
|
if (pkg.publishConfig?.['packCommand']) {
|
|
51
|
-
const cmds =
|
|
52
|
-
typeof pkg.publishConfig['packCommand'] === 'string'
|
|
53
|
-
? splitCmd(pkg.publishConfig['packCommand'])
|
|
54
|
-
: pkg.publishConfig['packCommand'];
|
|
51
|
+
const cmds = typeof pkg.publishConfig['packCommand'] === 'string' ? splitCmd(pkg.publishConfig['packCommand']) : pkg.publishConfig['packCommand'];
|
|
55
52
|
|
|
56
53
|
if (!Array.isArray(cmds)) {
|
|
57
54
|
logger.fatal`publishConfig.packCommand必须是字符串或字符串数组, 但实际是: ${typeof pkg.publishConfig['packCommand']}`;
|
|
@@ -122,7 +119,7 @@ export abstract class PackageManager {
|
|
|
122
119
|
logger.debug(' 发布成功: %s @ %s [%s]', r.name, r.version, r.published);
|
|
123
120
|
return r;
|
|
124
121
|
} catch (e: any) {
|
|
125
|
-
logger.error` tarball发布失败! ${e}`;
|
|
122
|
+
logger.error` tarball发布失败! ${e.message}`;
|
|
126
123
|
throw e;
|
|
127
124
|
}
|
|
128
125
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { prettyPrintError } from '@idlebox/common';
|
|
2
1
|
import { logger } from '@idlebox/logger';
|
|
3
2
|
import { execLazyError, exists } from '@idlebox/node';
|
|
4
3
|
import { resolve } from 'node:path';
|
|
@@ -33,7 +32,7 @@ class RegistryError extends Error {
|
|
|
33
32
|
super(error.summary || 'no error summary');
|
|
34
33
|
|
|
35
34
|
if (this.error.detail) {
|
|
36
|
-
this.stack = this.error.detail;
|
|
35
|
+
this.stack = this.error.detail.trimEnd() + '\n' + this.stack;
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
|
|
@@ -99,7 +98,13 @@ export class PNPM extends PackageManager {
|
|
|
99
98
|
|
|
100
99
|
logger.warn`publish long<${pack}> error: ${e}`;
|
|
101
100
|
console.error(all);
|
|
102
|
-
|
|
101
|
+
|
|
102
|
+
// prettyPrintError(`publish package`, {
|
|
103
|
+
// message: `${e.message}\ncommand: ${this.binary} ${cmds.join(' ')}\nworking dir: ${cwd}`,
|
|
104
|
+
// stack: e.stack,
|
|
105
|
+
// });
|
|
106
|
+
|
|
107
|
+
e.message = `${e.message}\ncommand: ${this.binary} ${cmds.join(' ')}\nworking dir: ${cwd}`;
|
|
103
108
|
|
|
104
109
|
throw e;
|
|
105
110
|
}
|
|
@@ -69,13 +69,7 @@ async function resolveNpmVersion([packageName, currentVersion]: [string, string]
|
|
|
69
69
|
|
|
70
70
|
return [packageName, newVersion, currentVersion];
|
|
71
71
|
} catch (e: any) {
|
|
72
|
-
console.error(
|
|
73
|
-
'[npm:resolve][try %s] failed fetch package "%s": [%s] %s',
|
|
74
|
-
currentTry,
|
|
75
|
-
packageName,
|
|
76
|
-
e.code,
|
|
77
|
-
e.message
|
|
78
|
-
);
|
|
72
|
+
console.error('[npm:resolve][try %s] failed fetch package "%s": [%s] %s', currentTry, packageName, e.code, e.message);
|
|
79
73
|
lastError = e;
|
|
80
74
|
if (e.code === 'ECONNRESET') {
|
|
81
75
|
retryCnt++;
|
|
@@ -97,11 +91,7 @@ export async function resolveNpm(versions: Map<string, string>) {
|
|
|
97
91
|
|
|
98
92
|
const nc = Number.parseInt((await getNpmConfigValue('network-concurrency')) || '4');
|
|
99
93
|
|
|
100
|
-
for await (const [packName, newVersion, currentVersion] of asyncPool(
|
|
101
|
-
nc,
|
|
102
|
-
[...versions.entries()],
|
|
103
|
-
resolveNpmVersion
|
|
104
|
-
)) {
|
|
94
|
+
for await (const [packName, newVersion, currentVersion] of asyncPool(nc, [...versions.entries()], resolveNpmVersion)) {
|
|
105
95
|
versions.set(packName, newVersion);
|
|
106
96
|
|
|
107
97
|
let updated = '';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { WorkspaceBase } from '@build-script/monorepo-lib';
|
|
2
2
|
import { commandInPath, PathEnvironment } from '@idlebox/node';
|
|
3
3
|
import type { PackageManager, PackageManagerUsageKind } from './driver.abstract.js';
|
|
4
4
|
import { NPM } from './driver.npm.js';
|
|
@@ -7,21 +7,11 @@ import { reconfigureProxyWithNpmrc } from './proxy.js';
|
|
|
7
7
|
|
|
8
8
|
export type IPackageManager = PackageManager;
|
|
9
9
|
|
|
10
|
-
type PackageManagerConstructor = new (
|
|
11
|
-
usage: PackageManagerUsageKind,
|
|
12
|
-
workspace: MonorepoWorkspace,
|
|
13
|
-
subdir?: string,
|
|
14
|
-
) => IPackageManager;
|
|
10
|
+
type PackageManagerConstructor = new (usage: PackageManagerUsageKind, workspace: WorkspaceBase, subdir?: string) => IPackageManager;
|
|
15
11
|
|
|
16
12
|
let pmCls: PackageManagerConstructor | undefined;
|
|
17
13
|
|
|
18
|
-
export async function createPackageManager(
|
|
19
|
-
usage: PackageManagerUsageKind,
|
|
20
|
-
workspace?: MonorepoWorkspace,
|
|
21
|
-
subdir?: string,
|
|
22
|
-
): Promise<IPackageManager> {
|
|
23
|
-
if (!workspace) workspace = await createWorkspace();
|
|
24
|
-
|
|
14
|
+
export async function createPackageManager(usage: PackageManagerUsageKind, workspace: WorkspaceBase, subdir?: string): Promise<IPackageManager> {
|
|
25
15
|
if (pmCls) {
|
|
26
16
|
return new pmCls(usage, workspace, subdir);
|
|
27
17
|
}
|
|
@@ -50,7 +50,7 @@ export function getProxyValue(url: string) {
|
|
|
50
50
|
logger.verbose(` hit equals`);
|
|
51
51
|
return '';
|
|
52
52
|
}
|
|
53
|
-
const domainEnding = npPart[0] === '.' ? npPart :
|
|
53
|
+
const domainEnding = npPart[0] === '.' ? npPart : `.${npPart}`;
|
|
54
54
|
if (domain.endsWith(domainEnding)) {
|
|
55
55
|
logger.verbose(` hit ending: ${domainEnding}`);
|
|
56
56
|
return '';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { logger } from '@idlebox/logger';
|
|
2
|
+
import type { PackageManager } from '../package-manager/driver.abstract.js';
|
|
3
|
+
|
|
4
|
+
export async function clearNpmMetaCache(pm: PackageManager, names: readonly string[]) {
|
|
5
|
+
logger.debug('刷新npm缓存...');
|
|
6
|
+
try {
|
|
7
|
+
const cache = await pm.createCacheHandler();
|
|
8
|
+
for (const name of names) {
|
|
9
|
+
await cache.deleteMetadata(name);
|
|
10
|
+
}
|
|
11
|
+
} catch (e) {
|
|
12
|
+
logger.warn`failed flush npm cache: ${e}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import type { IPackageInfo } from '@build-script/monorepo-lib';
|
|
2
1
|
import { logger } from '@idlebox/logger';
|
|
3
2
|
import { checkChildProcessResult, printLine } from '@idlebox/node';
|
|
4
3
|
import { execa } from 'execa';
|
|
5
4
|
import { CSI, isQuiet } from '../functions/cli.js';
|
|
6
|
-
import { PackageManagerUsageKind } from '../package-manager/driver.abstract.js';
|
|
7
|
-
import { createPackageManager } from '../package-manager/package-manager.js';
|
|
8
|
-
|
|
9
|
-
export function cnpmSync(list: ReadonlyArray<IPackageInfo>, collectOutput = isQuiet, dryRun = false) {
|
|
10
|
-
const names = list
|
|
11
|
-
.filter((e) => {
|
|
12
|
-
return !!e.packageJson.name && !e.packageJson.private;
|
|
13
|
-
})
|
|
14
|
-
.map((e) => e.packageJson.name);
|
|
15
|
-
|
|
16
|
-
return cnpmSyncNames(names, collectOutput, dryRun);
|
|
17
|
-
}
|
|
18
5
|
|
|
19
6
|
export async function cnpmSyncNames(names: ReadonlyArray<string>, collectOutput = isQuiet, dryRun = false) {
|
|
20
7
|
console.log(`🔃 cnpm同步${names.length}个包`);
|
|
@@ -43,24 +30,13 @@ export async function cnpmSyncNames(names: ReadonlyArray<string>, collectOutput
|
|
|
43
30
|
},
|
|
44
31
|
});
|
|
45
32
|
|
|
46
|
-
logger.debug('刷新npm缓存...');
|
|
47
|
-
try {
|
|
48
|
-
const pm = await createPackageManager(PackageManagerUsageKind.Read);
|
|
49
|
-
const cache = await pm.createCacheHandler();
|
|
50
|
-
for (const name of names) {
|
|
51
|
-
await cache.deleteMetadata(name);
|
|
52
|
-
}
|
|
53
|
-
} catch (e) {
|
|
54
|
-
logger.warn`failed flush npm cache: ${e}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
33
|
try {
|
|
58
34
|
checkChildProcessResult(p);
|
|
59
35
|
if (collectOutput) {
|
|
60
36
|
process.stderr.write(`${CSI}K`);
|
|
61
37
|
}
|
|
62
38
|
console.log(' ✨ cnpm同步请求成功');
|
|
63
|
-
} catch (
|
|
39
|
+
} catch (_e) {
|
|
64
40
|
if (collectOutput) {
|
|
65
41
|
printLine();
|
|
66
42
|
logger.error(p.all as any);
|
|
@@ -72,5 +72,12 @@ export async function executeChangeDetect(pm: IPackageManager, options: IDetectO
|
|
|
72
72
|
const changedFiles = await gitrepo.commitChanges();
|
|
73
73
|
logger.verbose` changed files: list<${changedFiles}>`;
|
|
74
74
|
|
|
75
|
+
if (logger.debug.isEnabled) {
|
|
76
|
+
if (changedFiles.includes('package.json')) {
|
|
77
|
+
const diff = await gitrepo.fileDiff('package.json');
|
|
78
|
+
logger.debug(` - package.json 文件的修改:\n${diff}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
75
82
|
return { changedFiles, hasChange: changedFiles.length > 0, remoteVersion: remotePackage.version };
|
|
76
83
|
}
|
|
@@ -24,7 +24,7 @@ export async function downloadFileCached(url: string, file: string) {
|
|
|
24
24
|
} catch {}
|
|
25
25
|
|
|
26
26
|
if (meta?.url === url) {
|
|
27
|
-
logger.
|
|
27
|
+
logger.debug(' -> 已经下载');
|
|
28
28
|
return file;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -108,9 +108,7 @@ function send_request(url: string, headers: OutgoingHttpHeaders): Promise<any> {
|
|
|
108
108
|
logger.debug(`[http] 请求 ${url}`);
|
|
109
109
|
|
|
110
110
|
const request = get(url, { headers }, (response) => {
|
|
111
|
-
logger.debug(
|
|
112
|
-
`[http] 响应 ${response.statusCode} [encoding: ${response.headers['content-encoding']}][${response.headers['content-length']} bytes]`,
|
|
113
|
-
);
|
|
111
|
+
logger.debug(`[http] 响应 ${response.statusCode} [encoding: ${response.headers['content-encoding']}][${response.headers['content-length']} bytes]`);
|
|
114
112
|
if (response.statusCode === 200) {
|
|
115
113
|
const bytes = Number.parseInt(response.headers['content-length'] ?? '--');
|
|
116
114
|
|
|
@@ -118,9 +116,7 @@ function send_request(url: string, headers: OutgoingHttpHeaders): Promise<any> {
|
|
|
118
116
|
let downloaded = 0;
|
|
119
117
|
response.on('data', (bs) => {
|
|
120
118
|
downloaded += bs.length;
|
|
121
|
-
process.stderr.write(
|
|
122
|
-
`\x1B[2mdownload: ${downloaded} of ${bytes} bytes (${Math.round((downloaded / bytes) * 100)}%)\x1B[0m\r`,
|
|
123
|
-
);
|
|
119
|
+
process.stderr.write(`\x1B[2mdownload: ${downloaded} of ${bytes} bytes (${Math.round((downloaded / bytes) * 100)}%)\x1B[0m\r`);
|
|
124
120
|
});
|
|
125
121
|
response.on('end', () => {
|
|
126
122
|
process.stderr.write('\x1B[K');
|
|
@@ -144,14 +140,7 @@ function send_request(url: string, headers: OutgoingHttpHeaders): Promise<any> {
|
|
|
144
140
|
break;
|
|
145
141
|
}
|
|
146
142
|
resolve(Object.assign(response, { stream }));
|
|
147
|
-
} else if (
|
|
148
|
-
(response.statusCode === 302 ||
|
|
149
|
-
response.statusCode === 301 ||
|
|
150
|
-
response.statusCode === 303 ||
|
|
151
|
-
response.statusCode === 307 ||
|
|
152
|
-
response.statusCode === 308) &&
|
|
153
|
-
response.headers.location
|
|
154
|
-
) {
|
|
143
|
+
} else if ((response.statusCode === 302 || response.statusCode === 301 || response.statusCode === 303 || response.statusCode === 307 || response.statusCode === 308) && response.headers.location) {
|
|
155
144
|
reject(new RedirectError(url, response.headers.location, response.statusCode));
|
|
156
145
|
} else {
|
|
157
146
|
reject(new HttpError(url, response.statusCode as number, response.statusMessage as string));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WorkspaceBase } from '@build-script/monorepo-lib';
|
|
2
2
|
import { registerGlobalLifecycle } from '@idlebox/common';
|
|
3
3
|
import { writeJsonFile } from '@idlebox/json-edit';
|
|
4
4
|
import { logger } from '@idlebox/logger';
|
|
@@ -15,7 +15,7 @@ export class TempWorkingFolder {
|
|
|
15
15
|
private _exists = false;
|
|
16
16
|
|
|
17
17
|
constructor(
|
|
18
|
-
private readonly workspace:
|
|
18
|
+
private readonly workspace: WorkspaceBase,
|
|
19
19
|
name: string,
|
|
20
20
|
__internal_isChild = false,
|
|
21
21
|
) {
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
* GENERATED FILE, DO NOT MODIFY
|
|
8
8
|
* 这是生成的文件,千万不要修改
|
|
9
9
|
*
|
|
10
|
-
* @build-script/codegen 1.0.
|
|
10
|
+
* @build-script/codegen 1.0.5 - The Simple Code Generater
|
|
11
11
|
* https://github.com/GongT/baobao
|
|
12
12
|
*
|
|
13
13
|
******************************************************************************/
|
|
14
14
|
|
|
15
|
-
export const self_package_version = "0.0.
|
|
15
|
+
export const self_package_version = "0.0.5";
|
|
16
16
|
export const self_package_name = "@build-script/package-tools";
|
|
17
17
|
export const self_package_repository = "undefined";
|
|
18
18
|
|
|
@@ -2,7 +2,7 @@ import type { FileBuilder, IOutputShim } from '@build-script/heft-plugin-base';
|
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
|
|
5
|
-
export function generate(
|
|
5
|
+
export function generate(_builder: FileBuilder, logger: IOutputShim) {
|
|
6
6
|
const pkgFile = path.resolve(__dirname, '../../package.json');
|
|
7
7
|
const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
|
|
8
8
|
|
package/src/main.ts
CHANGED
|
@@ -3,17 +3,7 @@ import { AppExit, prettyPrintError } from '@idlebox/common';
|
|
|
3
3
|
import { createRootLogger, EnableLogLevel } from '@idlebox/logger';
|
|
4
4
|
import { resolve } from 'node:path';
|
|
5
5
|
import cmdList from './command-file-map.generated.js';
|
|
6
|
-
import {
|
|
7
|
-
argv,
|
|
8
|
-
DieError,
|
|
9
|
-
isHelp,
|
|
10
|
-
isQuiet,
|
|
11
|
-
isVerbose,
|
|
12
|
-
pCmd,
|
|
13
|
-
pDesc,
|
|
14
|
-
printCommonOptions,
|
|
15
|
-
type CommandDefine,
|
|
16
|
-
} from './common/functions/cli.js';
|
|
6
|
+
import { argv, DieError, isHelp, isQuiet, isVerbose, pCmd, pDesc, printCommonOptions, type CommandDefine } from './common/functions/cli.js';
|
|
17
7
|
import { registerShutdownHandlers, shutdown } from './common/functions/global-lifecycle.js';
|
|
18
8
|
import { configureProxyFromEnvironment } from './common/package-manager/proxy.js';
|
|
19
9
|
|
|
@@ -121,9 +111,7 @@ async function main() {
|
|
|
121
111
|
}
|
|
122
112
|
|
|
123
113
|
function printLegend() {
|
|
124
|
-
process.stderr.write(
|
|
125
|
-
`\x1B[2mUsage:\x1B[0m\n ${usage_prefix} \x1B[38;5;10m<命令>\x1B[0m \x1B[38;5;14m[命令参数]\x1B[0m\n`,
|
|
126
|
-
);
|
|
114
|
+
process.stderr.write(`\x1B[2mUsage:\x1B[0m\n ${usage_prefix} \x1B[38;5;10m<命令>\x1B[0m \x1B[38;5;14m[命令参数]\x1B[0m\n`);
|
|
127
115
|
}
|
|
128
116
|
|
|
129
117
|
function table() {
|