@trackunit/nx-utils 0.0.22 → 0.0.24
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 +7 -0
- package/package.json +8 -10
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/nxTestUtils.js +2 -2
- package/src/nxTestUtils.js.map +1 -1
- package/src/projectUtils.js +8 -6
- package/src/projectUtils.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.24](https://github.com/Trackunit/manager/compare/nx-utils/0.0.23...nx-utils/0.0.24) (2023-07-03)
|
|
6
|
+
|
|
7
|
+
## [0.0.23](https://github.com/Trackunit/manager/compare/nx-utils/0.0.22...nx-utils/0.0.23) (2023-07-03)
|
|
8
|
+
|
|
9
|
+
### Dependency Updates
|
|
10
|
+
|
|
11
|
+
* `test-setup` updated to version `0.0.1`
|
|
5
12
|
## [0.0.22](https://github.com/Trackunit/manager/compare/nx-utils/0.0.21...nx-utils/0.0.22) (2023-06-19)
|
|
6
13
|
|
|
7
14
|
## [0.0.21](https://github.com/Trackunit/manager/compare/nx-utils/0.0.20...nx-utils/0.0.21) (2023-06-13)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/nx-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"repository": "https://github.com/Trackunit/manager",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -8,16 +8,14 @@
|
|
|
8
8
|
"node": ">=16.x"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@react-google-maps/api": "2.18.1",
|
|
11
|
+
"@react-google-maps/api": "^2.18.1",
|
|
12
12
|
"@react-spring/web": "9.6.0",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"react": "
|
|
17
|
-
"react-
|
|
18
|
-
"
|
|
19
|
-
"react-virtualized-auto-sizer": "1.0.7",
|
|
20
|
-
"tslib": "2.4.1"
|
|
13
|
+
"jest-canvas-mock": "^2.4.0",
|
|
14
|
+
"moment-timezone": "^0.5.37",
|
|
15
|
+
"react": "^18.2.0",
|
|
16
|
+
"react-i18next": "^12.2.2",
|
|
17
|
+
"react-virtualized-auto-sizer": "^1.0.7",
|
|
18
|
+
"tslib": "1.10.0"
|
|
21
19
|
},
|
|
22
20
|
"types": "./src/index.d.ts"
|
|
23
21
|
}
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateFile = exports.uniq = exports.readJson = exports.readFile = exports.checkFilesExist = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
// eslint-disable-next-line no-restricted-imports
|
|
6
|
-
var testing_1 = require("@
|
|
6
|
+
var testing_1 = require("@nx/plugin/testing");
|
|
7
7
|
Object.defineProperty(exports, "checkFilesExist", { enumerable: true, get: function () { return testing_1.checkFilesExist; } });
|
|
8
8
|
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return testing_1.readFile; } });
|
|
9
9
|
Object.defineProperty(exports, "readJson", { enumerable: true, get: function () { return testing_1.readJson; } });
|
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,
|
|
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"]}
|
package/src/nxTestUtils.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureNxProject = void 0;
|
|
4
4
|
// eslint-disable-next-line no-restricted-imports
|
|
5
|
-
const testing_1 = require("@
|
|
5
|
+
const testing_1 = require("@nx/plugin/testing");
|
|
6
6
|
const child_process_1 = require("child_process");
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const tmpPath = (0, testing_1.tmpProjPath)();
|
|
10
10
|
const runNxNewCommand = (args, silent) => {
|
|
11
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=@
|
|
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
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Ensures that a project has been setup in the e2e directory
|
package/src/nxTestUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nxTestUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/nxTestUtils.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"nxTestUt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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"]}
|
package/src/projectUtils.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.unique = exports.uniqNxFolder = exports.createNxWorkspaceSetup = exports.runNxCommandAsync = exports.runCommandAsync = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const devkit_1 = require("@
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
// eslint-disable-next-line no-restricted-imports
|
|
7
|
-
const testing_1 = require("@
|
|
7
|
+
const testing_1 = require("@nx/plugin/testing");
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
9
|
const fs_1 = require("fs");
|
|
10
10
|
const os_1 = require("os");
|
|
@@ -15,15 +15,17 @@ const path_1 = require("path");
|
|
|
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;
|
|
18
|
+
var _a, _b, _c, _d, _e, _f;
|
|
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
|
-
|
|
26
|
-
|
|
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])) {
|
|
27
|
+
outputPath = projectConfig.targets.build.outputs[0].replace("{workspaceRoot}/", "");
|
|
28
|
+
}
|
|
27
29
|
if (outputPath) {
|
|
28
30
|
const packageJsonPath = (0, path_1.join)(process.cwd(), projectConfig.root, "package.json");
|
|
29
31
|
if ((0, testing_1.fileExists)(packageJsonPath)) {
|
|
@@ -67,7 +69,7 @@ function copyFolderSync(source, destination) {
|
|
|
67
69
|
const runNxNewCommand = (nxRoot, silent) => {
|
|
68
70
|
const projectName = nxRoot.split(path_1.sep).pop();
|
|
69
71
|
const nxRootParent = (0, path_1.dirname)(nxRoot);
|
|
70
|
-
const cmd = `npx create-nx-workspace@
|
|
72
|
+
const cmd = `npx create-nx-workspace@16.4.1 ${projectName} --appName=e2e --interactive=false --npmScope=e2e --preset=react-monorepo --verbose --nxCloud=false --packageManager=yarn --skipGit --bundler=webpack --style=css`;
|
|
71
73
|
return (0, child_process_1.execSync)(cmd, Object.assign({ cwd: nxRootParent }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
|
|
72
74
|
};
|
|
73
75
|
/**
|
package/src/projectUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,yCAAuE;AACvE,iDAAiD;AACjD,qDAAwE;AACxE,iDAA+C;AAC/C,2BAAyF;AAEzF,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,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC;YAChD,MAAM,UAAU,GAAG,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,0CAAE,UAAU,CAAC;YAEpD,IAAI,UAAU,EAAE;gBACd,MAAM,eAAe,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,IAAI,EAAE,cAAc,CAAC,CAA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,CAAC,UAAkB,EAAE,EAAE;IAC/C,MAAM,cAAc,GAAG,IAAA,WAAI,EAAC,UAAU,EAAE,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 \"@nrwl/devkit\";\n// eslint-disable-next-line no-restricted-imports\nimport { fileExists, tmpProjPath, uniq } from \"@nrwl/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 const buildTarget = projectConfig.targets.build;\n const outputPath = buildTarget?.options?.outputPath;\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@15.9.4 ${projectName} --interactive=false --skip-install --npmScope=e2e --preset=ts --verbose --nxCloud=false --packageManager=yarn --skipGit`;\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 = (nxRootDir: string, projects: ProjectDistPath[], type: \"dependencies\" | \"devDependencies\") => {\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,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EAAE;IAC/C,MAAM,cAAc,GAAG,IAAA,WAAI,EAAC,UAAU,EAAE,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.4.1 ${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"]}
|