@atlaspack/core 2.12.1-dev.3401 → 2.12.1-dev.3443
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AssetGraph.js +1 -2
- package/lib/Atlaspack.js +25 -3
- package/lib/AtlaspackConfig.schema.js +10 -36
- package/lib/BundleGraph.js +59 -5
- package/lib/Dependency.js +46 -1
- package/lib/Environment.js +12 -2
- package/lib/PackagerRunner.js +3 -45
- package/lib/RequestTracker.js +112 -30
- package/lib/SymbolPropagation.js +1 -1
- package/lib/Transformation.js +1 -15
- package/lib/UncommittedAsset.js +4 -4
- package/lib/Validation.js +1 -13
- package/lib/applyRuntimes.js +96 -20
- package/lib/assetUtils.js +9 -3
- package/lib/atlaspack-v3/AtlaspackV3.js +6 -8
- package/lib/atlaspack-v3/fs.js +8 -1
- package/lib/atlaspack-v3/worker/compat.js +57 -0
- package/lib/atlaspack-v3/worker/worker.js +156 -1
- package/lib/public/BundleGraph.js +68 -0
- package/lib/requests/AssetGraphRequestRust.js +79 -12
- package/lib/requests/BundleGraphRequest.js +19 -0
- package/lib/requests/WriteBundleRequest.js +15 -15
- package/lib/requests/asset-graph-diff.js +128 -0
- package/lib/resolveOptions.js +15 -8
- package/lib/types.js +2 -1
- package/package.json +19 -17
- package/src/AssetGraph.js +1 -1
- package/src/Atlaspack.js +28 -6
- package/src/AtlaspackConfig.schema.js +13 -36
- package/src/BundleGraph.js +77 -1
- package/src/CommittedAsset.js +1 -1
- package/src/Dependency.js +50 -12
- package/src/Environment.js +13 -15
- package/src/PackagerRunner.js +5 -53
- package/src/RequestTracker.js +144 -38
- package/src/SymbolPropagation.js +5 -2
- package/src/Transformation.js +1 -9
- package/src/UncommittedAsset.js +6 -6
- package/src/Validation.js +1 -7
- package/src/applyRuntimes.js +86 -22
- package/src/assetUtils.js +12 -19
- package/src/atlaspack-v3/AtlaspackV3.js +8 -11
- package/src/atlaspack-v3/fs.js +8 -3
- package/src/atlaspack-v3/jsCallable.js +4 -0
- package/src/atlaspack-v3/worker/compat.js +82 -0
- package/src/atlaspack-v3/worker/worker.js +209 -2
- package/src/public/BundleGraph.js +106 -0
- package/src/requests/AssetGraphRequestRust.js +105 -17
- package/src/requests/BundleGraphRequest.js +18 -0
- package/src/requests/WriteBundleRequest.js +17 -23
- package/src/requests/asset-graph-diff.js +145 -0
- package/src/resolveOptions.js +12 -2
- package/src/types.js +10 -0
- package/test/AssetGraph.test.js +23 -9
- package/test/AtlaspackConfigRequest.test.js +0 -161
- package/test/BundleGraph.test.js +8 -3
- package/test/Dependency.test.js +21 -0
- package/test/Environment.test.js +16 -5
- package/test/InternalAsset.test.js +8 -2
- package/test/PublicAsset.test.js +6 -2
- package/test/PublicBundle.test.js +1 -0
- package/test/PublicMutableBundleGraph.test.js +9 -4
- package/test/RequestTracker.test.js +139 -2
- package/test/SymbolPropagation.test.js +1 -0
- package/test/TargetRequest.test.js +25 -25
- package/test/requests/WriteBundleRequest.test.js +132 -0
- package/lib/atlaspack-v3/plugins/Resolver.js +0 -12
- package/lib/atlaspack-v3/plugins/index.js +0 -16
- package/src/atlaspack-v3/plugins/Resolver.js +0 -9
- package/src/atlaspack-v3/plugins/index.js +0 -3
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
import assert from 'assert';
|
|
4
4
|
import nullthrows from 'nullthrows';
|
|
5
|
-
import RequestTracker, {
|
|
5
|
+
import RequestTracker, {
|
|
6
|
+
type RunAPI,
|
|
7
|
+
cleanUpOrphans,
|
|
8
|
+
} from '../src/RequestTracker';
|
|
9
|
+
import {Graph} from '@atlaspack/graph';
|
|
6
10
|
import WorkerFarm from '@atlaspack/workers';
|
|
7
11
|
import {DEFAULT_OPTIONS} from './test-utils';
|
|
8
|
-
import {INITIAL_BUILD} from '../src/constants';
|
|
12
|
+
import {FILE_CREATE, FILE_UPDATE, INITIAL_BUILD} from '../src/constants';
|
|
9
13
|
import {makeDeferredWithPromise} from '@atlaspack/utils';
|
|
14
|
+
import {toProjectPath} from '../src/projectPath';
|
|
15
|
+
import {DEFAULT_FEATURE_FLAGS, setFeatureFlags} from '../../feature-flags/src';
|
|
10
16
|
|
|
11
17
|
const options = DEFAULT_OPTIONS;
|
|
12
18
|
const farm = new WorkerFarm({workerPath: require.resolve('../src/worker.js')});
|
|
@@ -445,4 +451,135 @@ describe('RequestTracker', () => {
|
|
|
445
451
|
|
|
446
452
|
assert.equal(tracker.graph.getNode(nodeId)?.invalidateReason, 1);
|
|
447
453
|
});
|
|
454
|
+
|
|
455
|
+
describe('respondToFSEvents', () => {
|
|
456
|
+
[true, false].forEach(value => {
|
|
457
|
+
beforeEach(() => {
|
|
458
|
+
setFeatureFlags({
|
|
459
|
+
...DEFAULT_FEATURE_FLAGS,
|
|
460
|
+
fixQuadraticCacheInvalidation: value === true ? 'NEW' : 'OLD',
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
afterEach(() => {
|
|
465
|
+
setFeatureFlags({
|
|
466
|
+
...DEFAULT_FEATURE_FLAGS,
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
describe(`optimizations feature-flag ${String(value)}`, () => {
|
|
471
|
+
it('should invalidate file requests on file changes', async () => {
|
|
472
|
+
let tracker = new RequestTracker({farm, options});
|
|
473
|
+
await tracker.runRequest({
|
|
474
|
+
id: 'abc',
|
|
475
|
+
type: 7,
|
|
476
|
+
// $FlowFixMe string isn't a valid result
|
|
477
|
+
run: async ({api}: {api: RunAPI<string | void>, ...}) => {
|
|
478
|
+
api.invalidateOnFileUpdate(toProjectPath('', 'my-file'));
|
|
479
|
+
let result = await Promise.resolve('hello');
|
|
480
|
+
api.storeResult(result);
|
|
481
|
+
},
|
|
482
|
+
input: null,
|
|
483
|
+
});
|
|
484
|
+
const requestId = tracker.graph.getNodeIdByContentKey('abc');
|
|
485
|
+
const invalidated = await tracker.respondToFSEvents(
|
|
486
|
+
[
|
|
487
|
+
{
|
|
488
|
+
type: 'update',
|
|
489
|
+
path: 'my-file',
|
|
490
|
+
},
|
|
491
|
+
],
|
|
492
|
+
Number.MAX_VALUE,
|
|
493
|
+
);
|
|
494
|
+
assert.equal(invalidated, true);
|
|
495
|
+
assert.equal(
|
|
496
|
+
tracker.graph.getNode(requestId)?.invalidateReason,
|
|
497
|
+
FILE_UPDATE,
|
|
498
|
+
);
|
|
499
|
+
assert.deepEqual(Array.from(tracker.graph.invalidNodeIds), [
|
|
500
|
+
requestId,
|
|
501
|
+
]);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('should invalidate file name requests with invalidate above invalidations', async () => {
|
|
505
|
+
let tracker = new RequestTracker({farm, options});
|
|
506
|
+
await tracker.runRequest({
|
|
507
|
+
id: 'abc',
|
|
508
|
+
type: 7,
|
|
509
|
+
// $FlowFixMe string isn't a valid result
|
|
510
|
+
run: async ({api}: {api: RunAPI<string | void>, ...}) => {
|
|
511
|
+
api.invalidateOnFileCreate({
|
|
512
|
+
fileName: 'package.json',
|
|
513
|
+
aboveFilePath: toProjectPath(
|
|
514
|
+
'',
|
|
515
|
+
'./node_modules/something/package.json',
|
|
516
|
+
),
|
|
517
|
+
});
|
|
518
|
+
let result = await Promise.resolve('hello');
|
|
519
|
+
api.storeResult(result);
|
|
520
|
+
},
|
|
521
|
+
input: null,
|
|
522
|
+
});
|
|
523
|
+
const requestId = tracker.graph.getNodeIdByContentKey('abc');
|
|
524
|
+
const invalidated = await tracker.respondToFSEvents(
|
|
525
|
+
[
|
|
526
|
+
{
|
|
527
|
+
type: 'create',
|
|
528
|
+
path: './package.json',
|
|
529
|
+
},
|
|
530
|
+
],
|
|
531
|
+
Number.MAX_VALUE,
|
|
532
|
+
);
|
|
533
|
+
assert.equal(invalidated, true);
|
|
534
|
+
assert.equal(
|
|
535
|
+
tracker.graph.getNode(requestId)?.invalidateReason,
|
|
536
|
+
FILE_CREATE,
|
|
537
|
+
);
|
|
538
|
+
assert.deepEqual(Array.from(tracker.graph.invalidNodeIds), [
|
|
539
|
+
requestId,
|
|
540
|
+
]);
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
describe('cleanUpOrphans', () => {
|
|
548
|
+
it('cleans-up unreachable nodes', () => {
|
|
549
|
+
const graph: Graph<string, number> = new Graph();
|
|
550
|
+
const root = graph.addNode('root');
|
|
551
|
+
graph.setRootNodeId(root);
|
|
552
|
+
const node1 = graph.addNode('node1');
|
|
553
|
+
const node2 = graph.addNode('node2');
|
|
554
|
+
const node3 = graph.addNode('node3');
|
|
555
|
+
const orphan1 = graph.addNode('orphan1');
|
|
556
|
+
const orphan2 = graph.addNode('orphan2');
|
|
557
|
+
|
|
558
|
+
/*
|
|
559
|
+
|
|
560
|
+
root --- node1 --- node2 ----------- orphan1 --- orphan2
|
|
561
|
+
\---- node3 (^ remove)
|
|
562
|
+
|
|
563
|
+
*/
|
|
564
|
+
|
|
565
|
+
const getNonNullNodes = graph => graph.nodes.filter(node => node != null);
|
|
566
|
+
|
|
567
|
+
graph.addEdge(root, node1);
|
|
568
|
+
graph.addEdge(node1, node2);
|
|
569
|
+
graph.addEdge(node2, orphan1);
|
|
570
|
+
graph.addEdge(orphan1, orphan2);
|
|
571
|
+
graph.addEdge(root, node3);
|
|
572
|
+
|
|
573
|
+
assert.deepEqual(cleanUpOrphans(graph), []);
|
|
574
|
+
assert.equal(getNonNullNodes(graph).length, 6);
|
|
575
|
+
assert.equal(Array.from(graph.getAllEdges()).length, 5);
|
|
576
|
+
|
|
577
|
+
graph.removeEdge(node2, orphan1, 1, false);
|
|
578
|
+
assert.equal(getNonNullNodes(graph).length, 6);
|
|
579
|
+
assert.equal(Array.from(graph.getAllEdges()).length, 4);
|
|
580
|
+
|
|
581
|
+
assert.deepEqual(cleanUpOrphans(graph), [orphan1, orphan2]);
|
|
582
|
+
assert.equal(getNonNullNodes(graph).length, 4);
|
|
583
|
+
assert.equal(Array.from(graph.getAllEdges()).length, 3);
|
|
584
|
+
});
|
|
448
585
|
});
|
|
@@ -125,7 +125,7 @@ describe('TargetResolver', () => {
|
|
|
125
125
|
publicUrl: '/',
|
|
126
126
|
distDir: normalizeSeparators(path.resolve('customA')),
|
|
127
127
|
env: {
|
|
128
|
-
id: '
|
|
128
|
+
id: 'd821e85f6b50315e',
|
|
129
129
|
context: 'browser',
|
|
130
130
|
includeNodeModules: true,
|
|
131
131
|
engines: {
|
|
@@ -146,7 +146,7 @@ describe('TargetResolver', () => {
|
|
|
146
146
|
distEntry: 'b.js',
|
|
147
147
|
distDir: normalizeSeparators(path.resolve('customB')),
|
|
148
148
|
env: {
|
|
149
|
-
id: '
|
|
149
|
+
id: 'e45cc12216f7857d',
|
|
150
150
|
context: 'node',
|
|
151
151
|
includeNodeModules: false,
|
|
152
152
|
engines: {
|
|
@@ -177,7 +177,7 @@ describe('TargetResolver', () => {
|
|
|
177
177
|
distEntry: 'index.js',
|
|
178
178
|
publicUrl: '/',
|
|
179
179
|
env: {
|
|
180
|
-
id: '
|
|
180
|
+
id: 'f628a18b9d37974c',
|
|
181
181
|
context: 'node',
|
|
182
182
|
engines: {
|
|
183
183
|
node: '>= 8.0.0',
|
|
@@ -211,7 +211,7 @@ describe('TargetResolver', () => {
|
|
|
211
211
|
distEntry: 'index.js',
|
|
212
212
|
publicUrl: '/',
|
|
213
213
|
env: {
|
|
214
|
-
id: '
|
|
214
|
+
id: 'f9afb61b20ba7ecf',
|
|
215
215
|
context: 'browser',
|
|
216
216
|
engines: {
|
|
217
217
|
browsers: ['last 1 version'],
|
|
@@ -247,7 +247,7 @@ describe('TargetResolver', () => {
|
|
|
247
247
|
distEntry: 'index.js',
|
|
248
248
|
publicUrl: '/assets',
|
|
249
249
|
env: {
|
|
250
|
-
id: '
|
|
250
|
+
id: '7c0fe07c8a3a38da',
|
|
251
251
|
context: 'browser',
|
|
252
252
|
engines: {
|
|
253
253
|
browsers: ['last 1 version'],
|
|
@@ -293,7 +293,7 @@ describe('TargetResolver', () => {
|
|
|
293
293
|
distEntry: 'index.js',
|
|
294
294
|
publicUrl: '/',
|
|
295
295
|
env: {
|
|
296
|
-
id: '
|
|
296
|
+
id: 'e45cc12216f7857d',
|
|
297
297
|
context: 'node',
|
|
298
298
|
engines: {
|
|
299
299
|
node: '>= 8.0.0',
|
|
@@ -336,7 +336,7 @@ describe('TargetResolver', () => {
|
|
|
336
336
|
distEntry: 'index.js',
|
|
337
337
|
publicUrl: '/',
|
|
338
338
|
env: {
|
|
339
|
-
id: '
|
|
339
|
+
id: 'f628a18b9d37974c',
|
|
340
340
|
context: 'node',
|
|
341
341
|
engines: {
|
|
342
342
|
node: '>= 8.0.0',
|
|
@@ -370,7 +370,7 @@ describe('TargetResolver', () => {
|
|
|
370
370
|
distEntry: 'index.js',
|
|
371
371
|
publicUrl: '/',
|
|
372
372
|
env: {
|
|
373
|
-
id: '
|
|
373
|
+
id: '75603271034eff15',
|
|
374
374
|
context: 'browser',
|
|
375
375
|
engines: {
|
|
376
376
|
browsers: ['last 1 version'],
|
|
@@ -404,7 +404,7 @@ describe('TargetResolver', () => {
|
|
|
404
404
|
distEntry: 'index.js',
|
|
405
405
|
publicUrl: '/',
|
|
406
406
|
env: {
|
|
407
|
-
id: '
|
|
407
|
+
id: 'a8f05066473f62d0',
|
|
408
408
|
context: 'browser',
|
|
409
409
|
engines: {
|
|
410
410
|
browsers: ['ie11'],
|
|
@@ -455,7 +455,7 @@ describe('TargetResolver', () => {
|
|
|
455
455
|
distEntry: 'index.js',
|
|
456
456
|
publicUrl: '/',
|
|
457
457
|
env: {
|
|
458
|
-
id: '
|
|
458
|
+
id: 'f628a18b9d37974c',
|
|
459
459
|
context: 'node',
|
|
460
460
|
engines: {
|
|
461
461
|
node: '>= 8.0.0',
|
|
@@ -489,7 +489,7 @@ describe('TargetResolver', () => {
|
|
|
489
489
|
distEntry: 'index.js',
|
|
490
490
|
publicUrl: '/',
|
|
491
491
|
env: {
|
|
492
|
-
id: '
|
|
492
|
+
id: '8a530881a691863e',
|
|
493
493
|
context: 'browser',
|
|
494
494
|
engines: {
|
|
495
495
|
browsers: ['last 1 version'],
|
|
@@ -523,7 +523,7 @@ describe('TargetResolver', () => {
|
|
|
523
523
|
distEntry: 'index.js',
|
|
524
524
|
publicUrl: '/',
|
|
525
525
|
env: {
|
|
526
|
-
id: '
|
|
526
|
+
id: '4dcd5bfb2f44e1a0',
|
|
527
527
|
context: 'browser',
|
|
528
528
|
engines: {
|
|
529
529
|
browsers: ['ie11'],
|
|
@@ -566,7 +566,7 @@ describe('TargetResolver', () => {
|
|
|
566
566
|
distEntry: undefined,
|
|
567
567
|
publicUrl: 'www',
|
|
568
568
|
env: {
|
|
569
|
-
id: '
|
|
569
|
+
id: '073545c36b2ddaab',
|
|
570
570
|
context: 'browser',
|
|
571
571
|
engines: {
|
|
572
572
|
browsers: '> 0.25%',
|
|
@@ -621,7 +621,7 @@ describe('TargetResolver', () => {
|
|
|
621
621
|
distDir: normalizeSeparators(path.resolve('customB')),
|
|
622
622
|
publicUrl: '/',
|
|
623
623
|
env: {
|
|
624
|
-
id: '
|
|
624
|
+
id: 'd821e85f6b50315e',
|
|
625
625
|
context: 'browser',
|
|
626
626
|
engines: {
|
|
627
627
|
browsers: ['> 0.25%'],
|
|
@@ -663,7 +663,7 @@ describe('TargetResolver', () => {
|
|
|
663
663
|
distDir: normalizeSeparators(path.resolve('customA')),
|
|
664
664
|
publicUrl: '/',
|
|
665
665
|
env: {
|
|
666
|
-
id: '
|
|
666
|
+
id: 'd821e85f6b50315e',
|
|
667
667
|
context: 'browser',
|
|
668
668
|
engines: {
|
|
669
669
|
browsers: ['> 0.25%'],
|
|
@@ -692,7 +692,7 @@ describe('TargetResolver', () => {
|
|
|
692
692
|
distEntry: 'index.js',
|
|
693
693
|
publicUrl: '/',
|
|
694
694
|
env: {
|
|
695
|
-
id: '
|
|
695
|
+
id: '4d60aebb4fbb9f8b',
|
|
696
696
|
context: 'node',
|
|
697
697
|
engines: {
|
|
698
698
|
browsers: [
|
|
@@ -1070,7 +1070,7 @@ describe('TargetResolver', () => {
|
|
|
1070
1070
|
distEntry: 'index.mjs',
|
|
1071
1071
|
publicUrl: '/',
|
|
1072
1072
|
env: {
|
|
1073
|
-
id: '
|
|
1073
|
+
id: 'fb14362a83d338f6',
|
|
1074
1074
|
context: 'browser',
|
|
1075
1075
|
engines: {
|
|
1076
1076
|
browsers: [
|
|
@@ -1115,7 +1115,7 @@ describe('TargetResolver', () => {
|
|
|
1115
1115
|
distEntry: 'index.js',
|
|
1116
1116
|
publicUrl: '/',
|
|
1117
1117
|
env: {
|
|
1118
|
-
id: '
|
|
1118
|
+
id: 'fb14362a83d338f6',
|
|
1119
1119
|
context: 'browser',
|
|
1120
1120
|
engines: {
|
|
1121
1121
|
browsers: [
|
|
@@ -1164,7 +1164,7 @@ describe('TargetResolver', () => {
|
|
|
1164
1164
|
distEntry: 'index.js',
|
|
1165
1165
|
publicUrl: '/',
|
|
1166
1166
|
env: {
|
|
1167
|
-
id: '
|
|
1167
|
+
id: 'f628a18b9d37974c',
|
|
1168
1168
|
context: 'node',
|
|
1169
1169
|
engines: {
|
|
1170
1170
|
node: '>= 8.0.0',
|
|
@@ -1198,7 +1198,7 @@ describe('TargetResolver', () => {
|
|
|
1198
1198
|
distEntry: 'index.js',
|
|
1199
1199
|
publicUrl: '/assets',
|
|
1200
1200
|
env: {
|
|
1201
|
-
id: '
|
|
1201
|
+
id: '7c0fe07c8a3a38da',
|
|
1202
1202
|
context: 'browser',
|
|
1203
1203
|
engines: {
|
|
1204
1204
|
browsers: ['last 1 version'],
|
|
@@ -1246,7 +1246,7 @@ describe('TargetResolver', () => {
|
|
|
1246
1246
|
distDir: serveDistDir,
|
|
1247
1247
|
publicUrl: '/',
|
|
1248
1248
|
env: {
|
|
1249
|
-
id: '
|
|
1249
|
+
id: '858b9b5a5dca37d4',
|
|
1250
1250
|
context: 'browser',
|
|
1251
1251
|
engines: {
|
|
1252
1252
|
browsers: [
|
|
@@ -1283,7 +1283,7 @@ describe('TargetResolver', () => {
|
|
|
1283
1283
|
),
|
|
1284
1284
|
publicUrl: '/',
|
|
1285
1285
|
env: {
|
|
1286
|
-
id: '
|
|
1286
|
+
id: '8f31176c88184c4f',
|
|
1287
1287
|
context: 'browser',
|
|
1288
1288
|
engines: {
|
|
1289
1289
|
browsers: ['Chrome 80'],
|
|
@@ -1316,7 +1316,7 @@ describe('TargetResolver', () => {
|
|
|
1316
1316
|
distEntry: undefined,
|
|
1317
1317
|
publicUrl: '/',
|
|
1318
1318
|
env: {
|
|
1319
|
-
id: '
|
|
1319
|
+
id: '8f31176c88184c4f',
|
|
1320
1320
|
context: 'browser',
|
|
1321
1321
|
engines: {
|
|
1322
1322
|
browsers: ['Chrome 80'],
|
|
@@ -1366,7 +1366,7 @@ describe('TargetResolver', () => {
|
|
|
1366
1366
|
distEntry: undefined,
|
|
1367
1367
|
publicUrl: '/',
|
|
1368
1368
|
env: {
|
|
1369
|
-
id: '
|
|
1369
|
+
id: '75603271034eff15',
|
|
1370
1370
|
context: 'browser',
|
|
1371
1371
|
engines: {
|
|
1372
1372
|
browsers: ['last 1 version'],
|
|
@@ -1406,7 +1406,7 @@ describe('TargetResolver', () => {
|
|
|
1406
1406
|
distEntry: undefined,
|
|
1407
1407
|
publicUrl: '/',
|
|
1408
1408
|
env: {
|
|
1409
|
-
id: '
|
|
1409
|
+
id: 'd5ff950a2c05db56',
|
|
1410
1410
|
context: 'browser',
|
|
1411
1411
|
engines: {
|
|
1412
1412
|
browsers: ['IE 11'],
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _Resolver = require("./Resolver");
|
|
7
|
-
Object.keys(_Resolver).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _Resolver[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _Resolver[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|