@depup/ts-morph 27.0.2-depup.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/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/ts-morph.js +21738 -0
- package/lib/ts-morph.d.ts +11198 -0
- package/package.json +92 -0
- package/readme.md +111 -0
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/ts-morph",
|
|
3
|
+
"version": "27.0.2-depup.0",
|
|
4
|
+
"description": "TypeScript compiler wrapper for static analysis and code manipulation. (with updated dependencies)",
|
|
5
|
+
"main": "dist/ts-morph.js",
|
|
6
|
+
"types": "lib/ts-morph.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dopublish": "deno task type-check-docs && deno task code-generate && deno task package && deno task publish-code-verification && echo \"Run: npm publish\"",
|
|
9
|
+
"build": "deno task build:declarations && deno task build:node",
|
|
10
|
+
"build:node": "rimraf dist && rollup -c ",
|
|
11
|
+
"build:deno": "deno task build:declarations && rimraf dist-deno && rollup -c --environment BUILD:deno && deno run -A scripts/buildDeno.ts",
|
|
12
|
+
"build:declarations": "deno run -A scripts/generation/main.ts create-declaration-file",
|
|
13
|
+
"test": "deno run -A npm:mocha",
|
|
14
|
+
"test:debug": "deno task test --inspect-brk",
|
|
15
|
+
"test:watch": "deno task test --watch-extensions ts --watch",
|
|
16
|
+
"test:ci": "deno task test",
|
|
17
|
+
"test:ts-versions": "deno run -A scripts/test/testTypeScriptVersions.ts",
|
|
18
|
+
"type-check": "deno run -A scripts/typeCheckLibrary.ts",
|
|
19
|
+
"code-generate": "deno run -A scripts/generation/main.ts",
|
|
20
|
+
"output-wrapped-nodes": "deno run -A scripts/generation/outputWrappedNodesInfo.ts",
|
|
21
|
+
"package": "deno task build",
|
|
22
|
+
"publish-code-verification": "deno task code-verification && deno task ensure-no-declaration-file-errors",
|
|
23
|
+
"code-verification": "deno run -A scripts/verification/main.ts ensure-structures-match-classes ensure-overload-structures-match ensure-array-inputs-readonly ensure-classes-implement-structure-methods ensure-mixin-not-applied-multiple-times validate-public-api-class-member-names validate-compiler-node-to-wrapped-type validate-code-fences",
|
|
24
|
+
"ensure-structures-match-classes": "deno run -A scripts/verification/main.ts ensure-structures-match-classes",
|
|
25
|
+
"ensure-overload-structures-match": "deno run -A scripts/verification/main.ts ensure-overload-structures-match",
|
|
26
|
+
"ensure-no-project-compile-errors": "deno run -A scripts/verification/ensureNoProjectCompileErrors.ts",
|
|
27
|
+
"ensure-no-declaration-file-errors": "deno run -A scripts/verification/ensureNoDeclarationFileErrors.ts",
|
|
28
|
+
"ensure-array-inputs-readonly": "deno run -A scripts/verification/main ensure-array-inputs-readonly.ts",
|
|
29
|
+
"ensure-or-throw-exists": "deno run -A scripts/verification/main ensure-or-throw-exists.ts",
|
|
30
|
+
"type-check-docs": "deno run -A scripts/typeCheckDocumentation.ts"
|
|
31
|
+
},
|
|
32
|
+
"repository": "git+https://github.com/dsherret/ts-morph.git",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"ts-morph",
|
|
35
|
+
"depup",
|
|
36
|
+
"updated-dependencies",
|
|
37
|
+
"security",
|
|
38
|
+
"latest",
|
|
39
|
+
"patched",
|
|
40
|
+
"typescript",
|
|
41
|
+
"ast",
|
|
42
|
+
"static analysis",
|
|
43
|
+
"code generation",
|
|
44
|
+
"code refactor"
|
|
45
|
+
],
|
|
46
|
+
"author": "David Sherret",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/dsherret/ts-morph/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/dsherret/ts-morph#readme",
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@ts-morph/common": "~0.28.1",
|
|
54
|
+
"code-block-writer": "^13.0.3"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
58
|
+
"@types/chai": "^5.2.1",
|
|
59
|
+
"@types/diff": "^7.0.2",
|
|
60
|
+
"@types/mocha": "^10.0.10",
|
|
61
|
+
"@types/node": "^22.14.1",
|
|
62
|
+
"chai": "^5.2.0",
|
|
63
|
+
"conditional-type-checks": "^1.0.6",
|
|
64
|
+
"cross-env": "^7.0.3",
|
|
65
|
+
"diff": "^7.0.0",
|
|
66
|
+
"mocha": "11.1.0",
|
|
67
|
+
"rimraf": "^6.0.1",
|
|
68
|
+
"rollup": "=4.40.0",
|
|
69
|
+
"ts-node": "10.9.2",
|
|
70
|
+
"typescript": "~5.9.2"
|
|
71
|
+
},
|
|
72
|
+
"browser": {
|
|
73
|
+
"fs": false,
|
|
74
|
+
"os": false,
|
|
75
|
+
"fs.realpath": false,
|
|
76
|
+
"mkdirp": false,
|
|
77
|
+
"dir-glob": false,
|
|
78
|
+
"graceful-fs": false,
|
|
79
|
+
"source-map-support": false,
|
|
80
|
+
"glob-parent": false,
|
|
81
|
+
"glob": false,
|
|
82
|
+
"tinyglobby": false
|
|
83
|
+
},
|
|
84
|
+
"depup": {
|
|
85
|
+
"changes": {},
|
|
86
|
+
"depsUpdated": 0,
|
|
87
|
+
"originalPackage": "ts-morph",
|
|
88
|
+
"originalVersion": "27.0.2",
|
|
89
|
+
"processedAt": "2026-03-22T00:40:02.424Z",
|
|
90
|
+
"smokeTest": "passed"
|
|
91
|
+
}
|
|
92
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# ts-morph
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/ts-morph)
|
|
4
|
+
[](https://github.com/dsherret/ts-morph/actions?query=workflow%3ACI)
|
|
5
|
+
[](http://github.com/badges/stability-badges)
|
|
6
|
+
|
|
7
|
+
[TypeScript](https://github.com/Microsoft/TypeScript) Compiler API wrapper. Provides an easier way to programmatically navigate and manipulate TypeScript and JavaScript code.
|
|
8
|
+
|
|
9
|
+
Formerly `ts-simple-ast`.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
- [Documentation](https://ts-morph.com/)
|
|
14
|
+
- [Declaration file](https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/lib/ts-morph.d.ts)
|
|
15
|
+
|
|
16
|
+
## Main Features
|
|
17
|
+
|
|
18
|
+
1. Wraps the compiler API objects to provide helper methods for getting information and programmatically changing files.
|
|
19
|
+
2. Allows falling back to the compiler API objects if necessary (ex. `classDeclaration.compilerNode` or `typeChecker.compilerObject`).
|
|
20
|
+
3. All changes are kept in memory (including file and directory moves) until specifying to save to the underlying file system.
|
|
21
|
+
4. Changes are made to the text and wrapped nodes can be held on to between manipulations.
|
|
22
|
+
|
|
23
|
+
## Getting Started
|
|
24
|
+
|
|
25
|
+
1. [Installing](https://ts-morph.com/)
|
|
26
|
+
2. [Instantiating](https://ts-morph.com/setup/)
|
|
27
|
+
3. [Adding source files](https://ts-morph.com/setup/adding-source-files)
|
|
28
|
+
4. [Getting source files](https://ts-morph.com/navigation/getting-source-files)
|
|
29
|
+
5. [Navigating](https://ts-morph.com/navigation/example)
|
|
30
|
+
6. [Manipulating](https://ts-morph.com/manipulation/)
|
|
31
|
+
|
|
32
|
+
## Library Progress
|
|
33
|
+
|
|
34
|
+
This library is still under active development. Most common code manipulation/generation use cases are implemented, but there's still a lot of work to do. Please open an issue if you find a feature missing, bug, or question that isn't in the issue tracker.
|
|
35
|
+
|
|
36
|
+
- [Breaking changes](https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/breaking-changes.md)
|
|
37
|
+
- [Change log](https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/CHANGELOG.md)
|
|
38
|
+
- [Wrapped nodes progress report](https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/wrapped-nodes.md)
|
|
39
|
+
|
|
40
|
+
## Example
|
|
41
|
+
|
|
42
|
+
<!-- dprint-ignore -->
|
|
43
|
+
```ts
|
|
44
|
+
import { Project, StructureKind } from "ts-morph";
|
|
45
|
+
|
|
46
|
+
// initialize
|
|
47
|
+
const project = new Project({
|
|
48
|
+
// Optionally specify compiler options, tsconfig.json, in-memory file system, and more here.
|
|
49
|
+
// If you initialize with a tsconfig.json, then it will automatically populate the project
|
|
50
|
+
// with the associated source files.
|
|
51
|
+
// Read more: https://ts-morph.com/setup/
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// add source files
|
|
55
|
+
project.addSourceFilesAtPaths("src/**/*.ts");
|
|
56
|
+
const myClassFile = project.createSourceFile("src/MyClass.ts", "export class MyClass {}");
|
|
57
|
+
const myEnumFile = project.createSourceFile("src/MyEnum.ts", {
|
|
58
|
+
statements: [{
|
|
59
|
+
kind: StructureKind.Enum,
|
|
60
|
+
name: "MyEnum",
|
|
61
|
+
isExported: true,
|
|
62
|
+
members: [{ name: "member" }],
|
|
63
|
+
}],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// get information
|
|
67
|
+
const myClass = myClassFile.getClassOrThrow("MyClass");
|
|
68
|
+
myClass.getName(); // returns: "MyClass"
|
|
69
|
+
myClass.hasExportKeyword(); // returns: true
|
|
70
|
+
myClass.isDefaultExport(); // returns: false
|
|
71
|
+
|
|
72
|
+
// manipulate
|
|
73
|
+
const myInterface = myClassFile.addInterface({
|
|
74
|
+
name: "IMyInterface",
|
|
75
|
+
isExported: true,
|
|
76
|
+
properties: [{
|
|
77
|
+
name: "myProp",
|
|
78
|
+
type: "number",
|
|
79
|
+
}],
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
myClass.rename("NewName");
|
|
83
|
+
myClass.addImplements(myInterface.getName());
|
|
84
|
+
myClass.addProperty({
|
|
85
|
+
name: "myProp",
|
|
86
|
+
initializer: "5",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
project.getSourceFileOrThrow("src/ExistingFile.ts").delete();
|
|
90
|
+
|
|
91
|
+
// asynchronously save all the changes above
|
|
92
|
+
await project.save();
|
|
93
|
+
|
|
94
|
+
// get underlying compiler node from the typescript AST from any node
|
|
95
|
+
const compilerNode = myClassFile.compilerNode;
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Or navigate existing compiler nodes created with the TypeScript compiler (the `ts` named export is the TypeScript compiler):
|
|
99
|
+
|
|
100
|
+
```ts ignore-error: 1109
|
|
101
|
+
import { createWrappedNode, ClassDeclaration, ts } from "ts-morph";
|
|
102
|
+
|
|
103
|
+
// some code that creates a class declaration using the ts object
|
|
104
|
+
const classNode: ts.ClassDeclaration = ...;
|
|
105
|
+
|
|
106
|
+
// create and use a wrapped node
|
|
107
|
+
const classDec = createWrappedNode(classNode) as ClassDeclaration;
|
|
108
|
+
const firstProperty = classDec.getProperties()[0];
|
|
109
|
+
|
|
110
|
+
// ... do more stuff here ...
|
|
111
|
+
```
|