@rxap/workspace-ts-morph 0.0.2-dev.1 → 0.1.0-dev.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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/package.json +8 -8
- package/src/index.js +3 -6
- package/src/index.js.map +1 -1
- package/src/lib/add-dir.js +12 -16
- package/src/lib/add-dir.js.map +1 -1
- package/src/lib/apply-ts-morph-project.js +7 -11
- package/src/lib/apply-ts-morph-project.js.map +1 -1
- package/src/lib/ts-morph-transform.d.ts +8 -5
- package/src/lib/ts-morph-transform.js +31 -36
- package/src/lib/ts-morph-transform.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.1.0-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/workspace-ts-morph@0.1.0-dev.0...@rxap/workspace-ts-morph@0.1.0-dev.1) (2023-08-16)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- change from commonjs to es2022 ([fd0f2ba](https://gitlab.com/rxap/packages/commit/fd0f2bae24eae7c854e96f630076cd5598c30be6))
|
|
11
|
+
|
|
12
|
+
# [0.1.0-dev.0](https://gitlab.com/rxap/packages/compare/@rxap/workspace-ts-morph@0.0.2-dev.1...@rxap/workspace-ts-morph@0.1.0-dev.0) (2023-08-05)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- support replace option ([50f2ac4](https://gitlab.com/rxap/packages/commit/50f2ac4d89017027c51a51223cd58a466edef1d0))
|
|
17
|
+
|
|
6
18
|
## [0.0.2-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/workspace-ts-morph@0.0.2-dev.0...@rxap/workspace-ts-morph@0.0.2-dev.1) (2023-08-04)
|
|
7
19
|
|
|
8
20
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -17,5 +17,5 @@ yarn add @rxap/workspace-ts-morph
|
|
|
17
17
|
```
|
|
18
18
|
**Install peer dependencies:**
|
|
19
19
|
```bash
|
|
20
|
-
yarn add @rxap/utilities@^16.0.0-dev.
|
|
20
|
+
yarn add @rxap/utilities@^16.0.0-dev.6 @rxap/workspace-utilities@^0.1.0-dev.2 ts-morph@^18.0.0
|
|
21
21
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxap/workspace-ts-morph",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "0.1.0-dev.1",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"directory": "../../../dist/packages/workspace/ts-morph"
|
|
@@ -34,24 +34,24 @@
|
|
|
34
34
|
"tslib": "2.6.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@rxap/utilities": "^16.0.0-dev.
|
|
38
|
-
"@rxap/workspace-utilities": "^0.1.0-dev.
|
|
37
|
+
"@rxap/utilities": "^16.0.0-dev.6",
|
|
38
|
+
"@rxap/workspace-utilities": "^0.1.0-dev.2",
|
|
39
39
|
"ts-morph": "^18.0.0",
|
|
40
|
-
"@rxap/node-utilities": "1.1.0-dev.
|
|
40
|
+
"@rxap/node-utilities": "1.1.0-dev.2"
|
|
41
41
|
},
|
|
42
42
|
"nx-migrations": {
|
|
43
43
|
"packageGroup": [
|
|
44
44
|
{
|
|
45
45
|
"package": "@rxap/utilities",
|
|
46
|
-
"version": "16.0.0-dev.
|
|
46
|
+
"version": "16.0.0-dev.6"
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
"package": "@rxap/workspace-utilities",
|
|
50
|
-
"version": "0.1.0-dev.
|
|
50
|
+
"version": "0.1.0-dev.2"
|
|
51
51
|
}
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "bbab80e59acbe435a02e69c9fec022780cf4640d",
|
|
55
55
|
"main": "./src/index.js",
|
|
56
56
|
"types": "./src/index.d.ts"
|
|
57
57
|
}
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
1
|
// region
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export * from './lib/add-dir';
|
|
3
|
+
export * from './lib/apply-ts-morph-project';
|
|
4
|
+
export * from './lib/ts-morph-transform';
|
|
8
5
|
// endregion
|
|
9
6
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/workspace/ts-morph/src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/workspace/ts-morph/src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,YAAY"}
|
package/src/lib/add-dir.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.AddDir = void 0;
|
|
4
|
-
const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
5
|
-
const path_1 = require("path");
|
|
1
|
+
import { IsGeneratorTreeLike, IsSchematicTreeLike, } from '@rxap/workspace-utilities';
|
|
2
|
+
import { join, relative, } from 'path';
|
|
6
3
|
/**
|
|
7
4
|
* Adds all files recursively from a specify path to the project.
|
|
8
5
|
* @param tree A nx Tree instance
|
|
@@ -10,32 +7,31 @@ const path_1 = require("path");
|
|
|
10
7
|
* @param project A ts-morph Project instance
|
|
11
8
|
* @param filter A filter function base on the pathFragment and dirEntry
|
|
12
9
|
*/
|
|
13
|
-
function AddDir(tree, directoryPath, project, filter = path => path.endsWith('.ts'), basePath = directoryPath) {
|
|
14
|
-
if (
|
|
10
|
+
export function AddDir(tree, directoryPath, project, filter = path => path.endsWith('.ts'), basePath = directoryPath) {
|
|
11
|
+
if (IsSchematicTreeLike(tree)) {
|
|
15
12
|
return SchematicAddDir(tree.getDir(directoryPath), project, '', (pathFragment, dirEntry) => filter(pathFragment, dirEntry.path));
|
|
16
13
|
}
|
|
17
|
-
if (
|
|
14
|
+
if (IsGeneratorTreeLike(tree)) {
|
|
18
15
|
if (tree.isFile(directoryPath)) {
|
|
19
16
|
throw new Error(`The path '${directoryPath}' does not point to a dir entry`);
|
|
20
17
|
}
|
|
21
18
|
const children = tree.children(directoryPath);
|
|
22
|
-
const files = children.filter(fileOrDirectoryName => tree.isFile(
|
|
19
|
+
const files = children.filter(fileOrDirectoryName => tree.isFile(join(directoryPath, fileOrDirectoryName)));
|
|
23
20
|
const includeFiles = files.filter(fileName => filter(fileName, directoryPath));
|
|
24
21
|
for (const fileName of includeFiles) {
|
|
25
|
-
const filePath =
|
|
26
|
-
const projectFilePath =
|
|
22
|
+
const filePath = join(directoryPath, fileName);
|
|
23
|
+
const projectFilePath = relative(basePath, filePath);
|
|
27
24
|
if (!project.getSourceFile(projectFilePath)) {
|
|
28
25
|
project.createSourceFile(projectFilePath, tree.read(filePath).toString('utf-8'));
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
|
-
for (const dirName of tree.children(directoryPath).filter(pf => !tree.isFile(
|
|
32
|
-
AddDir(tree,
|
|
28
|
+
for (const dirName of tree.children(directoryPath).filter(pf => !tree.isFile(join(directoryPath, pf)))) {
|
|
29
|
+
AddDir(tree, join(directoryPath, dirName), project, filter, basePath);
|
|
33
30
|
}
|
|
34
31
|
return;
|
|
35
32
|
}
|
|
36
33
|
throw new Error('The tree is not a valid nx or angular schematic tree');
|
|
37
34
|
}
|
|
38
|
-
exports.AddDir = AddDir;
|
|
39
35
|
/**
|
|
40
36
|
* Adds all files recursively from a specify DirEntry to the project.
|
|
41
37
|
* @param dir A schematic DirEntry instance
|
|
@@ -47,7 +43,7 @@ function SchematicAddDir(dir, project, parentPath = '', filter = pathFragment =>
|
|
|
47
43
|
for (const pathFragment of dir.subfiles.filter(pf => filter(pf, dir))) {
|
|
48
44
|
const fileEntry = dir.file(pathFragment);
|
|
49
45
|
if (fileEntry) {
|
|
50
|
-
const filePath =
|
|
46
|
+
const filePath = join(parentPath, pathFragment);
|
|
51
47
|
if (!project.getSourceFile(filePath)) {
|
|
52
48
|
project.createSourceFile(filePath, fileEntry.content.toString('utf-8'));
|
|
53
49
|
}
|
|
@@ -59,7 +55,7 @@ function SchematicAddDir(dir, project, parentPath = '', filter = pathFragment =>
|
|
|
59
55
|
for (const pathFragment of dir.subdirs) {
|
|
60
56
|
const dirEntry = dir.dir(pathFragment);
|
|
61
57
|
if (dirEntry) {
|
|
62
|
-
SchematicAddDir(dirEntry, project,
|
|
58
|
+
SchematicAddDir(dirEntry, project, join(parentPath, pathFragment), filter);
|
|
63
59
|
}
|
|
64
60
|
else {
|
|
65
61
|
throw new Error('The path fragment does not point to a dir entry');
|
package/src/lib/add-dir.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-dir.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/add-dir.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"add-dir.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/add-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,mBAAmB,GAEpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,IAAI,EACJ,QAAQ,GACT,MAAM,MAAM,CAAC;AAGd;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CACpB,IAAc,EACd,a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GAAG,CAAC,YAAY,CAAC,CAAC;QACvC,IAAI,QAAQ,EAAE;YACZ,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,CAAC;SAC5E;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;SACpE;KACF;AACH,CAAC"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const ts_morph_1 = require("ts-morph");
|
|
1
|
+
import { TreeAdapter, } from '@rxap/workspace-utilities';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { Project, } from 'ts-morph';
|
|
7
4
|
function areSame(sourceFile1, sourceFile2) {
|
|
8
5
|
const leafNodes1 = getLeafNodes(sourceFile1);
|
|
9
6
|
const leafNodes2 = getLeafNodes(sourceFile2);
|
|
@@ -36,7 +33,7 @@ function areSame(sourceFile1, sourceFile2) {
|
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
function ApplyTsMorphProject(tree, project, basePath = '', organizeImports = true, fixMissingImports = false) {
|
|
36
|
+
export function ApplyTsMorphProject(tree, project, basePath = '', organizeImports = true, fixMissingImports = false) {
|
|
40
37
|
if (organizeImports || fixMissingImports) {
|
|
41
38
|
project
|
|
42
39
|
.getSourceFiles()
|
|
@@ -49,14 +46,14 @@ function ApplyTsMorphProject(tree, project, basePath = '', organizeImports = tru
|
|
|
49
46
|
}
|
|
50
47
|
});
|
|
51
48
|
}
|
|
52
|
-
const treeAdapter = new
|
|
49
|
+
const treeAdapter = new TreeAdapter(tree);
|
|
53
50
|
project
|
|
54
51
|
.getSourceFiles()
|
|
55
52
|
.forEach(sourceFile => {
|
|
56
|
-
const filePath =
|
|
53
|
+
const filePath = join(basePath, sourceFile.getFilePath());
|
|
57
54
|
if (tree.exists(filePath)) {
|
|
58
55
|
const currentContent = treeAdapter.read(filePath).toString('utf-8');
|
|
59
|
-
const tmpProject = new
|
|
56
|
+
const tmpProject = new Project();
|
|
60
57
|
const newContent = sourceFile.getFullText();
|
|
61
58
|
if (!areSame(sourceFile, tmpProject.createSourceFile('/tmp.ts', currentContent))) {
|
|
62
59
|
treeAdapter.overwrite(filePath, newContent);
|
|
@@ -67,5 +64,4 @@ function ApplyTsMorphProject(tree, project, basePath = '', organizeImports = tru
|
|
|
67
64
|
}
|
|
68
65
|
});
|
|
69
66
|
}
|
|
70
|
-
exports.ApplyTsMorphProject = ApplyTsMorphProject;
|
|
71
67
|
//# sourceMappingURL=apply-ts-morph-project.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-ts-morph-project.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/apply-ts-morph-project.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"apply-ts-morph-project.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/apply-ts-morph-project.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAEZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAEL,OAAO,GAER,MAAM,UAAU,CAAC;AAElB,SAAS,OAAO,CAAC,WAAuB,EAAE,WAAuB;IAC/D,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAE7C,iDAAiD;IACjD,OAAO,IAAI,EAAE;QACX,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAEhC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE;YAC5B,OAAO,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AQ,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QAE1D,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;YACzB,MAAM,cAAc,GAAG,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACrE,MAAM,UAAU,GAAG,IAAI,OAAO,EAAE,CAAC;YACjC,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;YAC5C,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,EAAE;gBAChF,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;aAC7C;SACF;aAAM;YACL,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;SACxD;IAEH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { BuildAngularBasePathOptions, TreeLike } from '@rxap/workspace-utilities';
|
|
2
2
|
import { Project, ProjectOptions, SourceFile } from 'ts-morph';
|
|
3
3
|
export type TsMorphTransformCallback = ((project: Project, sourceFile: undefined) => void) | ((project: Project, sourceFile: SourceFile) => void) | ((project: Project, sourceFile: SourceFile[]) => void);
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
4
|
+
export interface TsMorphTransformOptions {
|
|
5
|
+
replace?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function TsMorphTransform(tree: TreeLike, sourceRoot: string, cb: (project: Project, sourceFile: SourceFile[]) => void, options?: TsMorphTransformOptions, projectOptions?: Partial<ProjectOptions>, filePath?: string[]): void;
|
|
8
|
+
export declare function TsMorphTransform(tree: TreeLike, sourceRoot: string, cb: (project: Project, sourceFile: SourceFile) => void, options?: TsMorphTransformOptions, projectOptions?: Partial<ProjectOptions>, filePath?: string): void;
|
|
9
|
+
export declare function TsMorphTransform(tree: TreeLike, sourceRoot: string, cb: (project: Project, sourceFile: undefined) => void, options?: TsMorphTransformOptions, projectOptions?: Partial<ProjectOptions>, filePath?: undefined): void;
|
|
10
|
+
export interface TsMorphNestProjectTransformOptions extends TsMorphTransformOptions {
|
|
8
11
|
project: string;
|
|
9
12
|
feature?: string | null;
|
|
10
13
|
shared?: boolean;
|
|
@@ -17,7 +20,7 @@ export declare function TsMorphNestProjectTransform(tree: TreeLike, options: Rea
|
|
|
17
20
|
*/
|
|
18
21
|
export declare function TsMorphNestProjectTransform(tree: TreeLike, options: Readonly<TsMorphNestProjectTransformOptions>, cb: (project: Project, sourceFile: SourceFile) => void, filePath: string): void;
|
|
19
22
|
export declare function TsMorphNestProjectTransform(tree: TreeLike, options: Readonly<TsMorphNestProjectTransformOptions>, cb: (project: Project, sourceFile: undefined) => void, filePath?: undefined): void;
|
|
20
|
-
export interface TsMorphAngularProjectTransformOptions extends BuildAngularBasePathOptions {
|
|
23
|
+
export interface TsMorphAngularProjectTransformOptions extends BuildAngularBasePathOptions, TsMorphTransformOptions {
|
|
21
24
|
projectOptions?: Partial<ProjectOptions>;
|
|
22
25
|
}
|
|
23
26
|
export declare function TsMorphAngularProjectTransform(tree: TreeLike, options: Readonly<TsMorphAngularProjectTransformOptions>, cb: (project: Project, sourceFile: SourceFile[]) => void, filePath: string[]): void;
|
|
@@ -1,43 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const add_dir_1 = require("./add-dir");
|
|
9
|
-
const apply_ts_morph_project_1 = require("./apply-ts-morph-project");
|
|
10
|
-
function TsMorphTransform(tree, sourceRoot, cb, options = {}, filePathFilter) {
|
|
1
|
+
import { deepMerge } from '@rxap/utilities';
|
|
2
|
+
import { BuildAngularBasePath, BuildNestBasePath, } from '@rxap/workspace-utilities';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { IndentationText, Project, QuoteKind, } from 'ts-morph';
|
|
5
|
+
import { AddDir } from './add-dir';
|
|
6
|
+
import { ApplyTsMorphProject } from './apply-ts-morph-project';
|
|
7
|
+
export function TsMorphTransform(tree, sourceRoot, cb, options = {}, projectOptions = {}, filePathFilter) {
|
|
11
8
|
const filePath = filePathFilter ?
|
|
12
9
|
Array.isArray(filePathFilter) ?
|
|
13
10
|
filePathFilter.map(f => f.replace(/\?$/, '')) :
|
|
14
11
|
[filePathFilter.replace(/\?$/, '')] :
|
|
15
12
|
undefined;
|
|
16
|
-
const project = new
|
|
13
|
+
const project = new Project(deepMerge({
|
|
17
14
|
manipulationSettings: {
|
|
18
|
-
indentationText:
|
|
19
|
-
quoteKind:
|
|
15
|
+
indentationText: IndentationText.TwoSpaces,
|
|
16
|
+
quoteKind: QuoteKind.Single,
|
|
20
17
|
},
|
|
21
18
|
useInMemoryFileSystem: true,
|
|
22
|
-
},
|
|
23
|
-
(
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
}, projectOptions));
|
|
20
|
+
if (!options.replace) {
|
|
21
|
+
AddDir(tree, sourceRoot, project, filePath ?
|
|
22
|
+
(fileName, dirPath) => {
|
|
23
|
+
const fullPath = join(dirPath, fileName);
|
|
24
|
+
if (dirPath.endsWith(fileName)) {
|
|
25
|
+
throw new Error(`The dirPath '${dirPath}' ends with the fileName '${fileName}'`);
|
|
26
|
+
}
|
|
27
|
+
return filePath.some(f => fullPath.endsWith(f));
|
|
28
|
+
} :
|
|
29
|
+
undefined);
|
|
30
|
+
}
|
|
32
31
|
let sourceFile = undefined;
|
|
33
32
|
if (filePath) {
|
|
34
33
|
if (Array.isArray(filePath)) {
|
|
35
34
|
sourceFile = filePath.map((f, index) => {
|
|
36
|
-
var _a;
|
|
37
35
|
let sf = project.getSourceFile(f);
|
|
38
36
|
if (!sf) {
|
|
39
37
|
if (Array.isArray(filePathFilter)) {
|
|
40
|
-
if (
|
|
38
|
+
if (options.replace || filePathFilter[index]?.endsWith('?')) {
|
|
41
39
|
sf = project.createSourceFile(f, '');
|
|
42
40
|
}
|
|
43
41
|
else {
|
|
@@ -49,7 +47,7 @@ function TsMorphTransform(tree, sourceRoot, cb, options = {}, filePathFilter) {
|
|
|
49
47
|
if (index !== 0) {
|
|
50
48
|
throw new Error('FATAL: The filePathFilter is not an array and the index is not 0');
|
|
51
49
|
}
|
|
52
|
-
if (
|
|
50
|
+
if (options.replace || filePathFilter?.endsWith('?')) {
|
|
53
51
|
sf = project.createSourceFile(f, '');
|
|
54
52
|
}
|
|
55
53
|
else {
|
|
@@ -65,17 +63,14 @@ function TsMorphTransform(tree, sourceRoot, cb, options = {}, filePathFilter) {
|
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
cb(project, sourceFile);
|
|
68
|
-
|
|
66
|
+
ApplyTsMorphProject(tree, project, sourceRoot, false);
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return TsMorphTransform(tree, basePath, cb, options.projectOptions, filePath);
|
|
68
|
+
export function TsMorphNestProjectTransform(tree, options, cb, filePath) {
|
|
69
|
+
const basePath = BuildNestBasePath(tree, options);
|
|
70
|
+
return TsMorphTransform(tree, basePath, cb, { replace: options.replace }, options.projectOptions, filePath);
|
|
74
71
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return TsMorphTransform(tree, basePath, cb, options.projectOptions, filePath);
|
|
72
|
+
export function TsMorphAngularProjectTransform(tree, options, cb, filePath) {
|
|
73
|
+
const basePath = BuildAngularBasePath(tree, options);
|
|
74
|
+
return TsMorphTransform(tree, basePath, cb, { replace: options.replace }, options.projectOptions, filePath);
|
|
79
75
|
}
|
|
80
|
-
exports.TsMorphAngularProjectTransform = TsMorphAngularProjectTransform;
|
|
81
76
|
//# sourceMappingURL=ts-morph-transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-morph-transform.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/ts-morph-transform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ts-morph-transform.js","sourceRoot":"","sources":["../../../../../../packages/workspace/ts-morph/src/lib/ts-morph-transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,oBAAoB,EAEpB,iBAAiB,GAElB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,eAAe,EACf,OAAO,EAEP,SAAS,GAEV,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAkC/D,MAAM,UAAU,gBAAgB,CAC9B,IAAc,EACd,UAAkB,EAClB,EAA4B,EAC5B,UAAmC,EAAE,EACrC,iBAA0C,EAAE,EAC5C,cAA8C;IAE9C,MAAM,QAAQ,GAAG,cAAc,CAAC,CAAC;QAC/B,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;YAC7B,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/C,CAAE,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAE,CAAC,CAAC;QACzC,SAAS,CAAC;IAEZ,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC;QACpC,oBAAoB,EAAE;YACpB,eAAe,EAAE,eAAe,CAAC,SAAS;YAC1C,SAAS,EAAE,SAAS,CAAC,MAAM;SAC5B;QACD,qBAAqB,EAAE,IAAI;KAC5B,EAA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