@build-script/package-tools 0.0.3 → 0.0.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@build-script/package-tools",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "bin": {
6
6
  "package-tools": "./load.js",
7
7
  "njspkg": "./load.js"
@@ -21,14 +21,14 @@
21
21
  "source-map-support": "^0.5.21",
22
22
  "targz": "^1.0.1",
23
23
  "tiny-async-pool": "^2.1.0",
24
- "@build-script/monorepo-lib": "^0.0.2",
25
- "@idlebox/common": "^1.4.15",
26
- "@idlebox/args": "^0.0.10",
27
- "@idlebox/ensure-symlink": "^1.0.33",
28
- "@idlebox/logger": "^0.0.3",
29
- "@idlebox/json-edit": "^0.0.2",
30
- "@idlebox/dependency-graph": "^0.0.2",
31
- "@idlebox/node": "^1.4.8"
24
+ "@build-script/monorepo-lib": "^0.0.3",
25
+ "@idlebox/common": "^1.4.16",
26
+ "@idlebox/json-edit": "^0.0.3",
27
+ "@idlebox/args": "^0.0.11",
28
+ "@idlebox/ensure-symlink": "^1.0.34",
29
+ "@idlebox/logger": "^0.0.4",
30
+ "@idlebox/node": "^1.4.9",
31
+ "@idlebox/dependency-graph": "^0.0.3"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@rushstack/heft": "^0.74.0",
@@ -41,10 +41,10 @@
41
41
  "@types/targz": "^1.0.5",
42
42
  "@types/tiny-async-pool": "^2.0.3",
43
43
  "@types/tinycolor2": "^1.4.6",
44
- "@build-script/codegen": "^1.0.2",
45
- "@build-script/single-dog-asset": "^1.0.36",
44
+ "@build-script/codegen": "^1.0.4",
46
45
  "@internal/local-rig": "^1.0.1",
47
- "@mpis/run": "^0.0.3"
46
+ "@build-script/single-dog-asset": "^1.0.37",
47
+ "@mpis/run": "^0.0.4"
48
48
  },
49
49
  "license": "MIT",
50
50
  "author": "GongT <admin@gongt.me>",
@@ -7,7 +7,7 @@
7
7
  * GENERATED FILE, DO NOT MODIFY
8
8
  * 这是生成的文件,千万不要修改
9
9
  *
10
- * @build-script/codegen 1.0.2 - The Simple Code Generater
10
+ * @build-script/codegen 1.0.4 - The Simple Code Generater
11
11
  * https://github.com/GongT/baobao
12
12
  *
13
13
  ******************************************************************************/
@@ -57,7 +57,7 @@ class BuildPackageJob implements IWatchEvents {
57
57
  indexDisplay++;
58
58
  const { length } = this.state;
59
59
  const w = length.toFixed(0).length;
60
- console.log(`📦 [${indexDisplay.toFixed(0).padStart(w)}/${length}] ${this.project.name}`);
60
+ console.log(`${CSI}K📦 [${indexDisplay.toFixed(0).padStart(w)}/${length}] ${this.project.name}`);
61
61
  console.log(this.logText.join('\n'));
62
62
  this.logText.length = 0;
63
63
  });
