@yidun/cdn-upload-webpack-plugin 1.1.7 → 1.1.8

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/package.json +1 -1
  2. package/src/vite.js +9 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yidun/cdn-upload-webpack-plugin",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "A webpack plugin for upload dist to cdn.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/vite.js CHANGED
@@ -85,50 +85,27 @@ function CdnUploadVitePlugin (options) {
85
85
  filesToUpload = files.filter((_, index) => uploadFlags[index])
86
86
  const skippedCount = files.length - filesToUpload.length
87
87
  const precheckCost = Date.now() - precheckStart
88
- console.log(`CdnUploadVitePlugin: precheck done, total=${files.length}, upload=${filesToUpload.length}, skipped=${skippedCount}, cost=${precheckCost}ms`)
89
- if (skippedCount > 0) {
90
- console.log(`CdnUploadVitePlugin: skip upload ${skippedCount} hashed files already on CDN`)
91
- }
88
+ console.log(`CdnUploadVitePlugin: precheck done total=${files.length}, upload=${filesToUpload.length}, skipped=${skippedCount}, cost=${precheckCost}ms`)
92
89
  }
93
90
  if (filesToUpload.length === 0) {
94
- if (cleanupAfterUpload) {
95
- cleanupFiles(dirs, cleanupKeepRules)
96
- console.log('CdnUploadVitePlugin: local static assets cleaned')
97
- }
98
- const totalCost = Date.now() - uploadStageStart
99
- console.log(`CdnUploadVitePlugin: no files need upload, total upload stage cost=${totalCost}ms`)
100
- if (buildStartAt > 0) {
101
- console.log(`CdnUploadVitePlugin: build+upload total cost=${Date.now() - buildStartAt}ms`)
102
- }
91
+ if (cleanupAfterUpload) cleanupFiles(dirs, cleanupKeepRules)
92
+ const buildCost = buildStartAt > 0 ? `, build+upload=${Date.now() - buildStartAt}ms` : ''
93
+ console.log(`CdnUploadVitePlugin: done no files to upload, total=${Date.now() - uploadStageStart}ms${buildCost}${cleanupAfterUpload ? ' [cleaned]' : ''}`)
103
94
  return
104
95
  }
105
96
  const tasks = filesToUpload.map((file) => new NosUploadTask(client, file))
106
97
  const uploadStart = Date.now()
98
+ console.log(`CdnUploadVitePlugin: uploading ${filesToUpload.length} files ...`)
107
99
  return new Promise((resolve, reject) => {
108
100
  const taskDispatcher = new TaskDispatcher(tasks, {
109
- onSuccess: async (task) => {
110
- // cdn 上传成功后健康检查
111
- const { _file, _namespace } = task?.[0] || {}
112
- const data = await fetch(`${domain}/${_namespace}/${_file.relative}`)
113
- if (!data.ok || data.status !== 200) {
114
- return reject(new Error(`CdnUploadVitePlugin Error: url: ${data.url}, status: ${data.status}`))
115
- }
116
- if (cleanupAfterUpload) {
117
- cleanupFiles(dirs, cleanupKeepRules)
118
- console.log('CdnUploadVitePlugin: local static assets cleaned')
119
- }
120
- const uploadCost = Date.now() - uploadStart
121
- const totalCost = Date.now() - uploadStageStart
122
- console.log(`CdnUploadVitePlugin: upload cost=${uploadCost}ms, total upload stage cost=${totalCost}ms`)
123
- if (buildStartAt > 0) {
124
- console.log(`CdnUploadVitePlugin: build+upload total cost=${Date.now() - buildStartAt}ms`)
125
- }
126
- console.log('CdnUploadVitePlugin: assets upload success')
101
+ onSuccess: () => {
102
+ if (cleanupAfterUpload) cleanupFiles(dirs, cleanupKeepRules)
103
+ const buildCost = buildStartAt > 0 ? `, build+upload=${Date.now() - buildStartAt}ms` : ''
104
+ console.log(`CdnUploadVitePlugin: done upload=${Date.now() - uploadStart}ms, total=${Date.now() - uploadStageStart}ms${buildCost}${cleanupAfterUpload ? ' [cleaned]' : ''}`)
127
105
  resolve()
128
106
  },
129
107
  onError: (error) => reject(error)
130
108
  })
131
- console.log('CdnUploadVitePlugin: assets uploading ...')
132
109
  taskDispatcher.dispatch(parallelCount)
133
110
  })
134
111
  }