xhs-mp-pack 2.1.0 → 2.1.2
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,73 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
// @ts-nocheck
|
|
3
|
-
const minify =
|
|
12
|
+
const minify = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4
13
|
const minifyFns = Array.isArray(options.minimizer.implementation)
|
|
5
14
|
? options.minimizer.implementation
|
|
6
15
|
: [options.minimizer.implementation];
|
|
7
|
-
|
|
8
16
|
const result = { outputs: [], warnings: [], errors: [] };
|
|
9
|
-
|
|
10
17
|
let needSourceMap = false;
|
|
11
|
-
|
|
12
18
|
for (let i = 0; i <= minifyFns.length - 1; i++) {
|
|
13
19
|
const minifyFn = minifyFns[i];
|
|
14
20
|
const minifyOptions = Array.isArray(options.minimizer.options)
|
|
15
21
|
? options.minimizer.options[i]
|
|
16
22
|
: options.minimizer.options;
|
|
17
|
-
const prevResult =
|
|
18
|
-
result.outputs.length
|
|
19
|
-
|
|
20
|
-
: { code: options.input, map: options.inputSourceMap };
|
|
23
|
+
const prevResult = result.outputs.length > 0
|
|
24
|
+
? result.outputs[result.outputs.length - 1]
|
|
25
|
+
: { code: options.input, map: options.inputSourceMap };
|
|
21
26
|
const { code, map } = prevResult;
|
|
22
27
|
// eslint-disable-next-line no-await-in-loop
|
|
23
|
-
const minifyResult =
|
|
24
|
-
{ [options.name]: code },
|
|
25
|
-
map,
|
|
26
|
-
minifyOptions
|
|
27
|
-
);
|
|
28
|
-
|
|
28
|
+
const minifyResult = yield minifyFn({ [options.name]: code }, map, minifyOptions);
|
|
29
29
|
if (typeof minifyResult.code !== "string") {
|
|
30
|
-
throw new Error(
|
|
31
|
-
"minimizer function doesn't return the 'code' property or result is not a string value"
|
|
32
|
-
);
|
|
30
|
+
throw new Error("minimizer function doesn't return the 'code' property or result is not a string value");
|
|
33
31
|
}
|
|
34
|
-
|
|
35
32
|
if (minifyResult.map) {
|
|
36
33
|
needSourceMap = true;
|
|
37
34
|
}
|
|
38
|
-
|
|
39
35
|
if (minifyResult.errors) {
|
|
40
36
|
result.errors = result.errors.concat(minifyResult.errors);
|
|
41
37
|
}
|
|
42
|
-
|
|
43
38
|
if (minifyResult.warnings) {
|
|
44
39
|
result.warnings = result.warnings.concat(minifyResult.warnings);
|
|
45
40
|
}
|
|
46
|
-
|
|
47
41
|
result.outputs.push({ code: minifyResult.code, map: minifyResult.map });
|
|
48
42
|
}
|
|
49
|
-
|
|
50
43
|
if (!needSourceMap) {
|
|
51
44
|
result.outputs = [result.outputs[result.outputs.length - 1]];
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
return result;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"module",
|
|
65
|
-
"__filename",
|
|
66
|
-
"__dirname",
|
|
67
|
-
`'use strict'\nreturn ${options}`
|
|
68
|
-
)(exports, require, module, __filename, __dirname);
|
|
69
|
-
|
|
70
|
-
return minify(evaluatedOptions);
|
|
47
|
+
});
|
|
48
|
+
function transform(options) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
// 'use strict' => this === undefined (Clean Scope)
|
|
51
|
+
// Safer for possible security issues, albeit not critical at all here
|
|
52
|
+
// eslint-disable-next-line no-new-func, no-param-reassign
|
|
53
|
+
const evaluatedOptions = new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
|
|
54
|
+
return minify(evaluatedOptions);
|
|
55
|
+
});
|
|
71
56
|
}
|
|
72
|
-
|
|
73
57
|
module.exports = { minify, transform };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types=".pnpm/source-map-js@1.2.0/node_modules/source-map-js" />
|
|
2
|
+
export function throttleAll(limit: any, tasks: any): Promise<any>;
|
|
3
|
+
export function memoize(fn: any): () => any;
|
|
4
|
+
export function cssnanoMinify(input: any, sourceMap: any, minimizerOptions?: {
|
|
5
|
+
preset: string;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
code: string;
|
|
8
|
+
map: import("source-map-js").RawSourceMap | undefined;
|
|
9
|
+
warnings: string[];
|
|
10
|
+
}>;
|
|
@@ -1,147 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
1
11
|
// @ts-nocheck
|
|
2
|
-
const notSettled = Symbol(`not-settled`)
|
|
3
|
-
|
|
12
|
+
const notSettled = Symbol(`not-settled`);
|
|
4
13
|
function throttleAll(limit, tasks) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`,
|
|
8
|
-
)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
|
|
12
|
-
throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const result = Array(tasks.length).fill(notSettled)
|
|
17
|
-
const entries = tasks.entries()
|
|
18
|
-
const next = () => {
|
|
19
|
-
const { done, value } = entries.next()
|
|
20
|
-
|
|
21
|
-
if (done) {
|
|
22
|
-
const isLast = !result.includes(notSettled)
|
|
23
|
-
|
|
24
|
-
if (isLast) resolve(result)
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const [index, task] = value
|
|
30
|
-
|
|
31
|
-
const onFulfilled = x => {
|
|
32
|
-
result[index] = x
|
|
33
|
-
next()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
task().then(onFulfilled, reject)
|
|
14
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
15
|
+
throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`);
|
|
37
16
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function cssnanoMinify(input, sourceMap, minimizerOptions = { preset: 'default' }) {
|
|
44
|
-
const load = async module => {
|
|
45
|
-
let exports
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
49
|
-
exports = require(module)
|
|
50
|
-
|
|
51
|
-
return exports
|
|
52
|
-
} catch (requireError) {
|
|
53
|
-
let importESM
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
// eslint-disable-next-line no-new-func
|
|
57
|
-
importESM = new Function('id', 'return import(id);')
|
|
58
|
-
} catch (e) {
|
|
59
|
-
importESM = null
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (requireError.code === 'ERR_REQUIRE_ESM' && importESM) {
|
|
63
|
-
exports = await importESM(module)
|
|
64
|
-
|
|
65
|
-
return exports.default
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
throw requireError
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const [[name, code]] = Object.entries(input)
|
|
73
|
-
const postcssOptions = {
|
|
74
|
-
from: name,
|
|
75
|
-
...minimizerOptions.processorOptions,
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (typeof postcssOptions.parser === 'string') {
|
|
79
|
-
try {
|
|
80
|
-
postcssOptions.parser = await load(postcssOptions.parser)
|
|
81
|
-
} catch (error) {
|
|
82
|
-
throw new Error(
|
|
83
|
-
`Loading PostCSS "${postcssOptions.parser}" parser failed: ${error.message}\n\n(@${name})`,
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (typeof postcssOptions.stringifier === 'string') {
|
|
89
|
-
try {
|
|
90
|
-
postcssOptions.stringifier = await load(postcssOptions.stringifier)
|
|
91
|
-
} catch (error) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
`Loading PostCSS "${postcssOptions.stringifier}" stringifier failed: ${error.message}\n\n(@${name})`,
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (typeof postcssOptions.syntax === 'string') {
|
|
99
|
-
try {
|
|
100
|
-
postcssOptions.syntax = await load(postcssOptions.syntax)
|
|
101
|
-
} catch (error) {
|
|
102
|
-
throw new Error(
|
|
103
|
-
`Loading PostCSS "${postcssOptions.syntax}" syntax failed: ${error.message}\n\n(@${name})`,
|
|
104
|
-
)
|
|
17
|
+
if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
|
|
18
|
+
throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`);
|
|
105
19
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const result = Array(tasks.length).fill(notSettled);
|
|
22
|
+
const entries = tasks.entries();
|
|
23
|
+
const next = () => {
|
|
24
|
+
const { done, value } = entries.next();
|
|
25
|
+
if (done) {
|
|
26
|
+
const isLast = !result.includes(notSettled);
|
|
27
|
+
if (isLast)
|
|
28
|
+
resolve(result);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const [index, task] = value;
|
|
32
|
+
const onFulfilled = x => {
|
|
33
|
+
result[index] = x;
|
|
34
|
+
next();
|
|
35
|
+
};
|
|
36
|
+
task().then(onFulfilled, reject);
|
|
37
|
+
};
|
|
38
|
+
Array(limit).fill(0).forEach(next);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function cssnanoMinify(input, sourceMap, minimizerOptions = { preset: 'default' }) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const load = (module) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
let exports;
|
|
45
|
+
try {
|
|
46
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
47
|
+
exports = require(module);
|
|
48
|
+
return exports;
|
|
49
|
+
}
|
|
50
|
+
catch (requireError) {
|
|
51
|
+
let importESM;
|
|
52
|
+
try {
|
|
53
|
+
// eslint-disable-next-line no-new-func
|
|
54
|
+
importESM = new Function('id', 'return import(id);');
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
importESM = null;
|
|
58
|
+
}
|
|
59
|
+
if (requireError.code === 'ERR_REQUIRE_ESM' && importESM) {
|
|
60
|
+
exports = yield importESM(module);
|
|
61
|
+
return exports.default;
|
|
62
|
+
}
|
|
63
|
+
throw requireError;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const [[name, code]] = Object.entries(input);
|
|
67
|
+
const postcssOptions = Object.assign({ from: name }, minimizerOptions.processorOptions);
|
|
68
|
+
if (typeof postcssOptions.parser === 'string') {
|
|
69
|
+
try {
|
|
70
|
+
postcssOptions.parser = yield load(postcssOptions.parser);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new Error(`Loading PostCSS "${postcssOptions.parser}" parser failed: ${error.message}\n\n(@${name})`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (typeof postcssOptions.stringifier === 'string') {
|
|
77
|
+
try {
|
|
78
|
+
postcssOptions.stringifier = yield load(postcssOptions.stringifier);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw new Error(`Loading PostCSS "${postcssOptions.stringifier}" stringifier failed: ${error.message}\n\n(@${name})`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (typeof postcssOptions.syntax === 'string') {
|
|
85
|
+
try {
|
|
86
|
+
postcssOptions.syntax = yield load(postcssOptions.syntax);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw new Error(`Loading PostCSS "${postcssOptions.syntax}" syntax failed: ${error.message}\n\n(@${name})`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (sourceMap) {
|
|
93
|
+
postcssOptions.map = { annotation: false };
|
|
94
|
+
}
|
|
95
|
+
const postcss = require('postcss').default;
|
|
96
|
+
const cssnano = require('cssnano');
|
|
97
|
+
const result = yield postcss([cssnano(minimizerOptions)]).process(code, postcssOptions);
|
|
98
|
+
return {
|
|
99
|
+
code: result.css,
|
|
100
|
+
map: result.map ? result.map.toJSON() : undefined,
|
|
101
|
+
warnings: result.warnings().map(String),
|
|
102
|
+
};
|
|
103
|
+
});
|
|
121
104
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
105
|
function memoize(fn) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return result
|
|
140
|
-
}
|
|
106
|
+
let cache = false;
|
|
107
|
+
let result;
|
|
108
|
+
return () => {
|
|
109
|
+
if (cache) {
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
result = fn();
|
|
113
|
+
cache = true;
|
|
114
|
+
// Allow to clean up memory for fn
|
|
115
|
+
// and all dependent resources
|
|
116
|
+
// eslint-disable-next-line no-undefined, no-param-reassign
|
|
117
|
+
fn = undefined;
|
|
118
|
+
return result;
|
|
119
|
+
};
|
|
141
120
|
}
|
|
142
|
-
|
|
143
121
|
module.exports = {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
122
|
+
throttleAll,
|
|
123
|
+
memoize,
|
|
124
|
+
cssnanoMinify,
|
|
125
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xhs-mp-pack",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "xhs mp compiler core.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"category": "esm",
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"watchpack": "^2.4.0",
|
|
56
56
|
"webpack-chain": "^6.5.1",
|
|
57
57
|
"webpack-sources": "^3.2.3",
|
|
58
|
-
"xhs-mp-compiler-utils": "2.1.
|
|
59
|
-
"xhs-mp-project": "2.1.
|
|
60
|
-
"xhs-mp-shared-fs": "2.1.
|
|
58
|
+
"xhs-mp-compiler-utils": "2.1.2",
|
|
59
|
+
"xhs-mp-project": "2.1.2",
|
|
60
|
+
"xhs-mp-shared-fs": "2.1.2"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/babel__generator": "7.6.3",
|