@trackunit/nx-utils 0.0.7 → 0.0.9
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 +4 -0
- package/package.json +3 -4
- package/src/ast/astUtils.d.ts +17 -0
- package/src/ast/astUtils.js +17 -4
- package/src/ast/astUtils.js.map +1 -1
- package/src/fileUpdater.d.ts +8 -0
- package/src/fileUpdater.js +24 -0
- package/src/fileUpdater.js.map +1 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +9 -0
- package/src/index.js.map +1 -1
- package/src/nxTestUtils.d.ts +7 -0
- package/src/nxTestUtils.js +1 -0
- package/src/nxTestUtils.js.map +1 -1
- package/src/projectUtils.d.ts +37 -0
- package/src/projectUtils.js +30 -23
- package/src/projectUtils.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.9](https://github.com/Trackunit/manager/compare/nx-utils/0.0.8...nx-utils/0.0.9) (2023-04-19)
|
|
6
|
+
|
|
7
|
+
## [0.0.8](https://github.com/Trackunit/manager/compare/nx-utils/0.0.7...nx-utils/0.0.8) (2023-04-14)
|
|
8
|
+
|
|
5
9
|
## [0.0.7](https://github.com/Trackunit/manager/compare/nx-utils/0.0.6...nx-utils/0.0.7) (2023-04-14)
|
|
6
10
|
|
|
7
11
|
## [0.0.6](https://github.com/Trackunit/manager/compare/nx-utils/0.0.5...nx-utils/0.0.6) (2023-04-11)
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/nx-utils",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "src/
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"main": "src/index.js",
|
|
5
5
|
"repository": "https://github.com/Trackunit/manager",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
7
|
-
"types": "./src/index.d.ts",
|
|
8
7
|
"dependencies": {
|
|
9
8
|
"@phenomnomnominal/tsquery": "4.2.0",
|
|
10
9
|
"tslib": "2.4.1"
|
|
11
10
|
},
|
|
12
|
-
"
|
|
11
|
+
"types": "./src/index.d.ts"
|
|
13
12
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function removes a property with a given name from an object literal
|
|
3
|
+
* provided as a text string.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} fileContent The source code as text
|
|
6
|
+
* @param {string} propertyNames The properties to remove from the object
|
|
7
|
+
*/
|
|
8
|
+
export declare function removePropertyWithName(fileContent: string, ...propertyNames: string[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* This function adds a new property with a given name and value to an object literal
|
|
11
|
+
* provided as a text string.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} fileContent - the source code as text
|
|
14
|
+
* @param {string} propertyName - the name of the property to add
|
|
15
|
+
* @param {string | string[]} propertyValue - the value of the property to add
|
|
16
|
+
*/
|
|
17
|
+
export declare function addPropertyWithName(fileContent: string, propertyName: string, propertyValue: string | string[] | Record<string, string>): string;
|
package/src/ast/astUtils.js
CHANGED
|
@@ -8,10 +8,10 @@ const ts = tslib_1.__importStar(require("typescript"));
|
|
|
8
8
|
* This function removes a property with a given name from an object literal
|
|
9
9
|
* provided as a text string.
|
|
10
10
|
*
|
|
11
|
-
* @param {string} fileContent
|
|
12
|
-
* @param {string}
|
|
11
|
+
* @param {string} fileContent The source code as text
|
|
12
|
+
* @param {string} propertyNames The properties to remove from the object
|
|
13
13
|
*/
|
|
14
|
-
function removePropertyWithName(fileContent,
|
|
14
|
+
function removePropertyWithName(fileContent, ...propertyNames) {
|
|
15
15
|
const sourceFile = tsquery_1.tsquery.ast(fileContent);
|
|
16
16
|
const updatedSourceFile = tsquery_1.tsquery.map(sourceFile, "ObjectLiteralExpression", node => {
|
|
17
17
|
if (ts.isObjectLiteralExpression(node)) {
|
|
@@ -19,7 +19,7 @@ function removePropertyWithName(fileContent, propertyName) {
|
|
|
19
19
|
const updatedProperties = node.properties.filter(property => {
|
|
20
20
|
return !(ts.isPropertyAssignment(property) &&
|
|
21
21
|
ts.isIdentifier(property.name) &&
|
|
22
|
-
property.name.text
|
|
22
|
+
propertyNames.includes(property.name.text));
|
|
23
23
|
});
|
|
24
24
|
return ts.factory.createObjectLiteralExpression(updatedProperties, true);
|
|
25
25
|
}
|
|
@@ -55,6 +55,12 @@ function addPropertyWithName(fileContent, propertyName, propertyValue) {
|
|
|
55
55
|
ts.factory.createPropertyAssignment(ts.factory.createIdentifier(propertyName), arrayLiteral),
|
|
56
56
|
];
|
|
57
57
|
}
|
|
58
|
+
else if (typeof propertyValue === "object") {
|
|
59
|
+
updatedProperties = [
|
|
60
|
+
...node.properties,
|
|
61
|
+
ts.factory.createPropertyAssignment(ts.factory.createIdentifier(propertyName), ts.factory.createObjectLiteralExpression(createObjectLiteralElementLike(propertyValue))),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
58
64
|
return ts.factory.createObjectLiteralExpression(updatedProperties, true);
|
|
59
65
|
}
|
|
60
66
|
return node;
|
|
@@ -62,4 +68,11 @@ function addPropertyWithName(fileContent, propertyName, propertyValue) {
|
|
|
62
68
|
return ts.createPrinter().printFile(updatedSourceFile);
|
|
63
69
|
}
|
|
64
70
|
exports.addPropertyWithName = addPropertyWithName;
|
|
71
|
+
function createObjectLiteralElementLike(obj) {
|
|
72
|
+
const properties = [];
|
|
73
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
74
|
+
properties.push(ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createStringLiteral(value)));
|
|
75
|
+
}
|
|
76
|
+
return properties;
|
|
77
|
+
}
|
|
65
78
|
//# sourceMappingURL=astUtils.js.map
|
package/src/ast/astUtils.js.map
CHANGED
|
@@ -1 +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,
|
|
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,GAAG,aAAuB;IACpF,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,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3C,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;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,YAAoB,EACpB,aAAyD;IAEzD,M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ACF,CAAC;aACH;YACD,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;AAxCD,kDAwCC;AAED,SAAS,8BAA8B,CAAC,GAA2B;IACjE,MAAM,UAAU,GAAkC,EAAE,CAAC;IACrD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC9C,UAAU,CAAC,IAAI,CACb,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAChH,CAAC;KACH;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","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} propertyNames The properties to remove from the object\n */\nexport function removePropertyWithName(fileContent: string, ...propertyNames: 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 propertyNames.includes(property.name.text)\n );\n });\n return ts.factory.createObjectLiteralExpression(updatedProperties, true);\n }\n return node;\n });\n return ts.createPrinter().printFile(updatedSourceFile);\n}\n\n/**\n * This function adds a new property with a given name and value to an object literal\n * provided as a text string.\n *\n * @param {string} fileContent - the source code as text\n * @param {string} propertyName - the name of the property to add\n * @param {string | string[]} propertyValue - the value of the property to add\n */\nexport function addPropertyWithName(\n fileContent: string,\n propertyName: string,\n propertyValue: string | string[] | Record<string, string>\n) {\n const sourceFile = tsquery.ast(fileContent);\n const updatedSourceFile = tsquery.map(sourceFile, \"ObjectLiteralExpression\", node => {\n if (ts.isObjectLiteralExpression(node)) {\n // Add a new property to the object literal\n let updatedProperties;\n if (typeof propertyValue === \"string\") {\n updatedProperties = [\n ...node.properties,\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(propertyName),\n ts.factory.createStringLiteral(propertyValue)\n ),\n ];\n } else if (Array.isArray(propertyValue)) {\n const arrayLiteral = ts.factory.createArrayLiteralExpression(\n propertyValue.map(value => ts.factory.createStringLiteral(value))\n );\n updatedProperties = [\n ...node.properties,\n ts.factory.createPropertyAssignment(ts.factory.createIdentifier(propertyName), arrayLiteral),\n ];\n } else if (typeof propertyValue === \"object\") {\n updatedProperties = [\n ...node.properties,\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(propertyName),\n ts.factory.createObjectLiteralExpression(createObjectLiteralElementLike(propertyValue))\n ),\n ];\n }\n return ts.factory.createObjectLiteralExpression(updatedProperties, true);\n }\n return node;\n });\n return ts.createPrinter().printFile(updatedSourceFile);\n}\n\nfunction createObjectLiteralElementLike(obj: Record<string, string>): ts.ObjectLiteralElementLike[] {\n const properties: ts.ObjectLiteralElementLike[] = [];\n for (const [key, value] of Object.entries(obj)) {\n properties.push(\n ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createStringLiteral(value))\n );\n }\n return properties;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Tree } from "@nrwl/devkit";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param tree File system tree
|
|
5
|
+
* @param path Path to source file in the Tree
|
|
6
|
+
* @param updater Function that maps the current file content to a new to be written to the Tree
|
|
7
|
+
*/
|
|
8
|
+
export declare const updateFileInTree: (tree: Tree, path: string, updater: (fileContent: string) => string) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateFileInTree = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param tree File system tree
|
|
7
|
+
* @param path Path to source file in the Tree
|
|
8
|
+
* @param updater Function that maps the current file content to a new to be written to the Tree
|
|
9
|
+
*/
|
|
10
|
+
const updateFileInTree = (tree, path, updater) => {
|
|
11
|
+
if (!tree.exists(path)) {
|
|
12
|
+
throw new Error("File not found: " + path);
|
|
13
|
+
}
|
|
14
|
+
const fileContent = tree.read(path, "utf-8");
|
|
15
|
+
if (!fileContent) {
|
|
16
|
+
throw new Error("File is empty: " + path);
|
|
17
|
+
}
|
|
18
|
+
const result = updater(fileContent);
|
|
19
|
+
if (result !== fileContent) {
|
|
20
|
+
tree.write(path, result);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.updateFileInTree = updateFileInTree;
|
|
24
|
+
//# sourceMappingURL=fileUpdater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileUpdater.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/fileUpdater.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,IAAY,EAAE,OAAwC,EAAE,EAAE;IACrG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;KAC5C;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;KAC3C;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpC,IAAI,MAAM,KAAK,WAAW,EAAE;QAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;KAC1B;AACH,CAAC,CAAC;AAdW,QAAA,gBAAgB,oBAc3B","sourcesContent":["import { Tree } from \"@nrwl/devkit\";\n\n/**\n *\n * @param tree File system tree\n * @param path Path to source file in the Tree\n * @param updater Function that maps the current file content to a new to be written to the Tree\n */\nexport const updateFileInTree = (tree: Tree, path: string, updater: (fileContent: string) => string) => {\n if (!tree.exists(path)) {\n throw new Error(\"File not found: \" + path);\n }\n\n const fileContent = tree.read(path, \"utf-8\");\n if (!fileContent) {\n throw new Error(\"File is empty: \" + path);\n }\n const result = updater(fileContent);\n\n if (result !== fileContent) {\n tree.write(path, result);\n }\n};\n"]}
|
package/src/index.d.ts
ADDED
package/src/index.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateFile = exports.uniq = exports.readJson = exports.readFile = exports.checkFilesExist = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
// eslint-disable-next-line no-restricted-imports
|
|
6
|
+
var testing_1 = require("@nrwl/nx-plugin/testing");
|
|
7
|
+
Object.defineProperty(exports, "checkFilesExist", { enumerable: true, get: function () { return testing_1.checkFilesExist; } });
|
|
8
|
+
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return testing_1.readFile; } });
|
|
9
|
+
Object.defineProperty(exports, "readJson", { enumerable: true, get: function () { return testing_1.readJson; } });
|
|
10
|
+
Object.defineProperty(exports, "uniq", { enumerable: true, get: function () { return testing_1.uniq; } });
|
|
11
|
+
Object.defineProperty(exports, "updateFile", { enumerable: true, get: function () { return testing_1.updateFile; } });
|
|
4
12
|
tslib_1.__exportStar(require("./ast/astUtils"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./fileUpdater"), exports);
|
|
5
14
|
tslib_1.__exportStar(require("./nxTestUtils"), exports);
|
|
6
15
|
tslib_1.__exportStar(require("./projectUtils"), exports);
|
|
7
16
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAiD;AACjD,mDAAgG;AAAvF,0GAAA,eAAe,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,+FAAA,IAAI,OAAA;AAAE,qGAAA,UAAU,OAAA;AAC9D,yDAA+B;AAC/B,wDAA8B;AAC9B,wDAA8B;AAC9B,yDAA+B","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nexport { checkFilesExist, readFile, readJson, uniq, updateFile } from \"@nrwl/nx-plugin/testing\";\nexport * from \"./ast/astUtils\";\nexport * from \"./fileUpdater\";\nexport * from \"./nxTestUtils\";\nexport * from \"./projectUtils\";\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures that a project has been setup in the e2e directory
|
|
3
|
+
* It will also copy `@nrwl` packages to the e2e directory
|
|
4
|
+
* When yarn install works in nx-plugin we can replace this file.
|
|
5
|
+
* - https://github.com/nrwl/nx/issues/15263
|
|
6
|
+
*/
|
|
7
|
+
export declare const ensureNxProject: (npmPackageName: string, pluginDistPath: string) => void;
|
package/src/nxTestUtils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureNxProject = void 0;
|
|
4
|
+
// eslint-disable-next-line no-restricted-imports
|
|
4
5
|
const testing_1 = require("@nrwl/nx-plugin/testing");
|
|
5
6
|
const child_process_1 = require("child_process");
|
|
6
7
|
const fs_1 = require("fs");
|
package/src/nxTestUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nxTestUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/nxTestUtils.ts"],"names":[],"mappings":";;;AAAA,qDAMiC;AACjC,iDAAyC;AACzC,2BAAmD;AACnD,+BAA+B;AAE/B,MAAM,OAAO,GAAG,IAAA,qBAAW,GAAE,CAAC;AAE9B,MAAM,eAAe,GAAG,CAAC,IAAa,EAAE,MAAgB,EAAE,EAAE;IAC1D,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IACrC,OAAO,IAAA,wBAAQ,EACb,QAAQ,OAAO,CAAC,OAAO,CACrB,IAAI,CACL,iCAAiC,WAAW,gGAC3C,IAAI,IAAI,EACV,EAAE,kBAEA,GAAG,EAAE,WAAW,IACb,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAExE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAC,cAAsB,EAAE,cAAsB,EAAE,EAAE;IAChF,IAAI,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE;QACvB,IAAA,WAAM,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KACtC;IACD,IAAA,cAAS,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,IAAA,iBAAO,GAAE,CAAC;IACV,eAAe,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC;IAChD,IAAA,mCAAyB,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IAC1D,IAAA,oBAAU,EAAC,OAAO,GAA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AU,EAAC,OAAO,GAAG,WAAW,EAAE,EAAE,CAAC,CAAC;IACtC,IAAA,kCAAwB,GAAE,CAAC;AAC7B,CAAC,CAAC;AAVW,QAAA,eAAe,mBAU1B","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport {\n cleanup,\n patchPackageJsonForPlugin,\n runPackageManagerInstall,\n tmpProjPath,\n updateFile,\n} from \"@nrwl/nx-plugin/testing\";\nimport { execSync } from \"child_process\";\nimport { existsSync, mkdirSync, rmSync } from \"fs\";\nimport { dirname } from \"path\";\n\nconst tmpPath = tmpProjPath();\n\nconst runNxNewCommand = (args?: string, silent?: boolean) => {\n const localTmpDir = dirname(tmpPath);\n return execSync(\n `node ${require.resolve(\n \"nx\"\n )} new proj --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=empty ${\n args || \"\"\n }`,\n {\n cwd: localTmpDir,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n }\n );\n};\n\n/**\n * Ensures that a project has been setup in the e2e directory\n * It will also copy `@nrwl` packages to the e2e directory\n * When yarn install works in nx-plugin we can replace this file.\n * - https://github.com/nrwl/nx/issues/15263\n */\nexport const ensureNxProject = (npmPackageName: string, pluginDistPath: string) => {\n if (existsSync(tmpPath)) {\n rmSync(tmpPath, { recursive: true });\n }\n mkdirSync(tmpPath, { recursive: true });\n cleanup();\n runNxNewCommand(\"--package-manager=yarn\", true);\n patchPackageJsonForPlugin(npmPackageName, pluginDistPath);\n updateFile(tmpPath + \"yarn.lock\", \"\");\n runPackageManagerInstall();\n};\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface ProjectDistPath {
|
|
3
|
+
package: string;
|
|
4
|
+
path: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Run a command asynchronously inside the e2e directory.
|
|
8
|
+
*
|
|
9
|
+
* @param command command to run
|
|
10
|
+
* @param projectName the name of the project in e2e directory
|
|
11
|
+
* @param opts options
|
|
12
|
+
*/
|
|
13
|
+
export declare function runCommandAsync(command: string, projectName: string, opts?: {
|
|
14
|
+
silenceError?: boolean;
|
|
15
|
+
env?: NodeJS.ProcessEnv;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Run a nx command asynchronously inside the e2e directory
|
|
22
|
+
*
|
|
23
|
+
* @param command command to run
|
|
24
|
+
* @param projectName the name of the project in e2e directory
|
|
25
|
+
* @param opts options
|
|
26
|
+
*/
|
|
27
|
+
export declare function runNxCommandAsync(command: string, projectName: string, opts?: {
|
|
28
|
+
silenceError?: boolean;
|
|
29
|
+
env?: NodeJS.ProcessEnv;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
stdout: string;
|
|
32
|
+
stderr: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Ensure nx projects are in package.json in tmp nxRootDir
|
|
36
|
+
*/
|
|
37
|
+
export declare const ensureNxProjects: (dependencies: ProjectDistPath[], devDependencies: ProjectDistPath[], nxRootDir: string, packageManager?: string) => Promise<void>;
|
package/src/projectUtils.js
CHANGED
|
@@ -3,35 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ensureNxProjects = exports.runNxCommandAsync = exports.runCommandAsync = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nrwl/devkit");
|
|
6
|
+
// eslint-disable-next-line no-restricted-imports
|
|
6
7
|
const testing_1 = require("@nrwl/nx-plugin/testing");
|
|
7
8
|
const child_process_1 = require("child_process");
|
|
8
9
|
const fs = tslib_1.__importStar(require("fs"));
|
|
9
10
|
const path_1 = require("path");
|
|
10
|
-
const RETRY_LIMIT = 5;
|
|
11
|
-
const retry = (fn, retries = RETRY_LIMIT, delay = 0) => {
|
|
12
|
-
let retryCount = 0;
|
|
13
|
-
const runFn = () => {
|
|
14
|
-
try {
|
|
15
|
-
fn();
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
if (retryCount < retries) {
|
|
19
|
-
retryCount++;
|
|
20
|
-
setTimeout(runFn, delay);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
// eslint-disable-next-line no-console
|
|
24
|
-
console.error(`Command failed after ${retryCount} retries. Aborting.`);
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
runFn();
|
|
30
|
-
};
|
|
31
11
|
const runNxNewCommand = (nxRoot, args, silent) => {
|
|
32
12
|
const localTmpDir = (0, testing_1.tmpProjPath)();
|
|
33
|
-
|
|
34
|
-
return;
|
|
13
|
+
return (0, child_process_1.execSync)(`node ${require.resolve("@nrwl/tao")} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=ts ${args || ""}`, Object.assign({ cwd: localTmpDir }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
|
|
35
14
|
};
|
|
36
15
|
/**
|
|
37
16
|
* Run a command asynchronously inside the e2e directory.
|
|
@@ -48,6 +27,12 @@ function runCommandAsync(command, projectName, opts = {
|
|
|
48
27
|
cwd: (0, testing_1.tmpProjPath)(projectName),
|
|
49
28
|
env: Object.assign(Object.assign({}, process.env), opts.env),
|
|
50
29
|
}, (err, stdout, stderr) => {
|
|
30
|
+
if (command.includes("--verbose") || (stderr === null || stderr === void 0 ? void 0 : stderr.length) > 0) {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log(`Stdout for cmd: ${command}:\n`, stdout);
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.log(`Stderr for cmd: ${command}:\n`, stderr);
|
|
35
|
+
}
|
|
51
36
|
if (!opts.silenceError && err) {
|
|
52
37
|
reject(err);
|
|
53
38
|
}
|
|
@@ -79,6 +64,7 @@ function runNxCommandAsync(command, projectName, opts = {
|
|
|
79
64
|
exports.runNxCommandAsync = runNxCommandAsync;
|
|
80
65
|
const newNxProject = (nxRootDir, nxRootPath, dependencies, devDependencies, packageManager) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
81
66
|
runNxNewCommand(nxRootDir, `--package-manager=${packageManager}`, true);
|
|
67
|
+
updateWorkspaceLayout(nxRootPath);
|
|
82
68
|
patchDistProjects(dependencies, "dependencies");
|
|
83
69
|
patchDistProjects(devDependencies, "devDependencies");
|
|
84
70
|
patchDistProjects(dependencies, "peerDependencies");
|
|
@@ -91,6 +77,7 @@ const newNxProject = (nxRootDir, nxRootPath, dependencies, devDependencies, pack
|
|
|
91
77
|
patchMainPackageJson(nxRootPath, devDependencies, "dependencies");
|
|
92
78
|
patchMainPackageJson(nxRootPath, devDependencies, "devDependencies");
|
|
93
79
|
patchMainPackageJson(nxRootPath, devDependencies, "peerDependencies");
|
|
80
|
+
updatePackageJson(nxRootPath);
|
|
94
81
|
yield runCommandAsync("yarn", nxRootDir);
|
|
95
82
|
});
|
|
96
83
|
function getAbsPath(distPath) {
|
|
@@ -105,6 +92,8 @@ const ensureNxProjects = (dependencies, devDependencies, nxRootDir, packageManag
|
|
|
105
92
|
fs.rmSync(nxRootPath, { recursive: true });
|
|
106
93
|
}
|
|
107
94
|
fs.mkdirSync(nxRootPath, { recursive: true });
|
|
95
|
+
// eslint-disable-next-line no-console
|
|
96
|
+
console.log("Using NX root dir:", nxRootPath);
|
|
108
97
|
yield newNxProject(nxRootDir, nxRootPath, dependencies, devDependencies, packageManager);
|
|
109
98
|
});
|
|
110
99
|
exports.ensureNxProjects = ensureNxProjects;
|
|
@@ -154,4 +143,22 @@ const patchDistProjects = (paths, type) => {
|
|
|
154
143
|
(0, devkit_1.writeJsonFile)(absPackageJson, newPackageJson);
|
|
155
144
|
}
|
|
156
145
|
};
|
|
146
|
+
const updateWorkspaceLayout = (nxRootPath) => {
|
|
147
|
+
const nxJsonPath = (0, path_1.join)(nxRootPath, "nx.json");
|
|
148
|
+
const nxJson = (0, devkit_1.readJsonFile)(nxJsonPath);
|
|
149
|
+
nxJson.workspaceLayout = {
|
|
150
|
+
appsDir: "apps",
|
|
151
|
+
libsDir: "libs",
|
|
152
|
+
};
|
|
153
|
+
(0, devkit_1.writeJsonFile)(nxJsonPath, nxJson);
|
|
154
|
+
};
|
|
155
|
+
const updatePackageJson = (nxRootPath) => {
|
|
156
|
+
const absPackageJson = (0, path_1.join)(nxRootPath, "package.json");
|
|
157
|
+
const newNxPackageJson = (0, devkit_1.readJsonFile)(absPackageJson);
|
|
158
|
+
const managerPackageJsonPath = (0, path_1.join)(__dirname, "..", "..", "..", "..", "package.json");
|
|
159
|
+
const managerPackageJson = (0, devkit_1.readJsonFile)(managerPackageJsonPath);
|
|
160
|
+
newNxPackageJson.engines = managerPackageJson.engines;
|
|
161
|
+
newNxPackageJson.volta = managerPackageJson.volta;
|
|
162
|
+
(0, devkit_1.writeJsonFile)(absPackageJson, newNxPackageJson);
|
|
163
|
+
};
|
|
157
164
|
//# sourceMappingURL=projectUtils.js.map
|
package/src/projectUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,qDAAkE;AAClE,iDAA+C;AAC/C,+CAAyB;AACzB,+BAA4B;AAK5B,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,MAAM,KAAK,GAAG,CAAC,EAAY,EAAE,UAAkB,WAAW,EAAE,KAAK,GAAG,CAAC,EAAQ,EAAE;IAC7E,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,IAAI;YACF,EAAE,EAAE,CAAC;SACN;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,UAAU,GAAG,OAAO,EAAE;g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A,WAAI,EAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QAC1D,MAAM,WAAW,GAAG,IAAA,qBAAY,EAAC,cAAc,CAAC,CAAC;QACjD,MAAM,WAAW,GAAG,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,IAAI,CAAC,KAAI,EAAE,CAAC;QAE9C,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;YACvB,MAAM,WAAW,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,WAAW,EAAE;gBACxE,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,OAAO,cAAc,GAAG,CAAC,OAAO,OAAO,WAAW,EAAE,CAAC,CAAC;gBAC9E,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC;aACxC;SACF;QACD,MAAM,cAAc,qBAAQ,WAAW,CAAE,CAAC;QAC1C,cAAc,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;QACnC,IAAA,sBAAa,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;KAC/C;AACH,CAAC,CAAC","sourcesContent":["import { readJsonFile, writeJsonFile } from \"@nrwl/devkit\";\nimport { fileExists, tmpProjPath } from \"@nrwl/nx-plugin/testing\";\nimport { exec, execSync } from \"child_process\";\nimport * as fs from \"fs\";\nimport { join } from \"path\";\nexport interface ProjectDistPath {\n package: string;\n path: string;\n}\nconst RETRY_LIMIT = 5;\n\nconst retry = (fn: () => {}, retries: number = RETRY_LIMIT, delay = 0): void => {\n let retryCount = 0;\n\n const runFn = (): void => {\n try {\n fn();\n } catch (error) {\n if (retryCount < retries) {\n retryCount++;\n setTimeout(runFn, delay);\n } else {\n // eslint-disable-next-line no-console\n console.error(`Command failed after ${retryCount} retries. Aborting.`);\n throw error;\n }\n }\n };\n\n runFn();\n};\n\nconst runNxNewCommand = (nxRoot: string, args?: string, silent?: boolean) => {\n const localTmpDir = tmpProjPath();\n\n retry(\n () =>\n execSync(\n `node ${require.resolve(\n \"@nrwl/tao\"\n )} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=empty ${\n args || \"\"\n }`,\n {\n cwd: localTmpDir,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n }\n ),\n 3,\n 3000\n );\n\n return;\n};\n\n/**\n * Run a command asynchronously inside the e2e directory.\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n exec(\n command,\n {\n cwd: tmpProjPath(projectName),\n env: { ...process.env, ...opts.env },\n },\n (err, stdout, stderr) => {\n if (!opts.silenceError && err) {\n reject(err);\n }\n resolve({ stdout, stderr });\n }\n );\n });\n}\n\n/**\n * Run a nx command asynchronously inside the e2e directory\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runNxCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n if (fileExists(tmpProjPath(join(projectName, \"package.json\")))) {\n return runCommandAsync(`yarn nx ${command}`, projectName, opts);\n } else if (process.platform === \"win32\") {\n return runCommandAsync(`./nx.bat ${command}`, projectName, opts);\n } else {\n return runCommandAsync(`./nx ${command}`, projectName, opts);\n }\n}\n\nconst newNxProject = async (\n nxRootDir: string,\n nxRootPath: string,\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n packageManager: string\n) => {\n runNxNewCommand(nxRootDir, `--package-manager=${packageManager}`, true);\n patchDistProjects(dependencies, \"dependencies\");\n patchDistProjects(devDependencies, \"devDependencies\");\n\n patchDistProjects(dependencies, \"peerDependencies\");\n patchDistProjects(devDependencies, \"peerDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\", true);\n\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\", true);\n\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"peerDependencies\");\n\n patchMainPackageJson(nxRootPath, devDependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"peerDependencies\");\n await runCommandAsync(\"yarn\", nxRootDir);\n};\n\nfunction getAbsPath(distPath: string) {\n return join(process.cwd(), distPath);\n}\n\n/**\n * Ensure nx projects are in package.json in tmp nxRootDir\n */\nexport const ensureNxProjects = async (\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n nxRootDir: string,\n packageManager = \"yarn\"\n) => {\n const nxRootPath = tmpProjPath(nxRootDir);\n if (fs.existsSync(nxRootPath)) {\n fs.rmSync(nxRootPath, { recursive: true });\n }\n fs.mkdirSync(nxRootPath, { recursive: true });\n await newNxProject(nxRootDir, nxRootPath, dependencies, devDependencies, packageManager);\n};\n\n/**\n *\n * @param paths paths\n * @param type type\n * @param forceAdd force it\n */\nconst patchMainPackageJson = (\n testDir: string,\n paths: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\",\n forceAdd = false\n) => {\n const absPackageJson = join(testDir, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n const newPackageJson = { ...packageJson };\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(`Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n } else if (forceAdd) {\n // eslint-disable-next-line no-console\n console.log(`Added ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n};\n\nconst patchDistProjects = (paths: ProjectDistPath[], type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\") => {\n for (const path of paths) {\n const absDistPath1 = getAbsPath(path.path);\n const absPackageJson = join(absDistPath1, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(` In ${path.package} => Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n const newPackageJson = { ...packageJson };\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,iDAAiD;AACjD,qDAAkE;AAClE,iDAA+C;AAC/C,+CAAyB;AACzB,+BAA4B;AAM5B,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,IAAa,EAAE,MAAgB,EAAE,EAAE;IAC1E,MAAM,WAAW,GAAG,IAAA,qBAAW,GAAE,CAAC;IAClC,OAAO,IAAA,wBAAQ,EACb,QAAQ,OAAO,CAAC,OAAO,CACrB,WAAW,CACZ,QAAQ,MAAM,wBAAwB,WAAW,6FAChD,IAAI,IAAI,EACV,EAAE,kBAEA,GAAG,EAAE,WAAW,IACb,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ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AE,cAAc,CAAC,CAAC;IACvF,MAAM,kBAAkB,GAAG,IAAA,qBAAY,EAAC,sBAAsB,CAAC,CAAC;IAChE,gBAAgB,CAAC,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;IACtD,gBAAgB,CAAC,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC;IAClD,IAAA,sBAAa,EAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;AAClD,CAAC,CAAC","sourcesContent":["import { readJsonFile, writeJsonFile } from \"@nrwl/devkit\";\n// eslint-disable-next-line no-restricted-imports\nimport { fileExists, tmpProjPath } from \"@nrwl/nx-plugin/testing\";\nimport { exec, execSync } from \"child_process\";\nimport * as fs from \"fs\";\nimport { join } from \"path\";\nexport interface ProjectDistPath {\n package: string;\n path: string;\n}\n\nconst runNxNewCommand = (nxRoot: string, args?: string, silent?: boolean) => {\n const localTmpDir = tmpProjPath();\n return execSync(\n `node ${require.resolve(\n \"@nrwl/tao\"\n )} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=ts ${\n args || \"\"\n }`,\n {\n cwd: localTmpDir,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n }\n );\n};\n\n/**\n * Run a command asynchronously inside the e2e directory.\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n exec(\n command,\n {\n cwd: tmpProjPath(projectName),\n env: { ...process.env, ...opts.env },\n },\n (err, stdout, stderr) => {\n if (command.includes(\"--verbose\") || stderr?.length > 0) {\n // eslint-disable-next-line no-console\n console.log(`Stdout for cmd: ${command}:\\n`, stdout);\n // eslint-disable-next-line no-console\n console.log(`Stderr for cmd: ${command}:\\n`, stderr);\n }\n if (!opts.silenceError && err) {\n reject(err);\n }\n resolve({ stdout, stderr });\n }\n );\n });\n}\n\n/**\n * Run a nx command asynchronously inside the e2e directory\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runNxCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n if (fileExists(tmpProjPath(join(projectName, \"package.json\")))) {\n return runCommandAsync(`yarn nx ${command}`, projectName, opts);\n } else if (process.platform === \"win32\") {\n return runCommandAsync(`./nx.bat ${command}`, projectName, opts);\n } else {\n return runCommandAsync(`./nx ${command}`, projectName, opts);\n }\n}\n\nconst newNxProject = async (\n nxRootDir: string,\n nxRootPath: string,\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n packageManager: string\n) => {\n runNxNewCommand(nxRootDir, `--package-manager=${packageManager}`, true);\n updateWorkspaceLayout(nxRootPath);\n patchDistProjects(dependencies, \"dependencies\");\n patchDistProjects(devDependencies, \"devDependencies\");\n\n patchDistProjects(dependencies, \"peerDependencies\");\n patchDistProjects(devDependencies, \"peerDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\", true);\n\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\", true);\n\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"peerDependencies\");\n\n patchMainPackageJson(nxRootPath, devDependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"peerDependencies\");\n\n updatePackageJson(nxRootPath);\n\n await runCommandAsync(\"yarn\", nxRootDir);\n};\n\nfunction getAbsPath(distPath: string) {\n return join(process.cwd(), distPath);\n}\n\n/**\n * Ensure nx projects are in package.json in tmp nxRootDir\n */\nexport const ensureNxProjects = async (\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n nxRootDir: string,\n packageManager = \"yarn\"\n) => {\n const nxRootPath = tmpProjPath(nxRootDir);\n if (fs.existsSync(nxRootPath)) {\n fs.rmSync(nxRootPath, { recursive: true });\n }\n fs.mkdirSync(nxRootPath, { recursive: true });\n // eslint-disable-next-line no-console\n console.log(\"Using NX root dir:\", nxRootPath);\n await newNxProject(nxRootDir, nxRootPath, dependencies, devDependencies, packageManager);\n};\n\n/**\n *\n * @param paths paths\n * @param type type\n * @param forceAdd force it\n */\nconst patchMainPackageJson = (\n testDir: string,\n paths: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\",\n forceAdd = false\n) => {\n const absPackageJson = join(testDir, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n const newPackageJson = { ...packageJson };\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(`Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n } else if (forceAdd) {\n // eslint-disable-next-line no-console\n console.log(`Added ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n};\n\nconst patchDistProjects = (paths: ProjectDistPath[], type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\") => {\n for (const path of paths) {\n const absDistPath1 = getAbsPath(path.path);\n const absPackageJson = join(absDistPath1, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(` In ${path.package} => Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n const newPackageJson = { ...packageJson };\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n }\n};\nconst updateWorkspaceLayout = (nxRootPath: string) => {\n const nxJsonPath = join(nxRootPath, \"nx.json\");\n const nxJson = readJsonFile(nxJsonPath);\n nxJson.workspaceLayout = {\n appsDir: \"apps\",\n libsDir: \"libs\",\n };\n writeJsonFile(nxJsonPath, nxJson);\n};\nconst updatePackageJson = (nxRootPath: string) => {\n const absPackageJson = join(nxRootPath, \"package.json\");\n const newNxPackageJson = readJsonFile(absPackageJson);\n const managerPackageJsonPath = join(__dirname, \"..\", \"..\", \"..\", \"..\", \"package.json\");\n const managerPackageJson = readJsonFile(managerPackageJsonPath);\n newNxPackageJson.engines = managerPackageJson.engines;\n newNxPackageJson.volta = managerPackageJson.volta;\n writeJsonFile(absPackageJson, newNxPackageJson);\n};\n"]}
|