@fanwang/pack-util 3.2.0 → 3.2.1

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.
Files changed (2) hide show
  1. package/bin/index.js +30 -18
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -16,7 +16,7 @@ const program = new Command()
16
16
  program
17
17
  .name('pack-util')
18
18
  .description('Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.')
19
- .version('3.2.0')
19
+ .version('3.2.1')
20
20
 
21
21
  const limit = pLimit(10)
22
22
  async function getPackageInfos(packageManager) {
@@ -36,15 +36,16 @@ async function getPackageInfos(packageManager) {
36
36
  acc.add(key)
37
37
  if (pkg.peerDependencies) {
38
38
  Object.keys(pkg.peerDependencies).forEach((peer) => {
39
- const peerVersion = pkg.peerDependencies[peer]
39
+ let peerVersion = pkg.peerDependencies[peer]
40
+ if (peerVersion.includes('>='))
41
+ peerVersion = '*'
40
42
  // 只匹配版本号
41
43
  const versionRegex = /(\d+\.\d+\.\d+)/
42
44
  const versionMatch = peerVersion.match(versionRegex)
43
- if (versionMatch && versionMatch[1]) {
44
- const exactVersion = versionMatch[1]
45
- const peerPackageKey = `${peer}@${exactVersion}`
46
- acc.add(peerPackageKey)
47
- }
45
+ if (versionMatch && versionMatch[1])
46
+ acc.add(`${peer}@${versionMatch[1]}`)
47
+ else
48
+ acc.add(`${peer}@*`)
48
49
  })
49
50
  }
50
51
  return acc
@@ -71,15 +72,21 @@ async function getPackageInfos(packageManager) {
71
72
 
72
73
  let index = 0
73
74
  // 利用 npm pack 在外网上对 dependencies 中的所有包打包。
74
- // const packPackage = async (packageName) => {
75
- // const { stdout } = await execa('npm', ['pack', packageName, '--pack-destination=./node_modules_pack'])
76
- // index++
77
- // // console.log(`${index}: ${stdout}`)
78
- // process.stdout.clearLine()
79
- // process.stdout.cursorTo(0)
80
- // process.stdout.write(`${index}: ${stdout}`) // 在同一行打印处理进度
81
- // return stdout
82
- // }
75
+ async function packPackage(packageName) {
76
+ try {
77
+ const { stdout } = await execa('npm', ['pack', packageName, '--pack-destination=./node_modules_pack'])
78
+ index++
79
+ // console.log(`${index}: ${stdout}`)
80
+ process.stdout.clearLine()
81
+ process.stdout.cursorTo(0)
82
+ process.stdout.write(`${index}: ${stdout}`) // 在同一行打印处理进度
83
+ return stdout
84
+ }
85
+ catch (error) {
86
+ console.error(`\nWARN: Failed to pack package ${packageName}: ${error.message}`)
87
+ return packageName
88
+ }
89
+ }
83
90
 
84
91
  // 直接利用依赖包的下载地址进行下载
85
92
  async function downloadPackage(packageUrl) {
@@ -175,8 +182,13 @@ program
175
182
  const fullname = packageName.substring(0, atIndex)
176
183
  const name = fullname.includes('/') ? fullname.split('/')[1] : fullname
177
184
  const version = packageName.substring(atIndex + 1)
178
- const packageUrl = `${registryUrl}${fullname}/-/${name}-${version}.tgz`
179
- return limit(() => downloadPackage(packageUrl))
185
+ if (version === '*') {
186
+ return limit(() => packPackage(fullname))
187
+ }
188
+ else {
189
+ const packageUrl = `${registryUrl}${fullname}/-/${name}-${version}.tgz`
190
+ return limit(() => downloadPackage(packageUrl))
191
+ }
180
192
  })
181
193
  await Promise.all(packTasks)
182
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanwang/pack-util",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.",
5
5
  "bin": {
6
6
  "pack-util": "./bin/index.js"