hw-weapp-compiler 1.0.5 → 1.0.7
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/loader/js-loader.js +1 -2
- package/build/loader/wxml-loader.js +1 -2
- package/build/loader/wxs-loader.js +1 -2
- package/build/plugin/index.js +1 -1
- package/build/utils/createCompilerHandler.js +15 -1
- package/build/utils/getWxmlAssets.js +3 -9
- package/build/utils/loadModule.js +11 -50
- package/package.json +1 -1
|
@@ -13,7 +13,6 @@ const entries = getEntries();
|
|
|
13
13
|
|
|
14
14
|
module.exports = async function loader(source) {
|
|
15
15
|
this.cacheable(true);
|
|
16
|
-
const callback = this.async();
|
|
17
16
|
const filePath = this.resourcePath;
|
|
18
17
|
const fileInfo = path.parse(filePath);
|
|
19
18
|
const sourceStr = source.toString();
|
|
@@ -46,7 +45,7 @@ module.exports = async function loader(source) {
|
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
return imports.join('');
|
|
50
49
|
};
|
|
51
50
|
|
|
52
51
|
module.exports.raw = true;
|
|
@@ -9,7 +9,6 @@ const { loadModule } = require('../utils/loadModule');
|
|
|
9
9
|
|
|
10
10
|
module.exports = async function loader(source) {
|
|
11
11
|
this.cacheable(true);
|
|
12
|
-
const callback = this.async();
|
|
13
12
|
const filePath = this.resourcePath;
|
|
14
13
|
let content = source.toString();
|
|
15
14
|
const {
|
|
@@ -46,6 +45,6 @@ module.exports = async function loader(source) {
|
|
|
46
45
|
// wxml文件 - 并行 loadModule
|
|
47
46
|
await Promise.all(wxmls.map(([, file]) => loadModule.call(this, file)));
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
return content;
|
|
50
49
|
};
|
|
51
50
|
module.exports.raw = true;
|
|
@@ -9,7 +9,6 @@ const { loadModule } = require('../utils/loadModule');
|
|
|
9
9
|
|
|
10
10
|
module.exports = async function loader(source) {
|
|
11
11
|
this.cacheable(true);
|
|
12
|
-
const callback = this.async();
|
|
13
12
|
const filePath = this.resourcePath;
|
|
14
13
|
const content = source.toString();
|
|
15
14
|
const fileInfo = path.parse(filePath);
|
|
@@ -26,6 +25,6 @@ module.exports = async function loader(source) {
|
|
|
26
25
|
}),
|
|
27
26
|
);
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
return content;
|
|
30
29
|
};
|
|
31
30
|
module.exports.raw = true;
|
package/build/plugin/index.js
CHANGED
|
@@ -7,17 +7,31 @@ const chalk = require('chalk');
|
|
|
7
7
|
function createCompilerHandler(label) {
|
|
8
8
|
return (err, stats) => {
|
|
9
9
|
if (err) {
|
|
10
|
+
console.error(chalk.red(`${label} failed with fatal error:`));
|
|
10
11
|
console.error(err);
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
if (stats.hasErrors()) {
|
|
15
|
-
console.
|
|
16
|
+
console.error(
|
|
16
17
|
stats.toString({
|
|
17
18
|
chunks: false,
|
|
18
19
|
colors: true,
|
|
19
20
|
}),
|
|
20
21
|
);
|
|
22
|
+
console.error(chalk.red(`${label} completed with errors`));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (stats.hasWarnings()) {
|
|
27
|
+
console.warn(
|
|
28
|
+
stats.toString({
|
|
29
|
+
chunks: false,
|
|
30
|
+
colors: true,
|
|
31
|
+
warnings: true,
|
|
32
|
+
errors: false,
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
21
35
|
}
|
|
22
36
|
|
|
23
37
|
console.log(chalk.green(`${label} completed in ${(stats.endTime - stats.startTime) / 1000} seconds`));
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
const { createPool, POOL_SIZE } = require('./loadModule');
|
|
2
1
|
const htmlparser2 = require('htmlparser2');
|
|
3
2
|
const path = require('path');
|
|
4
3
|
const fse = require('fs-extra');
|
|
5
4
|
const { ASSET_EXT_PATTERN, PATTERNS, SRC_DIR } = require('../config/constants');
|
|
6
5
|
|
|
7
|
-
const resolvePool = createPool(POOL_SIZE);
|
|
8
|
-
|
|
9
6
|
function getWxmlAssets(filePath, content) {
|
|
10
7
|
const resolvePath = (attr, dir) => {
|
|
11
|
-
return
|
|
12
|
-
() =>
|
|
13
|
-
new Promise((resolve) => {
|
|
14
|
-
this.resolve(SRC_DIR, attr, async (err, result) => {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
this.resolve(SRC_DIR, attr, async (err, result) => {
|
|
15
10
|
let res = result;
|
|
16
11
|
if (err) {
|
|
17
12
|
if (await fse.pathExists(path.resolve(dir, attr))) {
|
|
@@ -25,8 +20,7 @@ function getWxmlAssets(filePath, content) {
|
|
|
25
20
|
resolve(res);
|
|
26
21
|
}
|
|
27
22
|
});
|
|
28
|
-
|
|
29
|
-
);
|
|
23
|
+
});
|
|
30
24
|
};
|
|
31
25
|
return new Promise((resolve, reject) => {
|
|
32
26
|
let allAttrs = [];
|
|
@@ -1,55 +1,16 @@
|
|
|
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();
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const pool = createPool(POOL_SIZE);
|
|
34
|
-
|
|
35
1
|
function loadModule(file) {
|
|
36
|
-
return
|
|
37
|
-
()
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
}),
|
|
49
|
-
);
|
|
2
|
+
return new Promise((resolve) => {
|
|
3
|
+
this.addDependency(file);
|
|
4
|
+
this.loadModule(file, (err, src) => {
|
|
5
|
+
if (err) {
|
|
6
|
+
this.emitError(err);
|
|
7
|
+
resolve(null);
|
|
8
|
+
} else {
|
|
9
|
+
resolve(src);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
});
|
|
50
13
|
}
|
|
51
14
|
module.exports = {
|
|
52
15
|
loadModule,
|
|
53
|
-
createPool,
|
|
54
|
-
POOL_SIZE,
|
|
55
16
|
};
|