@atlaspack/core 2.12.1-dev.3401 → 2.12.1-dev.3450
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/lib/AssetGraph.js +1 -2
- package/lib/Atlaspack.js +25 -3
- package/lib/AtlaspackConfig.schema.js +10 -36
- package/lib/BundleGraph.js +59 -5
- package/lib/Dependency.js +46 -1
- package/lib/Environment.js +12 -2
- package/lib/PackagerRunner.js +3 -45
- package/lib/RequestTracker.js +112 -30
- package/lib/SymbolPropagation.js +1 -1
- package/lib/Transformation.js +1 -15
- package/lib/UncommittedAsset.js +4 -4
- package/lib/Validation.js +1 -13
- package/lib/applyRuntimes.js +96 -20
- package/lib/assetUtils.js +9 -3
- package/lib/atlaspack-v3/AtlaspackV3.js +6 -8
- package/lib/atlaspack-v3/fs.js +8 -1
- package/lib/atlaspack-v3/worker/compat.js +57 -0
- package/lib/atlaspack-v3/worker/worker.js +247 -1
- package/lib/public/BundleGraph.js +68 -0
- package/lib/requests/AssetGraphRequestRust.js +79 -12
- package/lib/requests/BundleGraphRequest.js +19 -0
- package/lib/requests/WriteBundleRequest.js +15 -15
- package/lib/requests/asset-graph-diff.js +128 -0
- package/lib/resolveOptions.js +15 -8
- package/lib/types.js +2 -1
- package/package.json +19 -17
- package/src/AssetGraph.js +1 -1
- package/src/Atlaspack.js +28 -6
- package/src/AtlaspackConfig.schema.js +13 -36
- package/src/BundleGraph.js +77 -1
- package/src/CommittedAsset.js +1 -1
- package/src/Dependency.js +50 -12
- package/src/Environment.js +13 -15
- package/src/PackagerRunner.js +5 -53
- package/src/RequestTracker.js +144 -38
- package/src/SymbolPropagation.js +5 -2
- package/src/Transformation.js +1 -9
- package/src/UncommittedAsset.js +6 -6
- package/src/Validation.js +1 -7
- package/src/applyRuntimes.js +86 -22
- package/src/assetUtils.js +12 -19
- package/src/atlaspack-v3/AtlaspackV3.js +8 -11
- package/src/atlaspack-v3/fs.js +8 -3
- package/src/atlaspack-v3/jsCallable.js +4 -0
- package/src/atlaspack-v3/worker/compat.js +82 -0
- package/src/atlaspack-v3/worker/worker.js +300 -2
- package/src/public/BundleGraph.js +106 -0
- package/src/requests/AssetGraphRequestRust.js +105 -17
- package/src/requests/BundleGraphRequest.js +18 -0
- package/src/requests/WriteBundleRequest.js +17 -23
- package/src/requests/asset-graph-diff.js +145 -0
- package/src/resolveOptions.js +12 -2
- package/src/types.js +10 -0
- package/test/AssetGraph.test.js +23 -9
- package/test/AtlaspackConfigRequest.test.js +0 -161
- package/test/BundleGraph.test.js +8 -3
- package/test/Dependency.test.js +21 -0
- package/test/Environment.test.js +16 -5
- package/test/InternalAsset.test.js +8 -2
- package/test/PublicAsset.test.js +6 -2
- package/test/PublicBundle.test.js +1 -0
- package/test/PublicMutableBundleGraph.test.js +9 -4
- package/test/RequestTracker.test.js +139 -2
- package/test/SymbolPropagation.test.js +1 -0
- package/test/TargetRequest.test.js +25 -25
- package/test/requests/WriteBundleRequest.test.js +132 -0
- package/lib/atlaspack-v3/plugins/Resolver.js +0 -12
- package/lib/atlaspack-v3/plugins/index.js +0 -16
- package/src/atlaspack-v3/plugins/Resolver.js +0 -9
- package/src/atlaspack-v3/plugins/index.js +0 -3
package/lib/AssetGraph.js
CHANGED
|
@@ -189,8 +189,7 @@ class AssetGraph extends _graph().ContentGraph {
|
|
|
189
189
|
// The passed project path is ignored in this case, because there is no `loc`
|
|
190
190
|
(0, _Dependency.createDependency)('', {
|
|
191
191
|
specifier: (0, _projectPath.fromProjectPathRelative)(entry.filePath),
|
|
192
|
-
specifierType: '
|
|
193
|
-
// ???
|
|
192
|
+
specifierType: 'url',
|
|
194
193
|
pipeline: target.pipeline,
|
|
195
194
|
target: target,
|
|
196
195
|
env: target.env,
|
package/lib/Atlaspack.js
CHANGED
|
@@ -151,6 +151,11 @@ class Atlaspack {
|
|
|
151
151
|
if (this.#initialized) {
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
|
+
const featureFlags = {
|
|
155
|
+
..._featureFlags().DEFAULT_FEATURE_FLAGS,
|
|
156
|
+
...this.#initialOptions.featureFlags
|
|
157
|
+
};
|
|
158
|
+
(0, _featureFlags().setFeatureFlags)(featureFlags);
|
|
154
159
|
await _sourceMap().init;
|
|
155
160
|
await (_rust().init === null || _rust().init === void 0 ? void 0 : (0, _rust().init)());
|
|
156
161
|
try {
|
|
@@ -162,7 +167,10 @@ class Atlaspack {
|
|
|
162
167
|
// Fallthrough
|
|
163
168
|
_logger().default.warn(e);
|
|
164
169
|
}
|
|
165
|
-
let resolvedOptions = await (0, _resolveOptions.default)(
|
|
170
|
+
let resolvedOptions = await (0, _resolveOptions.default)({
|
|
171
|
+
...this.#initialOptions,
|
|
172
|
+
featureFlags
|
|
173
|
+
});
|
|
166
174
|
this.#resolvedOptions = resolvedOptions;
|
|
167
175
|
let rustAtlaspack;
|
|
168
176
|
if (resolvedOptions.featureFlags.atlaspackV3) {
|
|
@@ -176,15 +184,26 @@ class Atlaspack {
|
|
|
176
184
|
rustAtlaspack = new _atlaspackV.AtlaspackV3({
|
|
177
185
|
...options,
|
|
178
186
|
corePath: _path().default.join(__dirname, '..'),
|
|
187
|
+
threads: process.env.NODE_ENV === 'test' ? 2 : undefined,
|
|
179
188
|
entries: Array.isArray(entries) ? entries : entries == null ? undefined : [entries],
|
|
180
|
-
|
|
189
|
+
env: resolvedOptions.env,
|
|
190
|
+
fs: inputFS && (0, _atlaspackV.toFileSystemV3)(inputFS),
|
|
191
|
+
defaultTargetOptions: {
|
|
192
|
+
// $FlowFixMe projectPath is just a string
|
|
193
|
+
distDir: resolvedOptions.defaultTargetOptions.distDir,
|
|
194
|
+
engines: resolvedOptions.defaultTargetOptions.engines,
|
|
195
|
+
isLibrary: resolvedOptions.defaultTargetOptions.isLibrary,
|
|
196
|
+
outputFormat: resolvedOptions.defaultTargetOptions.outputFormat,
|
|
197
|
+
sourceMaps: resolvedOptions.defaultTargetOptions.sourceMaps,
|
|
198
|
+
shouldOptimize: resolvedOptions.defaultTargetOptions.shouldOptimize,
|
|
199
|
+
shouldScopeHoist: resolvedOptions.defaultTargetOptions.shouldScopeHoist
|
|
200
|
+
}
|
|
181
201
|
});
|
|
182
202
|
}
|
|
183
203
|
let {
|
|
184
204
|
config
|
|
185
205
|
} = await (0, _AtlaspackConfigRequest.loadAtlaspackConfig)(resolvedOptions);
|
|
186
206
|
this.#config = new _AtlaspackConfig.default(config, resolvedOptions);
|
|
187
|
-
(0, _featureFlags().setFeatureFlags)(resolvedOptions.featureFlags);
|
|
188
207
|
if (this.#initialOptions.workerFarm) {
|
|
189
208
|
if (this.#initialOptions.workerFarm.ending) {
|
|
190
209
|
throw new Error('Supplied WorkerFarm is ending');
|
|
@@ -508,6 +527,9 @@ class Atlaspack {
|
|
|
508
527
|
});
|
|
509
528
|
return this.#farm.takeHeapSnapshot();
|
|
510
529
|
}
|
|
530
|
+
async unstable_invalidate() {
|
|
531
|
+
await this._init();
|
|
532
|
+
}
|
|
511
533
|
async unstable_transform(options) {
|
|
512
534
|
var _options$env;
|
|
513
535
|
if (!this.#initialized) {
|
|
@@ -5,42 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.validatePackageName = validatePackageName;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
function validatePackageName(pkg, pluginType, key) {
|
|
19
|
-
// $FlowFixMe
|
|
20
|
-
if (!pkg) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
(0, _assert().default)(typeof pkg === 'string', `"${key}" must be a string`);
|
|
24
|
-
|
|
25
|
-
// Probably all of these need to be removed
|
|
26
|
-
if (pkg.startsWith('@atlaspack') || pkg.startsWith('@parcel')) {
|
|
27
|
-
(0, _assert().default)(pkg.replace(/^@atlaspack\//, '').startsWith(`${pluginType}-`), `Official atlaspack ${pluginType} packages must be named according to "@atlaspack/${pluginType}-{name}"`);
|
|
28
|
-
} else if (pkg.startsWith('@')) {
|
|
29
|
-
// Disabling this validation to allow for migration to parcel
|
|
30
|
-
// let [scope, name] = pkg.split('/');
|
|
31
|
-
// assert(
|
|
32
|
-
// name.startsWith(`parcel-${pluginType}-`) ||
|
|
33
|
-
// name === `parcel-${pluginType}` ||
|
|
34
|
-
// name.startsWith(`parcel-${pluginType}-`) ||
|
|
35
|
-
// name === `parcel-${pluginType}`,
|
|
36
|
-
// `Scoped parcel ${pluginType} packages must be named according to "${scope}/parcel-${pluginType}[-{name}]"`,
|
|
37
|
-
// );
|
|
38
|
-
} else if (!pkg.startsWith('.')) {
|
|
39
|
-
(0, _assert().default)(pkg.startsWith(`parcel-${pluginType}-`) || pkg.startsWith(`atlaspack-${pluginType}`),
|
|
40
|
-
// let the error message be wrong for now
|
|
41
|
-
`Atlaspack ${pluginType} packages must be named according to "parcel-${pluginType}-{name}"`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
8
|
+
// Parcel validates plugin package names due to:
|
|
9
|
+
//
|
|
10
|
+
// * https://github.com/parcel-bundler/parcel/issues/3397#issuecomment-521353931
|
|
11
|
+
//
|
|
12
|
+
// Ultimately:
|
|
13
|
+
//
|
|
14
|
+
// * We do not care about package names
|
|
15
|
+
// * Validation makes interop between parcel/atlaspack confusing.
|
|
16
|
+
//
|
|
17
|
+
function validatePackageName() {}
|
|
44
18
|
const validatePluginName = (pluginType, key) => {
|
|
45
19
|
return val => {
|
|
46
20
|
// allow plugin spread...
|
package/lib/BundleGraph.js
CHANGED
|
@@ -44,6 +44,13 @@ var _utils2 = require("./utils");
|
|
|
44
44
|
var _Environment = require("./public/Environment");
|
|
45
45
|
var _projectPath = require("./projectPath");
|
|
46
46
|
var _constants = require("./constants");
|
|
47
|
+
function _featureFlags() {
|
|
48
|
+
const data = require("@atlaspack/feature-flags");
|
|
49
|
+
_featureFlags = function () {
|
|
50
|
+
return data;
|
|
51
|
+
};
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
47
54
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
48
55
|
const bundleGraphEdgeTypes = exports.bundleGraphEdgeTypes = {
|
|
49
56
|
// A lack of an edge type indicates to follow the edge while traversing
|
|
@@ -107,16 +114,19 @@ class BundleGraph {
|
|
|
107
114
|
/** The internal core Graph structure */
|
|
108
115
|
|
|
109
116
|
_bundlePublicIds /*: Set<string> */ = new Set();
|
|
117
|
+
_conditions /*: Map<string, Condition> */ = new Map();
|
|
110
118
|
constructor({
|
|
111
119
|
graph,
|
|
112
120
|
publicIdByAssetId,
|
|
113
121
|
assetPublicIds,
|
|
114
|
-
bundleContentHashes
|
|
122
|
+
bundleContentHashes,
|
|
123
|
+
conditions
|
|
115
124
|
}) {
|
|
116
125
|
this._graph = graph;
|
|
117
126
|
this._assetPublicIds = assetPublicIds;
|
|
118
127
|
this._publicIdByAssetId = publicIdByAssetId;
|
|
119
128
|
this._bundleContentHashes = bundleContentHashes;
|
|
129
|
+
this._conditions = conditions;
|
|
120
130
|
}
|
|
121
131
|
|
|
122
132
|
/**
|
|
@@ -128,6 +138,8 @@ class BundleGraph {
|
|
|
128
138
|
let assetGroupIds = new Map();
|
|
129
139
|
let dependencies = new Map();
|
|
130
140
|
let assetGraphNodeIdToBundleGraphNodeId = new Map();
|
|
141
|
+
let conditions = new Map();
|
|
142
|
+
let placeholderToDependency = new Map();
|
|
131
143
|
let assetGraphRootNode = assetGraph.rootNodeId != null ? assetGraph.getNode(assetGraph.rootNodeId) : null;
|
|
132
144
|
(0, _assert().default)(assetGraphRootNode != null && assetGraphRootNode.type === 'root');
|
|
133
145
|
assetGraph.dfsFast(nodeId => {
|
|
@@ -146,6 +158,17 @@ class BundleGraph {
|
|
|
146
158
|
}
|
|
147
159
|
} else if (node != null && node.type === 'asset_group') {
|
|
148
160
|
assetGroupIds.set(nodeId, assetGraph.getNodeIdsConnectedFrom(nodeId));
|
|
161
|
+
} else if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && node != null && node.type === 'dependency') {
|
|
162
|
+
var _dep$meta;
|
|
163
|
+
// The dependency placeholders in the `importCond` calls that will be in the transformed
|
|
164
|
+
// code need to be mapped to the "real" dependencies, so we need access to a map of placeholders
|
|
165
|
+
// to dependencies
|
|
166
|
+
const dep = node.value;
|
|
167
|
+
// $FlowFixMe[incompatible-type] Meta is untyped
|
|
168
|
+
const placeholder = (_dep$meta = dep.meta) === null || _dep$meta === void 0 ? void 0 : _dep$meta.placeholder;
|
|
169
|
+
if (placeholder != null) {
|
|
170
|
+
placeholderToDependency.set(placeholder, dep);
|
|
171
|
+
}
|
|
149
172
|
}
|
|
150
173
|
});
|
|
151
174
|
let walkVisited = new Set();
|
|
@@ -153,6 +176,34 @@ class BundleGraph {
|
|
|
153
176
|
if (walkVisited.has(nodeId)) return;
|
|
154
177
|
walkVisited.add(nodeId);
|
|
155
178
|
let node = (0, _nullthrows().default)(assetGraph.getNode(nodeId));
|
|
179
|
+
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && node.type === 'asset') {
|
|
180
|
+
const asset = node.value;
|
|
181
|
+
if (Array.isArray(asset.meta.conditions)) {
|
|
182
|
+
// $FlowFixMe
|
|
183
|
+
for (const condition of asset.meta.conditions) {
|
|
184
|
+
// Resolve the placeholders that were attached to the asset in JSTransformer to dependencies,
|
|
185
|
+
// as well as create a public id for the condition.
|
|
186
|
+
const {
|
|
187
|
+
key,
|
|
188
|
+
ifTruePlaceholder,
|
|
189
|
+
ifFalsePlaceholder
|
|
190
|
+
} = condition;
|
|
191
|
+
const condHash = (0, _rust().hashString)(`${key}:${ifTruePlaceholder}:${ifFalsePlaceholder}`);
|
|
192
|
+
const condPublicId = (0, _utils2.getPublicId)(condHash, v => conditions.has(v));
|
|
193
|
+
if (conditions.has(condHash)) {
|
|
194
|
+
throw new Error('Unexpected duplicate asset');
|
|
195
|
+
} else {
|
|
196
|
+
conditions.set(condHash, {
|
|
197
|
+
publicId: condPublicId,
|
|
198
|
+
assets: new Set([asset]),
|
|
199
|
+
key,
|
|
200
|
+
ifTrueDependency: (0, _nullthrows().default)(placeholderToDependency.get(ifTruePlaceholder), 'ifTruePlaceholder was undefined'),
|
|
201
|
+
ifFalseDependency: (0, _nullthrows().default)(placeholderToDependency.get(ifFalsePlaceholder), 'ifFalsePlaceholder was undefined')
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
156
207
|
if (node.type === 'dependency' && node.value.symbols != null && node.value.env.shouldScopeHoist &&
|
|
157
208
|
// Disable in dev mode because this feature is at odds with safeToIncrementallyBundle
|
|
158
209
|
isProduction) {
|
|
@@ -338,7 +389,8 @@ class BundleGraph {
|
|
|
338
389
|
graph,
|
|
339
390
|
assetPublicIds,
|
|
340
391
|
bundleContentHashes: new Map(),
|
|
341
|
-
publicIdByAssetId
|
|
392
|
+
publicIdByAssetId,
|
|
393
|
+
conditions
|
|
342
394
|
});
|
|
343
395
|
}
|
|
344
396
|
serialize() {
|
|
@@ -347,7 +399,8 @@ class BundleGraph {
|
|
|
347
399
|
graph: this._graph.serialize(),
|
|
348
400
|
assetPublicIds: this._assetPublicIds,
|
|
349
401
|
bundleContentHashes: this._bundleContentHashes,
|
|
350
|
-
publicIdByAssetId: this._publicIdByAssetId
|
|
402
|
+
publicIdByAssetId: this._publicIdByAssetId,
|
|
403
|
+
conditions: this._conditions
|
|
351
404
|
};
|
|
352
405
|
}
|
|
353
406
|
static deserialize(serialized) {
|
|
@@ -355,7 +408,8 @@ class BundleGraph {
|
|
|
355
408
|
graph: _graph().ContentGraph.deserialize(serialized.graph),
|
|
356
409
|
assetPublicIds: serialized.assetPublicIds,
|
|
357
410
|
bundleContentHashes: serialized.bundleContentHashes,
|
|
358
|
-
publicIdByAssetId: serialized.publicIdByAssetId
|
|
411
|
+
publicIdByAssetId: serialized.publicIdByAssetId,
|
|
412
|
+
conditions: serialized.conditions
|
|
359
413
|
});
|
|
360
414
|
}
|
|
361
415
|
createBundle(opts) {
|
|
@@ -768,7 +822,7 @@ class BundleGraph {
|
|
|
768
822
|
return true;
|
|
769
823
|
}
|
|
770
824
|
let assetNodeId = (0, _nullthrows().default)(this._graph.getNodeIdByContentKey(asset.id));
|
|
771
|
-
if (this._graph.getNodeIdsConnectedTo(assetNodeId, bundleGraphEdgeTypes.references).map(id => this._graph.getNode(id)).some(node => (node === null || node === void 0 ? void 0 : node.type) === 'dependency' && node.value.priority === _types.Priority.lazy && node.value.specifierType !== _types.SpecifierType.url)) {
|
|
825
|
+
if (this._graph.getNodeIdsConnectedTo(assetNodeId, bundleGraphEdgeTypes.references).map(id => this._graph.getNode(id)).some(node => (node === null || node === void 0 ? void 0 : node.type) === 'dependency' && (node.value.priority === _types.Priority.lazy || node.value.priority === _types.Priority.conditional) && node.value.specifierType !== _types.SpecifierType.url)) {
|
|
772
826
|
// If this asset is referenced by any async dependency, it's referenced.
|
|
773
827
|
return true;
|
|
774
828
|
}
|
package/lib/Dependency.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createDependency = createDependency;
|
|
7
|
+
exports.createDependencyId = createDependencyId;
|
|
7
8
|
exports.mergeDependencies = mergeDependencies;
|
|
8
9
|
function _rust() {
|
|
9
10
|
const data = require("@atlaspack/rust");
|
|
@@ -15,8 +16,52 @@ function _rust() {
|
|
|
15
16
|
var _types = require("./types");
|
|
16
17
|
var _utils = require("./utils");
|
|
17
18
|
var _projectPath = require("./projectPath");
|
|
19
|
+
function _assert() {
|
|
20
|
+
const data = _interopRequireDefault(require("assert"));
|
|
21
|
+
_assert = function () {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
function createDependencyId({
|
|
28
|
+
sourceAssetId,
|
|
29
|
+
specifier,
|
|
30
|
+
env,
|
|
31
|
+
target,
|
|
32
|
+
pipeline,
|
|
33
|
+
specifierType,
|
|
34
|
+
bundleBehavior,
|
|
35
|
+
priority,
|
|
36
|
+
packageConditions
|
|
37
|
+
}) {
|
|
38
|
+
(0, _assert().default)(typeof specifierType === 'string');
|
|
39
|
+
(0, _assert().default)(typeof priority === 'string' || priority == null);
|
|
40
|
+
const params = {
|
|
41
|
+
sourceAssetId,
|
|
42
|
+
specifier,
|
|
43
|
+
env,
|
|
44
|
+
target,
|
|
45
|
+
pipeline,
|
|
46
|
+
specifierType: _types.SpecifierType[specifierType],
|
|
47
|
+
bundleBehavior,
|
|
48
|
+
priority: priority ? _types.Priority[priority] : _types.Priority.sync,
|
|
49
|
+
packageConditions
|
|
50
|
+
};
|
|
51
|
+
return (0, _rust().createDependencyId)(params);
|
|
52
|
+
}
|
|
18
53
|
function createDependency(projectRoot, opts) {
|
|
19
|
-
let id = opts.id || (
|
|
54
|
+
let id = opts.id || createDependencyId({
|
|
55
|
+
bundleBehavior: opts.bundleBehavior,
|
|
56
|
+
env: opts.env,
|
|
57
|
+
packageConditions: opts.packageConditions,
|
|
58
|
+
pipeline: opts.pipeline,
|
|
59
|
+
priority: opts.priority,
|
|
60
|
+
sourceAssetId: opts.sourceAssetId,
|
|
61
|
+
specifier: opts.specifier,
|
|
62
|
+
specifierType: opts.specifierType,
|
|
63
|
+
target: opts.target
|
|
64
|
+
});
|
|
20
65
|
let dep = {
|
|
21
66
|
id,
|
|
22
67
|
specifier: opts.specifier,
|
package/lib/Environment.js
CHANGED
|
@@ -105,7 +105,7 @@ function createEnvironment({
|
|
|
105
105
|
loc
|
|
106
106
|
};
|
|
107
107
|
res.id = getEnvironmentHash(res);
|
|
108
|
-
return res;
|
|
108
|
+
return Object.freeze(res);
|
|
109
109
|
}
|
|
110
110
|
function mergeEnvironments(projectRoot, a, b) {
|
|
111
111
|
// If merging the same object, avoid copying.
|
|
@@ -124,5 +124,15 @@ function mergeEnvironments(projectRoot, a, b) {
|
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
function getEnvironmentHash(env) {
|
|
127
|
-
return (0, _rust().
|
|
127
|
+
return (0, _rust().createEnvironmentId)({
|
|
128
|
+
context: env.context,
|
|
129
|
+
engines: env.engines,
|
|
130
|
+
includeNodeModules: env.includeNodeModules,
|
|
131
|
+
outputFormat: env.outputFormat,
|
|
132
|
+
sourceType: env.sourceType,
|
|
133
|
+
isLibrary: env.isLibrary,
|
|
134
|
+
shouldOptimize: env.shouldOptimize,
|
|
135
|
+
shouldScopeHoist: env.shouldScopeHoist,
|
|
136
|
+
sourceMap: env.sourceMap
|
|
137
|
+
});
|
|
128
138
|
}
|
package/lib/PackagerRunner.js
CHANGED
|
@@ -11,13 +11,6 @@ function _assert() {
|
|
|
11
11
|
};
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
|
-
function _utils() {
|
|
15
|
-
const data = require("@atlaspack/utils");
|
|
16
|
-
_utils = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
14
|
function _logger() {
|
|
22
15
|
const data = require("@atlaspack/logger");
|
|
23
16
|
_logger = function () {
|
|
@@ -32,13 +25,6 @@ function _diagnostic() {
|
|
|
32
25
|
};
|
|
33
26
|
return data;
|
|
34
27
|
}
|
|
35
|
-
function _stream() {
|
|
36
|
-
const data = require("stream");
|
|
37
|
-
_stream = function () {
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
42
28
|
function _nullthrows() {
|
|
43
29
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
44
30
|
_nullthrows = function () {
|
|
@@ -314,7 +300,7 @@ class PackagerRunner {
|
|
|
314
300
|
let bundle = _Bundle.NamedBundle.get(internalBundle, internalBundleGraph, this.options);
|
|
315
301
|
let bundleGraph = new _BundleGraph.default(internalBundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options);
|
|
316
302
|
let optimizers = await this.config.getOptimizers(bundle.name, internalBundle.pipeline);
|
|
317
|
-
if (
|
|
303
|
+
if (optimizers.length === 0) {
|
|
318
304
|
return {
|
|
319
305
|
type: bundle.type,
|
|
320
306
|
contents,
|
|
@@ -447,40 +433,13 @@ class PackagerRunner {
|
|
|
447
433
|
}
|
|
448
434
|
return devDepHashes;
|
|
449
435
|
}
|
|
450
|
-
async readFromCache(cacheKey) {
|
|
451
|
-
let contentKey = PackagerRunner.getContentKey(cacheKey);
|
|
452
|
-
let mapKey = PackagerRunner.getMapKey(cacheKey);
|
|
453
|
-
let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
|
|
454
|
-
let contentExists = isLargeBlob || (await this.options.cache.has(contentKey));
|
|
455
|
-
if (!contentExists) {
|
|
456
|
-
return null;
|
|
457
|
-
}
|
|
458
|
-
let mapExists = await this.options.cache.has(mapKey);
|
|
459
|
-
return {
|
|
460
|
-
contents: isLargeBlob ? this.options.cache.getStream(contentKey) : (0, _utils().blobToStream)(await this.options.cache.getBlob(contentKey)),
|
|
461
|
-
map: mapExists ? (0, _utils().blobToStream)(await this.options.cache.getBlob(mapKey)) : null
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
436
|
async writeToCache(cacheKeys, type, contents, map) {
|
|
465
437
|
let size = 0;
|
|
466
438
|
let hash;
|
|
467
439
|
let hashReferences = [];
|
|
468
|
-
let isLargeBlob = false;
|
|
469
440
|
|
|
470
441
|
// TODO: don't replace hash references in binary files??
|
|
471
|
-
if (contents
|
|
472
|
-
isLargeBlob = true;
|
|
473
|
-
let boundaryStr = '';
|
|
474
|
-
let h = new (_rust().Hash)();
|
|
475
|
-
await this.options.cache.setStream(cacheKeys.content, (0, _utils().blobToStream)(contents).pipe(new (_utils().TapStream)(buf => {
|
|
476
|
-
let str = boundaryStr + buf.toString();
|
|
477
|
-
hashReferences = hashReferences.concat(str.match(_constants.HASH_REF_REGEX) ?? []);
|
|
478
|
-
size += buf.length;
|
|
479
|
-
h.writeBuffer(buf);
|
|
480
|
-
boundaryStr = str.slice(str.length - BOUNDARY_LENGTH);
|
|
481
|
-
})));
|
|
482
|
-
hash = h.finish();
|
|
483
|
-
} else if (typeof contents === 'string') {
|
|
442
|
+
if (typeof contents === 'string') {
|
|
484
443
|
let buffer = Buffer.from(contents);
|
|
485
444
|
size = buffer.byteLength;
|
|
486
445
|
hash = (0, _rust().hashBuffer)(buffer);
|
|
@@ -500,8 +459,7 @@ class PackagerRunner {
|
|
|
500
459
|
size,
|
|
501
460
|
hash,
|
|
502
461
|
hashReferences,
|
|
503
|
-
cacheKeys
|
|
504
|
-
isLargeBlob
|
|
462
|
+
cacheKeys
|
|
505
463
|
};
|
|
506
464
|
await this.options.cache.set(cacheKeys.info, info);
|
|
507
465
|
return info;
|