@davidwells/extract-deps 0.0.4 → 0.0.6
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/.claude/settings.local.json +7 -1
- package/examples/verify-basic.js +45 -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/examples/verify-package-entries.js +74 -0
- package/package.json +6 -2
- package/src/dep-graph.js +337 -0
- package/src/get-cjs-exports.js +112 -7
- package/src/get-imports.js +1 -0
- package/src/utils.js +1 -1
- package/src/vendor/inspect-parameters-declaration.js +282 -0
- package/src/verify-package-entries.js +228 -0
- package/tests/dep-graph.test.js +358 -0
- package/tests/fixtures/cjs-broken-example/index.js +8 -0
- package/tests/fixtures/cjs-broken-example/one.js +9 -0
- package/tests/fixtures/cjs-broken-example/package.json +7 -0
- package/tests/fixtures/cjs-broken-example/sub-folder/sub-sub-folder/three.js +6 -0
- package/tests/fixtures/cjs-broken-example/sub-folder/two.js +8 -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-deep-example/package.json +15 -0
- package/tests/fixtures/cjs-example/index.js +8 -0
- package/tests/fixtures/cjs-example/one.js +9 -0
- package/tests/fixtures/cjs-example/package.json +7 -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-broken-fixture/index.js +8 -0
- package/tests/fixtures/esm-broken-fixture/one.js +9 -0
- package/tests/fixtures/esm-broken-fixture/package.json +15 -0
- package/tests/fixtures/esm-broken-fixture/sub-folder/sub-sub-folder/three.js +6 -0
- package/tests/fixtures/esm-broken-fixture/sub-folder/sub-sub-folder-two/deep.js +6 -0
- package/tests/fixtures/esm-broken-fixture/sub-folder/sub-sub-folder-two/even-deeper/wow-deep.js +5 -0
- package/tests/fixtures/esm-broken-fixture/sub-folder/two.js +8 -0
- package/tests/fixtures/esm-broken-fixture/valid.js +7 -0
- package/tests/fixtures/esm-fixture/index.js +8 -0
- package/tests/fixtures/esm-fixture/one.js +9 -0
- package/tests/fixtures/esm-fixture/package.json +11 -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 +171 -0
- package/tests/get-imports.test.js +4 -1
- package/tests/manual/broken-cjs.js +38 -0
- package/tests/manual/broken-esm.js +37 -0
- package/tests/verify-package-entries.test.js +272 -0
- 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
|
@@ -588,4 +588,175 @@ module.exports = async function handler(event) {
|
|
|
588
588
|
assert.equal(foundExports[0].exportName, '', 'exportName should empty because it default function')
|
|
589
589
|
})
|
|
590
590
|
|
|
591
|
+
test('should handle Object.defineProperty on module.exports', () => {
|
|
592
|
+
const code = `
|
|
593
|
+
function assembleStyles() {
|
|
594
|
+
return { color: 'red', fontSize: '16px' }
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
Object.defineProperty(module, 'exports', {
|
|
598
|
+
enumerable: true,
|
|
599
|
+
get: assembleStyles
|
|
600
|
+
})
|
|
601
|
+
`
|
|
602
|
+
|
|
603
|
+
const foundExports = getCjsExports(code)
|
|
604
|
+
|
|
605
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
606
|
+
assert.equal(foundExports[0].exportType, 'default', 'Should be default export')
|
|
607
|
+
assert.equal(foundExports[0].exportName, '', 'Default export should have empty name')
|
|
608
|
+
assert.equal(foundExports[0].exportDefinitionName, 'assembleStyles', 'Should extract getter function name')
|
|
609
|
+
assert.ok(foundExports[0].isDefineProperty, 'Should have isDefineProperty flag')
|
|
610
|
+
assert.ok(foundExports[0].exportValue.includes('Object.defineProperty'), 'Should include full defineProperty call')
|
|
611
|
+
})
|
|
612
|
+
|
|
613
|
+
test('should handle Object.defineProperty on exports with named function', () => {
|
|
614
|
+
const code = `
|
|
615
|
+
function getVersion() {
|
|
616
|
+
return '1.0.0'
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
Object.defineProperty(exports, 'version', {
|
|
620
|
+
enumerable: true,
|
|
621
|
+
get: getVersion
|
|
622
|
+
})
|
|
623
|
+
`
|
|
624
|
+
|
|
625
|
+
const foundExports = getCjsExports(code)
|
|
626
|
+
|
|
627
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
628
|
+
assert.equal(foundExports[0].exportType, 'named', 'Should be named export')
|
|
629
|
+
assert.equal(foundExports[0].exportName, 'version', 'Should extract property name')
|
|
630
|
+
assert.equal(foundExports[0].exportDefinitionName, 'getVersion', 'Should extract getter function name')
|
|
631
|
+
assert.ok(foundExports[0].isDefineProperty, 'Should have isDefineProperty flag')
|
|
632
|
+
})
|
|
633
|
+
|
|
634
|
+
test('should handle Object.defineProperty with arrow function getter', () => {
|
|
635
|
+
const code = `
|
|
636
|
+
Object.defineProperty(exports, 'version', {
|
|
637
|
+
enumerable: true,
|
|
638
|
+
get: () => '1.0.0'
|
|
639
|
+
})
|
|
640
|
+
`
|
|
641
|
+
|
|
642
|
+
const foundExports = getCjsExports(code)
|
|
643
|
+
|
|
644
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
645
|
+
assert.equal(foundExports[0].exportType, 'named', 'Should be named export')
|
|
646
|
+
assert.equal(foundExports[0].exportName, 'version', 'Should extract property name')
|
|
647
|
+
assert.equal(foundExports[0].exportDefinitionName, 'arrow function', 'Should detect arrow function')
|
|
648
|
+
assert.ok(foundExports[0].isDefineProperty, 'Should have isDefineProperty flag')
|
|
649
|
+
})
|
|
650
|
+
|
|
651
|
+
test('should handle Object.defineProperty with getter method', () => {
|
|
652
|
+
const code = `
|
|
653
|
+
Object.defineProperty(exports, 'config', {
|
|
654
|
+
enumerable: true,
|
|
655
|
+
get() {
|
|
656
|
+
return { debug: true }
|
|
657
|
+
}
|
|
658
|
+
})
|
|
659
|
+
`
|
|
660
|
+
|
|
661
|
+
const foundExports = getCjsExports(code)
|
|
662
|
+
|
|
663
|
+
assert.ok(foundExports.length === 1, 'Should find 1 export')
|
|
664
|
+
assert.equal(foundExports[0].exportType, 'named', 'Should be named export')
|
|
665
|
+
assert.equal(foundExports[0].exportName, 'config', 'Should extract property name')
|
|
666
|
+
assert.equal(foundExports[0].exportDefinitionName, 'getter method', 'Should detect getter method')
|
|
667
|
+
assert.ok(foundExports[0].isDefineProperty, 'Should have isDefineProperty flag')
|
|
668
|
+
})
|
|
669
|
+
|
|
670
|
+
test('should handle multiple Object.defineProperty exports', () => {
|
|
671
|
+
const code = `
|
|
672
|
+
Object.defineProperty(exports, 'foo', {
|
|
673
|
+
get: getFoo
|
|
674
|
+
})
|
|
675
|
+
|
|
676
|
+
Object.defineProperty(exports, 'bar', {
|
|
677
|
+
get: () => 'bar value'
|
|
678
|
+
})
|
|
679
|
+
|
|
680
|
+
Object.defineProperty(exports, 'baz', {
|
|
681
|
+
get() {
|
|
682
|
+
return 'baz value'
|
|
683
|
+
}
|
|
684
|
+
})
|
|
685
|
+
`
|
|
686
|
+
|
|
687
|
+
const foundExports = getCjsExports(code)
|
|
688
|
+
|
|
689
|
+
assert.ok(foundExports.length === 3, 'Should find 3 exports')
|
|
690
|
+
|
|
691
|
+
const fooExport = foundExports.find(exp => exp.exportName === 'foo')
|
|
692
|
+
assert.ok(fooExport, 'Should find foo export')
|
|
693
|
+
assert.equal(fooExport.exportDefinitionName, 'getFoo', 'Should extract named function')
|
|
694
|
+
|
|
695
|
+
const barExport = foundExports.find(exp => exp.exportName === 'bar')
|
|
696
|
+
assert.ok(barExport, 'Should find bar export')
|
|
697
|
+
assert.equal(barExport.exportDefinitionName, 'arrow function', 'Should detect arrow function')
|
|
698
|
+
|
|
699
|
+
const bazExport = foundExports.find(exp => exp.exportName === 'baz')
|
|
700
|
+
assert.ok(bazExport, 'Should find baz export')
|
|
701
|
+
assert.equal(bazExport.exportDefinitionName, 'getter method', 'Should detect getter method')
|
|
702
|
+
|
|
703
|
+
foundExports.forEach(exp => {
|
|
704
|
+
assert.ok(exp.isDefineProperty, 'All should have isDefineProperty flag')
|
|
705
|
+
})
|
|
706
|
+
})
|
|
707
|
+
|
|
708
|
+
test('should handle mixed exports with Object.defineProperty', () => {
|
|
709
|
+
const code = `
|
|
710
|
+
// Standard exports
|
|
711
|
+
module.exports.hello = function() { return 'hello' }
|
|
712
|
+
exports.foo = function() {}
|
|
713
|
+
exports.bar = 'bar'
|
|
714
|
+
|
|
715
|
+
// Object.defineProperty exports
|
|
716
|
+
function assembleStyles() {
|
|
717
|
+
return { color: 'red' }
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
Object.defineProperty(module, 'exports', {
|
|
721
|
+
enumerable: true,
|
|
722
|
+
get: assembleStyles
|
|
723
|
+
})
|
|
724
|
+
|
|
725
|
+
Object.defineProperty(exports, 'version', {
|
|
726
|
+
enumerable: true,
|
|
727
|
+
get: () => '1.0.0'
|
|
728
|
+
})
|
|
729
|
+
`
|
|
730
|
+
|
|
731
|
+
const foundExports = getCjsExports(code)
|
|
732
|
+
|
|
733
|
+
assert.ok(foundExports.length === 5, 'Should find 5 exports total')
|
|
734
|
+
|
|
735
|
+
// Check standard exports
|
|
736
|
+
const helloExport = foundExports.find(exp => exp.exportName === 'hello')
|
|
737
|
+
assert.ok(helloExport, 'Should find hello export')
|
|
738
|
+
assert.ok(!helloExport.isDefineProperty, 'Standard export should not have isDefineProperty flag')
|
|
739
|
+
|
|
740
|
+
const barExport = foundExports.find(exp => exp.exportName === 'bar')
|
|
741
|
+
assert.ok(barExport, 'Should find bar export')
|
|
742
|
+
assert.equal(barExport.exportValue, "'bar'", 'Should only capture bar value, not following code')
|
|
743
|
+
|
|
744
|
+
// Check Object.defineProperty exports
|
|
745
|
+
const definePropertyExports = foundExports.filter(exp => exp.isDefineProperty)
|
|
746
|
+
assert.equal(definePropertyExports.length, 2, 'Should find 2 Object.defineProperty exports')
|
|
747
|
+
|
|
748
|
+
const moduleExport = definePropertyExports.find(exp => exp.exportType === 'default')
|
|
749
|
+
assert.ok(moduleExport, 'Should find module.exports defineProperty')
|
|
750
|
+
assert.equal(moduleExport.exportDefinitionName, 'assembleStyles', 'Should extract getter name')
|
|
751
|
+
|
|
752
|
+
const versionExport = definePropertyExports.find(exp => exp.exportName === 'version')
|
|
753
|
+
assert.ok(versionExport, 'Should find version defineProperty')
|
|
754
|
+
assert.equal(versionExport.exportDefinitionName, 'arrow function', 'Should detect arrow function')
|
|
755
|
+
|
|
756
|
+
// Check sorting by index
|
|
757
|
+
for (let i = 1; i < foundExports.length; i++) {
|
|
758
|
+
assert.ok(foundExports[i].index >= foundExports[i-1].index, 'Exports should be sorted by index')
|
|
759
|
+
}
|
|
760
|
+
})
|
|
761
|
+
|
|
591
762
|
test.run()
|
|
@@ -96,7 +96,7 @@ test('get jsDoc Imports', async () => {
|
|
|
96
96
|
const importsFound = getTypeImports(code)
|
|
97
97
|
/*
|
|
98
98
|
console.log('importsFound')
|
|
99
|
-
|
|
99
|
+
console.log(importsFound)
|
|
100
100
|
/** */
|
|
101
101
|
assert.equal(normalizeTestResult(importsFound), [
|
|
102
102
|
{
|
|
@@ -104,6 +104,7 @@ test('get jsDoc Imports', async () => {
|
|
|
104
104
|
importPath: './foo',
|
|
105
105
|
importName: 'hdhdhdhdhddh',
|
|
106
106
|
isImport: true,
|
|
107
|
+
isTypeImport: true,
|
|
107
108
|
isRelative: true
|
|
108
109
|
},
|
|
109
110
|
{
|
|
@@ -111,6 +112,7 @@ test('get jsDoc Imports', async () => {
|
|
|
111
112
|
importPath: 'lodash',
|
|
112
113
|
importName: 'omit',
|
|
113
114
|
isImport: true,
|
|
115
|
+
isTypeImport: true,
|
|
114
116
|
isRelative: false
|
|
115
117
|
},
|
|
116
118
|
{
|
|
@@ -118,6 +120,7 @@ test('get jsDoc Imports', async () => {
|
|
|
118
120
|
importPath: 'uvu/assert',
|
|
119
121
|
importName: '',
|
|
120
122
|
isImport: true,
|
|
123
|
+
isTypeImport: true,
|
|
121
124
|
isRelative: false
|
|
122
125
|
}
|
|
123
126
|
])
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Verify package.json entry points and their dependencies
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const { getPackageEntryPoints, verifyPackageEntries } = require('../../src/verify-package-entries')
|
|
4
|
+
|
|
5
|
+
if (require.main === module) {
|
|
6
|
+
// const pkgPath = path.resolve(__dirname, '../fixtures/esm-broken-fixture/package.json')
|
|
7
|
+
const pkgPath = path.resolve(__dirname, '../fixtures/cjs-broken-example/package.json')
|
|
8
|
+
console.log('=== Package Entry Points ===\n')
|
|
9
|
+
const entryPoints = getPackageEntryPoints(pkgPath)
|
|
10
|
+
entryPoints.forEach(ep => {
|
|
11
|
+
console.log(`${ep.field}: ${ep.path}`)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
console.log('\n=== Verification Results ===\n')
|
|
15
|
+
const throwIfErrors = false
|
|
16
|
+
const results = verifyPackageEntries(pkgPath, { throwIfErrors })
|
|
17
|
+
console.log('results', results)
|
|
18
|
+
|
|
19
|
+
results.entryPoints.forEach(ep => {
|
|
20
|
+
console.log('\n──────────────────────────────────────────────────────────────')
|
|
21
|
+
console.log('PATH: ', ep.path)
|
|
22
|
+
console.log(`Field: "${ep.field}"`)
|
|
23
|
+
console.log(`Valid: ${ep.valid ? '✅' : '❌'}`)
|
|
24
|
+
if (ep.sourceFiles) {
|
|
25
|
+
console.log(`srcFiles: ${ep.sourceFiles.length} files`)
|
|
26
|
+
ep.sourceFiles.forEach(sf => {
|
|
27
|
+
console.log(`- ${sf}`)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
if (ep.error) {
|
|
31
|
+
console.log(`Error:`)
|
|
32
|
+
console.log(ep.error.message)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
console.log('\n──────────────────────────────────────────────────────────────')
|
|
36
|
+
console.log(`\nTotal unique dependencies: ${results.sourceFiles.size}`)
|
|
37
|
+
console.log(`Total errors: ${results.errors.length}`)
|
|
38
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Verify package.json entry points and their dependencies
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const { getPackageEntryPoints, verifyPackageEntries } = require('../../src/verify-package-entries')
|
|
4
|
+
|
|
5
|
+
if (require.main === module) {
|
|
6
|
+
const pkgPath = path.resolve(__dirname, '../fixtures/esm-broken-fixture/package.json')
|
|
7
|
+
console.log('=== Package Entry Points ===\n')
|
|
8
|
+
const entryPoints = getPackageEntryPoints(pkgPath)
|
|
9
|
+
entryPoints.forEach(ep => {
|
|
10
|
+
console.log(`${ep.field}: ${ep.path}`)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
console.log('\n=== Verification Results ===\n')
|
|
14
|
+
const throwIfErrors = false
|
|
15
|
+
const results = verifyPackageEntries(pkgPath, { throwIfErrors })
|
|
16
|
+
console.log('results', results)
|
|
17
|
+
|
|
18
|
+
results.entryPoints.forEach(ep => {
|
|
19
|
+
console.log('\n──────────────────────────────────────────────────────────────')
|
|
20
|
+
console.log('PATH: ', ep.path)
|
|
21
|
+
console.log(`Field: "${ep.field}"`)
|
|
22
|
+
console.log(`Valid: ${ep.valid ? '✅' : '❌'}`)
|
|
23
|
+
if (ep.sourceFiles) {
|
|
24
|
+
console.log(`srcFiles: ${ep.sourceFiles.length} files`)
|
|
25
|
+
}
|
|
26
|
+
if (ep.error) {
|
|
27
|
+
console.log(`Error:`)
|
|
28
|
+
console.log(ep.error.message)
|
|
29
|
+
}
|
|
30
|
+
ep.sourceFiles.forEach(dep => {
|
|
31
|
+
console.log(`- ${dep}`)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
console.log('\n──────────────────────────────────────────────────────────────')
|
|
35
|
+
console.log(`\nTotal unique dependencies: ${results.sourceFiles.size}`)
|
|
36
|
+
console.log(`Total errors: ${results.errors.length}`)
|
|
37
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// Test package.json entry point verification
|
|
2
|
+
const { test } = require('uvu')
|
|
3
|
+
const assert = require('uvu/assert')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const { getPackageEntryPoints, verifyPackageEntries, collectEntryPoints } = require('../src/verify-package-entries')
|
|
6
|
+
|
|
7
|
+
const CJS_EXAMPLE_PKG = path.resolve(__dirname, './fixtures/cjs-example/package.json')
|
|
8
|
+
const ESM_FIXTURE_PKG = path.resolve(__dirname, './fixtures/esm-fixture/package.json')
|
|
9
|
+
const CJS_DEEP_EXAMPLE_PKG = path.resolve(__dirname, './fixtures/cjs-deep-example/package.json')
|
|
10
|
+
|
|
11
|
+
const packageStub = {
|
|
12
|
+
"name": "my-package",
|
|
13
|
+
"version": "1.0.0",
|
|
14
|
+
"description": "Example package with all entry points",
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"browser": "./dist/browser.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"bin": {
|
|
20
|
+
"my-cli": "./bin/cli.js"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.cjs",
|
|
27
|
+
"browser": "./dist/browser.js"
|
|
28
|
+
},
|
|
29
|
+
"./dep-graph": "./src/dep-graph.js",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"bin"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test('getPackageEntryPoints should extract all entry points from package.json', () => {
|
|
39
|
+
const entryPoints = collectEntryPoints(packageStub, 'dir-path')
|
|
40
|
+
console.log('entryPoints', entryPoints)
|
|
41
|
+
assert.ok(Array.isArray(entryPoints), 'Should return an array')
|
|
42
|
+
assert.ok(entryPoints.length > 0, 'Should have at least one entry point')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// getPackageEntryPoints tests
|
|
46
|
+
test('getPackageEntryPoints should extract main field', () => {
|
|
47
|
+
const entryPoints = getPackageEntryPoints(CJS_EXAMPLE_PKG)
|
|
48
|
+
console.log('entryPoints', entryPoints)
|
|
49
|
+
|
|
50
|
+
assert.ok(Array.isArray(entryPoints), 'Should return an array')
|
|
51
|
+
assert.ok(entryPoints.length > 0, 'Should have at least one entry point')
|
|
52
|
+
|
|
53
|
+
const mainEntry = entryPoints.find(ep => ep.field === 'main')
|
|
54
|
+
assert.ok(mainEntry, 'Should have main entry point')
|
|
55
|
+
assert.is(mainEntry.path, './index.js', 'Main path should be ./index.js')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('getPackageEntryPoints should extract multiple fields', () => {
|
|
59
|
+
const entryPoints = getPackageEntryPoints(ESM_FIXTURE_PKG)
|
|
60
|
+
|
|
61
|
+
const fields = entryPoints.map(ep => ep.field)
|
|
62
|
+
assert.ok(fields.includes('main'), 'Should include main')
|
|
63
|
+
assert.ok(fields.includes('module'), 'Should include module')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('getPackageEntryPoints should extract exports field', () => {
|
|
67
|
+
const entryPoints = getPackageEntryPoints(ESM_FIXTURE_PKG)
|
|
68
|
+
|
|
69
|
+
const exportsEntry = entryPoints.find(ep => ep.field.startsWith('exports'))
|
|
70
|
+
assert.ok(exportsEntry, 'Should have exports entry point')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('getPackageEntryPoints should handle complex exports with conditionals', () => {
|
|
74
|
+
const entryPoints = getPackageEntryPoints(CJS_DEEP_EXAMPLE_PKG)
|
|
75
|
+
|
|
76
|
+
const fields = entryPoints.map(ep => ep.field)
|
|
77
|
+
|
|
78
|
+
// Should extract conditional exports
|
|
79
|
+
assert.ok(fields.some(f => f.includes('require')), 'Should extract require conditional')
|
|
80
|
+
assert.ok(fields.some(f => f.includes('import')), 'Should extract import conditional')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('getPackageEntryPoints should skip .d.ts files', () => {
|
|
84
|
+
const entryPoints = getPackageEntryPoints(ESM_FIXTURE_PKG)
|
|
85
|
+
|
|
86
|
+
const hasDts = entryPoints.some(ep => ep.path.endsWith('.d.ts'))
|
|
87
|
+
assert.not(hasDts, 'Should not include .d.ts files')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('getPackageEntryPoints should skip .json files', () => {
|
|
91
|
+
const entryPoints = getPackageEntryPoints(ESM_FIXTURE_PKG)
|
|
92
|
+
|
|
93
|
+
const hasJson = entryPoints.some(ep => ep.path.endsWith('.json'))
|
|
94
|
+
assert.not(hasJson, 'Should not include .json files')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('getPackageEntryPoints should resolve absolute paths', () => {
|
|
98
|
+
const entryPoints = getPackageEntryPoints(CJS_EXAMPLE_PKG)
|
|
99
|
+
|
|
100
|
+
entryPoints.forEach(ep => {
|
|
101
|
+
assert.ok(path.isAbsolute(ep.resolvedPath), 'Resolved path should be absolute')
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('getPackageEntryPoints should extract nested exports', () => {
|
|
106
|
+
const entryPoints = getPackageEntryPoints(CJS_DEEP_EXAMPLE_PKG)
|
|
107
|
+
|
|
108
|
+
const fields = entryPoints.map(ep => ep.field)
|
|
109
|
+
|
|
110
|
+
// Should have nested paths like exports./one, exports./sub
|
|
111
|
+
assert.ok(fields.some(f => f.includes('one')), 'Should extract nested export "./one"')
|
|
112
|
+
assert.ok(fields.some(f => f.includes('sub')), 'Should extract nested export "./sub"')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// verifyPackageEntries tests
|
|
116
|
+
test('verifyPackageEntries should return correct structure', () => {
|
|
117
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG)
|
|
118
|
+
console.log('results', results)
|
|
119
|
+
|
|
120
|
+
assert.ok(results.entryPoints, 'Should have entryPoints')
|
|
121
|
+
assert.ok(results.sourceFiles, 'Should have sourceFiles')
|
|
122
|
+
assert.ok(results.errors, 'Should have errors')
|
|
123
|
+
|
|
124
|
+
assert.ok(Array.isArray(results.entryPoints), 'entryPoints should be array')
|
|
125
|
+
assert.ok(results.sourceFiles instanceof Set, 'sourceFiles should be Set')
|
|
126
|
+
assert.ok(Array.isArray(results.errors), 'errors should be array')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('verifyPackageEntries should verify valid entry points', () => {
|
|
130
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG)
|
|
131
|
+
|
|
132
|
+
const validCount = results.entryPoints.filter(ep => ep.valid).length
|
|
133
|
+
assert.ok(validCount > 0, 'Should have at least one valid entry point')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('verifyPackageEntries should collect dependencies by default', () => {
|
|
137
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG)
|
|
138
|
+
|
|
139
|
+
results.entryPoints.forEach(ep => {
|
|
140
|
+
if (ep.valid) {
|
|
141
|
+
assert.ok(ep.sourceFiles, 'Valid entry should have sourceFiles')
|
|
142
|
+
assert.ok(Array.isArray(ep.sourceFiles), 'sourceFiles should be array')
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('verifyPackageEntries should deduplicate dependencies in sourceFiles', () => {
|
|
148
|
+
const results = verifyPackageEntries(CJS_DEEP_EXAMPLE_PKG)
|
|
149
|
+
|
|
150
|
+
// Count total sourceFiles from all entry points
|
|
151
|
+
let totalDeps = 0
|
|
152
|
+
results.entryPoints.forEach(ep => {
|
|
153
|
+
if (ep.sourceFiles) {
|
|
154
|
+
totalDeps += ep.sourceFiles.length
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
// sourceFiles should be less than or equal to total (deduplication)
|
|
159
|
+
assert.ok(results.sourceFiles.size <= totalDeps, 'sourceFiles should deduplicate')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('verifyPackageEntries should work with collectDeps option', () => {
|
|
163
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG, { collectDeps: true })
|
|
164
|
+
|
|
165
|
+
assert.ok(results.sourceFiles.size > 0, 'Should collect dependencies')
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test('verifyPackageEntries should skip sourceFiles when collectDeps is false', () => {
|
|
169
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG, { collectDeps: false })
|
|
170
|
+
console.log('results', results)
|
|
171
|
+
results.entryPoints.forEach(ep => {
|
|
172
|
+
console.log('ep', ep)
|
|
173
|
+
assert.equal(ep.sourceFiles, [], 'Should not collect sourceFiles when collectDeps is false')
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
assert.is(results.sourceFiles.size, 0, 'sourceFiles should be empty')
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('verifyPackageEntries should work with verifyGraph option', () => {
|
|
180
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG, { verifyGraph: true })
|
|
181
|
+
|
|
182
|
+
// Should complete without throwing
|
|
183
|
+
assert.ok(results, 'Should return results')
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('verifyPackageEntries should skip verification when verifyGraph is false', () => {
|
|
187
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG, { verifyGraph: false })
|
|
188
|
+
|
|
189
|
+
// Should still collect sourceFiles but skip verification
|
|
190
|
+
assert.ok(results.sourceFiles.size > 0, 'Should still collect sourceFiles')
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
test('verifyPackageEntries should collect all errors', () => {
|
|
194
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG)
|
|
195
|
+
|
|
196
|
+
// With valid fixtures, should have 0 errors
|
|
197
|
+
assert.is(results.errors.length, 0, 'Valid fixtures should have no errors')
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
test('verifyPackageEntries should mark entry as invalid on error', () => {
|
|
201
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG)
|
|
202
|
+
|
|
203
|
+
results.entryPoints.forEach(ep => {
|
|
204
|
+
if (!ep.valid) {
|
|
205
|
+
assert.ok(ep.error, 'Invalid entry should have error')
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test('verifyPackageEntries should process all entries even if one fails', () => {
|
|
211
|
+
const results = verifyPackageEntries(CJS_DEEP_EXAMPLE_PKG)
|
|
212
|
+
|
|
213
|
+
// Should process all 6 entry points from deep example
|
|
214
|
+
assert.ok(results.entryPoints.length >= 6, 'Should process all entry points')
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
test('verifyPackageEntries should collect sourceFiles for each entry separately', () => {
|
|
218
|
+
const results = verifyPackageEntries(CJS_DEEP_EXAMPLE_PKG)
|
|
219
|
+
|
|
220
|
+
const validEntries = results.entryPoints.filter(ep => ep.valid)
|
|
221
|
+
|
|
222
|
+
validEntries.forEach(ep => {
|
|
223
|
+
assert.ok(ep.sourceFiles, 'Each entry should have its own sourceFiles')
|
|
224
|
+
assert.ok(Array.isArray(ep.sourceFiles), 'sourceFiles should be array')
|
|
225
|
+
assert.ok(ep.sourceFiles.length > 0, 'sourceFiles should not be empty')
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
test('verifyPackageEntries should work with simple package', () => {
|
|
230
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG)
|
|
231
|
+
|
|
232
|
+
assert.is(results.errors.length, 0, 'Should have no errors')
|
|
233
|
+
assert.ok(results.sourceFiles.size > 0, 'Should have dependencies')
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('verifyPackageEntries should work with ESM package', () => {
|
|
237
|
+
const results = verifyPackageEntries(ESM_FIXTURE_PKG)
|
|
238
|
+
|
|
239
|
+
assert.is(results.errors.length, 0, 'Should have no errors')
|
|
240
|
+
assert.ok(results.sourceFiles.size > 0, 'Should have dependencies')
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
test('verifyPackageEntries should work with complex package', () => {
|
|
244
|
+
const results = verifyPackageEntries(CJS_DEEP_EXAMPLE_PKG)
|
|
245
|
+
|
|
246
|
+
assert.is(results.errors.length, 0, 'Should have no errors')
|
|
247
|
+
assert.ok(results.sourceFiles.size > 0, 'Should have dependencies')
|
|
248
|
+
assert.ok(results.entryPoints.length >= 6, 'Should have multiple entry points')
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
test('verifyPackageEntries should include entry point file in sourceFiles', () => {
|
|
252
|
+
const results = verifyPackageEntries(CJS_EXAMPLE_PKG)
|
|
253
|
+
|
|
254
|
+
const mainEntry = results.entryPoints.find(ep => ep.field === 'main')
|
|
255
|
+
assert.ok(mainEntry, 'Should have main entry')
|
|
256
|
+
assert.ok(mainEntry.sourceFiles, 'Should have sourceFiles')
|
|
257
|
+
|
|
258
|
+
// Entry point file should be in its sourceFiles (as it's the last file in build order)
|
|
259
|
+
const hasEntryInDeps = mainEntry.sourceFiles.some(dep => dep === mainEntry.resolvedPath)
|
|
260
|
+
assert.ok(hasEntryInDeps, 'Entry point should be in its own sourceFiles list')
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
test('verifyPackageEntries should collect unique sourceFiles across all entries', () => {
|
|
264
|
+
const results = verifyPackageEntries(CJS_DEEP_EXAMPLE_PKG)
|
|
265
|
+
|
|
266
|
+
const sourceFilesArray = Array.from(results.sourceFiles)
|
|
267
|
+
const uniqueDeps = [...new Set(sourceFilesArray)]
|
|
268
|
+
|
|
269
|
+
assert.is(sourceFilesArray.length, uniqueDeps.length, 'sourceFiles should not have duplicates')
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
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
|