@parcel/optimizer-terser 2.0.0-beta.2 → 2.0.0-nightly.1004

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.
@@ -75,17 +75,35 @@ function _path() {
75
75
  return data;
76
76
  }
77
77
 
78
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
78
+ 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
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; }
80
+ 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
81
 
82
82
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
83
83
 
84
84
  var _default = new (_plugin().Optimizer)({
85
+ async loadConfig({
86
+ config,
87
+ options
88
+ }) {
89
+ let userConfig = await config.getConfigFrom(_path().default.join(options.projectRoot, 'index'), ['.terserrc', '.terserrc.js']);
90
+
91
+ if (userConfig) {
92
+ let isJavascript = _path().default.extname(userConfig.filePath) === '.js';
93
+
94
+ if (isJavascript) {
95
+ config.invalidateOnStartup();
96
+ }
97
+ }
98
+
99
+ return userConfig === null || userConfig === void 0 ? void 0 : userConfig.contents;
100
+ },
101
+
85
102
  async optimize({
86
103
  contents,
87
104
  map,
88
105
  bundle,
106
+ config: userConfig,
89
107
  options,
90
108
  getSourceMapReference
91
109
  }) {
@@ -97,11 +115,10 @@ var _default = new (_plugin().Optimizer)({
97
115
  }
98
116
 
99
117
  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']);
101
118
  let originalMap = map ? await map.stringify({}) : null;
102
- let config = { ...(userConfig === null || userConfig === void 0 ? void 0 : userConfig.config),
119
+ let config = { ...userConfig,
103
120
  sourceMap: bundle.env.sourceMap ? {
104
- filename: _path().default.relative(options.projectRoot, bundle.filePath),
121
+ filename: _path().default.relative(options.projectRoot, _path().default.join(bundle.target.distDir, bundle.name)),
105
122
  asObject: true,
106
123
  content: originalMap
107
124
  } : false,
@@ -136,16 +153,16 @@ var _default = new (_plugin().Optimizer)({
136
153
  diagnostics.push({
137
154
  message,
138
155
  origin: '@parcel/optimizer-terser',
139
- language: 'js',
140
- filePath,
141
- codeFrame: {
156
+ codeFrames: [{
157
+ language: 'js',
158
+ filePath,
142
159
  code: await options.inputFS.readFile(filePath, 'utf8'),
143
160
  codeHighlights: [{
144
161
  message,
145
162
  start: original,
146
163
  end: original
147
164
  }]
148
- },
165
+ }],
149
166
  hints: ["It's likely that Terser doesn't support this syntax yet."]
150
167
  });
151
168
  }
@@ -158,16 +175,16 @@ var _default = new (_plugin().Optimizer)({
158
175
  diagnostics.push({
159
176
  message,
160
177
  origin: '@parcel/optimizer-terser',
161
- language: 'js',
162
- filePath: undefined,
163
- codeFrame: {
178
+ codeFrames: [{
179
+ language: 'js',
180
+ filePath: undefined,
164
181
  code,
165
182
  codeHighlights: [{
166
183
  message,
167
184
  start: loc,
168
185
  end: loc
169
186
  }]
170
- },
187
+ }],
171
188
  hints: ["It's likely that Terser doesn't support this syntax yet."]
172
189
  });
173
190
  }
@@ -186,7 +203,7 @@ var _default = new (_plugin().Optimizer)({
186
203
 
187
204
  if (resultMap && typeof resultMap !== 'string') {
188
205
  sourceMap = new (_sourceMap().default)(options.projectRoot);
189
- sourceMap.addRawMappings(resultMap);
206
+ sourceMap.addVLQMap(resultMap);
190
207
  let sourcemapReference = await getSourceMapReference(sourceMap);
191
208
 
192
209
  if (sourcemapReference) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/optimizer-terser",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-nightly.1004+47379bf8",
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-beta.1"
20
+ "parcel": "2.0.0-nightly.1002+47379bf8"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/diagnostic": "2.0.0-beta.2",
24
- "@parcel/plugin": "2.0.0-beta.2",
25
- "@parcel/source-map": "2.0.0-alpha.4.21",
26
- "@parcel/utils": "2.0.0-beta.2",
23
+ "@parcel/diagnostic": "2.0.0-nightly.1004+47379bf8",
24
+ "@parcel/plugin": "2.0.0-nightly.1004+47379bf8",
25
+ "@parcel/source-map": "^2.0.0",
26
+ "@parcel/utils": "2.0.0-nightly.1004+47379bf8",
27
27
  "nullthrows": "^1.1.1",
28
28
  "terser": "^5.2.0"
29
29
  },
30
- "gitHead": "a3aa86815e098c90fda72a08d29646ff059ab74d"
30
+ "gitHead": "47379bf8fabeb2cfe03ade8802d942388b153e5b"
31
31
  }
@@ -3,32 +3,51 @@
3
3
  import nullthrows from 'nullthrows';
4
4
  import {minify} from 'terser';
5
5
  import {Optimizer} from '@parcel/plugin';
6
- import {blobToString, loadConfig} from '@parcel/utils';
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 optimize({contents, map, bundle, options, getSourceMapReference}) {
13
+ async loadConfig({config, options}) {
14
+ let userConfig = await config.getConfigFrom(
15
+ path.join(options.projectRoot, 'index'),
16
+ ['.terserrc', '.terserrc.js'],
17
+ );
18
+
19
+ if (userConfig) {
20
+ let isJavascript = path.extname(userConfig.filePath) === '.js';
21
+ if (isJavascript) {
22
+ config.invalidateOnStartup();
23
+ }
24
+ }
25
+
26
+ return userConfig?.contents;
27
+ },
28
+ async optimize({
29
+ contents,
30
+ map,
31
+ bundle,
32
+ config: userConfig,
33
+ options,
34
+ getSourceMapReference,
35
+ }) {
14
36
  if (!bundle.env.shouldOptimize) {
15
37
  return {contents, map};
16
38
  }
17
39
 
18
40
  let code = await blobToString(contents);
19
41
 
20
- let userConfig = await loadConfig(
21
- options.inputFS,
22
- path.join(options.entryRoot, 'index'),
23
- ['.terserrc', '.uglifyrc', '.uglifyrc.js', '.terserrc.js'],
24
- );
25
-
26
42
  let originalMap = map ? await map.stringify({}) : null;
27
43
  let config = {
28
- ...userConfig?.config,
44
+ ...userConfig,
29
45
  sourceMap: bundle.env.sourceMap
30
46
  ? {
31
- filename: path.relative(options.projectRoot, bundle.filePath),
47
+ filename: path.relative(
48
+ options.projectRoot,
49
+ path.join(bundle.target.distDir, bundle.name),
50
+ ),
32
51
  asObject: true,
33
52
  content: originalMap,
34
53
  }
@@ -55,12 +74,14 @@ export default (new Optimizer({
55
74
  diagnostics.push({
56
75
  message,
57
76
  origin: '@parcel/optimizer-terser',
58
- language: 'js',
59
- filePath,
60
- codeFrame: {
61
- code: await options.inputFS.readFile(filePath, 'utf8'),
62
- codeHighlights: [{message, start: original, end: original}],
63
- },
77
+ codeFrames: [
78
+ {
79
+ language: 'js',
80
+ filePath,
81
+ code: await options.inputFS.readFile(filePath, 'utf8'),
82
+ codeHighlights: [{message, start: original, end: original}],
83
+ },
84
+ ],
64
85
  hints: ["It's likely that Terser doesn't support this syntax yet."],
65
86
  });
66
87
  }
@@ -73,12 +94,14 @@ export default (new Optimizer({
73
94
  diagnostics.push({
74
95
  message,
75
96
  origin: '@parcel/optimizer-terser',
76
- language: 'js',
77
- filePath: undefined,
78
- codeFrame: {
79
- code,
80
- codeHighlights: [{message, start: loc, end: loc}],
81
- },
97
+ codeFrames: [
98
+ {
99
+ language: 'js',
100
+ filePath: undefined,
101
+ code,
102
+ codeHighlights: [{message, start: loc, end: loc}],
103
+ },
104
+ ],
82
105
  hints: ["It's likely that Terser doesn't support this syntax yet."],
83
106
  });
84
107
  }
@@ -93,7 +116,7 @@ export default (new Optimizer({
93
116
  let resultMap = result.map;
94
117
  if (resultMap && typeof resultMap !== 'string') {
95
118
  sourceMap = new SourceMap(options.projectRoot);
96
- sourceMap.addRawMappings(resultMap);
119
+ sourceMap.addVLQMap(resultMap);
97
120
  let sourcemapReference = await getSourceMapReference(sourceMap);
98
121
  if (sourcemapReference) {
99
122
  minifiedContents += `\n//# sourceMappingURL=${sourcemapReference}\n`;