@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
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type {FileSystem, FileOptions} from '@atlaspack/fs';
|
|
4
4
|
import type {ContentKey} from '@atlaspack/graph';
|
|
5
5
|
import type {Async, FilePath, Compressor} from '@atlaspack/types';
|
|
6
|
+
import {replaceHashReferences} from '@atlaspack/rust';
|
|
6
7
|
|
|
7
8
|
import type {RunAPI, StaticRunOpts} from '../RequestTracker';
|
|
8
9
|
import type {Bundle, PackagedBundleInfo, AtlaspackOptions} from '../types';
|
|
@@ -16,7 +17,7 @@ import {HASH_REF_HASH_LEN, HASH_REF_PREFIX} from '../constants';
|
|
|
16
17
|
import nullthrows from 'nullthrows';
|
|
17
18
|
import path from 'path';
|
|
18
19
|
import {NamedBundle} from '../public/Bundle';
|
|
19
|
-
import {blobToStream
|
|
20
|
+
import {blobToStream} from '@atlaspack/utils';
|
|
20
21
|
import {Readable, Transform, pipeline} from 'stream';
|
|
21
22
|
import {
|
|
22
23
|
fromProjectPath,
|
|
@@ -129,20 +130,8 @@ async function run({input, options, api}) {
|
|
|
129
130
|
: {
|
|
130
131
|
mode: (await inputFS.stat(mainEntry.filePath)).mode,
|
|
131
132
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
contentStream = options.cache.getStream(cacheKeys.content);
|
|
135
|
-
} else {
|
|
136
|
-
contentStream = blobToStream(
|
|
137
|
-
await options.cache.getBlob(cacheKeys.content),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
let size = 0;
|
|
141
|
-
contentStream = contentStream.pipe(
|
|
142
|
-
new TapStream(buf => {
|
|
143
|
-
size += buf.length;
|
|
144
|
-
}),
|
|
145
|
-
);
|
|
133
|
+
const contents: Buffer = await options.cache.getBlob(cacheKeys.content);
|
|
134
|
+
const size = contents.byteLength;
|
|
146
135
|
|
|
147
136
|
let configResult = nullthrows(
|
|
148
137
|
await api.runRequest<null, ConfigAndCachePath>(
|
|
@@ -155,7 +144,7 @@ async function run({input, options, api}) {
|
|
|
155
144
|
invalidateDevDeps(invalidDevDeps, options, config);
|
|
156
145
|
|
|
157
146
|
await writeFiles(
|
|
158
|
-
|
|
147
|
+
contents,
|
|
159
148
|
info,
|
|
160
149
|
hashRefToNameHash,
|
|
161
150
|
options,
|
|
@@ -174,7 +163,7 @@ async function run({input, options, api}) {
|
|
|
174
163
|
(await options.cache.has(mapKey))
|
|
175
164
|
) {
|
|
176
165
|
await writeFiles(
|
|
177
|
-
|
|
166
|
+
await options.cache.getBlob(mapKey),
|
|
178
167
|
info,
|
|
179
168
|
hashRefToNameHash,
|
|
180
169
|
options,
|
|
@@ -201,7 +190,7 @@ async function run({input, options, api}) {
|
|
|
201
190
|
}
|
|
202
191
|
|
|
203
192
|
async function writeFiles(
|
|
204
|
-
|
|
193
|
+
contents: Buffer,
|
|
205
194
|
info: BundleInfo,
|
|
206
195
|
hashRefToNameHash: Map<string, string>,
|
|
207
196
|
options: AtlaspackOptions,
|
|
@@ -217,16 +206,19 @@ async function writeFiles(
|
|
|
217
206
|
);
|
|
218
207
|
let fullPath = fromProjectPath(options.projectRoot, filePath);
|
|
219
208
|
|
|
220
|
-
|
|
221
|
-
?
|
|
222
|
-
|
|
209
|
+
const stream = info.hashReferences.length
|
|
210
|
+
? replaceHashReferences(
|
|
211
|
+
contents,
|
|
212
|
+
Object.fromEntries(hashRefToNameHash.entries()),
|
|
213
|
+
)
|
|
214
|
+
: contents;
|
|
223
215
|
|
|
224
216
|
let promises = [];
|
|
225
217
|
for (let compressor of compressors) {
|
|
226
218
|
promises.push(
|
|
227
219
|
runCompressor(
|
|
228
220
|
compressor,
|
|
229
|
-
|
|
221
|
+
blobToStream(stream),
|
|
230
222
|
options,
|
|
231
223
|
outputFS,
|
|
232
224
|
fullPath,
|
|
@@ -300,7 +292,9 @@ async function runCompressor(
|
|
|
300
292
|
}
|
|
301
293
|
}
|
|
302
294
|
|
|
303
|
-
function replaceStream(
|
|
295
|
+
export function replaceStream(
|
|
296
|
+
hashRefToNameHash: Map<string, string>,
|
|
297
|
+
): Transform {
|
|
304
298
|
let boundaryStr = Buffer.alloc(0);
|
|
305
299
|
let replaced = Buffer.alloc(0);
|
|
306
300
|
return new Transform({
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
// @flow strict-local
|
|
3
|
+
|
|
4
|
+
// $FlowFixMe
|
|
5
|
+
import deepClone from 'rfdc/default';
|
|
6
|
+
// $FlowFixMe
|
|
7
|
+
import {diff} from 'jest-diff';
|
|
8
|
+
import AssetGraph from '../AssetGraph';
|
|
9
|
+
import type {AssetGraphNode} from '../types';
|
|
10
|
+
import {fromProjectPathRelative, toProjectPath} from '../projectPath';
|
|
11
|
+
|
|
12
|
+
function filterNode(node) {
|
|
13
|
+
let clone = deepClone(node);
|
|
14
|
+
|
|
15
|
+
// Clean up anything you don't want to see in the diff
|
|
16
|
+
// delete clone.id;
|
|
17
|
+
delete clone.value.id;
|
|
18
|
+
delete clone.value.meta.id;
|
|
19
|
+
delete clone.value.sourceAssetId;
|
|
20
|
+
delete clone.value.env.id;
|
|
21
|
+
delete clone.value.isEsm;
|
|
22
|
+
delete clone.value.shouldWrap;
|
|
23
|
+
delete clone.value.contentKey;
|
|
24
|
+
delete clone.value.placeholder;
|
|
25
|
+
delete clone.value.code;
|
|
26
|
+
delete clone.value.hasCjsExports;
|
|
27
|
+
delete clone.value.staticExports;
|
|
28
|
+
delete clone.value.isConstantModule;
|
|
29
|
+
delete clone.value.hasNodeReplacements;
|
|
30
|
+
delete clone.value.stats;
|
|
31
|
+
delete clone.value.astKey;
|
|
32
|
+
delete clone.value.astGenerator;
|
|
33
|
+
delete clone.value.dependencies;
|
|
34
|
+
|
|
35
|
+
return clone;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function compactDeep(
|
|
39
|
+
obj: mixed,
|
|
40
|
+
ignoredPatterns: Array<string> = [],
|
|
41
|
+
currentPath: string = '$',
|
|
42
|
+
) {
|
|
43
|
+
if (obj instanceof Map) {
|
|
44
|
+
const copy = {};
|
|
45
|
+
Array.from(obj.entries()).forEach(([k, v]) => {
|
|
46
|
+
if (v != null) {
|
|
47
|
+
copy[k] = compactDeep(v, ignoredPatterns, `${currentPath}.${k}`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return copy;
|
|
51
|
+
} else if (Array.isArray(obj)) {
|
|
52
|
+
return obj.map(v => compactDeep(v, ignoredPatterns, `${currentPath}[]`));
|
|
53
|
+
} else if (typeof obj === 'object') {
|
|
54
|
+
const copy = {};
|
|
55
|
+
Object.entries(obj ?? {}).forEach(([key, value]) => {
|
|
56
|
+
const path = `${currentPath}.${key}`;
|
|
57
|
+
if (ignoredPatterns.some(pattern => path.includes(pattern))) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Equivalent false == null
|
|
61
|
+
if (key === 'isWeak' && value === false) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (value != null) {
|
|
66
|
+
copy[key] = compactDeep(value, ignoredPatterns, path);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return copy;
|
|
70
|
+
} else if (obj != null) {
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function assetGraphDiff(jsAssetGraph: AssetGraph, rustAssetGraph: AssetGraph) {
|
|
76
|
+
const getNodes = graph => {
|
|
77
|
+
let nodes = {};
|
|
78
|
+
|
|
79
|
+
graph.traverse(nodeId => {
|
|
80
|
+
let node: AssetGraphNode | null = graph.getNode(nodeId) ?? null;
|
|
81
|
+
if (!node) return;
|
|
82
|
+
|
|
83
|
+
if (node.type === 'dependency') {
|
|
84
|
+
let sourcePath = node.value.sourcePath ?? toProjectPath('', 'entry');
|
|
85
|
+
nodes[
|
|
86
|
+
`dep:${fromProjectPathRelative(sourcePath)}:${node.value.specifier}`
|
|
87
|
+
] = filterNode(node);
|
|
88
|
+
} else if (node.type === 'asset') {
|
|
89
|
+
nodes[`asset:${fromProjectPathRelative(node.value.filePath)}`] =
|
|
90
|
+
filterNode(node);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return nodes;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const jsNodes = getNodes(jsAssetGraph);
|
|
98
|
+
const rustNodes = getNodes(rustAssetGraph);
|
|
99
|
+
|
|
100
|
+
const all = new Set([...Object.keys(jsNodes), ...Object.keys(rustNodes)]);
|
|
101
|
+
const missing = [];
|
|
102
|
+
const extra = [];
|
|
103
|
+
|
|
104
|
+
for (const key of all.keys()) {
|
|
105
|
+
if (process.env.NATIVE_COMPARE !== 'true') {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
let jsNode = jsNodes[key];
|
|
109
|
+
let rustNode = rustNodes[key];
|
|
110
|
+
|
|
111
|
+
if (!rustNode) {
|
|
112
|
+
missing.push(key);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!jsNode) {
|
|
116
|
+
extra.push(key);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(key);
|
|
121
|
+
const ignoredPatterns = [
|
|
122
|
+
// ignored because we don't copy the environment ID back from rust
|
|
123
|
+
// in the target value
|
|
124
|
+
'$.value.target.env.id',
|
|
125
|
+
// ignore asset.mapKey because we don't do persistence on rust yet
|
|
126
|
+
'$.value.mapKey',
|
|
127
|
+
// ignore this because it's just the output hash. We don't need to compute
|
|
128
|
+
// this yet
|
|
129
|
+
'$.value.outputHash',
|
|
130
|
+
// ignore correspondingRequest from all nodes
|
|
131
|
+
'$.correspondingRequest',
|
|
132
|
+
];
|
|
133
|
+
console.log(
|
|
134
|
+
diff(
|
|
135
|
+
compactDeep(rustNode, ignoredPatterns),
|
|
136
|
+
compactDeep(jsNode, ignoredPatterns),
|
|
137
|
+
),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log('Missing', missing);
|
|
142
|
+
console.log('Extra', extra);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = assetGraphDiff;
|
package/src/resolveOptions.js
CHANGED
|
@@ -12,7 +12,8 @@ import type {AtlaspackOptions} from './types';
|
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import {hashString} from '@atlaspack/rust';
|
|
14
14
|
import {NodeFS} from '@atlaspack/fs';
|
|
15
|
-
import {LMDBCache, FSCache} from '@atlaspack/cache';
|
|
15
|
+
import {LMDBCache, LMDBLiteCache, FSCache} from '@atlaspack/cache';
|
|
16
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
16
17
|
import {NodePackageManager} from '@atlaspack/package-manager';
|
|
17
18
|
import {
|
|
18
19
|
getRootDir,
|
|
@@ -108,10 +109,17 @@ export default async function resolveOptions(
|
|
|
108
109
|
? path.resolve(initialOptions.watchDir)
|
|
109
110
|
: projectRoot;
|
|
110
111
|
|
|
112
|
+
const makeLMDBCache = () => {
|
|
113
|
+
if (getFeatureFlag('useLmdbJsLite')) {
|
|
114
|
+
return new LMDBLiteCache(cacheDir);
|
|
115
|
+
}
|
|
116
|
+
return new LMDBCache(cacheDir);
|
|
117
|
+
};
|
|
118
|
+
|
|
111
119
|
let cache =
|
|
112
120
|
initialOptions.cache ??
|
|
113
121
|
(outputFS instanceof NodeFS
|
|
114
|
-
?
|
|
122
|
+
? makeLMDBCache()
|
|
115
123
|
: new FSCache(outputFS, cacheDir));
|
|
116
124
|
|
|
117
125
|
let mode = initialOptions.mode ?? 'development';
|
|
@@ -223,6 +231,8 @@ export default async function resolveOptions(
|
|
|
223
231
|
outputFormat: initialOptions?.defaultTargetOptions?.outputFormat,
|
|
224
232
|
isLibrary: initialOptions?.defaultTargetOptions?.isLibrary,
|
|
225
233
|
},
|
|
234
|
+
// unused, feature-flags are set above this to allow this function to use
|
|
235
|
+
// feature-flags
|
|
226
236
|
featureFlags: {...DEFAULT_FEATURE_FLAGS, ...initialOptions?.featureFlags},
|
|
227
237
|
parcelVersion: ATLASPACK_VERSION,
|
|
228
238
|
};
|
package/src/types.js
CHANGED
|
@@ -115,6 +115,7 @@ export const Priority = {
|
|
|
115
115
|
sync: 0,
|
|
116
116
|
parallel: 1,
|
|
117
117
|
lazy: 2,
|
|
118
|
+
conditional: 3,
|
|
118
119
|
};
|
|
119
120
|
|
|
120
121
|
// Must match package_json.rs in node-resolver-rs.
|
|
@@ -542,6 +543,7 @@ export type Bundle = {|
|
|
|
542
543
|
displayName: ?string,
|
|
543
544
|
pipeline: ?string,
|
|
544
545
|
manualSharedBundle?: ?string,
|
|
546
|
+
conditions?: Map<string, string>,
|
|
545
547
|
|};
|
|
546
548
|
|
|
547
549
|
export type BundleNode = {|
|
|
@@ -580,3 +582,11 @@ export type ValidationOpts = {|
|
|
|
580
582
|
|};
|
|
581
583
|
|
|
582
584
|
export type ReportFn = (event: ReporterEvent) => void | Promise<void>;
|
|
585
|
+
|
|
586
|
+
export type Condition = {|
|
|
587
|
+
publicId: string,
|
|
588
|
+
assets: Set<Asset>,
|
|
589
|
+
key: string,
|
|
590
|
+
ifTrueDependency: Dependency,
|
|
591
|
+
ifFalseDependency: Dependency,
|
|
592
|
+
|};
|
package/test/AssetGraph.test.js
CHANGED
|
@@ -9,13 +9,16 @@ import AssetGraph, {
|
|
|
9
9
|
nodeFromAsset,
|
|
10
10
|
} from '../src/AssetGraph';
|
|
11
11
|
import {createDependency as _createDependency} from '../src/Dependency';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
createAsset as _createAsset,
|
|
14
|
+
type AssetOptions,
|
|
15
|
+
} from '../src/assetUtils';
|
|
13
16
|
import {DEFAULT_ENV, DEFAULT_TARGETS} from './test-utils';
|
|
14
17
|
import {toProjectPath as _toProjectPath} from '../src/projectPath';
|
|
15
18
|
|
|
16
19
|
const stats = {size: 0, time: 0};
|
|
17
20
|
|
|
18
|
-
function createAsset(opts) {
|
|
21
|
+
function createAsset(opts: AssetOptions) {
|
|
19
22
|
return _createAsset('/', opts);
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -134,7 +137,7 @@ describe('AssetGraph', () => {
|
|
|
134
137
|
graph.hasContentKey(
|
|
135
138
|
createDependency({
|
|
136
139
|
specifier: 'path/to/index1/src/main.js',
|
|
137
|
-
specifierType: '
|
|
140
|
+
specifierType: 'url',
|
|
138
141
|
target: DEFAULT_TARGETS[0],
|
|
139
142
|
env: DEFAULT_ENV,
|
|
140
143
|
}).id,
|
|
@@ -144,7 +147,7 @@ describe('AssetGraph', () => {
|
|
|
144
147
|
graph.hasContentKey(
|
|
145
148
|
createDependency({
|
|
146
149
|
specifier: 'path/to/index2/src/main.js',
|
|
147
|
-
specifierType: '
|
|
150
|
+
specifierType: 'url',
|
|
148
151
|
target: DEFAULT_TARGETS[0],
|
|
149
152
|
env: DEFAULT_ENV,
|
|
150
153
|
}).id,
|
|
@@ -191,7 +194,7 @@ describe('AssetGraph', () => {
|
|
|
191
194
|
to: graph.getNodeIdByContentKey(
|
|
192
195
|
createDependency({
|
|
193
196
|
specifier: 'path/to/index1/src/main.js',
|
|
194
|
-
specifierType: '
|
|
197
|
+
specifierType: 'url',
|
|
195
198
|
target: DEFAULT_TARGETS[0],
|
|
196
199
|
env: DEFAULT_ENV,
|
|
197
200
|
}).id,
|
|
@@ -208,7 +211,7 @@ describe('AssetGraph', () => {
|
|
|
208
211
|
to: graph.getNodeIdByContentKey(
|
|
209
212
|
createDependency({
|
|
210
213
|
specifier: 'path/to/index2/src/main.js',
|
|
211
|
-
specifierType: '
|
|
214
|
+
specifierType: 'url',
|
|
212
215
|
target: DEFAULT_TARGETS[0],
|
|
213
216
|
env: DEFAULT_ENV,
|
|
214
217
|
}).id,
|
|
@@ -246,7 +249,7 @@ describe('AssetGraph', () => {
|
|
|
246
249
|
|
|
247
250
|
let dep = createDependency({
|
|
248
251
|
specifier: 'path/to/index/src/main.js',
|
|
249
|
-
specifierType: '
|
|
252
|
+
specifierType: 'url',
|
|
250
253
|
target: DEFAULT_TARGETS[0],
|
|
251
254
|
env: DEFAULT_ENV,
|
|
252
255
|
});
|
|
@@ -310,7 +313,7 @@ describe('AssetGraph', () => {
|
|
|
310
313
|
|
|
311
314
|
let dep = createDependency({
|
|
312
315
|
specifier: 'path/to/index/src/main.js',
|
|
313
|
-
specifierType: '
|
|
316
|
+
specifierType: 'url',
|
|
314
317
|
target: DEFAULT_TARGETS[0],
|
|
315
318
|
env: DEFAULT_ENV,
|
|
316
319
|
sourcePath: '',
|
|
@@ -322,6 +325,7 @@ describe('AssetGraph', () => {
|
|
|
322
325
|
let assets = [
|
|
323
326
|
createAsset({
|
|
324
327
|
id: '1',
|
|
328
|
+
code: null,
|
|
325
329
|
filePath,
|
|
326
330
|
type: 'js',
|
|
327
331
|
isSource: true,
|
|
@@ -341,6 +345,7 @@ describe('AssetGraph', () => {
|
|
|
341
345
|
}),
|
|
342
346
|
createAsset({
|
|
343
347
|
id: '2',
|
|
348
|
+
code: null,
|
|
344
349
|
filePath,
|
|
345
350
|
type: 'js',
|
|
346
351
|
isSource: true,
|
|
@@ -360,6 +365,7 @@ describe('AssetGraph', () => {
|
|
|
360
365
|
}),
|
|
361
366
|
createAsset({
|
|
362
367
|
id: '3',
|
|
368
|
+
code: null,
|
|
363
369
|
filePath,
|
|
364
370
|
type: 'js',
|
|
365
371
|
isSource: true,
|
|
@@ -400,6 +406,7 @@ describe('AssetGraph', () => {
|
|
|
400
406
|
let assets2 = [
|
|
401
407
|
createAsset({
|
|
402
408
|
id: '1',
|
|
409
|
+
code: null,
|
|
403
410
|
filePath,
|
|
404
411
|
type: 'js',
|
|
405
412
|
isSource: true,
|
|
@@ -419,6 +426,7 @@ describe('AssetGraph', () => {
|
|
|
419
426
|
}),
|
|
420
427
|
createAsset({
|
|
421
428
|
id: '2',
|
|
429
|
+
code: null,
|
|
422
430
|
filePath,
|
|
423
431
|
type: 'js',
|
|
424
432
|
isSource: true,
|
|
@@ -473,7 +481,7 @@ describe('AssetGraph', () => {
|
|
|
473
481
|
|
|
474
482
|
let dep = createDependency({
|
|
475
483
|
specifier: 'path/to/index/src/main.js',
|
|
476
|
-
specifierType: '
|
|
484
|
+
specifierType: 'url',
|
|
477
485
|
env: DEFAULT_ENV,
|
|
478
486
|
target: DEFAULT_TARGETS[0],
|
|
479
487
|
});
|
|
@@ -496,6 +504,7 @@ describe('AssetGraph', () => {
|
|
|
496
504
|
let assets = [
|
|
497
505
|
createAsset({
|
|
498
506
|
id: '1',
|
|
507
|
+
code: null,
|
|
499
508
|
filePath,
|
|
500
509
|
type: 'js',
|
|
501
510
|
isSource: true,
|
|
@@ -505,6 +514,7 @@ describe('AssetGraph', () => {
|
|
|
505
514
|
}),
|
|
506
515
|
createAsset({
|
|
507
516
|
id: '2',
|
|
517
|
+
code: null,
|
|
508
518
|
uniqueKey: 'dependent-asset-1',
|
|
509
519
|
filePath,
|
|
510
520
|
type: 'js',
|
|
@@ -515,6 +525,7 @@ describe('AssetGraph', () => {
|
|
|
515
525
|
}),
|
|
516
526
|
createAsset({
|
|
517
527
|
id: '3',
|
|
528
|
+
code: null,
|
|
518
529
|
uniqueKey: 'dependent-asset-2',
|
|
519
530
|
filePath,
|
|
520
531
|
type: 'js',
|
|
@@ -572,6 +583,7 @@ describe('AssetGraph', () => {
|
|
|
572
583
|
});
|
|
573
584
|
let indexAsset = createAsset({
|
|
574
585
|
id: 'assetIndex',
|
|
586
|
+
code: null,
|
|
575
587
|
filePath: toProjectPath('/index.js'),
|
|
576
588
|
type: 'js',
|
|
577
589
|
isSource: true,
|
|
@@ -600,6 +612,7 @@ describe('AssetGraph', () => {
|
|
|
600
612
|
let fooUtilsDepNode = nodeFromDep(fooUtilsDep);
|
|
601
613
|
let fooAsset = createAsset({
|
|
602
614
|
id: 'assetFoo',
|
|
615
|
+
code: null,
|
|
603
616
|
filePath: toProjectPath('/foo.js'),
|
|
604
617
|
type: 'js',
|
|
605
618
|
isSource: true,
|
|
@@ -642,6 +655,7 @@ describe('AssetGraph', () => {
|
|
|
642
655
|
});
|
|
643
656
|
let barAsset = createAsset({
|
|
644
657
|
id: 'assetBar',
|
|
658
|
+
code: null,
|
|
645
659
|
filePath: toProjectPath('/bar.js'),
|
|
646
660
|
type: 'js',
|
|
647
661
|
isSource: true,
|
|
@@ -13,107 +13,11 @@ import {
|
|
|
13
13
|
resolveAtlaspackConfig,
|
|
14
14
|
processConfig,
|
|
15
15
|
} from '../src/requests/AtlaspackConfigRequest';
|
|
16
|
-
import {validatePackageName} from '../src/AtlaspackConfig.schema';
|
|
17
16
|
import {DEFAULT_OPTIONS, relative} from './test-utils';
|
|
18
17
|
import {toProjectPath} from '../src/projectPath';
|
|
19
18
|
|
|
20
19
|
describe('AtlaspackConfigRequest', () => {
|
|
21
|
-
describe('validatePackageName', () => {
|
|
22
|
-
it('should error on an invalid official package', () => {
|
|
23
|
-
assert.throws(() => {
|
|
24
|
-
validatePackageName('@atlaspack/foo-bar', 'transform', 'transformers');
|
|
25
|
-
}, /Official atlaspack transform packages must be named according to "@atlaspack\/transform-{name}"/);
|
|
26
|
-
|
|
27
|
-
assert.throws(() => {
|
|
28
|
-
validatePackageName(
|
|
29
|
-
'@atlaspack/transformer',
|
|
30
|
-
'transform',
|
|
31
|
-
'transformers',
|
|
32
|
-
);
|
|
33
|
-
}, /Official atlaspack transform packages must be named according to "@atlaspack\/transform-{name}"/);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should succeed on a valid official package', () => {
|
|
37
|
-
validatePackageName(
|
|
38
|
-
'@atlaspack/transform-bar',
|
|
39
|
-
'transform',
|
|
40
|
-
'transformers',
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should error on an invalid community package', () => {
|
|
45
|
-
assert.throws(() => {
|
|
46
|
-
validatePackageName('foo-bar', 'transform', 'transformers');
|
|
47
|
-
}, /Atlaspack transform packages must be named according to "parcel-transform-{name}"/);
|
|
48
|
-
|
|
49
|
-
assert.throws(() => {
|
|
50
|
-
validatePackageName('parcel-foo-bar', 'transform', 'transformers');
|
|
51
|
-
}, /Atlaspack transform packages must be named according to "parcel-transform-{name}"/);
|
|
52
|
-
|
|
53
|
-
assert.throws(() => {
|
|
54
|
-
validatePackageName('parcel-transform', 'transform', 'transformers');
|
|
55
|
-
}, /Atlaspack transform packages must be named according to "parcel-transform-{name}"/);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should succeed on a valid community package', () => {
|
|
59
|
-
validatePackageName('parcel-transform-bar', 'transform', 'transformers');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Skipping this while the migration to parcel occurs
|
|
63
|
-
it.skip('should error on an invalid scoped package', () => {
|
|
64
|
-
assert.throws(() => {
|
|
65
|
-
validatePackageName('@test/foo-bar', 'transform', 'transformers');
|
|
66
|
-
}, /Scoped atlaspack transform packages must be named according to "@test\/parcel-transform\[-{name}\]"/);
|
|
67
|
-
|
|
68
|
-
assert.throws(() => {
|
|
69
|
-
validatePackageName(
|
|
70
|
-
'@test/atlaspack-foo-bar',
|
|
71
|
-
'transform',
|
|
72
|
-
'transformers',
|
|
73
|
-
);
|
|
74
|
-
}, /Scoped atlaspack transform packages must be named according to "@test\/parcel-transform\[-{name}\]"/);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should succeed on a valid scoped package', () => {
|
|
78
|
-
validatePackageName(
|
|
79
|
-
'@test/atlaspack-transform-bar',
|
|
80
|
-
'transform',
|
|
81
|
-
'transformers',
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
validatePackageName(
|
|
85
|
-
'@test/atlaspack-transform',
|
|
86
|
-
'transform',
|
|
87
|
-
'transformers',
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should succeed on a local package', () => {
|
|
92
|
-
validatePackageName(
|
|
93
|
-
'./atlaspack-transform-bar',
|
|
94
|
-
'transform',
|
|
95
|
-
'transformers',
|
|
96
|
-
);
|
|
97
|
-
validatePackageName('./bar', 'transform', 'transformers');
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
20
|
describe('validateConfigFile', () => {
|
|
102
|
-
it('should throw on invalid config', () => {
|
|
103
|
-
assert.throws(() => {
|
|
104
|
-
validateConfigFile(
|
|
105
|
-
{
|
|
106
|
-
filePath: '.parcelrc',
|
|
107
|
-
extends: 'parcel-config-foo',
|
|
108
|
-
transformers: {
|
|
109
|
-
'*.js': ['parcel-invalid-plugin'],
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
'.parcelrc',
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
21
|
it('should require pipeline to be an array', () => {
|
|
118
22
|
assert.throws(() => {
|
|
119
23
|
validateConfigFile(
|
|
@@ -140,18 +44,6 @@ describe('AtlaspackConfigRequest', () => {
|
|
|
140
44
|
});
|
|
141
45
|
});
|
|
142
46
|
|
|
143
|
-
it('should require package names to be valid', () => {
|
|
144
|
-
assert.throws(() => {
|
|
145
|
-
validateConfigFile(
|
|
146
|
-
{
|
|
147
|
-
filePath: '.parcelrc',
|
|
148
|
-
resolvers: ['parcel-foo-bar'],
|
|
149
|
-
},
|
|
150
|
-
'.parcelrc',
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
47
|
it('should succeed with an array of valid package names', () => {
|
|
156
48
|
validateConfigFile(
|
|
157
49
|
{
|
|
@@ -185,21 +77,6 @@ describe('AtlaspackConfigRequest', () => {
|
|
|
185
77
|
});
|
|
186
78
|
});
|
|
187
79
|
|
|
188
|
-
it('should trigger the validator function for each key', () => {
|
|
189
|
-
assert.throws(() => {
|
|
190
|
-
validateConfigFile(
|
|
191
|
-
{
|
|
192
|
-
filePath: '.parcelrc',
|
|
193
|
-
transformers: {
|
|
194
|
-
'types:*.{ts,tsx}': ['@atlaspack/transformer-typescript-types'],
|
|
195
|
-
'bundle-text:*': ['-inline-string', '...'],
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
'.parcelrc',
|
|
199
|
-
);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
80
|
it('should require extends to be a string or array of strings', () => {
|
|
204
81
|
assert.throws(() => {
|
|
205
82
|
validateConfigFile(
|
|
@@ -242,44 +119,6 @@ describe('AtlaspackConfigRequest', () => {
|
|
|
242
119
|
);
|
|
243
120
|
});
|
|
244
121
|
|
|
245
|
-
it('should validate package names', () => {
|
|
246
|
-
assert.throws(() => {
|
|
247
|
-
validateConfigFile(
|
|
248
|
-
{
|
|
249
|
-
filePath: '.parcelrc',
|
|
250
|
-
extends: 'foo',
|
|
251
|
-
},
|
|
252
|
-
'.parcelrc',
|
|
253
|
-
);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
assert.throws(() => {
|
|
257
|
-
validateConfigFile(
|
|
258
|
-
{
|
|
259
|
-
filePath: '.parcelrc',
|
|
260
|
-
extends: ['foo', 'bar'],
|
|
261
|
-
},
|
|
262
|
-
'.parcelrc',
|
|
263
|
-
);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
validateConfigFile(
|
|
267
|
-
{
|
|
268
|
-
filePath: '.parcelrc',
|
|
269
|
-
extends: 'parcel-config-foo',
|
|
270
|
-
},
|
|
271
|
-
'.parcelrc',
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
validateConfigFile(
|
|
275
|
-
{
|
|
276
|
-
filePath: '.parcelrc',
|
|
277
|
-
extends: ['parcel-config-foo', 'parcel-config-bar'],
|
|
278
|
-
},
|
|
279
|
-
'.parcelrc',
|
|
280
|
-
);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
122
|
it('should throw for invalid top level keys', () => {
|
|
284
123
|
assert.throws(
|
|
285
124
|
() => {
|