hw-weapp-compiler 1.0.4 → 1.0.5
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.
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
const { createPool, POOL_SIZE } = require('./loadModule');
|
|
1
2
|
const htmlparser2 = require('htmlparser2');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const fse = require('fs-extra');
|
|
4
5
|
const { ASSET_EXT_PATTERN, PATTERNS, SRC_DIR } = require('../config/constants');
|
|
5
6
|
|
|
7
|
+
const resolvePool = createPool(POOL_SIZE);
|
|
8
|
+
|
|
6
9
|
function getWxmlAssets(filePath, content) {
|
|
7
10
|
const resolvePath = (attr, dir) => {
|
|
8
|
-
return
|
|
9
|
-
|
|
11
|
+
return resolvePool(
|
|
12
|
+
() =>
|
|
13
|
+
new Promise((resolve) => {
|
|
14
|
+
this.resolve(SRC_DIR, attr, async (err, result) => {
|
|
10
15
|
let res = result;
|
|
11
16
|
if (err) {
|
|
12
17
|
if (await fse.pathExists(path.resolve(dir, attr))) {
|
|
@@ -20,7 +25,8 @@ function getWxmlAssets(filePath, content) {
|
|
|
20
25
|
resolve(res);
|
|
21
26
|
}
|
|
22
27
|
});
|
|
23
|
-
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
24
30
|
};
|
|
25
31
|
return new Promise((resolve, reject) => {
|
|
26
32
|
let allAttrs = [];
|
|
@@ -1,16 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const POOL_SIZE = 16;
|
|
2
|
+
|
|
3
|
+
function createPool(limit) {
|
|
4
|
+
let active = 0;
|
|
5
|
+
const pending = [];
|
|
6
|
+
const next = () => {
|
|
7
|
+
while (pending.length && active < limit) {
|
|
8
|
+
const { fn, resolve, reject } = pending.shift();
|
|
9
|
+
active++;
|
|
10
|
+
Promise.resolve()
|
|
11
|
+
.then(fn)
|
|
12
|
+
.then(
|
|
13
|
+
(v) => {
|
|
14
|
+
active--;
|
|
15
|
+
resolve(v);
|
|
16
|
+
next();
|
|
17
|
+
},
|
|
18
|
+
(e) => {
|
|
19
|
+
active--;
|
|
20
|
+
reject(e);
|
|
21
|
+
next();
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return (fn) =>
|
|
27
|
+
new Promise((resolve, reject) => {
|
|
28
|
+
pending.push({ fn, resolve, reject });
|
|
29
|
+
next();
|
|
11
30
|
});
|
|
12
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const pool = createPool(POOL_SIZE);
|
|
34
|
+
|
|
35
|
+
function loadModule(file) {
|
|
36
|
+
return pool(
|
|
37
|
+
() =>
|
|
38
|
+
new Promise((resolve) => {
|
|
39
|
+
this.addDependency(file);
|
|
40
|
+
this.loadModule(file, (err, src) => {
|
|
41
|
+
if (err) {
|
|
42
|
+
this.emitError(err);
|
|
43
|
+
resolve(null);
|
|
44
|
+
} else {
|
|
45
|
+
resolve(src);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
13
50
|
}
|
|
14
51
|
module.exports = {
|
|
15
52
|
loadModule,
|
|
53
|
+
createPool,
|
|
54
|
+
POOL_SIZE,
|
|
16
55
|
};
|
package/build/webpack.config.js
CHANGED
|
@@ -309,6 +309,7 @@ module.exports = (options, { analyzer, quiet } = {}) => {
|
|
|
309
309
|
loader: 'babel-loader',
|
|
310
310
|
options: {
|
|
311
311
|
cacheDirectory: true,
|
|
312
|
+
cacheCompression: false,
|
|
312
313
|
presets: [
|
|
313
314
|
[
|
|
314
315
|
'@babel/preset-env',
|
|
@@ -338,7 +339,6 @@ module.exports = (options, { analyzer, quiet } = {}) => {
|
|
|
338
339
|
cacheGroups,
|
|
339
340
|
},
|
|
340
341
|
},
|
|
341
|
-
cache: false,
|
|
342
342
|
},
|
|
343
343
|
options,
|
|
344
344
|
);
|