@trackunit/nx-utils 0.0.6 → 0.0.7

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.7](https://github.com/Trackunit/manager/compare/nx-utils/0.0.6...nx-utils/0.0.7) (2023-04-14)
6
+
5
7
  ## [0.0.6](https://github.com/Trackunit/manager/compare/nx-utils/0.0.5...nx-utils/0.0.6) (2023-04-11)
6
8
 
7
9
  ## [0.0.5](https://github.com/Trackunit/manager/compare/nx-utils/0.0.4...nx-utils/0.0.5) (2023-04-09)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/nx-utils",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "main": "src/lib/index.ts",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removePropertyWithName = void 0;
3
+ exports.addPropertyWithName = exports.removePropertyWithName = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const tsquery_1 = require("@phenomnomnominal/tsquery");
6
6
  const ts = tslib_1.__importStar(require("typescript"));
@@ -28,4 +28,38 @@ function removePropertyWithName(fileContent, propertyName) {
28
28
  return ts.createPrinter().printFile(updatedSourceFile);
29
29
  }
30
30
  exports.removePropertyWithName = removePropertyWithName;
31
+ /**
32
+ * This function adds a new property with a given name and value to an object literal
33
+ * provided as a text string.
34
+ *
35
+ * @param {string} fileContent - the source code as text
36
+ * @param {string} propertyName - the name of the property to add
37
+ * @param {string | string[]} propertyValue - the value of the property to add
38
+ */
39
+ function addPropertyWithName(fileContent, propertyName, propertyValue) {
40
+ const sourceFile = tsquery_1.tsquery.ast(fileContent);
41
+ const updatedSourceFile = tsquery_1.tsquery.map(sourceFile, "ObjectLiteralExpression", node => {
42
+ if (ts.isObjectLiteralExpression(node)) {
43
+ // Add a new property to the object literal
44
+ let updatedProperties;
45
+ if (typeof propertyValue === "string") {
46
+ updatedProperties = [
47
+ ...node.properties,
48
+ ts.factory.createPropertyAssignment(ts.factory.createIdentifier(propertyName), ts.factory.createStringLiteral(propertyValue)),
49
+ ];
50
+ }
51
+ else if (Array.isArray(propertyValue)) {
52
+ const arrayLiteral = ts.factory.createArrayLiteralExpression(propertyValue.map(value => ts.factory.createStringLiteral(value)));
53
+ updatedProperties = [
54
+ ...node.properties,
55
+ ts.factory.createPropertyAssignment(ts.factory.createIdentifier(propertyName), arrayLiteral),
56
+ ];
57
+ }
58
+ return ts.factory.createObjectLiteralExpression(updatedProperties, true);
59
+ }
60
+ return node;
61
+ });
62
+ return ts.createPrinter().printFile(updatedSourceFile);
63
+ }
64
+ exports.addPropertyWithName = addPropertyWithName;
31
65
  //# sourceMappingURL=astUtils.js.map
@@ -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,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"]}
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,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,CAAC,aAAa,CAAC,EAAE;gBACvC,MAAM,YAAY,GAAG,EAAE,CAAC,OAAO,CAAC,4BAA4B,CAC1D,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAClE,CAAC;gBACF,iBAAiB,GAAG;oBAClB,GAAG,IAAI,CAAC,UAAU;oBAClB,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;iBAC7F,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;AA5BD,kDA4BC","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\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(fileContent: string, propertyName: string, propertyValue: string | string[]) {\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 }\n return ts.factory.createObjectLiteralExpression(updatedProperties, true);\n }\n return node;\n });\n return ts.createPrinter().printFile(updatedSourceFile);\n}\n"]}
@@ -7,9 +7,31 @@ const testing_1 = require("@nrwl/nx-plugin/testing");
7
7
  const child_process_1 = require("child_process");
8
8
  const fs = tslib_1.__importStar(require("fs"));
9
9
  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
+ };
10
31
  const runNxNewCommand = (nxRoot, args, silent) => {
11
32
  const localTmpDir = (0, testing_1.tmpProjPath)();
12
- 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=empty ${args || ""}`, Object.assign({ cwd: localTmpDir }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
33
+ retry(() => (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=empty ${args || ""}`, Object.assign({ cwd: localTmpDir }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {}))), 3, 3000);
34
+ return;
13
35
  };
14
36
  /**
15
37
  * Run a command asynchronously inside the e2e directory.
@@ -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;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,gGAChD,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;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,OAAe,EACf,WAAmB,EACnB,OAA4D;IAC1D,YAAY,EAAE,KAAK;CACpB;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAA,oBAAI,EACF,OAAO,EACP;YACE,GAAG,EAAE,IAAA,qBAAW,EAAC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CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,KAAwB,EAAE,IAA6D,EAAE,EAAE;IACpH,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,cAAc,GAAG,IAAA,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}\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=empty ${\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 (!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,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;gBACxB,UAAU,EAAE,CAAC;gBACb,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;aAC1B;iBAAM;gBACL,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CAAC,wBAAwB,UAAU,qBAAqB,CA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AAX,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"]}