fcis 0.1.0
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/.plans/001-fcis-analyzer.md +832 -0
- package/.plans/002-fcis-analyzer-improvements.md +205 -0
- package/README.md +272 -0
- package/TECHNICAL.md +386 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1836 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +709 -0
- package/dist/index.js +1845 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
- package/pnpm-workspace.yaml +0 -0
- package/src/analyzer.ts +266 -0
- package/src/classification/classifier.ts +156 -0
- package/src/classification/derive-status.ts +171 -0
- package/src/classification/quality-scorer.ts +481 -0
- package/src/cli.ts +286 -0
- package/src/detection/detect-markers.ts +480 -0
- package/src/detection/markers.ts +332 -0
- package/src/extraction/extract-functions.ts +570 -0
- package/src/extraction/extractor.ts +188 -0
- package/src/index.ts +111 -0
- package/src/reporting/report-console.ts +416 -0
- package/src/reporting/report-json.ts +232 -0
- package/src/scoring/scorer.ts +504 -0
- package/src/types.ts +248 -0
- package/tests/classifier.test.ts +480 -0
- package/tests/derive-status.test.ts +464 -0
- package/tests/detect-markers.test.ts +639 -0
- package/tests/extractor.test.ts +155 -0
- package/tests/integration.test.ts +706 -0
- package/tests/quality-scorer.test.ts +650 -0
- package/tests/scorer.test.ts +768 -0
- package/tsconfig.json +34 -0
- package/tsup.config.ts +17 -0
- package/vendor/ts-morph/.editorconfig +10 -0
- package/vendor/ts-morph/.gitattributes +11 -0
- package/vendor/ts-morph/.github/CODE_OF_CONDUCT.md +77 -0
- package/vendor/ts-morph/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- package/vendor/ts-morph/.github/ISSUE_TEMPLATE/custom.md +4 -0
- package/vendor/ts-morph/.github/ISSUE_TEMPLATE/feature_request.md +18 -0
- package/vendor/ts-morph/.github/workflows/ci.yml +50 -0
- package/vendor/ts-morph/.github/workflows/publish.yml +53 -0
- package/vendor/ts-morph/.vscode/settings.json +10 -0
- package/vendor/ts-morph/CONTRIBUTING.md +23 -0
- package/vendor/ts-morph/DEVELOPMENT.md +32 -0
- package/vendor/ts-morph/LICENSE +21 -0
- package/vendor/ts-morph/deno.json +8 -0
- package/vendor/ts-morph/deno.lock +1233 -0
- package/vendor/ts-morph/docs/CNAME +1 -0
- package/vendor/ts-morph/docs/Gemfile +2 -0
- package/vendor/ts-morph/docs/_config.yml +5 -0
- package/vendor/ts-morph/docs/_layouts/default.html +159 -0
- package/vendor/ts-morph/docs/_script-templates/main.ts +116 -0
- package/vendor/ts-morph/docs/assets/css/style.scss +212 -0
- package/vendor/ts-morph/docs/details/ambient.md +38 -0
- package/vendor/ts-morph/docs/details/async.md +31 -0
- package/vendor/ts-morph/docs/details/classes.md +314 -0
- package/vendor/ts-morph/docs/details/comment-ranges.md +7 -0
- package/vendor/ts-morph/docs/details/comments.md +122 -0
- package/vendor/ts-morph/docs/details/decorators.md +119 -0
- package/vendor/ts-morph/docs/details/documentation.md +73 -0
- package/vendor/ts-morph/docs/details/enums.md +117 -0
- package/vendor/ts-morph/docs/details/exports.md +308 -0
- package/vendor/ts-morph/docs/details/expressions.md +46 -0
- package/vendor/ts-morph/docs/details/functions.md +150 -0
- package/vendor/ts-morph/docs/details/generators.md +27 -0
- package/vendor/ts-morph/docs/details/identifiers.md +79 -0
- package/vendor/ts-morph/docs/details/imports.md +191 -0
- package/vendor/ts-morph/docs/details/index.md +52 -0
- package/vendor/ts-morph/docs/details/initializers.md +40 -0
- package/vendor/ts-morph/docs/details/interfaces.md +218 -0
- package/vendor/ts-morph/docs/details/literals.md +20 -0
- package/vendor/ts-morph/docs/details/modifiers.md +38 -0
- package/vendor/ts-morph/docs/details/modules.md +113 -0
- package/vendor/ts-morph/docs/details/namespaces.md +7 -0
- package/vendor/ts-morph/docs/details/object-literal-expressions.md +106 -0
- package/vendor/ts-morph/docs/details/parameters.md +64 -0
- package/vendor/ts-morph/docs/details/signatures.md +41 -0
- package/vendor/ts-morph/docs/details/source-files.md +292 -0
- package/vendor/ts-morph/docs/details/type-aliases.md +34 -0
- package/vendor/ts-morph/docs/details/type-parameters.md +72 -0
- package/vendor/ts-morph/docs/details/types.md +254 -0
- package/vendor/ts-morph/docs/details/variables.md +110 -0
- package/vendor/ts-morph/docs/emitting.md +151 -0
- package/vendor/ts-morph/docs/index.md +25 -0
- package/vendor/ts-morph/docs/manipulation/code-writer.md +20 -0
- package/vendor/ts-morph/docs/manipulation/formatting.md +76 -0
- package/vendor/ts-morph/docs/manipulation/index.md +136 -0
- package/vendor/ts-morph/docs/manipulation/order.md +14 -0
- package/vendor/ts-morph/docs/manipulation/performance.md +222 -0
- package/vendor/ts-morph/docs/manipulation/removing.md +31 -0
- package/vendor/ts-morph/docs/manipulation/renaming.md +106 -0
- package/vendor/ts-morph/docs/manipulation/settings.md +76 -0
- package/vendor/ts-morph/docs/manipulation/structures.md +117 -0
- package/vendor/ts-morph/docs/manipulation/transforms.md +84 -0
- package/vendor/ts-morph/docs/metrics/performance.json +4 -0
- package/vendor/ts-morph/docs/navigation/ambient-modules.md +22 -0
- package/vendor/ts-morph/docs/navigation/compiler-nodes.md +82 -0
- package/vendor/ts-morph/docs/navigation/directories.md +287 -0
- package/vendor/ts-morph/docs/navigation/example.md +50 -0
- package/vendor/ts-morph/docs/navigation/finding-references.md +53 -0
- package/vendor/ts-morph/docs/navigation/getting-source-files.md +59 -0
- package/vendor/ts-morph/docs/navigation/images/getChildrenVsForEachChild.gif +0 -0
- package/vendor/ts-morph/docs/navigation/index.md +94 -0
- package/vendor/ts-morph/docs/navigation/language-service.md +23 -0
- package/vendor/ts-morph/docs/navigation/program.md +25 -0
- package/vendor/ts-morph/docs/navigation/type-checker.md +33 -0
- package/vendor/ts-morph/docs/setup/adding-source-files.md +145 -0
- package/vendor/ts-morph/docs/setup/ast-viewers.md +46 -0
- package/vendor/ts-morph/docs/setup/diagnostics.md +109 -0
- package/vendor/ts-morph/docs/setup/file-system.md +106 -0
- package/vendor/ts-morph/docs/setup/images/atom-ast.png +0 -0
- package/vendor/ts-morph/docs/setup/images/atom-ast_small.png +0 -0
- package/vendor/ts-morph/docs/setup/images/atom-command-palette.png +0 -0
- package/vendor/ts-morph/docs/setup/images/atom-file.png +0 -0
- package/vendor/ts-morph/docs/setup/images/ts-ast-viewer.png +0 -0
- package/vendor/ts-morph/docs/setup/index.md +94 -0
- package/vendor/ts-morph/docs/utilities.md +55 -0
- package/vendor/ts-morph/dprint.json +23 -0
- package/vendor/ts-morph/package.json +30 -0
- package/vendor/ts-morph/packages/bootstrap/LICENSE +21 -0
- package/vendor/ts-morph/packages/bootstrap/lib/ts-morph-bootstrap.d.ts +397 -0
- package/vendor/ts-morph/packages/bootstrap/package.json +46 -0
- package/vendor/ts-morph/packages/bootstrap/readme.md +200 -0
- package/vendor/ts-morph/packages/common/LICENSE +21 -0
- package/vendor/ts-morph/packages/common/lib/ts-morph-common.d.ts +1082 -0
- package/vendor/ts-morph/packages/common/lib/typescript.d.ts +11439 -0
- package/vendor/ts-morph/packages/common/package.json +65 -0
- package/vendor/ts-morph/packages/common/readme.md +5 -0
- package/vendor/ts-morph/packages/scripts/changeTypeScriptVersion.ts +28 -0
- package/vendor/ts-morph/packages/scripts/createDeclarationProject.ts +47 -0
- package/vendor/ts-morph/packages/scripts/deps.ts +2 -0
- package/vendor/ts-morph/packages/scripts/execScript.ts +31 -0
- package/vendor/ts-morph/packages/scripts/folders.ts +11 -0
- package/vendor/ts-morph/packages/scripts/getDevCompilerVersions.ts +19 -0
- package/vendor/ts-morph/packages/scripts/mod.ts +7 -0
- package/vendor/ts-morph/packages/scripts/utils/Memoize.ts +36 -0
- package/vendor/ts-morph/packages/scripts/utils/forEachTypeText.ts +23 -0
- package/vendor/ts-morph/packages/scripts/utils/makeConstructorsPrivate.ts +26 -0
- package/vendor/ts-morph/packages/scripts/utils/mod.ts +4 -0
- package/vendor/ts-morph/packages/scripts/utils/printDiagnostics.ts +10 -0
- package/vendor/ts-morph/packages/ts-morph/LICENSE +21 -0
- package/vendor/ts-morph/packages/ts-morph/lib/ts-morph.d.ts +11198 -0
- package/vendor/ts-morph/packages/ts-morph/package.json +78 -0
- package/vendor/ts-morph/packages/ts-morph/readme.md +111 -0
- package/vendor/ts-morph/readme.md +14 -0
- package/vendor/ts-morph/rfcs/README.md +13 -0
- package/vendor/ts-morph/rfcs/RFC-0001 - Inserting Into Statements Handling Comments.md +181 -0
- package/vendor/ts-morph/tsconfig.common.json +17 -0
- package/vitest.config.ts +16 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Utilities
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Utilities
|
|
6
|
+
|
|
7
|
+
This is an outline of any utilities currently available in the library.
|
|
8
|
+
|
|
9
|
+
### Get compiler options from tsconfig.json
|
|
10
|
+
|
|
11
|
+
Get the compiler options from a file by using the `getCompilerOptionsFromTsConfig` function:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { getCompilerOptionsFromTsConfig } from "ts-morph";
|
|
15
|
+
|
|
16
|
+
const result = getCompilerOptionsFromTsConfig("file/path/to/tsconfig.json");
|
|
17
|
+
|
|
18
|
+
result.options; // compiler options
|
|
19
|
+
result.errors; // diagnostics
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Type Guards
|
|
23
|
+
|
|
24
|
+
There is a collection of type guard functions that are useful for finding out the type of a node:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { Node } from "ts-morph";
|
|
28
|
+
|
|
29
|
+
// ... some code here that gets a node ...
|
|
30
|
+
|
|
31
|
+
if (Node.isClassDeclaration(node)) {
|
|
32
|
+
// node is of type ClassDeclaration in here
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Printing a Node
|
|
37
|
+
|
|
38
|
+
Usually with the library, you can print any node by calling the `.print()` method:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
node.print(); // returns: string
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
But sometimes you might want to print a compiler node. There's a `printNode` utility function for doing that:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { printNode, ts } from "ts-morph";
|
|
48
|
+
|
|
49
|
+
// get a compiler node from somewhere
|
|
50
|
+
const compilerNode: ts.Node = ...;
|
|
51
|
+
// optionally provide a source file and there is some printing options on this
|
|
52
|
+
const functionText = printNode(compilerNode);
|
|
53
|
+
|
|
54
|
+
console.log(functionText);
|
|
55
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"indentWidth": 2,
|
|
3
|
+
"lineWidth": 160,
|
|
4
|
+
"typescript": {
|
|
5
|
+
"useBraces": "preferNone"
|
|
6
|
+
},
|
|
7
|
+
"excludes": [
|
|
8
|
+
"**/node_modules",
|
|
9
|
+
"**/*-lock.json",
|
|
10
|
+
"packages/*/dist/",
|
|
11
|
+
"packages/*/lib/*.ts",
|
|
12
|
+
"**/CHANGELOG.md",
|
|
13
|
+
"packages/ts-morph/src/compiler/ast/common/Node.ts",
|
|
14
|
+
"./deno",
|
|
15
|
+
"dist-deno"
|
|
16
|
+
],
|
|
17
|
+
"plugins": [
|
|
18
|
+
"https://plugins.dprint.dev/typescript-0.95.9.wasm",
|
|
19
|
+
"https://plugins.dprint.dev/json-0.20.0.wasm",
|
|
20
|
+
"https://plugins.dprint.dev/markdown-0.19.0.wasm",
|
|
21
|
+
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-morph/main",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"description": "Main github repo for ts-morph packages.",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"setup": "deno install && deno task build",
|
|
8
|
+
"build": "cd packages && deno task --cwd common build && deno task --cwd bootstrap build && deno task --cwd ts-morph build",
|
|
9
|
+
"build:deno": "cd packages && deno task --cwd common build:deno && deno task --cwd bootstrap build:deno && deno task --cwd ts-morph build:deno",
|
|
10
|
+
"format": "dprint fmt"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/dsherret/ts-morph.git"
|
|
15
|
+
},
|
|
16
|
+
"author": "David Sherret",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/dsherret/ts-morph/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/dsherret/ts-morph#readme",
|
|
22
|
+
"workspaces": [
|
|
23
|
+
"packages/common",
|
|
24
|
+
"packages/bootstrap",
|
|
25
|
+
"packages/ts-morph"
|
|
26
|
+
],
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"dprint": "^0.50.1"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 David Sherret
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { RuntimeDirEntry, ts } from "@ts-morph/common";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Holds the compiler options.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CompilerOptionsContainer extends SettingsContainer<ts.CompilerOptions> {
|
|
7
|
+
constructor(defaultSettings?: ts.CompilerOptions);
|
|
8
|
+
/**
|
|
9
|
+
* Sets one or all of the compiler options.
|
|
10
|
+
*
|
|
11
|
+
* WARNING: Setting the compiler options will cause a complete reparse of all the source files.
|
|
12
|
+
* @param settings - Compiler options to set.
|
|
13
|
+
*/
|
|
14
|
+
set(settings: Partial<ts.CompilerOptions>): void;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the encoding from the compiler options or returns utf-8.
|
|
17
|
+
*/
|
|
18
|
+
getEncoding(): string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Represents a file system that can be interacted with.
|
|
23
|
+
*/
|
|
24
|
+
export interface FileSystemHost {
|
|
25
|
+
/** Gets if this file system is case sensitive. */
|
|
26
|
+
isCaseSensitive(): boolean;
|
|
27
|
+
/** Asynchronously deletes the specified file or directory. */
|
|
28
|
+
delete(path: string): Promise<void>;
|
|
29
|
+
/** Synchronously deletes the specified file or directory */
|
|
30
|
+
deleteSync(path: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Reads all the child directories and files.
|
|
33
|
+
* @remarks Implementers should have this return the full file path.
|
|
34
|
+
*/
|
|
35
|
+
readDirSync(dirPath: string): RuntimeDirEntry[];
|
|
36
|
+
/** Asynchronously reads a file at the specified path. */
|
|
37
|
+
readFile(filePath: string, encoding?: string): Promise<string>;
|
|
38
|
+
/** Synchronously reads a file at the specified path. */
|
|
39
|
+
readFileSync(filePath: string, encoding?: string): string;
|
|
40
|
+
/** Asynchronously writes a file to the file system. */
|
|
41
|
+
writeFile(filePath: string, fileText: string): Promise<void>;
|
|
42
|
+
/** Synchronously writes a file to the file system. */
|
|
43
|
+
writeFileSync(filePath: string, fileText: string): void;
|
|
44
|
+
/** Asynchronously creates a directory at the specified path. */
|
|
45
|
+
mkdir(dirPath: string): Promise<void>;
|
|
46
|
+
/** Synchronously creates a directory at the specified path. */
|
|
47
|
+
mkdirSync(dirPath: string): void;
|
|
48
|
+
/** Asynchronously moves a file or directory. */
|
|
49
|
+
move(srcPath: string, destPath: string): Promise<void>;
|
|
50
|
+
/** Synchronously moves a file or directory. */
|
|
51
|
+
moveSync(srcPath: string, destPath: string): void;
|
|
52
|
+
/** Asynchronously copies a file or directory. */
|
|
53
|
+
copy(srcPath: string, destPath: string): Promise<void>;
|
|
54
|
+
/** Synchronously copies a file or directory. */
|
|
55
|
+
copySync(srcPath: string, destPath: string): void;
|
|
56
|
+
/** Asynchronously checks if a file exists.
|
|
57
|
+
* @remarks Implementers should throw an `errors.FileNotFoundError` when it does not exist.
|
|
58
|
+
*/
|
|
59
|
+
fileExists(filePath: string): Promise<boolean>;
|
|
60
|
+
/** Synchronously checks if a file exists.
|
|
61
|
+
* @remarks Implementers should throw an `errors.FileNotFoundError` when it does not exist.
|
|
62
|
+
*/
|
|
63
|
+
fileExistsSync(filePath: string): boolean;
|
|
64
|
+
/** Asynchronously checks if a directory exists. */
|
|
65
|
+
directoryExists(dirPath: string): Promise<boolean>;
|
|
66
|
+
/** Synchronously checks if a directory exists. */
|
|
67
|
+
directoryExistsSync(dirPath: string): boolean;
|
|
68
|
+
/** See https://nodejs.org/api/fs.html#fs_fs_realpathsync_path_options */
|
|
69
|
+
realpathSync(path: string): string;
|
|
70
|
+
/** Gets the current directory of the environment. */
|
|
71
|
+
getCurrentDirectory(): string;
|
|
72
|
+
/** Uses pattern matching to find files or directories. */
|
|
73
|
+
glob(patterns: ReadonlyArray<string>): Promise<string[]>;
|
|
74
|
+
/** Synchronously uses pattern matching to find files or directories. */
|
|
75
|
+
globSync(patterns: ReadonlyArray<string>): string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** An implementation of a file system that exists in memory only. */
|
|
79
|
+
export declare class InMemoryFileSystemHost implements FileSystemHost {
|
|
80
|
+
#private;
|
|
81
|
+
/**
|
|
82
|
+
* Constructor.
|
|
83
|
+
*/
|
|
84
|
+
constructor();
|
|
85
|
+
/** @inheritdoc */
|
|
86
|
+
isCaseSensitive(): boolean;
|
|
87
|
+
/** @inheritdoc */
|
|
88
|
+
delete(path: string): Promise<void>;
|
|
89
|
+
/** @inheritdoc */
|
|
90
|
+
deleteSync(path: string): void;
|
|
91
|
+
/** @inheritdoc */
|
|
92
|
+
readDirSync(dirPath: string): RuntimeDirEntry[];
|
|
93
|
+
/** @inheritdoc */
|
|
94
|
+
readFile(filePath: string, encoding?: string): Promise<string>;
|
|
95
|
+
/** @inheritdoc */
|
|
96
|
+
readFileSync(filePath: string, encoding?: string): string;
|
|
97
|
+
/** @inheritdoc */
|
|
98
|
+
writeFile(filePath: string, fileText: string): Promise<void>;
|
|
99
|
+
/** @inheritdoc */
|
|
100
|
+
writeFileSync(filePath: string, fileText: string): void;
|
|
101
|
+
/** @inheritdoc */
|
|
102
|
+
mkdir(dirPath: string): Promise<void>;
|
|
103
|
+
/** @inheritdoc */
|
|
104
|
+
mkdirSync(dirPath: string): void;
|
|
105
|
+
/** @inheritdoc */
|
|
106
|
+
move(srcPath: string, destPath: string): Promise<void>;
|
|
107
|
+
/** @inheritdoc */
|
|
108
|
+
moveSync(srcPath: string, destPath: string): void;
|
|
109
|
+
/** @inheritdoc */
|
|
110
|
+
copy(srcPath: string, destPath: string): Promise<void>;
|
|
111
|
+
/** @inheritdoc */
|
|
112
|
+
copySync(srcPath: string, destPath: string): void;
|
|
113
|
+
/** @inheritdoc */
|
|
114
|
+
fileExists(filePath: string): Promise<boolean>;
|
|
115
|
+
/** @inheritdoc */
|
|
116
|
+
fileExistsSync(filePath: string): boolean;
|
|
117
|
+
/** @inheritdoc */
|
|
118
|
+
directoryExists(dirPath: string): Promise<boolean>;
|
|
119
|
+
/** @inheritdoc */
|
|
120
|
+
directoryExistsSync(dirPath: string): boolean;
|
|
121
|
+
/** @inheritdoc */
|
|
122
|
+
realpathSync(path: string): string;
|
|
123
|
+
/** @inheritdoc */
|
|
124
|
+
getCurrentDirectory(): string;
|
|
125
|
+
/** @inheritdoc */
|
|
126
|
+
glob(patterns: ReadonlyArray<string>): Promise<string[]>;
|
|
127
|
+
/** @inheritdoc */
|
|
128
|
+
globSync(patterns: ReadonlyArray<string>): string[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Host for implementing custom module and/or type reference directive resolution. */
|
|
132
|
+
export interface ResolutionHost {
|
|
133
|
+
resolveModuleNames?: ts.LanguageServiceHost["resolveModuleNames"];
|
|
134
|
+
getResolvedModuleWithFailedLookupLocationsFromCache?: ts.LanguageServiceHost["getResolvedModuleWithFailedLookupLocationsFromCache"];
|
|
135
|
+
resolveTypeReferenceDirectives?: ts.LanguageServiceHost["resolveTypeReferenceDirectives"];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Factory used to create a resolution host.
|
|
140
|
+
* @remarks The compiler options are retrieved via a function in order to get the project's current compiler options.
|
|
141
|
+
*/
|
|
142
|
+
export type ResolutionHostFactory = (moduleResolutionHost: ts.ModuleResolutionHost, getCompilerOptions: () => ts.CompilerOptions) => ResolutionHost;
|
|
143
|
+
|
|
144
|
+
/** Collection of reusable resolution hosts. */
|
|
145
|
+
export declare const ResolutionHosts: {
|
|
146
|
+
deno: ResolutionHostFactory;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export declare abstract class SettingsContainer<T extends object> {
|
|
150
|
+
#private;
|
|
151
|
+
protected _settings: T;
|
|
152
|
+
/**
|
|
153
|
+
* Constructor.
|
|
154
|
+
* @param defaultSettings - The settings to use by default.
|
|
155
|
+
*/
|
|
156
|
+
constructor(defaultSettings: T);
|
|
157
|
+
/**
|
|
158
|
+
* Resets the settings to the default.
|
|
159
|
+
*/
|
|
160
|
+
reset(): void;
|
|
161
|
+
/**
|
|
162
|
+
* Gets a copy of the settings as an object.
|
|
163
|
+
*/
|
|
164
|
+
get(): T;
|
|
165
|
+
/**
|
|
166
|
+
* Sets one or all of the settings.
|
|
167
|
+
* @param settings - Settings to set.
|
|
168
|
+
*/
|
|
169
|
+
set(settings: Partial<T>): void;
|
|
170
|
+
/**
|
|
171
|
+
* Subscribe to modifications in the settings container.
|
|
172
|
+
* @param action - Action to execute when the settings change.
|
|
173
|
+
*/
|
|
174
|
+
onModified(action: () => void): void;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Asynchronously creates a new collection of source files to analyze.
|
|
179
|
+
* @param options Options for creating the project.
|
|
180
|
+
*/
|
|
181
|
+
export declare function createProject(options?: ProjectOptions): Promise<Project>;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Synchronously creates a new collection of source files to analyze.
|
|
185
|
+
* @param options Options for creating the project.
|
|
186
|
+
*/
|
|
187
|
+
export declare function createProjectSync(options?: ProjectOptions): Project;
|
|
188
|
+
|
|
189
|
+
/** Options for creating a project. */
|
|
190
|
+
export interface ProjectOptions {
|
|
191
|
+
/** Compiler options */
|
|
192
|
+
compilerOptions?: ts.CompilerOptions;
|
|
193
|
+
/** File path to the tsconfig.json file. */
|
|
194
|
+
tsConfigFilePath?: string;
|
|
195
|
+
/** Whether to skip adding source files from the specified tsconfig.json. @default false */
|
|
196
|
+
skipAddingFilesFromTsConfig?: boolean;
|
|
197
|
+
/** Skip resolving file dependencies when providing a ts config file path and adding the files from tsconfig. @default false */
|
|
198
|
+
skipFileDependencyResolution?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Skip loading the lib files. Unlike the compiler API, ts-morph does not load these
|
|
201
|
+
* from the node_modules folder, but instead loads them from some other JS code
|
|
202
|
+
* and uses a fake path for their existence. If you want to use a custom lib files
|
|
203
|
+
* folder path, then provide one using the libFolderPath options.
|
|
204
|
+
* @default false
|
|
205
|
+
*/
|
|
206
|
+
skipLoadingLibFiles?: boolean;
|
|
207
|
+
/** The folder to use for loading lib files. */
|
|
208
|
+
libFolderPath?: string;
|
|
209
|
+
/** Whether to use an in-memory file system. */
|
|
210
|
+
useInMemoryFileSystem?: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Optional file system host. Useful for mocking access to the file system.
|
|
213
|
+
* @remarks Consider using `useInMemoryFileSystem` instead.
|
|
214
|
+
*/
|
|
215
|
+
fileSystem?: FileSystemHost;
|
|
216
|
+
/** Creates a resolution host for specifying custom module and/or type reference directive resolution. */
|
|
217
|
+
resolutionHost?: ResolutionHostFactory;
|
|
218
|
+
/**
|
|
219
|
+
* Unstable and will probably be removed in the future.
|
|
220
|
+
* I believe this option should be internal to the library and if you know how to achieve
|
|
221
|
+
* that then please consider submitting a PR.
|
|
222
|
+
*/
|
|
223
|
+
isKnownTypesPackageName?: ts.LanguageServiceHost["isKnownTypesPackageName"];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Project that holds source files. */
|
|
227
|
+
export declare class Project {
|
|
228
|
+
#private;
|
|
229
|
+
private constructor();
|
|
230
|
+
/** Gets the compiler options for modification. */
|
|
231
|
+
readonly compilerOptions: CompilerOptionsContainer;
|
|
232
|
+
/** Gets the file system host used for this project. */
|
|
233
|
+
readonly fileSystem: FileSystemHost;
|
|
234
|
+
/**
|
|
235
|
+
* Asynchronously adds an existing source file from a file path or throws if it doesn't exist.
|
|
236
|
+
*
|
|
237
|
+
* Will return the source file if it was already added.
|
|
238
|
+
* @param filePath - File path to get the file from.
|
|
239
|
+
* @param options - Options for adding the file.
|
|
240
|
+
* @throws FileNotFoundError when the file is not found.
|
|
241
|
+
*/
|
|
242
|
+
addSourceFileAtPath(filePath: string, options?: {
|
|
243
|
+
scriptKind?: ts.ScriptKind;
|
|
244
|
+
}): Promise<ts.SourceFile>;
|
|
245
|
+
/**
|
|
246
|
+
* Synchronously adds an existing source file from a file path or throws if it doesn't exist.
|
|
247
|
+
*
|
|
248
|
+
* Will return the source file if it was already added.
|
|
249
|
+
* @param filePath - File path to get the file from.
|
|
250
|
+
* @param options - Options for adding the file.
|
|
251
|
+
* @throws FileNotFoundError when the file is not found.
|
|
252
|
+
*/
|
|
253
|
+
addSourceFileAtPathSync(filePath: string, options?: {
|
|
254
|
+
scriptKind?: ts.ScriptKind;
|
|
255
|
+
}): ts.SourceFile;
|
|
256
|
+
/**
|
|
257
|
+
* Asynchronously adds a source file from a file path if it exists or returns undefined.
|
|
258
|
+
*
|
|
259
|
+
* Will return the source file if it was already added.
|
|
260
|
+
* @param filePath - File path to get the file from.
|
|
261
|
+
* @param options - Options for adding the file.
|
|
262
|
+
* @skipOrThrowCheck
|
|
263
|
+
*/
|
|
264
|
+
addSourceFileAtPathIfExists(filePath: string, options?: {
|
|
265
|
+
scriptKind?: ts.ScriptKind;
|
|
266
|
+
}): Promise<ts.SourceFile | undefined>;
|
|
267
|
+
/**
|
|
268
|
+
* Synchronously adds a source file from a file path if it exists or returns undefined.
|
|
269
|
+
*
|
|
270
|
+
* Will return the source file if it was already added.
|
|
271
|
+
* @param filePath - File path to get the file from.
|
|
272
|
+
* @param options - Options for adding the file.
|
|
273
|
+
* @skipOrThrowCheck
|
|
274
|
+
*/
|
|
275
|
+
addSourceFileAtPathIfExistsSync(filePath: string, options?: {
|
|
276
|
+
scriptKind?: ts.ScriptKind;
|
|
277
|
+
}): ts.SourceFile | undefined;
|
|
278
|
+
/**
|
|
279
|
+
* Asynchronously adds source files based on file globs.
|
|
280
|
+
* @param fileGlobs - File glob or globs to add files based on.
|
|
281
|
+
* @returns The matched source files.
|
|
282
|
+
*/
|
|
283
|
+
addSourceFilesByPaths(fileGlobs: string | ReadonlyArray<string>): Promise<ts.SourceFile[]>;
|
|
284
|
+
/**
|
|
285
|
+
* Synchronously adds source files based on file globs.
|
|
286
|
+
* @param fileGlobs - File glob or globs to add files based on.
|
|
287
|
+
* @returns The matched source files.
|
|
288
|
+
* @remarks This is much slower than the asynchronous version.
|
|
289
|
+
*/
|
|
290
|
+
addSourceFilesByPathsSync(fileGlobs: string | ReadonlyArray<string>): ts.SourceFile[];
|
|
291
|
+
/**
|
|
292
|
+
* Asynchronously adds all the source files from the specified tsconfig.json.
|
|
293
|
+
*
|
|
294
|
+
* Note that this is done by default when specifying a tsconfig file in the constructor and not explicitly setting the
|
|
295
|
+
* `skipAddingSourceFilesFromTsConfig` option to `true`.
|
|
296
|
+
* @param tsConfigFilePath - File path to the tsconfig.json file.
|
|
297
|
+
*/
|
|
298
|
+
addSourceFilesFromTsConfig(tsConfigFilePath: string): Promise<ts.SourceFile[]>;
|
|
299
|
+
/**
|
|
300
|
+
* Synchronously adds all the source files from the specified tsconfig.json.
|
|
301
|
+
*
|
|
302
|
+
* Note that this is done by default when specifying a tsconfig file in the constructor and not explicitly setting the
|
|
303
|
+
* `skipAddingSourceFilesFromTsConfig` option to `true`.
|
|
304
|
+
* @param tsConfigFilePath - File path to the tsconfig.json file.
|
|
305
|
+
*/
|
|
306
|
+
addSourceFilesFromTsConfigSync(tsConfigFilePath: string): ts.SourceFile[];
|
|
307
|
+
/**
|
|
308
|
+
* Creates a source file at the specified file path with the specified text.
|
|
309
|
+
*
|
|
310
|
+
* Note: The file will not be created and saved to the file system until .save() is called on the source file.
|
|
311
|
+
* @param filePath - File path of the source file.
|
|
312
|
+
* @param sourceFileText - Text to use for the source file.
|
|
313
|
+
* @param options - Options.
|
|
314
|
+
* @throws - InvalidOperationError if a source file already exists at the provided file path.
|
|
315
|
+
*/
|
|
316
|
+
createSourceFile(filePath: string, sourceFileText?: string, options?: {
|
|
317
|
+
scriptKind?: ts.ScriptKind;
|
|
318
|
+
}): ts.SourceFile;
|
|
319
|
+
/**
|
|
320
|
+
* Updates the source file stored in the project at the specified path.
|
|
321
|
+
* @param filePath - File path of the source file.
|
|
322
|
+
* @param sourceFileText - Text of the source file.
|
|
323
|
+
* @param options - Options for updating the source file.
|
|
324
|
+
*/
|
|
325
|
+
updateSourceFile(filePath: string, sourceFileText: string, options?: {
|
|
326
|
+
scriptKind?: ts.ScriptKind;
|
|
327
|
+
}): ts.SourceFile;
|
|
328
|
+
/**
|
|
329
|
+
* Updates the source file stored in the project. The `fileName` of the source file object is used to tell which file to update.
|
|
330
|
+
* @param newSourceFile - The new source file.
|
|
331
|
+
*/
|
|
332
|
+
updateSourceFile(newSourceFile: ts.SourceFile): ts.SourceFile;
|
|
333
|
+
/**
|
|
334
|
+
* Removes the source file at the provided file path.
|
|
335
|
+
* @param filePath - File path of the source file.
|
|
336
|
+
*/
|
|
337
|
+
removeSourceFile(filePath: string): void;
|
|
338
|
+
/**
|
|
339
|
+
* Removes the provided source file based on its `fileName`.
|
|
340
|
+
* @param sourceFile - Source file to remove.
|
|
341
|
+
*/
|
|
342
|
+
removeSourceFile(sourceFile: ts.SourceFile): void;
|
|
343
|
+
/**
|
|
344
|
+
* Adds the source files the project's source files depend on to the project.
|
|
345
|
+
* @remarks
|
|
346
|
+
* * This should be done after source files are added to the project, preferably once to
|
|
347
|
+
* avoid doing more work than necessary.
|
|
348
|
+
* * This is done by default when creating a Project and providing a tsconfig.json and
|
|
349
|
+
* not specifying to not add the source files.
|
|
350
|
+
*/
|
|
351
|
+
resolveSourceFileDependencies(): void;
|
|
352
|
+
/**
|
|
353
|
+
* Creates a new program.
|
|
354
|
+
* Note: You should get a new program any time source files are added, removed, or changed.
|
|
355
|
+
*/
|
|
356
|
+
createProgram(options?: ts.CreateProgramOptions): ts.Program;
|
|
357
|
+
/**
|
|
358
|
+
* Gets the language service.
|
|
359
|
+
*/
|
|
360
|
+
getLanguageService(): ts.LanguageService;
|
|
361
|
+
/**
|
|
362
|
+
* Gets a source file by a file name or file path. Throws an error if it doesn't exist.
|
|
363
|
+
* @param fileNameOrPath - File name or path that the path could end with or equal.
|
|
364
|
+
*/
|
|
365
|
+
getSourceFileOrThrow(fileNameOrPath: string): ts.SourceFile;
|
|
366
|
+
/**
|
|
367
|
+
* Gets a source file by a search function. Throws an error if it doesn't exist.
|
|
368
|
+
* @param searchFunction - Search function.
|
|
369
|
+
*/
|
|
370
|
+
getSourceFileOrThrow(searchFunction: (file: ts.SourceFile) => boolean): ts.SourceFile;
|
|
371
|
+
/**
|
|
372
|
+
* Gets a source file by a file name or file path. Returns undefined if none exists.
|
|
373
|
+
* @param fileNameOrPath - File name or path that the path could end with or equal.
|
|
374
|
+
*/
|
|
375
|
+
getSourceFile(fileNameOrPath: string): ts.SourceFile | undefined;
|
|
376
|
+
/**
|
|
377
|
+
* Gets a source file by a search function. Returns undefined if none exists.
|
|
378
|
+
* @param searchFunction - Search function.
|
|
379
|
+
*/
|
|
380
|
+
getSourceFile(searchFunction: (file: ts.SourceFile) => boolean): ts.SourceFile | undefined;
|
|
381
|
+
/** Gets the source files in the project. */
|
|
382
|
+
getSourceFiles(): ts.SourceFile[];
|
|
383
|
+
/**
|
|
384
|
+
* Formats an array of diagnostics with their color and context into a string.
|
|
385
|
+
* @param diagnostics - Diagnostics to get a string of.
|
|
386
|
+
* @param options - Collection of options. For example, the new line character to use (defaults to the OS' new line character).
|
|
387
|
+
*/
|
|
388
|
+
formatDiagnosticsWithColorAndContext(diagnostics: ReadonlyArray<ts.Diagnostic>, opts?: {
|
|
389
|
+
newLineChar?: "\n" | "\r\n";
|
|
390
|
+
}): string;
|
|
391
|
+
/**
|
|
392
|
+
* Gets a ts.ModuleResolutionHost for the project.
|
|
393
|
+
*/
|
|
394
|
+
getModuleResolutionHost(): ts.ModuleResolutionHost;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export { ts };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-morph/bootstrap",
|
|
3
|
+
"version": "0.28.1",
|
|
4
|
+
"description": "API for getting quickly set up with the TypeScript Compiler API.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"compiler",
|
|
8
|
+
"bootstrap"
|
|
9
|
+
],
|
|
10
|
+
"main": "dist/ts-morph-bootstrap.js",
|
|
11
|
+
"types": "lib/ts-morph-bootstrap.d.ts",
|
|
12
|
+
"author": "David Sherret",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": "git+https://github.com/dsherret/ts-morph.git",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "deno task build:declarations && deno task build:node",
|
|
17
|
+
"build:node": "rimraf dist && deno task rollup",
|
|
18
|
+
"build:deno": "deno task build:declarations && rimraf dist-deno && deno task rollup --environment BUILD:deno && deno run -A scripts/buildDeno.ts",
|
|
19
|
+
"build:declarations": "deno run -A scripts/buildDeclarations.ts",
|
|
20
|
+
"test": "deno run -A npm:mocha",
|
|
21
|
+
"test:ci": "deno task test",
|
|
22
|
+
"test:debug": "deno task test --inspect-brk",
|
|
23
|
+
"test:ts-versions": "deno run -A scripts/test/testTypeScriptVersions.ts",
|
|
24
|
+
"rollup": "rollup -c"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@ts-morph/common": "~0.28.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
31
|
+
"@types/chai": "^5.2.1",
|
|
32
|
+
"@types/mocha": "^10.0.10",
|
|
33
|
+
"@types/node": "^22.14.1",
|
|
34
|
+
"chai": "^5.2.0",
|
|
35
|
+
"cross-env": "^7.0.3",
|
|
36
|
+
"mocha": "^11.1.0",
|
|
37
|
+
"rimraf": "^6.0.1",
|
|
38
|
+
"rollup": "=4.40.0",
|
|
39
|
+
"ts-node": "^10.9.2",
|
|
40
|
+
"tslib": "^2.8.1",
|
|
41
|
+
"typescript": "~5.9.2"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|