@atlaspack/bundler-experimental 2.12.1-canary.3624 → 2.12.1-canary.3625
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/package.json +12 -12
- package/test/fixtureFromGraph.js +190 -0
- package/test/fixtureFromGraph.test.js +106 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atlaspack/bundler-experimental",
|
3
|
-
"version": "2.12.1-canary.
|
3
|
+
"version": "2.12.1-canary.3625+6c4f222b8",
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -16,19 +16,19 @@
|
|
16
16
|
"parcel": "^2.12.0"
|
17
17
|
},
|
18
18
|
"dependencies": {
|
19
|
-
"@atlaspack/core": "2.12.1-canary.
|
20
|
-
"@atlaspack/diagnostic": "2.12.1-canary.
|
21
|
-
"@atlaspack/feature-flags": "2.12.1-canary.
|
22
|
-
"@atlaspack/graph": "3.2.1-canary.
|
23
|
-
"@atlaspack/logger": "2.12.1-canary.
|
24
|
-
"@atlaspack/plugin": "2.12.1-canary.
|
25
|
-
"@atlaspack/rust": "2.12.1-canary.
|
26
|
-
"@atlaspack/types": "2.12.1-canary.
|
27
|
-
"@atlaspack/utils": "2.12.1-canary.
|
19
|
+
"@atlaspack/core": "2.12.1-canary.3625+6c4f222b8",
|
20
|
+
"@atlaspack/diagnostic": "2.12.1-canary.3625+6c4f222b8",
|
21
|
+
"@atlaspack/feature-flags": "2.12.1-canary.3625+6c4f222b8",
|
22
|
+
"@atlaspack/graph": "3.2.1-canary.3625+6c4f222b8",
|
23
|
+
"@atlaspack/logger": "2.12.1-canary.3625+6c4f222b8",
|
24
|
+
"@atlaspack/plugin": "2.12.1-canary.3625+6c4f222b8",
|
25
|
+
"@atlaspack/rust": "2.12.1-canary.3625+6c4f222b8",
|
26
|
+
"@atlaspack/types": "2.12.1-canary.3625+6c4f222b8",
|
27
|
+
"@atlaspack/utils": "2.12.1-canary.3625+6c4f222b8",
|
28
28
|
"nullthrows": "^1.1.1"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
|
-
"@atlaspack/fs": "2.12.1-canary.
|
31
|
+
"@atlaspack/fs": "2.12.1-canary.3625+6c4f222b8"
|
32
32
|
},
|
33
|
-
"gitHead": "
|
33
|
+
"gitHead": "6c4f222b816a32ea2ac5cef41a1784e8d044f142"
|
34
34
|
}
|
@@ -0,0 +1,190 @@
|
|
1
|
+
// @flow strict-local
|
2
|
+
|
3
|
+
/*!
|
4
|
+
* This module provides a way to write fixtures where we don't care about the
|
5
|
+
* code within the assets; only the shape of the asset graphs.
|
6
|
+
*/
|
7
|
+
import type {FileSystem} from '@atlaspack/fs';
|
8
|
+
import path from 'path';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* A node in the fixture graph
|
12
|
+
*/
|
13
|
+
export type GraphEntry = AssetEntry;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* An asset in the fixture graph. Just a path and dependencies
|
17
|
+
*/
|
18
|
+
export type AssetEntry = {|
|
19
|
+
type: 'asset',
|
20
|
+
value: {|
|
21
|
+
filePath: string,
|
22
|
+
dependencies: DependencyEntry[],
|
23
|
+
|},
|
24
|
+
|};
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Sync or async dependency between assets
|
28
|
+
*/
|
29
|
+
export type DependencyEntry = {|
|
30
|
+
type: 'dependency',
|
31
|
+
value: {|
|
32
|
+
from: string,
|
33
|
+
to: string,
|
34
|
+
type: 'sync' | 'async',
|
35
|
+
|},
|
36
|
+
|};
|
37
|
+
|
38
|
+
export type DependencySpec = {|
|
39
|
+
to: string,
|
40
|
+
type: 'sync' | 'async',
|
41
|
+
|};
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Create an asset node in the fixture graph
|
45
|
+
*/
|
46
|
+
export function asset(
|
47
|
+
path: string,
|
48
|
+
dependencies?: (string | DependencySpec)[],
|
49
|
+
): GraphEntry {
|
50
|
+
return {
|
51
|
+
type: 'asset',
|
52
|
+
value: {
|
53
|
+
filePath: path,
|
54
|
+
dependencies:
|
55
|
+
dependencies?.map((dependency) => {
|
56
|
+
if (typeof dependency === 'string') {
|
57
|
+
return {
|
58
|
+
type: 'dependency',
|
59
|
+
value: {
|
60
|
+
from: path,
|
61
|
+
to: dependency,
|
62
|
+
type: 'sync',
|
63
|
+
},
|
64
|
+
};
|
65
|
+
} else {
|
66
|
+
return {
|
67
|
+
type: 'dependency',
|
68
|
+
value: {
|
69
|
+
from: path,
|
70
|
+
to: dependency.to,
|
71
|
+
type: dependency.type,
|
72
|
+
},
|
73
|
+
};
|
74
|
+
}
|
75
|
+
}) ?? [],
|
76
|
+
},
|
77
|
+
};
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Create the files for a fixture graph over the `fs` filesystem.
|
82
|
+
*/
|
83
|
+
export async function fixtureFromGraph(
|
84
|
+
dirname: string,
|
85
|
+
fs: FileSystem,
|
86
|
+
entries: GraphEntry[],
|
87
|
+
): Promise<string> {
|
88
|
+
await fs.mkdirp(dirname);
|
89
|
+
|
90
|
+
for (let entry of entries) {
|
91
|
+
if (entry.type === 'asset') {
|
92
|
+
const dependencies = entry.value.dependencies ?? [];
|
93
|
+
const symbols = dependencies
|
94
|
+
.filter((d) => d.value.type === 'sync')
|
95
|
+
.map((_, i) => `d${i}`);
|
96
|
+
const asyncDependencies = dependencies
|
97
|
+
.filter((d) => d.value.type === 'async')
|
98
|
+
.map((d) => `import('./${d.value.to}')`);
|
99
|
+
const contents = [
|
100
|
+
...dependencies
|
101
|
+
.filter((d) => {
|
102
|
+
return d.value.type === 'sync';
|
103
|
+
})
|
104
|
+
.map((dependency, i) => {
|
105
|
+
return `import ${symbols[i]} from './${dependency.value.to}';`;
|
106
|
+
}),
|
107
|
+
`export default function run() { return [${[
|
108
|
+
...symbols,
|
109
|
+
...asyncDependencies,
|
110
|
+
].join(', ')}] }`,
|
111
|
+
].join('\n');
|
112
|
+
|
113
|
+
await fs.writeFile(path.join(dirname, entry.value.filePath), contents);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
return dotFromGraph(entries);
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Create a graphviz dot string from a fixture graph
|
122
|
+
*
|
123
|
+
* The contents of the GraphViz file will contain (in this order):
|
124
|
+
*
|
125
|
+
* * the list of all asset nodes
|
126
|
+
* * the dependencies between assets
|
127
|
+
*
|
128
|
+
* Given a graph build with:
|
129
|
+
*
|
130
|
+
* ```
|
131
|
+
* fixtureFromGraph('dir', fs, [
|
132
|
+
* asset('a.js', ['b.js', 'c.js']),
|
133
|
+
* asset('b.js', ['d.js']),
|
134
|
+
* asset('d.js'),
|
135
|
+
* ])
|
136
|
+
* ```
|
137
|
+
*
|
138
|
+
* The output will be:
|
139
|
+
* ```
|
140
|
+
* digraph assets {
|
141
|
+
* labelloc="t";
|
142
|
+
* label="Assets";
|
143
|
+
*
|
144
|
+
* "a.js";
|
145
|
+
* "b.js";
|
146
|
+
* "c.js";
|
147
|
+
* "d.js";
|
148
|
+
*
|
149
|
+
* "a.js" -> "b.js";
|
150
|
+
* "a.js" -> "c.js";
|
151
|
+
* "b.js" -> "d.js";
|
152
|
+
* }
|
153
|
+
* ```
|
154
|
+
*
|
155
|
+
* That is:
|
156
|
+
*
|
157
|
+
* * iterate all nodes and declare them
|
158
|
+
* * iterate all dependencies between nodes and declare them
|
159
|
+
*
|
160
|
+
*/
|
161
|
+
export function dotFromGraph(entries: GraphEntry[]): string {
|
162
|
+
const contents = [];
|
163
|
+
|
164
|
+
for (let entry of entries) {
|
165
|
+
if (entry.type === 'asset') {
|
166
|
+
const asset = entry.value;
|
167
|
+
contents.push(`"${asset.filePath}";`);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
contents.push('');
|
172
|
+
|
173
|
+
for (let entry of entries) {
|
174
|
+
if (entry.type === 'asset') {
|
175
|
+
const asset = entry.value;
|
176
|
+
for (let dependency of entry.value.dependencies) {
|
177
|
+
contents.push(`"${asset.filePath}" -> "${dependency.value.to}";`);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
return `
|
183
|
+
digraph assets {
|
184
|
+
labelloc="t";
|
185
|
+
label="Assets";
|
186
|
+
|
187
|
+
${contents.map((line) => (line.length > 0 ? ` ${line}` : '')).join('\n')}
|
188
|
+
}
|
189
|
+
`.trim();
|
190
|
+
}
|
@@ -0,0 +1,106 @@
|
|
1
|
+
// @flow strict-local
|
2
|
+
|
3
|
+
import {MemoryFS} from '@atlaspack/fs';
|
4
|
+
import assert from 'assert';
|
5
|
+
import {workerFarm} from '@atlaspack/test-utils';
|
6
|
+
import {asset, fixtureFromGraph, dotFromGraph} from './fixtureFromGraph';
|
7
|
+
|
8
|
+
describe('fixtureFromGraph', () => {
|
9
|
+
before(async function () {
|
10
|
+
this.timeout(10000);
|
11
|
+
// Warm up worker farm so that the first test doesn't account for this time.
|
12
|
+
await workerFarm.callAllWorkers('ping', []);
|
13
|
+
});
|
14
|
+
|
15
|
+
it('can create fixtures for single files', async () => {
|
16
|
+
const fs = new MemoryFS(workerFarm);
|
17
|
+
await fixtureFromGraph('dir', fs, [
|
18
|
+
asset('file1.js'),
|
19
|
+
asset('file2.js'),
|
20
|
+
asset('file3.js'),
|
21
|
+
]);
|
22
|
+
|
23
|
+
assert.deepEqual(await fs.readdir('dir'), [
|
24
|
+
'file1.js',
|
25
|
+
'file2.js',
|
26
|
+
'file3.js',
|
27
|
+
]);
|
28
|
+
assert.equal(
|
29
|
+
await fs.readFile('dir/file1.js', 'utf8'),
|
30
|
+
'export default function run() { return [] }',
|
31
|
+
);
|
32
|
+
});
|
33
|
+
|
34
|
+
it('will create files with imports between themselves', async () => {
|
35
|
+
const fs = new MemoryFS(workerFarm);
|
36
|
+
await fixtureFromGraph('dir', fs, [
|
37
|
+
asset('file1.js', ['file2.js', 'file3.js']),
|
38
|
+
asset('file2.js'),
|
39
|
+
asset('file3.js'),
|
40
|
+
]);
|
41
|
+
|
42
|
+
assert.deepEqual(await fs.readdir('dir'), [
|
43
|
+
'file1.js',
|
44
|
+
'file2.js',
|
45
|
+
'file3.js',
|
46
|
+
]);
|
47
|
+
assert.equal(
|
48
|
+
await fs.readFile('dir/file1.js', 'utf8'),
|
49
|
+
`
|
50
|
+
import d0 from './file2.js';
|
51
|
+
import d1 from './file3.js';
|
52
|
+
export default function run() { return [d0, d1] }
|
53
|
+
`.trim(),
|
54
|
+
);
|
55
|
+
});
|
56
|
+
|
57
|
+
it('will create files with async imports between themselves', async () => {
|
58
|
+
const fs = new MemoryFS(workerFarm);
|
59
|
+
await fixtureFromGraph('dir', fs, [
|
60
|
+
asset('file1.js', ['file2.js', {to: 'file3.js', type: 'async'}]),
|
61
|
+
asset('file2.js'),
|
62
|
+
asset('file3.js'),
|
63
|
+
]);
|
64
|
+
|
65
|
+
assert.deepEqual(await fs.readdir('dir'), [
|
66
|
+
'file1.js',
|
67
|
+
'file2.js',
|
68
|
+
'file3.js',
|
69
|
+
]);
|
70
|
+
assert.equal(
|
71
|
+
await fs.readFile('dir/file1.js', 'utf8'),
|
72
|
+
`
|
73
|
+
import d0 from './file2.js';
|
74
|
+
export default function run() { return [d0, import('./file3.js')] }
|
75
|
+
`.trim(),
|
76
|
+
);
|
77
|
+
});
|
78
|
+
|
79
|
+
describe('dotFromGraph', () => {
|
80
|
+
it('creates a dot string from a graph', () => {
|
81
|
+
const graph = [
|
82
|
+
asset('file1.js', ['file2.js', 'file3.js']),
|
83
|
+
asset('file2.js'),
|
84
|
+
asset('file3.js'),
|
85
|
+
];
|
86
|
+
const dot = dotFromGraph(graph);
|
87
|
+
|
88
|
+
assert.equal(
|
89
|
+
dot,
|
90
|
+
`
|
91
|
+
digraph assets {
|
92
|
+
labelloc="t";
|
93
|
+
label="Assets";
|
94
|
+
|
95
|
+
"file1.js";
|
96
|
+
"file2.js";
|
97
|
+
"file3.js";
|
98
|
+
|
99
|
+
"file1.js" -> "file2.js";
|
100
|
+
"file1.js" -> "file3.js";
|
101
|
+
}
|
102
|
+
`.trim(),
|
103
|
+
);
|
104
|
+
});
|
105
|
+
});
|
106
|
+
});
|