@atlaspack/core 2.12.1-canary.3556 → 2.12.1-canary.3557

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.
@@ -18,16 +18,16 @@ function _buildCache() {
18
18
  };
19
19
  return data;
20
20
  }
21
- function _sourceMap() {
22
- const data = _interopRequireDefault(require("@parcel/source-map"));
23
- _sourceMap = function () {
21
+ function _utils() {
22
+ const data = require("@atlaspack/utils");
23
+ _utils = function () {
24
24
  return data;
25
25
  };
26
26
  return data;
27
27
  }
28
- function _utils() {
29
- const data = require("@atlaspack/utils");
30
- _utils = function () {
28
+ function _sourceMap() {
29
+ const data = _interopRequireDefault(require("@parcel/source-map"));
30
+ _sourceMap = function () {
31
31
  return data;
32
32
  };
33
33
  return data;
@@ -98,6 +98,22 @@ class CommittedAsset {
98
98
  if (mapKey != null && this.mapBuffer == null) {
99
99
  this.mapBuffer = (async () => {
100
100
  try {
101
+ // Handle v3 assets that were processed by the native asset graph code (i.e. not runtime
102
+ // or helper assets)
103
+ if (this.options.featureFlags.atlaspackV3 && this.value.meta.isV3 === true) {
104
+ let buffer = await this.options.cache.getBuffer(mapKey);
105
+ if (!buffer) {
106
+ return buffer;
107
+ }
108
+
109
+ // We make the conversion from json to buffer here, since both js packagers lazily
110
+ // instantiate a sourcemap from the map buffer. This ensures we do not have to modify
111
+ // the packagers in any significant way. Additionally, storing the SourceMap objects
112
+ // upfront in these packagers appears to make larger builds more prone to failing.
113
+ let sourceMap = new (_sourceMap().default)(this.options.projectRoot);
114
+ sourceMap.addVLQMap(JSON.parse(buffer.toString()));
115
+ return sourceMap.toBuffer();
116
+ }
101
117
  return await this.options.cache.getBlob(mapKey);
102
118
  } catch (err) {
103
119
  if (err.code === 'ENOENT' && this.value.astKey != null) {
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MutableAsset = void 0;
7
+ function _sourceMap() {
8
+ const data = _interopRequireDefault(require("@parcel/source-map"));
9
+ _sourceMap = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
7
14
  function _stream() {
8
15
  const data = require("stream");
9
16
  _stream = function () {
@@ -15,40 +22,42 @@ var _bitflags = require("./bitflags");
15
22
  var _assetSymbols = require("./asset-symbols");
16
23
  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); }
17
24
  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; }
25
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
26
  class MutableAsset {
19
- #inner;
27
+ #astDirty;
20
28
  #ast;
21
29
  #contents;
22
- #astDirty;
30
+ #inner;
31
+ #map;
32
+ #projectRoot;
33
+ #sourceMap;
23
34
  get astGenerator() {
24
35
  throw new Error('get MutableAsset.astGenerator');
25
36
  }
26
37
  set astGenerator(value) {
27
38
  throw new Error('set MutableAsset.astGenerator');
28
39
  }
29
- constructor(asset, contents, env, fs) {
30
- this.#inner = asset;
31
- this.stats = asset.stats;
32
- this.id = asset.id;
40
+ constructor(asset, contents, env, fs, map, projectRoot) {
41
+ this.bundleBehavior = _bitflags.bundleBehaviorMap.fromNullable(asset.bundleBehavior);
42
+ this.env = env;
33
43
  this.filePath = asset.filePath;
34
- this.type;
35
- this.symbols = new _assetSymbols.MutableAssetSymbols(asset.symbols);
36
- this.stats = asset.stats;
44
+ this.fs = fs;
37
45
  this.id = asset.id;
38
- this.filePath = asset.filePath;
39
- this.type = asset.type;
40
- this.query = new URLSearchParams(asset.query);
46
+ this.isBundleSplittable = asset.isBundleSplittable;
41
47
  this.isSource = asset.isSource;
42
48
  this.meta = asset.meta;
43
- this.bundleBehavior = _bitflags.bundleBehaviorMap.fromNullable(asset.bundleBehavior);
44
- this.isBundleSplittable = asset.isBundleSplittable;
49
+ this.pipeline = asset.pipeline;
50
+ this.query = new URLSearchParams(asset.query);
45
51
  this.sideEffects = asset.sideEffects;
52
+ this.stats = asset.stats;
53
+ this.symbols = new _assetSymbols.MutableAssetSymbols(asset.symbols);
54
+ this.type = asset.type;
46
55
  this.uniqueKey = asset.uniqueKey;
47
- this.pipeline = asset.pipeline;
48
- this.#contents = contents;
49
- this.fs = fs;
50
- this.env = env;
51
56
  this.#astDirty = false;
57
+ this.#contents = contents;
58
+ this.#inner = asset;
59
+ this.#map = map;
60
+ this.#projectRoot = projectRoot;
52
61
  }
53
62
 
54
63
  // eslint-disable-next-line require-await
@@ -94,16 +103,23 @@ class MutableAsset {
94
103
  });
95
104
  }
96
105
  getMap() {
97
- // TODO: Provide source maps once they exist
98
- return Promise.resolve(null);
106
+ // Only create the source map if it is requested
107
+ if (!this.#sourceMap && this.#map && typeof this.#map === 'string') {
108
+ let sourceMap = new (_sourceMap().default)(this.#projectRoot);
109
+ // $FlowFixMe Flow is dumb
110
+ sourceMap.addVLQMap(JSON.parse(this.#map));
111
+ this.#sourceMap = sourceMap;
112
+ }
113
+ return Promise.resolve(this.#sourceMap);
99
114
  }
100
115
 
101
116
  // eslint-disable-next-line no-unused-vars
102
- setMap() {
103
- throw new Error('MutableAsset.setMap()');
117
+ setMap(sourceMap) {
118
+ this.isMapDirty = true;
119
+ this.#sourceMap = sourceMap;
104
120
  }
105
121
  getMapBuffer() {
106
- throw new Error('MutableAsset.getMapBuffer');
122
+ throw new Error('getMapBuffer() is considered an internal implementation detail, please use getMap() instead');
107
123
  }
108
124
  getDependencies() {
109
125
  throw new Error('MutableAsset.getDependencies');
@@ -169,7 +169,7 @@ class AtlaspackWorker {
169
169
  env: napiEnv,
170
170
  options,
171
171
  asset: innerAsset
172
- }, contents) => {
172
+ }, contents, map) => {
173
173
  var _transformer$loadConf;
174
174
  const state = this.#transformers.get(key);
175
175
  if (!state) {
@@ -187,7 +187,7 @@ class AtlaspackWorker {
187
187
  return Promise.resolve(resolvedPath);
188
188
  };
189
189
  const env = new _compat.Environment(napiEnv);
190
- const mutableAsset = new _compat.MutableAsset(innerAsset, contents, env, this.#fs);
190
+ const mutableAsset = new _compat.MutableAsset(innerAsset, contents, env, this.#fs, map, options.projectRoot);
191
191
  const defaultOptions = {
192
192
  logger: new _compat.PluginLogger(),
193
193
  tracer: new _compat.PluginTracer(),
@@ -243,6 +243,9 @@ class AtlaspackWorker {
243
243
  } else {
244
244
  mutableAsset.setStream(output.content);
245
245
  }
246
+ if (output.map) {
247
+ mutableAsset.setMap(output.map);
248
+ }
246
249
  }
247
250
  }
248
251
  (0, _assert().default)(result.length === 1, '[V3] Unimplemented: Multiple asset return from Node transformer');
@@ -250,19 +253,23 @@ class AtlaspackWorker {
250
253
  return [{
251
254
  id: mutableAsset.id,
252
255
  bundleBehavior: _compat.bundleBehaviorMap.intoNullable(mutableAsset.bundleBehavior),
253
- filePath: mutableAsset.filePath,
254
- type: mutableAsset.type,
255
256
  code: [],
257
+ filePath: mutableAsset.filePath,
258
+ isBundleSplittable: mutableAsset.isBundleSplittable,
259
+ isSource: mutableAsset.isSource,
256
260
  meta: mutableAsset.meta,
257
261
  pipeline: mutableAsset.pipeline,
258
262
  // Query should be undefined if it's empty
259
263
  query: mutableAsset.query.toString() || undefined,
260
- symbols: mutableAsset.symbols.intoNapi(),
261
- uniqueKey: mutableAsset.uniqueKey,
262
264
  sideEffects: mutableAsset.sideEffects,
263
- isBundleSplittable: mutableAsset.isBundleSplittable,
264
- isSource: mutableAsset.isSource
265
- }, await mutableAsset.getBuffer()];
265
+ symbols: mutableAsset.symbols.intoNapi(),
266
+ type: mutableAsset.type,
267
+ uniqueKey: mutableAsset.uniqueKey
268
+ }, await mutableAsset.getBuffer(),
269
+ // Only send back the map if it has changed
270
+ mutableAsset.isMapDirty ?
271
+ // $FlowFixMe A dirty map means this will be valid
272
+ JSON.stringify((await mutableAsset.getMap()).toVLQ()) : ''];
266
273
  });
267
274
  }
268
275
  exports.AtlaspackWorker = AtlaspackWorker;
@@ -18,24 +18,9 @@ function _diagnostic() {
18
18
  };
19
19
  return data;
20
20
  }
21
- function _rust() {
22
- const data = require("@atlaspack/rust");
23
- _rust = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
21
  var _AssetGraph = _interopRequireWildcard(require("../AssetGraph"));
29
- var _constants = require("../constants");
30
22
  var _RequestTracker = require("../RequestTracker");
31
23
  var _SymbolPropagation = require("../SymbolPropagation");
32
- function _sourceMap() {
33
- const data = _interopRequireDefault(require("@parcel/source-map"));
34
- _sourceMap = function () {
35
- return data;
36
- };
37
- return data;
38
- }
39
24
  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); }
40
25
  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; }
41
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -57,7 +42,7 @@ function createAssetGraphRequestRust(rustAtlaspack) {
57
42
  let {
58
43
  assetGraph,
59
44
  changedAssets
60
- } = getAssetGraph(serializedAssetGraph, options);
45
+ } = getAssetGraph(serializedAssetGraph);
61
46
  let changedAssetsPropagation = new Set(changedAssets.keys());
62
47
  let errors = (0, _SymbolPropagation.propagateSymbols)({
63
48
  options,
@@ -86,7 +71,7 @@ function createAssetGraphRequestRust(rustAtlaspack) {
86
71
  input
87
72
  });
88
73
  }
89
- function getAssetGraph(serializedGraph, options) {
74
+ function getAssetGraph(serializedGraph) {
90
75
  let graph = new _AssetGraph.default({
91
76
  _contentKeyToNodeId: new Map(),
92
77
  _nodeIdToContentKey: new Map(),
@@ -154,21 +139,18 @@ function getAssetGraph(serializedGraph, options) {
154
139
  deps = new Map();
155
140
  dependencyMap.set(id, deps);
156
141
  }
157
- asset.dependencies = deps;
158
142
  asset.committed = true;
159
143
  asset.contentKey = id;
144
+ asset.dependencies = deps;
160
145
  asset.env.id = getEnvId(asset.env);
146
+ asset.mapKey = `map:${asset.id}`;
147
+
148
+ // We need to add this property for source map handling, as some assets like runtimes
149
+ // are processed after the Rust transformation and take the v2 code path
150
+ asset.meta.isV3 = true;
161
151
  if (asset.symbols != null) {
162
152
  asset.symbols = new Map(asset.symbols.map(mapSymbols));
163
153
  }
164
- if (asset.map) {
165
- let mapKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:map:${asset.id}`);
166
- let sourceMap = new (_sourceMap().default)(options.projectRoot);
167
- sourceMap.addVLQMap(JSON.parse(asset.map));
168
- asset.mapKey = mapKey;
169
- options.cache.setBlob(mapKey, sourceMap.toBuffer());
170
- delete asset.map;
171
- }
172
154
  cachedAssets.set(id, asset.code);
173
155
  changedAssets.set(id, asset);
174
156
  graph.addNodeByContentKey(id, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.12.1-canary.3556+d32468aff",
3
+ "version": "2.12.1-canary.3557+4ec090221",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,21 +20,21 @@
20
20
  "check-ts": "tsc --noEmit index.d.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@atlaspack/build-cache": "2.12.1-canary.3556+d32468aff",
24
- "@atlaspack/cache": "2.12.1-canary.3556+d32468aff",
25
- "@atlaspack/diagnostic": "2.12.1-canary.3556+d32468aff",
26
- "@atlaspack/events": "2.12.1-canary.3556+d32468aff",
27
- "@atlaspack/feature-flags": "2.12.1-canary.3556+d32468aff",
28
- "@atlaspack/fs": "2.12.1-canary.3556+d32468aff",
29
- "@atlaspack/graph": "3.2.1-canary.3556+d32468aff",
30
- "@atlaspack/logger": "2.12.1-canary.3556+d32468aff",
31
- "@atlaspack/package-manager": "2.12.1-canary.3556+d32468aff",
32
- "@atlaspack/plugin": "2.12.1-canary.3556+d32468aff",
33
- "@atlaspack/profiler": "2.12.1-canary.3556+d32468aff",
34
- "@atlaspack/rust": "2.12.1-canary.3556+d32468aff",
35
- "@atlaspack/types": "2.12.1-canary.3556+d32468aff",
36
- "@atlaspack/utils": "2.12.1-canary.3556+d32468aff",
37
- "@atlaspack/workers": "2.12.1-canary.3556+d32468aff",
23
+ "@atlaspack/build-cache": "2.12.1-canary.3557+4ec090221",
24
+ "@atlaspack/cache": "2.12.1-canary.3557+4ec090221",
25
+ "@atlaspack/diagnostic": "2.12.1-canary.3557+4ec090221",
26
+ "@atlaspack/events": "2.12.1-canary.3557+4ec090221",
27
+ "@atlaspack/feature-flags": "2.12.1-canary.3557+4ec090221",
28
+ "@atlaspack/fs": "2.12.1-canary.3557+4ec090221",
29
+ "@atlaspack/graph": "3.2.1-canary.3557+4ec090221",
30
+ "@atlaspack/logger": "2.12.1-canary.3557+4ec090221",
31
+ "@atlaspack/package-manager": "2.12.1-canary.3557+4ec090221",
32
+ "@atlaspack/plugin": "2.12.1-canary.3557+4ec090221",
33
+ "@atlaspack/profiler": "2.12.1-canary.3557+4ec090221",
34
+ "@atlaspack/rust": "2.12.1-canary.3557+4ec090221",
35
+ "@atlaspack/types": "2.12.1-canary.3557+4ec090221",
36
+ "@atlaspack/utils": "2.12.1-canary.3557+4ec090221",
37
+ "@atlaspack/workers": "2.12.1-canary.3557+4ec090221",
38
38
  "@mischnic/json-sourcemap": "^0.1.0",
39
39
  "@parcel/source-map": "^2.1.1",
40
40
  "base-x": "^3.0.8",
@@ -66,5 +66,5 @@
66
66
  "browser": {
67
67
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
68
68
  },
69
- "gitHead": "d32468affac184f10d2167710022e72133ee162c"
69
+ "gitHead": "4ec0902215c46322d903e12467b31a8cedc0e879"
70
70
  }
@@ -1,15 +1,14 @@
1
1
  // @flow strict-local
2
2
 
3
- import type {AST, Blob} from '@atlaspack/types';
4
- import type {Asset, Dependency, AtlaspackOptions} from './types';
5
-
6
3
  import {Readable} from 'stream';
7
4
 
8
5
  import {deserializeRaw} from '@atlaspack/build-cache';
9
- import SourceMap from '@parcel/source-map';
6
+ import type {AST, Blob} from '@atlaspack/types';
10
7
  import {bufferStream, blobToStream, streamFromPromise} from '@atlaspack/utils';
8
+ import SourceMap from '@parcel/source-map';
11
9
 
12
10
  import {generateFromAST} from './assetUtils';
11
+ import type {Asset, Dependency, AtlaspackOptions} from './types';
13
12
 
14
13
  export default class CommittedAsset {
15
14
  key: ?string;
@@ -20,7 +19,6 @@ export default class CommittedAsset {
20
19
  map: ?Promise<?SourceMap>;
21
20
  ast: ?Promise<AST>;
22
21
  code: ?string;
23
- generatingPromise: ?Promise<void>;
24
22
 
25
23
  constructor(value: Asset, options: AtlaspackOptions) {
26
24
  this.value = value;
@@ -97,6 +95,26 @@ export default class CommittedAsset {
97
95
  if (mapKey != null && this.mapBuffer == null) {
98
96
  this.mapBuffer = (async () => {
99
97
  try {
98
+ // Handle v3 assets that were processed by the native asset graph code (i.e. not runtime
99
+ // or helper assets)
100
+ if (
101
+ this.options.featureFlags.atlaspackV3 &&
102
+ this.value.meta.isV3 === true
103
+ ) {
104
+ let buffer = await this.options.cache.getBuffer(mapKey);
105
+ if (!buffer) {
106
+ return buffer;
107
+ }
108
+
109
+ // We make the conversion from json to buffer here, since both js packagers lazily
110
+ // instantiate a sourcemap from the map buffer. This ensures we do not have to modify
111
+ // the packagers in any significant way. Additionally, storing the SourceMap objects
112
+ // upfront in these packagers appears to make larger builds more prone to failing.
113
+ let sourceMap = new SourceMap(this.options.projectRoot);
114
+ sourceMap.addVLQMap(JSON.parse(buffer.toString()));
115
+ return sourceMap.toBuffer();
116
+ }
117
+
100
118
  return await this.options.cache.getBlob(mapKey);
101
119
  } catch (err) {
102
120
  if (err.code === 'ENOENT' && this.value.astKey != null) {
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
 
3
- import type SourceMap from '@parcel/source-map';
3
+ import SourceMap from '@parcel/source-map';
4
4
  import * as napi from '@atlaspack/rust';
5
5
  import {Readable} from 'stream';
6
6
  import type {
@@ -24,26 +24,30 @@ import {MutableAssetSymbols} from './asset-symbols';
24
24
  export type InnerAsset = napi.Asset;
25
25
 
26
26
  export class MutableAsset implements IMutableAsset {
27
- fs: FileSystem;
27
+ bundleBehavior: ?BundleBehavior;
28
28
  env: Environment;
29
- symbols: MutableAssetSymbols;
30
- stats: Stats;
31
- id: string;
32
29
  filePath: FilePath;
33
- type: string;
34
- query: URLSearchParams;
30
+ fs: FileSystem;
31
+ id: string;
32
+ isBundleSplittable: boolean;
33
+ isMapDirty: boolean;
35
34
  isSource: boolean;
36
35
  meta: Meta;
37
- bundleBehavior: ?BundleBehavior;
38
- isBundleSplittable: boolean;
36
+ pipeline: ?string;
37
+ query: URLSearchParams;
39
38
  sideEffects: boolean;
39
+ stats: Stats;
40
+ symbols: MutableAssetSymbols;
41
+ type: string;
40
42
  uniqueKey: ?string;
41
- pipeline: ?string;
42
43
 
43
- #inner: InnerAsset;
44
+ #astDirty: boolean;
44
45
  #ast: ?AST;
45
46
  #contents: Buffer;
46
- #astDirty: boolean;
47
+ #inner: InnerAsset;
48
+ #map: ?string;
49
+ #projectRoot: string;
50
+ #sourceMap: ?SourceMap;
47
51
 
48
52
  get astGenerator(): ?ASTGenerator {
49
53
  throw new Error('get MutableAsset.astGenerator');
@@ -58,29 +62,30 @@ export class MutableAsset implements IMutableAsset {
58
62
  contents: Buffer,
59
63
  env: Environment,
60
64
  fs: FileSystem,
65
+ map: ?string,
66
+ projectRoot: string,
61
67
  ) {
62
- this.#inner = asset;
63
- this.stats = asset.stats;
64
- this.id = asset.id;
68
+ this.bundleBehavior = bundleBehaviorMap.fromNullable(asset.bundleBehavior);
69
+ this.env = env;
65
70
  this.filePath = asset.filePath;
66
- this.type;
67
- this.symbols = new MutableAssetSymbols(asset.symbols);
68
- this.stats = asset.stats;
71
+ this.fs = fs;
69
72
  this.id = asset.id;
70
- this.filePath = asset.filePath;
71
- this.type = asset.type;
72
- this.query = new URLSearchParams(asset.query);
73
+ this.isBundleSplittable = asset.isBundleSplittable;
73
74
  this.isSource = asset.isSource;
74
75
  this.meta = asset.meta;
75
- this.bundleBehavior = bundleBehaviorMap.fromNullable(asset.bundleBehavior);
76
- this.isBundleSplittable = asset.isBundleSplittable;
76
+ this.pipeline = asset.pipeline;
77
+ this.query = new URLSearchParams(asset.query);
77
78
  this.sideEffects = asset.sideEffects;
79
+ this.stats = asset.stats;
80
+ this.symbols = new MutableAssetSymbols(asset.symbols);
81
+ this.type = asset.type;
78
82
  this.uniqueKey = asset.uniqueKey;
79
- this.pipeline = asset.pipeline;
80
- this.#contents = contents;
81
- this.fs = fs;
82
- this.env = env;
83
+
83
84
  this.#astDirty = false;
85
+ this.#contents = contents;
86
+ this.#inner = asset;
87
+ this.#map = map;
88
+ this.#projectRoot = projectRoot;
84
89
  }
85
90
 
86
91
  // eslint-disable-next-line require-await
@@ -136,17 +141,27 @@ export class MutableAsset implements IMutableAsset {
136
141
  }
137
142
 
138
143
  getMap(): Promise<?SourceMap> {
139
- // TODO: Provide source maps once they exist
140
- return Promise.resolve(null);
144
+ // Only create the source map if it is requested
145
+ if (!this.#sourceMap && this.#map && typeof this.#map === 'string') {
146
+ let sourceMap = new SourceMap(this.#projectRoot);
147
+ // $FlowFixMe Flow is dumb
148
+ sourceMap.addVLQMap(JSON.parse(this.#map));
149
+ this.#sourceMap = sourceMap;
150
+ }
151
+
152
+ return Promise.resolve(this.#sourceMap);
141
153
  }
142
154
 
143
155
  // eslint-disable-next-line no-unused-vars
144
156
  setMap(sourceMap: ?SourceMap): void {
145
- throw new Error('MutableAsset.setMap()');
157
+ this.isMapDirty = true;
158
+ this.#sourceMap = sourceMap;
146
159
  }
147
160
 
148
161
  getMapBuffer(): Promise<?Buffer> {
149
- throw new Error('MutableAsset.getMapBuffer');
162
+ throw new Error(
163
+ 'getMapBuffer() is considered an internal implementation detail, please use getMap() instead',
164
+ );
150
165
  }
151
166
 
152
167
  getDependencies(): $ReadOnlyArray<Dependency> {
@@ -159,10 +159,10 @@ export class AtlaspackWorker {
159
159
  );
160
160
 
161
161
  runTransformerTransform: JsCallable<
162
- [RunTransformerTransformOptions, Buffer],
162
+ [RunTransformerTransformOptions, Buffer, ?string],
163
163
  Promise<RunTransformerTransformResult>,
164
164
  > = jsCallable(
165
- async ({key, env: napiEnv, options, asset: innerAsset}, contents) => {
165
+ async ({key, env: napiEnv, options, asset: innerAsset}, contents, map) => {
166
166
  const state = this.#transformers.get(key);
167
167
  if (!state) {
168
168
  throw new Error(`Transformer not found: ${key}`);
@@ -188,6 +188,8 @@ export class AtlaspackWorker {
188
188
  contents,
189
189
  env,
190
190
  this.#fs,
191
+ map,
192
+ options.projectRoot,
191
193
  );
192
194
 
193
195
  const defaultOptions = {
@@ -250,6 +252,10 @@ export class AtlaspackWorker {
250
252
  } else {
251
253
  mutableAsset.setStream(output.content);
252
254
  }
255
+
256
+ if (output.map) {
257
+ mutableAsset.setMap(output.map);
258
+ }
253
259
  }
254
260
  }
255
261
 
@@ -269,20 +275,25 @@ export class AtlaspackWorker {
269
275
  bundleBehavior: bundleBehaviorMap.intoNullable(
270
276
  mutableAsset.bundleBehavior,
271
277
  ),
272
- filePath: mutableAsset.filePath,
273
- type: mutableAsset.type,
274
278
  code: [],
279
+ filePath: mutableAsset.filePath,
280
+ isBundleSplittable: mutableAsset.isBundleSplittable,
281
+ isSource: mutableAsset.isSource,
275
282
  meta: mutableAsset.meta,
276
283
  pipeline: mutableAsset.pipeline,
277
284
  // Query should be undefined if it's empty
278
285
  query: mutableAsset.query.toString() || undefined,
286
+ sideEffects: mutableAsset.sideEffects,
279
287
  symbols: mutableAsset.symbols.intoNapi(),
288
+ type: mutableAsset.type,
280
289
  uniqueKey: mutableAsset.uniqueKey,
281
- sideEffects: mutableAsset.sideEffects,
282
- isBundleSplittable: mutableAsset.isBundleSplittable,
283
- isSource: mutableAsset.isSource,
284
290
  },
285
291
  await mutableAsset.getBuffer(),
292
+ // Only send back the map if it has changed
293
+ mutableAsset.isMapDirty
294
+ ? // $FlowFixMe A dirty map means this will be valid
295
+ JSON.stringify((await mutableAsset.getMap()).toVLQ())
296
+ : '',
286
297
  ];
287
298
  },
288
299
  );
@@ -366,4 +377,4 @@ type RunTransformerTransformOptions = {|
366
377
  asset: napi.Asset,
367
378
  |};
368
379
 
369
- type RunTransformerTransformResult = [napi.RpcAssetResult, Buffer];
380
+ type RunTransformerTransformResult = [napi.RpcAssetResult, Buffer, string];
@@ -3,12 +3,10 @@
3
3
  import invariant from 'assert';
4
4
 
5
5
  import ThrowableDiagnostic from '@atlaspack/diagnostic';
6
- import {hashString} from '@atlaspack/rust';
7
6
  import type {Async} from '@atlaspack/types';
8
7
 
9
8
  import AssetGraph, {nodeFromAssetGroup} from '../AssetGraph';
10
9
  import type {AtlaspackV3} from '../atlaspack-v3';
11
- import {ATLASPACK_VERSION} from '../constants';
12
10
  import {requestTypes, type StaticRunOpts} from '../RequestTracker';
13
11
  import {propagateSymbols} from '../SymbolPropagation';
14
12
  import type {Environment} from '../types';
@@ -17,7 +15,6 @@ import type {
17
15
  AssetGraphRequestInput,
18
16
  AssetGraphRequestResult,
19
17
  } from './AssetGraphRequest';
20
- import SourceMap from '@parcel/source-map';
21
18
 
22
19
  type RunInput = {|
23
20
  input: AssetGraphRequestInput,
@@ -51,10 +48,7 @@ export function createAssetGraphRequestRust(
51
48
  });
52
49
  }
53
50
 
54
- let {assetGraph, changedAssets} = getAssetGraph(
55
- serializedAssetGraph,
56
- options,
57
- );
51
+ let {assetGraph, changedAssets} = getAssetGraph(serializedAssetGraph);
58
52
 
59
53
  let changedAssetsPropagation = new Set(changedAssets.keys());
60
54
  let errors = propagateSymbols({
@@ -86,7 +80,7 @@ export function createAssetGraphRequestRust(
86
80
  });
87
81
  }
88
82
 
89
- function getAssetGraph(serializedGraph, options) {
83
+ function getAssetGraph(serializedGraph) {
90
84
  let graph = new AssetGraph({
91
85
  _contentKeyToNodeId: new Map(),
92
86
  _nodeIdToContentKey: new Map(),
@@ -176,23 +170,19 @@ function getAssetGraph(serializedGraph, options) {
176
170
  deps = new Map();
177
171
  dependencyMap.set(id, deps);
178
172
  }
179
- asset.dependencies = deps;
180
173
 
181
174
  asset.committed = true;
182
175
  asset.contentKey = id;
176
+ asset.dependencies = deps;
183
177
  asset.env.id = getEnvId(asset.env);
184
- if (asset.symbols != null) {
185
- asset.symbols = new Map(asset.symbols.map(mapSymbols));
186
- }
178
+ asset.mapKey = `map:${asset.id}`;
187
179
 
188
- if (asset.map) {
189
- let mapKey = hashString(`${ATLASPACK_VERSION}:map:${asset.id}`);
190
- let sourceMap = new SourceMap(options.projectRoot);
191
- sourceMap.addVLQMap(JSON.parse(asset.map));
180
+ // We need to add this property for source map handling, as some assets like runtimes
181
+ // are processed after the Rust transformation and take the v2 code path
182
+ asset.meta.isV3 = true;
192
183
 
193
- asset.mapKey = mapKey;
194
- options.cache.setBlob(mapKey, sourceMap.toBuffer());
195
- delete asset.map;
184
+ if (asset.symbols != null) {
185
+ asset.symbols = new Map(asset.symbols.map(mapSymbols));
196
186
  }
197
187
 
198
188
  cachedAssets.set(id, asset.code);