hw-weapp-compiler 1.0.20 → 1.0.21
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/build/dev.js +7 -1
- package/build/utils/upload.js +24 -8
- package/package.json +1 -1
package/build/dev.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const webpack = require('webpack');
|
|
2
|
+
const chalk = require('chalk');
|
|
2
3
|
const { ENV } = require('./config/constants');
|
|
3
4
|
const webpackConfig = require('./webpack.config');
|
|
4
5
|
const { createCompilerHandler } = require('./utils/createCompilerHandler');
|
|
@@ -20,7 +21,7 @@ module.exports = async (opts) => {
|
|
|
20
21
|
),
|
|
21
22
|
);
|
|
22
23
|
|
|
23
|
-
compiler.watch(
|
|
24
|
+
const watching = compiler.watch(
|
|
24
25
|
{
|
|
25
26
|
aggregateTimeout: 300,
|
|
26
27
|
poll: false,
|
|
@@ -28,4 +29,9 @@ module.exports = async (opts) => {
|
|
|
28
29
|
},
|
|
29
30
|
createCompilerHandler('dev'),
|
|
30
31
|
);
|
|
32
|
+
|
|
33
|
+
if (!opts || opts.quiet !== true) {
|
|
34
|
+
console.log(chalk.cyan('dev 正在监听文件变化'));
|
|
35
|
+
}
|
|
36
|
+
return watching;
|
|
31
37
|
};
|
package/build/utils/upload.js
CHANGED
|
@@ -16,7 +16,7 @@ const { DIST_DIR } = require('../config/constants');
|
|
|
16
16
|
|
|
17
17
|
const { obsConfig, ossConfig } = getConfig();
|
|
18
18
|
|
|
19
|
-
let
|
|
19
|
+
let obsClientPromise;
|
|
20
20
|
let ossClient;
|
|
21
21
|
|
|
22
22
|
function getObsResponseError(action, result) {
|
|
@@ -60,13 +60,26 @@ function createObsCallback(action, resolve, reject) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
async function initializeObsClient(Client = OBSClient, config = obsConfig) {
|
|
64
|
+
const client = new Client({ ...config });
|
|
65
|
+
|
|
66
|
+
// esdk-obs-nodejs 3.26.x 的构造函数不会等待异步 initFactory()。
|
|
67
|
+
// 静态 AK/SK 初始化会在下一个微任务完成,立即调用 API 时 signatureContext 仍为 null。
|
|
68
|
+
await Promise.resolve();
|
|
69
|
+
if (!client.util || !client.util.signatureContext) {
|
|
70
|
+
throw new Error('OBS client initialization failed');
|
|
71
|
+
}
|
|
72
|
+
return client;
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
function getObsClient() {
|
|
64
|
-
if (!
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
if (!obsClientPromise) {
|
|
77
|
+
obsClientPromise = initializeObsClient().catch((error) => {
|
|
78
|
+
obsClientPromise = undefined;
|
|
79
|
+
throw error;
|
|
67
80
|
});
|
|
68
81
|
}
|
|
69
|
-
return
|
|
82
|
+
return obsClientPromise;
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
function getOssClient() {
|
|
@@ -89,9 +102,10 @@ function getOssStat(file) {
|
|
|
89
102
|
return getOssClient().head(compatiblePath(path.join(ossConfig.dir, path.relative(DIST_DIR, file))));
|
|
90
103
|
}
|
|
91
104
|
|
|
92
|
-
function doObsUpload(file) {
|
|
105
|
+
async function doObsUpload(file) {
|
|
106
|
+
const client = await getObsClient();
|
|
93
107
|
return new Promise((resolve, reject) => {
|
|
94
|
-
|
|
108
|
+
client.putObject(
|
|
95
109
|
{
|
|
96
110
|
Bucket: obsConfig.bucket,
|
|
97
111
|
Key: compatiblePath(path.join(obsConfig.dir, path.relative(DIST_DIR, file))),
|
|
@@ -102,8 +116,9 @@ function doObsUpload(file) {
|
|
|
102
116
|
});
|
|
103
117
|
}
|
|
104
118
|
async function getObsStat(file) {
|
|
119
|
+
const client = await getObsClient();
|
|
105
120
|
return new Promise((resolve, reject) => {
|
|
106
|
-
|
|
121
|
+
client.getObjectMetadata(
|
|
107
122
|
{
|
|
108
123
|
Bucket: obsConfig.bucket,
|
|
109
124
|
Key: compatiblePath(path.join(obsConfig.dir, path.relative(DIST_DIR, file))),
|
|
@@ -189,6 +204,7 @@ module.exports = {
|
|
|
189
204
|
_internals: {
|
|
190
205
|
createObsCallback,
|
|
191
206
|
getObsResponseError,
|
|
207
|
+
initializeObsClient,
|
|
192
208
|
uploadFile,
|
|
193
209
|
uploadFiles,
|
|
194
210
|
},
|