@parcel/optimizer-terser 2.0.0-beta.3.1 → 2.0.0-dev.1510
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 +22 -54
- package/package.json +7 -7
- package/src/TerserOptimizer.js +34 -22
package/lib/TerserOptimizer.js
CHANGED
|
@@ -4,88 +4,71 @@ 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
|
-
function
|
|
79
|
-
|
|
80
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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
|
-
|
|
56
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
57
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
82
58
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
83
|
-
|
|
84
|
-
|
|
59
|
+
var _default = exports.default = new (_plugin().Optimizer)({
|
|
60
|
+
async loadConfig({
|
|
61
|
+
config,
|
|
62
|
+
options
|
|
63
|
+
}) {
|
|
64
|
+
let userConfig = await config.getConfigFrom(_path().default.join(options.projectRoot, 'index'), ['.terserrc', '.terserrc.js', '.terserrc.cjs', '.terserrc.mjs']);
|
|
65
|
+
return userConfig === null || userConfig === void 0 ? void 0 : userConfig.contents;
|
|
66
|
+
},
|
|
85
67
|
async optimize({
|
|
86
68
|
contents,
|
|
87
69
|
map,
|
|
88
70
|
bundle,
|
|
71
|
+
config: userConfig,
|
|
89
72
|
options,
|
|
90
73
|
getSourceMapReference
|
|
91
74
|
}) {
|
|
@@ -95,11 +78,10 @@ var _default = new (_plugin().Optimizer)({
|
|
|
95
78
|
map
|
|
96
79
|
};
|
|
97
80
|
}
|
|
98
|
-
|
|
99
81
|
let code = await (0, _utils().blobToString)(contents);
|
|
100
|
-
let userConfig = await (0, _utils().loadConfig)(options.inputFS, _path().default.join(options.entryRoot, 'index'), ['.terserrc', '.uglifyrc', '.uglifyrc.js', '.terserrc.js'], options.projectRoot);
|
|
101
82
|
let originalMap = map ? await map.stringify({}) : null;
|
|
102
|
-
let config = {
|
|
83
|
+
let config = {
|
|
84
|
+
...userConfig,
|
|
103
85
|
sourceMap: bundle.env.sourceMap ? {
|
|
104
86
|
filename: _path().default.relative(options.projectRoot, _path().default.join(bundle.target.distDir, bundle.name)),
|
|
105
87
|
asObject: true,
|
|
@@ -109,7 +91,6 @@ var _default = new (_plugin().Optimizer)({
|
|
|
109
91
|
module: bundle.env.outputFormat === 'esmodule'
|
|
110
92
|
};
|
|
111
93
|
let result;
|
|
112
|
-
|
|
113
94
|
try {
|
|
114
95
|
result = await (0, _terser().minify)(code, config);
|
|
115
96
|
} catch (error) {
|
|
@@ -119,37 +100,32 @@ var _default = new (_plugin().Optimizer)({
|
|
|
119
100
|
line,
|
|
120
101
|
col
|
|
121
102
|
} = error;
|
|
122
|
-
|
|
123
103
|
if (line != null && col != null) {
|
|
124
104
|
message = (0, _diagnostic().escapeMarkdown)(message);
|
|
125
105
|
let diagnostics = [];
|
|
126
106
|
let mapping = map === null || map === void 0 ? void 0 : map.findClosestMapping(line, col);
|
|
127
|
-
|
|
128
107
|
if (mapping && mapping.original && mapping.source) {
|
|
129
108
|
let {
|
|
130
109
|
source,
|
|
131
110
|
original
|
|
132
111
|
} = mapping;
|
|
133
|
-
|
|
134
112
|
let filePath = _path().default.resolve(options.projectRoot, source);
|
|
135
|
-
|
|
136
113
|
diagnostics.push({
|
|
137
114
|
message,
|
|
138
115
|
origin: '@parcel/optimizer-terser',
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
116
|
+
codeFrames: [{
|
|
117
|
+
language: 'js',
|
|
118
|
+
filePath,
|
|
142
119
|
code: await options.inputFS.readFile(filePath, 'utf8'),
|
|
143
120
|
codeHighlights: [{
|
|
144
121
|
message,
|
|
145
122
|
start: original,
|
|
146
123
|
end: original
|
|
147
124
|
}]
|
|
148
|
-
},
|
|
125
|
+
}],
|
|
149
126
|
hints: ["It's likely that Terser doesn't support this syntax yet."]
|
|
150
127
|
});
|
|
151
128
|
}
|
|
152
|
-
|
|
153
129
|
if (diagnostics.length === 0 || options.logLevel === 'verbose') {
|
|
154
130
|
let loc = {
|
|
155
131
|
line: line,
|
|
@@ -158,20 +134,19 @@ var _default = new (_plugin().Optimizer)({
|
|
|
158
134
|
diagnostics.push({
|
|
159
135
|
message,
|
|
160
136
|
origin: '@parcel/optimizer-terser',
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
137
|
+
codeFrames: [{
|
|
138
|
+
language: 'js',
|
|
139
|
+
filePath: undefined,
|
|
164
140
|
code,
|
|
165
141
|
codeHighlights: [{
|
|
166
142
|
message,
|
|
167
143
|
start: loc,
|
|
168
144
|
end: loc
|
|
169
145
|
}]
|
|
170
|
-
},
|
|
146
|
+
}],
|
|
171
147
|
hints: ["It's likely that Terser doesn't support this syntax yet."]
|
|
172
148
|
});
|
|
173
149
|
}
|
|
174
|
-
|
|
175
150
|
throw new (_diagnostic().default)({
|
|
176
151
|
diagnostic: diagnostics
|
|
177
152
|
});
|
|
@@ -179,27 +154,20 @@ var _default = new (_plugin().Optimizer)({
|
|
|
179
154
|
throw error;
|
|
180
155
|
}
|
|
181
156
|
}
|
|
182
|
-
|
|
183
157
|
let sourceMap = null;
|
|
184
158
|
let minifiedContents = (0, _nullthrows().default)(result.code);
|
|
185
159
|
let resultMap = result.map;
|
|
186
|
-
|
|
187
160
|
if (resultMap && typeof resultMap !== 'string') {
|
|
188
161
|
sourceMap = new (_sourceMap().default)(options.projectRoot);
|
|
189
162
|
sourceMap.addVLQMap(resultMap);
|
|
190
163
|
let sourcemapReference = await getSourceMapReference(sourceMap);
|
|
191
|
-
|
|
192
164
|
if (sourcemapReference) {
|
|
193
165
|
minifiedContents += `\n//# sourceMappingURL=${sourcemapReference}\n`;
|
|
194
166
|
}
|
|
195
167
|
}
|
|
196
|
-
|
|
197
168
|
return {
|
|
198
169
|
contents: minifiedContents,
|
|
199
170
|
map: sourceMap
|
|
200
171
|
};
|
|
201
172
|
}
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
exports.default = _default;
|
|
173
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/optimizer-terser",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-dev.1510+a9bb85adf",
|
|
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.0.0-
|
|
20
|
+
"parcel": "^2.0.0-dev.1508+a9bb85adf"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.0.0-
|
|
24
|
-
"@parcel/plugin": "2.0.0-
|
|
25
|
-
"@parcel/source-map": "2.
|
|
26
|
-
"@parcel/utils": "2.0.0-
|
|
23
|
+
"@parcel/diagnostic": "2.0.0-dev.1510+a9bb85adf",
|
|
24
|
+
"@parcel/plugin": "2.0.0-dev.1510+a9bb85adf",
|
|
25
|
+
"@parcel/source-map": "^2.1.1",
|
|
26
|
+
"@parcel/utils": "2.0.0-dev.1510+a9bb85adf",
|
|
27
27
|
"nullthrows": "^1.1.1",
|
|
28
28
|
"terser": "^5.2.0"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "a9bb85adf8f3b38631e178b3aacaa30c78696e36"
|
|
31
31
|
}
|
package/src/TerserOptimizer.js
CHANGED
|
@@ -3,30 +3,38 @@
|
|
|
3
3
|
import nullthrows from 'nullthrows';
|
|
4
4
|
import {minify} from 'terser';
|
|
5
5
|
import {Optimizer} from '@parcel/plugin';
|
|
6
|
-
import {blobToString
|
|
6
|
+
import {blobToString} from '@parcel/utils';
|
|
7
7
|
import SourceMap from '@parcel/source-map';
|
|
8
8
|
import ThrowableDiagnostic, {escapeMarkdown} from '@parcel/diagnostic';
|
|
9
9
|
|
|
10
10
|
import path from 'path';
|
|
11
11
|
|
|
12
12
|
export default (new Optimizer({
|
|
13
|
-
async
|
|
13
|
+
async loadConfig({config, options}) {
|
|
14
|
+
let userConfig = await config.getConfigFrom(
|
|
15
|
+
path.join(options.projectRoot, 'index'),
|
|
16
|
+
['.terserrc', '.terserrc.js', '.terserrc.cjs', '.terserrc.mjs'],
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return userConfig?.contents;
|
|
20
|
+
},
|
|
21
|
+
async optimize({
|
|
22
|
+
contents,
|
|
23
|
+
map,
|
|
24
|
+
bundle,
|
|
25
|
+
config: userConfig,
|
|
26
|
+
options,
|
|
27
|
+
getSourceMapReference,
|
|
28
|
+
}) {
|
|
14
29
|
if (!bundle.env.shouldOptimize) {
|
|
15
30
|
return {contents, map};
|
|
16
31
|
}
|
|
17
32
|
|
|
18
33
|
let code = await blobToString(contents);
|
|
19
34
|
|
|
20
|
-
let userConfig = await loadConfig(
|
|
21
|
-
options.inputFS,
|
|
22
|
-
path.join(options.entryRoot, 'index'),
|
|
23
|
-
['.terserrc', '.uglifyrc', '.uglifyrc.js', '.terserrc.js'],
|
|
24
|
-
options.projectRoot,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
35
|
let originalMap = map ? await map.stringify({}) : null;
|
|
28
36
|
let config = {
|
|
29
|
-
...userConfig
|
|
37
|
+
...userConfig,
|
|
30
38
|
sourceMap: bundle.env.sourceMap
|
|
31
39
|
? {
|
|
32
40
|
filename: path.relative(
|
|
@@ -59,12 +67,14 @@ export default (new Optimizer({
|
|
|
59
67
|
diagnostics.push({
|
|
60
68
|
message,
|
|
61
69
|
origin: '@parcel/optimizer-terser',
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
codeFrames: [
|
|
71
|
+
{
|
|
72
|
+
language: 'js',
|
|
73
|
+
filePath,
|
|
74
|
+
code: await options.inputFS.readFile(filePath, 'utf8'),
|
|
75
|
+
codeHighlights: [{message, start: original, end: original}],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
68
78
|
hints: ["It's likely that Terser doesn't support this syntax yet."],
|
|
69
79
|
});
|
|
70
80
|
}
|
|
@@ -77,12 +87,14 @@ export default (new Optimizer({
|
|
|
77
87
|
diagnostics.push({
|
|
78
88
|
message,
|
|
79
89
|
origin: '@parcel/optimizer-terser',
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
codeFrames: [
|
|
91
|
+
{
|
|
92
|
+
language: 'js',
|
|
93
|
+
filePath: undefined,
|
|
94
|
+
code,
|
|
95
|
+
codeHighlights: [{message, start: loc, end: loc}],
|
|
96
|
+
},
|
|
97
|
+
],
|
|
86
98
|
hints: ["It's likely that Terser doesn't support this syntax yet."],
|
|
87
99
|
});
|
|
88
100
|
}
|