@teambit/dependencies 1.0.785 → 1.0.787
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/dist/files-dependency-builder/build-tree.js +1 -1
- package/dist/files-dependency-builder/build-tree.js.map +1 -1
- package/dist/files-dependency-builder/dependency-tree/index.d.ts +1 -1
- package/dist/files-dependency-builder/dependency-tree/index.js +7 -7
- package/dist/files-dependency-builder/dependency-tree/index.js.map +1 -1
- package/dist/files-dependency-builder/dependency-tree/index.spec.js +73 -73
- package/dist/files-dependency-builder/dependency-tree/index.spec.js.map +1 -1
- package/dist/files-dependency-builder/filing-cabinet/index.spec.js +1 -1
- package/dist/files-dependency-builder/filing-cabinet/index.spec.js.map +1 -1
- package/dist/files-dependency-builder/generate-tree-madge.d.ts +1 -1
- package/dist/files-dependency-builder/generate-tree-madge.js +5 -5
- package/dist/files-dependency-builder/generate-tree-madge.js.map +1 -1
- package/dist/files-dependency-builder/precinct/index.d.ts +1 -1
- package/dist/files-dependency-builder/precinct/index.js +2 -2
- package/dist/files-dependency-builder/precinct/index.js.map +1 -1
- package/dist/files-dependency-builder/precinct/index.spec.js +19 -19
- package/dist/files-dependency-builder/precinct/index.spec.js.map +1 -1
- package/files-dependency-builder/build-tree.ts +1 -1
- package/files-dependency-builder/dependency-tree/index.spec.ts +73 -73
- package/files-dependency-builder/dependency-tree/index.ts +7 -7
- package/files-dependency-builder/filing-cabinet/index.spec.ts +1 -1
- package/files-dependency-builder/generate-tree-madge.ts +5 -5
- package/files-dependency-builder/precinct/index.spec.ts +19 -19
- package/files-dependency-builder/precinct/index.ts +2 -2
- package/package.json +8 -8
- /package/dist/{preview-1760566720786.js → preview-1760636469189.js} +0 -0
|
@@ -33,11 +33,11 @@ function cleanUnitDir() {
|
|
|
33
33
|
describe('dependencyTree', function () {
|
|
34
34
|
this.timeout(8000);
|
|
35
35
|
function testTreesForFormat(format, ext = '.js') {
|
|
36
|
-
it('returns an object form of the dependency tree for a file', () => {
|
|
36
|
+
it('returns an object form of the dependency tree for a file', async () => {
|
|
37
37
|
const root = `${UNIT_TEST_DIR}/${format}`;
|
|
38
38
|
const filename = path.normalize(`${root}/a${ext}`);
|
|
39
39
|
|
|
40
|
-
const tree = dependencyTree({ filename, root });
|
|
40
|
+
const tree = await dependencyTree({ filename, root });
|
|
41
41
|
|
|
42
42
|
assert(tree instanceof Object);
|
|
43
43
|
|
|
@@ -142,20 +142,20 @@ describe('dependencyTree', function () {
|
|
|
142
142
|
cleanUnitDir();
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
-
it('returns an empty object for a non-existent filename', () => {
|
|
145
|
+
it('returns an empty object for a non-existent filename', async () => {
|
|
146
146
|
mockfs({
|
|
147
147
|
imaginary: {},
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
const root = `${UNIT_TEST_DIR}/imaginary`;
|
|
151
151
|
const filename = `${root}/notafile.js`;
|
|
152
|
-
const tree = dependencyTree({ filename, root });
|
|
152
|
+
const tree = await dependencyTree({ filename, root });
|
|
153
153
|
|
|
154
154
|
assert(tree instanceof Object);
|
|
155
155
|
assert(!Object.keys(tree).length);
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
it('handles nested tree structures', () => {
|
|
158
|
+
it('handles nested tree structures', async () => {
|
|
159
159
|
const directory = `${UNIT_TEST_DIR}/extended`;
|
|
160
160
|
|
|
161
161
|
mockfs({
|
|
@@ -177,7 +177,7 @@ describe('dependencyTree', function () {
|
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
const filename = path.normalize(`${directory}/a.js`);
|
|
180
|
-
const tree = dependencyTree({ filename, directory });
|
|
180
|
+
const tree = await dependencyTree({ filename, directory });
|
|
181
181
|
assert(tree[filename] instanceof Object);
|
|
182
182
|
|
|
183
183
|
// b and c
|
|
@@ -192,7 +192,7 @@ describe('dependencyTree', function () {
|
|
|
192
192
|
assert.equal(cTree.length, 2);
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
it('does not include files that are not real (#13)', () => {
|
|
195
|
+
it('does not include files that are not real (#13)', async () => {
|
|
196
196
|
mockfs({
|
|
197
197
|
[`${UNIT_TEST_DIR}/onlyRealDeps`]: {
|
|
198
198
|
'a.js': 'var notReal = require("./notReal");',
|
|
@@ -202,13 +202,13 @@ describe('dependencyTree', function () {
|
|
|
202
202
|
const directory = `${UNIT_TEST_DIR}/onlyRealDeps`;
|
|
203
203
|
const filename = path.normalize(`${directory}/a.js`);
|
|
204
204
|
|
|
205
|
-
const tree = dependencyTree({ filename, directory });
|
|
205
|
+
const tree = await dependencyTree({ filename, directory });
|
|
206
206
|
const subTree = tree[filename];
|
|
207
207
|
|
|
208
208
|
assert.ok(!Object.keys(subTree).some((dep) => dep.indexOf('notReal') !== -1));
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
-
it('does not choke on cyclic dependencies', () => {
|
|
211
|
+
it('does not choke on cyclic dependencies', async () => {
|
|
212
212
|
mockfs({
|
|
213
213
|
[`${UNIT_TEST_DIR}/cyclic`]: {
|
|
214
214
|
'a.js': 'var b = require("./b");',
|
|
@@ -221,28 +221,28 @@ describe('dependencyTree', function () {
|
|
|
221
221
|
|
|
222
222
|
const spy = sinon.spy(dependencyTreeRewired, '_getDependencies');
|
|
223
223
|
|
|
224
|
-
const tree = dependencyTreeRewired.default({ filename, directory });
|
|
224
|
+
const tree = await dependencyTreeRewired.default({ filename, directory });
|
|
225
225
|
|
|
226
226
|
assert(spy.callCount === 2);
|
|
227
227
|
assert(Object.keys(tree[filename]).length);
|
|
228
228
|
|
|
229
|
-
dependencyTreeRewired._getDependencies.restore();
|
|
229
|
+
await dependencyTreeRewired._getDependencies.restore();
|
|
230
230
|
});
|
|
231
231
|
|
|
232
|
-
it('excludes Nodejs core modules by default', () => {
|
|
232
|
+
it('excludes Nodejs core modules by default', async () => {
|
|
233
233
|
const directory = `${fixtures}/commonjs`;
|
|
234
234
|
const filename = path.normalize(`${directory}/b.js`);
|
|
235
235
|
|
|
236
|
-
const tree = dependencyTree({ filename, directory });
|
|
236
|
+
const tree = await dependencyTree({ filename, directory });
|
|
237
237
|
assert(Object.keys(tree[filename]).length === 0);
|
|
238
238
|
assert(Object.keys(tree)[0].indexOf('b.js') !== -1);
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
-
it('returns a list of absolutely pathed files', () => {
|
|
241
|
+
it('returns a list of absolutely pathed files', async () => {
|
|
242
242
|
const directory = `${UNIT_TEST_DIR}/commonjs`;
|
|
243
243
|
const filename = `${directory}/b.js`;
|
|
244
244
|
|
|
245
|
-
const tree = dependencyTree({ filename, directory });
|
|
245
|
+
const tree = await dependencyTree({ filename, directory });
|
|
246
246
|
// eslint-disable-next-line
|
|
247
247
|
for (const node in tree.nodes) {
|
|
248
248
|
assert(node.indexOf(process.cwd()) !== -1);
|
|
@@ -250,7 +250,7 @@ describe('dependencyTree', function () {
|
|
|
250
250
|
});
|
|
251
251
|
|
|
252
252
|
describe('when given a detective configuration', () => {
|
|
253
|
-
it('passes it through to precinct', () => {
|
|
253
|
+
it('passes it through to precinct', async () => {
|
|
254
254
|
const spy = sinon.spy(precinct, 'paperwork');
|
|
255
255
|
const directory = path.normalize(`${fixtures}/onlyRealDeps`);
|
|
256
256
|
const filename = path.normalize(`${directory}/a.js`);
|
|
@@ -260,7 +260,7 @@ describe('dependencyTree', function () {
|
|
|
260
260
|
},
|
|
261
261
|
};
|
|
262
262
|
|
|
263
|
-
dependencyTree({
|
|
263
|
+
await dependencyTree({
|
|
264
264
|
filename,
|
|
265
265
|
directory,
|
|
266
266
|
detective: detectiveConfig,
|
|
@@ -273,7 +273,7 @@ describe('dependencyTree', function () {
|
|
|
273
273
|
|
|
274
274
|
describe('when given a list to store non existent partials', () => {
|
|
275
275
|
describe('and the file contains no valid partials', () => {
|
|
276
|
-
it('stores the invalid partials', () => {
|
|
276
|
+
it('stores the invalid partials', async () => {
|
|
277
277
|
mockfs({
|
|
278
278
|
[`${UNIT_TEST_DIR}/onlyRealDeps`]: {
|
|
279
279
|
'a.js': 'var notReal = require("./notReal");',
|
|
@@ -284,7 +284,7 @@ describe('dependencyTree', function () {
|
|
|
284
284
|
const filename = path.normalize(`${directory}/a.js`);
|
|
285
285
|
const nonExistent = [];
|
|
286
286
|
|
|
287
|
-
dependencyTree({ filename, directory, nonExistent });
|
|
287
|
+
await dependencyTree({ filename, directory, nonExistent });
|
|
288
288
|
|
|
289
289
|
assert.equal(Object.keys(nonExistent).length, 1);
|
|
290
290
|
assert.equal(nonExistent[filename][0], './notReal');
|
|
@@ -292,7 +292,7 @@ describe('dependencyTree', function () {
|
|
|
292
292
|
});
|
|
293
293
|
|
|
294
294
|
describe('and the file contains all valid partials', () => {
|
|
295
|
-
it('does not store anything', () => {
|
|
295
|
+
it('does not store anything', async () => {
|
|
296
296
|
mockfs({
|
|
297
297
|
[`${UNIT_TEST_DIR}/onlyRealDeps`]: {
|
|
298
298
|
'a.js': 'var b = require("./b");',
|
|
@@ -304,14 +304,14 @@ describe('dependencyTree', function () {
|
|
|
304
304
|
const filename = `${directory}/a.js`;
|
|
305
305
|
const nonExistent = [];
|
|
306
306
|
|
|
307
|
-
dependencyTree({ filename, directory, nonExistent });
|
|
307
|
+
await dependencyTree({ filename, directory, nonExistent });
|
|
308
308
|
|
|
309
309
|
assert.equal(nonExistent.length, 0);
|
|
310
310
|
});
|
|
311
311
|
});
|
|
312
312
|
|
|
313
313
|
describe('and the file contains a mix of invalid and valid partials', () => {
|
|
314
|
-
it('stores the invalid ones', () => {
|
|
314
|
+
it('stores the invalid ones', async () => {
|
|
315
315
|
mockfs({
|
|
316
316
|
[`${UNIT_TEST_DIR}/onlyRealDeps`]: {
|
|
317
317
|
'a.js': 'var b = require("./b");',
|
|
@@ -324,7 +324,7 @@ describe('dependencyTree', function () {
|
|
|
324
324
|
const filename = path.normalize(`${directory}/a.js`);
|
|
325
325
|
const nonExistent = [];
|
|
326
326
|
|
|
327
|
-
dependencyTree({ filename, directory, nonExistent });
|
|
327
|
+
await dependencyTree({ filename, directory, nonExistent });
|
|
328
328
|
|
|
329
329
|
assert.equal(Object.keys(nonExistent).length, 1);
|
|
330
330
|
assert.equal(nonExistent[path.normalize(`${directory}/c.js`)][0], './notRealMan');
|
|
@@ -332,7 +332,7 @@ describe('dependencyTree', function () {
|
|
|
332
332
|
});
|
|
333
333
|
|
|
334
334
|
describe('and there is more than one reference to the invalid partial', () => {
|
|
335
|
-
it('should include the non-existent partial per file', () => {
|
|
335
|
+
it('should include the non-existent partial per file', async () => {
|
|
336
336
|
mockfs({
|
|
337
337
|
[`${UNIT_TEST_DIR}/onlyRealDeps`]: {
|
|
338
338
|
'a.js': 'var b = require("./b");\nvar crap = require("./notRealMan");',
|
|
@@ -345,7 +345,7 @@ describe('dependencyTree', function () {
|
|
|
345
345
|
const filename = path.normalize(`${directory}/a.js`);
|
|
346
346
|
const nonExistent = [];
|
|
347
347
|
|
|
348
|
-
dependencyTree({ filename, directory, nonExistent });
|
|
348
|
+
await dependencyTree({ filename, directory, nonExistent });
|
|
349
349
|
|
|
350
350
|
assert.equal(Object.keys(nonExistent).length, 2);
|
|
351
351
|
assert.equal(nonExistent[filename][0], './notRealMan');
|
|
@@ -368,8 +368,8 @@ describe('dependencyTree', function () {
|
|
|
368
368
|
});
|
|
369
369
|
|
|
370
370
|
it('throws if the filename is missing', () => {
|
|
371
|
-
assert.
|
|
372
|
-
dependencyTree({
|
|
371
|
+
assert.rejects(async () => {
|
|
372
|
+
await dependencyTree({
|
|
373
373
|
filename: undefined,
|
|
374
374
|
// @ts-ignore
|
|
375
375
|
directory: this._directory,
|
|
@@ -378,17 +378,17 @@ describe('dependencyTree', function () {
|
|
|
378
378
|
});
|
|
379
379
|
|
|
380
380
|
it('throws if the root is missing', () => {
|
|
381
|
-
assert.
|
|
382
|
-
dependencyTree({ filename: undefined });
|
|
381
|
+
assert.rejects(async () => {
|
|
382
|
+
await dependencyTree({ filename: undefined });
|
|
383
383
|
});
|
|
384
384
|
});
|
|
385
385
|
|
|
386
386
|
it('throws if a supplied filter is not a function', () => {
|
|
387
|
-
assert.
|
|
387
|
+
assert.rejects(async () => {
|
|
388
388
|
const directory = `${UNIT_TEST_DIR}/onlyRealDeps`;
|
|
389
389
|
const filename = `${directory}/a.js`;
|
|
390
390
|
|
|
391
|
-
dependencyTree({
|
|
391
|
+
await dependencyTree({
|
|
392
392
|
filename,
|
|
393
393
|
directory,
|
|
394
394
|
filter: 'foobar',
|
|
@@ -397,11 +397,11 @@ describe('dependencyTree', function () {
|
|
|
397
397
|
});
|
|
398
398
|
|
|
399
399
|
it('does not throw on the legacy `root` option', () => {
|
|
400
|
-
assert.
|
|
400
|
+
assert.doesNotReject(async () => {
|
|
401
401
|
const directory = `${UNIT_TEST_DIR}/onlyRealDeps`;
|
|
402
402
|
const filename = `${directory}/a.js`;
|
|
403
403
|
|
|
404
|
-
dependencyTree({
|
|
404
|
+
await dependencyTree({
|
|
405
405
|
filename,
|
|
406
406
|
root: directory,
|
|
407
407
|
});
|
|
@@ -416,8 +416,8 @@ describe('dependencyTree', function () {
|
|
|
416
416
|
});
|
|
417
417
|
|
|
418
418
|
it('does not throw', () => {
|
|
419
|
-
assert.
|
|
420
|
-
dependencyTree({
|
|
419
|
+
assert.doesNotReject(async () => {
|
|
420
|
+
await dependencyTree({
|
|
421
421
|
filename: 'foo',
|
|
422
422
|
// @ts-ignore
|
|
423
423
|
directory: this._directory,
|
|
@@ -425,9 +425,9 @@ describe('dependencyTree', function () {
|
|
|
425
425
|
});
|
|
426
426
|
});
|
|
427
427
|
|
|
428
|
-
it('returns no dependencies', () => {
|
|
428
|
+
it('returns no dependencies', async () => {
|
|
429
429
|
// @ts-ignore
|
|
430
|
-
const tree = dependencyTree({ filename: 'foo', directory: this._directory });
|
|
430
|
+
const tree = await dependencyTree({ filename: 'foo', directory: this._directory });
|
|
431
431
|
assert(!tree.length);
|
|
432
432
|
});
|
|
433
433
|
});
|
|
@@ -438,11 +438,11 @@ describe('dependencyTree', function () {
|
|
|
438
438
|
this._spy = sinon.spy(dependencyTreeRewired, '_getDependencies');
|
|
439
439
|
});
|
|
440
440
|
|
|
441
|
-
afterEach(() => {
|
|
442
|
-
dependencyTreeRewired._getDependencies.restore();
|
|
441
|
+
afterEach(async () => {
|
|
442
|
+
await dependencyTreeRewired._getDependencies.restore();
|
|
443
443
|
});
|
|
444
444
|
|
|
445
|
-
it('returns the precomputed list of a cached entry point', () => {
|
|
445
|
+
it('returns the precomputed list of a cached entry point', async () => {
|
|
446
446
|
const filename = `${UNIT_TEST_DIR}/amd/a.js`;
|
|
447
447
|
const directory = `${UNIT_TEST_DIR}/amd`;
|
|
448
448
|
|
|
@@ -451,7 +451,7 @@ describe('dependencyTree', function () {
|
|
|
451
451
|
[filename]: { pathMap: { dependencies: [] } },
|
|
452
452
|
};
|
|
453
453
|
|
|
454
|
-
const tree = dependencyTree({
|
|
454
|
+
const tree = await dependencyTree({
|
|
455
455
|
filename,
|
|
456
456
|
directory,
|
|
457
457
|
visited: cache,
|
|
@@ -481,10 +481,10 @@ describe('dependencyTree', function () {
|
|
|
481
481
|
|
|
482
482
|
testTreesForFormat('es6');
|
|
483
483
|
|
|
484
|
-
it('resolves files that have jsx', () => {
|
|
484
|
+
it('resolves files that have jsx', async () => {
|
|
485
485
|
// @ts-ignore
|
|
486
486
|
const filename = path.normalize(`${this._directory}/jsx.js`);
|
|
487
|
-
const tree = dependencyTree({
|
|
487
|
+
const tree = await dependencyTree({
|
|
488
488
|
filename,
|
|
489
489
|
// @ts-ignore
|
|
490
490
|
directory: this._directory,
|
|
@@ -493,10 +493,10 @@ describe('dependencyTree', function () {
|
|
|
493
493
|
assert.ok(tree[filename].includes(path.normalize(`${this._directory}/c.js`)));
|
|
494
494
|
});
|
|
495
495
|
|
|
496
|
-
it('resolves files with a jsx extension', () => {
|
|
496
|
+
it('resolves files with a jsx extension', async () => {
|
|
497
497
|
// @ts-ignore
|
|
498
498
|
const filename = path.normalize(`${this._directory}/foo.jsx`);
|
|
499
|
-
const tree = dependencyTree({
|
|
499
|
+
const tree = await dependencyTree({
|
|
500
500
|
filename,
|
|
501
501
|
// @ts-ignore
|
|
502
502
|
directory: this._directory,
|
|
@@ -505,10 +505,10 @@ describe('dependencyTree', function () {
|
|
|
505
505
|
assert.ok(tree[filename].includes(path.normalize(`${this._directory}/b.js`)));
|
|
506
506
|
});
|
|
507
507
|
|
|
508
|
-
it('resolves files that have es7', () => {
|
|
508
|
+
it('resolves files that have es7', async () => {
|
|
509
509
|
// @ts-ignore
|
|
510
510
|
const filename = path.normalize(`${this._directory}/es7.js`);
|
|
511
|
-
const tree = dependencyTree({
|
|
511
|
+
const tree = await dependencyTree({
|
|
512
512
|
filename,
|
|
513
513
|
// @ts-ignore
|
|
514
514
|
directory: this._directory,
|
|
@@ -585,11 +585,11 @@ describe('dependencyTree', function () {
|
|
|
585
585
|
});
|
|
586
586
|
|
|
587
587
|
describe('when a filter function is supplied', () => {
|
|
588
|
-
it('uses the filter to determine if a file should be included in the results', () => {
|
|
588
|
+
it('uses the filter to determine if a file should be included in the results', async () => {
|
|
589
589
|
const directory = path.normalize(`${fixtures}/onlyRealDeps`);
|
|
590
590
|
const filename = path.normalize(`${directory}/a.js`);
|
|
591
591
|
|
|
592
|
-
const tree = dependencyTree({
|
|
592
|
+
const tree = await dependencyTree({
|
|
593
593
|
filename,
|
|
594
594
|
directory,
|
|
595
595
|
// Skip all 3rd party deps
|
|
@@ -618,11 +618,11 @@ describe('dependencyTree', function () {
|
|
|
618
618
|
});
|
|
619
619
|
});
|
|
620
620
|
|
|
621
|
-
it('includes the lazy dependency', () => {
|
|
621
|
+
it('includes the lazy dependency', async () => {
|
|
622
622
|
const directory = `${UNIT_TEST_DIR}/cjs`;
|
|
623
623
|
const filename = path.normalize(`${directory}/foo.js`);
|
|
624
624
|
|
|
625
|
-
const tree = dependencyTree({ filename, directory });
|
|
625
|
+
const tree = await dependencyTree({ filename, directory });
|
|
626
626
|
assert.ok(tree[filename].includes(path.normalize(`${directory}/bar.js`)));
|
|
627
627
|
});
|
|
628
628
|
});
|
|
@@ -638,11 +638,11 @@ describe('dependencyTree', function () {
|
|
|
638
638
|
});
|
|
639
639
|
|
|
640
640
|
describe('and mixedImport mode is turned on', () => {
|
|
641
|
-
it('includes the lazy dependency', () => {
|
|
641
|
+
it('includes the lazy dependency', async () => {
|
|
642
642
|
const directory = `${UNIT_TEST_DIR}/es6`;
|
|
643
643
|
const filename = path.normalize(`${directory}/foo.js`);
|
|
644
644
|
|
|
645
|
-
const tree = dependencyTree({
|
|
645
|
+
const tree = await dependencyTree({
|
|
646
646
|
filename,
|
|
647
647
|
directory,
|
|
648
648
|
detective: {
|
|
@@ -667,11 +667,11 @@ describe('dependencyTree', function () {
|
|
|
667
667
|
});
|
|
668
668
|
});
|
|
669
669
|
|
|
670
|
-
it('includes the dynamic import', () => {
|
|
670
|
+
it('includes the dynamic import', async () => {
|
|
671
671
|
const directory = path.normalize(`${UNIT_TEST_DIR}/es6`);
|
|
672
672
|
const filename = path.normalize(`${directory}/foo.js`);
|
|
673
673
|
|
|
674
|
-
const tree = dependencyTree({
|
|
674
|
+
const tree = await dependencyTree({
|
|
675
675
|
filename,
|
|
676
676
|
directory,
|
|
677
677
|
});
|
|
@@ -692,16 +692,16 @@ describe('dependencyTree', function () {
|
|
|
692
692
|
});
|
|
693
693
|
});
|
|
694
694
|
|
|
695
|
-
it('should include it as a dependency and not throw an error', () => {
|
|
695
|
+
it('should include it as a dependency and not throw an error', async () => {
|
|
696
696
|
const directory = path.normalize(`${UNIT_TEST_DIR}/baz`);
|
|
697
697
|
const filename = path.normalize(`${directory}/foo.js`);
|
|
698
698
|
|
|
699
|
-
const tree = dependencyTree({
|
|
699
|
+
const tree = await dependencyTree({
|
|
700
700
|
filename,
|
|
701
701
|
directory,
|
|
702
702
|
});
|
|
703
703
|
|
|
704
|
-
assert.ok(
|
|
704
|
+
assert.ok(path.normalize(path.join(directory, 'bar.json')) in tree);
|
|
705
705
|
});
|
|
706
706
|
});
|
|
707
707
|
|
|
@@ -725,11 +725,11 @@ describe('dependencyTree', function () {
|
|
|
725
725
|
});
|
|
726
726
|
});
|
|
727
727
|
|
|
728
|
-
it('it includes the module entry as dependency', () => {
|
|
728
|
+
it('it includes the module entry as dependency', async () => {
|
|
729
729
|
const directory = `${UNIT_TEST_DIR}/es6`;
|
|
730
730
|
const filename = `${directory}/module.entry.js`;
|
|
731
731
|
|
|
732
|
-
const tree = dependencyTree({
|
|
732
|
+
const tree = await dependencyTree({
|
|
733
733
|
filename,
|
|
734
734
|
directory,
|
|
735
735
|
nodeModulesConfig: {
|
|
@@ -777,7 +777,7 @@ describe('dependencyTree', function () {
|
|
|
777
777
|
});
|
|
778
778
|
});
|
|
779
779
|
|
|
780
|
-
it('should not override the cache with wrong packages', () => {
|
|
780
|
+
it('should not override the cache with wrong packages', async () => {
|
|
781
781
|
const directory = path.normalize(`${UNIT_TEST_DIR}/baz`);
|
|
782
782
|
const fooFile = path.normalize(`${directory}/foo.js`);
|
|
783
783
|
const barFile = path.normalize(`${directory}/bar.js`);
|
|
@@ -791,18 +791,18 @@ describe('dependencyTree', function () {
|
|
|
791
791
|
|
|
792
792
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
793
793
|
config.filename = fooFile;
|
|
794
|
-
dependencyTree(config);
|
|
794
|
+
await dependencyTree(config);
|
|
795
795
|
expect(nonExistent[fooFile]).to.deep.equal(['non-exist-foo-pkg']);
|
|
796
796
|
|
|
797
797
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
798
798
|
config.filename = barFile;
|
|
799
|
-
dependencyTree(config);
|
|
799
|
+
await dependencyTree(config);
|
|
800
800
|
expect(nonExistent[fooFile]).to.deep.equal(['non-exist-foo-pkg']);
|
|
801
801
|
expect(nonExistent[barFile]).to.deep.equal(['non-exist-bar-pkg']);
|
|
802
802
|
|
|
803
803
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
804
804
|
config.filename = bazFile;
|
|
805
|
-
dependencyTree(config);
|
|
805
|
+
await dependencyTree(config);
|
|
806
806
|
expect(nonExistent[fooFile]).to.deep.equal(['non-exist-foo-pkg']);
|
|
807
807
|
expect(nonExistent[barFile]).to.deep.equal(['non-exist-bar-pkg']);
|
|
808
808
|
expect(nonExistent[bazFile]).to.deep.equal(['non-exist-baz-pkg']);
|
|
@@ -817,7 +817,7 @@ describe('dependencyTree', function () {
|
|
|
817
817
|
},
|
|
818
818
|
});
|
|
819
819
|
});
|
|
820
|
-
it('should not crash with "RangeError: Maximum call stack size exceeded" error', () => {
|
|
820
|
+
it('should not crash with "RangeError: Maximum call stack size exceeded" error', async () => {
|
|
821
821
|
const directory = path.normalize(`${UNIT_TEST_DIR}/baz`);
|
|
822
822
|
const baseFile = path.normalize(`${directory}/base.scss`);
|
|
823
823
|
const indexFile = path.normalize(`${directory}/index.jsx`);
|
|
@@ -827,16 +827,16 @@ describe('dependencyTree', function () {
|
|
|
827
827
|
|
|
828
828
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
829
829
|
config.filename = baseFile;
|
|
830
|
-
dependencyTree(config);
|
|
830
|
+
await dependencyTree(config);
|
|
831
831
|
|
|
832
832
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
833
833
|
config.filename = indexFile;
|
|
834
|
-
const dependencies = dependencyTree(config);
|
|
834
|
+
const dependencies = await dependencyTree(config);
|
|
835
835
|
expect(dependencies).to.be.ok;
|
|
836
836
|
});
|
|
837
837
|
});
|
|
838
838
|
describe('files with dynamic import', () => {
|
|
839
|
-
it('should not show missing dependencies', () => {
|
|
839
|
+
it('should not show missing dependencies', async () => {
|
|
840
840
|
mockfs({
|
|
841
841
|
[`${UNIT_TEST_DIR}/dynamic`]: {
|
|
842
842
|
'foo.js': 'const a = "./b"; import(a); require(a);',
|
|
@@ -846,7 +846,7 @@ describe('dependencyTree', function () {
|
|
|
846
846
|
const filename = path.normalize(`${directory}/foo.js`);
|
|
847
847
|
const visited = {};
|
|
848
848
|
|
|
849
|
-
dependencyTree({
|
|
849
|
+
await dependencyTree({
|
|
850
850
|
filename,
|
|
851
851
|
directory,
|
|
852
852
|
visited,
|
|
@@ -855,7 +855,7 @@ describe('dependencyTree', function () {
|
|
|
855
855
|
});
|
|
856
856
|
});
|
|
857
857
|
describe('files with import from cdn (http, https)', () => {
|
|
858
|
-
it('should not show missing dependencies when importing from https', () => {
|
|
858
|
+
it('should not show missing dependencies when importing from https', async () => {
|
|
859
859
|
mockfs({
|
|
860
860
|
[`${UNIT_TEST_DIR}/cdn`]: {
|
|
861
861
|
'foo.js': 'import { a } from "https://unpkg.com";',
|
|
@@ -864,14 +864,14 @@ describe('dependencyTree', function () {
|
|
|
864
864
|
const directory = path.normalize(`${UNIT_TEST_DIR}/cdn`);
|
|
865
865
|
const filename = path.normalize(`${directory}/foo.js`);
|
|
866
866
|
const visited = {};
|
|
867
|
-
dependencyTree({
|
|
867
|
+
await dependencyTree({
|
|
868
868
|
filename,
|
|
869
869
|
directory,
|
|
870
870
|
visited,
|
|
871
871
|
});
|
|
872
872
|
expect(visited[filename].missing).to.be.undefined;
|
|
873
873
|
});
|
|
874
|
-
it('should not show missing dependencies when importing from http', () => {
|
|
874
|
+
it('should not show missing dependencies when importing from http', async () => {
|
|
875
875
|
mockfs({
|
|
876
876
|
[`${UNIT_TEST_DIR}/cdn`]: {
|
|
877
877
|
'bar.js': 'const b = require("http://pkg.com");',
|
|
@@ -880,7 +880,7 @@ describe('dependencyTree', function () {
|
|
|
880
880
|
const directory = path.normalize(`${UNIT_TEST_DIR}/cdn`);
|
|
881
881
|
const filename = path.normalize(`${directory}/bar.js`);
|
|
882
882
|
const visited = {};
|
|
883
|
-
dependencyTree({
|
|
883
|
+
await dependencyTree({
|
|
884
884
|
filename,
|
|
885
885
|
directory,
|
|
886
886
|
visited,
|
|
@@ -23,7 +23,7 @@ const debug = debugFactory('tree');
|
|
|
23
23
|
* @param {Array} [options.nonExistent] - List of partials that do not exist
|
|
24
24
|
* @return {Object}
|
|
25
25
|
*/
|
|
26
|
-
export default function (options) {
|
|
26
|
+
export default async function (options) {
|
|
27
27
|
const config = new Config(options);
|
|
28
28
|
|
|
29
29
|
if (!fs.existsSync(config.filename)) {
|
|
@@ -59,7 +59,7 @@ module.exports.toList = function (options) {
|
|
|
59
59
|
* @param {Config} config
|
|
60
60
|
* @return {Array}
|
|
61
61
|
*/
|
|
62
|
-
module.exports._getDependencies = function (config) {
|
|
62
|
+
module.exports._getDependencies = async function (config) {
|
|
63
63
|
let dependenciesRaw; // from some detectives it comes as an array, from some it is an object
|
|
64
64
|
const precinctOptions = config.detectiveConfig;
|
|
65
65
|
precinctOptions.includeCore = false;
|
|
@@ -68,7 +68,7 @@ module.exports._getDependencies = function (config) {
|
|
|
68
68
|
delete precinct.ast;
|
|
69
69
|
|
|
70
70
|
try {
|
|
71
|
-
dependenciesRaw = precinct.paperwork(config.filename, precinctOptions);
|
|
71
|
+
dependenciesRaw = await precinct.paperwork(config.filename, precinctOptions);
|
|
72
72
|
} catch (e: any) {
|
|
73
73
|
debug(`error getting dependencies: ${e.message}`);
|
|
74
74
|
debug(e.stack);
|
|
@@ -165,7 +165,7 @@ module.exports._getDependencies = function (config) {
|
|
|
165
165
|
* `pathMap` has the dependencies and some more info, such as importSpecifiers. we should use only
|
|
166
166
|
* pathMap and get rid of tree.
|
|
167
167
|
*/
|
|
168
|
-
function traverse(config) {
|
|
168
|
+
async function traverse(config) {
|
|
169
169
|
const tree = [];
|
|
170
170
|
const stack = [config.filename];
|
|
171
171
|
while (stack.length) {
|
|
@@ -174,16 +174,16 @@ function traverse(config) {
|
|
|
174
174
|
if (config.visited[dependency]) {
|
|
175
175
|
populateFromCache(dependency);
|
|
176
176
|
} else {
|
|
177
|
-
traverseDependency(dependency);
|
|
177
|
+
await traverseDependency(dependency);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
return tree;
|
|
182
182
|
|
|
183
|
-
function traverseDependency(dependency) {
|
|
183
|
+
async function traverseDependency(dependency) {
|
|
184
184
|
const localConfig = config.clone();
|
|
185
185
|
localConfig.filename = dependency;
|
|
186
|
-
let dependencies = module.exports._getDependencies(localConfig);
|
|
186
|
+
let dependencies = await module.exports._getDependencies(localConfig);
|
|
187
187
|
if (config.filter) {
|
|
188
188
|
debug('using filter function to filter out dependencies');
|
|
189
189
|
debug(`number of dependencies before filtering: ${dependencies.length}`);
|
|
@@ -80,7 +80,7 @@ describe('filing-cabinet', () => {
|
|
|
80
80
|
directory: `${UNIT_TEST_DIR}/js/es6/`,
|
|
81
81
|
ast,
|
|
82
82
|
});
|
|
83
|
-
assert.ok(result.endsWith('es6/bar.js'));
|
|
83
|
+
assert.ok(result.endsWith(path.normalize('es6/bar.js')));
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
it('resolves the dependency successfully', () => {
|
|
@@ -118,7 +118,7 @@ type GenerateTreeResults = {
|
|
|
118
118
|
* @param config
|
|
119
119
|
* @return {Object}
|
|
120
120
|
*/
|
|
121
|
-
export default function generateTree(files: string[] = [], config): GenerateTreeResults {
|
|
121
|
+
export default async function generateTree(files: string[] = [], config): Promise<GenerateTreeResults> {
|
|
122
122
|
const depTree = {};
|
|
123
123
|
const nonExistent = {};
|
|
124
124
|
const npmPaths = {};
|
|
@@ -126,14 +126,14 @@ export default function generateTree(files: string[] = [], config): GenerateTree
|
|
|
126
126
|
const pathMap = [];
|
|
127
127
|
const errors = {};
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
for await (const file of files) {
|
|
130
130
|
if (depTree[file]) {
|
|
131
|
-
|
|
131
|
+
continue;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
const detective = config.detectiveOptions;
|
|
135
135
|
try {
|
|
136
|
-
const dependencyTreeResult = dependencyTree({
|
|
136
|
+
const dependencyTreeResult = await dependencyTree({
|
|
137
137
|
filename: file,
|
|
138
138
|
directory: config.baseDir,
|
|
139
139
|
requireConfig: config.requireConfig,
|
|
@@ -165,7 +165,7 @@ export default function generateTree(files: string[] = [], config): GenerateTree
|
|
|
165
165
|
} catch (err: any) {
|
|
166
166
|
errors[file] = err;
|
|
167
167
|
}
|
|
168
|
-
}
|
|
168
|
+
}
|
|
169
169
|
|
|
170
170
|
let tree = convertTreePaths(depTree, pathCache, config.baseDir);
|
|
171
171
|
|