@davidwells/extract-deps 0.0.5 → 0.0.7

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.
Files changed (34) hide show
  1. package/.claude/settings.local.json +7 -1
  2. package/examples/verify-basic.js +2 -0
  3. package/examples/verify-package-entries.js +74 -0
  4. package/package.json +2 -2
  5. package/src/dep-graph.js +82 -14
  6. package/src/get-cjs-exports.js +112 -7
  7. package/src/get-imports.js +1 -0
  8. package/src/utils.js +1 -1
  9. package/src/vendor/inspect-parameters-declaration.js +282 -0
  10. package/src/verify-package-entries.js +228 -0
  11. package/tests/dep-graph.test.js +172 -0
  12. package/tests/fixtures/cjs-broken-example/index.js +8 -0
  13. package/tests/fixtures/cjs-broken-example/one.js +9 -0
  14. package/tests/fixtures/cjs-broken-example/package.json +7 -0
  15. package/tests/fixtures/cjs-broken-example/sub-folder/sub-sub-folder/three.js +6 -0
  16. package/tests/fixtures/cjs-broken-example/sub-folder/two.js +8 -0
  17. package/tests/fixtures/cjs-deep-example/package.json +15 -0
  18. package/tests/fixtures/cjs-example/package.json +7 -0
  19. package/tests/fixtures/dir-index-example/entry.js +6 -0
  20. package/tests/fixtures/dir-index-example/shared-pkg/index.js +4 -0
  21. package/tests/fixtures/esm-broken-fixture/index.js +8 -0
  22. package/tests/fixtures/esm-broken-fixture/one.js +9 -0
  23. package/tests/fixtures/esm-broken-fixture/package.json +15 -0
  24. package/tests/fixtures/esm-broken-fixture/sub-folder/sub-sub-folder/three.js +6 -0
  25. package/tests/fixtures/esm-broken-fixture/sub-folder/sub-sub-folder-two/deep.js +6 -0
  26. package/tests/fixtures/esm-broken-fixture/sub-folder/sub-sub-folder-two/even-deeper/wow-deep.js +5 -0
  27. package/tests/fixtures/esm-broken-fixture/sub-folder/two.js +8 -0
  28. package/tests/fixtures/esm-broken-fixture/valid.js +7 -0
  29. package/tests/fixtures/esm-fixture/package.json +11 -0
  30. package/tests/get-cjs-exports.test.js +171 -0
  31. package/tests/get-imports.test.js +4 -1
  32. package/tests/manual/broken-cjs.js +38 -0
  33. package/tests/manual/broken-esm.js +37 -0
  34. package/tests/verify-package-entries.test.js +272 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "cjs-example",
3
+ "version": "1.0.0",
4
+ "description": "CJS fixture for testing",
5
+ "main": "./index.js",
6
+ "type": "commonjs"
7
+ }
@@ -0,0 +1,6 @@
1
+
2
+ const three = 'three'
3
+
4
+ module.exports = {
5
+ three
6
+ }
@@ -0,0 +1,8 @@
1
+ const { three } = require('./sub-sub-folder/three')
2
+
3
+ const two = 'two'
4
+
5
+ module.exports = {
6
+ two,
7
+ three
8
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "cjs-deep-example",
3
+ "version": "1.0.0",
4
+ "description": "Complex CJS fixture for testing with multiple entry points",
5
+ "main": "./index.js",
6
+ "module": "./d-one.js",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./index.js",
10
+ "import": "./d-one.js"
11
+ },
12
+ "./one": "./d-one.js",
13
+ "./sub": "./d-sub-folder/d-two.js"
14
+ }
15
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "cjs-example",
3
+ "version": "1.0.0",
4
+ "description": "CJS fixture for testing",
5
+ "main": "./index.js",
6
+ "type": "commonjs"
7
+ }
@@ -0,0 +1,6 @@
1
+ // Entry file that imports directory (should resolve to index.js)
2
+ const shared = require('./shared-pkg')
3
+
4
+ module.exports = {
5
+ run: () => shared.helper()
6
+ }
@@ -0,0 +1,4 @@
1
+ // Shared package entry point
2
+ module.exports = {
3
+ helper: () => 'shared'
4
+ }
@@ -0,0 +1,8 @@
1
+ import lodash from 'lodash'
2
+ import { one, two, three } from './one.js'
3
+
4
+ export {
5
+ one,
6
+ two,
7
+ three,
8
+ }
@@ -0,0 +1,9 @@
1
+ import { two, three, four } from './sub-folder/two.js'
2
+
3
+ const one = 'one'
4
+
5
+ export {
6
+ one,
7
+ two,
8
+ three
9
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "esm-fixture",
3
+ "version": "1.0.0",
4
+ "description": "ESM fixture for testing",
5
+ "main": "./index.js",
6
+ "module": "./index.js",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./index.js",
10
+ "./valid": "./valid.js",
11
+ "./deep/deep": "./sub-folder/sub-sub-folder-two/deep.js",
12
+ "./test-deep-missing-import-ref": "./one.js",
13
+ "./non-existent-file": "./non-existent-file.js"
14
+ }
15
+ }
@@ -0,0 +1,6 @@
1
+
2
+ const three = 'three'
3
+
4
+ export {
5
+ three
6
+ }
@@ -0,0 +1,6 @@
1
+ import { wowDeep } from './even-deeper/wow-deep.js'
2
+ const deep = 'deep'
3
+
4
+ export {
5
+ deep
6
+ }
@@ -0,0 +1,5 @@
1
+ const wowDeep = 'wowDeep'
2
+
3
+ export {
4
+ wowDeep
5
+ }
@@ -0,0 +1,8 @@
1
+ import { three } from './sub-sub-folder/three.js'
2
+
3
+ const two = 'two'
4
+
5
+ export {
6
+ two,
7
+ three
8
+ }
@@ -0,0 +1,7 @@
1
+ import { three } from './sub-folder/sub-sub-folder/three.js'
2
+ const valid = 'valid'
3
+
4
+ export {
5
+ valid,
6
+ three
7
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "esm-fixture",
3
+ "version": "1.0.0",
4
+ "description": "ESM fixture for testing",
5
+ "main": "./index.js",
6
+ "module": "./index.js",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./index.js"
10
+ }
11
+ }
@@ -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
- deepLog(importsFound)
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
+ }