@davidwells/extract-deps 0.0.1 → 0.0.3
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 +9 -0
- package/package.json +1 -1
- package/src/get-cjs-exports.js +351 -0
- package/src/get-exports.js +6 -3
- package/src/index.js +15 -1
- package/src/utils.js +104 -6
- package/tests/get-cjs-exports.test.js +539 -0
- package/tests/get-exports.test.js +136 -99
|
@@ -22,39 +22,39 @@ export default 42
|
|
|
22
22
|
export default () => {}
|
|
23
23
|
`
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
assert.ok(
|
|
28
|
-
|
|
25
|
+
const foundExports = getDefaultExports(code)
|
|
26
|
+
|
|
27
|
+
assert.ok(foundExports.length === 6, 'Should find 6 default exports')
|
|
28
|
+
|
|
29
29
|
// Check function export
|
|
30
|
-
const functionExport =
|
|
30
|
+
const functionExport = foundExports.find(exp => exp.exportName === 'myFunction')
|
|
31
31
|
assert.ok(functionExport, 'Should find function export')
|
|
32
32
|
assert.equal(functionExport.exportType, 'default')
|
|
33
33
|
assert.equal(functionExport.exportValue, 'function myFunction')
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
// Check class export
|
|
36
|
-
const classExport =
|
|
36
|
+
const classExport = foundExports.find(exp => exp.exportName === 'MyClass')
|
|
37
37
|
assert.ok(classExport, 'Should find class export')
|
|
38
38
|
assert.equal(classExport.exportType, 'default')
|
|
39
39
|
assert.equal(classExport.exportValue, 'class MyClass')
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
// Check object literal
|
|
42
|
-
const objectExport =
|
|
42
|
+
const objectExport = foundExports.find(exp => exp.exportName === 'literal')
|
|
43
43
|
assert.ok(objectExport, 'Should find object literal export')
|
|
44
44
|
assert.equal(objectExport.exportValue, "{ foo: 'bar' }")
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
// Check array literal
|
|
47
|
-
const arrayExport =
|
|
47
|
+
const arrayExport = foundExports.find(exp => exp.exportValue === '[1, 2, 3]')
|
|
48
48
|
assert.ok(arrayExport, 'Should find array literal export')
|
|
49
49
|
assert.equal(arrayExport.exportName, 'literal')
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
// Check number literal
|
|
52
|
-
const numberExport =
|
|
52
|
+
const numberExport = foundExports.find(exp => exp.exportValue === '42')
|
|
53
53
|
assert.ok(numberExport, 'Should find number literal export')
|
|
54
54
|
assert.equal(numberExport.exportName, '42')
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
// Check arrow function
|
|
57
|
-
const arrowExport =
|
|
57
|
+
const arrowExport = foundExports.find(exp => exp.exportValue === '() =>')
|
|
58
58
|
assert.ok(arrowExport, 'Should find arrow function export')
|
|
59
59
|
assert.equal(arrowExport.exportName, 'anonymous')
|
|
60
60
|
})
|
|
@@ -69,19 +69,19 @@ export class MyClass {}
|
|
|
69
69
|
export async function asyncFunction() {}
|
|
70
70
|
`
|
|
71
71
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
assert.ok(
|
|
75
|
-
|
|
76
|
-
const exportNames =
|
|
72
|
+
const foundExports = getNamedExports(code)
|
|
73
|
+
|
|
74
|
+
assert.ok(foundExports.length === 6, 'Should find 6 named exports')
|
|
75
|
+
|
|
76
|
+
const exportNames = foundExports.map(exp => exp.exportName)
|
|
77
77
|
assert.ok(exportNames.includes('myVariable'), 'Should find const export')
|
|
78
78
|
assert.ok(exportNames.includes('anotherVariable'), 'Should find let export')
|
|
79
79
|
assert.ok(exportNames.includes('thirdVariable'), 'Should find var export')
|
|
80
80
|
assert.ok(exportNames.includes('myFunction'), 'Should find function export')
|
|
81
81
|
assert.ok(exportNames.includes('MyClass'), 'Should find class export')
|
|
82
82
|
assert.ok(exportNames.includes('asyncFunction'), 'Should find async function export')
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
|
|
84
|
+
foundExports.forEach(exp => {
|
|
85
85
|
assert.equal(exp.exportType, 'named')
|
|
86
86
|
assert.ok(exp.isExport)
|
|
87
87
|
})
|
|
@@ -96,28 +96,28 @@ export { default as aliasedDefault } from './module'
|
|
|
96
96
|
export { Component, Button } from './components'
|
|
97
97
|
`
|
|
98
98
|
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
assert.ok(
|
|
102
|
-
|
|
99
|
+
const foundExports = getNamedDeclarationExports(code)
|
|
100
|
+
|
|
101
|
+
assert.ok(foundExports.length === 8, 'Should find 8 named declaration exports')
|
|
102
|
+
|
|
103
103
|
// Check simple exports
|
|
104
|
-
const simpleExports =
|
|
104
|
+
const simpleExports = foundExports.filter(exp => !exp.exportAlias)
|
|
105
105
|
assert.ok(simpleExports.length === 6, 'Should have 6 simple exports')
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
// Check aliased exports
|
|
108
|
-
const aliasedExports =
|
|
108
|
+
const aliasedExports = foundExports.filter(exp => exp.exportAlias)
|
|
109
109
|
assert.ok(aliasedExports.length === 2, 'Should have 2 aliased exports')
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
// Check specific aliases
|
|
112
|
-
const aliasedFunction =
|
|
112
|
+
const aliasedFunction = foundExports.find(exp => exp.exportAlias === 'aliasedFunction')
|
|
113
113
|
assert.ok(aliasedFunction, 'Should find aliased function export')
|
|
114
114
|
assert.equal(aliasedFunction.exportName, 'myFunction')
|
|
115
|
-
|
|
116
|
-
const aliasedDefault =
|
|
115
|
+
|
|
116
|
+
const aliasedDefault = foundExports.find(exp => exp.exportAlias === 'aliasedDefault')
|
|
117
117
|
assert.ok(aliasedDefault, 'Should find aliased default export')
|
|
118
118
|
assert.equal(aliasedDefault.exportName, 'default')
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
|
|
120
|
+
foundExports.forEach(exp => {
|
|
121
121
|
assert.equal(exp.exportType, 'named')
|
|
122
122
|
assert.ok(exp.isExport)
|
|
123
123
|
})
|
|
@@ -130,16 +130,16 @@ export * from './utils'
|
|
|
130
130
|
export * from '@angular/core'
|
|
131
131
|
`
|
|
132
132
|
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
assert.ok(
|
|
136
|
-
|
|
137
|
-
const fromModules =
|
|
133
|
+
const foundExports = getAllExports(code)
|
|
134
|
+
|
|
135
|
+
assert.ok(foundExports.length === 3, 'Should find 3 all exports')
|
|
136
|
+
|
|
137
|
+
const fromModules = foundExports.map(exp => exp.from)
|
|
138
138
|
assert.ok(fromModules.includes('./module'), 'Should export all from ./module')
|
|
139
139
|
assert.ok(fromModules.includes('./utils'), 'Should export all from ./utils')
|
|
140
140
|
assert.ok(fromModules.includes('@angular/core'), 'Should export all from @angular/core')
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
|
|
142
|
+
foundExports.forEach(exp => {
|
|
143
143
|
assert.equal(exp.exportType, 'all')
|
|
144
144
|
assert.ok(exp.isExport)
|
|
145
145
|
})
|
|
@@ -152,21 +152,21 @@ export * as utils from './utils'
|
|
|
152
152
|
export * as angular from '@angular/core'
|
|
153
153
|
`
|
|
154
154
|
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
assert.ok(
|
|
158
|
-
|
|
159
|
-
const namespaceNames =
|
|
155
|
+
const foundExports = getNamespaceExports(code)
|
|
156
|
+
|
|
157
|
+
assert.ok(foundExports.length === 3, 'Should find 3 namespace exports')
|
|
158
|
+
|
|
159
|
+
const namespaceNames = foundExports.map(exp => exp.namespace)
|
|
160
160
|
assert.ok(namespaceNames.includes('namespace'), 'Should find namespace export')
|
|
161
161
|
assert.ok(namespaceNames.includes('utils'), 'Should find utils namespace export')
|
|
162
162
|
assert.ok(namespaceNames.includes('angular'), 'Should find angular namespace export')
|
|
163
|
-
|
|
164
|
-
const fromModules =
|
|
163
|
+
|
|
164
|
+
const fromModules = foundExports.map(exp => exp.from)
|
|
165
165
|
assert.ok(fromModules.includes('./module'), 'Should export namespace from ./module')
|
|
166
166
|
assert.ok(fromModules.includes('./utils'), 'Should export namespace from ./utils')
|
|
167
167
|
assert.ok(fromModules.includes('@angular/core'), 'Should export namespace from @angular/core')
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
|
|
169
|
+
foundExports.forEach(exp => {
|
|
170
170
|
assert.equal(exp.exportType, 'namespace')
|
|
171
171
|
assert.ok(exp.isExport)
|
|
172
172
|
})
|
|
@@ -180,17 +180,17 @@ export type User = { id: string; name: string }
|
|
|
180
180
|
export interface ComponentProps { children: React.ReactNode }
|
|
181
181
|
`
|
|
182
182
|
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
assert.ok(
|
|
186
|
-
|
|
187
|
-
const typeNames =
|
|
183
|
+
const foundExports = getTypeExports(code)
|
|
184
|
+
|
|
185
|
+
assert.ok(foundExports.length === 4, 'Should find 4 type exports')
|
|
186
|
+
|
|
187
|
+
const typeNames = foundExports.map(exp => exp.exportName)
|
|
188
188
|
assert.ok(typeNames.includes('MyType'), 'Should find MyType export')
|
|
189
189
|
assert.ok(typeNames.includes('MyInterface'), 'Should find MyInterface export')
|
|
190
190
|
assert.ok(typeNames.includes('User'), 'Should find User type export')
|
|
191
191
|
assert.ok(typeNames.includes('ComponentProps'), 'Should find ComponentProps interface export')
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
|
|
193
|
+
foundExports.forEach(exp => {
|
|
194
194
|
assert.equal(exp.exportType, 'type')
|
|
195
195
|
assert.ok(exp.isExport)
|
|
196
196
|
})
|
|
@@ -203,25 +203,25 @@ export { Component } from './component' with { type: 'css' }
|
|
|
203
203
|
export { data } from './data.json' assert { type: 'json' }
|
|
204
204
|
`
|
|
205
205
|
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
assert.ok(
|
|
209
|
-
|
|
206
|
+
const foundExports = getAssertionExports(code)
|
|
207
|
+
|
|
208
|
+
assert.ok(foundExports.length === 3, 'Should find 3 assertion exports')
|
|
209
|
+
|
|
210
210
|
// Check JSON assertion
|
|
211
|
-
const jsonExports =
|
|
211
|
+
const jsonExports = foundExports.filter(exp => exp.assertion.includes('json'))
|
|
212
212
|
assert.ok(jsonExports.length === 2, 'Should find 2 JSON assertion exports')
|
|
213
|
-
|
|
213
|
+
|
|
214
214
|
// Check CSS assertion
|
|
215
|
-
const cssExports =
|
|
215
|
+
const cssExports = foundExports.filter(exp => exp.assertion.includes('css'))
|
|
216
216
|
assert.ok(cssExports.length === 1, 'Should find 1 CSS assertion export')
|
|
217
|
-
|
|
217
|
+
|
|
218
218
|
// Check assertion types
|
|
219
|
-
const assertExports =
|
|
220
|
-
const withExports =
|
|
219
|
+
const assertExports = foundExports.filter(exp => exp.assertionType === 'assert')
|
|
220
|
+
const withExports = foundExports.filter(exp => exp.assertionType === 'with')
|
|
221
221
|
assert.ok(assertExports.length === 2, 'Should find 2 assert exports')
|
|
222
222
|
assert.ok(withExports.length === 1, 'Should find 1 with export')
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
|
|
224
|
+
foundExports.forEach(exp => {
|
|
225
225
|
assert.equal(exp.exportType, 'assertion')
|
|
226
226
|
assert.ok(exp.isExport)
|
|
227
227
|
assert.ok(exp.isAssertion)
|
|
@@ -251,33 +251,33 @@ export type MyType = string
|
|
|
251
251
|
export interface MyInterface {}
|
|
252
252
|
`
|
|
253
253
|
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
assert.ok(
|
|
257
|
-
|
|
258
|
-
const exportTypes =
|
|
254
|
+
const foundExports = getExports(code)
|
|
255
|
+
|
|
256
|
+
assert.ok(foundExports.length === 11, 'Should find 11 total exports')
|
|
257
|
+
|
|
258
|
+
const exportTypes = foundExports.map(exp => exp.exportType)
|
|
259
259
|
const defaultCount = exportTypes.filter(type => type === 'default').length
|
|
260
260
|
const namedCount = exportTypes.filter(type => type === 'named').length
|
|
261
261
|
const allCount = exportTypes.filter(type => type === 'all').length
|
|
262
262
|
const namespaceCount = exportTypes.filter(type => type === 'namespace').length
|
|
263
263
|
const typeCount = exportTypes.filter(type => type === 'type').length
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
assert.equal(defaultCount, 2, 'Should have 2 default exports')
|
|
266
266
|
assert.equal(namedCount, 5, 'Should have 5 named exports')
|
|
267
267
|
assert.equal(allCount, 1, 'Should have 1 all export')
|
|
268
268
|
assert.equal(namespaceCount, 1, 'Should have 1 namespace export')
|
|
269
269
|
assert.equal(typeCount, 2, 'Should have 2 type exports')
|
|
270
|
-
|
|
270
|
+
|
|
271
271
|
// Check sorting by index
|
|
272
|
-
for (let i = 1; i <
|
|
273
|
-
assert.ok(
|
|
272
|
+
for (let i = 1; i < foundExports.length; i++) {
|
|
273
|
+
assert.ok(foundExports[i].index >= foundExports[i-1].index, 'Exports should be sorted by index')
|
|
274
274
|
}
|
|
275
275
|
})
|
|
276
276
|
|
|
277
277
|
test('should handle empty code', () => {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
assert.ok(
|
|
278
|
+
const foundExports = getExports('')
|
|
279
|
+
|
|
280
|
+
assert.ok(foundExports.length === 0, 'Should return empty array for empty code')
|
|
281
281
|
})
|
|
282
282
|
|
|
283
283
|
test('should handle code with no exports', () => {
|
|
@@ -286,10 +286,10 @@ function myFunction() {}
|
|
|
286
286
|
const myVariable = 'value'
|
|
287
287
|
import { something } from './module'
|
|
288
288
|
`
|
|
289
|
-
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
assert.ok(
|
|
289
|
+
|
|
290
|
+
const foundExports = getExports(code)
|
|
291
|
+
|
|
292
|
+
assert.ok(foundExports.length === 0, 'Should return empty array for code with no exports')
|
|
293
293
|
})
|
|
294
294
|
|
|
295
295
|
test('should handle complex export patterns', () => {
|
|
@@ -312,16 +312,17 @@ export {
|
|
|
312
312
|
} from './app'
|
|
313
313
|
`
|
|
314
314
|
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
315
|
+
const foundExports = getExports(code)
|
|
316
|
+
// console.log('foundExports', foundExports)
|
|
317
|
+
|
|
318
|
+
assert.ok(foundExports.length > 0, 'Should find exports in complex code')
|
|
319
|
+
|
|
319
320
|
// Should handle anonymous functions and classes
|
|
320
|
-
const anonymousExports =
|
|
321
|
+
const anonymousExports = foundExports.filter(exp => exp.exportName === 'anonymous')
|
|
321
322
|
assert.ok(anonymousExports.length >= 2, 'Should find anonymous function and class exports')
|
|
322
|
-
|
|
323
|
+
|
|
323
324
|
// Should handle complex named declaration exports
|
|
324
|
-
const namedDeclarations =
|
|
325
|
+
const namedDeclarations = foundExports.filter(exp => exp.exportType === 'named')
|
|
325
326
|
assert.ok(namedDeclarations.length >= 6, 'Should find complex named declaration exports')
|
|
326
327
|
})
|
|
327
328
|
|
|
@@ -331,16 +332,52 @@ export { default } from './module' assert { type: 'json' }
|
|
|
331
332
|
export { Component } from './component' with { type: 'css' }
|
|
332
333
|
`
|
|
333
334
|
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
const foundExports = getExports(code, { includeAssertionExports: true })
|
|
336
|
+
|
|
337
|
+
// console.log('foundExports', foundExports)
|
|
338
|
+
|
|
339
|
+
assert.ok(foundExports.length === 4, 'Should find 4 exports when assertions enabled')
|
|
340
|
+
|
|
341
|
+
const assertionExports = foundExports.filter(exp => exp.isAssertion)
|
|
339
342
|
assert.ok(assertionExports.length === 2, 'Should find 2 assertion exports')
|
|
340
|
-
|
|
343
|
+
|
|
341
344
|
// Test without assertion exports
|
|
342
345
|
const exportsWithoutAssertions = getExports(code, { includeAssertionExports: false })
|
|
343
346
|
assert.ok(exportsWithoutAssertions.length === 2, 'Should find 2 named exports when assertions disabled')
|
|
344
347
|
})
|
|
345
348
|
|
|
349
|
+
|
|
350
|
+
test('export with default', () => {
|
|
351
|
+
/* single line export */
|
|
352
|
+
const code = `export { default as MyComponent, Button, Input }`
|
|
353
|
+
/* Equivalent to: */
|
|
354
|
+
const longForm = `
|
|
355
|
+
import MyComponent, { Button, Input } from './components'
|
|
356
|
+
export { MyComponent, Button, Input }
|
|
357
|
+
`
|
|
358
|
+
|
|
359
|
+
const longFormExports = getExports(longForm)
|
|
360
|
+
// console.log('longFormExports', longFormExports)
|
|
361
|
+
assert.ok(longFormExports.length === 3, 'Should find 3 exports in longForm')
|
|
362
|
+
|
|
363
|
+
const foundExports = getExports(code)
|
|
364
|
+
|
|
365
|
+
// console.log('foundExports', foundExports)
|
|
366
|
+
|
|
367
|
+
assert.ok(foundExports.length === 3, 'Should find 3 exports when assertions enabled')
|
|
368
|
+
|
|
369
|
+
const firstExport = foundExports[0]
|
|
370
|
+
assert.ok(firstExport.exportName === 'default', 'Should find default export')
|
|
371
|
+
assert.ok(firstExport.exportAlias === 'MyComponent', 'Should find MyComponent export')
|
|
372
|
+
assert.ok(firstExport.exportType === 'named', 'Should find named export')
|
|
373
|
+
|
|
374
|
+
const secondExport = foundExports[1]
|
|
375
|
+
assert.ok(secondExport.exportName === 'Button', 'Should find Button export')
|
|
376
|
+
assert.ok(secondExport.exportType === 'named', 'Should find named export')
|
|
377
|
+
|
|
378
|
+
const thirdExport = foundExports[2]
|
|
379
|
+
assert.ok(thirdExport.exportName === 'Input', 'Should find Input export')
|
|
380
|
+
assert.ok(thirdExport.exportType === 'named', 'Should find named export')
|
|
381
|
+
})
|
|
382
|
+
|
|
346
383
|
test.run()
|