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

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@yidun/cdn-upload-webpack-plugin",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "A webpack plugin for upload dist to cdn.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,7 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(node test/index.js)"
5
+ ]
6
+ }
7
+ }
package/src/vite.js CHANGED
@@ -95,17 +95,23 @@ function CdnUploadVitePlugin (options) {
95
95
  }
96
96
  const tasks = filesToUpload.map((file) => new NosUploadTask(client, file))
97
97
  const uploadStart = Date.now()
98
- console.log(`CdnUploadVitePlugin: uploading ${filesToUpload.length} files ...`)
98
+ console.log('CdnUploadVitePlugin: assets uploading ...')
99
99
  return new Promise((resolve, reject) => {
100
100
  const taskDispatcher = new TaskDispatcher(tasks, {
101
- onSuccess: () => {
101
+ onSuccess: async (task) => {
102
+ // cdn 上传成功后健康检查
103
+ const { _file, _namespace } = task?.[0] || {}
104
+ const data = await fetch(`${domain}/${_namespace}/${_file.relative}`)
105
+ if (!data.ok || data.status !== 200) {
106
+ reject(new Error(`CdnUploadVitePlugin Error: url: ${data.url}, status: ${data.status}`))
107
+ }
108
+ console.log('CdnUploadVitePlugin: assets upload success')
102
109
  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]' : ''}`)
105
110
  resolve()
106
111
  },
107
112
  onError: (error) => reject(error)
108
113
  })
114
+ console.log('CdnUploadVitePlugin: assets uploading ...')
109
115
  taskDispatcher.dispatch(parallelCount)
110
116
  })
111
117
  }