@rxap/schematics-ts-morph 14.1.0-dev.1 → 14.1.0-dev.3

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,29 @@
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-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)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * add fixMissingImports option ([b9ae8ed](https://gitlab.com/rxap/packages/commit/b9ae8ed4b25d635b70844d083283057e3de73873))
12
+ * only update changed files ([ae95f39](https://gitlab.com/rxap/packages/commit/ae95f390c06779bd5d275301580a69511bddca44))
13
+
14
+
15
+
16
+
17
+
18
+ # [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)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * remove verbose logging ([adeaa66](https://gitlab.com/rxap/packages/commit/adeaa66a9f9a8879d98d2127eccedd127bcae961))
24
+
25
+
26
+
27
+
28
+
6
29
  # [14.1.0-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/schematics-ts-morph@14.1.0-dev.0...@rxap/schematics-ts-morph@14.1.0-dev.1) (2023-04-09)
7
30
 
8
31
 
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.1",
3
+ "version": "14.1.0-dev.3",
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-dev.0",
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,34 +2,69 @@
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) {
8
- console.debug(`organize '${project.getSourceFiles().length}' ts files imports`);
40
+ if (organizeImports || fixMissingImports) {
9
41
  project
10
42
  .getSourceFiles()
11
- .forEach(sourceFile => sourceFile.organizeImports());
43
+ .forEach(sourceFile => {
44
+ if (fixMissingImports) {
45
+ sourceFile.fixMissingImports();
46
+ }
47
+ if (organizeImports) {
48
+ sourceFile.organizeImports();
49
+ }
50
+ });
12
51
  }
13
- console.debug(`write '${project.getSourceFiles().length}' ts files to tree`);
14
- let written = 0;
15
52
  project
16
53
  .getSourceFiles()
17
54
  .forEach(sourceFile => {
18
55
  const filePath = (0, path_1.join)(basePath, sourceFile.getFilePath());
19
56
  if (tree.exists(filePath)) {
20
57
  const currentContent = tree.read(filePath).toString('utf-8');
58
+ const tmpProject = new ts_morph_1.Project();
21
59
  const newContent = sourceFile.getFullText();
22
- if (currentContent.trim() !== newContent.trim()) {
23
- written++;
60
+ if (!areSame(sourceFile, tmpProject.createSourceFile('/tmp.ts', currentContent))) {
24
61
  tree.overwrite(filePath, newContent);
25
62
  }
26
63
  }
27
64
  else {
28
65
  tree.create(filePath, sourceFile.getFullText());
29
- written++;
30
66
  }
31
67
  });
32
- console.log('written: ' + written);
33
68
  };
34
69
  }
35
70
  exports.ApplyTsMorphProject = ApplyTsMorphProject;
@@ -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,CAAC,KAAK,CAAC,aAAa,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,oBAAoB,CAAC,CAAC;YAChF,OAAO;iBACJ,cAAc,EAAE;iBAChB,OAAO,CAAC,UAAU,CA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