@atlaspack/core 2.12.1-dev.3401 → 2.12.1-dev.3443
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 +156 -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 +209 -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/resolveOptions.js
CHANGED
|
@@ -32,6 +32,13 @@ function _cache() {
|
|
|
32
32
|
};
|
|
33
33
|
return data;
|
|
34
34
|
}
|
|
35
|
+
function _featureFlags() {
|
|
36
|
+
const data = require("@atlaspack/feature-flags");
|
|
37
|
+
_featureFlags = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
35
42
|
function _packageManager() {
|
|
36
43
|
const data = require("@atlaspack/package-manager");
|
|
37
44
|
_packageManager = function () {
|
|
@@ -49,13 +56,6 @@ function _utils() {
|
|
|
49
56
|
var _loadDotEnv = _interopRequireDefault(require("./loadDotEnv"));
|
|
50
57
|
var _projectPath = require("./projectPath");
|
|
51
58
|
var _AtlaspackConfigRequest = require("./requests/AtlaspackConfigRequest");
|
|
52
|
-
function _featureFlags() {
|
|
53
|
-
const data = require("@atlaspack/feature-flags");
|
|
54
|
-
_featureFlags = function () {
|
|
55
|
-
return data;
|
|
56
|
-
};
|
|
57
|
-
return data;
|
|
58
|
-
}
|
|
59
59
|
var _constants = require("./constants");
|
|
60
60
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
61
61
|
// Default cache directory name
|
|
@@ -111,7 +111,12 @@ async function resolveOptions(initialOptions) {
|
|
|
111
111
|
// where symlinked dependencies outside the project root need to trigger HMR
|
|
112
112
|
// updates. Default to the project root if not provided.
|
|
113
113
|
let watchDir = initialOptions.watchDir != null ? _path().default.resolve(initialOptions.watchDir) : projectRoot;
|
|
114
|
-
let cache = initialOptions.cache ?? (outputFS instanceof _fs().NodeFS ?
|
|
114
|
+
let cache = initialOptions.cache ?? (outputFS instanceof _fs().NodeFS ? (() => {
|
|
115
|
+
if ((0, _featureFlags().getFeatureFlag)('useLmdbJsLite')) {
|
|
116
|
+
return new (_cache().LMDBLiteCache)(cacheDir);
|
|
117
|
+
}
|
|
118
|
+
return new (_cache().LMDBCache)(cacheDir);
|
|
119
|
+
})() : new (_cache().FSCache)(outputFS, cacheDir));
|
|
115
120
|
let mode = initialOptions.mode ?? 'development';
|
|
116
121
|
let shouldOptimize = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau = initialOptions.defaultTargetOptions) === null || _initialOptions$defau === void 0 ? void 0 : _initialOptions$defau.shouldOptimize) ?? mode === 'production';
|
|
117
122
|
let publicUrl = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau2 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau2 === void 0 ? void 0 : _initialOptions$defau2.publicUrl) ?? '/';
|
|
@@ -192,6 +197,8 @@ async function resolveOptions(initialOptions) {
|
|
|
192
197
|
outputFormat: initialOptions === null || initialOptions === void 0 || (_initialOptions$defau8 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau8 === void 0 ? void 0 : _initialOptions$defau8.outputFormat,
|
|
193
198
|
isLibrary: initialOptions === null || initialOptions === void 0 || (_initialOptions$defau9 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau9 === void 0 ? void 0 : _initialOptions$defau9.isLibrary
|
|
194
199
|
},
|
|
200
|
+
// unused, feature-flags are set above this to allow this function to use
|
|
201
|
+
// feature-flags
|
|
195
202
|
featureFlags: {
|
|
196
203
|
..._featureFlags().DEFAULT_FEATURE_FLAGS,
|
|
197
204
|
...(initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.featureFlags)
|
package/lib/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/core",
|
|
3
|
-
"version": "2.12.1-dev.
|
|
4
|
-
"license": "MIT",
|
|
3
|
+
"version": "2.12.1-dev.3443+d1170cfc7",
|
|
4
|
+
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"check-ts": "tsc --noEmit index.d.ts"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@atlaspack/cache": "2.12.1-dev.
|
|
24
|
-
"@atlaspack/diagnostic": "2.12.1-dev.
|
|
25
|
-
"@atlaspack/events": "2.12.1-dev.
|
|
26
|
-
"@atlaspack/feature-flags": "2.12.1-dev.
|
|
27
|
-
"@atlaspack/fs": "2.12.1-dev.
|
|
28
|
-
"@atlaspack/graph": "3.2.1-dev.
|
|
29
|
-
"@atlaspack/logger": "2.12.1-dev.
|
|
30
|
-
"@atlaspack/package-manager": "2.12.1-dev.
|
|
31
|
-
"@atlaspack/plugin": "2.12.1-dev.
|
|
32
|
-
"@atlaspack/profiler": "2.12.1-dev.
|
|
33
|
-
"@atlaspack/rust": "2.12.1-dev.
|
|
34
|
-
"@atlaspack/types": "2.12.1-dev.
|
|
35
|
-
"@atlaspack/utils": "2.12.1-dev.
|
|
36
|
-
"@atlaspack/workers": "2.12.1-dev.
|
|
23
|
+
"@atlaspack/cache": "2.12.1-dev.3443+d1170cfc7",
|
|
24
|
+
"@atlaspack/diagnostic": "2.12.1-dev.3443+d1170cfc7",
|
|
25
|
+
"@atlaspack/events": "2.12.1-dev.3443+d1170cfc7",
|
|
26
|
+
"@atlaspack/feature-flags": "2.12.1-dev.3443+d1170cfc7",
|
|
27
|
+
"@atlaspack/fs": "2.12.1-dev.3443+d1170cfc7",
|
|
28
|
+
"@atlaspack/graph": "3.2.1-dev.3443+d1170cfc7",
|
|
29
|
+
"@atlaspack/logger": "2.12.1-dev.3443+d1170cfc7",
|
|
30
|
+
"@atlaspack/package-manager": "2.12.1-dev.3443+d1170cfc7",
|
|
31
|
+
"@atlaspack/plugin": "2.12.1-dev.3443+d1170cfc7",
|
|
32
|
+
"@atlaspack/profiler": "2.12.1-dev.3443+d1170cfc7",
|
|
33
|
+
"@atlaspack/rust": "2.12.1-dev.3443+d1170cfc7",
|
|
34
|
+
"@atlaspack/types": "2.12.1-dev.3443+d1170cfc7",
|
|
35
|
+
"@atlaspack/utils": "2.12.1-dev.3443+d1170cfc7",
|
|
36
|
+
"@atlaspack/workers": "2.12.1-dev.3443+d1170cfc7",
|
|
37
37
|
"@mischnic/json-sourcemap": "^0.1.0",
|
|
38
38
|
"@parcel/source-map": "^2.1.1",
|
|
39
39
|
"base-x": "^3.0.8",
|
|
@@ -50,10 +50,12 @@
|
|
|
50
50
|
"@atlaspack/babel-register": "2.12.0",
|
|
51
51
|
"@types/node": ">= 18",
|
|
52
52
|
"graphviz": "^0.0.9",
|
|
53
|
+
"jest-diff": "*",
|
|
54
|
+
"rfdc": "1",
|
|
53
55
|
"tempy": "^0.2.1"
|
|
54
56
|
},
|
|
55
57
|
"browser": {
|
|
56
58
|
"./src/serializerCore.js": "./src/serializerCore.browser.js"
|
|
57
59
|
},
|
|
58
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "d1170cfc79beb290b2a066f472f68f71f7d7cb23"
|
|
59
61
|
}
|
package/src/AssetGraph.js
CHANGED
|
@@ -227,7 +227,7 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
|
|
|
227
227
|
// The passed project path is ignored in this case, because there is no `loc`
|
|
228
228
|
createDependency('', {
|
|
229
229
|
specifier: fromProjectPathRelative(entry.filePath),
|
|
230
|
-
specifierType: '
|
|
230
|
+
specifierType: 'url',
|
|
231
231
|
pipeline: target.pipeline,
|
|
232
232
|
target: target,
|
|
233
233
|
env: target.env,
|
package/src/Atlaspack.js
CHANGED
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
fromProjectPathRelative,
|
|
58
58
|
} from './projectPath';
|
|
59
59
|
import {tracer} from '@atlaspack/profiler';
|
|
60
|
-
import {setFeatureFlags} from '@atlaspack/feature-flags';
|
|
60
|
+
import {setFeatureFlags, DEFAULT_FEATURE_FLAGS} from '@atlaspack/feature-flags';
|
|
61
61
|
import {AtlaspackV3, toFileSystemV3} from './atlaspack-v3';
|
|
62
62
|
|
|
63
63
|
registerCoreWithSerializer();
|
|
@@ -105,6 +105,12 @@ export default class Atlaspack {
|
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
const featureFlags = {
|
|
109
|
+
...DEFAULT_FEATURE_FLAGS,
|
|
110
|
+
...this.#initialOptions.featureFlags,
|
|
111
|
+
};
|
|
112
|
+
setFeatureFlags(featureFlags);
|
|
113
|
+
|
|
108
114
|
await initSourcemaps;
|
|
109
115
|
await initRust?.();
|
|
110
116
|
try {
|
|
@@ -117,9 +123,10 @@ export default class Atlaspack {
|
|
|
117
123
|
logger.warn(e);
|
|
118
124
|
}
|
|
119
125
|
|
|
120
|
-
let resolvedOptions: AtlaspackOptions = await resolveOptions(
|
|
121
|
-
this.#initialOptions,
|
|
122
|
-
|
|
126
|
+
let resolvedOptions: AtlaspackOptions = await resolveOptions({
|
|
127
|
+
...this.#initialOptions,
|
|
128
|
+
featureFlags,
|
|
129
|
+
});
|
|
123
130
|
this.#resolvedOptions = resolvedOptions;
|
|
124
131
|
|
|
125
132
|
let rustAtlaspack: AtlaspackV3;
|
|
@@ -130,20 +137,31 @@ export default class Atlaspack {
|
|
|
130
137
|
rustAtlaspack = new AtlaspackV3({
|
|
131
138
|
...options,
|
|
132
139
|
corePath: path.join(__dirname, '..'),
|
|
140
|
+
threads: process.env.NODE_ENV === 'test' ? 2 : undefined,
|
|
133
141
|
entries: Array.isArray(entries)
|
|
134
142
|
? entries
|
|
135
143
|
: entries == null
|
|
136
144
|
? undefined
|
|
137
145
|
: [entries],
|
|
146
|
+
env: resolvedOptions.env,
|
|
138
147
|
fs: inputFS && toFileSystemV3(inputFS),
|
|
148
|
+
defaultTargetOptions: {
|
|
149
|
+
// $FlowFixMe projectPath is just a string
|
|
150
|
+
distDir: resolvedOptions.defaultTargetOptions.distDir,
|
|
151
|
+
engines: resolvedOptions.defaultTargetOptions.engines,
|
|
152
|
+
isLibrary: resolvedOptions.defaultTargetOptions.isLibrary,
|
|
153
|
+
outputFormat: resolvedOptions.defaultTargetOptions.outputFormat,
|
|
154
|
+
sourceMaps: resolvedOptions.defaultTargetOptions.sourceMaps,
|
|
155
|
+
shouldOptimize: resolvedOptions.defaultTargetOptions.shouldOptimize,
|
|
156
|
+
shouldScopeHoist:
|
|
157
|
+
resolvedOptions.defaultTargetOptions.shouldScopeHoist,
|
|
158
|
+
},
|
|
139
159
|
});
|
|
140
160
|
}
|
|
141
161
|
|
|
142
162
|
let {config} = await loadAtlaspackConfig(resolvedOptions);
|
|
143
163
|
this.#config = new AtlaspackConfig(config, resolvedOptions);
|
|
144
164
|
|
|
145
|
-
setFeatureFlags(resolvedOptions.featureFlags);
|
|
146
|
-
|
|
147
165
|
if (this.#initialOptions.workerFarm) {
|
|
148
166
|
if (this.#initialOptions.workerFarm.ending) {
|
|
149
167
|
throw new Error('Supplied WorkerFarm is ending');
|
|
@@ -531,6 +549,10 @@ export default class Atlaspack {
|
|
|
531
549
|
return this.#farm.takeHeapSnapshot();
|
|
532
550
|
}
|
|
533
551
|
|
|
552
|
+
async unstable_invalidate(): Promise<void> {
|
|
553
|
+
await this._init();
|
|
554
|
+
}
|
|
555
|
+
|
|
534
556
|
async unstable_transform(
|
|
535
557
|
options: AtlaspackTransformOptions,
|
|
536
558
|
): Promise<Array<Asset>> {
|
|
@@ -1,47 +1,24 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
import type {PackageName} from '@atlaspack/types';
|
|
3
3
|
import type {SchemaEntity} from '@atlaspack/utils';
|
|
4
|
-
import assert from 'assert';
|
|
5
4
|
|
|
6
|
-
//
|
|
7
|
-
//
|
|
5
|
+
// Parcel validates plugin package names due to:
|
|
6
|
+
//
|
|
7
|
+
// * https://github.com/parcel-bundler/parcel/issues/3397#issuecomment-521353931
|
|
8
|
+
//
|
|
9
|
+
// Ultimately:
|
|
10
|
+
//
|
|
11
|
+
// * We do not care about package names
|
|
12
|
+
// * Validation makes interop between parcel/atlaspack confusing.
|
|
13
|
+
//
|
|
8
14
|
export function validatePackageName(
|
|
15
|
+
// eslint-disable-next-line no-unused-vars
|
|
9
16
|
pkg: ?PackageName,
|
|
17
|
+
// eslint-disable-next-line no-unused-vars
|
|
10
18
|
pluginType: string,
|
|
19
|
+
// eslint-disable-next-line no-unused-vars
|
|
11
20
|
key: string,
|
|
12
|
-
) {
|
|
13
|
-
// $FlowFixMe
|
|
14
|
-
if (!pkg) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
assert(typeof pkg === 'string', `"${key}" must be a string`);
|
|
19
|
-
|
|
20
|
-
// Probably all of these need to be removed
|
|
21
|
-
if (pkg.startsWith('@atlaspack') || pkg.startsWith('@parcel')) {
|
|
22
|
-
assert(
|
|
23
|
-
pkg.replace(/^@atlaspack\//, '').startsWith(`${pluginType}-`),
|
|
24
|
-
`Official atlaspack ${pluginType} packages must be named according to "@atlaspack/${pluginType}-{name}"`,
|
|
25
|
-
);
|
|
26
|
-
} else if (pkg.startsWith('@')) {
|
|
27
|
-
// Disabling this validation to allow for migration to parcel
|
|
28
|
-
// let [scope, name] = pkg.split('/');
|
|
29
|
-
// assert(
|
|
30
|
-
// name.startsWith(`parcel-${pluginType}-`) ||
|
|
31
|
-
// name === `parcel-${pluginType}` ||
|
|
32
|
-
// name.startsWith(`parcel-${pluginType}-`) ||
|
|
33
|
-
// name === `parcel-${pluginType}`,
|
|
34
|
-
// `Scoped parcel ${pluginType} packages must be named according to "${scope}/parcel-${pluginType}[-{name}]"`,
|
|
35
|
-
// );
|
|
36
|
-
} else if (!pkg.startsWith('.')) {
|
|
37
|
-
assert(
|
|
38
|
-
pkg.startsWith(`parcel-${pluginType}-`) ||
|
|
39
|
-
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
|
-
}
|
|
44
|
-
}
|
|
21
|
+
) {}
|
|
45
22
|
|
|
46
23
|
const validatePluginName = (pluginType: string, key: string) => {
|
|
47
24
|
return (val: string) => {
|
package/src/BundleGraph.js
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
Symbol,
|
|
7
7
|
TraversalActions,
|
|
8
8
|
BundleBehavior as IBundleBehavior,
|
|
9
|
+
ConditionMeta,
|
|
9
10
|
} from '@atlaspack/types';
|
|
10
11
|
import type {
|
|
11
12
|
ContentKey,
|
|
@@ -26,6 +27,7 @@ import type {
|
|
|
26
27
|
Environment,
|
|
27
28
|
InternalSourceLocation,
|
|
28
29
|
Target,
|
|
30
|
+
Condition,
|
|
29
31
|
} from './types';
|
|
30
32
|
import type AssetGraph from './AssetGraph';
|
|
31
33
|
import type {ProjectPath} from './projectPath';
|
|
@@ -46,6 +48,7 @@ import {getBundleGroupId, getPublicId} from './utils';
|
|
|
46
48
|
import {ISOLATED_ENVS} from './public/Environment';
|
|
47
49
|
import {fromProjectPath, fromProjectPathRelative} from './projectPath';
|
|
48
50
|
import {HASH_REF_PREFIX} from './constants';
|
|
51
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
49
52
|
|
|
50
53
|
export const bundleGraphEdgeTypes = {
|
|
51
54
|
// A lack of an edge type indicates to follow the edge while traversing
|
|
@@ -91,6 +94,7 @@ type BundleGraphOpts = {|
|
|
|
91
94
|
bundleContentHashes: Map<string, string>,
|
|
92
95
|
assetPublicIds: Set<string>,
|
|
93
96
|
publicIdByAssetId: Map<string, string>,
|
|
97
|
+
conditions: Map<string, Condition>,
|
|
94
98
|
|};
|
|
95
99
|
|
|
96
100
|
type SerializedBundleGraph = {|
|
|
@@ -99,6 +103,7 @@ type SerializedBundleGraph = {|
|
|
|
99
103
|
bundleContentHashes: Map<string, string>,
|
|
100
104
|
assetPublicIds: Set<string>,
|
|
101
105
|
publicIdByAssetId: Map<string, string>,
|
|
106
|
+
conditions: Map<string, Condition>,
|
|
102
107
|
|};
|
|
103
108
|
|
|
104
109
|
function makeReadOnlySet<T>(set: Set<T>): $ReadOnlySet<T> {
|
|
@@ -139,22 +144,26 @@ export default class BundleGraph {
|
|
|
139
144
|
/** The internal core Graph structure */
|
|
140
145
|
_graph: ContentGraph<BundleGraphNode, BundleGraphEdgeType>;
|
|
141
146
|
_bundlePublicIds /*: Set<string> */ = new Set<string>();
|
|
147
|
+
_conditions /*: Map<string, Condition> */ = new Map<string, Condition>();
|
|
142
148
|
|
|
143
149
|
constructor({
|
|
144
150
|
graph,
|
|
145
151
|
publicIdByAssetId,
|
|
146
152
|
assetPublicIds,
|
|
147
153
|
bundleContentHashes,
|
|
154
|
+
conditions,
|
|
148
155
|
}: {|
|
|
149
156
|
graph: ContentGraph<BundleGraphNode, BundleGraphEdgeType>,
|
|
150
157
|
publicIdByAssetId: Map<string, string>,
|
|
151
158
|
assetPublicIds: Set<string>,
|
|
152
159
|
bundleContentHashes: Map<string, string>,
|
|
160
|
+
conditions: Map<string, Condition>,
|
|
153
161
|
|}) {
|
|
154
162
|
this._graph = graph;
|
|
155
163
|
this._assetPublicIds = assetPublicIds;
|
|
156
164
|
this._publicIdByAssetId = publicIdByAssetId;
|
|
157
165
|
this._bundleContentHashes = bundleContentHashes;
|
|
166
|
+
this._conditions = conditions;
|
|
158
167
|
}
|
|
159
168
|
|
|
160
169
|
/**
|
|
@@ -171,6 +180,9 @@ export default class BundleGraph {
|
|
|
171
180
|
let assetGroupIds = new Map();
|
|
172
181
|
let dependencies = new Map();
|
|
173
182
|
let assetGraphNodeIdToBundleGraphNodeId = new Map<NodeId, NodeId>();
|
|
183
|
+
let conditions = new Map<string, Condition>();
|
|
184
|
+
|
|
185
|
+
let placeholderToDependency = new Map<string, Dependency>();
|
|
174
186
|
|
|
175
187
|
let assetGraphRootNode =
|
|
176
188
|
assetGraph.rootNodeId != null
|
|
@@ -195,6 +207,20 @@ export default class BundleGraph {
|
|
|
195
207
|
}
|
|
196
208
|
} else if (node != null && node.type === 'asset_group') {
|
|
197
209
|
assetGroupIds.set(nodeId, assetGraph.getNodeIdsConnectedFrom(nodeId));
|
|
210
|
+
} else if (
|
|
211
|
+
getFeatureFlag('conditionalBundlingApi') &&
|
|
212
|
+
node != null &&
|
|
213
|
+
node.type === 'dependency'
|
|
214
|
+
) {
|
|
215
|
+
// The dependency placeholders in the `importCond` calls that will be in the transformed
|
|
216
|
+
// code need to be mapped to the "real" dependencies, so we need access to a map of placeholders
|
|
217
|
+
// to dependencies
|
|
218
|
+
const dep = node.value;
|
|
219
|
+
// $FlowFixMe[incompatible-type] Meta is untyped
|
|
220
|
+
const placeholder: string | void = dep.meta?.placeholder;
|
|
221
|
+
if (placeholder != null) {
|
|
222
|
+
placeholderToDependency.set(placeholder, dep);
|
|
223
|
+
}
|
|
198
224
|
}
|
|
199
225
|
});
|
|
200
226
|
|
|
@@ -204,6 +230,51 @@ export default class BundleGraph {
|
|
|
204
230
|
walkVisited.add(nodeId);
|
|
205
231
|
|
|
206
232
|
let node = nullthrows(assetGraph.getNode(nodeId));
|
|
233
|
+
|
|
234
|
+
if (getFeatureFlag('conditionalBundlingApi') && node.type === 'asset') {
|
|
235
|
+
const asset = node.value;
|
|
236
|
+
if (Array.isArray(asset.meta.conditions)) {
|
|
237
|
+
// $FlowFixMe
|
|
238
|
+
for (const condition of (asset.meta.conditions: ConditionMeta[])) {
|
|
239
|
+
// Resolve the placeholders that were attached to the asset in JSTransformer to dependencies,
|
|
240
|
+
// as well as create a public id for the condition.
|
|
241
|
+
const {
|
|
242
|
+
key,
|
|
243
|
+
ifTruePlaceholder,
|
|
244
|
+
ifFalsePlaceholder,
|
|
245
|
+
}: {
|
|
246
|
+
key: string,
|
|
247
|
+
ifTruePlaceholder: string,
|
|
248
|
+
ifFalsePlaceholder: string,
|
|
249
|
+
...
|
|
250
|
+
} = condition;
|
|
251
|
+
|
|
252
|
+
const condHash = hashString(
|
|
253
|
+
`${key}:${ifTruePlaceholder}:${ifFalsePlaceholder}`,
|
|
254
|
+
);
|
|
255
|
+
const condPublicId = getPublicId(condHash, v => conditions.has(v));
|
|
256
|
+
|
|
257
|
+
if (conditions.has(condHash)) {
|
|
258
|
+
throw new Error('Unexpected duplicate asset');
|
|
259
|
+
} else {
|
|
260
|
+
conditions.set(condHash, {
|
|
261
|
+
publicId: condPublicId,
|
|
262
|
+
assets: new Set([asset]),
|
|
263
|
+
key,
|
|
264
|
+
ifTrueDependency: nullthrows(
|
|
265
|
+
placeholderToDependency.get(ifTruePlaceholder),
|
|
266
|
+
'ifTruePlaceholder was undefined',
|
|
267
|
+
),
|
|
268
|
+
ifFalseDependency: nullthrows(
|
|
269
|
+
placeholderToDependency.get(ifFalsePlaceholder),
|
|
270
|
+
'ifFalsePlaceholder was undefined',
|
|
271
|
+
),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
207
278
|
if (
|
|
208
279
|
node.type === 'dependency' &&
|
|
209
280
|
node.value.symbols != null &&
|
|
@@ -440,11 +511,13 @@ export default class BundleGraph {
|
|
|
440
511
|
);
|
|
441
512
|
}
|
|
442
513
|
}
|
|
514
|
+
|
|
443
515
|
return new BundleGraph({
|
|
444
516
|
graph,
|
|
445
517
|
assetPublicIds,
|
|
446
518
|
bundleContentHashes: new Map(),
|
|
447
519
|
publicIdByAssetId,
|
|
520
|
+
conditions,
|
|
448
521
|
});
|
|
449
522
|
}
|
|
450
523
|
|
|
@@ -455,6 +528,7 @@ export default class BundleGraph {
|
|
|
455
528
|
assetPublicIds: this._assetPublicIds,
|
|
456
529
|
bundleContentHashes: this._bundleContentHashes,
|
|
457
530
|
publicIdByAssetId: this._publicIdByAssetId,
|
|
531
|
+
conditions: this._conditions,
|
|
458
532
|
};
|
|
459
533
|
}
|
|
460
534
|
|
|
@@ -464,6 +538,7 @@ export default class BundleGraph {
|
|
|
464
538
|
assetPublicIds: serialized.assetPublicIds,
|
|
465
539
|
bundleContentHashes: serialized.bundleContentHashes,
|
|
466
540
|
publicIdByAssetId: serialized.publicIdByAssetId,
|
|
541
|
+
conditions: serialized.conditions,
|
|
467
542
|
});
|
|
468
543
|
}
|
|
469
544
|
|
|
@@ -1215,7 +1290,8 @@ export default class BundleGraph {
|
|
|
1215
1290
|
.some(
|
|
1216
1291
|
node =>
|
|
1217
1292
|
node?.type === 'dependency' &&
|
|
1218
|
-
node.value.priority === Priority.lazy
|
|
1293
|
+
(node.value.priority === Priority.lazy ||
|
|
1294
|
+
node.value.priority === Priority.conditional) &&
|
|
1219
1295
|
node.value.specifierType !== SpecifierType.url,
|
|
1220
1296
|
)
|
|
1221
1297
|
) {
|
package/src/CommittedAsset.js
CHANGED
|
@@ -17,7 +17,7 @@ export default class CommittedAsset {
|
|
|
17
17
|
mapBuffer: ?Promise<?Buffer>;
|
|
18
18
|
map: ?Promise<?SourceMap>;
|
|
19
19
|
ast: ?Promise<AST>;
|
|
20
|
-
|
|
20
|
+
code: ?string;
|
|
21
21
|
generatingPromise: ?Promise<void>;
|
|
22
22
|
|
|
23
23
|
constructor(value: Asset, options: AtlaspackOptions) {
|
package/src/Dependency.js
CHANGED
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
SemverRange,
|
|
10
10
|
} from '@atlaspack/types';
|
|
11
11
|
import type {Dependency, Environment, Target} from './types';
|
|
12
|
-
import {
|
|
12
|
+
import {createDependencyId as createDependencyIdRust} from '@atlaspack/rust';
|
|
13
13
|
import {
|
|
14
14
|
SpecifierType,
|
|
15
15
|
Priority,
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
|
|
20
20
|
import {toInternalSourceLocation} from './utils';
|
|
21
21
|
import {toProjectPath} from './projectPath';
|
|
22
|
+
import assert from 'assert';
|
|
22
23
|
|
|
23
24
|
type DependencyOpts = {|
|
|
24
25
|
id?: string,
|
|
@@ -45,23 +46,60 @@ type DependencyOpts = {|
|
|
|
45
46
|
pipeline?: ?string,
|
|
46
47
|
|};
|
|
47
48
|
|
|
49
|
+
export function createDependencyId({
|
|
50
|
+
sourceAssetId,
|
|
51
|
+
specifier,
|
|
52
|
+
env,
|
|
53
|
+
target,
|
|
54
|
+
pipeline,
|
|
55
|
+
specifierType,
|
|
56
|
+
bundleBehavior,
|
|
57
|
+
priority,
|
|
58
|
+
packageConditions,
|
|
59
|
+
}: {|
|
|
60
|
+
sourceAssetId: string | void,
|
|
61
|
+
specifier: DependencySpecifier,
|
|
62
|
+
env: Environment,
|
|
63
|
+
target: Target | void,
|
|
64
|
+
pipeline: ?string,
|
|
65
|
+
specifierType: $Keys<typeof SpecifierType>,
|
|
66
|
+
bundleBehavior: ?IBundleBehavior,
|
|
67
|
+
priority: $Keys<typeof Priority> | void,
|
|
68
|
+
packageConditions: Array<string> | void,
|
|
69
|
+
|}): string {
|
|
70
|
+
assert(typeof specifierType === 'string');
|
|
71
|
+
assert(typeof priority === 'string' || priority == null);
|
|
72
|
+
const params = {
|
|
73
|
+
sourceAssetId,
|
|
74
|
+
specifier,
|
|
75
|
+
env,
|
|
76
|
+
target,
|
|
77
|
+
pipeline,
|
|
78
|
+
specifierType: SpecifierType[specifierType],
|
|
79
|
+
bundleBehavior,
|
|
80
|
+
priority: priority ? Priority[priority] : Priority.sync,
|
|
81
|
+
packageConditions,
|
|
82
|
+
};
|
|
83
|
+
return createDependencyIdRust(params);
|
|
84
|
+
}
|
|
85
|
+
|
|
48
86
|
export function createDependency(
|
|
49
87
|
projectRoot: FilePath,
|
|
50
88
|
opts: DependencyOpts,
|
|
51
89
|
): Dependency {
|
|
52
90
|
let id =
|
|
53
91
|
opts.id ||
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
);
|
|
92
|
+
createDependencyId({
|
|
93
|
+
bundleBehavior: opts.bundleBehavior,
|
|
94
|
+
env: opts.env,
|
|
95
|
+
packageConditions: opts.packageConditions,
|
|
96
|
+
pipeline: opts.pipeline,
|
|
97
|
+
priority: opts.priority,
|
|
98
|
+
sourceAssetId: opts.sourceAssetId,
|
|
99
|
+
specifier: opts.specifier,
|
|
100
|
+
specifierType: opts.specifierType,
|
|
101
|
+
target: opts.target,
|
|
102
|
+
});
|
|
65
103
|
|
|
66
104
|
let dep: Dependency = {
|
|
67
105
|
id,
|
package/src/Environment.js
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
FilePath,
|
|
6
6
|
} from '@atlaspack/types';
|
|
7
7
|
import type {Environment, InternalSourceLocation} from './types';
|
|
8
|
-
import {
|
|
8
|
+
import {createEnvironmentId} from '@atlaspack/rust';
|
|
9
9
|
import {toInternalSourceLocation} from './utils';
|
|
10
10
|
import PublicEnvironment from './public/Environment';
|
|
11
11
|
import {environmentToInternalEnvironment} from './public/Environment';
|
|
@@ -109,7 +109,7 @@ export function createEnvironment({
|
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
res.id = getEnvironmentHash(res);
|
|
112
|
-
return res;
|
|
112
|
+
return Object.freeze(res);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
export function mergeEnvironments(
|
|
@@ -135,17 +135,15 @@ export function mergeEnvironments(
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
function getEnvironmentHash(env: Environment): string {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
]),
|
|
150
|
-
);
|
|
138
|
+
return createEnvironmentId({
|
|
139
|
+
context: env.context,
|
|
140
|
+
engines: env.engines,
|
|
141
|
+
includeNodeModules: env.includeNodeModules,
|
|
142
|
+
outputFormat: env.outputFormat,
|
|
143
|
+
sourceType: env.sourceType,
|
|
144
|
+
isLibrary: env.isLibrary,
|
|
145
|
+
shouldOptimize: env.shouldOptimize,
|
|
146
|
+
shouldScopeHoist: env.shouldScopeHoist,
|
|
147
|
+
sourceMap: env.sourceMap,
|
|
148
|
+
});
|
|
151
149
|
}
|