@davidwells/extract-deps 0.0.6 → 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.
package/package.json
CHANGED
package/src/dep-graph.js
CHANGED
|
@@ -14,6 +14,14 @@ function fsExistsSync(path) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function isFileSync(filePath) {
|
|
18
|
+
try {
|
|
19
|
+
return fs.statSync(filePath).isFile()
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
/**
|
|
18
26
|
* Resolve a relative import to an actual file path
|
|
19
27
|
* @param {string} baseDir - Directory containing the importing file
|
|
@@ -23,10 +31,10 @@ function fsExistsSync(path) {
|
|
|
23
31
|
function resolveImportPath(baseDir, importPath) {
|
|
24
32
|
const possibleExtensions = ['.js', '.mjs', '.ts', '.json', '']
|
|
25
33
|
|
|
26
|
-
// Try direct file resolution
|
|
34
|
+
// Try direct file resolution (must be a file, not directory)
|
|
27
35
|
for (const ext of possibleExtensions) {
|
|
28
36
|
const testPath = path.resolve(baseDir, importPath + ext)
|
|
29
|
-
if (
|
|
37
|
+
if (isFileSync(testPath)) {
|
|
30
38
|
return testPath
|
|
31
39
|
}
|
|
32
40
|
}
|
package/tests/dep-graph.test.js
CHANGED
|
@@ -355,4 +355,31 @@ module.exports = { missing1, missing2 }
|
|
|
355
355
|
}
|
|
356
356
|
})
|
|
357
357
|
|
|
358
|
+
// Directory to index.js resolution tests
|
|
359
|
+
const DIR_INDEX_FIXTURE_PATH = path.resolve(__dirname, './fixtures/dir-index-example/entry.js')
|
|
360
|
+
|
|
361
|
+
test('should resolve directory import to index.js', () => {
|
|
362
|
+
const graph = depGraph(DIR_INDEX_FIXTURE_PATH)
|
|
363
|
+
|
|
364
|
+
assert.ok(graph instanceof Map, 'Should return a Map')
|
|
365
|
+
assert.ok(graph.size === 2, 'Graph should have 2 files (entry.js and shared-pkg/index.js)')
|
|
366
|
+
|
|
367
|
+
const entries = Array.from(graph.keys())
|
|
368
|
+
const hasEntry = entries.some(key => key.includes('entry.js'))
|
|
369
|
+
const hasIndex = entries.some(key => key.includes('shared-pkg/index.js'))
|
|
370
|
+
|
|
371
|
+
assert.ok(hasEntry, 'Graph should include entry.js')
|
|
372
|
+
assert.ok(hasIndex, 'Graph should resolve directory to index.js')
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
test('resolveDepPaths should work with directory imports', () => {
|
|
376
|
+
const deps = resolveDepPaths(DIR_INDEX_FIXTURE_PATH)
|
|
377
|
+
|
|
378
|
+
assert.ok(Array.isArray(deps), 'Should return an array')
|
|
379
|
+
assert.is(deps.length, 2, 'Should have 2 files')
|
|
380
|
+
|
|
381
|
+
assert.ok(deps.some(p => p.includes('shared-pkg/index.js')), 'Should include resolved index.js')
|
|
382
|
+
assert.ok(deps.some(p => p.includes('entry.js')), 'Should include entry.js')
|
|
383
|
+
})
|
|
384
|
+
|
|
358
385
|
test.run()
|