@@ -65,7 +65,7 @@ class BuildPackageJob implements IWatchEvents {
65
65
  indexDisplay++;
66
66
  const { length } = this.state;
67
67
  const w = length.toFixed(0).length;
68
- console.log(`📦 [${indexDisplay.toFixed(0).padStart(w)}/${length}] ${this.project.name}`);
68
+ console.log(`${CSI}K📦 [${indexDisplay.toFixed(0).padStart(w)}/${length}] ${this.project.name}`);
69
69
  console.log(this.logText.join('\n'));
70
70
  prettyPrintError('❌pack failed', e);
71
71
  this.logText.length = 0;
@@ -89,10 +89,13 @@ class BuildPackageJob implements IWatchEvents {
89
89
  let shouldPublish = hasChange || changedFiles.length > 0;
90
90
  let localVersion = this.project.packageJson.version;
91
91
 
92
+ this.log(
93
+ ` 👀 ${changedFiles.length} 个文件有修改: ${changedFiles.slice(0, 3).join(', ')}${changedFiles.length > 3 ? ' ...' : ''}`,
94
+ );
92
95
  if (hasChange) {
93
96
  const packageJson = await pm.loadPackageJson();
94
97
  localVersion = await increaseVersion(packageJson, remoteVersion || '0.0.0');
95
- this.log(` ✍️ 已修改本地包版本: ${localVersion}`);
98
+ this.log(` ✍️ 已修改本地包版本: ${localVersion}`);
96
99
  }
97
100
  if (!shouldPublish) {
98
101
  this.log(` ✨ ${CSI}38;5;10m未发现修改${CSI}0m\n`);
@@ -109,9 +112,9 @@ class BuildPackageJob implements IWatchEvents {
109
112
  this.shouldPublish = await pm.pack(tempFile);
110
113
 
111
114
  if (remoteVersion) {
112
- this.log(` 🎈 即将发布新版本 "${this.project.packageJson.version}" 以更新远程版本 "${remoteVersion}"`);
115
+ this.log(` 🎈 即将发布新版本 "${localVersion}" 以更新远程版本 "${remoteVersion}"`);
113
116
  } else {
114
- this.log(` 🎈 即将发布初始版本 "${this.project.packageJson.version}"`);
117
+ this.log(` 🎈 即将发布初始版本 "${localVersion}"`);
115
118
  }
116
119
  this._onSuccess.fire();
117
120
  }
@@ -145,7 +148,16 @@ export async function main() {
145
148
  const projects = await workspace.listPackages();
146
149
 
147
150
  const concurrency = argv.flag(['--debug', '-d']) > 0 ? 1 : 10;
151
+ if (concurrency === 1) {
152
+ logger.warn`由于设置了--debug参数,运行模式改为单线程`;
153
+ }
148
154
  const graph = new BuilderDependencyGraph<BuildPackageJob>(concurrency, logger);
155
+
156
+ function debugSummary() {
157
+ const info = graph.debugFormatSummary();
158
+ process.stderr.write(`${CSI}K${info}\r`);
159
+ }
160
+
149
161
  const opts = options();
150
162
 
151
163
  const shouldPublishProjects = projects.filter((project) => {
@@ -163,20 +175,21 @@ export async function main() {
163
175
 
164
176
  let index = 0;
165
177
  for (const project of shouldPublishProjects) {
166
- graph.addNode(
167
- project.name,
168
- project.devDependencies,
169
- new BuildPackageJob(
170
- {
171
- index,
172
- length: shouldPublishProjects.length,
173
- options: opts,
174
- },
175
- project,
176
- workspace,
177
- ),
178
+ const job = new BuildPackageJob(
179
+ {
180
+ index,
181
+ length: shouldPublishProjects.length,
182
+ options: opts,
183
+ },
184
+ project,
185
+ workspace,
178
186
  );
179
187
 
188
+ job.onRunning(debugSummary);
189
+ job.onSuccess(debugSummary);
190
+ job.onFailed(debugSummary);
191
+ graph.addNode(project.name, project.devDependencies, job);
192
+
180
193
  index++;
181
194
  }
182
195
 
@@ -74,16 +74,16 @@ export abstract class CommandDefine {
74
74
  }
75
75
  }
76
76
 
77
- export const isVerbose = argv.flag('--verbose') > 0;
78
77
  export const isQuiet = argv.flag(['--silent', '-s', '--quiet']) > 0;
79
78
  export const isJsonOutput = argv.flag('--json') > 0;
80
79
  export const isHelp = argv.flag(['--help', '-h']) > 0;
81
80
  export const distTagInput = argv.single('--dist-tag') || 'latest';
82
81
  export const registryInput = argv.single('--registry') || 'detect';
83
- export const isDebugMode = argv.flag('--debug') > 0;
82
+ export const isDebugMode = argv.flag(['--debug', '-d']) > 0;
83
+ export const isVerbose = argv.flag(['--debug', '-d']) > 1;
84
84
 
85
85
  if (isVerbose && isQuiet) {
86
- die('不能同时使用 --verbose 和 --quiet');
86
+ die(`不能同时使用 --debug 和 --quiet: ${process.argv}`);
87
87
  }
88
88
 
89
89
  export function pArgS(s: string) {
@@ -72,4 +72,47 @@ export class GitWorkingTree {
72
72
  return item.replace('Would remove ', '');
73
73
  });
74
74
  }
75
+
76
+ async fileDiff(file: string) {
77
+ const { stdout } = await this._exec(['diff', '--color=never', '-U0', `HEAD~1`, file]);
78
+ logger.verbose(stdout.trimEnd());
79
+ const lines = stdout.toString().trim().split('\n').slice(4);
80
+
81
+ let diff = formatChangeSideBySide('Published', 'Local');
82
+ let last_change = { old: '', new: '' };
83
+ for (const line of lines) {
84
+ if (line.startsWith('@@ ')) {
85
+ diff += formatChangeSideBySide(last_change.old, last_change.new);
86
+ last_change = { old: '', new: '' };
87
+ continue;
88
+ }
89
+
90
+ if (line.startsWith('+')) {
91
+ last_change.new += line.slice(1) + '\n';
92
+ } else if (line.startsWith('-')) {
93
+ last_change.old += line.slice(1) + '\n';
94
+ }
95
+ }
96
+ diff += formatChangeSideBySide(last_change.old, last_change.new);
97
+ return diff.trim();
98
+ }
99
+ }
100
+
101
+ function formatChangeSideBySide(oldText: string, newText: string): string {
102
+ if (!oldText && !newText) {
103
+ return '';
104
+ }
105
+
106
+ const oldLines = oldText.split('\n').map((l) => l.replaceAll('\t', ' '));
107
+ const newLines = newText.split('\n').map((l) => l.replaceAll('\t', ' '));
108
+
109
+ const maxLines = Math.max(oldLines.length, newLines.length);
110
+ const formattedLines: string[] = [];
111
+ for (let i = 0; i < maxLines; i++) {
112
+ const oldLine = oldLines[i] || '';
113
+ const newLine = newLines[i] || '';
114
+ const formattedLine = `${oldLine.padEnd(40, ' ')} | ${newLine}`;
115
+ formattedLines.push(formattedLine);
116
+ }
117
+ return formattedLines.join('\n') + '\n';
75
118
  }
@@ -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.log(' -> 已经下载');
27
+ logger.debug(' -> 已经下载');
28
28
  return file;
29
29
  }
30
30
  }
@@ -7,12 +7,12 @@
7
7
  * GENERATED FILE, DO NOT MODIFY
8
8
  * 这是生成的文件,千万不要修改
9
9
  *
10
- * @build-script/codegen 1.0.2 - The Simple Code Generater
10
+ * @build-script/codegen 1.0.4 - 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.3";
15
+ export const self_package_version = "0.0.4";
16
16
  export const self_package_name = "@build-script/package-tools";
17
17
  export const self_package_repository = "undefined";
18
18