@trackunit/nx-utils 0.0.1-alpha-307439490d.0
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 +5 -0
- package/README.md +18 -0
- package/package.json +12 -0
- package/src/index.js +6 -0
- package/src/index.js.map +1 -0
- package/src/nxTestUtils.js +31 -0
- package/src/nxTestUtils.js.map +1 -0
- package/src/projectUtils.js +135 -0
- package/src/projectUtils.js.map +1 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
> **⚠️ Beta**
|
|
2
|
+
>
|
|
3
|
+
> This is a beta version and subject to change without notice.
|
|
4
|
+
|
|
5
|
+
# Trackunit NX utils
|
|
6
|
+
The `@trackunit/nx-utils` package is a small package containing reusable test utils for nx.
|
|
7
|
+
|
|
8
|
+
Trackunit Iris Apps are used by external developers to integrate custom functionality into [the Trackunit Manager platform](https://www.trackunit.com/services/manager/).
|
|
9
|
+
|
|
10
|
+
For more info and a full guide on Iris App SDK Development, please visit our [Developer Hub](https://developers.trackunit.com/).
|
|
11
|
+
## Basic Usage
|
|
12
|
+
This package is not meant for isolated usage but is a part of the [`@trackunit/iris-app`](https://www.npmjs.com/package/@trackunit/iris-app) package.
|
|
13
|
+
|
|
14
|
+
## Trackunit
|
|
15
|
+
This package was developed by Trackunit ApS.
|
|
16
|
+
Trackunit is the leading SaaS-based IoT solution for the construction industry, offering an ecosystem of hardware, fleet management software & telematics.
|
|
17
|
+
|
|
18
|
+

|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trackunit/nx-utils",
|
|
3
|
+
"version": "0.0.1-alpha-307439490d.0",
|
|
4
|
+
"main": "src/lib/index.ts",
|
|
5
|
+
"repository": "https://github.com/Trackunit/manager",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"tslib": "2.4.1"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {}
|
|
12
|
+
}
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,yDAA+B","sourcesContent":["export * from \"./nxTestUtils\";\nexport * from \"./projectUtils\";\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureNxProject = void 0;
|
|
4
|
+
const testing_1 = require("@nrwl/nx-plugin/testing");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const tmpPath = (0, testing_1.tmpProjPath)();
|
|
9
|
+
const runNxNewCommand = (args, silent) => {
|
|
10
|
+
const localTmpDir = (0, path_1.dirname)(tmpPath);
|
|
11
|
+
return (0, child_process_1.execSync)(`node ${require.resolve("nx")} new proj --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=empty ${args || ""}`, Object.assign({ cwd: localTmpDir }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Ensures that a project has been setup in the e2e directory
|
|
15
|
+
* It will also copy `@nrwl` packages to the e2e directory
|
|
16
|
+
* When yarn install works in nx-plugin we can replace this file.
|
|
17
|
+
* - https://github.com/nrwl/nx/issues/15263
|
|
18
|
+
*/
|
|
19
|
+
const ensureNxProject = (npmPackageName, pluginDistPath) => {
|
|
20
|
+
if ((0, fs_1.existsSync)(tmpPath)) {
|
|
21
|
+
(0, fs_1.rmSync)(tmpPath, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
(0, fs_1.mkdirSync)(tmpPath, { recursive: true });
|
|
24
|
+
(0, testing_1.cleanup)();
|
|
25
|
+
runNxNewCommand("--package-manager=yarn", true);
|
|
26
|
+
(0, testing_1.patchPackageJsonForPlugin)(npmPackageName, pluginDistPath);
|
|
27
|
+
(0, testing_1.updateFile)(tmpPath + "yarn.lock", "");
|
|
28
|
+
(0, testing_1.runPackageManagerInstall)();
|
|
29
|
+
};
|
|
30
|
+
exports.ensureNxProject = ensureNxProject;
|
|
31
|
+
//# sourceMappingURL=nxTestUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nxTestUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/nxTestUtils.ts"],"names":[],"mappings":";;;AAAA,qDAMiC;AACjC,iDAAyC;AACzC,2BAAmD;AACnD,+BAA+B;AAE/B,MAAM,OAAO,GAAG,IAAA,qBAAW,GAAE,CAAC;AAE9B,MAAM,eAAe,GAAG,CAAC,IAAa,EAAE,MAAgB,EAAE,EAAE;IAC1D,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IACrC,OAAO,IAAA,wBAAQ,EACb,QAAQ,OAAO,CAAC,OAAO,CACrB,IAAI,CACL,iCAAiC,WAAW,gGAC3C,IAAI,IAAI,EACV,EAAE,kBAEA,GAAG,EAAE,WAAW,IACb,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAExE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAC,cAAsB,EAAE,cAAsB,EAAE,EAAE;IAChF,IAAI,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE;QACvB,IAAA,WAAM,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KACtC;IACD,IAAA,cAAS,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,IAAA,iBAAO,GAAE,CAAC;IACV,eAAe,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC;IAChD,IAAA,mCAAyB,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IAC1D,IAAA,oBAAU,EAAC,OAAO,GAAG,WAAW,EAAE,EAAE,CAAC,CAAC;IACtC,IAAA,kCAAwB,GAAE,CAAC;AAC7B,CAAC,CAAC;AAVW,QAAA,eAAe,mBAU1B","sourcesContent":["import {\n cleanup,\n patchPackageJsonForPlugin,\n runPackageManagerInstall,\n tmpProjPath,\n updateFile,\n} from \"@nrwl/nx-plugin/testing\";\nimport { execSync } from \"child_process\";\nimport { existsSync, mkdirSync, rmSync } from \"fs\";\nimport { dirname } from \"path\";\n\nconst tmpPath = tmpProjPath();\n\nconst runNxNewCommand = (args?: string, silent?: boolean) => {\n const localTmpDir = dirname(tmpPath);\n return execSync(\n `node ${require.resolve(\n \"nx\"\n )} new proj --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=empty ${\n args || \"\"\n }`,\n {\n cwd: localTmpDir,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n }\n );\n};\n\n/**\n * Ensures that a project has been setup in the e2e directory\n * It will also copy `@nrwl` packages to the e2e directory\n * When yarn install works in nx-plugin we can replace this file.\n * - https://github.com/nrwl/nx/issues/15263\n */\nexport const ensureNxProject = (npmPackageName: string, pluginDistPath: string) => {\n if (existsSync(tmpPath)) {\n rmSync(tmpPath, { recursive: true });\n }\n mkdirSync(tmpPath, { recursive: true });\n cleanup();\n runNxNewCommand(\"--package-manager=yarn\", true);\n patchPackageJsonForPlugin(npmPackageName, pluginDistPath);\n updateFile(tmpPath + \"yarn.lock\", \"\");\n runPackageManagerInstall();\n};\n"]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureNxProjects = exports.runNxCommandAsync = exports.runCommandAsync = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nrwl/devkit");
|
|
6
|
+
const testing_1 = require("@nrwl/nx-plugin/testing");
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const runNxNewCommand = (nxRoot, args, silent) => {
|
|
11
|
+
const localTmpDir = (0, testing_1.tmpProjPath)();
|
|
12
|
+
return (0, child_process_1.execSync)(`node ${require.resolve("@nrwl/tao")} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=empty ${args || ""}`, Object.assign({ cwd: localTmpDir }, (silent && false ? { stdio: ["ignore", "ignore", "ignore"] } : {})));
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Run a command asynchronously inside the e2e directory.
|
|
16
|
+
*
|
|
17
|
+
* @param command command to run
|
|
18
|
+
* @param projectName the name of the project in e2e directory
|
|
19
|
+
* @param opts options
|
|
20
|
+
*/
|
|
21
|
+
function runCommandAsync(command, projectName, opts = {
|
|
22
|
+
silenceError: false,
|
|
23
|
+
}) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
(0, child_process_1.exec)(command, {
|
|
26
|
+
cwd: (0, testing_1.tmpProjPath)(projectName),
|
|
27
|
+
env: Object.assign(Object.assign({}, process.env), opts.env),
|
|
28
|
+
}, (err, stdout, stderr) => {
|
|
29
|
+
if (!opts.silenceError && err) {
|
|
30
|
+
reject(err);
|
|
31
|
+
}
|
|
32
|
+
resolve({ stdout, stderr });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.runCommandAsync = runCommandAsync;
|
|
37
|
+
/**
|
|
38
|
+
* Run a nx command asynchronously inside the e2e directory
|
|
39
|
+
*
|
|
40
|
+
* @param command command to run
|
|
41
|
+
* @param projectName the name of the project in e2e directory
|
|
42
|
+
* @param opts options
|
|
43
|
+
*/
|
|
44
|
+
function runNxCommandAsync(command, projectName, opts = {
|
|
45
|
+
silenceError: false,
|
|
46
|
+
}) {
|
|
47
|
+
if ((0, testing_1.fileExists)((0, testing_1.tmpProjPath)((0, path_1.join)(projectName, "package.json")))) {
|
|
48
|
+
return runCommandAsync(`yarn nx ${command}`, projectName, opts);
|
|
49
|
+
}
|
|
50
|
+
else if (process.platform === "win32") {
|
|
51
|
+
return runCommandAsync(`./nx.bat ${command}`, projectName, opts);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return runCommandAsync(`./nx ${command}`, projectName, opts);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.runNxCommandAsync = runNxCommandAsync;
|
|
58
|
+
const newNxProject = (nxRootDir, nxRootPath, dependencies, devDependencies, packageManager) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
runNxNewCommand(nxRootDir, `--package-manager=${packageManager}`, true);
|
|
60
|
+
patchDistProjects(dependencies, "dependencies");
|
|
61
|
+
patchDistProjects(devDependencies, "devDependencies");
|
|
62
|
+
patchDistProjects(dependencies, "peerDependencies");
|
|
63
|
+
patchDistProjects(devDependencies, "peerDependencies");
|
|
64
|
+
patchMainPackageJson(nxRootPath, dependencies, "dependencies", true);
|
|
65
|
+
patchMainPackageJson(nxRootPath, devDependencies, "devDependencies", true);
|
|
66
|
+
patchMainPackageJson(nxRootPath, dependencies, "dependencies");
|
|
67
|
+
patchMainPackageJson(nxRootPath, dependencies, "devDependencies");
|
|
68
|
+
patchMainPackageJson(nxRootPath, dependencies, "peerDependencies");
|
|
69
|
+
patchMainPackageJson(nxRootPath, devDependencies, "dependencies");
|
|
70
|
+
patchMainPackageJson(nxRootPath, devDependencies, "devDependencies");
|
|
71
|
+
patchMainPackageJson(nxRootPath, devDependencies, "peerDependencies");
|
|
72
|
+
yield runCommandAsync("yarn", nxRootDir);
|
|
73
|
+
});
|
|
74
|
+
function getAbsPath(distPath) {
|
|
75
|
+
return (0, path_1.join)(process.cwd(), distPath);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Ensure nx projects are in package.json in tmp nxRootDir
|
|
79
|
+
*/
|
|
80
|
+
const ensureNxProjects = (dependencies, devDependencies, nxRootDir, packageManager = "yarn") => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
const nxRootPath = (0, testing_1.tmpProjPath)(nxRootDir);
|
|
82
|
+
if (fs.existsSync(nxRootPath)) {
|
|
83
|
+
fs.rmSync(nxRootPath, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
fs.mkdirSync(nxRootPath, { recursive: true });
|
|
86
|
+
yield newNxProject(nxRootDir, nxRootPath, dependencies, devDependencies, packageManager);
|
|
87
|
+
});
|
|
88
|
+
exports.ensureNxProjects = ensureNxProjects;
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param paths paths
|
|
92
|
+
* @param type type
|
|
93
|
+
* @param forceAdd force it
|
|
94
|
+
*/
|
|
95
|
+
const patchMainPackageJson = (testDir, paths, type, forceAdd = false) => {
|
|
96
|
+
const absPackageJson = (0, path_1.join)(testDir, "package.json");
|
|
97
|
+
const packageJson = (0, devkit_1.readJsonFile)(absPackageJson);
|
|
98
|
+
const packageDeps = (packageJson === null || packageJson === void 0 ? void 0 : packageJson[type]) || {};
|
|
99
|
+
const newPackageJson = Object.assign({}, packageJson);
|
|
100
|
+
for (const pkg of paths) {
|
|
101
|
+
const absDistPath = `file:/${getAbsPath(pkg.path)}`;
|
|
102
|
+
if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {
|
|
103
|
+
// eslint-disable-next-line no-console
|
|
104
|
+
console.log(`Update ${pkg.package} => ${absDistPath}`);
|
|
105
|
+
packageDeps[pkg.package] = absDistPath;
|
|
106
|
+
}
|
|
107
|
+
else if (forceAdd) {
|
|
108
|
+
// eslint-disable-next-line no-console
|
|
109
|
+
console.log(`Added ${pkg.package} => ${absDistPath}`);
|
|
110
|
+
packageDeps[pkg.package] = absDistPath;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
newPackageJson[type] = packageDeps;
|
|
114
|
+
(0, devkit_1.writeJsonFile)(absPackageJson, newPackageJson);
|
|
115
|
+
};
|
|
116
|
+
const patchDistProjects = (paths, type) => {
|
|
117
|
+
for (const path of paths) {
|
|
118
|
+
const absDistPath1 = getAbsPath(path.path);
|
|
119
|
+
const absPackageJson = (0, path_1.join)(absDistPath1, "package.json");
|
|
120
|
+
const packageJson = (0, devkit_1.readJsonFile)(absPackageJson);
|
|
121
|
+
const packageDeps = (packageJson === null || packageJson === void 0 ? void 0 : packageJson[type]) || {};
|
|
122
|
+
for (const pkg of paths) {
|
|
123
|
+
const absDistPath = `file:/${getAbsPath(pkg.path)}`;
|
|
124
|
+
if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {
|
|
125
|
+
// eslint-disable-next-line no-console
|
|
126
|
+
console.log(` In ${path.package} => Update ${pkg.package} => ${absDistPath}`);
|
|
127
|
+
packageDeps[pkg.package] = absDistPath;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const newPackageJson = Object.assign({}, packageJson);
|
|
131
|
+
newPackageJson[type] = packageDeps;
|
|
132
|
+
(0, devkit_1.writeJsonFile)(absPackageJson, newPackageJson);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=projectUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectUtils.js","sourceRoot":"","sources":["../../../../../libs/nx/utils/src/projectUtils.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,qDAAkE;AAClE,iDAA+C;AAC/C,+CAAyB;AACzB,+BAA4B;AAM5B,MAAM,e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IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,WAAW,EAAE;gBACxE,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,OAAO,cAAc,GAAG,CAAC,OAAO,OAAO,WAAW,EAAE,CAAC,CAAC;gBAC9E,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC;aACxC;SACF;QACD,MAAM,cAAc,qBAAQ,WAAW,CAAE,CAAC;QAC1C,cAAc,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;QACnC,IAAA,sBAAa,EAAC,cAAc,EAAE,cAAc,CAAC,CAAC;KAC/C;AACH,CAAC,CAAC","sourcesContent":["import { readJsonFile, writeJsonFile } from \"@nrwl/devkit\";\nimport { fileExists, tmpProjPath } from \"@nrwl/nx-plugin/testing\";\nimport { exec, execSync } from \"child_process\";\nimport * as fs from \"fs\";\nimport { join } from \"path\";\nexport interface ProjectDistPath {\n package: string;\n path: string;\n}\n\nconst runNxNewCommand = (nxRoot: string, args?: string, silent?: boolean) => {\n const localTmpDir = tmpProjPath();\n return execSync(\n `node ${require.resolve(\n \"@nrwl/tao\"\n )} new ${nxRoot} --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nrwl/workspace --npmScope=proj --preset=empty ${\n args || \"\"\n }`,\n {\n cwd: localTmpDir,\n ...(silent && false ? { stdio: [\"ignore\", \"ignore\", \"ignore\"] } : {}),\n }\n );\n};\n\n/**\n * Run a command asynchronously inside the e2e directory.\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n exec(\n command,\n {\n cwd: tmpProjPath(projectName),\n env: { ...process.env, ...opts.env },\n },\n (err, stdout, stderr) => {\n if (!opts.silenceError && err) {\n reject(err);\n }\n resolve({ stdout, stderr });\n }\n );\n });\n}\n\n/**\n * Run a nx command asynchronously inside the e2e directory\n *\n * @param command command to run\n * @param projectName the name of the project in e2e directory\n * @param opts options\n */\nexport function runNxCommandAsync(\n command: string,\n projectName: string,\n opts: { silenceError?: boolean; env?: NodeJS.ProcessEnv } = {\n silenceError: false,\n }\n): Promise<{ stdout: string; stderr: string }> {\n if (fileExists(tmpProjPath(join(projectName, \"package.json\")))) {\n return runCommandAsync(`yarn nx ${command}`, projectName, opts);\n } else if (process.platform === \"win32\") {\n return runCommandAsync(`./nx.bat ${command}`, projectName, opts);\n } else {\n return runCommandAsync(`./nx ${command}`, projectName, opts);\n }\n}\n\nconst newNxProject = async (\n nxRootDir: string,\n nxRootPath: string,\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n packageManager: string\n) => {\n runNxNewCommand(nxRootDir, `--package-manager=${packageManager}`, true);\n patchDistProjects(dependencies, \"dependencies\");\n patchDistProjects(devDependencies, \"devDependencies\");\n\n patchDistProjects(dependencies, \"peerDependencies\");\n patchDistProjects(devDependencies, \"peerDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\", true);\n\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\", true);\n\n patchMainPackageJson(nxRootPath, dependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, dependencies, \"peerDependencies\");\n\n patchMainPackageJson(nxRootPath, devDependencies, \"dependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"devDependencies\");\n patchMainPackageJson(nxRootPath, devDependencies, \"peerDependencies\");\n await runCommandAsync(\"yarn\", nxRootDir);\n};\n\nfunction getAbsPath(distPath: string) {\n return join(process.cwd(), distPath);\n}\n\n/**\n * Ensure nx projects are in package.json in tmp nxRootDir\n */\nexport const ensureNxProjects = async (\n dependencies: ProjectDistPath[],\n devDependencies: ProjectDistPath[],\n nxRootDir: string,\n packageManager = \"yarn\"\n) => {\n const nxRootPath = tmpProjPath(nxRootDir);\n if (fs.existsSync(nxRootPath)) {\n fs.rmSync(nxRootPath, { recursive: true });\n }\n fs.mkdirSync(nxRootPath, { recursive: true });\n await newNxProject(nxRootDir, nxRootPath, dependencies, devDependencies, packageManager);\n};\n\n/**\n *\n * @param paths paths\n * @param type type\n * @param forceAdd force it\n */\nconst patchMainPackageJson = (\n testDir: string,\n paths: ProjectDistPath[],\n type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\",\n forceAdd = false\n) => {\n const absPackageJson = join(testDir, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n const newPackageJson = { ...packageJson };\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(`Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n } else if (forceAdd) {\n // eslint-disable-next-line no-console\n console.log(`Added ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n};\n\nconst patchDistProjects = (paths: ProjectDistPath[], type: \"dependencies\" | \"devDependencies\" | \"peerDependencies\") => {\n for (const path of paths) {\n const absDistPath1 = getAbsPath(path.path);\n const absPackageJson = join(absDistPath1, \"package.json\");\n const packageJson = readJsonFile(absPackageJson);\n const packageDeps = packageJson?.[type] || {};\n\n for (const pkg of paths) {\n const absDistPath = `file:/${getAbsPath(pkg.path)}`;\n if (packageDeps[pkg.package] && packageDeps[pkg.package] !== absDistPath) {\n // eslint-disable-next-line no-console\n console.log(` In ${path.package} => Update ${pkg.package} => ${absDistPath}`);\n packageDeps[pkg.package] = absDistPath;\n }\n }\n const newPackageJson = { ...packageJson };\n newPackageJson[type] = packageDeps;\n writeJsonFile(absPackageJson, newPackageJson);\n }\n};\n"]}
|