@trackunit/nx-utils 0.0.59 → 0.0.60

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,11 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.60](https://github.com/Trackunit/manager/compare/nx-utils/0.0.59...nx-utils/0.0.60) (2024-01-15)
6
+
7
+ ### Dependency Updates
8
+
9
+ * `test-setup` updated to version `0.0.59`
5
10
  ## [0.0.59](https://github.com/Trackunit/manager/compare/nx-utils/0.0.58...nx-utils/0.0.59) (2024-01-04)
6
11
 
7
12
  ### Dependency Updates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/nx-utils",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
4
4
  "main": "./src/index.js",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -8,7 +8,6 @@
8
8
  "node": ">=18.x"
9
9
  },
10
10
  "dependencies": {
11
- "@nx/devkit": "17.1.3",
12
11
  "@nx/plugin": "17.1.3",
13
12
  "tslib": "^2.6.2"
14
13
  },
@@ -1,77 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRootFolder = exports.unique = exports.uniqNxFolder = exports.createNxWorkspaceSetup = exports.runNxCommandAsync = exports.runCommandAsync = void 0;
4
- const tslib_1 = require("tslib");
5
- const devkit_1 = require("@nx/devkit");
3
+ exports.createRootFolder = exports.unique = exports.uniqNxFolder = exports.runNxCommandAsync = exports.runCommandAsync = void 0;
6
4
  // eslint-disable-next-line no-restricted-imports
7
5
  const testing_1 = require("@nx/plugin/testing");
8
6
  const child_process_1 = require("child_process");
9
7
  const fs_1 = require("fs");
10
8
  const os_1 = require("os");
11
9
  const path_1 = require("path");
