@rxap/schematics-ts-morph 14.1.0-dev.2 → 14.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/CHANGELOG.md CHANGED
@@ -3,6 +3,26 @@
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
+ # [14.1.0](https://gitlab.com/rxap/packages/compare/@rxap/schematics-ts-morph@14.1.0-dev.3...@rxap/schematics-ts-morph@14.1.0) (2023-05-17)
7
+
8
+ **Note:** Version bump only for package @rxap/schematics-ts-morph
9
+
10
+
11
+
12
+
13
+
14
+ # [14.1.0-dev.3](https://gitlab.com/rxap/packages/compare/@rxap/schematics-ts-morph@14.1.0-dev.2...@rxap/schematics-ts-morph@14.1.0-dev.3) (2023-04-18)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * add fixMissingImports option ([b9ae8ed](https://gitlab.com/rxap/packages/commit/b9ae8ed4b25d635b70844d083283057e3de73873))
20
+ * only update changed files ([ae95f39](https://gitlab.com/rxap/packages/commit/ae95f390c06779bd5d275301580a69511bddca44))
21
+
22
+
23
+
24
+
25
+
6
26
  # [14.1.0-dev.2](https://gitlab.com/rxap/packages/compare/@rxap/schematics-ts-morph@14.1.0-dev.1...@rxap/schematics-ts-morph@14.1.0-dev.2) (2023-04-10)
7
27
 
8
28
 
package/README.md CHANGED
@@ -15,6 +15,6 @@
15
15
  # Installation
16
16
 
17
17
  ```
18
- yarn add @rxap/schematics-ts-morph @rxap/schematics-utilities@^14.0.4
18
+ yarn add @rxap/schematics-ts-morph @rxap/schematics-utilities@^14.0.5-dev.0
19
19
  ```
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxap/schematics-ts-morph",
3
- "version": "14.1.0-dev.2",
3
+ "version": "14.1.0",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1"
6
6
  },
@@ -35,7 +35,7 @@
35
35
  "migrations": "./migration.json"
36
36
  },
37
37
  "peerDependencies": {
38
- "@rxap/schematics-utilities": "^14.0.4",
38
+ "@rxap/schematics-utilities": "^14.0.5",
39
39
  "ts-morph": "^13.0.3",
40
40
  "semver": "^7.3.5"
41
41
  },
@@ -1,3 +1,3 @@
1
1
  import { Rule } from '@angular-devkit/schematics';
2
2
  import { Project } from 'ts-morph';
3
- export declare function ApplyTsMorphProject(project: Project, basePath?: string, organizeImports?: boolean): Rule;
3
+ export declare function ApplyTsMorphProject(project: Project, basePath?: string, organizeImports?: boolean, fixMissingImports?: boolean): Rule;
@@ -2,29 +2,67 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApplyTsMorphProject = void 0;
4
4
  const path_1 = require("path");
5
- function ApplyTsMorphProject(project, basePath = '', organizeImports = true) {
5
+ const ts_morph_1 = require("ts-morph");
6
+ function areSame(sourceFile1, sourceFile2) {
7
+ const leafNodes1 = getLeafNodes(sourceFile1);
8
+ const leafNodes2 = getLeafNodes(sourceFile2);
9
+ while (true) {
10
+ const leaf1 = leafNodes1.next();
11
+ const leaf2 = leafNodes2.next();
12
+ if (leaf1.done && leaf2.done) {
13
+ return true;
14
+ }
15
+ if (leaf1.done || leaf2.done) {
16
+ return false;
17
+ }
18
+ if (leaf1.value.getText() !== leaf2.value.getText()) {
19
+ return false;
20
+ }
21
+ }
22
+ function* getLeafNodes(sourceFile) {
23
+ yield* searchNode(sourceFile);
24
+ // @ts-ignore
25
+ function* searchNode(node) {
26
+ const children = node.getChildren();
27
+ if (children.length === 0) {
28
+ yield node;
29
+ }
30
+ else {
31
+ for (const child of children) {
32
+ yield* searchNode(child);
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ function ApplyTsMorphProject(project, basePath = '', organizeImports = true, fixMissingImports = false) {
6
39
  return tree => {
7
- if (organizeImports) {
40
+ if (organizeImports || fixMissingImports) {
8
41
  project
9
42
  .getSourceFiles()
10
- .forEach(sourceFile => sourceFile.organizeImports());
43
+ .forEach(sourceFile => {
44
+ if (fixMissingImports) {
45
+ sourceFile.fixMissingImports();
46
+ }
47
+ if (organizeImports) {
48
+ sourceFile.organizeImports();
49
+ }
50
+ });
11
51
  }
12
- let written = 0;
13
52
  project
14
53
  .getSourceFiles()
15
54
  .forEach(sourceFile => {
16
55
  const filePath = (0, path_1.join)(basePath, sourceFile.getFilePath());
17
56
  if (tree.exists(filePath)) {
18
57
  const currentContent = tree.read(filePath).toString('utf-8');
58
+ const tmpProject = new ts_morph_1.Project();
19
59
  const newContent = sourceFile.getFullText();
20
- if (currentContent.trim() !== newContent.trim()) {
21
- written++;
60
+ if (!areSame(sourceFile, tmpProject.createSourceFile('/tmp.ts', currentContent))) {
22
61
  tree.overwrite(filePath, newContent);
23
62
  }
24
63
  }
25
64
  else {
26
65
  tree.create(filePath, sourceFile.getFullText());
27
- written++;
28
66
  }
29
67
  });
30
68
  };
@@ -1 +1 @@
1
- {"version":3,"file":"apply-ts-morph-project.js","sourceRoot":"","sources":["../../../../../libs/ts-morph/src/lib/apply-ts-morph-project.ts"],"names":[],"mappings":";;;AACA,+BAA4B;AAG5B,SAAgB,mBAAmB,CAAC,OAAgB,EAAE,WAAmB,EAAE,EAAE,kBAA2B,IAAI;IAC1G,OAAO,IAAI,CAAC,EAAE;QAEZ,IAAI,eAAe,EAAE;YACnB,OAAO;iBACJ,cAAc,EAAE;iBAChB,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,EAAE,CAAC,CAAC;SACxD;QAED,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,OAAO;aACJ,cAAc,EAAE;aAChB,OAAO,CAAC,UAAU,CAAC,EAAE;YAEpB,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,QAAQ,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;YAE1D,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;gBACzB,MAAM,cAAc,GAAG,IAAI,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