@trackunit/nx-utils 0.0.31 → 0.0.32

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.32](https://github.com/Trackunit/manager/compare/nx-utils/0.0.31...nx-utils/0.0.32) (2023-08-29)
6
+
5
7
  ## [0.0.31](https://github.com/Trackunit/manager/compare/nx-utils/0.0.30...nx-utils/0.0.31) (2023-08-15)
6
8
 
7
9
  ## [0.0.30](https://github.com/Trackunit/manager/compare/nx-utils/0.0.29...nx-utils/0.0.30) (2023-08-14)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/nx-utils",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "main": "src/index.js",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
package/src/index.js CHANGED
@@ -9,6 +9,5 @@ Object.defineProperty(exports, "readFile", { enumerable: true, get: function ()
9
9
  Object.defineProperty(exports, "readJson", { enumerable: true, get: function () { return testing_1.readJson; } });
10
10
  Object.defineProperty(exports, "uniq", { enumerable: true, get: function () { return testing_1.uniq; } });
11
11
  Object.defineProperty(exports, "updateFile", { enumerable: true, get: function () { return testing_1.updateFile; } });
12
- tslib_1.__exportStar(require("./nxTestUtils"), exports);
13
12
  tslib_1.__exportStar(require("./projectUtils"), exports);
14
13
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAiD;AACjD,8CAA2F;AAAlF,0GAAA,eAAe,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,+FAAA,IAAI,OAAA;AAAE,qGAAA,UAAU,OAAA;AAC9D,wDAA8B;AAC9B,yDAA+B","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nexport { checkFilesExist, readFile, readJson, uniq, updateFile } from \"@nx/plugin/testing\";\nexport * from \"./nxTestUtils\";\nexport * from \"./projectUtils\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAiD;AACjD,8CAA2F;AAAlF,0GAAA,eAAe,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,+FAAA,IAAI,OAAA;AAAE,qGAAA,UAAU,OAAA;AAC9D,yDAA+B","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nexport { checkFilesExist, readFile, readJson, uniq, updateFile } from \"@nx/plugin/testing\";\nexport * from \"./projectUtils\";\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unique = exports.uniqNxFolder = exports.createNxWorkspaceSetup = exports.runNxCommandAsync = exports.runCommandAsync = void 0;
3
+ exports.createRootFolder = exports.unique = exports.uniqNxFolder = exports.createNxWorkspaceSetup = exports.runNxCommandAsync = exports.runCommandAsync = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  // eslint-disable-next-line no-restricted-imports
@@ -10,20 +10,20 @@ const fs_1 = require("fs");
10
10
  const os_1 = require("os");
11
11
  const path_1 = require("path");
12
12
  /**
13
- * Returns the path to the project's dist folder based on the package.json name
13
+ * Returns the path to the project's dist folder based on the package name
14
14
  *
15
15
  * @returns { ProjectDistPath[] } the path to the project's dist folder based on the package.json name
16
16
  */
17
17
  const getProjectDetails = () => {
18
- var _a, _b, _c, _d, _e, _f;
18
+ var _a;
19
19
  const workspaces = new devkit_1.Workspaces(process.cwd());
20
20
  const workspaceConfig = workspaces.readWorkspaceConfiguration();
21
21
  const projects = [];
22
22
  for (const project of Object.entries(workspaceConfig.projects)) {
23
23
  const projectConfig = project[1];
24
24
  if ((_a = projectConfig.targets) === null || _a === void 0 ? void 0 : _a.build) {
25
- let outputPath = (_b = projectConfig.targets) === null || _b === void 0 ? void 0 : _b.build.options.outputPath;
26
- if (!outputPath && ((_d = (_c = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _c === void 0 ? void 0 : _c.build) === null || _d === void 0 ? void 0 : _d.outputs) && ((_f = (_e = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _e === void 0 ? void 0 : _e.build) === null || _f === void 0 ? void 0 : _f.outputs[0])) {
25
+ let outputPath = projectConfig.targets.build.options.outputPath;
26
+ if (!outputPath && projectConfig.targets.build.outputs && projectConfig.targets.build.outputs[0]) {
27
27
  outputPath = projectConfig.targets.build.outputs[0].replace("{workspaceRoot}/", "");
28
28
  }
29
29
  if (outputPath) {
@@ -70,26 +70,28 @@ const runNxNewCommand = (nxRoot, silent) => {
70
70
  const projectName = nxRoot.split(path_1.sep).pop();
71
71
  const nxRootParent = (0, path_1.dirname)(nxRoot);
72
72
  const cmd = `npx create-nx-workspace@16.6.0 ${projectName} --appName=e2e --interactive=false --npmScope=e2e --preset=react-monorepo --verbose --nxCloud=false --packageManager=yarn --skipGit --bundler=webpack --style=css`;
73
- return (0, child_process_1.execSync)(cmd, Object.assign({ cwd: nxRootParent }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
73
+ return (0, child_process_1.execSync)(cmd, Object.assign({ cwd: nxRootParent }, (silent ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
74
74
  };
75
75
  /**
76
- * Run a command asynchronously inside the e2e directory.
76
+ * Run a command asynchronously with the option of outputting stdout and stderr.
77
77
  *
78
78
  * @param command command to run
79
- * @param nxRootDir the nx workspace root directory
79
+ * @param rootDir command execution directory
80
80
  * @param opts options
81
+ * @param opts.silenceError silence errors logged to console
82
+ * @param opts.env environment variables to pass to the command
81
83
  */
82
- function runCommandAsync(command, nxRootDir, opts = {
84
+ function runCommandAsync(command, rootDir, opts = {
83
85
  silenceError: false,
84
86
  }) {
85
87
  return new Promise((resolve, reject) => {
86
88
  (0, child_process_1.exec)(command, {
87
- cwd: nxRootDir,
89
+ cwd: rootDir,
88
90
  env: Object.assign(Object.assign({}, process.env), opts.env),
89
91
  }, (err, stdout, stderr) => {
90
- if (command.includes("--verbose") || (stderr === null || stderr === void 0 ? void 0 : stderr.length) > 0) {
92
+ if (command.includes("--verbose") || stderr.length > 0) {
91
93
  // eslint-disable-next-line no-console
92
- console.log(`---------------------\n`, `Cwd: ${nxRootDir}\n`, `Cmd: ${command}\n`, `Stdout:\n`, stdout, `\nStderr:\n`, stderr, `\n---------------------`);
94
+ console.log(`---------------------\n`, `Cwd: ${rootDir}\n`, `Cmd: ${command}\n`, `Stdout:\n`, stdout, `\nStderr:\n`, stderr, `\n---------------------`);
93
95
  }
94
96
  if (!opts.silenceError && err) {
95
97
  reject(err);
@@ -105,6 +107,8 @@ exports.runCommandAsync = runCommandAsync;
105
107
  * @param command command to run
106
108
  * @param nxRootDir the nx workspace root directory
107
109
  * @param opts options
110
+ * @param opts.silenceError silence errors logged to console
111
+ * @param opts.env environment variables to pass to the command
108
112
  */
109
113
  function runNxCommandAsync(command, nxRootDir, opts = {
110
114
  silenceError: false,
@@ -113,7 +117,7 @@ function runNxCommandAsync(command, nxRootDir, opts = {
113
117
  return runCommandAsync(`./nx.bat ${command}`, nxRootDir, opts);
114
118
  }
115
119
  else {
116
- return runCommandAsync(`INSTALL_TU_PACKAGES=false nx ${command}`, nxRootDir, opts);
120
+ return runCommandAsync(`nx ${command}`, nxRootDir, opts);
117
121
  }
118
122
  }
119
123
  exports.runNxCommandAsync = runNxCommandAsync;
@@ -134,14 +138,10 @@ const newNxWorkspace = (nxRootDir, dependencies, devDependencies) => tslib_1.__a
134
138
  const newDistFolder = (0, path_1.join)(nxRootDir, "dist");
135
139
  const managerDistFolder = (0, path_1.join)(process.cwd(), "dist");
136
140
  copyFolderSync(managerDistFolder, newDistFolder);
137
- // Fix paths in package.json for dist folder
138
- const details = getProjectDetails();
139
- dependencies.push(...patchDistProjects(nxRootDir, details, "dependencies"));
140
- devDependencies.push(...patchDistProjects(nxRootDir, details, "devDependencies"));
141
141
  // Patch package.json with own dependencies
142
+ const details = getProjectDetails();
142
143
  patchMainPackageJson(nxRootDir, dependencies, details, "dependencies");
143
144
  patchMainPackageJson(nxRootDir, devDependencies, details, "devDependencies");
144
- updatePackageJson(nxRootDir);
145
145
  // Since npm install is not installing local dependencies, we need to run this command
146
146
  yield runCommandAsync("yarn install", nxRootDir);
147
147
  });
@@ -154,7 +154,7 @@ const newNxWorkspace = (nxRootDir, dependencies, devDependencies) => tslib_1.__a
154
154
  * It is expected that the dist folder of your repo has built the needed packages beforehand.
155
155
  * The dist folder will be copied to the nx workspace root directory.
156
156
  * The nx workspace will be created with the following options:
157
- * - preset=ts
157
+ * - preset=react-monorepo
158
158
  * - npmScope=e2e
159
159
  * - skip-install
160
160
  * - interactive=false
@@ -166,12 +166,7 @@ const newNxWorkspace = (nxRootDir, dependencies, devDependencies) => tslib_1.__a
166
166
  * @param nxRootDir the nx workspace root directory
167
167
  */
168
168
  const createNxWorkspaceSetup = (dependencies, devDependencies, nxRootDir) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
169
- if ((0, fs_1.existsSync)(nxRootDir)) {
170
- (0, fs_1.rmSync)(nxRootDir, { recursive: true });
171
- }
172
- (0, fs_1.mkdirSync)(nxRootDir, { recursive: true });
173
- // eslint-disable-next-line no-console
174
- console.log("Using NX workspace:", nxRootDir);
169
+ createRootFolder(nxRootDir);
175
170
  yield newNxWorkspace(nxRootDir, dependencies, devDependencies);
176
171
  });
177
172
  exports.createNxWorkspaceSetup = createNxWorkspaceSetup;
@@ -199,52 +194,7 @@ const patchMainPackageJson = (nxRootDir, packagesToAdd, paths, type) => {
199
194
  (0, devkit_1.writeJsonFile)(absPackageJson, newPackageJson);
200
195
  };
201
196
  /**
202
- * Patch the package.json of the dist folder of the given paths with the given type
203
- * This is needed because the dist folder of the packages are not published to npm
204
- * and therefore the package.json of the dist folder needs to be patched with the
205
- * correct path to the dist folder.
206
- *
207
- * @param nxRootDir the nx workspace root directory
208
- * @param projects paths to the dist folder of the packages
209
- * @param type type of dependency to add
210
- * @returns { string[] } packages that were patched
211
- */
212
- const patchDistProjects = (nxRootDir, projects, type) => {
213
- const libsUsed = [];
214
- for (const project of projects) {
215
- const absDistPath = (0, path_1.join)(nxRootDir, project.path);
216
- if ((0, fs_1.existsSync)(absDistPath)) {
217
- const absPackageJsonPath = (0, path_1.join)(absDistPath, "package.json");
218
- const packageJson = (0, devkit_1.readJsonFile)(absPackageJsonPath);
219
- const packageDeps = (packageJson === null || packageJson === void 0 ? void 0 : packageJson[type]) || {};
220
- for (const dependencyName of Object.keys(packageDeps)) {
221
- const dependencyInLocalDist = projects.filter(p => p.package === dependencyName);
222
- if (dependencyInLocalDist.length > 0) {
223
- const absPathToDependencyInLocalDist = (0, path_1.join)(nxRootDir, dependencyInLocalDist[0].path);
224
- if ((0, fs_1.existsSync)(absPathToDependencyInLocalDist)) {
225
- const localNpmPath = `file:${absPathToDependencyInLocalDist}`;
226
- if (packageDeps[dependencyName] !== localNpmPath) {
227
- packageDeps[dependencyName] = localNpmPath;
228
- if (!libsUsed.includes(dependencyName)) {
229
- libsUsed.push(dependencyName);
230
- }
231
- }
232
- }
233
- else {
234
- throw new Error(`${absPathToDependencyInLocalDist} does not exist, but is listed as a dependency of ${project.package},
235
- maybe you need to add an implicit dependency to the project.json of ${project.package}?`);
236
- }
237
- }
238
- }
239
- const newPackageJson = Object.assign({}, packageJson);
240
- newPackageJson[type] = packageDeps;
241
- (0, devkit_1.writeJsonFile)(absPackageJsonPath, newPackageJson);
242
- }
243
- }
244
- return libsUsed;
245
- };
246
- /**
247
- * Update the nx.json workspaceLayout to the new format
197
+ * Update the nx.json workspaceLayout to apps/libs format
248
198
  * This is needed because the nx.json workspaceLayout is not updated when creating a new nx workspace
249
199
  * with the nx cli.
250
200
  *
@@ -259,23 +209,6 @@ const updateWorkspaceLayout = (nxRootPath) => {
259
209
  };
260
210
  (0, devkit_1.writeJsonFile)(nxJsonPath, nxJson);
261
211
  };
262
- /**
263
- * Update the package.json engines and volta to the new format
264
- * This is needed because the package.json engines and volta is not updated when creating a new nx workspace
265
- * with the nx cli.
266
- * The engines and volta are copied from the package.json of the nx cli.
267
- *
268
- * @param nxRootPath the nx workspace root directory
269
- */
270
- const updatePackageJson = (nxRootPath) => {
271
- const absPackageJson = (0, path_1.join)(nxRootPath, "package.json");
272
- const newNxPackageJson = (0, devkit_1.readJsonFile)(absPackageJson);
273
- const managerPackageJsonPath = (0, path_1.join)(__dirname, "..", "..", "..", "..", "package.json");
274
- const managerPackageJson = (0, devkit_1.readJsonFile)(managerPackageJsonPath);
275
- newNxPackageJson.engines = managerPackageJson.engines;
276
- newNxPackageJson.volta = managerPackageJson.volta;
277
- (0, devkit_1.writeJsonFile)(absPackageJson, newNxPackageJson);
278
- };
279
212
  /**
280
213
  * Creates a unique path to a folder in the tmp directory of the OS or in the tmp directory of this repo.
281
214
  *
@@ -297,4 +230,16 @@ const unique = (name) => {
297
230
  return (0, testing_1.uniq)(name);
298
231
  };
299
232
  exports.unique = unique;
233
+ /**
234
+ * Creates a new root folder for the end 2 end test.
235
+ */
236
+ function createRootFolder(e2eRootDir) {
237
+ if ((0, fs_1.existsSync)(e2eRootDir)) {
238
+ (0, fs_1.rmSync)(e2eRootDir, { recursive: true });
239
+ }
240
+ (0, fs_1.mkdirSync)(e2eRootDir, { recursive: true });
241
+ // eslint-disable-next-line no-console
242
+ console.log("Using E2E root folder:", e2eRootDir);
243
+ }
244
+ exports.createRootFolder = createRootFolder;
300
245
  //# sourceMappingURL=projectUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.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AAE,cAAc,CAAC,CAAC;IACxD,MAAM,gBAAgB,GAAG,IAAA,qBAAY,EAAC,cAAc,CAAC,CAAC;IACtD,MAAM,sBAAsB,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,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;AAEF;;;;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","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 { exec, execSync } from \"child_process\";\nimport { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, rmSync } from \"fs\";\nimport { PackageJson } from \"nx/src/utils/package-json\";\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.json 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@16.6.0 ${projectName} --appName=e2e --interactive=false --npmScope=e2e --preset=react-monorepo --verbose --nxCloud=false --packageManager=yarn --skipGit --bundler=webpack --style=css`;\n\n return execSync(cmd, {\n cwd: nxRootParent,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n });\n};\n\n/**\n * Run a command asynchronously inside the e2e directory.\n *\n * @param command command to run\n * @param nxRootDir the nx workspace root directory\n * @param opts options\n */\nexport function runCommandAsync(\n command: string,\n nxRootDir: 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: nxRootDir,\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(\n `---------------------\\n`,\n `Cwd: ${nxRootDir}\\n`,\n `Cmd: ${command}\\n`,\n `Stdout:\\n`,\n stdout,\n `\\nStderr:\\n`,\n stderr,\n `\\n---------------------`\n );\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 nx workspace directory\n *\n * @param command command to run\n * @param nxRootDir the nx workspace root directory\n * @param opts options\n */\nexport function runNxCommandAsync(\n command: string,\n nxRootDir: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n if (process.platform === \"win32\") {\n return runCommandAsync(`./nx.bat ${command}`, nxRootDir, opts);\n } else {\n return runCommandAsync(`INSTALL_TU_PACKAGES=false nx ${command}`, nxRootDir, opts);\n }\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 // Fix paths in package.json for dist folder\n const details = getProjectDetails();\n dependencies.push(...patchDistProjects(nxRootDir, details, \"dependencies\"));\n devDependencies.push(...patchDistProjects(nxRootDir, details, \"devDependencies\"));\n\n // Patch package.json with own dependencies\n patchMainPackageJson(nxRootDir, dependencies, details, \"dependencies\");\n patchMainPackageJson(nxRootDir, devDependencies, details, \"devDependencies\");\n\n updatePackageJson(nxRootDir);\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=ts\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 if (existsSync(nxRootDir)) {\n rmSync(nxRootDir, { recursive: true });\n }\n mkdirSync(nxRootDir, { recursive: true });\n // eslint-disable-next-line no-console\n console.log(\"Using NX workspace:\", 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 * Patch the package.json of the dist folder of the given paths with the given type\n * This is needed because the dist folder of the packages are not published to npm\n * and therefore the package.json of the dist folder needs to be patched with the\n * correct path to the dist folder.\n *\n * @param nxRootDir the nx workspace root directory\n * @param projects paths to the dist folder of the packages\n * @param type type of dependency to add\n * @returns { string[] } packages that were patched\n */\nconst patchDistProjects = (\n nxRootDir: string,\n projects: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\"\n) => {\n const libsUsed: string[] = [];\n for (const project of projects) {\n const absDistPath = join(nxRootDir, project.path);\n if (existsSync(absDistPath)) {\n const absPackageJsonPath = join(absDistPath, \"package.json\");\n const packageJson = readJsonFile(absPackageJsonPath) as PackageJson;\n const packageDeps = packageJson?.[type] || {};\n\n for (const dependencyName of Object.keys(packageDeps)) {\n const dependencyInLocalDist = projects.filter(p => p.package === dependencyName);\n if (dependencyInLocalDist.length > 0) {\n const absPathToDependencyInLocalDist = join(nxRootDir, dependencyInLocalDist[0].path);\n if (existsSync(absPathToDependencyInLocalDist)) {\n const localNpmPath = `file:${absPathToDependencyInLocalDist}`;\n if (packageDeps[dependencyName] !== localNpmPath) {\n packageDeps[dependencyName] = localNpmPath;\n if (!libsUsed.includes(dependencyName)) {\n libsUsed.push(dependencyName);\n }\n }\n } else {\n throw new Error(\n `${absPathToDependencyInLocalDist} does not exist, but is listed as a dependency of ${project.package}, \n maybe you need to add an implicit dependency to the project.json of ${project.package}?`\n );\n }\n }\n }\n const newPackageJson = { ...packageJson };\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJsonPath, newPackageJson);\n }\n }\n return libsUsed;\n};\n\n/**\n * Update the nx.json workspaceLayout to the new 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 * Update the package.json engines and volta to the new format\n * This is needed because the package.json engines and volta is not updated when creating a new nx workspace\n * with the nx cli.\n * The engines and volta are copied from the package.json of the nx cli.\n *\n * @param nxRootPath the nx workspace root directory\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\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"]}
1
+ {"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,uCAAqE;AACrE,iDAAiD;AACjD,gDAAmE;AACnE,iDAA+C;AAC/C,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,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;aACrF;YACD,IAAI,UAAU,EAAE;gBACd,MAAM,eAAe,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;gBAChF,IAAI,IAAA,oBAAU,EAAC,eAAe,CAAC,EAAE;oBAC/B,MAAM,WAAW,GA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GAAG,IAAA,qBAAY,EAAC,UAAU,CAAC,CAAC;IACxC,MAAM,CAAC,eAAe,GAAG;QACvB,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,MAAM;KAChB,CAAC;IACF,IAAA,sBAAa,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF;;;;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":["import { readJsonFile, Workspaces, writeJsonFile } from \"@nx/devkit\";\n// eslint-disable-next-line no-restricted-imports\nimport { fileExists, tmpProjPath, uniq } from \"@nx/plugin/testing\";\nimport { exec, execSync } 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@16.6.0 ${projectName} --appName=e2e --interactive=false --npmScope=e2e --preset=react-monorepo --verbose --nxCloud=false --packageManager=yarn --skipGit --bundler=webpack --style=css`;\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.env environment variables to pass to the command\n */\nexport function runCommandAsync(\n command: string,\n rootDir: 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: rootDir,\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(\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 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 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.env environment variables to pass to the command\n */\nexport function runNxCommandAsync(\n command: string,\n nxRootDir: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n if (process.platform === \"win32\") {\n return runCommandAsync(`./nx.bat ${command}`, nxRootDir, opts);\n } else {\n return runCommandAsync(`nx ${command}`, nxRootDir, opts);\n }\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,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureNxProject = void 0;
4
- // eslint-disable-next-line no-restricted-imports
5
- const testing_1 = require("@nx/plugin/testing");
6
- const child_process_1 = require("child_process");
7
- const fs_1 = require("fs");
8
- const path_1 = require("path");
9
- const tmpPath = (0, testing_1.tmpProjPath)();
10
- const runNxNewCommand = (args, silent) => {
11
- const localTmpDir = (0, path_1.dirname)(tmpPath);
12
- return (0, child_process_1.execSync)(`node ${require.resolve("nx")} new proj --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nx/workspace --npmScope=proj --preset=empty ${args || ""}`, Object.assign({ cwd: localTmpDir }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
13
- };
14
- /**
15
- * Ensures that a project has been setup in the e2e directory
16
- * It will also copy `@nrwl` packages to the e2e directory
17
- * When yarn install works in nx-plugin we can replace this file.
18
- * - https://github.com/nrwl/nx/issues/15263
19
- */
20
- const ensureNxProject = (npmPackageName, pluginDistPath) => {
21
- if ((0, fs_1.existsSync)(tmpPath)) {
22
- (0, fs_1.rmSync)(tmpPath, { recursive: true });
23
- }
24
- (0, fs_1.mkdirSync)(tmpPath, { recursive: true });
25
- (0, testing_1.cleanup)();
26
- runNxNewCommand("--package-manager=yarn", true);
27
- (0, testing_1.patchPackageJsonForPlugin)(npmPackageName, pluginDistPath);
28
- (0, testing_1.updateFile)(tmpPath + "yarn.lock", "");
29
- (0, testing_1.runPackageManagerInstall)();
30
- };
31
- exports.ensureNxProject = ensureNxProject;
32
- //# sourceMappingURL=nxTestUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nxTestUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/nxTestUtils.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AACjD,gDAM4B;AAC5B,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,8FAC3C,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,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 \"@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=@nx/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"]}