@atlaspack/core 2.16.2-canary.136 → 2.16.2-canary.138

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,36 @@
1
1
  # @atlaspack/core
2
2
 
3
+ ## 2.20.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#721](https://github.com/atlassian-labs/atlaspack/pull/721) [`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd) Thanks [@benjervis](https://github.com/benjervis)! - Add support for bundle merging based on `webpackChunkName` comments.
8
+
9
+ Adding a `webpackChunkName` comment to an import will allow the bundler to merge multiple imports into a single bundle.
10
+
11
+ e.g.:
12
+
13
+ ```ts
14
+ import(/* webpackChunkName: "my-chunk" */ './my-module');
15
+ import(/* webpackChunkName: "my-chunk" */ './another-module');
16
+ ```
17
+
18
+ This can be enabled with the feature flag `supportWebpackChunkName`.
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
23
+ - @atlaspack/feature-flags@2.20.0
24
+ - @atlaspack/fs@2.15.16
25
+ - @atlaspack/profiler@2.14.18
26
+ - @atlaspack/types@2.15.11
27
+ - @atlaspack/workers@2.14.21
28
+ - @atlaspack/cache@3.2.16
29
+ - @atlaspack/graph@3.5.10
30
+ - @atlaspack/utils@2.17.3
31
+ - @atlaspack/package-manager@2.14.21
32
+ - @atlaspack/plugin@2.14.21
33
+
3
34
  ## 2.19.2
4
35
 
5
36
  ### Patch Changes
@@ -617,8 +617,12 @@ class BundleGraph {
617
617
  return this.getBundlesInBundleGroup(node.value, {
618
618
  includeInline: true
619
619
  }).find(b => {
620
- let mainEntryId = b.entryAssetIds[b.entryAssetIds.length - 1];
621
- return mainEntryId != null && node.value.entryAssetId === mainEntryId;
620
+ if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
621
+ return b.entryAssetIds.some(id => id === node.value.entryAssetId);
622
+ } else {
623
+ let mainEntryId = b.entryAssetIds[b.entryAssetIds.length - 1];
624
+ return mainEntryId != null && node.value.entryAssetId === mainEntryId;
625
+ }
622
626
  });
623
627
  }
624
628
  }
@@ -39,6 +39,13 @@ var _types = require("../types");
39
39
  var _BundleGroup = _interopRequireWildcard(require("./BundleGroup"));
40
40
  var _IdentifierRegistry = require("../IdentifierRegistry");
41
41
  var _EnvironmentManager = require("../EnvironmentManager");
42
+ function _featureFlags() {
43
+ const data = require("@atlaspack/feature-flags");
44
+ _featureFlags = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
42
49
  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); }
43
50
  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; }
44
51
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -143,6 +150,17 @@ class MutableBundleGraph extends _BundleGraph.default {
143
150
  (0, _assert().default)((entryAssetNode === null || entryAssetNode === void 0 ? void 0 : entryAssetNode.type) === 'asset', 'Entry asset does not exist');
144
151
  isPlaceholder = entryAssetNode.requested === false;
145
152
  }
