@davidwells/extract-deps 0.0.3 → 0.0.5
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/examples/verify-basic.js +43 -0
- package/examples/verify-build-graph.js +58 -0
- package/examples/verify-build-order.js +113 -0
- package/examples/verify-find-dependents.js +74 -0
- package/examples/verify-impact-analysis.js +97 -0
- package/package.json +5 -1
- package/src/dep-graph.js +277 -0
- package/src/get-cjs-exports.js +3 -30
- package/src/get-exports.js +38 -40
- package/src/utils.js +41 -1
- package/tests/dep-graph.test.js +213 -0
- package/tests/fixtures/cjs-deep-example/d-one.js +10 -0
- package/tests/fixtures/cjs-deep-example/d-sub-folder/d-sub-sub-folder/d-three.js +7 -0
- package/tests/fixtures/cjs-deep-example/d-sub-folder/d-two-a.js +8 -0
- package/tests/fixtures/cjs-deep-example/d-sub-folder/d-two-b.js +8 -0
- package/tests/fixtures/cjs-deep-example/d-sub-folder/d-two.js +8 -0
- package/tests/fixtures/cjs-deep-example/index.js +8 -0
- package/tests/fixtures/cjs-example/index.js +8 -0
- package/tests/fixtures/cjs-example/one.js +9 -0
- package/tests/fixtures/cjs-example/sub-folder/sub-sub-folder/three.js +6 -0
- package/tests/fixtures/cjs-example/sub-folder/two.js +8 -0
- package/tests/fixtures/cjs-parent.js +5 -0
- package/tests/fixtures/esm-fixture/index.js +8 -0
- package/tests/fixtures/esm-fixture/one.js +9 -0
- package/tests/fixtures/esm-fixture/sub-folder/sub-sub-folder/three.js +6 -0
- package/tests/fixtures/esm-fixture/sub-folder/two.js +8 -0
- package/tests/get-cjs-exports.test.js +53 -1
- package/tests/get-exports.test.js +162 -10
- package/types/dep-graph.d.ts +22 -0
- package/types/dep-graph.d.ts.map +1 -0
- package/types/get-cjs-exports.d.ts +35 -0
- package/types/get-cjs-exports.d.ts.map +1 -0
- package/types/get-exports.d.ts +3 -1
- package/types/get-exports.d.ts.map +1 -1
- package/types/index.d.ts +7 -3
- package/types/index.d.ts.map +1 -1
- package/types/utils.d.ts +2 -1
- package/types/utils.d.ts.map +1 -1
|
@@ -23,40 +23,51 @@ export default () => {}
|
|
|
23
23
|
`
|
|
24
24
|
|
|
25
25
|
const foundExports = getDefaultExports(code)
|
|
26
|
+
console.log('foundExports', foundExports)
|
|
26
27
|
|
|
27
|
-
assert.ok(foundExports.length ===
|
|
28
|
+
assert.ok(foundExports.length === 7, 'Should find 7 default exports')
|
|
28
29
|
|
|
29
30
|
// Check function export
|
|
30
|
-
const functionExport = foundExports.find(exp => exp.
|
|
31
|
+
const functionExport = foundExports.find(exp => exp.exportDefinitionName === 'myFunction')
|
|
31
32
|
assert.ok(functionExport, 'Should find function export')
|
|
32
33
|
assert.equal(functionExport.exportType, 'default')
|
|
33
|
-
assert.equal(functionExport.exportValue, 'function myFunction')
|
|
34
|
+
assert.equal(functionExport.exportValue, 'function myFunction() {}')
|
|
34
35
|
|
|
35
36
|
// Check class export
|
|
36
|
-
const classExport = foundExports.find(exp => exp.
|
|
37
|
+
const classExport = foundExports.find(exp => exp.exportDefinitionName === 'MyClass')
|
|
37
38
|
assert.ok(classExport, 'Should find class export')
|
|
38
39
|
assert.equal(classExport.exportType, 'default')
|
|
39
|
-
assert.equal(classExport.exportValue, 'class MyClass')
|
|
40
|
+
assert.equal(classExport.exportValue, 'class MyClass {}')
|
|
40
41
|
|
|
41
42
|
// Check object literal
|
|
42
|
-
const objectExport = foundExports.find(exp => exp.
|
|
43
|
+
const objectExport = foundExports.find(exp => exp.exportDefinitionName === 'literal-object')
|
|
43
44
|
assert.ok(objectExport, 'Should find object literal export')
|
|
44
45
|
assert.equal(objectExport.exportValue, "{ foo: 'bar' }")
|
|
46
|
+
assert.equal(objectExport.exportName, '')
|
|
47
|
+
|
|
48
|
+
// Check string literal
|
|
49
|
+
const stringExport = foundExports.find(exp => exp.exportDefinitionName === 'literal-string')
|
|
50
|
+
assert.ok(stringExport, 'Should find string literal export')
|
|
51
|
+
assert.equal(stringExport.exportValue, "'hello'", 'exportValue should be "hello"')
|
|
52
|
+
assert.equal(stringExport.exportName, '', 'exportName should be empty')
|
|
45
53
|
|
|
46
54
|
// Check array literal
|
|
47
55
|
const arrayExport = foundExports.find(exp => exp.exportValue === '[1, 2, 3]')
|
|
48
56
|
assert.ok(arrayExport, 'Should find array literal export')
|
|
49
|
-
assert.equal(arrayExport.
|
|
57
|
+
assert.equal(arrayExport.exportDefinitionName, 'literal-array')
|
|
58
|
+
assert.equal(arrayExport.exportName, '')
|
|
50
59
|
|
|
51
60
|
// Check number literal
|
|
52
61
|
const numberExport = foundExports.find(exp => exp.exportValue === '42')
|
|
53
62
|
assert.ok(numberExport, 'Should find number literal export')
|
|
54
|
-
assert.equal(numberExport.
|
|
63
|
+
assert.equal(numberExport.exportDefinitionName, 'literal-number')
|
|
64
|
+
assert.equal(numberExport.exportName, '')
|
|
55
65
|
|
|
56
66
|
// Check arrow function
|
|
57
67
|
const arrowExport = foundExports.find(exp => exp.exportValue === '() =>')
|
|
58
68
|
assert.ok(arrowExport, 'Should find arrow function export')
|
|
59
|
-
assert.equal(arrowExport.
|
|
69
|
+
assert.equal(arrowExport.exportDefinitionName, 'anonymous')
|
|
70
|
+
assert.equal(arrowExport.exportName, '')
|
|
60
71
|
})
|
|
61
72
|
|
|
62
73
|
test('should extract named exports', () => {
|
|
@@ -318,7 +329,7 @@ export {
|
|
|
318
329
|
assert.ok(foundExports.length > 0, 'Should find exports in complex code')
|
|
319
330
|
|
|
320
331
|
// Should handle anonymous functions and classes
|
|
321
|
-
const anonymousExports = foundExports.filter(exp => exp.
|
|
332
|
+
const anonymousExports = foundExports.filter(exp => exp.exportDefinitionName === 'anonymous')
|
|
322
333
|
assert.ok(anonymousExports.length >= 2, 'Should find anonymous function and class exports')
|
|
323
334
|
|
|
324
335
|
// Should handle complex named declaration exports
|
|
@@ -380,4 +391,145 @@ export { MyComponent, Button, Input }
|
|
|
380
391
|
assert.ok(thirdExport.exportType === 'named', 'Should find named export')
|
|
381
392
|
})
|
|
382
393
|
|
|
394
|
+
|
|
395
|
+
test('lambda function default function', () => {
|
|
396
|
+
const code = `
|
|
397
|
+
const handler = async event => {
|
|
398
|
+
return {
|
|
399
|
+
statusCode: 200,
|
|
400
|
+
body: JSON.stringify(
|
|
401
|
+
{
|
|
402
|
+
message: 'yo function',
|
|
403
|
+
input: event,
|
|
404
|
+
},
|
|
405
|
+
null,
|
|
406
|
+
2
|
|
407
|
+
),
|
|
408
|
+
};
|
|
409
|
+
};
|
|
410
|
+
export default handler
|
|
411
|
+
`
|
|
412
|
+
|
|
413
|
+
const foundExports = getExports(code)
|
|
414
|
+
console.log('foundExports', foundExports)
|
|
415
|
+
|
|
416
|
+
// TODO add assertions
|
|
417
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
418
|
+
assert.ok(foundExports[0].exportType, 'Should have exportType array')
|
|
419
|
+
assert.equal(foundExports[0].exportType, 'default', 'exportType should be default')
|
|
420
|
+
assert.equal(foundExports[0].exportName, '', 'exportName should empty because it default function')
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
test('lambda function default function inline', () => {
|
|
425
|
+
const code = `
|
|
426
|
+
export default async function handler(event) {
|
|
427
|
+
return {
|
|
428
|
+
statusCode: 200,
|
|
429
|
+
body: JSON.stringify({
|
|
430
|
+
message: 'yo function',
|
|
431
|
+
input: event,
|
|
432
|
+
}, null, 2),
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
`
|
|
436
|
+
|
|
437
|
+
const foundExports = getExports(code)
|
|
438
|
+
console.log('foundExports', foundExports)
|
|
439
|
+
|
|
440
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
441
|
+
assert.ok(foundExports[0].exportType, 'Should have keys array')
|
|
442
|
+
assert.equal(foundExports[0].exportType, 'default', 'exportType should be default')
|
|
443
|
+
assert.equal(foundExports[0].exportName, '', 'exportName should empty because it default function')
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
test('lambda function default object', () => {
|
|
447
|
+
const code = `
|
|
448
|
+
const handler = async event => {
|
|
449
|
+
return {
|
|
450
|
+
statusCode: 200,
|
|
451
|
+
body: JSON.stringify(
|
|
452
|
+
{
|
|
453
|
+
message: 'yo function',
|
|
454
|
+
input: event,
|
|
455
|
+
},
|
|
456
|
+
null,
|
|
457
|
+
2
|
|
458
|
+
),
|
|
459
|
+
};
|
|
460
|
+
};
|
|
461
|
+
export default {
|
|
462
|
+
handler,
|
|
463
|
+
}
|
|
464
|
+
`
|
|
465
|
+
|
|
466
|
+
const foundExports = getExports(code)
|
|
467
|
+
console.log('foundExports', foundExports)
|
|
468
|
+
|
|
469
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
470
|
+
assert.ok(foundExports[0].keys, 'Should have keys array')
|
|
471
|
+
assert.equal(foundExports[0].keys.length, 1, 'Should have 1 key')
|
|
472
|
+
assert.equal(foundExports[0].keys[0], 'handler', 'Key should be "handler" without trailing comma')
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
test('lambda function named object', () => {
|
|
477
|
+
const code = `
|
|
478
|
+
const handler = async event => {
|
|
479
|
+
return {
|
|
480
|
+
statusCode: 200,
|
|
481
|
+
body: JSON.stringify(
|
|
482
|
+
{
|
|
483
|
+
message: 'yo function',
|
|
484
|
+
input: event,
|
|
485
|
+
},
|
|
486
|
+
null,
|
|
487
|
+
2
|
|
488
|
+
),
|
|
489
|
+
};
|
|
490
|
+
};
|
|
491
|
+
export {
|
|
492
|
+
handler,
|
|
493
|
+
}
|
|
494
|
+
`
|
|
495
|
+
|
|
496
|
+
const foundExports = getExports(code)
|
|
497
|
+
console.log('foundExports', foundExports)
|
|
498
|
+
|
|
499
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
500
|
+
assert.ok(foundExports[0].exportType, 'Should have keys array')
|
|
501
|
+
assert.equal(foundExports[0].exportType, 'named', 'exportType should be named')
|
|
502
|
+
assert.equal(foundExports[0].exportName, 'handler', 'exportName should be "handler" without trailing comma')
|
|
503
|
+
})
|
|
504
|
+
|
|
505
|
+
test('lambda function named object with alias', () => {
|
|
506
|
+
const code = `
|
|
507
|
+
const handler = async event => {
|
|
508
|
+
return {
|
|
509
|
+
statusCode: 200,
|
|
510
|
+
body: JSON.stringify(
|
|
511
|
+
{
|
|
512
|
+
message: 'yo function',
|
|
513
|
+
input: event,
|
|
514
|
+
},
|
|
515
|
+
null,
|
|
516
|
+
2
|
|
517
|
+
),
|
|
518
|
+
};
|
|
519
|
+
};
|
|
520
|
+
export {
|
|
521
|
+
handler as myHandler
|
|
522
|
+
}
|
|
523
|
+
`
|
|
524
|
+
|
|
525
|
+
const foundExports = getExports(code)
|
|
526
|
+
console.log('foundExports', foundExports)
|
|
527
|
+
|
|
528
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
529
|
+
assert.ok(foundExports[0].exportType, 'Should have keys array')
|
|
530
|
+
assert.equal(foundExports[0].exportType, 'named', 'exportType should be named')
|
|
531
|
+
assert.equal(foundExports[0].exportName, 'handler', 'exportName should be "handler" without trailing comma')
|
|
532
|
+
assert.equal(foundExports[0].exportAlias, 'myHandler', 'exportAlias should be "myHandler" without trailing comma')
|
|
533
|
+
})
|
|
534
|
+
|
|
383
535
|
test.run()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build dependency graph for a file and its dependencies
|
|
3
|
+
* @param {string} filePath - File to analyze
|
|
4
|
+
* @param {object} options - Options
|
|
5
|
+
* @param {boolean} [options.buildGraph] - If true, build and return dependency graph. Default: true
|
|
6
|
+
* @param {boolean} [options.verifyGraph] - If true, verify imports/exports. Default: true
|
|
7
|
+
* @param {boolean} [options.throwOnFirstError] - If true, throw immediately on first error. Default: false
|
|
8
|
+
* @returns {Map<string, string[]>|undefined} - Dependency graph where keys are file paths and values are arrays of dependency paths. Returns undefined if buildGraph is false.
|
|
9
|
+
*/
|
|
10
|
+
export function depGraph(filePath: string, options?: {
|
|
11
|
+
buildGraph?: boolean;
|
|
12
|
+
verifyGraph?: boolean;
|
|
13
|
+
throwOnFirstError?: boolean;
|
|
14
|
+
}): Map<string, string[]> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get all dependency file paths in build order (dependencies first), deduplicated
|
|
17
|
+
* @param {string} filePath - Entry file path
|
|
18
|
+
* @param {object} options - Options to pass to depGraph
|
|
19
|
+
* @returns {string[]} - Array of unique dependency file paths in topological order
|
|
20
|
+
*/
|
|
21
|
+
export function resolveDepPaths(filePath: string, options?: object): string[];
|
|
22
|
+
//# sourceMappingURL=dep-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dep-graph.d.ts","sourceRoot":"","sources":["../src/dep-graph.js"],"names":[],"mappings":"AA+LA;;;;;;;;GAQG;AACH,mCAPW,MAAM;IAEY,UAAU,GAA5B,OAAO;IACW,WAAW,GAA7B,OAAO;IACW,iBAAiB,GAAnC,OAAO;IACL,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC,GAAC,SAAS,CAiB3C;AAGD;;;;;GAKG;AACH,0CAJW,MAAM,YACN,MAAM,GACJ,MAAM,EAAE,CAsCpB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function getCjsExports(code: any): any[];
|
|
2
|
+
export function getModuleExportsAssignment(originalText?: string, sanitizedText?: string): {
|
|
3
|
+
line: string;
|
|
4
|
+
exportType: string;
|
|
5
|
+
exportName: string;
|
|
6
|
+
exportDefinitionName: any;
|
|
7
|
+
exportValue: string;
|
|
8
|
+
index: number;
|
|
9
|
+
isExport: boolean;
|
|
10
|
+
}[];
|
|
11
|
+
export function getModuleExportsProperty(originalText?: string, sanitizedText?: string): {
|
|
12
|
+
line: string;
|
|
13
|
+
exportType: string;
|
|
14
|
+
exportName: string;
|
|
15
|
+
exportValue: string;
|
|
16
|
+
index: number;
|
|
17
|
+
isExport: boolean;
|
|
18
|
+
}[];
|
|
19
|
+
export function getExportsProperty(originalText?: string, sanitizedText?: string): {
|
|
20
|
+
line: string;
|
|
21
|
+
exportType: string;
|
|
22
|
+
exportName: string;
|
|
23
|
+
exportValue: string;
|
|
24
|
+
index: number;
|
|
25
|
+
isExport: boolean;
|
|
26
|
+
}[];
|
|
27
|
+
export function getObjectAssignExports(originalText?: string, sanitizedText?: string): {
|
|
28
|
+
line: string;
|
|
29
|
+
exportType: string;
|
|
30
|
+
exportName: string;
|
|
31
|
+
exportValue: string;
|
|
32
|
+
index: number;
|
|
33
|
+
isExport: boolean;
|
|
34
|
+
}[];
|
|
35
|
+
//# sourceMappingURL=get-cjs-exports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-cjs-exports.d.ts","sourceRoot":"","sources":["../src/get-cjs-exports.js"],"names":[],"mappings":"AA+BA,gDAuBC;AA+BD;;;;;;;;IAqGC;AAED;;;;;;;IAqBC;AAED;;;;;;;IAqBC;AAED;;;;;;;IAiDC"}
|
package/types/get-exports.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export function getExports(code: any, options?: {}): any[];
|
|
|
2
2
|
export function getDefaultExports(targetText?: string): {
|
|
3
3
|
line: string;
|
|
4
4
|
exportType: string;
|
|
5
|
-
exportName:
|
|
5
|
+
exportName: string;
|
|
6
|
+
exportDefinitionName: any;
|
|
6
7
|
exportValue: string;
|
|
7
8
|
index: number;
|
|
8
9
|
isExport: boolean;
|
|
@@ -42,6 +43,7 @@ export function getAssertionExports(targetText?: string): {
|
|
|
42
43
|
exportType: string;
|
|
43
44
|
exportName: string;
|
|
44
45
|
definitions: any;
|
|
46
|
+
keys: any;
|
|
45
47
|
from: string;
|
|
46
48
|
assertion: string;
|
|
47
49
|
assertionType: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-exports.d.ts","sourceRoot":"","sources":["../src/get-exports.js"],"names":[],"mappings":"AAiBA,
|
|
1
|
+
{"version":3,"file":"get-exports.d.ts","sourceRoot":"","sources":["../src/get-exports.js"],"names":[],"mappings":"AAiBA,2DA+BC;AAED;;;;;;;;IAqDC;AAED;;;;;;IAeC;AAED,uEAuBC;AAED;;;;;;IAeC;AAED;;;;;;;IAgBC;AAED;;;;;;IAeC;AAED;;;;;;;;;;;;IA0BC"}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function extractDeps(code: any): {
|
|
1
|
+
export function extractDeps(code: any, filePath?: string): {
|
|
2
2
|
imports: {
|
|
3
3
|
line: string;
|
|
4
4
|
varType: string;
|
|
@@ -9,6 +9,7 @@ export function extractDeps(code: any): {
|
|
|
9
9
|
isImport: boolean;
|
|
10
10
|
isRelative: boolean;
|
|
11
11
|
}[];
|
|
12
|
+
exports: any[];
|
|
12
13
|
requires: {
|
|
13
14
|
line: string;
|
|
14
15
|
varType: string;
|
|
@@ -20,8 +21,11 @@ export function extractDeps(code: any): {
|
|
|
20
21
|
isRelative: boolean;
|
|
21
22
|
isDynamic: boolean;
|
|
22
23
|
}[];
|
|
23
|
-
|
|
24
|
+
moduleExports: any[];
|
|
24
25
|
};
|
|
26
|
+
import { hasESMSyntax } from "./detect-syntax";
|
|
27
|
+
import { hasCJSSyntax } from "./detect-syntax";
|
|
28
|
+
import { detectSyntax } from "./detect-syntax";
|
|
25
29
|
import { getRequires } from "./get-requires";
|
|
26
30
|
import { getDynamicRequires } from "./get-requires";
|
|
27
31
|
import { getStaticRequires } from "./get-requires";
|
|
@@ -35,5 +39,5 @@ import { getNamedDeclarationExports } from "./get-exports";
|
|
|
35
39
|
import { getAllExports } from "./get-exports";
|
|
36
40
|
import { getNamespaceExports } from "./get-exports";
|
|
37
41
|
import { getTypeExports } from "./get-exports";
|
|
38
|
-
export { getRequires, getDynamicRequires, getStaticRequires, getImports, getStaticImports, getDynamicImports, getExports, getDefaultExports, getNamedExports, getNamedDeclarationExports, getAllExports, getNamespaceExports, getTypeExports };
|
|
42
|
+
export { hasESMSyntax, hasCJSSyntax, detectSyntax, getRequires, getDynamicRequires, getStaticRequires, getImports, getStaticImports, getDynamicImports, getExports, getDefaultExports, getNamedExports, getNamedDeclarationExports, getAllExports, getNamespaceExports, getTypeExports };
|
|
39
43
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;;;;;;;;;EAgBC"}
|
package/types/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export function isRelativeImport(importLocation: any): boolean;
|
|
2
2
|
export function isRelativeImportWithQuotes(importLocation: any): boolean;
|
|
3
|
-
export function getNames(names: any): any;
|
|
3
|
+
export function getNames(names: any, aliasKey?: string): any;
|
|
4
|
+
export function extractExportName(exportValue: any): any;
|
|
4
5
|
//# sourceMappingURL=utils.d.ts.map
|
package/types/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAEA,+DAEC;AAED,yEAKC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAEA,+DAEC;AAED,yEAKC;AAgFD,6DA+DC;AAGD,yDAqCC"}
|