@atlaspack/core 2.12.1-dev.3443 → 2.12.1-dev.3460
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 +5 -1
- package/lib/Atlaspack.js +2 -2
- package/lib/Dependency.js +1 -1
- package/lib/PackagerRunner.js +45 -3
- package/lib/SymbolPropagation.js +25 -36
- package/lib/assetUtils.js +1 -1
- package/lib/atlaspack-v3/fs.js +31 -29
- package/lib/atlaspack-v3/index.js +2 -2
- package/lib/atlaspack-v3/jsCallable.js +9 -4
- package/lib/atlaspack-v3/worker/compat/asset-symbols.js +192 -0
- package/lib/atlaspack-v3/worker/compat/bitflags.js +84 -0
- package/lib/atlaspack-v3/worker/compat/dependency.js +44 -0
- package/lib/atlaspack-v3/worker/compat/environment.js +68 -0
- package/lib/atlaspack-v3/worker/compat/index.js +104 -0
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +144 -0
- package/lib/atlaspack-v3/worker/compat/plugin-config.js +58 -0
- package/lib/atlaspack-v3/worker/compat/plugin-logger.js +29 -0
- package/lib/atlaspack-v3/worker/compat/plugin-options.js +113 -0
- package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +12 -0
- package/lib/atlaspack-v3/worker/compat/target.js +17 -0
- package/lib/atlaspack-v3/worker/worker.js +162 -83
- package/lib/projectPath.js +12 -4
- package/lib/requests/ConfigRequest.js +1 -1
- package/lib/requests/WriteBundleRequest.js +15 -15
- package/package.json +23 -16
- package/src/AssetGraph.js +15 -13
- package/src/Atlaspack.js +5 -6
- package/src/AtlaspackConfig.js +11 -9
- package/src/AtlaspackConfig.schema.js +1 -1
- package/src/BundleGraph.js +83 -79
- package/src/CommittedAsset.js +1 -1
- package/src/Dependency.js +1 -1
- package/src/PackagerRunner.js +56 -8
- package/src/ReporterRunner.js +4 -4
- package/src/RequestTracker.js +18 -18
- package/src/SymbolPropagation.js +40 -52
- package/src/Transformation.js +12 -12
- package/src/UncommittedAsset.js +2 -2
- package/src/Validation.js +5 -5
- package/src/applyRuntimes.js +2 -2
- package/src/assetUtils.js +1 -1
- package/src/atlaspack-v3/AtlaspackV3.js +1 -1
- package/src/atlaspack-v3/fs.js +39 -25
- package/src/atlaspack-v3/index.js +1 -1
- package/src/atlaspack-v3/jsCallable.js +11 -10
- package/src/atlaspack-v3/worker/compat/asset-symbols.js +225 -0
- package/src/atlaspack-v3/worker/compat/bitflags.js +100 -0
- package/src/atlaspack-v3/worker/compat/dependency.js +83 -0
- package/src/atlaspack-v3/worker/compat/environment.js +92 -0
- package/src/atlaspack-v3/worker/compat/index.js +10 -0
- package/src/atlaspack-v3/worker/compat/mutable-asset.js +184 -0
- package/src/atlaspack-v3/worker/compat/plugin-config.js +94 -0
- package/src/atlaspack-v3/worker/compat/plugin-logger.js +47 -0
- package/src/atlaspack-v3/worker/compat/plugin-options.js +137 -0
- package/src/atlaspack-v3/worker/compat/plugin-tracer.js +11 -0
- package/src/atlaspack-v3/worker/compat/target.js +27 -0
- package/src/atlaspack-v3/worker/worker.js +218 -113
- package/src/dumpGraphToGraphViz.js +1 -1
- package/src/loadDotEnv.js +1 -1
- package/src/projectPath.js +12 -4
- package/src/public/Asset.js +1 -1
- package/src/public/Bundle.js +3 -3
- package/src/public/BundleGraph.js +20 -20
- package/src/public/Config.js +1 -1
- package/src/public/MutableBundleGraph.js +8 -8
- package/src/requests/AssetGraphRequest.js +10 -10
- package/src/requests/AssetGraphRequestRust.js +3 -3
- package/src/requests/AssetRequest.js +3 -3
- package/src/requests/AtlaspackConfigRequest.js +5 -3
- package/src/requests/BundleGraphRequest.js +6 -6
- package/src/requests/ConfigRequest.js +5 -5
- package/src/requests/DevDepRequest.js +7 -7
- package/src/requests/EntryRequest.js +2 -2
- package/src/requests/TargetRequest.js +9 -8
- package/src/requests/ValidationRequest.js +2 -2
- package/src/requests/WriteBundleRequest.js +26 -20
- package/src/requests/WriteBundlesRequest.js +6 -6
- package/src/requests/asset-graph-diff.js +4 -4
- package/src/resolveOptions.js +3 -3
- package/src/serializer.js +2 -2
- package/src/serializerCore.browser.js +3 -2
- package/src/serializerCore.js +2 -2
- package/src/utils.js +2 -2
- package/test/AtlaspackConfigRequest.test.js +1 -1
- package/test/BundleGraph.test.js +3 -3
- package/test/Dependency.test.js +28 -0
- package/test/PublicMutableBundleGraph.test.js +2 -2
- package/test/RequestTracker.test.js +7 -6
- package/test/SymbolPropagation.test.js +9 -9
- package/test/requests/ConfigRequest.test.js +3 -6
- package/test/utils.test.js +1 -1
- package/lib/atlaspack-v3/worker/compat.js +0 -57
- package/src/atlaspack-v3/worker/compat.js +0 -82
- package/test/requests/WriteBundleRequest.test.js +0 -132
package/src/resolveOptions.js
CHANGED
|
@@ -42,7 +42,7 @@ function generateInstanceId(entries: Array<FilePath>): string {
|
|
|
42
42
|
|
|
43
43
|
// Compiles an array of globs to regex - used for lazy include/excludes
|
|
44
44
|
function compileGlobs(globs: string[]): RegExp[] {
|
|
45
|
-
return globs.map(glob => globToRegex(glob));
|
|
45
|
+
return globs.map((glob) => globToRegex(glob));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export default async function resolveOptions(
|
|
@@ -58,7 +58,7 @@ export default async function resolveOptions(
|
|
|
58
58
|
if (initialOptions.entries == null || initialOptions.entries === '') {
|
|
59
59
|
entries = [];
|
|
60
60
|
} else if (Array.isArray(initialOptions.entries)) {
|
|
61
|
-
entries = initialOptions.entries.map(entry =>
|
|
61
|
+
entries = initialOptions.entries.map((entry) =>
|
|
62
62
|
path.resolve(inputCwd, entry),
|
|
63
63
|
);
|
|
64
64
|
} else {
|
|
@@ -202,7 +202,7 @@ export default async function resolveOptions(
|
|
|
202
202
|
watchDir,
|
|
203
203
|
watchBackend: initialOptions.watchBackend,
|
|
204
204
|
watchIgnore: initialOptions.watchIgnore,
|
|
205
|
-
entries: entries.map(e => toProjectPath(projectRoot, e)),
|
|
205
|
+
entries: entries.map((e) => toProjectPath(projectRoot, e)),
|
|
206
206
|
targets: initialOptions.targets,
|
|
207
207
|
logLevel: initialOptions.logLevel ?? 'info',
|
|
208
208
|
projectRoot,
|
package/src/serializer.js
CHANGED
|
@@ -166,7 +166,7 @@ export function prepareForSerialization(object: any): any {
|
|
|
166
166
|
|
|
167
167
|
return mapObject(
|
|
168
168
|
object,
|
|
169
|
-
value => {
|
|
169
|
+
(value) => {
|
|
170
170
|
// Add a $$type property with the name of this class, if any is registered.
|
|
171
171
|
if (
|
|
172
172
|
value &&
|
|
@@ -201,7 +201,7 @@ export function prepareForSerialization(object: any): any {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
export function restoreDeserializedObject(object: any): any {
|
|
204
|
-
return mapObject(object, value => {
|
|
204
|
+
return mapObject(object, (value) => {
|
|
205
205
|
// If the value has a $$type property, use it to restore the object type
|
|
206
206
|
if (value && value.$$type) {
|
|
207
207
|
let ctor = nameToCtor.get(value.$$type);
|
|
@@ -4,5 +4,6 @@ import * as msgpackr from 'msgpackr';
|
|
|
4
4
|
|
|
5
5
|
let encoder = new msgpackr.Encoder({structuredClone: true});
|
|
6
6
|
|
|
7
|
-
export let serializeRaw: any => Buffer = v =>
|
|
8
|
-
|
|
7
|
+
export let serializeRaw: (any) => Buffer = (v) =>
|
|
8
|
+
Buffer.from(encoder.encode(v));
|
|
9
|
+
export let deserializeRaw: (Buffer) => any = (v) => encoder.decode(v);
|
package/src/serializerCore.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import v8 from 'v8';
|
|
3
3
|
|
|
4
|
-
export let serializeRaw: any => Buffer = v8.serialize;
|
|
5
|
-
export let deserializeRaw: Buffer => any = v8.deserialize;
|
|
4
|
+
export let serializeRaw: (any) => Buffer = v8.serialize;
|
|
5
|
+
export let deserializeRaw: (Buffer) => any = v8.deserialize;
|
package/src/utils.js
CHANGED
|
@@ -40,7 +40,7 @@ export class BuildAbortError extends Error {
|
|
|
40
40
|
|
|
41
41
|
export function getPublicId(
|
|
42
42
|
id: string,
|
|
43
|
-
alreadyExists: string => boolean,
|
|
43
|
+
alreadyExists: (string) => boolean,
|
|
44
44
|
): string {
|
|
45
45
|
let encoded = base62.encode(Buffer.from(id, 'hex'));
|
|
46
46
|
for (let end = 5; end <= encoded.length; end++) {
|
|
@@ -74,7 +74,7 @@ const ignoreOptions = new Set([
|
|
|
74
74
|
|
|
75
75
|
export function optionsProxy(
|
|
76
76
|
options: AtlaspackOptions,
|
|
77
|
-
invalidateOnOptionChange: string => void,
|
|
77
|
+
invalidateOnOptionChange: (string) => void,
|
|
78
78
|
addDevDependency?: (devDep: InternalDevDepOptions) => void,
|
|
79
79
|
): AtlaspackOptions {
|
|
80
80
|
let packageManager = addDevDependency
|
|
@@ -133,7 +133,7 @@ describe('AtlaspackConfigRequest', () => {
|
|
|
133
133
|
'.parcelrc',
|
|
134
134
|
);
|
|
135
135
|
},
|
|
136
|
-
e => {
|
|
136
|
+
(e) => {
|
|
137
137
|
assert.strictEqual(
|
|
138
138
|
e.diagnostics[0].codeFrames[0].codeHighlights[0].message,
|
|
139
139
|
`Possible values: "$schema", "bundler", "resolvers", "transformers", "validators", "namers", "packagers", "optimizers", "compressors", "reporters", "runtimes", "filePath", "resolveFrom"`,
|
package/test/BundleGraph.test.js
CHANGED
|
@@ -29,7 +29,7 @@ describe('BundleGraph', () => {
|
|
|
29
29
|
false,
|
|
30
30
|
);
|
|
31
31
|
assert.deepEqual(
|
|
32
|
-
getAssets(bundleGraph).map(a => bundleGraph.getAssetPublicId(a)),
|
|
32
|
+
getAssets(bundleGraph).map((a) => bundleGraph.getAssetPublicId(a)),
|
|
33
33
|
['296TI', '4DGUq'],
|
|
34
34
|
);
|
|
35
35
|
});
|
|
@@ -40,7 +40,7 @@ describe('BundleGraph', () => {
|
|
|
40
40
|
false,
|
|
41
41
|
);
|
|
42
42
|
assert.deepEqual(
|
|
43
|
-
getAssets(bundleGraph).map(a => bundleGraph.getAssetPublicId(a)),
|
|
43
|
+
getAssets(bundleGraph).map((a) => bundleGraph.getAssetPublicId(a)),
|
|
44
44
|
['296TI', '296TII'],
|
|
45
45
|
);
|
|
46
46
|
});
|
|
@@ -48,7 +48,7 @@ describe('BundleGraph', () => {
|
|
|
48
48
|
|
|
49
49
|
function getAssets(bundleGraph) {
|
|
50
50
|
let assets = [];
|
|
51
|
-
bundleGraph.traverse(node => {
|
|
51
|
+
bundleGraph.traverse((node) => {
|
|
52
52
|
if (node.type === 'asset') {
|
|
53
53
|
assets.push(node.value);
|
|
54
54
|
}
|
package/test/Dependency.test.js
CHANGED
|
@@ -17,5 +17,33 @@ describe('Dependency', () => {
|
|
|
17
17
|
});
|
|
18
18
|
expect(id1).toEqual(id2);
|
|
19
19
|
});
|
|
20
|
+
|
|
21
|
+
it('dependencies with different targets should have different IDs', () => {
|
|
22
|
+
let id1 = createDependencyId({
|
|
23
|
+
specifier: 'foo',
|
|
24
|
+
env: createEnvironment(),
|
|
25
|
+
specifierType: 'esm',
|
|
26
|
+
target: {
|
|
27
|
+
name: 'test-1234',
|
|
28
|
+
distDir: 'dist-dir',
|
|
29
|
+
env: createEnvironment(),
|
|
30
|
+
publicUrl: 'public-url',
|
|
31
|
+
source: '1234',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
let id2 = createDependencyId({
|
|
35
|
+
specifier: 'foo',
|
|
36
|
+
env: createEnvironment(),
|
|
37
|
+
specifierType: 'esm',
|
|
38
|
+
target: {
|
|
39
|
+
name: 'test-1234',
|
|
40
|
+
distDir: 'dist-dir',
|
|
41
|
+
env: createEnvironment(),
|
|
42
|
+
publicUrl: 'public-url',
|
|
43
|
+
source: '5678', // <- this is different
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
expect(id1).not.toEqual(id2);
|
|
47
|
+
});
|
|
20
48
|
});
|
|
21
49
|
});
|
|
@@ -38,7 +38,7 @@ describe('PublicMutableBundleGraph', () => {
|
|
|
38
38
|
DEFAULT_OPTIONS,
|
|
39
39
|
);
|
|
40
40
|
|
|
41
|
-
mutableBundleGraph.traverse(node => {
|
|
41
|
+
mutableBundleGraph.traverse((node) => {
|
|
42
42
|
if (
|
|
43
43
|
node.type === 'dependency' &&
|
|
44
44
|
mutableBundleGraph.getResolvedAsset(node.value)
|
|
@@ -59,7 +59,7 @@ describe('PublicMutableBundleGraph', () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
assert.deepEqual(
|
|
62
|
-
internalBundleGraph.getBundles().map(b => b.publicId),
|
|
62
|
+
internalBundleGraph.getBundles().map((b) => b.publicId),
|
|
63
63
|
['8LVYC', 'd7Pd5'],
|
|
64
64
|
);
|
|
65
65
|
});
|
|
@@ -15,7 +15,7 @@ import {toProjectPath} from '../src/projectPath';
|
|
|
15
15
|
import {DEFAULT_FEATURE_FLAGS, setFeatureFlags} from '../../feature-flags/src';
|
|
16
16
|
|
|
17
17
|
const options = DEFAULT_OPTIONS;
|
|
18
|
-
const farm = new WorkerFarm({workerPath: require.resolve('../src/worker
|
|
18
|
+
const farm = new WorkerFarm({workerPath: require.resolve('../src/worker')});
|
|
19
19
|
|
|
20
20
|
describe('RequestTracker', () => {
|
|
21
21
|
it('should not run requests that have not been invalidated', async () => {
|
|
@@ -84,7 +84,7 @@ describe('RequestTracker', () => {
|
|
|
84
84
|
assert(
|
|
85
85
|
tracker
|
|
86
86
|
.getInvalidRequests()
|
|
87
|
-
.map(req => req.id)
|
|
87
|
+
.map((req) => req.id)
|
|
88
88
|
.includes('abc'),
|
|
89
89
|
);
|
|
90
90
|
});
|
|
@@ -107,7 +107,7 @@ describe('RequestTracker', () => {
|
|
|
107
107
|
assert(
|
|
108
108
|
tracker
|
|
109
109
|
.getInvalidRequests()
|
|
110
|
-
.map(req => req.id)
|
|
110
|
+
.map((req) => req.id)
|
|
111
111
|
.includes('abc'),
|
|
112
112
|
);
|
|
113
113
|
});
|
|
@@ -186,7 +186,7 @@ describe('RequestTracker', () => {
|
|
|
186
186
|
assert(
|
|
187
187
|
tracker
|
|
188
188
|
.getInvalidRequests()
|
|
189
|
-
.map(req => req.id)
|
|
189
|
+
.map((req) => req.id)
|
|
190
190
|
.includes('abc'),
|
|
191
191
|
);
|
|
192
192
|
});
|
|
@@ -453,7 +453,7 @@ describe('RequestTracker', () => {
|
|
|
453
453
|
});
|
|
454
454
|
|
|
455
455
|
describe('respondToFSEvents', () => {
|
|
456
|
-
[true, false].forEach(value => {
|
|
456
|
+
[true, false].forEach((value) => {
|
|
457
457
|
beforeEach(() => {
|
|
458
458
|
setFeatureFlags({
|
|
459
459
|
...DEFAULT_FEATURE_FLAGS,
|
|
@@ -562,7 +562,8 @@ root --- node1 --- node2 ----------- orphan1 --- orphan2
|
|
|
562
562
|
|
|
563
563
|
*/
|
|
564
564
|
|
|
565
|
-
const getNonNullNodes = graph =>
|
|
565
|
+
const getNonNullNodes = (graph) =>
|
|
566
|
+
graph.nodes.filter((node) => node != null);
|
|
566
567
|
|
|
567
568
|
graph.addEdge(root, node1);
|
|
568
569
|
graph.addEdge(node1, node2);
|
|
@@ -191,14 +191,14 @@ function assertUsedSymbols(
|
|
|
191
191
|
_expectedDependency.map(([from, to, sym]) => [
|
|
192
192
|
from + ':' + to,
|
|
193
193
|
// $FlowFixMe[invalid-tuple-index]
|
|
194
|
-
sym ? sym.map(v => [v[0], v[1] ?? [to, v[0]]]) : sym,
|
|
194
|
+
sym ? sym.map((v) => [v[0], v[1] ?? [to, v[0]]]) : sym,
|
|
195
195
|
]),
|
|
196
196
|
);
|
|
197
197
|
|
|
198
198
|
if (isLibrary) {
|
|
199
199
|
let entryDep = nullthrows(
|
|
200
200
|
[...graph.nodes.values()].find(
|
|
201
|
-
n => n?.type === 'dependency' && n.value.sourceAssetId == null,
|
|
201
|
+
(n) => n?.type === 'dependency' && n.value.sourceAssetId == null,
|
|
202
202
|
),
|
|
203
203
|
);
|
|
204
204
|
invariant(entryDep.type === 'dependency');
|
|
@@ -374,13 +374,13 @@ function changeDependency(
|
|
|
374
374
|
): Iterable<[ContentKey, Asset]> {
|
|
375
375
|
let sourceAssetNode = nullthrowsAssetNode(
|
|
376
376
|
[...graph.nodes.values()].find(
|
|
377
|
-
n => n?.type === 'asset' && n.value.filePath === from,
|
|
377
|
+
(n) => n?.type === 'asset' && n.value.filePath === from,
|
|
378
378
|
),
|
|
379
379
|
);
|
|
380
380
|
sourceAssetNode.usedSymbolsDownDirty = true;
|
|
381
381
|
let depNode = nullthrowsDependencyNode(
|
|
382
382
|
[...graph.nodes.values()].find(
|
|
383
|
-
n =>
|
|
383
|
+
(n) =>
|
|
384
384
|
n?.type === 'dependency' &&
|
|
385
385
|
n.value.sourcePath === from &&
|
|
386
386
|
n.value.specifier === to,
|
|
@@ -397,7 +397,7 @@ function changeAsset(
|
|
|
397
397
|
): Iterable<[ContentKey, Asset]> {
|
|
398
398
|
let node = nullthrowsAssetNode(
|
|
399
399
|
[...graph.nodes.values()].find(
|
|
400
|
-
n => n?.type === 'asset' && n.value.filePath === asset,
|
|
400
|
+
(n) => n?.type === 'asset' && n.value.filePath === asset,
|
|
401
401
|
),
|
|
402
402
|
);
|
|
403
403
|
node.usedSymbolsUpDirty = true;
|
|
@@ -440,7 +440,7 @@ describe('SymbolPropagation', () => {
|
|
|
440
440
|
);
|
|
441
441
|
|
|
442
442
|
let changedAssets = [
|
|
443
|
-
...changeDependency(graph, 'index.js', '/lib.js', symbols => {
|
|
443
|
+
...changeDependency(graph, 'index.js', '/lib.js', (symbols) => {
|
|
444
444
|
symbols.set('b', {
|
|
445
445
|
local: 'b',
|
|
446
446
|
isWeak: false,
|
|
@@ -480,7 +480,7 @@ describe('SymbolPropagation', () => {
|
|
|
480
480
|
);
|
|
481
481
|
|
|
482
482
|
let changedAssets = [
|
|
483
|
-
...changeDependency(graph, 'index.js', '/lib.js', symbols => {
|
|
483
|
+
...changeDependency(graph, 'index.js', '/lib.js', (symbols) => {
|
|
484
484
|
symbols.delete('f');
|
|
485
485
|
symbols.set('f2', {
|
|
486
486
|
local: 'f2',
|
|
@@ -523,7 +523,7 @@ describe('SymbolPropagation', () => {
|
|
|
523
523
|
);
|
|
524
524
|
|
|
525
525
|
let changedAssets = [
|
|
526
|
-
...changeAsset(graph, 'lib.js', symbols => {
|
|
526
|
+
...changeAsset(graph, 'lib.js', (symbols) => {
|
|
527
527
|
symbols.delete('f');
|
|
528
528
|
symbols.set('f2', {
|
|
529
529
|
local: 'f2',
|
|
@@ -570,7 +570,7 @@ describe('SymbolPropagation', () => {
|
|
|
570
570
|
);
|
|
571
571
|
|
|
572
572
|
let changedAssets = [
|
|
573
|
-
...changeDependency(graph, 'index.js', '/lib.js', symbols => {
|
|
573
|
+
...changeDependency(graph, 'index.js', '/lib.js', (symbols) => {
|
|
574
574
|
symbols.set('b', {
|
|
575
575
|
local: 'b',
|
|
576
576
|
isWeak: false,
|
|
@@ -21,7 +21,7 @@ const mockCast = (f: any): any => f;
|
|
|
21
21
|
describe('ConfigRequest tests', () => {
|
|
22
22
|
const projectRoot = 'project_root';
|
|
23
23
|
const farm = new WorkerFarm({
|
|
24
|
-
workerPath: require.resolve('../../src/worker
|
|
24
|
+
workerPath: require.resolve('../../src/worker'),
|
|
25
25
|
maxConcurrentWorkers: 1,
|
|
26
26
|
});
|
|
27
27
|
let fs = new MemoryFS(farm);
|
|
@@ -48,7 +48,7 @@ describe('ConfigRequest tests', () => {
|
|
|
48
48
|
invalidateOnFileUpdate: sinon.spy(),
|
|
49
49
|
invalidateOnOptionChange: sinon.spy(),
|
|
50
50
|
invalidateOnStartup: sinon.spy(),
|
|
51
|
-
runRequest: sinon.spy(request => {
|
|
51
|
+
runRequest: sinon.spy((request) => {
|
|
52
52
|
return request.run({
|
|
53
53
|
api: mockRunApi,
|
|
54
54
|
options,
|
|
@@ -229,10 +229,7 @@ describe('ConfigRequest tests', () => {
|
|
|
229
229
|
invalidateOnConfigKeyChange: [
|
|
230
230
|
{
|
|
231
231
|
configKey: 'key1',
|
|
232
|
-
filePath: toProjectPath(
|
|
233
|
-
projectRoot,
|
|
234
|
-
path.join('project_root', 'config.json'),
|
|
235
|
-
),
|
|
232
|
+
filePath: toProjectPath(projectRoot, 'config.json'),
|
|
236
233
|
},
|
|
237
234
|
],
|
|
238
235
|
});
|
package/test/utils.test.js
CHANGED
|
@@ -28,7 +28,7 @@ describe('getPublicId', () => {
|
|
|
28
28
|
|
|
29
29
|
it('uses more characters if there is a collision', () => {
|
|
30
30
|
assert.equal(
|
|
31
|
-
getPublicId(id, publicId =>
|
|
31
|
+
getPublicId(id, (publicId) =>
|
|
32
32
|
[fullPublicId.slice(0, 5), fullPublicId.slice(0, 6)].includes(publicId),
|
|
33
33
|
),
|
|
34
34
|
fullPublicId.slice(0, 7),
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AssetCompat = void 0;
|
|
7
|
-
var _Environment = _interopRequireDefault(require("../../public/Environment"));
|
|
8
|
-
var _types = require("../../types");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
class AssetCompat {
|
|
11
|
-
// TODO: Type properly
|
|
12
|
-
|
|
13
|
-
constructor(_inner, options) {
|
|
14
|
-
this._inner = _inner;
|
|
15
|
-
// $FlowFixMe This isn't correct to flow but is enough to satisfy the runtime checks
|
|
16
|
-
this.env = new _Environment.default(_inner.env, options);
|
|
17
|
-
this._dependencies = [];
|
|
18
|
-
}
|
|
19
|
-
get id() {
|
|
20
|
-
return this._inner.id;
|
|
21
|
-
}
|
|
22
|
-
get filePath() {
|
|
23
|
-
return this._inner.filePath;
|
|
24
|
-
}
|
|
25
|
-
get type() {
|
|
26
|
-
return this._inner.type;
|
|
27
|
-
}
|
|
28
|
-
set type(value) {
|
|
29
|
-
this._inner.type = value;
|
|
30
|
-
}
|
|
31
|
-
get bundleBehavior() {
|
|
32
|
-
let bundleBehavior = this._inner.bundleBehavior;
|
|
33
|
-
return bundleBehavior == null ? null : _types.BundleBehaviorNames[bundleBehavior];
|
|
34
|
-
}
|
|
35
|
-
set bundleBehavior(bundleBehavior) {
|
|
36
|
-
this._inner.bundleBehavior = bundleBehavior ? _types.BundleBehavior[bundleBehavior] : null;
|
|
37
|
-
}
|
|
38
|
-
getCode() {
|
|
39
|
-
return Buffer.from(this._inner.code).toString();
|
|
40
|
-
}
|
|
41
|
-
setCode(code) {
|
|
42
|
-
this._inner.code = Array.from(new TextEncoder().encode(code));
|
|
43
|
-
}
|
|
44
|
-
getAST() {
|
|
45
|
-
return this._ast;
|
|
46
|
-
}
|
|
47
|
-
setAST(ast) {
|
|
48
|
-
this._ast = ast;
|
|
49
|
-
}
|
|
50
|
-
addDependency() {
|
|
51
|
-
throw new Error('[V3] Unimplemented: Asset.addDependency not yet implemented');
|
|
52
|
-
}
|
|
53
|
-
addURLDependency() {
|
|
54
|
-
throw new Error('[V3] Unimplemented: Asset.addURLDependency not yet implemented');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.AssetCompat = AssetCompat;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import type {PluginOptions, BundleBehavior, AST} from '@atlaspack/types';
|
|
3
|
-
|
|
4
|
-
import Environment from '../../public/Environment';
|
|
5
|
-
import {
|
|
6
|
-
BundleBehaviorNames,
|
|
7
|
-
BundleBehavior as BundleBehaviorMap,
|
|
8
|
-
} from '../../types';
|
|
9
|
-
|
|
10
|
-
export type InnerAsset = {|
|
|
11
|
-
id: string,
|
|
12
|
-
filePath: string,
|
|
13
|
-
code: Array<number>,
|
|
14
|
-
type: string,
|
|
15
|
-
bundleBehavior: number | null,
|
|
16
|
-
env: any,
|
|
17
|
-
|};
|
|
18
|
-
|
|
19
|
-
export class AssetCompat {
|
|
20
|
-
_inner: InnerAsset;
|
|
21
|
-
_ast: ?AST;
|
|
22
|
-
// TODO: Type properly
|
|
23
|
-
_dependencies: Array<any>;
|
|
24
|
-
|
|
25
|
-
constructor(_inner: InnerAsset, options: PluginOptions) {
|
|
26
|
-
this._inner = _inner;
|
|
27
|
-
// $FlowFixMe This isn't correct to flow but is enough to satisfy the runtime checks
|
|
28
|
-
this.env = new Environment(_inner.env, options);
|
|
29
|
-
this._dependencies = [];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get id(): string {
|
|
33
|
-
return this._inner.id;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get filePath(): string {
|
|
37
|
-
return this._inner.filePath;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get type(): string {
|
|
41
|
-
return this._inner.type;
|
|
42
|
-
}
|
|
43
|
-
set type(value: string) {
|
|
44
|
-
this._inner.type = value;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get bundleBehavior(): ?BundleBehavior {
|
|
48
|
-
let bundleBehavior = this._inner.bundleBehavior;
|
|
49
|
-
return bundleBehavior == null ? null : BundleBehaviorNames[bundleBehavior];
|
|
50
|
-
}
|
|
51
|
-
set bundleBehavior(bundleBehavior: ?BundleBehavior): void {
|
|
52
|
-
this._inner.bundleBehavior = bundleBehavior
|
|
53
|
-
? BundleBehaviorMap[bundleBehavior]
|
|
54
|
-
: null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
getCode(): string {
|
|
58
|
-
return Buffer.from(this._inner.code).toString();
|
|
59
|
-
}
|
|
60
|
-
setCode(code: string) {
|
|
61
|
-
this._inner.code = Array.from(new TextEncoder().encode(code));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getAST(): ?AST {
|
|
65
|
-
return this._ast;
|
|
66
|
-
}
|
|
67
|
-
setAST(ast: AST) {
|
|
68
|
-
this._ast = ast;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
addDependency(): string {
|
|
72
|
-
throw new Error(
|
|
73
|
-
'[V3] Unimplemented: Asset.addDependency not yet implemented',
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
addURLDependency(): string {
|
|
78
|
-
throw new Error(
|
|
79
|
-
'[V3] Unimplemented: Asset.addURLDependency not yet implemented',
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
|
-
import {replaceStream} from '../../src/requests/WriteBundleRequest';
|
|
4
|
-
import {Writable, pipeline} from 'stream';
|
|
5
|
-
import {replaceHashReferences} from '@atlaspack/rust';
|
|
6
|
-
import assert from 'assert';
|
|
7
|
-
import {blobToStream} from '@atlaspack/utils';
|
|
8
|
-
|
|
9
|
-
class BufferWritable extends Writable {
|
|
10
|
-
buffers: Buffer[];
|
|
11
|
-
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
this.buffers = [];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getBuffer(): Buffer {
|
|
18
|
-
return Buffer.concat(this.buffers);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_write(chunk: string | Buffer, encoding: string, callback) {
|
|
22
|
-
let buffer =
|
|
23
|
-
typeof chunk === 'string'
|
|
24
|
-
? // $FlowFixMe
|
|
25
|
-
Buffer.from(chunk, encoding)
|
|
26
|
-
: chunk;
|
|
27
|
-
this.buffers.push(buffer);
|
|
28
|
-
callback();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function generateSampleInput(
|
|
33
|
-
hashReferences: Map<string, string>,
|
|
34
|
-
inputSize: number,
|
|
35
|
-
): Buffe {
|
|
36
|
-
let output = '';
|
|
37
|
-
|
|
38
|
-
while (output.length < inputSize) {
|
|
39
|
-
if (Math.random() < 0.1) {
|
|
40
|
-
output += 'HASH_REF_1234567890123456';
|
|
41
|
-
} else {
|
|
42
|
-
for (let i = 0; i < 16; i++) {
|
|
43
|
-
output += String.fromCharCode(97 + Math.floor(Math.random() * 26));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return Buffer.from(output);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function javascriptReplaceHashReferences(
|
|
52
|
-
buffer: Buffer,
|
|
53
|
-
hashReferences: Map<string, string>,
|
|
54
|
-
): Promise<Buffer> {
|
|
55
|
-
const writable = new BufferWritable();
|
|
56
|
-
const transform = replaceStream(hashReferences);
|
|
57
|
-
|
|
58
|
-
await new Promise((resolve, reject) => {
|
|
59
|
-
pipeline(blobToStream(buffer), transform, writable, err => {
|
|
60
|
-
if (err) reject(err);
|
|
61
|
-
else resolve(null);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const output = writable.getBuffer();
|
|
66
|
-
return output;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
describe.only('replaceStream', () => {
|
|
70
|
-
const hashReferences = new Map([
|
|
71
|
-
['HASH_REF_1234567890123456', 'HASH_REF_replacedwithstri'],
|
|
72
|
-
]);
|
|
73
|
-
const buffer = Buffer.from(
|
|
74
|
-
'Hello HASH_REF_1234567890123456 more stuff here HASH_REF_1234567890123456',
|
|
75
|
-
);
|
|
76
|
-
const expectedOutput =
|
|
77
|
-
'Hello HASH_REF_replacedwithstri more stuff here HASH_REF_replacedwithstri';
|
|
78
|
-
|
|
79
|
-
it('javascript - replaces hash references in buffers', async () => {
|
|
80
|
-
const output = await javascriptReplaceHashReferences(
|
|
81
|
-
buffer,
|
|
82
|
-
hashReferences,
|
|
83
|
-
);
|
|
84
|
-
const outputString = output.toString();
|
|
85
|
-
assert.equal(outputString, expectedOutput);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('rust - replaces hash references in buffers', () => {
|
|
89
|
-
const output = replaceHashReferences(
|
|
90
|
-
buffer,
|
|
91
|
-
Object.fromEntries(hashReferences.entries()),
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const outputString = output.toString();
|
|
95
|
-
assert.equal(outputString, expectedOutput);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
let currentInputSize = 1024 * 1024; // Start at 1MB and grow to 40MB
|
|
99
|
-
const inputSizes = [];
|
|
100
|
-
while (currentInputSize < 40 * 1024 * 1024) {
|
|
101
|
-
inputSizes.push(currentInputSize);
|
|
102
|
-
currentInputSize *= 2;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
inputSizes.forEach(inputSize => {
|
|
106
|
-
describe('input size ' + inputSize / 1024 / 1024 + 'MB', () => {
|
|
107
|
-
const buffer = generateSampleInput(hashReferences, inputSize);
|
|
108
|
-
const expectedOutput = buffer
|
|
109
|
-
.toString()
|
|
110
|
-
.replace(/HASH_REF_1234567890123456/g, 'HASH_REF_replacedwithstri');
|
|
111
|
-
|
|
112
|
-
it('javascript - works on huge buffer', async () => {
|
|
113
|
-
const output = await javascriptReplaceHashReferences(
|
|
114
|
-
buffer,
|
|
115
|
-
hashReferences,
|
|
116
|
-
);
|
|
117
|
-
const outputString = output.toString();
|
|
118
|
-
assert.equal(outputString, expectedOutput);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('rust - works on huge buffer', () => {
|
|
122
|
-
const output = replaceHashReferences(
|
|
123
|
-
buffer,
|
|
124
|
-
Object.fromEntries(hashReferences.entries()),
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const outputString = output.toString();
|
|
128
|
-
assert.equal(outputString, expectedOutput);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|