153
+ let entryAssetIds = [];
154
+ if (entryAsset) {
155
+ entryAssetIds = [entryAsset.id];
156
+ if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
157
+ let bundleRoots = opts.bundleRoots ?? [entryAsset];
158
+ let bundleRootIds = bundleRoots.map(({
159
+ id
160
+ }) => id).filter(assetId => assetId !== entryAsset.id);
161
+ entryAssetIds.push(...bundleRootIds);
162
+ }
163
+ }
146
164
  let bundleNode = {
147
165
  type: 'bundle',
148
166
  id: bundleId,
@@ -151,7 +169,7 @@ class MutableBundleGraph extends _BundleGraph.default {
151
169
  hashReference: this.#options.shouldContentHash ? _constants.HASH_REF_PREFIX + bundleId : bundleId.slice(-8),
152
170
  type: opts.entryAsset ? opts.entryAsset.type : opts.type,
153
171
  env: opts.env ? (0, _EnvironmentManager.toEnvironmentRef)((0, _Environment.environmentToInternalEnvironment)(opts.env)) : (0, _nullthrows().default)(entryAsset).env,
154
- entryAssetIds: entryAsset ? [entryAsset.id] : [],
172
+ entryAssetIds,
155
173
  mainEntryId: entryAsset === null || entryAsset === void 0 ? void 0 : entryAsset.id,
156
174
  pipeline: opts.entryAsset ? opts.entryAsset.pipeline : opts.pipeline,
157
175
  needsStableName: opts.needsStableName,
@@ -166,8 +184,8 @@ class MutableBundleGraph extends _BundleGraph.default {
166
184
  }
167
185
  };
168
186
  let bundleNodeId = this.#graph._graph.addNodeByContentKey(bundleId, bundleNode);
169
- if (opts.entryAsset) {
170
- this.#graph._graph.addEdge(bundleNodeId, this.#graph._graph.getNodeIdByContentKey(opts.entryAsset.id));
187
+ for (let assetId of entryAssetIds) {
188
+ this.#graph._graph.addEdge(bundleNodeId, this.#graph._graph.getNodeIdByContentKey(assetId));
171
189
  }
172
190
  return _Bundle.Bundle.get(bundleNode.value, this.#graph, this.#options);
173
191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.16.2-canary.136+d90b6d22d",
3
+ "version": "2.16.2-canary.138+eda07caaf",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -21,21 +21,21 @@
21
21
  "check-ts": "tsc --noEmit index.d.ts"
22
22
  },
23
23
  "dependencies": {
24
- "@atlaspack/build-cache": "2.13.3-canary.204+d90b6d22d",
25
- "@atlaspack/cache": "3.1.1-canary.136+d90b6d22d",
26
- "@atlaspack/diagnostic": "2.14.1-canary.204+d90b6d22d",
27
- "@atlaspack/events": "2.14.1-canary.204+d90b6d22d",
28
- "@atlaspack/feature-flags": "2.14.1-canary.204+d90b6d22d",
29
- "@atlaspack/fs": "2.14.5-canary.136+d90b6d22d",
30
- "@atlaspack/graph": "3.4.1-canary.204+d90b6d22d",
31
- "@atlaspack/logger": "2.14.5-canary.136+d90b6d22d",
32
- "@atlaspack/package-manager": "2.14.5-canary.136+d90b6d22d",
33
- "@atlaspack/plugin": "2.14.5-canary.136+d90b6d22d",
34
- "@atlaspack/profiler": "2.14.1-canary.204+d90b6d22d",
35
- "@atlaspack/rust": "3.2.1-canary.136+d90b6d22d",
36
- "@atlaspack/types": "2.14.5-canary.136+d90b6d22d",
37
- "@atlaspack/utils": "2.14.5-canary.136+d90b6d22d",
38
- "@atlaspack/workers": "2.14.5-canary.136+d90b6d22d",
24
+ "@atlaspack/build-cache": "2.13.3-canary.206+eda07caaf",
25
+ "@atlaspack/cache": "3.1.1-canary.138+eda07caaf",
26
+ "@atlaspack/diagnostic": "2.14.1-canary.206+eda07caaf",
27
+ "@atlaspack/events": "2.14.1-canary.206+eda07caaf",
28
+ "@atlaspack/feature-flags": "2.14.1-canary.206+eda07caaf",
29
+ "@atlaspack/fs": "2.14.5-canary.138+eda07caaf",
30
+ "@atlaspack/graph": "3.4.1-canary.206+eda07caaf",
31
+ "@atlaspack/logger": "2.14.5-canary.138+eda07caaf",
32
+ "@atlaspack/package-manager": "2.14.5-canary.138+eda07caaf",
33
+ "@atlaspack/plugin": "2.14.5-canary.138+eda07caaf",
34
+ "@atlaspack/profiler": "2.14.1-canary.206+eda07caaf",
35
+ "@atlaspack/rust": "3.2.1-canary.138+eda07caaf",
36
+ "@atlaspack/types": "2.14.5-canary.138+eda07caaf",
37
+ "@atlaspack/utils": "2.14.5-canary.138+eda07caaf",
38
+ "@atlaspack/workers": "2.14.5-canary.138+eda07caaf",
39
39
  "@mischnic/json-sourcemap": "^0.1.0",
40
40
  "@parcel/source-map": "^2.1.1",
41
41
  "base-x": "^3.0.8",
@@ -60,5 +60,5 @@
60
60
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
61
61
  },
62
62
  "type": "commonjs",
63
- "gitHead": "d90b6d22db4f44b6831c33933ddd31d4a77800a6"
63
+ "gitHead": "eda07caafd2ebb814bbdbfd0ec12fa63124e213f"
64
64
  }
@@ -552,6 +552,7 @@ export default class BundleGraph {
552
552
  opts:
553
553
  | {|
554
554
  +entryAsset: Asset,
555
+ +bundleRoots?: Array<Asset>,
555
556
  +target: Target,
556
557
  +needsStableName?: ?boolean,
557
558
  +bundleBehavior?: ?IBundleBehavior,
@@ -932,8 +933,12 @@ export default class BundleGraph {
932
933
  return this.getBundlesInBundleGroup(node.value, {
933
934
  includeInline: true,
934
935
  }).find((b) => {
935
- let mainEntryId = b.entryAssetIds[b.entryAssetIds.length - 1];
936
- return mainEntryId != null && node.value.entryAssetId === mainEntryId;
936
+ if (getFeatureFlag('supportWebpackChunkName')) {
937
+ return b.entryAssetIds.some((id) => id === node.value.entryAssetId);
938
+ } else {
939
+ let mainEntryId = b.entryAssetIds[b.entryAssetIds.length - 1];
940
+ return mainEntryId != null && node.value.entryAssetId === mainEntryId;
941
+ }
937
942
  });
938
943
  }
939
944
  }
@@ -34,6 +34,7 @@ import BundleGroup, {bundleGroupToInternalBundleGroup} from './BundleGroup';
34
34
  import type {ProjectPath} from '../projectPath';
35
35
  import {identifierRegistry} from '../IdentifierRegistry';
36
36
  import {toEnvironmentRef} from '../EnvironmentManager';
37
+ import {getFeatureFlag} from '@atlaspack/feature-flags';
37
38
 
38
39
  function createBundleId(data: {|
39
40
  entryAssetId: string | null,
@@ -229,6 +230,17 @@ export default class MutableBundleGraph
229
230
  isPlaceholder = entryAssetNode.requested === false;
230
231
  }
231
232
 
233
+ let entryAssetIds = [];
234
+ if (entryAsset) {
235
+ entryAssetIds = [entryAsset.id];
236
+ if (getFeatureFlag('supportWebpackChunkName')) {
237
+ let bundleRoots = opts.bundleRoots ?? [entryAsset];
238
+ let bundleRootIds = bundleRoots
239
+ .map(({id}) => id)
240
+ .filter((assetId) => assetId !== entryAsset.id);
241
+ entryAssetIds.push(...bundleRootIds);
242
+ }
243
+ }
232
244
  let bundleNode: BundleNode = {
233
245
  type: 'bundle',
234
246
  id: bundleId,
@@ -241,7 +253,7 @@ export default class MutableBundleGraph
241
253
  env: opts.env
242
254
  ? toEnvironmentRef(environmentToInternalEnvironment(opts.env))
243
255
  : nullthrows(entryAsset).env,
244
- entryAssetIds: entryAsset ? [entryAsset.id] : [],
256
+ entryAssetIds,
245
257
  mainEntryId: entryAsset?.id,
246
258
  pipeline: opts.entryAsset ? opts.entryAsset.pipeline : opts.pipeline,
247
259
  needsStableName: opts.needsStableName,
@@ -266,10 +278,10 @@ export default class MutableBundleGraph
266
278
  bundleNode,
267
279
  );
268
280
 
269
- if (opts.entryAsset) {
281
+ for (let assetId of entryAssetIds) {
270
282
  this.#graph._graph.addEdge(
271
283
  bundleNodeId,
272
- this.#graph._graph.getNodeIdByContentKey(opts.entryAsset.id),
284
+ this.#graph._graph.getNodeIdByContentKey(assetId),
273
285
  );
274
286
  }
275
287
  return Bundle.get(bundleNode.value, this.#graph, this.#options);