Skip to content

Commit

Permalink
chore(misc): feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Feb 17, 2023
1 parent 69ff4f0 commit dc6fdcb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 44 deletions.
23 changes: 8 additions & 15 deletions packages/nx/src/nx-init/encapsulated/nxw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,16 @@ function matchesCurrentNxInstall(
nxJsonInstallation: NxJsonConfiguration['installation']
) {
try {
const currentInstallation: PackageJson = JSON.parse(
fs.readFileSync(installationPath, 'utf-8')
);
const currentInstallation: PackageJson = require(installationPath);
if (
currentInstallation.devDependencies['nx'] !==
nxJsonInstallation.version ||
JSON.parse(
fs.readFileSync(
path.join(
path.dirname(installationPath),
'node_modules',
'nx',
'package.json'
),
'utf-8'
)
).version !== nxJsonInstallation.version
require(path.join(
path.dirname(installationPath),
'node_modules',
'nx',
'package.json'
)).version !== nxJsonInstallation.version
) {
return false;
}
Expand Down Expand Up @@ -64,7 +57,7 @@ function ensureUpToDateInstallation() {
let nxJson: NxJsonConfiguration;

try {
nxJson = JSON.parse(fs.readFileSync(nxJsonPath, 'utf-8'));
nxJson = require(nxJsonPath);
} catch {
console.error(
'[NX]: nx.json is required when running in encapsulated mode. Run `npx nx init --encapsulated` to restore it.'
Expand Down
59 changes: 30 additions & 29 deletions packages/nx/src/utils/plugins/installed-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,36 @@ export function findInstalledPlugins(): PackageJson[] {
const packageJsonDeps = getDependenciesFromPackageJson();
const nxJsonDeps = getDependenciesFromNxJson();
const deps = packageJsonDeps.concat(nxJsonDeps);
return deps.reduce(
(arr: any[], nextDep: string): { project: string; version: string }[] => {
try {
const depPackageJson: Partial<PackageJson> =
readModulePackageJson(nextDep, [
workspaceRoot,
join(workspaceRoot, '.nx', ' installation'),
]).packageJson || {};
if (
[
'ng-update',
'nx-migrations',
'schematics',
'generators',
'builders',
'executors',
].some((field) => field in depPackageJson)
) {
arr.push({ package: nextDep, ...depPackageJson });
return arr;
} else {
return arr;
}
} catch {
return arr;
}
},
[]
);
const result: PackageJson[] = [];
for (const dep of deps) {
const pluginPackageJson = getNxPluginPackageJsonOrNull(dep);
if (pluginPackageJson) {
result.push(pluginPackageJson);
}
}
return result;
}

function getNxPluginPackageJsonOrNull(pkg: string): PackageJson | null {
try {
const { packageJson } = readModulePackageJson(pkg, [
workspaceRoot,
join(workspaceRoot, '.nx', ' installation'),
]);
return packageJson &&
[
'ng-update',
'nx-migrations',
'schematics',
'generators',
'builders',
'executors',
].some((field) => field in packageJson)
? packageJson
: null;
} catch {
return null;
}
}

function getDependenciesFromPackageJson(
Expand Down

0 comments on commit dc6fdcb

Please sign in to comment.