@atlaspack/core 2.12.1-canary.3354
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/LICENSE +201 -0
- package/index.d.ts +22 -0
- package/lib/AssetGraph.js +518 -0
- package/lib/Atlaspack.js +587 -0
- package/lib/AtlaspackConfig.js +298 -0
- package/lib/AtlaspackConfig.schema.js +125 -0
- package/lib/BundleGraph.js +1445 -0
- package/lib/CommittedAsset.js +133 -0
- package/lib/Dependency.js +88 -0
- package/lib/Environment.js +128 -0
- package/lib/InternalConfig.js +48 -0
- package/lib/PackagerRunner.js +519 -0
- package/lib/ReporterRunner.js +151 -0
- package/lib/RequestTracker.js +1089 -0
- package/lib/SymbolPropagation.js +625 -0
- package/lib/TargetDescriptor.schema.js +115 -0
- package/lib/Transformation.js +536 -0
- package/lib/UncommittedAsset.js +342 -0
- package/lib/Validation.js +215 -0
- package/lib/applyRuntimes.js +279 -0
- package/lib/assetUtils.js +189 -0
- package/lib/atlaspack-v3/AtlaspackV3.js +74 -0
- package/lib/atlaspack-v3/fs.js +30 -0
- package/lib/atlaspack-v3/index.js +19 -0
- package/lib/atlaspack-v3/jsCallable.js +15 -0
- package/lib/atlaspack-v3/plugins/Resolver.js +12 -0
- package/lib/atlaspack-v3/plugins/index.js +16 -0
- package/lib/atlaspack-v3/worker/index.js +3 -0
- package/lib/atlaspack-v3/worker/worker.js +30 -0
- package/lib/buildCache.js +18 -0
- package/lib/constants.js +21 -0
- package/lib/dumpGraphToGraphViz.js +206 -0
- package/lib/index.js +106 -0
- package/lib/loadAtlaspackPlugin.js +148 -0
- package/lib/loadDotEnv.js +54 -0
- package/lib/projectPath.js +86 -0
- package/lib/public/Asset.js +259 -0
- package/lib/public/Bundle.js +231 -0
- package/lib/public/BundleGraph.js +193 -0
- package/lib/public/BundleGroup.js +44 -0
- package/lib/public/Config.js +202 -0
- package/lib/public/Dependency.js +131 -0
- package/lib/public/Environment.js +244 -0
- package/lib/public/MutableBundleGraph.js +184 -0
- package/lib/public/PluginOptions.js +71 -0
- package/lib/public/Symbols.js +247 -0
- package/lib/public/Target.js +64 -0
- package/lib/registerCoreWithSerializer.js +45 -0
- package/lib/requests/AssetGraphRequest.js +427 -0
- package/lib/requests/AssetGraphRequestRust.js +187 -0
- package/lib/requests/AssetRequest.js +137 -0
- package/lib/requests/AtlaspackBuildRequest.js +78 -0
- package/lib/requests/AtlaspackConfigRequest.js +473 -0
- package/lib/requests/BundleGraphRequest.js +419 -0
- package/lib/requests/ConfigRequest.js +198 -0
- package/lib/requests/DevDepRequest.js +166 -0
- package/lib/requests/EntryRequest.js +295 -0
- package/lib/requests/PackageRequest.js +88 -0
- package/lib/requests/PathRequest.js +349 -0
- package/lib/requests/TargetRequest.js +1177 -0
- package/lib/requests/ValidationRequest.js +66 -0
- package/lib/requests/WriteBundleRequest.js +252 -0
- package/lib/requests/WriteBundlesRequest.js +153 -0
- package/lib/resolveOptions.js +234 -0
- package/lib/serializer.js +216 -0
- package/lib/serializerCore.browser.js +29 -0
- package/lib/serializerCore.js +16 -0
- package/lib/summarizeRequest.js +55 -0
- package/lib/types.js +35 -0
- package/lib/utils.js +160 -0
- package/lib/worker.js +170 -0
- package/package.json +59 -0
- package/src/AssetGraph.js +646 -0
- package/src/Atlaspack.js +632 -0
- package/src/AtlaspackConfig.js +490 -0
- package/src/AtlaspackConfig.schema.js +141 -0
- package/src/BundleGraph.js +2193 -0
- package/src/CommittedAsset.js +143 -0
- package/src/Dependency.js +142 -0
- package/src/Environment.js +151 -0
- package/src/InternalConfig.js +72 -0
- package/src/PackagerRunner.js +790 -0
- package/src/ReporterRunner.js +158 -0
- package/src/RequestTracker.js +1697 -0
- package/src/SymbolPropagation.js +794 -0
- package/src/TargetDescriptor.schema.js +136 -0
- package/src/Transformation.js +752 -0
- package/src/UncommittedAsset.js +426 -0
- package/src/Validation.js +223 -0
- package/src/applyRuntimes.js +341 -0
- package/src/assetUtils.js +254 -0
- package/src/atlaspack-v3/AtlaspackV3.js +73 -0
- package/src/atlaspack-v3/fs.js +36 -0
- package/src/atlaspack-v3/index.js +5 -0
- package/src/atlaspack-v3/jsCallable.js +13 -0
- package/src/atlaspack-v3/plugins/Resolver.js +9 -0
- package/src/atlaspack-v3/plugins/index.js +3 -0
- package/src/atlaspack-v3/worker/index.js +8 -0
- package/src/atlaspack-v3/worker/worker.js +14 -0
- package/src/buildCache.js +15 -0
- package/src/constants.js +22 -0
- package/src/dumpGraphToGraphViz.js +244 -0
- package/src/index.js +22 -0
- package/src/loadAtlaspackPlugin.js +239 -0
- package/src/loadDotEnv.js +56 -0
- package/src/projectPath.js +87 -0
- package/src/public/Asset.js +359 -0
- package/src/public/Bundle.js +337 -0
- package/src/public/BundleGraph.js +335 -0
- package/src/public/BundleGroup.js +55 -0
- package/src/public/Config.js +261 -0
- package/src/public/Dependency.js +176 -0
- package/src/public/Environment.js +316 -0
- package/src/public/MutableBundleGraph.js +320 -0
- package/src/public/PluginOptions.js +99 -0
- package/src/public/Symbols.js +315 -0
- package/src/public/Target.js +71 -0
- package/src/registerCoreWithSerializer.js +34 -0
- package/src/requests/AssetGraphRequest.js +577 -0
- package/src/requests/AssetGraphRequestRust.js +222 -0
- package/src/requests/AssetRequest.js +179 -0
- package/src/requests/AtlaspackBuildRequest.js +109 -0
- package/src/requests/AtlaspackConfigRequest.js +709 -0
- package/src/requests/BundleGraphRequest.js +547 -0
- package/src/requests/ConfigRequest.js +287 -0
- package/src/requests/DevDepRequest.js +246 -0
- package/src/requests/EntryRequest.js +385 -0
- package/src/requests/PackageRequest.js +105 -0
- package/src/requests/PathRequest.js +454 -0
- package/src/requests/TargetRequest.js +1632 -0
- package/src/requests/ValidationRequest.js +79 -0
- package/src/requests/WriteBundleRequest.js +362 -0
- package/src/requests/WriteBundlesRequest.js +209 -0
- package/src/resolveOptions.js +278 -0
- package/src/serializer.js +255 -0
- package/src/serializerCore.browser.js +8 -0
- package/src/serializerCore.js +5 -0
- package/src/summarizeRequest.js +47 -0
- package/src/types.js +581 -0
- package/src/utils.js +211 -0
- package/src/worker.js +189 -0
- package/test/AssetGraph.test.js +679 -0
- package/test/Atlaspack.test.js +142 -0
- package/test/AtlaspackConfig.test.js +405 -0
- package/test/AtlaspackConfigRequest.test.js +993 -0
- package/test/BundleGraph.test.js +121 -0
- package/test/EntryRequest.test.js +215 -0
- package/test/Environment.test.js +99 -0
- package/test/InternalAsset.test.js +76 -0
- package/test/PackagerRunner.test.js +27 -0
- package/test/PublicAsset.test.js +40 -0
- package/test/PublicBundle.test.js +68 -0
- package/test/PublicDependency.test.js +22 -0
- package/test/PublicEnvironment.test.js +27 -0
- package/test/PublicMutableBundleGraph.test.js +192 -0
- package/test/RequestTracker.test.js +448 -0
- package/test/SymbolPropagation.test.js +716 -0
- package/test/TargetRequest.test.js +1715 -0
- package/test/fixtures/application-targets/package.json +3 -0
- package/test/fixtures/atlaspack/index.js +1 -0
- package/test/fixtures/atlaspack/other.js +3 -0
- package/test/fixtures/atlaspack/package.json +1 -0
- package/test/fixtures/atlaspack/yarn.lock +0 -0
- package/test/fixtures/bundle.js +10 -0
- package/test/fixtures/common-targets/package.json +24 -0
- package/test/fixtures/common-targets-ignore/package.json +13 -0
- package/test/fixtures/config/.atlaspackrc +6 -0
- package/test/fixtures/config/subfolder/.atlaspackrc +6 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-json5 +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-multiple +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-node-modules +3 -0
- package/test/fixtures/config-malformed/.atlaspackrc +3 -0
- package/test/fixtures/config-node-pipeline/.atlaspackrc +6 -0
- package/test/fixtures/config-plugin-not-found/.atlaspackrc +6 -0
- package/test/fixtures/context/package.json +8 -0
- package/test/fixtures/custom-format-infer-ext/package.json +6 -0
- package/test/fixtures/custom-format-infer-type/package.json +7 -0
- package/test/fixtures/custom-format-mismatch/package.json +8 -0
- package/test/fixtures/custom-targets/package.json +20 -0
- package/test/fixtures/custom-targets-distdir/package.json +11 -0
- package/test/fixtures/duplicate-targets/package.json +4 -0
- package/test/fixtures/glob-like/[entry].js +0 -0
- package/test/fixtures/invalid-distpath/package.json +11 -0
- package/test/fixtures/invalid-engines/package.json +12 -0
- package/test/fixtures/invalid-source-missing/package.json +5 -0
- package/test/fixtures/invalid-source-not-file/package.json +5 -0
- package/test/fixtures/invalid-source-not-file/src/index.js +1 -0
- package/test/fixtures/invalid-target-source-missing/package.json +9 -0
- package/test/fixtures/invalid-target-source-not-file/package.json +9 -0
- package/test/fixtures/invalid-target-source-not-file/src/index.js +1 -0
- package/test/fixtures/invalid-targets/package.json +19 -0
- package/test/fixtures/library-custom-scopehoist/package.json +9 -0
- package/test/fixtures/library-scopehoist/package.json +8 -0
- package/test/fixtures/local-plugin-config-pkg/.atlaspackrc +3 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/index.json +8 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/local-plugin.js +7 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/package.json +7 -0
- package/test/fixtures/main-format-mismatch/package.json +8 -0
- package/test/fixtures/main-global/package.json +8 -0
- package/test/fixtures/main-mjs/package.json +8 -0
- package/test/fixtures/module-a.js +1 -0
- package/test/fixtures/module-b.js +1 -0
- package/test/fixtures/plugins/local-plugin.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/index.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/package.json +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/index.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/package.json +4 -0
- package/test/fixtures/targets-default-distdir-none/package.json +5 -0
- package/test/fixtures/targets-default-distdir-one/package.json +8 -0
- package/test/fixtures/targets-default-distdir-two/package.json +18 -0
- package/test/requests/ConfigRequest.test.js +254 -0
- package/test/serializer.test.js +302 -0
- package/test/test-utils.js +80 -0
- package/test/utils.test.js +43 -0
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import assert from 'assert';
|
|
3
|
+
import invariant from 'assert';
|
|
4
|
+
import nullthrows from 'nullthrows';
|
|
5
|
+
import AssetGraph, {
|
|
6
|
+
nodeFromAssetGroup,
|
|
7
|
+
nodeFromDep,
|
|
8
|
+
nodeFromEntryFile,
|
|
9
|
+
nodeFromAsset,
|
|
10
|
+
} from '../src/AssetGraph';
|
|
11
|
+
import {createDependency as _createDependency} from '../src/Dependency';
|
|
12
|
+
import {createAsset as _createAsset} from '../src/assetUtils';
|
|
13
|
+
import {DEFAULT_ENV, DEFAULT_TARGETS} from './test-utils';
|
|
14
|
+
import {toProjectPath as _toProjectPath} from '../src/projectPath';
|
|
15
|
+
|
|
16
|
+
const stats = {size: 0, time: 0};
|
|
17
|
+
|
|
18
|
+
function createAsset(opts) {
|
|
19
|
+
return _createAsset('/', opts);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function createDependency(opts) {
|
|
23
|
+
return _createDependency('/', opts);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function toProjectPath(p) {
|
|
27
|
+
return _toProjectPath('/', p);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('AssetGraph', () => {
|
|
31
|
+
it('initialization should create one root node with edges to entry_specifier nodes for each entry', () => {
|
|
32
|
+
let graph = new AssetGraph();
|
|
33
|
+
graph.setRootConnections({
|
|
34
|
+
entries: [
|
|
35
|
+
toProjectPath('/path/to/index1'),
|
|
36
|
+
toProjectPath('/path/to/index2'),
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
assert(graph.hasNode(nullthrows(graph.rootNodeId)));
|
|
41
|
+
assert(graph.hasContentKey('entry_specifier:path/to/index1'));
|
|
42
|
+
assert(graph.hasContentKey('entry_specifier:path/to/index2'));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('resolveEntry should connect an entry_specifier node to entry_file nodes', () => {
|
|
46
|
+
let graph = new AssetGraph();
|
|
47
|
+
graph.setRootConnections({
|
|
48
|
+
entries: [
|
|
49
|
+
toProjectPath('/path/to/index1'),
|
|
50
|
+
toProjectPath('/path/to/index2'),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
graph.resolveEntry(
|
|
55
|
+
toProjectPath('/path/to/index1'),
|
|
56
|
+
[
|
|
57
|
+
{
|
|
58
|
+
filePath: toProjectPath('/path/to/index1/src/main.js'),
|
|
59
|
+
packagePath: toProjectPath('/path/to/index1'),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
'123',
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
assert(
|
|
66
|
+
graph.hasContentKey(
|
|
67
|
+
nodeFromEntryFile({
|
|
68
|
+
filePath: toProjectPath('/path/to/index1/src/main.js'),
|
|
69
|
+
packagePath: toProjectPath('/path/to/index1'),
|
|
70
|
+
}).id,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
assert(
|
|
74
|
+
graph.hasEdge(
|
|
75
|
+
graph.getNodeIdByContentKey('entry_specifier:path/to/index1'),
|
|
76
|
+
graph.getNodeIdByContentKey(
|
|
77
|
+
nodeFromEntryFile({
|
|
78
|
+
filePath: toProjectPath('/path/to/index1/src/main.js'),
|
|
79
|
+
packagePath: toProjectPath('/path/to/index1'),
|
|
80
|
+
}).id,
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('resolveTargets should connect an entry_file node to dependencies for each target', () => {
|
|
87
|
+
let graph = new AssetGraph();
|
|
88
|
+
graph.setRootConnections({
|
|
89
|
+
entries: [
|
|
90
|
+
toProjectPath('/path/to/index1'),
|
|
91
|
+
toProjectPath('/path/to/index2'),
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
graph.resolveEntry(
|
|
96
|
+
toProjectPath('/path/to/index1'),
|
|
97
|
+
[
|
|
98
|
+
{
|
|
99
|
+
filePath: toProjectPath('/path/to/index1/src/main.js'),
|
|
100
|
+
packagePath: toProjectPath('/path/to/index1'),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
'1',
|
|
104
|
+
);
|
|
105
|
+
graph.resolveEntry(
|
|
106
|
+
toProjectPath('/path/to/index2'),
|
|
107
|
+
[
|
|
108
|
+
{
|
|
109
|
+
filePath: toProjectPath('/path/to/index2/src/main.js'),
|
|
110
|
+
packagePath: toProjectPath('/path/to/index2'),
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
'2',
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
graph.resolveTargets(
|
|
117
|
+
{
|
|
118
|
+
filePath: toProjectPath('/path/to/index1/src/main.js'),
|
|
119
|
+
packagePath: toProjectPath('/path/to/index1'),
|
|
120
|
+
},
|
|
121
|
+
DEFAULT_TARGETS,
|
|
122
|
+
'3',
|
|
123
|
+
);
|
|
124
|
+
graph.resolveTargets(
|
|
125
|
+
{
|
|
126
|
+
filePath: toProjectPath('/path/to/index2/src/main.js'),
|
|
127
|
+
packagePath: toProjectPath('/path/to/index2'),
|
|
128
|
+
},
|
|
129
|
+
DEFAULT_TARGETS,
|
|
130
|
+
'4',
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
assert(
|
|
134
|
+
graph.hasContentKey(
|
|
135
|
+
createDependency({
|
|
136
|
+
specifier: 'path/to/index1/src/main.js',
|
|
137
|
+
specifierType: 'esm',
|
|
138
|
+
target: DEFAULT_TARGETS[0],
|
|
139
|
+
env: DEFAULT_ENV,
|
|
140
|
+
}).id,
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
assert(
|
|
144
|
+
graph.hasContentKey(
|
|
145
|
+
createDependency({
|
|
146
|
+
specifier: 'path/to/index2/src/main.js',
|
|
147
|
+
specifierType: 'esm',
|
|
148
|
+
target: DEFAULT_TARGETS[0],
|
|
149
|
+
env: DEFAULT_ENV,
|
|
150
|
+
}).id,
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
assert.deepEqual(Array.from(graph.getAllEdges()), [
|
|
154
|
+
{
|
|
155
|
+
from: graph.rootNodeId,
|
|
156
|
+
to: graph.getNodeIdByContentKey('entry_specifier:path/to/index1'),
|
|
157
|
+
type: 1,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
from: graph.rootNodeId,
|
|
161
|
+
to: graph.getNodeIdByContentKey('entry_specifier:path/to/index2'),
|
|
162
|
+
type: 1,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
from: graph.getNodeIdByContentKey('entry_specifier:path/to/index1'),
|
|
166
|
+
to: graph.getNodeIdByContentKey(
|
|
167
|
+
nodeFromEntryFile({
|
|
168
|
+
filePath: toProjectPath('/path/to/index1/src/main.js'),
|
|
169
|
+
packagePath: toProjectPath('/path/to/index1'),
|
|
170
|
+
}).id,
|
|
171
|
+
),
|
|
172
|
+
type: 1,
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
from: graph.getNodeIdByContentKey('entry_specifier:path/to/index2'),
|
|
176
|
+
to: graph.getNodeIdByContentKey(
|
|
177
|
+
nodeFromEntryFile({
|
|
178
|
+
filePath: toProjectPath('/path/to/index2/src/main.js'),
|
|
179
|
+
packagePath: toProjectPath('/path/to/index2'),
|
|
180
|
+
}).id,
|
|
181
|
+
),
|
|
182
|
+
type: 1,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
from: graph.getNodeIdByContentKey(
|
|
186
|
+
nodeFromEntryFile({
|
|
187
|
+
filePath: toProjectPath('/path/to/index1/src/main.js'),
|
|
188
|
+
packagePath: toProjectPath('/path/to/index1'),
|
|
189
|
+
}).id,
|
|
190
|
+
),
|
|
191
|
+
to: graph.getNodeIdByContentKey(
|
|
192
|
+
createDependency({
|
|
193
|
+
specifier: 'path/to/index1/src/main.js',
|
|
194
|
+
specifierType: 'esm',
|
|
195
|
+
target: DEFAULT_TARGETS[0],
|
|
196
|
+
env: DEFAULT_ENV,
|
|
197
|
+
}).id,
|
|
198
|
+
),
|
|
199
|
+
type: 1,
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
from: graph.getNodeIdByContentKey(
|
|
203
|
+
nodeFromEntryFile({
|
|
204
|
+
filePath: toProjectPath('/path/to/index2/src/main.js'),
|
|
205
|
+
packagePath: toProjectPath('/path/to/index2'),
|
|
206
|
+
}).id,
|
|
207
|
+
),
|
|
208
|
+
to: graph.getNodeIdByContentKey(
|
|
209
|
+
createDependency({
|
|
210
|
+
specifier: 'path/to/index2/src/main.js',
|
|
211
|
+
specifierType: 'esm',
|
|
212
|
+
target: DEFAULT_TARGETS[0],
|
|
213
|
+
env: DEFAULT_ENV,
|
|
214
|
+
}).id,
|
|
215
|
+
),
|
|
216
|
+
type: 1,
|
|
217
|
+
},
|
|
218
|
+
]);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('resolveDependency should update the file a dependency is connected to', () => {
|
|
222
|
+
let graph = new AssetGraph();
|
|
223
|
+
graph.setRootConnections({
|
|
224
|
+
targets: DEFAULT_TARGETS,
|
|
225
|
+
entries: [toProjectPath('/path/to/index')],
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
graph.resolveEntry(
|
|
229
|
+
toProjectPath('/path/to/index'),
|
|
230
|
+
[
|
|
231
|
+
{
|
|
232
|
+
filePath: toProjectPath('/path/to/index/src/main.js'),
|
|
233
|
+
packagePath: toProjectPath('/path/to/index'),
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
'1',
|
|
237
|
+
);
|
|
238
|
+
graph.resolveTargets(
|
|
239
|
+
{
|
|
240
|
+
filePath: toProjectPath('/path/to/index/src/main.js'),
|
|
241
|
+
packagePath: toProjectPath('/path/to/index'),
|
|
242
|
+
},
|
|
243
|
+
DEFAULT_TARGETS,
|
|
244
|
+
'2',
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
let dep = createDependency({
|
|
248
|
+
specifier: 'path/to/index/src/main.js',
|
|
249
|
+
specifierType: 'esm',
|
|
250
|
+
target: DEFAULT_TARGETS[0],
|
|
251
|
+
env: DEFAULT_ENV,
|
|
252
|
+
});
|
|
253
|
+
let req = {
|
|
254
|
+
filePath: toProjectPath('/index.js'),
|
|
255
|
+
env: DEFAULT_ENV,
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
graph.resolveDependency(dep, req, '3');
|
|
259
|
+
let assetGroupNodeId = graph.getNodeIdByContentKey(
|
|
260
|
+
nodeFromAssetGroup(req).id,
|
|
261
|
+
);
|
|
262
|
+
let dependencyNodeId = graph.getNodeIdByContentKey(dep.id);
|
|
263
|
+
assert(graph.hasNode(assetGroupNodeId));
|
|
264
|
+
assert(graph.hasEdge(dependencyNodeId, assetGroupNodeId));
|
|
265
|
+
|
|
266
|
+
let req2 = {
|
|
267
|
+
filePath: toProjectPath('/index.jsx'),
|
|
268
|
+
env: DEFAULT_ENV,
|
|
269
|
+
};
|
|
270
|
+
graph.resolveDependency(dep, req2, '4');
|
|
271
|
+
|
|
272
|
+
let assetGroupNodeId2 = graph.getNodeIdByContentKey(
|
|
273
|
+
nodeFromAssetGroup(req2).id,
|
|
274
|
+
);
|
|
275
|
+
assert(!graph.hasNode(assetGroupNodeId));
|
|
276
|
+
assert(graph.hasNode(assetGroupNodeId2));
|
|
277
|
+
assert(graph.hasEdge(dependencyNodeId, assetGroupNodeId2));
|
|
278
|
+
assert(!graph.hasEdge(dependencyNodeId, assetGroupNodeId));
|
|
279
|
+
|
|
280
|
+
graph.resolveDependency(dep, req2, '5');
|
|
281
|
+
assert(graph.hasNode(assetGroupNodeId2));
|
|
282
|
+
assert(graph.hasEdge(dependencyNodeId, assetGroupNodeId2));
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('resolveAssetGroup should update the asset and dep nodes a file is connected to', () => {
|
|
286
|
+
let graph = new AssetGraph();
|
|
287
|
+
graph.setRootConnections({
|
|
288
|
+
targets: DEFAULT_TARGETS,
|
|
289
|
+
entries: [toProjectPath('/path/to/index')],
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
graph.resolveEntry(
|
|
293
|
+
toProjectPath('/path/to/index'),
|
|
294
|
+
[
|
|
295
|
+
{
|
|
296
|
+
filePath: toProjectPath('/path/to/index/src/main.js'),
|
|
297
|
+
packagePath: toProjectPath('/path/to/index'),
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
'1',
|
|
301
|
+
);
|
|
302
|
+
graph.resolveTargets(
|
|
303
|
+
{
|
|
304
|
+
filePath: toProjectPath('/path/to/index/src/main.js'),
|
|
305
|
+
packagePath: toProjectPath('/path/to/index'),
|
|
306
|
+
},
|
|
307
|
+
DEFAULT_TARGETS,
|
|
308
|
+
'2',
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
let dep = createDependency({
|
|
312
|
+
specifier: 'path/to/index/src/main.js',
|
|
313
|
+
specifierType: 'esm',
|
|
314
|
+
target: DEFAULT_TARGETS[0],
|
|
315
|
+
env: DEFAULT_ENV,
|
|
316
|
+
sourcePath: '',
|
|
317
|
+
});
|
|
318
|
+
let sourcePath = '/index.js';
|
|
319
|
+
let filePath = toProjectPath(sourcePath);
|
|
320
|
+
let req = {filePath, env: DEFAULT_ENV};
|
|
321
|
+
graph.resolveDependency(dep, req, '3');
|
|
322
|
+
let assets = [
|
|
323
|
+
createAsset({
|
|
324
|
+
id: '1',
|
|
325
|
+
filePath,
|
|
326
|
+
type: 'js',
|
|
327
|
+
isSource: true,
|
|
328
|
+
stats,
|
|
329
|
+
dependencies: new Map([
|
|
330
|
+
[
|
|
331
|
+
'utils',
|
|
332
|
+
createDependency({
|
|
333
|
+
specifier: './utils',
|
|
334
|
+
specifierType: 'esm',
|
|
335
|
+
env: DEFAULT_ENV,
|
|
336
|
+
sourcePath,
|
|
337
|
+
}),
|
|
338
|
+
],
|
|
339
|
+
]),
|
|
340
|
+
env: DEFAULT_ENV,
|
|
341
|
+
}),
|
|
342
|
+
createAsset({
|
|
343
|
+
id: '2',
|
|
344
|
+
filePath,
|
|
345
|
+
type: 'js',
|
|
346
|
+
isSource: true,
|
|
347
|
+
stats,
|
|
348
|
+
dependencies: new Map([
|
|
349
|
+
[
|
|
350
|
+
'styles',
|
|
351
|
+
createDependency({
|
|
352
|
+
specifier: './styles',
|
|
353
|
+
specifierType: 'esm',
|
|
354
|
+
env: DEFAULT_ENV,
|
|
355
|
+
sourcePath,
|
|
356
|
+
}),
|
|
357
|
+
],
|
|
358
|
+
]),
|
|
359
|
+
env: DEFAULT_ENV,
|
|
360
|
+
}),
|
|
361
|
+
createAsset({
|
|
362
|
+
id: '3',
|
|
363
|
+
filePath,
|
|
364
|
+
type: 'js',
|
|
365
|
+
isSource: true,
|
|
366
|
+
dependencies: new Map(),
|
|
367
|
+
env: DEFAULT_ENV,
|
|
368
|
+
stats,
|
|
369
|
+
}),
|
|
370
|
+
];
|
|
371
|
+
|
|
372
|
+
graph.resolveAssetGroup(req, assets, '4');
|
|
373
|
+
|
|
374
|
+
let nodeId1 = graph.getNodeIdByContentKey('1');
|
|
375
|
+
let nodeId2 = graph.getNodeIdByContentKey('2');
|
|
376
|
+
let nodeId3 = graph.getNodeIdByContentKey('3');
|
|
377
|
+
|
|
378
|
+
let assetGroupNode = graph.getNodeIdByContentKey(
|
|
379
|
+
nodeFromAssetGroup(req).id,
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
let dependencyNodeId1 = graph.getNodeIdByContentKey(
|
|
383
|
+
[...assets[0].dependencies.values()][0].id,
|
|
384
|
+
);
|
|
385
|
+
let dependencyNodeId2 = graph.getNodeIdByContentKey(
|
|
386
|
+
[...assets[1].dependencies.values()][0].id,
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
assert(graph.hasNode(nodeId1));
|
|
390
|
+
assert(graph.hasNode(nodeId2));
|
|
391
|
+
assert(graph.hasNode(nodeId3));
|
|
392
|
+
assert(graph.hasNode(dependencyNodeId1));
|
|
393
|
+
assert(graph.hasNode(dependencyNodeId2));
|
|
394
|
+
assert(graph.hasEdge(assetGroupNode, nodeId1));
|
|
395
|
+
assert(graph.hasEdge(assetGroupNode, nodeId2));
|
|
396
|
+
assert(graph.hasEdge(assetGroupNode, nodeId3));
|
|
397
|
+
assert(graph.hasEdge(nodeId1, dependencyNodeId1));
|
|
398
|
+
assert(graph.hasEdge(nodeId2, dependencyNodeId2));
|
|
399
|
+
|
|
400
|
+
let assets2 = [
|
|
401
|
+
createAsset({
|
|
402
|
+
id: '1',
|
|
403
|
+
filePath,
|
|
404
|
+
type: 'js',
|
|
405
|
+
isSource: true,
|
|
406
|
+
stats,
|
|
407
|
+
dependencies: new Map([
|
|
408
|
+
[
|
|
409
|
+
'utils',
|
|
410
|
+
createDependency({
|
|
411
|
+
specifier: './utils',
|
|
412
|
+
specifierType: 'esm',
|
|
413
|
+
env: DEFAULT_ENV,
|
|
414
|
+
sourcePath,
|
|
415
|
+
}),
|
|
416
|
+
],
|
|
417
|
+
]),
|
|
418
|
+
env: DEFAULT_ENV,
|
|
419
|
+
}),
|
|
420
|
+
createAsset({
|
|
421
|
+
id: '2',
|
|
422
|
+
filePath,
|
|
423
|
+
type: 'js',
|
|
424
|
+
isSource: true,
|
|
425
|
+
stats,
|
|
426
|
+
dependencies: new Map(),
|
|
427
|
+
env: DEFAULT_ENV,
|
|
428
|
+
}),
|
|
429
|
+
];
|
|
430
|
+
|
|
431
|
+
graph.resolveAssetGroup(req, assets2, '5');
|
|
432
|
+
|
|
433
|
+
assert(graph.hasNode(nodeId1));
|
|
434
|
+
assert(graph.hasNode(nodeId2));
|
|
435
|
+
assert(!graph.hasNode(nodeId3));
|
|
436
|
+
assert(graph.hasNode(dependencyNodeId1));
|
|
437
|
+
assert(!graph.hasNode(dependencyNodeId2));
|
|
438
|
+
assert(graph.hasEdge(assetGroupNode, nodeId1));
|
|
439
|
+
assert(graph.hasEdge(assetGroupNode, nodeId2));
|
|
440
|
+
assert(!graph.hasEdge(assetGroupNode, nodeId3));
|
|
441
|
+
assert(graph.hasEdge(nodeId1, dependencyNodeId1));
|
|
442
|
+
assert(!graph.hasEdge(nodeId2, dependencyNodeId2));
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// Assets can define dependent assets in the same asset group by declaring a dependency with a module
|
|
446
|
+
// specifier that matches the dependent asset's unique key. These dependent assets are then connected
|
|
447
|
+
// to the asset's dependency instead of the asset group.
|
|
448
|
+
it('resolveAssetGroup should handle dependent assets in asset groups', () => {
|
|
449
|
+
let graph = new AssetGraph();
|
|
450
|
+
graph.setRootConnections({
|
|
451
|
+
targets: DEFAULT_TARGETS,
|
|
452
|
+
entries: [toProjectPath('/index')],
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
graph.resolveEntry(
|
|
456
|
+
toProjectPath('/index'),
|
|
457
|
+
[
|
|
458
|
+
{
|
|
459
|
+
filePath: toProjectPath('/path/to/index/src/main.js'),
|
|
460
|
+
packagePath: toProjectPath('/path/to/index'),
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
'1',
|
|
464
|
+
);
|
|
465
|
+
graph.resolveTargets(
|
|
466
|
+
{
|
|
467
|
+
filePath: toProjectPath('/path/to/index/src/main.js'),
|
|
468
|
+
packagePath: toProjectPath('/path/to/index'),
|
|
469
|
+
},
|
|
470
|
+
DEFAULT_TARGETS,
|
|
471
|
+
'2',
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
let dep = createDependency({
|
|
475
|
+
specifier: 'path/to/index/src/main.js',
|
|
476
|
+
specifierType: 'esm',
|
|
477
|
+
env: DEFAULT_ENV,
|
|
478
|
+
target: DEFAULT_TARGETS[0],
|
|
479
|
+
});
|
|
480
|
+
let sourcePath = '/index.js';
|
|
481
|
+
let filePath = toProjectPath(sourcePath);
|
|
482
|
+
let req = {filePath, env: DEFAULT_ENV};
|
|
483
|
+
graph.resolveDependency(dep, req, '123');
|
|
484
|
+
let dep1 = createDependency({
|
|
485
|
+
specifier: 'dependent-asset-1',
|
|
486
|
+
specifierType: 'esm',
|
|
487
|
+
env: DEFAULT_ENV,
|
|
488
|
+
sourcePath,
|
|
489
|
+
});
|
|
490
|
+
let dep2 = createDependency({
|
|
491
|
+
specifier: 'dependent-asset-2',
|
|
492
|
+
specifierType: 'esm',
|
|
493
|
+
env: DEFAULT_ENV,
|
|
494
|
+
sourcePath,
|
|
495
|
+
});
|
|
496
|
+
let assets = [
|
|
497
|
+
createAsset({
|
|
498
|
+
id: '1',
|
|
499
|
+
filePath,
|
|
500
|
+
type: 'js',
|
|
501
|
+
isSource: true,
|
|
502
|
+
stats,
|
|
503
|
+
dependencies: new Map([['dep1', dep1]]),
|
|
504
|
+
env: DEFAULT_ENV,
|
|
505
|
+
}),
|
|
506
|
+
createAsset({
|
|
507
|
+
id: '2',
|
|
508
|
+
uniqueKey: 'dependent-asset-1',
|
|
509
|
+
filePath,
|
|
510
|
+
type: 'js',
|
|
511
|
+
isSource: true,
|
|
512
|
+
stats,
|
|
513
|
+
dependencies: new Map([['dep2', dep2]]),
|
|
514
|
+
env: DEFAULT_ENV,
|
|
515
|
+
}),
|
|
516
|
+
createAsset({
|
|
517
|
+
id: '3',
|
|
518
|
+
uniqueKey: 'dependent-asset-2',
|
|
519
|
+
filePath,
|
|
520
|
+
type: 'js',
|
|
521
|
+
isSource: true,
|
|
522
|
+
stats,
|
|
523
|
+
env: DEFAULT_ENV,
|
|
524
|
+
}),
|
|
525
|
+
];
|
|
526
|
+
|
|
527
|
+
graph.resolveAssetGroup(req, assets, '3');
|
|
528
|
+
|
|
529
|
+
let nodeId1 = graph.getNodeIdByContentKey('1');
|
|
530
|
+
let nodeId2 = graph.getNodeIdByContentKey('2');
|
|
531
|
+
let nodeId3 = graph.getNodeIdByContentKey('3');
|
|
532
|
+
|
|
533
|
+
let assetGroupNodeId = graph.getNodeIdByContentKey(
|
|
534
|
+
nodeFromAssetGroup(req).id,
|
|
535
|
+
);
|
|
536
|
+
|
|
537
|
+
let depNodeId1 = graph.getNodeIdByContentKey(nodeFromDep(dep1).id);
|
|
538
|
+
let depNodeId2 = graph.getNodeIdByContentKey(nodeFromDep(dep2).id);
|
|
539
|
+
|
|
540
|
+
assert(nodeId1);
|
|
541
|
+
assert(nodeId2);
|
|
542
|
+
assert(nodeId3);
|
|
543
|
+
assert(graph.hasEdge(assetGroupNodeId, nodeId1));
|
|
544
|
+
assert(!graph.hasEdge(assetGroupNodeId, nodeId2));
|
|
545
|
+
assert(!graph.hasEdge(assetGroupNodeId, nodeId3));
|
|
546
|
+
assert(graph.hasEdge(nodeId1, depNodeId1));
|
|
547
|
+
assert(graph.hasEdge(depNodeId1, nodeId2));
|
|
548
|
+
assert(graph.hasEdge(nodeId2, depNodeId2));
|
|
549
|
+
assert(graph.hasEdge(depNodeId2, nodeId3));
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it('should support marking and unmarking all parents with hasDeferred', () => {
|
|
553
|
+
let graph = new AssetGraph();
|
|
554
|
+
|
|
555
|
+
// index
|
|
556
|
+
let indexAssetGroup = {
|
|
557
|
+
filePath: toProjectPath('/index.js'),
|
|
558
|
+
env: DEFAULT_ENV,
|
|
559
|
+
};
|
|
560
|
+
graph.setRootConnections({assetGroups: [indexAssetGroup]});
|
|
561
|
+
let indexFooDep = createDependency({
|
|
562
|
+
specifier: './foo',
|
|
563
|
+
specifierType: 'esm',
|
|
564
|
+
env: DEFAULT_ENV,
|
|
565
|
+
sourcePath: '/index.js',
|
|
566
|
+
});
|
|
567
|
+
let indexBarDep = createDependency({
|
|
568
|
+
specifier: './bar',
|
|
569
|
+
specifierType: 'esm',
|
|
570
|
+
env: DEFAULT_ENV,
|
|
571
|
+
sourcePath: '/index.js',
|
|
572
|
+
});
|
|
573
|
+
let indexAsset = createAsset({
|
|
574
|
+
id: 'assetIndex',
|
|
575
|
+
filePath: toProjectPath('/index.js'),
|
|
576
|
+
type: 'js',
|
|
577
|
+
isSource: true,
|
|
578
|
+
stats,
|
|
579
|
+
dependencies: new Map([
|
|
580
|
+
['./foo', indexFooDep],
|
|
581
|
+
['./bar', indexBarDep],
|
|
582
|
+
]),
|
|
583
|
+
env: DEFAULT_ENV,
|
|
584
|
+
});
|
|
585
|
+
graph.resolveAssetGroup(indexAssetGroup, [indexAsset], '0');
|
|
586
|
+
|
|
587
|
+
// index imports foo
|
|
588
|
+
let fooAssetGroup = {
|
|
589
|
+
filePath: toProjectPath('/foo.js'),
|
|
590
|
+
env: DEFAULT_ENV,
|
|
591
|
+
};
|
|
592
|
+
graph.resolveDependency(indexFooDep, fooAssetGroup, '0');
|
|
593
|
+
let fooAssetGroupNode = nodeFromAssetGroup(fooAssetGroup);
|
|
594
|
+
let fooUtilsDep = createDependency({
|
|
595
|
+
specifier: './utils',
|
|
596
|
+
specifierType: 'esm',
|
|
597
|
+
env: DEFAULT_ENV,
|
|
598
|
+
sourcePath: '/foo.js',
|
|
599
|
+
});
|
|
600
|
+
let fooUtilsDepNode = nodeFromDep(fooUtilsDep);
|
|
601
|
+
let fooAsset = createAsset({
|
|
602
|
+
id: 'assetFoo',
|
|
603
|
+
filePath: toProjectPath('/foo.js'),
|
|
604
|
+
type: 'js',
|
|
605
|
+
isSource: true,
|
|
606
|
+
stats,
|
|
607
|
+
dependencies: new Map([['./utils', fooUtilsDep]]),
|
|
608
|
+
env: DEFAULT_ENV,
|
|
609
|
+
});
|
|
610
|
+
let fooAssetNode = nodeFromAsset(fooAsset);
|
|
611
|
+
graph.resolveAssetGroup(fooAssetGroup, [fooAsset], '0');
|
|
612
|
+
let utilsAssetGroup = {
|
|
613
|
+
filePath: toProjectPath('/utils.js'),
|
|
614
|
+
env: DEFAULT_ENV,
|
|
615
|
+
};
|
|
616
|
+
let utilsAssetGroupNode = nodeFromAssetGroup(utilsAssetGroup);
|
|
617
|
+
graph.resolveDependency(fooUtilsDep, utilsAssetGroup, '0');
|
|
618
|
+
|
|
619
|
+
// foo's dependency is deferred
|
|
620
|
+
graph.markParentsWithHasDeferred(
|
|
621
|
+
graph.getNodeIdByContentKey(fooUtilsDepNode.id),
|
|
622
|
+
);
|
|
623
|
+
let node = nullthrows(graph.getNodeByContentKey(fooAssetNode.id));
|
|
624
|
+
invariant(node.type === 'asset');
|
|
625
|
+
assert(node.hasDeferred);
|
|
626
|
+
node = nullthrows(graph.getNodeByContentKey(fooAssetGroupNode.id));
|
|
627
|
+
invariant(node.type === 'asset_group');
|
|
628
|
+
assert(node.hasDeferred);
|
|
629
|
+
|
|
630
|
+
// index also imports bar
|
|
631
|
+
let barAssetGroup = {
|
|
632
|
+
filePath: toProjectPath('/bar.js'),
|
|
633
|
+
env: DEFAULT_ENV,
|
|
634
|
+
};
|
|
635
|
+
graph.resolveDependency(indexBarDep, barAssetGroup, '0');
|
|
636
|
+
let barAssetGroupNode = nodeFromAssetGroup(barAssetGroup);
|
|
637
|
+
let barUtilsDep = createDependency({
|
|
638
|
+
specifier: './utils',
|
|
639
|
+
specifierType: 'esm',
|
|
640
|
+
env: DEFAULT_ENV,
|
|
641
|
+
sourcePath: '/bar.js',
|
|
642
|
+
});
|
|
643
|
+
let barAsset = createAsset({
|
|
644
|
+
id: 'assetBar',
|
|
645
|
+
filePath: toProjectPath('/bar.js'),
|
|
646
|
+
type: 'js',
|
|
647
|
+
isSource: true,
|
|
648
|
+
stats,
|
|
649
|
+
dependencies: new Map([['./utils', barUtilsDep]]),
|
|
650
|
+
env: DEFAULT_ENV,
|
|
651
|
+
});
|
|
652
|
+
let barAssetNode = nodeFromAsset(barAsset);
|
|
653
|
+
graph.resolveAssetGroup(barAssetGroup, [barAsset], '3');
|
|
654
|
+
graph.resolveDependency(barUtilsDep, utilsAssetGroup, '4');
|
|
655
|
+
|
|
656
|
+
// bar undeferres utils
|
|
657
|
+
graph.unmarkParentsWithHasDeferred(
|
|
658
|
+
graph.getNodeIdByContentKey(utilsAssetGroupNode.id),
|
|
659
|
+
);
|
|
660
|
+
node = nullthrows(graph.getNodeByContentKey(fooUtilsDep.id));
|
|
661
|
+
invariant(node.type === 'dependency');
|
|
662
|
+
assert(!node.hasDeferred);
|
|
663
|
+
node = nullthrows(graph.getNodeByContentKey(fooAssetNode.id));
|
|
664
|
+
invariant(node.type === 'asset');
|
|
665
|
+
assert(!node.hasDeferred);
|
|
666
|
+
node = nullthrows(graph.getNodeByContentKey(fooAssetGroupNode.id));
|
|
667
|
+
invariant(node.type === 'asset_group');
|
|
668
|
+
assert(!node.hasDeferred);
|
|
669
|
+
node = nullthrows(graph.getNodeByContentKey(barUtilsDep.id));
|
|
670
|
+
invariant(node.type === 'dependency');
|
|
671
|
+
assert(!node.hasDeferred);
|
|
672
|
+
node = nullthrows(graph.getNodeByContentKey(barAssetNode.id));
|
|
673
|
+
invariant(node.type === 'asset');
|
|
674
|
+
assert(!node.hasDeferred);
|
|
675
|
+
node = nullthrows(graph.getNodeByContentKey(barAssetGroupNode.id));
|
|
676
|
+
invariant(node.type === 'asset_group');
|
|
677
|
+
assert(!node.hasDeferred);
|
|
678
|
+
});
|
|
679
|
+
});
|