@davidwells/extract-deps 0.0.1
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/README.md +211 -0
- package/_usage.js +175 -0
- package/examples/get-exports.js +31 -0
- package/package.json +27 -0
- package/src/detect-syntax.js +70 -0
- package/src/get-exports.js +299 -0
- package/src/get-imports.js +165 -0
- package/src/get-requires.js +104 -0
- package/src/index.js +90 -0
- package/src/utils.js +64 -0
- package/tests/detect-syntax.test.js +280 -0
- package/tests/get-exports.test.js +346 -0
- package/tests/get-imports.test.js +395 -0
- package/tests/get-requires.test.js +201 -0
- package/tests/index.test.js +202 -0
- package/tests/test-utils.js +30 -0
- package/tsconfig.json +19 -0
- package/types/detect-syntax.d.ts +39 -0
- package/types/detect-syntax.d.ts.map +1 -0
- package/types/extract-deps/_usage.d.ts +20 -0
- package/types/extract-deps/_usage.d.ts.map +1 -0
- package/types/extract-deps/examples/get-exports.d.ts +2 -0
- package/types/extract-deps/examples/get-exports.d.ts.map +1 -0
- package/types/extract-deps/src/detect-syntax.d.ts +39 -0
- package/types/extract-deps/src/detect-syntax.d.ts.map +1 -0
- package/types/extract-deps/src/get-exports.d.ts +52 -0
- package/types/extract-deps/src/get-exports.d.ts.map +1 -0
- package/types/extract-deps/src/get-imports.d.ts +53 -0
- package/types/extract-deps/src/get-imports.d.ts.map +1 -0
- package/types/extract-deps/src/get-requires.d.ts +34 -0
- package/types/extract-deps/src/get-requires.d.ts.map +1 -0
- package/types/extract-deps/src/index.d.ts +39 -0
- package/types/extract-deps/src/index.d.ts.map +1 -0
- package/types/extract-deps/src/utils.d.ts +4 -0
- package/types/extract-deps/src/utils.d.ts.map +1 -0
- package/types/extract-deps/tests/detect-syntax.test.d.ts +2 -0
- package/types/extract-deps/tests/detect-syntax.test.d.ts.map +1 -0
- package/types/extract-deps/tests/get-exports.test.d.ts +2 -0
- package/types/extract-deps/tests/get-exports.test.d.ts.map +1 -0
- package/types/extract-deps/tests/get-imports.test.d.ts +2 -0
- package/types/extract-deps/tests/get-imports.test.d.ts.map +1 -0
- package/types/extract-deps/tests/get-requires.test.d.ts +2 -0
- package/types/extract-deps/tests/get-requires.test.d.ts.map +1 -0
- package/types/extract-deps/tests/index.test.d.ts +18 -0
- package/types/extract-deps/tests/index.test.d.ts.map +1 -0
- package/types/extract-deps/tests/test-utils.d.ts +9 -0
- package/types/extract-deps/tests/test-utils.d.ts.map +1 -0
- package/types/get-exports.d.ts +52 -0
- package/types/get-exports.d.ts.map +1 -0
- package/types/get-imports.d.ts +53 -0
- package/types/get-imports.d.ts.map +1 -0
- package/types/get-requires.d.ts +34 -0
- package/types/get-requires.d.ts.map +1 -0
- package/types/index.d.ts +39 -0
- package/types/index.d.ts.map +1 -0
- package/types/packages-list/index.d.ts +138 -0
- package/types/packages-list/index.d.ts.map +1 -0
- package/types/utils.d.ts +4 -0
- package/types/utils.d.ts.map +1 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
const { test } = require('uvu')
|
|
2
|
+
const assert = require('uvu/assert')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
|
|
6
|
+
// Relative requires for local packages
|
|
7
|
+
const { getPackagesList } = require('../../packages-list/index.js')
|
|
8
|
+
const { extractDeps, getImports, getRequires } = require('../src/index.js')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Object} PackageDeps
|
|
12
|
+
* @property {string} name - Package name
|
|
13
|
+
* @property {string} mainFile - Path to main file
|
|
14
|
+
* @property {Object} deps - Extracted dependencies
|
|
15
|
+
* @property {Array} deps.imports - Import statements found
|
|
16
|
+
* @property {Array} deps.requires - Require statements found
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Reads the main file content for a package
|
|
21
|
+
* @param {Object} pkg - Package object from getPackagesList
|
|
22
|
+
* @returns {Promise<string>} File content
|
|
23
|
+
*/
|
|
24
|
+
async function readMainFile(pkg) {
|
|
25
|
+
const mainFile = pkg.pkg.main || 'index.js'
|
|
26
|
+
const fullPath = path.join(pkg.dir.full, mainFile)
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
return await fs.promises.readFile(fullPath, 'utf-8')
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.log(error)
|
|
32
|
+
console.log(pkg)
|
|
33
|
+
console.log(`Could not read main file for ${pkg.name}: ${fullPath}`)
|
|
34
|
+
return ''
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Extracts dependencies from all packages in the lerna fixture
|
|
40
|
+
* @returns {Promise<PackageDeps[]>} Array of package dependencies
|
|
41
|
+
*/
|
|
42
|
+
async function extractAllPackageDeps() {
|
|
43
|
+
const fixturePath = path.join(__dirname, '../../packages-build-order/tests/lerna-fixture')
|
|
44
|
+
const packages = await getPackagesList(fixturePath, { excludeRoot: true })
|
|
45
|
+
//console.log('packages', packages)
|
|
46
|
+
|
|
47
|
+
const results = []
|
|
48
|
+
|
|
49
|
+
for (const pkg of packages) {
|
|
50
|
+
const mainFileContent = await readMainFile(pkg)
|
|
51
|
+
|
|
52
|
+
if (mainFileContent) {
|
|
53
|
+
const deps = extractDeps(mainFileContent)
|
|
54
|
+
const mainFile = pkg.pkg.main || 'index.js'
|
|
55
|
+
|
|
56
|
+
results.push({
|
|
57
|
+
name: pkg.name,
|
|
58
|
+
mainFile: path.join(pkg.dir.relative, mainFile),
|
|
59
|
+
deps: deps
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return results
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
test('should extract dependencies from lerna fixture packages', async () => {
|
|
68
|
+
const packageDeps = await extractAllPackageDeps()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
// Should have found packages
|
|
72
|
+
assert.ok(packageDeps.length > 0, 'Should find packages in fixture')
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
console.log('packageDeps', packageDeps)
|
|
76
|
+
// Log results for inspection
|
|
77
|
+
console.log('\n=== Package Dependencies Found ===')
|
|
78
|
+
packageDeps.forEach(pkg => {
|
|
79
|
+
console.log(`\n📦 ${pkg.name} (${pkg.mainFile}):`)
|
|
80
|
+
|
|
81
|
+
if (pkg.deps.imports.length > 0) {
|
|
82
|
+
console.log(' 📥 Imports:')
|
|
83
|
+
pkg.deps.imports.forEach(imp => {
|
|
84
|
+
console.log(` - ${imp.from || imp.moduleSpecifier}`)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (pkg.deps.requires.length > 0) {
|
|
89
|
+
console.log(' 📥 Requires:')
|
|
90
|
+
pkg.deps.requires.forEach(req => {
|
|
91
|
+
console.log(` - ${req.from}`)
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (pkg.deps.imports.length === 0 && pkg.deps.requires.length === 0) {
|
|
96
|
+
console.log(' 📥 No imports/requires found')
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
/** */
|
|
100
|
+
// Specific assertions for known packages
|
|
101
|
+
const usagePackage = packageDeps.find(pkg => pkg.name === 'testing-lerna-usage')
|
|
102
|
+
assert.ok(usagePackage, 'Should find testing-lerna-usage package')
|
|
103
|
+
|
|
104
|
+
if (usagePackage) {
|
|
105
|
+
assert.ok(usagePackage.deps.requires.length > 0, 'testing-lerna-usage should have requires')
|
|
106
|
+
|
|
107
|
+
const requireModules = usagePackage.deps.requires.map(req => req.from)
|
|
108
|
+
assert.ok(requireModules.includes('testing-lerna-one'), 'Should require testing-lerna-one')
|
|
109
|
+
assert.ok(requireModules.includes('testing-lerna-two'), 'Should require testing-lerna-two')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Check that packages without dependencies are handled correctly
|
|
113
|
+
const onePackage = packageDeps.find(pkg => pkg.name === 'testing-lerna-one')
|
|
114
|
+
assert.ok(onePackage, 'Should find testing-lerna-one package')
|
|
115
|
+
|
|
116
|
+
if (onePackage) {
|
|
117
|
+
// testing-lerna-one should have no imports/requires (just exports)
|
|
118
|
+
assert.ok(onePackage.deps.imports.length === 0, 'testing-lerna-one should have no imports')
|
|
119
|
+
assert.ok(onePackage.deps.requires.length === 0, 'testing-lerna-one should have no requires')
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('should handle packages with different main file locations', async () => {
|
|
124
|
+
const fixturePath = path.join(__dirname, '../../packages-build-order/tests/lerna-fixture')
|
|
125
|
+
const packages = await getPackagesList(fixturePath, { excludeRoot: true })
|
|
126
|
+
|
|
127
|
+
// Find packages with different main file configurations
|
|
128
|
+
const packagesWithMain = packages.filter(pkg => pkg.pkg.main)
|
|
129
|
+
const packagesWithoutMain = packages.filter(pkg => !pkg.pkg.main)
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
console.log('\n=== Main File Analysis ===')
|
|
133
|
+
console.log(`Packages with explicit main: ${packagesWithMain.length}`)
|
|
134
|
+
console.log(`Packages using default index.js: ${packagesWithoutMain.length}`)
|
|
135
|
+
/** */
|
|
136
|
+
// Verify we can read both types
|
|
137
|
+
for (const pkg of packagesWithMain) {
|
|
138
|
+
const content = await readMainFile(pkg)
|
|
139
|
+
assert.ok(content !== undefined, `Should be able to read main file for ${pkg.name}`)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
for (const pkg of packagesWithoutMain) {
|
|
143
|
+
const content = await readMainFile(pkg)
|
|
144
|
+
assert.ok(content !== undefined, `Should be able to read default index.js for ${pkg.name}`)
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('should extract specific import/require patterns', async () => {
|
|
149
|
+
const fixturePath = path.join(__dirname, '../../packages-build-order/tests/lerna-fixture')
|
|
150
|
+
const packages = await getPackagesList(fixturePath)
|
|
151
|
+
|
|
152
|
+
// Find the usage package which has known require patterns
|
|
153
|
+
const usagePackage = packages.find(pkg => pkg.name === 'testing-lerna-usage')
|
|
154
|
+
assert.ok(usagePackage, 'Should find testing-lerna-usage package')
|
|
155
|
+
|
|
156
|
+
const mainFileContent = await readMainFile(usagePackage)
|
|
157
|
+
const deps = extractDeps(mainFileContent)
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
console.log('\n=== Detailed Import/Require Analysis ===')
|
|
161
|
+
console.log('testing-lerna-usage dependencies:')
|
|
162
|
+
console.log('Requires:', deps.requires)
|
|
163
|
+
console.log('Imports:', deps.imports)
|
|
164
|
+
/** */
|
|
165
|
+
|
|
166
|
+
// Test specific require patterns
|
|
167
|
+
assert.ok(deps.requires.length === 2, 'Should have 2 require statements')
|
|
168
|
+
|
|
169
|
+
const requireModules = deps.requires.map(req => req.from)
|
|
170
|
+
assert.ok(requireModules.includes('testing-lerna-one'), 'Should require testing-lerna-one')
|
|
171
|
+
assert.ok(requireModules.includes('testing-lerna-two'), 'Should require testing-lerna-two')
|
|
172
|
+
|
|
173
|
+
// Test that no imports are found (since this package uses require)
|
|
174
|
+
assert.ok(deps.imports.length === 0, 'Should have no import statements')
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('should handle packages with no dependencies gracefully', async () => {
|
|
178
|
+
const fixturePath = path.join(__dirname, '../../packages-build-order/tests/lerna-fixture')
|
|
179
|
+
const packages = await getPackagesList(fixturePath)
|
|
180
|
+
|
|
181
|
+
// Find packages that should have no dependencies
|
|
182
|
+
const simplePackages = packages.filter(pkg =>
|
|
183
|
+
['testing-lerna-one', 'testing-lerna-two'].includes(pkg.name)
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
for (const pkg of simplePackages) {
|
|
187
|
+
const mainFileContent = await readMainFile(pkg)
|
|
188
|
+
const deps = extractDeps(mainFileContent)
|
|
189
|
+
|
|
190
|
+
/*
|
|
191
|
+
console.log(`\n${pkg.name} dependencies:`, {
|
|
192
|
+
imports: deps.imports.length,
|
|
193
|
+
requires: deps.requires.length
|
|
194
|
+
})
|
|
195
|
+
/** */
|
|
196
|
+
// These packages should have no imports or requires
|
|
197
|
+
assert.ok(deps.imports.length === 0, `${pkg.name} should have no imports`)
|
|
198
|
+
assert.ok(deps.requires.length === 0, `${pkg.name} should have no requires`)
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test.run()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const util = require('util')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes test results by removing the `index` field from import/require objects
|
|
5
|
+
* This is useful for testing since index values can vary and aren't part of the core functionality
|
|
6
|
+
* @param {Array|Object} result - The result object or array of result objects to normalize
|
|
7
|
+
* @returns {Array|Object} - The normalized result with index fields removed
|
|
8
|
+
*/
|
|
9
|
+
function normalizeTestResult(result) {
|
|
10
|
+
if (Array.isArray(result)) {
|
|
11
|
+
return result.map(item => normalizeTestResult(item))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (result && typeof result === 'object') {
|
|
15
|
+
const normalized = { ...result }
|
|
16
|
+
delete normalized.index
|
|
17
|
+
return normalized
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function deepLog(myObject) {
|
|
24
|
+
console.log(util.inspect(myObject, {showHidden: false, depth: null, colors: true}))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
normalizeTestResult,
|
|
29
|
+
deepLog
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"checkJs": true,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"emitDeclarationOnly": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"strict": false,
|
|
9
|
+
"noImplicitAny": false,
|
|
10
|
+
"strictNullChecks": false,
|
|
11
|
+
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"noUnusedLocals": false,
|
|
13
|
+
"noUnusedParameters": false,
|
|
14
|
+
"target": "ES2020",
|
|
15
|
+
"module": "CommonJS"
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*.js", "src/**/*.ts"],
|
|
18
|
+
"exclude": ["node_modules", "types"]
|
|
19
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for detecting syntax within a code string.
|
|
3
|
+
*/
|
|
4
|
+
export type DetectSyntaxOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* - Indicates whether comments should be stripped from the code before syntax checking.
|
|
7
|
+
*/
|
|
8
|
+
stripComments?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Options for detecting syntax within a code string.
|
|
12
|
+
* @typedef {Object} DetectSyntaxOptions
|
|
13
|
+
* @property {boolean} [stripComments=false] - Indicates whether comments should be stripped from the code before syntax checking.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Determines if a given code string contains ECMAScript module syntax.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} code - The source code to analyze.
|
|
19
|
+
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
|
|
20
|
+
* @returns {boolean} `true` if the code contains ESM syntax, otherwise `false`.
|
|
21
|
+
*/
|
|
22
|
+
export function hasESMSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Determines if a given string of code contains CommonJS syntax.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} code - The source code to analyze.
|
|
27
|
+
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
|
|
28
|
+
* @returns {boolean} `true` if the code contains CommonJS syntax, `false` otherwise.
|
|
29
|
+
*/
|
|
30
|
+
export function hasCJSSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Analyzes the supplied code to determine if it contains ECMAScript module syntax, CommonJS syntax, or both.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} code - The source code to analyze.
|
|
35
|
+
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
|
|
36
|
+
* @returns {Object} An object indicating the presence of ESM syntax (`hasESM`), CJS syntax (`hasCJS`) and whether both syntaxes are present (`isMixed`).
|
|
37
|
+
*/
|
|
38
|
+
export function detectSyntax(code: string, opts?: DetectSyntaxOptions): any;
|
|
39
|
+
//# sourceMappingURL=detect-syntax.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-syntax.d.ts","sourceRoot":"","sources":["../src/detect-syntax.js"],"names":[],"mappings":";;;;;;;oBAec,OAAO;;AAHrB;;;;GAIG;AAEH;;;;;;GAMG;AACH,mCAJW,MAAM,SACN,mBAAmB,GACjB,OAAO,CAMnB;AAED;;;;;;GAMG;AACH,mCAJW,MAAM,SACN,mBAAmB,GACjB,OAAO,CAMnB;AAED;;;;;;GAMG;AACH,mCAJW,MAAM,SACN,mBAAmB,OAe7B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analyze dependencies in the lerna fixture
|
|
3
|
+
*/
|
|
4
|
+
export function analyzeLernaFixture(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Example of using extractDeps with actual code files
|
|
7
|
+
*/
|
|
8
|
+
export function analyzeCodeDependencies(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Read and parse a package.json file
|
|
11
|
+
* @param {string} filePath - Path to the package.json file
|
|
12
|
+
* @returns {Object} Parsed package.json content
|
|
13
|
+
*/
|
|
14
|
+
export function readPackageJson(filePath: string): any;
|
|
15
|
+
/**
|
|
16
|
+
* Get all package.json files in the lerna fixture
|
|
17
|
+
* @returns {Array} Array of package.json file paths
|
|
18
|
+
*/
|
|
19
|
+
export function getPackageJsonFiles(): any[];
|
|
20
|
+
//# sourceMappingURL=_usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_usage.d.ts","sourceRoot":"","sources":["../../_usage.js"],"names":[],"mappings":"AAuDA;;GAEG;AACH,4CA8BC;AAED;;GAEG;AACH,gDA4CC;AA7HD;;;;GAIG;AACH,0CAHW,MAAM,OAWhB;AAED;;;GAGG;AACH,6CAsBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-exports.d.ts","sourceRoot":"","sources":["../../../examples/get-exports.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for detecting syntax within a code string.
|
|
3
|
+
*/
|
|
4
|
+
export type DetectSyntaxOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* - Indicates whether comments should be stripped from the code before syntax checking.
|
|
7
|
+
*/
|
|
8
|
+
stripComments?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Options for detecting syntax within a code string.
|
|
12
|
+
* @typedef {Object} DetectSyntaxOptions
|
|
13
|
+
* @property {boolean} [stripComments=false] - Indicates whether comments should be stripped from the code before syntax checking.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Determines if a given code string contains ECMAScript module syntax.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} code - The source code to analyze.
|
|
19
|
+
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
|
|
20
|
+
* @returns {boolean} `true` if the code contains ESM syntax, otherwise `false`.
|
|
21
|
+
*/
|
|
22
|
+
export function hasESMSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Determines if a given string of code contains CommonJS syntax.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} code - The source code to analyze.
|
|
27
|
+
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
|
|
28
|
+
* @returns {boolean} `true` if the code contains CommonJS syntax, `false` otherwise.
|
|
29
|
+
*/
|
|
30
|
+
export function hasCJSSyntax(code: string, opts?: DetectSyntaxOptions): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Analyzes the supplied code to determine if it contains ECMAScript module syntax, CommonJS syntax, or both.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} code - The source code to analyze.
|
|
35
|
+
* @param {DetectSyntaxOptions} opts - See {@link DetectSyntaxOptions}.
|
|
36
|
+
* @returns {Object} An object indicating the presence of ESM syntax (`hasESM`), CJS syntax (`hasCJS`) and whether both syntaxes are present (`isMixed`).
|
|
37
|
+
*/
|
|
38
|
+
export function detectSyntax(code: string, opts?: DetectSyntaxOptions): any;
|
|
39
|
+
//# sourceMappingURL=detect-syntax.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-syntax.d.ts","sourceRoot":"","sources":["../../../src/detect-syntax.js"],"names":[],"mappings":";;;;;;;oBAec,OAAO;;AAHrB;;;;GAIG;AAEH;;;;;;GAMG;AACH,mCAJW,MAAM,SACN,mBAAmB,GACjB,OAAO,CAMnB;AAED;;;;;;GAMG;AACH,mCAJW,MAAM,SACN,mBAAmB,GACjB,OAAO,CAMnB;AAED;;;;;;GAMG;AACH,mCAJW,MAAM,SACN,mBAAmB,OAe7B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function getExports(code: any, options?: {}): any[];
|
|
2
|
+
export function getDefaultExports(targetText?: string): {
|
|
3
|
+
line: string;
|
|
4
|
+
exportType: string;
|
|
5
|
+
exportName: any;
|
|
6
|
+
exportValue: string;
|
|
7
|
+
index: number;
|
|
8
|
+
isExport: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
export function getNamedExports(targetText?: string): {
|
|
11
|
+
line: string;
|
|
12
|
+
exportType: string;
|
|
13
|
+
exportName: string;
|
|
14
|
+
index: number;
|
|
15
|
+
isExport: boolean;
|
|
16
|
+
}[];
|
|
17
|
+
export function getNamedDeclarationExports(targetText?: string): any[];
|
|
18
|
+
export function getAllExports(targetText?: string): {
|
|
19
|
+
line: string;
|
|
20
|
+
exportType: string;
|
|
21
|
+
from: string;
|
|
22
|
+
index: number;
|
|
23
|
+
isExport: boolean;
|
|
24
|
+
}[];
|
|
25
|
+
export function getNamespaceExports(targetText?: string): {
|
|
26
|
+
line: string;
|
|
27
|
+
exportType: string;
|
|
28
|
+
namespace: string;
|
|
29
|
+
from: string;
|
|
30
|
+
index: number;
|
|
31
|
+
isExport: boolean;
|
|
32
|
+
}[];
|
|
33
|
+
export function getTypeExports(targetText?: string): {
|
|
34
|
+
line: string;
|
|
35
|
+
exportType: string;
|
|
36
|
+
exportName: string;
|
|
37
|
+
index: number;
|
|
38
|
+
isExport: boolean;
|
|
39
|
+
}[];
|
|
40
|
+
export function getAssertionExports(targetText?: string): {
|
|
41
|
+
line: string;
|
|
42
|
+
exportType: string;
|
|
43
|
+
exportName: string;
|
|
44
|
+
definitions: any;
|
|
45
|
+
from: string;
|
|
46
|
+
assertion: string;
|
|
47
|
+
assertionType: string;
|
|
48
|
+
index: number;
|
|
49
|
+
isExport: boolean;
|
|
50
|
+
isAssertion: boolean;
|
|
51
|
+
}[];
|
|
52
|
+
//# sourceMappingURL=get-exports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-exports.d.ts","sourceRoot":"","sources":["../../../src/get-exports.js"],"names":[],"mappings":"AAiBA,2DAsBC;AAED;;;;;;;IA4BC;AAED;;;;;;IAeC;AAED,uEAmBC;AAED;;;;;;IAeC;AAED;;;;;;;IAgBC;AAED;;;;;;IAeC;AAED;;;;;;;;;;;IAuBC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export function getImports(code: any, options?: {}): {
|
|
2
|
+
line: string;
|
|
3
|
+
varType: string;
|
|
4
|
+
varName: string;
|
|
5
|
+
definitions: any;
|
|
6
|
+
from: string;
|
|
7
|
+
index: number;
|
|
8
|
+
isImport: boolean;
|
|
9
|
+
isRelative: boolean;
|
|
10
|
+
}[];
|
|
11
|
+
export function getStaticImports(targetText?: string): {
|
|
12
|
+
line: string;
|
|
13
|
+
varType: string;
|
|
14
|
+
varName: string;
|
|
15
|
+
definitions: any;
|
|
16
|
+
from: string;
|
|
17
|
+
index: number;
|
|
18
|
+
isImport: boolean;
|
|
19
|
+
isRelative: boolean;
|
|
20
|
+
}[];
|
|
21
|
+
export function getTypeImports(targetText?: string): {
|
|
22
|
+
importStatement: string;
|
|
23
|
+
importPath: string;
|
|
24
|
+
importName: string;
|
|
25
|
+
index: number;
|
|
26
|
+
isImport: boolean;
|
|
27
|
+
isRelative: boolean;
|
|
28
|
+
}[];
|
|
29
|
+
export function getDynamicImports(targetText?: string): {
|
|
30
|
+
line: string;
|
|
31
|
+
varType: string;
|
|
32
|
+
varName: string;
|
|
33
|
+
definitions: any;
|
|
34
|
+
from: string;
|
|
35
|
+
index: number;
|
|
36
|
+
isImport: boolean;
|
|
37
|
+
isRelative: boolean;
|
|
38
|
+
isDynamic: boolean;
|
|
39
|
+
}[];
|
|
40
|
+
export function getAssertionImports(targetText?: string): {
|
|
41
|
+
line: string;
|
|
42
|
+
varType: string;
|
|
43
|
+
varName: string;
|
|
44
|
+
definitions: any;
|
|
45
|
+
from: string;
|
|
46
|
+
assertion: string;
|
|
47
|
+
assertionType: string;
|
|
48
|
+
index: number;
|
|
49
|
+
isImport: boolean;
|
|
50
|
+
isRelative: boolean;
|
|
51
|
+
isAssertion: boolean;
|
|
52
|
+
}[];
|
|
53
|
+
//# sourceMappingURL=get-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-imports.d.ts","sourceRoot":"","sources":["../../../src/get-imports.js"],"names":[],"mappings":"AAWA;;;;;;;;;IAQC;AAGD;;;;;;;;;IAkBC;AAED;;;;;;;IAgBC;AAED;;;;;;;;;;IAoBC;AAED;;;;;;;;;;;;IAwBC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function getRequires(code: any): {
|
|
2
|
+
line: string;
|
|
3
|
+
varType: string;
|
|
4
|
+
varName: string;
|
|
5
|
+
definitions: any;
|
|
6
|
+
from: string;
|
|
7
|
+
index: number;
|
|
8
|
+
isRequire: boolean;
|
|
9
|
+
isRelative: boolean;
|
|
10
|
+
isDynamic: boolean;
|
|
11
|
+
}[];
|
|
12
|
+
export function getStaticRequires(targetText?: string): {
|
|
13
|
+
line: string;
|
|
14
|
+
varType: string;
|
|
15
|
+
varName: string;
|
|
16
|
+
definitions: any;
|
|
17
|
+
from: string;
|
|
18
|
+
index: number;
|
|
19
|
+
isRequire: boolean;
|
|
20
|
+
isRelative: boolean;
|
|
21
|
+
isDynamic: boolean;
|
|
22
|
+
}[];
|
|
23
|
+
export function getDynamicRequires(code: any): {
|
|
24
|
+
line: string;
|
|
25
|
+
varType: string;
|
|
26
|
+
varName: string;
|
|
27
|
+
definitions: any;
|
|
28
|
+
from: string;
|
|
29
|
+
index: number;
|
|
30
|
+
isRequire: boolean;
|
|
31
|
+
isRelative: boolean;
|
|
32
|
+
isDynamic: boolean;
|
|
33
|
+
}[];
|
|
34
|
+
//# sourceMappingURL=get-requires.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-requires.d.ts","sourceRoot":"","sources":["../../../src/get-requires.js"],"names":[],"mappings":"AA8DA;;;;;;;;;;IAIC;AA5BD;;;;;;;;;;IAsBC;AArDD;;;;;;;;;;IA4BC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function extractDeps(code: any): {
|
|
2
|
+
imports: {
|
|
3
|
+
line: string;
|
|
4
|
+
varType: string;
|
|
5
|
+
varName: string;
|
|
6
|
+
definitions: any;
|
|
7
|
+
from: string;
|
|
8
|
+
index: number;
|
|
9
|
+
isImport: boolean;
|
|
10
|
+
isRelative: boolean;
|
|
11
|
+
}[];
|
|
12
|
+
requires: {
|
|
13
|
+
line: string;
|
|
14
|
+
varType: string;
|
|
15
|
+
varName: string;
|
|
16
|
+
definitions: any;
|
|
17
|
+
from: string;
|
|
18
|
+
index: number;
|
|
19
|
+
isRequire: boolean;
|
|
20
|
+
isRelative: boolean;
|
|
21
|
+
isDynamic: boolean;
|
|
22
|
+
}[];
|
|
23
|
+
exports: any[];
|
|
24
|
+
};
|
|
25
|
+
import { getRequires } from "./get-requires";
|
|
26
|
+
import { getDynamicRequires } from "./get-requires";
|
|
27
|
+
import { getStaticRequires } from "./get-requires";
|
|
28
|
+
import { getImports } from "./get-imports";
|
|
29
|
+
import { getStaticImports } from "./get-imports";
|
|
30
|
+
import { getDynamicImports } from "./get-imports";
|
|
31
|
+
import { getExports } from "./get-exports";
|
|
32
|
+
import { getDefaultExports } from "./get-exports";
|
|
33
|
+
import { getNamedExports } from "./get-exports";
|
|
34
|
+
import { getNamedDeclarationExports } from "./get-exports";
|
|
35
|
+
import { getAllExports } from "./get-exports";
|
|
36
|
+
import { getNamespaceExports } from "./get-exports";
|
|
37
|
+
import { getTypeExports } from "./get-exports";
|
|
38
|
+
export { getRequires, getDynamicRequires, getStaticRequires, getImports, getStaticImports, getDynamicImports, getExports, getDefaultExports, getNamedExports, getNamedDeclarationExports, getAllExports, getNamespaceExports, getTypeExports };
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;EAQC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.js"],"names":[],"mappings":"AAEA,+DAEC;AAED,yEAKC;AAED,6CA2CC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-syntax.test.d.ts","sourceRoot":"","sources":["../../../tests/detect-syntax.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-exports.test.d.ts","sourceRoot":"","sources":["../../../tests/get-exports.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-imports.test.d.ts","sourceRoot":"","sources":["../../../tests/get-imports.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-requires.test.d.ts","sourceRoot":"","sources":["../../../tests/get-requires.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type PackageDeps = {
|
|
2
|
+
/**
|
|
3
|
+
* - Package name
|
|
4
|
+
*/
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* - Path to main file
|
|
8
|
+
*/
|
|
9
|
+
mainFile: string;
|
|
10
|
+
/**
|
|
11
|
+
* - Extracted dependencies
|
|
12
|
+
*/
|
|
13
|
+
deps: {
|
|
14
|
+
imports: any[];
|
|
15
|
+
requires: any[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=index.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../tests/index.test.js"],"names":[],"mappings":";;;;UAWc,MAAM;;;;cACN,MAAM;;;;;QAEM,OAAO;QACP,QAAQ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes test results by removing the `index` field from import/require objects
|
|
3
|
+
* This is useful for testing since index values can vary and aren't part of the core functionality
|
|
4
|
+
* @param {Array|Object} result - The result object or array of result objects to normalize
|
|
5
|
+
* @returns {Array|Object} - The normalized result with index fields removed
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeTestResult(result: any[] | any): any[] | any;
|
|
8
|
+
export function deepLog(myObject: any): void;
|
|
9
|
+
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../tests/test-utils.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,4CAHW,WAAY,GACV,WAAY,CAcxB;AAED,6CAEC"}
|