@davidwells/extract-deps 0.1.11 → 0.1.13
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 +1 -1
- package/src/dep-graph.js +97 -13
- package/src/get-cjs-exports.js +5 -3
- package/src/get-exports.js +4 -2
- package/src/get-imports.js +2 -0
- package/src/get-requires.js +43 -1
- package/src/index.js +29 -0
- package/src/utils.js +216 -58
- package/tests/dep-graph.test.js +56 -1
- package/tests/fixtures/ts-regex-export-fixture/index.ts +8 -0
- package/tests/fixtures/ts-regex-export-fixture/message-builder.ts +23 -0
- package/tests/get-exports.test.js +27 -2
- package/tests/index.test.js +11 -0
- package/tests/parser-edge-cases.test.js +101 -0
- package/tests/utils.test.js +8 -0
- package/types/dep-graph.d.ts +45 -0
- package/types/dep-graph.d.ts.map +1 -0
- package/types/detect-syntax.d.ts +39 -0
- package/types/detect-syntax.d.ts.map +1 -0
- package/types/get-cjs-exports.d.ts +45 -0
- package/types/get-cjs-exports.d.ts.map +1 -0
- package/types/get-exports.d.ts +54 -0
- package/types/get-exports.d.ts.map +1 -0
- package/types/get-imports.d.ts +59 -0
- package/types/get-imports.d.ts.map +1 -0
- package/types/get-requires.d.ts +37 -0
- package/types/get-requires.d.ts.map +1 -0
- package/types/index.d.ts +25 -0
- package/types/index.d.ts.map +1 -0
- package/types/utils.d.ts +76 -0
- package/types/utils.d.ts.map +1 -0
- package/types/vendor/inspect-parameters-declaration.d.ts +4 -0
- package/types/vendor/inspect-parameters-declaration.d.ts.map +1 -0
- package/types/verify-package-entries.d.ts +30 -0
- package/types/verify-package-entries.d.ts.map +1 -0
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip comments from code while skipping strings, templates, and regex
|
|
3
|
+
* literals. Regex literals can legally contain `//`, for example `/https?:\/\//`,
|
|
4
|
+
* and must not be treated as line comments.
|
|
5
|
+
* @param {string} code
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function stripComments(code: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Blank the contents of every string/template literal in `code` that looks
|
|
11
|
+
* like it contains embedded code (its body mentions `import`, `export`,
|
|
12
|
+
* `require`, or `module.exports`). The opening and closing quote chars are
|
|
13
|
+
* preserved, as are newlines. Total length is preserved so character indices
|
|
14
|
+
* remain stable.
|
|
15
|
+
*
|
|
16
|
+
* Strings whose bodies don't reference those keywords — including ordinary
|
|
17
|
+
* module specifiers like `'lodash'`, paths like `'./foo.js'`, URLs, and
|
|
18
|
+
* arbitrary user text — pass through untouched, so the static-import/require
|
|
19
|
+
* regexes can still read their content.
|
|
20
|
+
*
|
|
21
|
+
* Without this pass, regex-based extractors falsely match `import`, `export`,
|
|
22
|
+
* and `require` keywords that appear inside code samples embedded in strings.
|
|
23
|
+
*
|
|
24
|
+
* Run after `stripComments` in the import/require/export extractors. The
|
|
25
|
+
* comment scanner already skips strings and regex literals, so this pass can
|
|
26
|
+
* focus on embedded-code strings without risking `//` in URLs or regexes.
|
|
27
|
+
*
|
|
28
|
+
* Caveat: `${...}` interpolations inside template literals are treated as
|
|
29
|
+
* part of the body, so a runtime `${import('./x.js')}` inside a template
|
|
30
|
+
* would be blanked. Very rare in practice; a proper tokenizer would be
|
|
31
|
+
* needed to do better.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} code
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export function stripStringContents(code: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Blank comment bodies and code-bearing string/template bodies together.
|
|
39
|
+
* Solves two bugs that occurred when the string-strip and comment-strip ran
|
|
40
|
+
* as naive regex passes:
|
|
41
|
+
*
|
|
42
|
+
* - Apostrophes inside JSDoc comments (e.g. `* Netlify's \`...`) were
|
|
43
|
+
* mis-paired with later quotes, which shifted subsequent backtick
|
|
44
|
+
* pairing and could swallow real `export` declarations a few lines
|
|
45
|
+
* later in the same file.
|
|
46
|
+
* - `//` and `/* *\/` sequences inside string bodies were mis-stripped
|
|
47
|
+
* as comments.
|
|
48
|
+
* - `//` inside regex literals such as `/^https?:\/\//i` was mis-stripped
|
|
49
|
+
* as a line comment.
|
|
50
|
+
*
|
|
51
|
+
* Length is preserved (each consumed char replaced by a space or newline
|
|
52
|
+
* kept verbatim) so downstream character indices stay valid.
|
|
53
|
+
*
|
|
54
|
+
* Strings whose bodies don't reference `import` / `export` / `require` /
|
|
55
|
+
* `module.exports` pass through unchanged, so module specifiers like
|
|
56
|
+
* `'lodash'` or `'./foo.js'` stay readable by the downstream regexes.
|
|
57
|
+
*
|
|
58
|
+
* Caveat: `${...}` interpolations inside template literals are part of the
|
|
59
|
+
* body, so `${import('./x.js')}` inside a template gets blanked. Rare in
|
|
60
|
+
* practice; a full parser would be needed otherwise.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} code
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
65
|
+
export function stripCommentsAndStrings(code: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Check if a module specifier is a Node.js built-in
|
|
68
|
+
* @param {string} moduleName - The module specifier (e.g., 'fs', 'node:fs/promises')
|
|
69
|
+
* @returns {boolean}
|
|
70
|
+
*/
|
|
71
|
+
export function isBuiltIn(moduleName: string): boolean;
|
|
72
|
+
export function isRelativeImport(importLocation: any): boolean;
|
|
73
|
+
export function isRelativeImportWithQuotes(importLocation: any): boolean;
|
|
74
|
+
export function getNames(names: any, aliasKey?: string): any;
|
|
75
|
+
export function extractExportName(exportValue: any): any;
|
|
76
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAsQA;;;;;;GAMG;AACH,oCAHW,MAAM,GACJ,MAAM,CAIlB;AAtQD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,0CAHW,MAAM,GACJ,MAAM,CA6ClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,8CAHW,MAAM,GACJ,MAAM,CAIlB;AAkKD;;;;GAIG;AACH,sCAHW,MAAM,GACJ,OAAO,CAUnB;AAED,+DAEC;AAED,yEAKC;AAgFD,6DA+DC;AAGD,yDAqCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect-parameters-declaration.d.ts","sourceRoot":"","sources":["../../src/vendor/inspect-parameters-declaration.js"],"names":[],"mappings":"AA0QA,oDAaC;AAtBD,qDAGC;AAED,gFAEC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract all entry points from package.json
|
|
3
|
+
* @param {string} packageJsonPath - Path to package.json
|
|
4
|
+
* @returns {Array<{field: string, path: string, resolvedPath: string}>} - Array of entry point objects
|
|
5
|
+
*/
|
|
6
|
+
export function getPackageEntryPoints(packageJsonPath: string): Array<{
|
|
7
|
+
field: string;
|
|
8
|
+
path: string;
|
|
9
|
+
resolvedPath: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Verify all package.json entry points and collect dependencies
|
|
13
|
+
* @param {string} packagePath - Path to package.json
|
|
14
|
+
* @param {object} options - Options
|
|
15
|
+
* @param {boolean} [options.collectDeps] - If true, collect dependency paths for each entry point. Default: true
|
|
16
|
+
* @param {boolean} [options.verifyGraph] - If true, verify imports/exports. Default: true
|
|
17
|
+
* @param {boolean} [options.throwIfErrors] - If true, throw an error if there are any errors. Default: false
|
|
18
|
+
* @returns {{entryPoints: Array, sourceFiles: Set, errors: Array}} - Verification results
|
|
19
|
+
*/
|
|
20
|
+
export function verifyPackageEntries(packagePath: string, options?: {
|
|
21
|
+
collectDeps?: boolean;
|
|
22
|
+
verifyGraph?: boolean;
|
|
23
|
+
throwIfErrors?: boolean;
|
|
24
|
+
}): {
|
|
25
|
+
entryPoints: any[];
|
|
26
|
+
sourceFiles: Set<any>;
|
|
27
|
+
errors: any[];
|
|
28
|
+
};
|
|
29
|
+
export function collectEntryPoints(packageJson: any, packageDir: any): any[];
|
|
30
|
+
//# sourceMappingURL=verify-package-entries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-package-entries.d.ts","sourceRoot":"","sources":["../src/verify-package-entries.js"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,uDAHW,MAAM,GACJ,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAC,CAAC,CAOtE;AAmGD;;;;;;;;GAQG;AACH,kDAPW,MAAM,YAEd;IAA0B,WAAW,GAA7B,OAAO;IACW,WAAW,GAA7B,OAAO;IACW,aAAa,GAA/B,OAAO;CACf,GAAU;IAAC,WAAW,QAAQ;IAAC,WAAW,WAAM;IAAC,MAAM,QAAO;CAAC,CAoEjE;AA5KD,6EA8DC"}
|