@parcel/optimizer-terser 2.0.0-beta.3.1 → 2.0.0-nightly.1006

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,9 +115,8 @@ 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'], options.projectRoot);
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
121
  filename: _path().default.relative(options.projectRoot, _path().default.join(bundle.target.distDir, bundle.name)),
105
122
  asObject: true,
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/optimizer-terser",
3
- "version": "2.0.0-beta.3.1",
3
+ "version": "2.0.0-nightly.1006+18b038d5",
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.1004+18b038d5"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/diagnostic": "2.0.0-beta.3.1",
24
- "@parcel/plugin": "2.0.0-beta.3.1",
25
- "@parcel/source-map": "2.0.0-rc.1.0",
26
- "@parcel/utils": "2.0.0-beta.3.1",
23
+ "@parcel/diagnostic": "2.0.0-nightly.1006+18b038d5",
24
+ "@parcel/plugin": "2.0.0-nightly.1006+18b038d5",
25
+ "@parcel/source-map": "^2.0.0",
26
+ "@parcel/utils": "2.0.0-nightly.1006+18b038d5",
27
27
  "nullthrows": "^1.1.1",
28
28
  "terser": "^5.2.0"
29
29
  },
30
- "gitHead": "daece49d003ba804bbdaa3a7ed3d6aaf446f166d"
30
+ "gitHead": "18b038d57043965afb31077db1f46dadb11a6a78"
31
31
  }
@@ -3,30 +3,45 @@
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
- options.projectRoot,
25
- );
26
-
27
42
  let originalMap = map ? await map.stringify({}) : null;
28
43
  let config = {
29
- ...userConfig?.config,
44
+ ...userConfig,
30
45
  sourceMap: bundle.env.sourceMap
31
46
  ? {
32
47
  filename: path.relative(
@@ -59,12 +74,14 @@ export default (new Optimizer({
59
74
  diagnostics.push({
60
75
  message,
61
76
  origin: '@parcel/optimizer-terser',
62
- language: 'js',
63
- filePath,
64
- codeFrame: {
65
- code: await options.inputFS.readFile(filePath, 'utf8'),
66
- codeHighlights: [{message, start: original, end: original}],
67
- },
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
+ ],
68
85
  hints: ["It's likely that Terser doesn't support this syntax yet."],
69
86
  });
70
87
  }
@@ -77,12 +94,14 @@ export default (new Optimizer({
77
94
  diagnostics.push({
78
95
  message,
79
96
  origin: '@parcel/optimizer-terser',
80
- language: 'js',
81
- filePath: undefined,
82
- codeFrame: {
83
- code,
84
- codeHighlights: [{message, start: loc, end: loc}],
85
- },
97
+ codeFrames: [
98
+ {
99
+ language: 'js',
100
+ filePath: undefined,
101
+ code,
102
+ codeHighlights: [{message, start: loc, end: loc}],
103
+ },
104
+ ],
86
105
  hints: ["It's likely that Terser doesn't support this syntax yet."],
87
106
  });
88
107
  }