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,200 @@
|
|
|
1
|
+
# @ts-morph/bootstrap
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/%40ts-morph%2Fbootstrap)
|
|
4
|
+
[](https://github.com/dsherret/ts-morph/actions?query=workflow%3ACI)
|
|
5
|
+
|
|
6
|
+
A library for quickly getting set up with the [TypeScript](https://github.com/Microsoft/TypeScript) Compiler API.
|
|
7
|
+
|
|
8
|
+
This library is separate from [ts-morph](https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/), but uses some of its underlying infrastructure.
|
|
9
|
+
|
|
10
|
+
- [Declarations](https://github.com/dsherret/ts-morph/blob/latest/packages/bootstrap/lib/ts-morph-bootstrap.d.ts)
|
|
11
|
+
|
|
12
|
+
## Example
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { createProject, ts } from "@ts-morph/bootstrap";
|
|
16
|
+
|
|
17
|
+
const project = await createProject(); // or createProjectSync
|
|
18
|
+
|
|
19
|
+
// these are typed as ts.SourceFile
|
|
20
|
+
const myClassFile = project.createSourceFile(
|
|
21
|
+
"MyClass.ts",
|
|
22
|
+
"export class MyClass { prop: string; }",
|
|
23
|
+
);
|
|
24
|
+
const mainFile = project.createSourceFile(
|
|
25
|
+
"main.ts",
|
|
26
|
+
"import { MyClass } from './MyClass'",
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// ts.Program
|
|
30
|
+
const program = project.createProgram();
|
|
31
|
+
// ts.TypeChecker
|
|
32
|
+
const typeChecker = program.getTypeChecker();
|
|
33
|
+
// ts.LanguageService
|
|
34
|
+
const languageService = project.getLanguageService();
|
|
35
|
+
// ts.ModuleResolutionHost
|
|
36
|
+
const moduleResolutionHost = project.getModuleResolutionHost();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Setup
|
|
40
|
+
|
|
41
|
+
Generally:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const project = await createProject({ tsConfigFilePath: "tsconfig.json" });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or use the synchronous API:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
const project = createProjectSync({ tsConfigFilePath: "tsconfig.json" });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### File Systems
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
// will use a real file system
|
|
57
|
+
const project = await createProject();
|
|
58
|
+
|
|
59
|
+
// in memory file system
|
|
60
|
+
const project2 = await createProject({ useInMemoryFileSystem: true });
|
|
61
|
+
|
|
62
|
+
// custom file system
|
|
63
|
+
const fileSystem: FileSystemHost = { ...etc... };
|
|
64
|
+
const project = await createProject({ fileSystem });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
To access the file system after creating a project, you can use the `fileSystem` property:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
project.fileSystem.writeFileSync("MyClass.ts", "class MyClass {}");
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Compiler options
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const project = await createProject({
|
|
77
|
+
compilerOptions: {
|
|
78
|
+
target: ts.ScriptTarget.ES3,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### tsconfig.json:
|
|
84
|
+
|
|
85
|
+
If you would like to manually specify the path to a tsconfig.json file then specify that:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const project = await createProject({
|
|
89
|
+
tsConfigFilePath: "packages/my-library/tsconfig.json",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// output all the source files that were added
|
|
93
|
+
console.log(project.getSourceFiles().map(s => s.fileName));
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
_Note:_ You can override any tsconfig.json options by also providing a `compilerOptions` object.
|
|
97
|
+
|
|
98
|
+
For your convenience, this will automatically add all the associated source files from the tsconfig.json. If you don't wish to do that, then you will need to explicitly set `skipAddingFilesFromTsConfig` to `true`:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
const project = await createProject({
|
|
102
|
+
tsConfigFilePath: "path/to/tsconfig.json",
|
|
103
|
+
skipAddingFilesFromTsConfig: true,
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Custom Module Resolution
|
|
108
|
+
|
|
109
|
+
Custom module resolution can be specified by providing a resolution host factory function. This also supports providing custom type reference directive resolution.
|
|
110
|
+
|
|
111
|
+
For example:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { createProject, ts } from "@ts-morph/bootstrap";
|
|
115
|
+
|
|
116
|
+
// This is deno style module resolution.
|
|
117
|
+
// Ex. `import { MyClass } from "./MyClass.ts"`;
|
|
118
|
+
const project = await createProject({
|
|
119
|
+
resolutionHost: (moduleResolutionHost, getCompilerOptions) => {
|
|
120
|
+
return {
|
|
121
|
+
resolveModuleNames: (moduleNames, containingFile) => {
|
|
122
|
+
const compilerOptions = getCompilerOptions();
|
|
123
|
+
const resolvedModules: ts.ResolvedModule[] = [];
|
|
124
|
+
|
|
125
|
+
for (const moduleName of moduleNames.map(removeTsExtension)) {
|
|
126
|
+
const result = ts.resolveModuleName(
|
|
127
|
+
moduleName,
|
|
128
|
+
containingFile,
|
|
129
|
+
compilerOptions,
|
|
130
|
+
moduleResolutionHost,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
if (result.resolvedModule)
|
|
134
|
+
resolvedModules.push(result.resolvedModule);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return resolvedModules;
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
function removeTsExtension(moduleName: string) {
|
|
142
|
+
if (moduleName.slice(-3).toLowerCase() === ".ts")
|
|
143
|
+
return moduleName.slice(0, -3);
|
|
144
|
+
return moduleName;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Adding Source Files
|
|
151
|
+
|
|
152
|
+
Use the following methods:
|
|
153
|
+
|
|
154
|
+
- `const sourceFiles = await project.addSourceFilesByPaths("**/*.ts");` or provide an array of file globs.
|
|
155
|
+
- `const sourceFile = await project.addSourceFileAtPath("src/my-file.ts");` or use `addSourceFileAtPathIfExists(filePath)`
|
|
156
|
+
- `const sourceFiles = await project.addSourceFilesFromTsConfig("path/to/tsconfig.json")`
|
|
157
|
+
|
|
158
|
+
Or use the corresponding `-Sync` suffix methods for a synchronous API (though it will be much slower).
|
|
159
|
+
|
|
160
|
+
## Creating Source Files
|
|
161
|
+
|
|
162
|
+
Use the `Project#createSourceFile` method:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
const sourceFile = project.createSourceFile("MyClass.ts", "class MyClass {}");
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Updating a Source File
|
|
169
|
+
|
|
170
|
+
Use the `Project#updateSourceFile` method. This can be provided a file path and string for the text or a new `ts.SourceFile` object:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
const newSourceFile = project.updateSourceFile("MyClass.ts", "class MyClass {}");
|
|
174
|
+
// or
|
|
175
|
+
project.updateSourceFile(newSourceFileObj);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Removing a Source File
|
|
179
|
+
|
|
180
|
+
Use the `Project#removeSourceFile` method:
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
project.removeSourceFile("MyClass.ts");
|
|
184
|
+
// or
|
|
185
|
+
project.removeSourceFile(sourceFile);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Formatting Diagnostics
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
import { createProject, ts } from "@ts-morph/bootstrap";
|
|
192
|
+
|
|
193
|
+
const project = await createProject({ useInMemoryFileSystem: true });
|
|
194
|
+
project.createSourceFile("test.ts", "const t: string = 5;");
|
|
195
|
+
|
|
196
|
+
const program = project.createProgram();
|
|
197
|
+
const diagnostics = ts.getPreEmitDiagnostics(project.createProgram());
|
|
198
|
+
|
|
199
|
+
console.log(project.formatDiagnosticsWithColorAndContext(diagnostics));
|
|
200
|
+
```
|
|
@@ -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.
|