@atlaspack/optimizer-swc 2.16.10-dev-fix-sourcemaps-50acc1acf.0 → 2.16.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaspack/optimizer-swc
2
2
 
3
+ ## 2.16.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atlaspack/source-map@3.3.8
9
+ - @atlaspack/utils@3.4.6
10
+ - @atlaspack/plugin@2.14.64
11
+
3
12
  ## 2.16.9
4
13
 
5
14
  ### Patch Changes
@@ -36,11 +36,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ const nullthrows_1 = __importDefault(require("nullthrows"));
40
+ const core_1 = require("@swc/core");
39
41
  const plugin_1 = require("@atlaspack/plugin");
40
42
  const utils_1 = require("@atlaspack/utils");
43
+ const source_map_1 = __importDefault(require("@atlaspack/source-map"));
41
44
  const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
42
45
  const path_1 = __importDefault(require("path"));
43
- const minifyWithSourceMap_1 = require("./minifyWithSourceMap");
44
46
  exports.default = new plugin_1.Optimizer({
45
47
  async loadConfig({ config, options }) {
46
48
  let userConfig = await config.getConfigFrom(path_1.default.join(options.projectRoot, 'index'), ['.terserrc', '.terserrc.js', '.terserrc.cjs', '.terserrc.mjs']);
@@ -53,15 +55,23 @@ exports.default = new plugin_1.Optimizer({
53
55
  let code = await (0, utils_1.blobToString)(contents);
54
56
  let result;
55
57
  try {
56
- result = await (0, minifyWithSourceMap_1.minifyWithSourceMap)(code, bundle.env.sourceMap ? (originalMap ?? null) : null, {
57
- target: 'es2022',
58
- mangle: true,
59
- compress: true,
60
- toplevel: bundle.env.outputFormat === 'esmodule' ||
61
- bundle.env.outputFormat === 'commonjs',
62
- module: bundle.env.outputFormat === 'esmodule',
63
- userConfig: userConfig,
64
- projectRoot: options.projectRoot,
58
+ result = await (0, core_1.transform)(code, {
59
+ jsc: {
60
+ target: 'es2022',
61
+ minify: {
62
+ mangle: true,
63
+ compress: true,
64
+ // @ts-expect-error TS2698
65
+ ...userConfig,
66
+ toplevel: bundle.env.outputFormat === 'esmodule' ||
67
+ bundle.env.outputFormat === 'commonjs',
68
+ module: bundle.env.outputFormat === 'esmodule',
69
+ },
70
+ },
71
+ minify: true,
72
+ sourceMaps: !!bundle.env.sourceMap,
73
+ configFile: false,
74
+ swcrc: false,
65
75
  });
66
76
  }
67
77
  catch (err) {
@@ -114,9 +124,15 @@ exports.default = new plugin_1.Optimizer({
114
124
  }
115
125
  throw err;
116
126
  }
117
- let minifiedContents = result.code;
118
- const sourceMap = result.map;
119
- if (sourceMap) {
127
+ let sourceMap = null;
128
+ let minifiedContents = (0, nullthrows_1.default)(result.code);
129
+ let resultMap = result.map;
130
+ if (resultMap) {
131
+ sourceMap = new source_map_1.default(options.projectRoot);
132
+ sourceMap.addVLQMap(JSON.parse(resultMap));
133
+ if (originalMap) {
134
+ sourceMap.extends(originalMap);
135
+ }
120
136
  let sourcemapReference = await getSourceMapReference(sourceMap);
121
137
  if (sourcemapReference) {
122
138
  minifiedContents += `\n//# sourceMappingURL=${sourcemapReference}\n`;
@@ -4,6 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ function _nullthrows() {
8
+ const data = _interopRequireDefault(require("nullthrows"));
9
+ _nullthrows = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _core() {
15
+ const data = require("@swc/core");
16
+ _core = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
7
21
  function _plugin() {
8
22
  const data = require("@atlaspack/plugin");
9
23
  _plugin = function () {
@@ -18,6 +32,13 @@ function _utils() {
18
32
  };
19
33
  return data;
20
34
  }
35
+ function _sourceMap() {
36
+ const data = _interopRequireDefault(require("@atlaspack/source-map"));
37
+ _sourceMap = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
21
42
  function _diagnostic() {
22
43
  const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
23
44
  _diagnostic = function () {
@@ -32,9 +53,8 @@ function _path() {
32
53
  };
33
54
  return data;
34
55
  }
35
- var _minifyWithSourceMap = require("./minifyWithSourceMap");
36
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
37
56
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
57
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
38
58
  var _default = exports.default = new (_plugin().Optimizer)({
39
59
  async loadConfig({
40
60
  config,
@@ -60,14 +80,22 @@ var _default = exports.default = new (_plugin().Optimizer)({
60
80
  let code = await (0, _utils().blobToString)(contents);
61
81
  let result;
62
82
  try {
63
- result = await (0, _minifyWithSourceMap.minifyWithSourceMap)(code, bundle.env.sourceMap ? originalMap ?? null : null, {
64
- target: 'es2022',
65
- mangle: true,
66
- compress: true,
67
- toplevel: bundle.env.outputFormat === 'esmodule' || bundle.env.outputFormat === 'commonjs',
68
- module: bundle.env.outputFormat === 'esmodule',
69
- userConfig: userConfig,
70
- projectRoot: options.projectRoot
83
+ result = await (0, _core().transform)(code, {
84
+ jsc: {
85
+ target: 'es2022',
86
+ minify: {
87
+ mangle: true,
88
+ compress: true,
89
+ // @ts-expect-error TS2698
90
+ ...userConfig,
91
+ toplevel: bundle.env.outputFormat === 'esmodule' || bundle.env.outputFormat === 'commonjs',
92
+ module: bundle.env.outputFormat === 'esmodule'
93
+ }
94
+ },
95
+ minify: true,
96
+ sourceMaps: !!bundle.env.sourceMap,
97
+ configFile: false,
98
+ swcrc: false
71
99
  });
72
100
  } catch (err) {
73
101
  // SWC doesn't give us nice error objects, so we need to parse the message.
@@ -120,9 +148,15 @@ var _default = exports.default = new (_plugin().Optimizer)({
120
148
  }
121
149
  throw err;
122
150
  }
123
- let minifiedContents = result.code;
124
- const sourceMap = result.map;
125
- if (sourceMap) {
151
+ let sourceMap = null;
152
+ let minifiedContents = (0, _nullthrows().default)(result.code);
153
+ let resultMap = result.map;
154
+ if (resultMap) {
155
+ sourceMap = new (_sourceMap().default)(options.projectRoot);
156
+ sourceMap.addVLQMap(JSON.parse(resultMap));
157
+ if (originalMap) {
158
+ sourceMap.extends(originalMap);
159
+ }
126
160
  let sourcemapReference = await getSourceMapReference(sourceMap);
127
161
  if (sourcemapReference) {
128
162
  minifiedContents += `\n//# sourceMappingURL=${sourcemapReference}\n`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/optimizer-swc",
3
- "version": "2.16.10-dev-fix-sourcemaps-50acc1acf.0",
3
+ "version": "2.16.10",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,16 +16,15 @@
16
16
  "node": ">= 16.0.0"
17
17
  },
18
18
  "dependencies": {
19
- "@atlaspack/diagnostic": "2.14.5-dev-fix-sourcemaps-50acc1acf.0",
20
- "@atlaspack/plugin": "2.14.64-dev-fix-sourcemaps-50acc1acf.0",
21
- "@atlaspack/source-map": "3.3.8-dev-fix-sourcemaps-50acc1acf.0",
22
- "@atlaspack/utils": "3.4.6-dev-fix-sourcemaps-50acc1acf.0",
19
+ "@atlaspack/diagnostic": "2.14.4",
20
+ "@atlaspack/plugin": "2.14.64",
21
+ "@atlaspack/source-map": "3.3.8",
22
+ "@atlaspack/utils": "3.4.6",
23
23
  "@swc/core": "1.15.11",
24
24
  "nullthrows": "^1.1.1"
25
25
  },
26
26
  "type": "commonjs",
27
27
  "scripts": {
28
28
  "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
29
- },
30
- "gitHead": "50acc1acf31d5c8415a8154841a8ed09264e665a"
29
+ }
31
30
  }
@@ -1,10 +1,11 @@
1
+ import nullthrows from 'nullthrows';
2
+ import {transform} from '@swc/core';
1
3
  import {Optimizer} from '@atlaspack/plugin';
2
4
  import {blobToString, stripAnsi} from '@atlaspack/utils';
5
+ import SourceMap from '@atlaspack/source-map';
3
6
  import ThrowableDiagnostic, {escapeMarkdown} from '@atlaspack/diagnostic';
4
7
  import path from 'path';
5
8
 
6
- import {minifyWithSourceMap} from './minifyWithSourceMap';
7
-
8
9
  export default new Optimizer({
9
10
  async loadConfig({config, options}) {
10
11
  let userConfig = await config.getConfigFrom(
@@ -29,21 +30,25 @@ export default new Optimizer({
29
30
  let code = await blobToString(contents);
30
31
  let result;
31
32
  try {
32
- result = await minifyWithSourceMap(
33
- code,
34
- bundle.env.sourceMap ? (originalMap ?? null) : null,
35
- {
33
+ result = await transform(code, {
34
+ jsc: {
36
35
  target: 'es2022',
37
- mangle: true,
38
- compress: true,
39
- toplevel:
40
- bundle.env.outputFormat === 'esmodule' ||
41
- bundle.env.outputFormat === 'commonjs',
42
- module: bundle.env.outputFormat === 'esmodule',
43
- userConfig: userConfig as Record<string, unknown> | undefined,
44
- projectRoot: options.projectRoot,
36
+ minify: {
37
+ mangle: true,
38
+ compress: true,
39
+ // @ts-expect-error TS2698
40
+ ...userConfig,
41
+ toplevel:
42
+ bundle.env.outputFormat === 'esmodule' ||
43
+ bundle.env.outputFormat === 'commonjs',
44
+ module: bundle.env.outputFormat === 'esmodule',
45
+ },
45
46
  },
46
- );
47
+ minify: true,
48
+ sourceMaps: !!bundle.env.sourceMap,
49
+ configFile: false,
50
+ swcrc: false,
51
+ });
47
52
  } catch (err: any) {
48
53
  // SWC doesn't give us nice error objects, so we need to parse the message.
49
54
  let message = escapeMarkdown(
@@ -102,9 +107,15 @@ export default new Optimizer({
102
107
  throw err;
103
108
  }
104
109
 
105
- let minifiedContents: string = result.code;
106
- const sourceMap = result.map;
107
- if (sourceMap) {
110
+ let sourceMap = null;
111
+ let minifiedContents: string = nullthrows(result.code);
112
+ let resultMap = result.map;
113
+ if (resultMap) {
114
+ sourceMap = new SourceMap(options.projectRoot);
115
+ sourceMap.addVLQMap(JSON.parse(resultMap));
116
+ if (originalMap) {
117
+ sourceMap.extends(originalMap);
118
+ }
108
119
  let sourcemapReference = await getSourceMapReference(sourceMap);
109
120
  if (sourcemapReference) {
110
121
  minifiedContents += `\n//# sourceMappingURL=${sourcemapReference}\n`;