@trackunit/nx-utils 0.0.2 → 0.0.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
@@ -2,6 +2,8 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.3](https://github.com/Trackunit/manager/compare/nx-utils/0.0.2...nx-utils/0.0.3) (2023-03-23)
6
+
5
7
  ## [0.0.2](https://github.com/Trackunit/manager/compare/nx-utils/0.0.1...nx-utils/0.0.2) (2023-03-22)
6
8
 
7
9
  ## 0.0.1 (2023-03-13)
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@trackunit/nx-utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "src/lib/index.ts",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
7
7
  "types": "./src/index.d.ts",
8
8
  "dependencies": {
9
+ "@phenomnomnominal/tsquery": "4.2.0",
9
10
  "tslib": "2.4.1"
10
11
  },
11
12
  "peerDependencies": {}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removePropertyWithName = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
6
+ const ts = tslib_1.__importStar(require("typescript"));
7
+ /**
8
+ * This function removes a property with a given name from an object literal
9
+ * provided as a text string.
10
+ *
11
+ * @param {string} fileContent - the source code as text
12
+ * @param {string} propertyName - the property to remove from the source code
13
+ */
14
+ function removePropertyWithName(fileContent, propertyName) {
15
+ const sourceFile = tsquery_1.tsquery.ast(fileContent);
16
+ const updatedSourceFile = tsquery_1.tsquery.map(sourceFile, "ObjectLiteralExpression", node => {
17
+ if (ts.isObjectLiteralExpression(node)) {
18
+ // Filter out the given property
19
+ const updatedProperties = node.properties.filter(property => {
20
+ return !(ts.isPropertyAssignment(property) &&
21
+ ts.isIdentifier(property.name) &&
22
+ property.name.text === propertyName);
23
+ });
24
+ return ts.factory.createObjectLiteralExpression(updatedProperties, true);
25
+ }
26
+ return node;
27
+ });
28
+ return ts.createPrinter().printFile(updatedSourceFile);
29
+ }
30
+ exports.removePropertyWithName = removePropertyWithName;
31
+ //# sourceMappingURL=astUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astUtils.js","sourceRoot":"","sources":["../../../../../../libs/nx/utils/src/ast/astUtils.ts"],"names":[],"mappings":";;;;AAAA,uDAAoD;AACpD,uDAAiC;AAEjC;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,WAAmB,EAAE,YAAoB;IAC9E,MAAM,UAAU,GAAG,iBAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC5C,MAAM,iBAAiB,GAAG,iBAAO,CAAC,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,IAAI,CAAC,EAAE;QAClF,IAAI,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE;YACtC,gCAAgC;YAChC,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;gBAC1D,OAAO,CAAC,CACN,EAAE,CAAC,oBAAoB,CAAC,QAAQ,CAAC;oBACjC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC;oBAC9B,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,CACpC,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,OAAO,EAAE,CAAC,OAAO,CAAC,6BAA6B,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;SAC1E;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;AACzD,CAAC;AAjBD,wDAiBC","sourcesContent":["import { tsquery } from \"@phenomnomnominal/tsquery\";\nimport * as ts from \"typescript\";\n\n/**\n * This function removes a property with a given name from an object literal\n * provided as a text string.\n *\n * @param {string} fileContent - the source code as text\n * @param {string} propertyName - the property to remove from the source code\n */\nexport function removePropertyWithName(fileContent: string, propertyName: string) {\n const sourceFile = tsquery.ast(fileContent);\n const updatedSourceFile = tsquery.map(sourceFile, \"ObjectLiteralExpression\", node => {\n if (ts.isObjectLiteralExpression(node)) {\n // Filter out the given property\n const updatedProperties = node.properties.filter(property => {\n return !(\n ts.isPropertyAssignment(property) &&\n ts.isIdentifier(property.name) &&\n property.name.text === propertyName\n );\n });\n return ts.factory.createObjectLiteralExpression(updatedProperties, true);\n }\n return node;\n });\n return ts.createPrinter().printFile(updatedSourceFile);\n}\n"]}
package/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./ast/astUtils"), exports);
4
5
  tslib_1.__exportStar(require("./nxTestUtils"), exports);
5
6
  tslib_1.__exportStar(require("./projectUtils"), exports);
6
7
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,yDAA+B","sourcesContent":["export * from \"./nxTestUtils\";\nexport * from \"./projectUtils\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,wDAA8B;AAC9B,yDAA+B","sourcesContent":["export * from \"./ast/astUtils\";\nexport * from \"./nxTestUtils\";\nexport * from \"./projectUtils\";\n"]}