@parcel/optimizer-terser 2.8.3 → 2.9.0
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/lib/TerserOptimizer.js +3 -51
- package/package.json +6 -6
- package/src/TerserOptimizer.js +1 -8
package/lib/TerserOptimizer.js
CHANGED
|
@@ -4,101 +4,66 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _nullthrows() {
|
|
9
8
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
10
|
-
|
|
11
9
|
_nullthrows = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _terser() {
|
|
19
15
|
const data = require("terser");
|
|
20
|
-
|
|
21
16
|
_terser = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _plugin() {
|
|
29
22
|
const data = require("@parcel/plugin");
|
|
30
|
-
|
|
31
23
|
_plugin = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _utils() {
|
|
39
29
|
const data = require("@parcel/utils");
|
|
40
|
-
|
|
41
30
|
_utils = function () {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _sourceMap() {
|
|
49
36
|
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
50
|
-
|
|
51
37
|
_sourceMap = function () {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
function _diagnostic() {
|
|
59
43
|
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
|
60
|
-
|
|
61
44
|
_diagnostic = function () {
|
|
62
45
|
return data;
|
|
63
46
|
};
|
|
64
|
-
|
|
65
47
|
return data;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
function _path() {
|
|
69
50
|
const data = _interopRequireDefault(require("path"));
|
|
70
|
-
|
|
71
51
|
_path = function () {
|
|
72
52
|
return data;
|
|
73
53
|
};
|
|
74
|
-
|
|
75
54
|
return data;
|
|
76
55
|
}
|
|
77
|
-
|
|
78
56
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
79
|
-
|
|
80
57
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
81
|
-
|
|
82
58
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
83
|
-
|
|
84
59
|
var _default = new (_plugin().Optimizer)({
|
|
85
60
|
async loadConfig({
|
|
86
61
|
config,
|
|
87
62
|
options
|
|
88
63
|
}) {
|
|
89
|
-
let userConfig = await config.getConfigFrom(_path().default.join(options.projectRoot, 'index'), ['.terserrc', '.terserrc.js', '.terserrc.cjs']);
|
|
90
|
-
|
|
91
|
-
if (userConfig) {
|
|
92
|
-
let isJavascript = _path().default.extname(userConfig.filePath) === '.js';
|
|
93
|
-
|
|
94
|
-
if (isJavascript) {
|
|
95
|
-
config.invalidateOnStartup();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
64
|
+
let userConfig = await config.getConfigFrom(_path().default.join(options.projectRoot, 'index'), ['.terserrc', '.terserrc.js', '.terserrc.cjs', '.terserrc.mjs']);
|
|
99
65
|
return userConfig === null || userConfig === void 0 ? void 0 : userConfig.contents;
|
|
100
66
|
},
|
|
101
|
-
|
|
102
67
|
async optimize({
|
|
103
68
|
contents,
|
|
104
69
|
map,
|
|
@@ -113,10 +78,10 @@ var _default = new (_plugin().Optimizer)({
|
|
|
113
78
|
map
|
|
114
79
|
};
|
|
115
80
|
}
|
|
116
|
-
|
|
117
81
|
let code = await (0, _utils().blobToString)(contents);
|
|
118
82
|
let originalMap = map ? await map.stringify({}) : null;
|
|
119
|
-
let config = {
|
|
83
|
+
let config = {
|
|
84
|
+
...userConfig,
|
|
120
85
|
sourceMap: bundle.env.sourceMap ? {
|
|
121
86
|
filename: _path().default.relative(options.projectRoot, _path().default.join(bundle.target.distDir, bundle.name)),
|
|
122
87
|
asObject: true,
|
|
@@ -126,7 +91,6 @@ var _default = new (_plugin().Optimizer)({
|
|
|
126
91
|
module: bundle.env.outputFormat === 'esmodule'
|
|
127
92
|
};
|
|
128
93
|
let result;
|
|
129
|
-
|
|
130
94
|
try {
|
|
131
95
|
result = await (0, _terser().minify)(code, config);
|
|
132
96
|
} catch (error) {
|
|
@@ -136,20 +100,16 @@ var _default = new (_plugin().Optimizer)({
|
|
|
136
100
|
line,
|
|
137
101
|
col
|
|
138
102
|
} = error;
|
|
139
|
-
|
|
140
103
|
if (line != null && col != null) {
|
|
141
104
|
message = (0, _diagnostic().escapeMarkdown)(message);
|
|
142
105
|
let diagnostics = [];
|
|
143
106
|
let mapping = map === null || map === void 0 ? void 0 : map.findClosestMapping(line, col);
|
|
144
|
-
|
|
145
107
|
if (mapping && mapping.original && mapping.source) {
|
|
146
108
|
let {
|
|
147
109
|
source,
|
|
148
110
|
original
|
|
149
111
|
} = mapping;
|
|
150
|
-
|
|
151
112
|
let filePath = _path().default.resolve(options.projectRoot, source);
|
|
152
|
-
|
|
153
113
|
diagnostics.push({
|
|
154
114
|
message,
|
|
155
115
|
origin: '@parcel/optimizer-terser',
|
|
@@ -166,7 +126,6 @@ var _default = new (_plugin().Optimizer)({
|
|
|
166
126
|
hints: ["It's likely that Terser doesn't support this syntax yet."]
|
|
167
127
|
});
|
|
168
128
|
}
|
|
169
|
-
|
|
170
129
|
if (diagnostics.length === 0 || options.logLevel === 'verbose') {
|
|
171
130
|
let loc = {
|
|
172
131
|
line: line,
|
|
@@ -188,7 +147,6 @@ var _default = new (_plugin().Optimizer)({
|
|
|
188
147
|
hints: ["It's likely that Terser doesn't support this syntax yet."]
|
|
189
148
|
});
|
|
190
149
|
}
|
|
191
|
-
|
|
192
150
|
throw new (_diagnostic().default)({
|
|
193
151
|
diagnostic: diagnostics
|
|
194
152
|
});
|
|
@@ -196,27 +154,21 @@ var _default = new (_plugin().Optimizer)({
|
|
|
196
154
|
throw error;
|
|
197
155
|
}
|
|
198
156
|
}
|
|
199
|
-
|
|
200
157
|
let sourceMap = null;
|
|
201
158
|
let minifiedContents = (0, _nullthrows().default)(result.code);
|
|
202
159
|
let resultMap = result.map;
|
|
203
|
-
|
|
204
160
|
if (resultMap && typeof resultMap !== 'string') {
|
|
205
161
|
sourceMap = new (_sourceMap().default)(options.projectRoot);
|
|
206
162
|
sourceMap.addVLQMap(resultMap);
|
|
207
163
|
let sourcemapReference = await getSourceMapReference(sourceMap);
|
|
208
|
-
|
|
209
164
|
if (sourcemapReference) {
|
|
210
165
|
minifiedContents += `\n//# sourceMappingURL=${sourcemapReference}\n`;
|
|
211
166
|
}
|
|
212
167
|
}
|
|
213
|
-
|
|
214
168
|
return {
|
|
215
169
|
contents: minifiedContents,
|
|
216
170
|
map: sourceMap
|
|
217
171
|
};
|
|
218
172
|
}
|
|
219
|
-
|
|
220
173
|
});
|
|
221
|
-
|
|
222
174
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/optimizer-terser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
"source": "src/TerserOptimizer.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "^2.
|
|
20
|
+
"parcel": "^2.9.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.
|
|
24
|
-
"@parcel/plugin": "2.
|
|
23
|
+
"@parcel/diagnostic": "2.9.0",
|
|
24
|
+
"@parcel/plugin": "2.9.0",
|
|
25
25
|
"@parcel/source-map": "^2.1.1",
|
|
26
|
-
"@parcel/utils": "2.
|
|
26
|
+
"@parcel/utils": "2.9.0",
|
|
27
27
|
"nullthrows": "^1.1.1",
|
|
28
28
|
"terser": "^5.2.0"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
|
|
31
31
|
}
|
package/src/TerserOptimizer.js
CHANGED
|
@@ -13,16 +13,9 @@ export default (new Optimizer({
|
|
|
13
13
|
async loadConfig({config, options}) {
|
|
14
14
|
let userConfig = await config.getConfigFrom(
|
|
15
15
|
path.join(options.projectRoot, 'index'),
|
|
16
|
-
['.terserrc', '.terserrc.js', '.terserrc.cjs'],
|
|
16
|
+
['.terserrc', '.terserrc.js', '.terserrc.cjs', '.terserrc.mjs'],
|
|
17
17
|
);
|
|
18
18
|
|
|
19
|
-
if (userConfig) {
|
|
20
|
-
let isJavascript = path.extname(userConfig.filePath) === '.js';
|
|
21
|
-
if (isJavascript) {
|
|
22
|
-
config.invalidateOnStartup();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
19
|
return userConfig?.contents;
|
|
27
20
|
},
|
|
28
21
|
async optimize({
|