12
- /**
13
- * Returns the path to the project's dist folder based on the package name
14
- *
15
- * @returns { ProjectDistPath[] } the path to the project's dist folder based on the package.json name
16
- */
17
- const getProjectDetails = () => {
18
- var _a;
19
- const workspaces = new devkit_1.Workspaces(process.cwd());
20
- const workspaceConfig = workspaces.readWorkspaceConfiguration();
21
- const projects = [];
22
- for (const project of Object.entries(workspaceConfig.projects)) {
23
- const projectConfig = project[1];
24
- if ((_a = projectConfig.targets) === null || _a === void 0 ? void 0 : _a.build) {
25
- let outputPath = projectConfig.targets.build.options.outputPath;
26
- if (!outputPath && projectConfig.targets.build.outputs && projectConfig.targets.build.outputs[0]) {
27
- outputPath = projectConfig.targets.build.outputs[0].replace("{workspaceRoot}/", "");
28
- }
29
- if (outputPath) {
30
- const packageJsonPath = (0, path_1.join)(process.cwd(), projectConfig.root, "package.json");
31
- if ((0, testing_1.fileExists)(packageJsonPath)) {
32
- const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
33
- const projectDetails = {
34
- package: packageJson.name,
35
- path: outputPath,
36
- };
37
- projects.push(projectDetails);
38
- }
39
- }
40
- }
41
- }
42
- return projects;
43
- };
44
- function copyFolderSync(source, destination) {
45
- // Check if source exists and is a directory
46
- if (!(0, fs_1.existsSync)(source) || !(0, fs_1.lstatSync)(source).isDirectory()) {
47
- return;
48
- }
49
- // Create destination directory if it doesn't exist
50
- if (!(0, fs_1.existsSync)(destination)) {
51
- (0, fs_1.mkdirSync)(destination);
52
- }
53
- // Get all files and directories inside the source directory
54
- const items = (0, fs_1.readdirSync)(source);
55
- // Iterate over each item and copy it to the destination directory
56
- items.forEach(item => {
57
- const itemPath = (0, path_1.join)(source, item);
58
- const destinationPath = (0, path_1.join)(destination, item);
59
- // If the item is a directory, recursively copy it
60
- if ((0, fs_1.lstatSync)(itemPath).isDirectory()) {
61
- copyFolderSync(itemPath, destinationPath);
62
- }
63
- else {
64
- // Otherwise, copy the file
65
- (0, fs_1.copyFileSync)(itemPath, destinationPath);
66
- }
67
- });
68
- }
69
- const runNxNewCommand = (nxRoot, silent) => {
70
- const projectName = nxRoot.split(path_1.sep).pop();
71
- const nxRootParent = (0, path_1.dirname)(nxRoot);
72
- const cmd = `npx create-nx-workspace@17.1.3 ${projectName} --appName=e2e --interactive=false --npmScope=e2e --preset=react-monorepo --verbose --nxCloud=false --packageManager=yarn --skipGit --bundler=webpack --style=css --e2eTestRunner=none`;
73
- return (0, child_process_1.execSync)(cmd, Object.assign({ cwd: nxRootParent }, (silent ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
74
- };
75
10
  /**
76
11
  * Run a command asynchronously with the option of outputting stdout and stderr.
77
12
  *
@@ -150,94 +85,6 @@ function runNxCommandAsync(command, nxRootDir, opts = {
150
85
  return runCommandAsync(cmd, nxRootDir, opts);
151
86
  }
152
87
  exports.runNxCommandAsync = runNxCommandAsync;
153
- /**
154
- * Create new Nx workspace
155
- *
156
- * @param nxRootDir the nx workspace root directory
157
- * @param dependencies dependencies to add to the nx repos package.json
158
- * @param devDependencies devDependencies to add to the nx repos package.json
159
- */
160
- const newNxWorkspace = (nxRootDir, dependencies, devDependencies) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
161
- if (!(0, path_1.isAbsolute)(nxRootDir)) {
162
- throw new Error("nxRootDir must be absolute path");
163
- }
164
- runNxNewCommand(nxRootDir, true);
165
- updateWorkspaceLayout(nxRootDir);
166
- // copy dist folder to nxRootDir
167
- const newDistFolder = (0, path_1.join)(nxRootDir, "dist");
168
- const managerDistFolder = (0, path_1.join)(process.cwd(), "dist");
169
- copyFolderSync(managerDistFolder, newDistFolder);
170
- // Patch package.json with own dependencies
171
- const details = getProjectDetails();
172
- patchMainPackageJson(nxRootDir, dependencies, details, "dependencies");
173
- patchMainPackageJson(nxRootDir, devDependencies, details, "devDependencies");
174
- // Since npm install is not installing local dependencies, we need to run this command
175
- yield runCommandAsync("yarn install", nxRootDir);
176
- });
177
- /**
178
- * Create a new nx workspace with the given dependencies and devDependencies.
179
- * The workspace will be created in the given nxRootDir.
180
- * If the nxRootDir already exists, it will be deleted first then created.
181
- * The nxRootDir must be an absolute path.
182
- * The dependencies and devDependencies will be added to the nx workspace package.json.
183
- * It is expected that the dist folder of your repo has built the needed packages beforehand.
184
- * The dist folder will be copied to the nx workspace root directory.
185
- * The nx workspace will be created with the following options:
186
- * - preset=react-monorepo
187
- * - npmScope=e2e
188
- * - skip-install
189
- * - interactive=false
190
- * - nxCloud=false
191
- * - packageManager=yarn
192
- *
193
- * @param dependencies dependencies to add to the nx repos package.json
194
- * @param devDependencies devDependencies to add to the nx repos package.json
195
- * @param nxRootDir the nx workspace root directory
196
- */
197
- const createNxWorkspaceSetup = (dependencies, devDependencies, nxRootDir) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
198
- createRootFolder(nxRootDir);
199
- yield newNxWorkspace(nxRootDir, dependencies, devDependencies);
200
- });
201
- exports.createNxWorkspaceSetup = createNxWorkspaceSetup;
202
- /**
203
- * Patch the main nx repo package.json with the given dependencies given type
204
- *
205
- * @param nxRootDir the nx workspace root directory
206
- * @param packagesToAdd packages to add
207
- * @param paths paths to the dist folder of the packages
208
- * @param type type of dependency to add
209
- */
210
- const patchMainPackageJson = (nxRootDir, packagesToAdd, paths, type) => {
211
- const absPackageJson = (0, path_1.join)(nxRootDir, "package.json");
212
- const packageJson = (0, devkit_1.readJsonFile)(absPackageJson);
213
- const packageDeps = (packageJson === null || packageJson === void 0 ? void 0 : packageJson[type]) || {};
214
- const newPackageJson = Object.assign({}, packageJson);
215
- for (const packageToAdd of packagesToAdd) {
216
- const path = paths.filter(p => p.package === packageToAdd)[0].path;
217
- if (path) {
218
- const absDistPath = `file:${(0, path_1.join)(nxRootDir, path)}`;
219
- packageDeps[packageToAdd] = absDistPath;
220
- }
221
- }
222
- newPackageJson[type] = packageDeps;
223
- (0, devkit_1.writeJsonFile)(absPackageJson, newPackageJson);
224
- };
225
- /**
226
- * Update the nx.json workspaceLayout to apps/libs format
227
- * This is needed because the nx.json workspaceLayout is not updated when creating a new nx workspace
228
- * with the nx cli.
229
- *
230
- * @param nxRootPath the nx workspace root directory
231
- */
232
- const updateWorkspaceLayout = (nxRootPath) => {
233
- const nxJsonPath = (0, path_1.join)(nxRootPath, "nx.json");
234
- const nxJson = (0, devkit_1.readJsonFile)(nxJsonPath);
235
- nxJson.workspaceLayout = {
236
- appsDir: "apps",
237
- libsDir: "libs",
238
- };
239
- (0, devkit_1.writeJsonFile)(nxJsonPath, nxJson);
240
- };
241
88
  /**
242
89
  * Creates a unique path to a folder in the tmp directory of the OS or in the tmp directory of this repo.
243
90
  *
@@ -1 +1 @@
1
- {"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,uCAAqE;AACrE,iDAAiD;AACjD,gDAAmE;AACnE,iDAAgF;AAChF,2BAAyF;AACzF,2BAA4B;AAC5B,+BAAsD;AAUtD;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,GAAsB,EAAE;;IAChD,MAAM,UAAU,GAAG,IAAI,mBAAU,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,UAAU,CAAC,0BAA0B,EAAE,CAAC;IAEhE,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE;QAC9D,MAAM,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,MAAA,aAAa,CAAC,OAAO,0CAAE,KAAK,EAAE;YAChC,IAAI,UAAU,GAAuB,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;YACpF,IAAI,CAAC,UAAU,IAAI,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBAChG,UAAU,GAAG,aAAa,CAA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AAC,UAAkB;IACjD,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,IAAA,WAAM,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KACzC;IACD,IAAA,cAAS,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC;AAPD,4CAOC","sourcesContent":["import { readJsonFile, Workspaces, writeJsonFile } from \"@nx/devkit\";\n// eslint-disable-next-line no-restricted-imports\nimport { fileExists, tmpProjPath, uniq } from \"@nx/plugin/testing\";\nimport { ChildProcessWithoutNullStreams, execSync, spawn } from \"child_process\";\nimport { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, rmSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { dirname, isAbsolute, join, sep } from \"path\";\n\n/**\n * The path to the project's dist folder based on the package.json name\n */\nexport interface ProjectDistPath {\n package: string;\n path: string;\n}\n\n/**\n * Returns the path to the project's dist folder based on the package name\n *\n * @returns { ProjectDistPath[] } the path to the project's dist folder based on the package.json name\n */\nconst getProjectDetails = (): ProjectDistPath[] => {\n const workspaces = new Workspaces(process.cwd());\n const workspaceConfig = workspaces.readWorkspaceConfiguration();\n\n const projects: ProjectDistPath[] = [];\n for (const project of Object.entries(workspaceConfig.projects)) {\n const projectConfig = project[1];\n if (projectConfig.targets?.build) {\n let outputPath: string | undefined = projectConfig.targets.build.options.outputPath;\n if (!outputPath && projectConfig.targets.build.outputs && projectConfig.targets.build.outputs[0]) {\n outputPath = projectConfig.targets.build.outputs[0].replace(\"{workspaceRoot}/\", \"\");\n }\n if (outputPath) {\n const packageJsonPath = join(process.cwd(), projectConfig.root, \"package.json\");\n if (fileExists(packageJsonPath)) {\n const packageJson = readJsonFile(packageJsonPath);\n const projectDetails = {\n package: packageJson.name,\n path: outputPath,\n };\n projects.push(projectDetails);\n }\n }\n }\n }\n return projects;\n};\n\nfunction copyFolderSync(source: string, destination: string) {\n // Check if source exists and is a directory\n if (!existsSync(source) || !lstatSync(source).isDirectory()) {\n return;\n }\n\n // Create destination directory if it doesn't exist\n if (!existsSync(destination)) {\n mkdirSync(destination);\n }\n\n // Get all files and directories inside the source directory\n const items = readdirSync(source);\n\n // Iterate over each item and copy it to the destination directory\n items.forEach(item => {\n const itemPath = join(source, item);\n const destinationPath = join(destination, item);\n\n // If the item is a directory, recursively copy it\n if (lstatSync(itemPath).isDirectory()) {\n copyFolderSync(itemPath, destinationPath);\n } else {\n // Otherwise, copy the file\n copyFileSync(itemPath, destinationPath);\n }\n });\n}\n\nconst runNxNewCommand = (nxRoot: string, silent?: boolean) => {\n const projectName = nxRoot.split(sep).pop();\n const nxRootParent = dirname(nxRoot);\n\n const cmd = `npx create-nx-workspace@17.1.3 ${projectName} --appName=e2e --interactive=false --npmScope=e2e --preset=react-monorepo --verbose --nxCloud=false --packageManager=yarn --skipGit --bundler=webpack --style=css --e2eTestRunner=none`;\n\n return execSync(cmd, {\n cwd: nxRootParent,\n ...(silent ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n });\n};\n\n/**\n * Run a command asynchronously with the option of outputting stdout and stderr.\n *\n * @param command command to run\n * @param rootDir command execution directory\n * @param opts options\n * @param opts.silenceError silence errors logged to console\n * @param opts.waitForProcessToTerminate Wait for the process to terminate before resolving.\n * @param opts.env environment variables to pass to the command\n */\nexport function runCommandAsync(\n command: string,\n rootDir: string,\n opts: { silenceError?: boolean; waitForProcessToTerminate?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n waitForProcessToTerminate: true,\n }\n): Promise<{ process: ChildProcessWithoutNullStreams; stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const [cmd, ...args] = [...command.split(\" \")];\n const childProcess = spawn(cmd, args, {\n cwd: rootDir,\n env: { ...process.env, ...opts.env },\n shell: true,\n });\n\n let stdout = \"\";\n let stderr = \"\";\n\n childProcess.stdout.on(\"data\", data => {\n stdout += data.toString();\n if (!opts.waitForProcessToTerminate && command.includes(\"--verbose\")) {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n }\n });\n\n childProcess.stderr.on(\"data\", data => {\n stderr += data.toString();\n if (!opts.waitForProcessToTerminate && command.includes(\"--verbose\")) {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n }\n });\n\n childProcess.on(\"close\", code => {\n if (code !== 0 && !opts.silenceError) {\n reject(new Error(stderr));\n } else if (opts.waitForProcessToTerminate) {\n if (command.includes(\"--verbose\") || stderr.length > 0) {\n // eslint-disable-next-line no-console\n console.log(\n `---------------------\\n`,\n `Cwd: ${rootDir}\\n`,\n `Cmd: ${command}\\n`,\n `Stdout:\\n`,\n stdout,\n `\\nStderr:\\n`,\n stderr,\n `\\n---------------------`\n );\n }\n resolve({ process: childProcess, stdout, stderr });\n }\n });\n\n childProcess.on(\"error\", err => {\n if (!opts.silenceError) {\n reject(err);\n }\n });\n\n if (!opts.waitForProcessToTerminate) {\n resolve({ process: childProcess, stdout: \"\", stderr: \"\" });\n }\n });\n}\n\n/**\n * Run a nx command asynchronously inside the given nx workspace directory\n *\n * @param command command to run\n * @param nxRootDir the nx workspace root directory\n * @param opts options\n * @param opts.silenceError silence errors logged to console\n * @param opts.waitForProcessToTerminate Wait for the process to terminate before resolving.\n * @param opts.env environment variables to pass to the command\n */\nexport function runNxCommandAsync(\n command: string,\n nxRootDir: string,\n opts: { silenceError?: boolean; waitForProcessToTerminate?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n waitForProcessToTerminate: true,\n }\n): Promise<{ process: ChildProcessWithoutNullStreams; stdout: string; stderr: string }> {\n const cmd = `${process.platform === \"win32\" ? \"./nx.bat\" : \"nx\"} ${command}`;\n return runCommandAsync(cmd, nxRootDir, opts);\n}\n\n/**\n * Create new Nx workspace\n *\n * @param nxRootDir the nx workspace root directory\n * @param dependencies dependencies to add to the nx repos package.json\n * @param devDependencies devDependencies to add to the nx repos package.json\n */\nconst newNxWorkspace = async (nxRootDir: string, dependencies: string[], devDependencies: string[]) => {\n if (!isAbsolute(nxRootDir)) {\n throw new Error(\"nxRootDir must be absolute path\");\n }\n runNxNewCommand(nxRootDir, true);\n updateWorkspaceLayout(nxRootDir);\n\n // copy dist folder to nxRootDir\n const newDistFolder = join(nxRootDir, \"dist\");\n const managerDistFolder = join(process.cwd(), \"dist\");\n copyFolderSync(managerDistFolder, newDistFolder);\n\n // Patch package.json with own dependencies\n const details = getProjectDetails();\n patchMainPackageJson(nxRootDir, dependencies, details, \"dependencies\");\n patchMainPackageJson(nxRootDir, devDependencies, details, \"devDependencies\");\n\n // Since npm install is not installing local dependencies, we need to run this command\n await runCommandAsync(\"yarn install\", nxRootDir);\n};\n\n/**\n * Create a new nx workspace with the given dependencies and devDependencies.\n * The workspace will be created in the given nxRootDir.\n * If the nxRootDir already exists, it will be deleted first then created.\n * The nxRootDir must be an absolute path.\n * The dependencies and devDependencies will be added to the nx workspace package.json.\n * It is expected that the dist folder of your repo has built the needed packages beforehand.\n * The dist folder will be copied to the nx workspace root directory.\n * The nx workspace will be created with the following options:\n * - preset=react-monorepo\n * - npmScope=e2e\n * - skip-install\n * - interactive=false\n * - nxCloud=false\n * - packageManager=yarn\n *\n * @param dependencies dependencies to add to the nx repos package.json\n * @param devDependencies devDependencies to add to the nx repos package.json\n * @param nxRootDir the nx workspace root directory\n */\nexport const createNxWorkspaceSetup = async (dependencies: string[], devDependencies: string[], nxRootDir: string) => {\n createRootFolder(nxRootDir);\n await newNxWorkspace(nxRootDir, dependencies, devDependencies);\n};\n\n/**\n * Patch the main nx repo package.json with the given dependencies given type\n *\n * @param nxRootDir the nx workspace root directory\n * @param packagesToAdd packages to add\n * @param paths paths to the dist folder of the packages\n * @param type type of dependency to add\n */\nconst patchMainPackageJson = (\n nxRootDir: string,\n packagesToAdd: string[],\n paths: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\"\n) => {\n const absPackageJson = join(nxRootDir, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n const newPackageJson = { ...packageJson };\n\n for (const packageToAdd of packagesToAdd) {\n const path = paths.filter(p => p.package === packageToAdd)[0].path;\n if (path) {\n const absDistPath = `file:${join(nxRootDir, path)}`;\n packageDeps[packageToAdd] = absDistPath;\n }\n }\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n};\n\n/**\n * Update the nx.json workspaceLayout to apps/libs format\n * This is needed because the nx.json workspaceLayout is not updated when creating a new nx workspace\n * with the nx cli.\n *\n * @param nxRootPath the nx workspace root directory\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};\n\n/**\n * Creates a unique path to a folder in the tmp directory of the OS or in the tmp directory of this repo.\n *\n * @returns { string } unique path\n */\nexport const uniqNxFolder = (name: string, parentFolder: \"OS_TMP\" | \"THIS_REPO\") => {\n if (parentFolder === \"THIS_REPO\") {\n return join(tmpProjPath(), uniq(name));\n }\n return join(tmpdir(), \"e2e\", uniq(name));\n};\n\n/**\n * Creates a unique name for a project.\n *\n * @returns { string } unique name\n */\nexport const unique = (name: string) => {\n return uniq(name);\n};\n\n/**\n * Creates a new root folder for the end 2 end test.\n */\nexport function createRootFolder(e2eRootDir: string) {\n if (existsSync(e2eRootDir)) {\n rmSync(e2eRootDir, { recursive: true });\n }\n mkdirSync(e2eRootDir, { recursive: true });\n // eslint-disable-next-line no-console\n console.log(\"Using E2E root folder:\", e2eRootDir);\n}\n"]}
1
+ {"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AACjD,gDAA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,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;IAC7E,OAAO,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC;AAVD,8CAUC;AAED;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,YAAoC,EAAE,EAAE;IACjF,IAAI,YAAY,KAAK,WAAW,EAAE;QAChC,OAAO,IAAA,WAAI,EAAC,IAAA,qBAAW,GAAE,EAAE,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC,CAAC;KACxC;IACD,OAAO,IAAA,WAAI,EAAC,IAAA,WAAM,GAAE,EAAE,KAAK,EAAE,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC;AALW,QAAA,YAAY,gBAKvB;AAEF;;;;GAIG;AACI,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE;IACrC,OAAO,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC;AACpB,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEF;;GAEG;AACH,SAAgB,gBAAgB,CAAC,UAAkB;IACjD,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,IAAA,WAAM,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KACzC;IACD,IAAA,cAAS,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC;AAPD,4CAOC","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport { tmpProjPath, uniq } from \"@nx/plugin/testing\";\nimport { ChildProcessWithoutNullStreams, spawn } from \"child_process\";\nimport { existsSync, mkdirSync, rmSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\n\n/**\n * Run a command asynchronously with the option of outputting stdout and stderr.\n *\n * @param command command to run\n * @param rootDir command execution directory\n * @param opts options\n * @param opts.silenceError silence errors logged to console\n * @param opts.waitForProcessToTerminate Wait for the process to terminate before resolving.\n * @param opts.env environment variables to pass to the command\n */\nexport function runCommandAsync(\n command: string,\n rootDir: string,\n opts: { silenceError?: boolean; waitForProcessToTerminate?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n waitForProcessToTerminate: true,\n }\n): Promise<{ process: ChildProcessWithoutNullStreams; stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const [cmd, ...args] = [...command.split(\" \")];\n const childProcess = spawn(cmd, args, {\n cwd: rootDir,\n env: { ...process.env, ...opts.env },\n shell: true,\n });\n\n let stdout = \"\";\n let stderr = \"\";\n\n childProcess.stdout.on(\"data\", data => {\n stdout += data.toString();\n if (!opts.waitForProcessToTerminate && command.includes(\"--verbose\")) {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n }\n });\n\n childProcess.stderr.on(\"data\", data => {\n stderr += data.toString();\n if (!opts.waitForProcessToTerminate && command.includes(\"--verbose\")) {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n }\n });\n\n childProcess.on(\"close\", code => {\n if (code !== 0 && !opts.silenceError) {\n reject(new Error(stderr));\n } else if (opts.waitForProcessToTerminate) {\n if (command.includes(\"--verbose\") || stderr.length > 0) {\n // eslint-disable-next-line no-console\n console.log(\n `---------------------\\n`,\n `Cwd: ${rootDir}\\n`,\n `Cmd: ${command}\\n`,\n `Stdout:\\n`,\n stdout,\n `\\nStderr:\\n`,\n stderr,\n `\\n---------------------`\n );\n }\n resolve({ process: childProcess, stdout, stderr });\n }\n });\n\n childProcess.on(\"error\", err => {\n if (!opts.silenceError) {\n reject(err);\n }\n });\n\n if (!opts.waitForProcessToTerminate) {\n resolve({ process: childProcess, stdout: \"\", stderr: \"\" });\n }\n });\n}\n\n/**\n * Run a nx command asynchronously inside the given nx workspace directory\n *\n * @param command command to run\n * @param nxRootDir the nx workspace root directory\n * @param opts options\n * @param opts.silenceError silence errors logged to console\n * @param opts.waitForProcessToTerminate Wait for the process to terminate before resolving.\n * @param opts.env environment variables to pass to the command\n */\nexport function runNxCommandAsync(\n command: string,\n nxRootDir: string,\n opts: { silenceError?: boolean; waitForProcessToTerminate?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n waitForProcessToTerminate: true,\n }\n): Promise<{ process: ChildProcessWithoutNullStreams; stdout: string; stderr: string }> {\n const cmd = `${process.platform === \"win32\" ? \"./nx.bat\" : \"nx\"} ${command}`;\n return runCommandAsync(cmd, nxRootDir, opts);\n}\n\n/**\n * Creates a unique path to a folder in the tmp directory of the OS or in the tmp directory of this repo.\n *\n * @returns { string } unique path\n */\nexport const uniqNxFolder = (name: string, parentFolder: \"OS_TMP\" | \"THIS_REPO\") => {\n if (parentFolder === \"THIS_REPO\") {\n return join(tmpProjPath(), uniq(name));\n }\n return join(tmpdir(), \"e2e\", uniq(name));\n};\n\n/**\n * Creates a unique name for a project.\n *\n * @returns { string } unique name\n */\nexport const unique = (name: string) => {\n return uniq(name);\n};\n\n/**\n * Creates a new root folder for the end 2 end test.\n */\nexport function createRootFolder(e2eRootDir: string) {\n if (existsSync(e2eRootDir)) {\n rmSync(e2eRootDir, { recursive: true });\n }\n mkdirSync(e2eRootDir, { recursive: true });\n // eslint-disable-next-line no-console\n console.log(\"Using E2E root folder:\", e2eRootDir);\n}"]}