@fanwang/pack-util 3.0.0 → 3.1.0

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 +24 -15
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -15,7 +15,7 @@ const program = new Command()
15
15
  program
16
16
  .name('pack-util')
17
17
  .description('Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.')
18
- .version('3.0.0')
18
+ .version('3.1.0')
19
19
 
20
20
 
21
21
  const limit = pLimit(10)
@@ -51,18 +51,20 @@ const getPackageInfos = async (packageManager) => {
51
51
  }
52
52
  }
53
53
 
54
- // 利用 npm pack 在外网上对 dependencies 中的所有包打包。
54
+
55
55
  var index = 0
56
- const packPackage = async (packageName) => {
57
- const { stdout } = await execa('npm', ['pack', packageName, '--pack-destination=./node_modules_pack'])
58
- index++
59
- // console.log(`${index}: ${stdout}`)
60
- process.stdout.clearLine()
61
- process.stdout.cursorTo(0)
62
- process.stdout.write(`${index}: ${stdout}`) // 在同一行打印处理进度
63
- return stdout
64
- }
56
+ // 利用 npm pack 在外网上对 dependencies 中的所有包打包。
57
+ // const packPackage = async (packageName) => {
58
+ // const { stdout } = await execa('npm', ['pack', packageName, '--pack-destination=./node_modules_pack'])
59
+ // index++
60
+ // // console.log(`${index}: ${stdout}`)
61
+ // process.stdout.clearLine()
62
+ // process.stdout.cursorTo(0)
63
+ // process.stdout.write(`${index}: ${stdout}`) // 在同一行打印处理进度
64
+ // return stdout
65
+ // }
65
66
 
67
+ // 直接利用依赖包的下载地址进行下载
66
68
  const downloadPackage = async (packageUrl) => {
67
69
  const urlObj = url.parse(packageUrl)
68
70
  const filename = urlObj.pathname.substring(urlObj.pathname.lastIndexOf('/') + 1)
@@ -142,12 +144,19 @@ program
142
144
  )
143
145
  await Promise.all(downloadTasks)
144
146
  } else {
145
- const packTasks = packages.map((packageName) =>
146
- limit(() => packPackage(packageName))
147
- )
147
+ const { stdout } = await execa('npm', ['config', 'get', 'registry'])
148
+ const registryUrl = stdout.endsWith('/') ? stdout : `${stdout}/`;
149
+ const packTasks = packages.map((packageName) => {
150
+ const atIndex = packageName.lastIndexOf('@')
151
+ const fullname = packageName.substring(0, atIndex)
152
+ const name = fullname.includes('/') ? fullname.split('/')[1] : fullname
153
+ const version = packageName.substring(atIndex + 1)
154
+ const packageUrl = `${registryUrl}${fullname}/-/${name}-${version}.tgz`;
155
+ return limit(() => downloadPackage(packageUrl))
156
+ })
148
157
  await Promise.all(packTasks)
149
158
  }
150
- console.log('All packages are successfully packed in ./node_modules_pack !')
159
+ console.log('\nAll packages are successfully packed in ./node_modules_pack!')
151
160
  })
152
161
  })
153
162
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanwang/pack-util",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
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"