@yidun/cdn-upload-webpack-plugin 1.1.4 → 1.1.6

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.4",
3
+ "version": "1.1.6",
4
4
  "description": "A webpack plugin for upload dist to cdn.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ const fetch = require('node-fetch')
1
2
  const { getFiles } = require('./utils')
2
3
  const { TaskDispatcher } = require('./task')
3
4
  const NosUploadTask = require('./adaptor/nos')
@@ -17,12 +18,13 @@ exports.CdnUploadWebpackPlugin = class CdnUploadWebpackPlugin {
17
18
  * @param {Number} parallelCount 并行上传数, 默认 3
18
19
  */
19
20
  constructor (options) {
20
- const { dirs, includeRootDir, ignores, client, parallelCount } = options
21
+ const { dirs, includeRootDir, ignores, client, parallelCount, domain = 'https://yidunfe.nosdn.127.net' } = options
21
22
  this._dirs = dirs
22
23
  this._includeRootDir = includeRootDir
23
24
  this._ignores = ignores
24
25
  this._client = client
25
26
  this._parallelCount = parallelCount
27
+ this._domain = domain
26
28
  }
27
29
 
28
30
  apply (compiler) {
@@ -30,8 +32,18 @@ exports.CdnUploadWebpackPlugin = class CdnUploadWebpackPlugin {
30
32
  const files = getFiles(this._dirs, this._includeRootDir, this._ignores)
31
33
  const tasks = files.map(file => new NosUploadTask(this._client, file))
32
34
  const taskDispatcher = new TaskDispatcher(tasks, {
33
- onSuccess: () => {
34
- console.log('CdnUploadWebpackPlugin: assets upload success')
35
+ onSuccess: async (task) => {
36
+ if (!task) {
37
+ callback(new Error('CdnUploadVitePlugin Error: task is empty'))
38
+ return
39
+ }
40
+ // cdn 上传成功后健康检查
41
+ const { _file, _namespace } = task[0] || {}
42
+ const data = await fetch(`${this._domain}/${_namespace}/${_file.relative}`)
43
+ if (!data.ok || data.status !== 200) {
44
+ callback(new Error(`CdnUploadVitePlugin Error: url: ${data.url}, status: ${data.status}`))
45
+ }
46
+ console.log('CdnUploadVitePlugin: assets upload success')
35
47
  callback()
36
48
  },
37
49
  onError: error => callback(error)
package/src/vite.js CHANGED
@@ -26,8 +26,12 @@ function CdnUploadVitePlugin (options) {
26
26
  return new Promise((resolve, reject) => {
27
27
  const taskDispatcher = new TaskDispatcher(tasks, {
28
28
  onSuccess: async (task) => {
29
+ if (!task) {
30
+ reject(new Error('CdnUploadVitePlugin Error: task is empty'))
31
+ return
32
+ }
29
33
  // cdn 上传成功后健康检查
30
- const { _file, _namespace } = task?.[0] || {}
34
+ const { _file, _namespace } = task[0] || {}
31
35
  const data = await fetch(`${domain}/${_namespace}/${_file.relative}`)
32
36
  if (!data.ok || data.status !== 200) {
33
37
  reject(new Error(`CdnUploadVitePlugin Error: url: ${data.url}, status: ${data.status}`))
@@ -1,3 +0,0 @@
1
- {
2
- "recommendations": ["Vue.volar"]
3
- }
package/example/README.md DELETED
@@ -1,4 +0,0 @@
1
- # Example
2
-
3
- * 在根目录下 `npm link`
4
- * 在example目录下 `npm link @yidun/cdn-upload-webpack-plugin`
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Vite + Vue + TS</title>
8
- </head>
9
- <body>
10
- <div id="app"></div>
11
- <script type="module" src="/src/main.ts"></script>
12
- </body>
13
- </html>