fix(core): quick fix to support trailing commas when reading hoisted … (#29436)
…versions <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Graph fails when there is a trailing comma in a package.json ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Graph does not fail and works when there is a trailing comma in a package.json ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
da4f55bca3
commit
85bc540a15
@ -13,7 +13,7 @@ import {
|
|||||||
} from '../../../project-graph/project-graph-builder';
|
} from '../../../project-graph/project-graph-builder';
|
||||||
import { CreateDependenciesContext } from '../../../project-graph/plugins';
|
import { CreateDependenciesContext } from '../../../project-graph/plugins';
|
||||||
|
|
||||||
jest.mock('fs', () => {
|
jest.mock('node:fs', () => {
|
||||||
const memFs = require('memfs').fs;
|
const memFs = require('memfs').fs;
|
||||||
return {
|
return {
|
||||||
...memFs,
|
...memFs,
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { existsSync, readFileSync } from 'fs';
|
|
||||||
import { PackageJson } from '../../../../utils/package-json';
|
import { PackageJson } from '../../../../utils/package-json';
|
||||||
import { workspaceRoot } from '../../../../utils/workspace-root';
|
import { workspaceRoot } from '../../../../utils/workspace-root';
|
||||||
|
import { readJsonFile } from '../../../../utils/fileutils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get version of hoisted package if available
|
* Get version of hoisted package if available
|
||||||
@ -8,12 +8,12 @@ import { workspaceRoot } from '../../../../utils/workspace-root';
|
|||||||
export function getHoistedPackageVersion(packageName: string): string {
|
export function getHoistedPackageVersion(packageName: string): string {
|
||||||
const fullPath = `${workspaceRoot}/node_modules/${packageName}/package.json`;
|
const fullPath = `${workspaceRoot}/node_modules/${packageName}/package.json`;
|
||||||
|
|
||||||
if (existsSync(fullPath)) {
|
try {
|
||||||
const content = readFileSync(fullPath, 'utf-8');
|
return readJsonFile(fullPath)?.version;
|
||||||
return JSON.parse(content)?.version;
|
} catch (e) {
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export type NormalizedPackageJson = Pick<
|
export type NormalizedPackageJson = Pick<
|
||||||
PackageJson,
|
PackageJson,
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import type {
|
|||||||
ProjectSnapshot,
|
ProjectSnapshot,
|
||||||
ResolvedDependencies,
|
ResolvedDependencies,
|
||||||
} from '@pnpm/lockfile-types';
|
} from '@pnpm/lockfile-types';
|
||||||
import { existsSync, readFileSync } from 'fs';
|
import { existsSync, readFileSync } from 'node:fs';
|
||||||
import { valid } from 'semver';
|
import { valid } from 'semver';
|
||||||
import { workspaceRoot } from '../../../../utils/workspace-root';
|
import { workspaceRoot } from '../../../../utils/workspace-root';
|
||||||
import { hashObject } from '../../../../hasher/file-hasher';
|
import { hashObject } from '../../../../hasher/file-hasher';
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { PackageJson } from '../../../utils/package-json';
|
|||||||
import { ProjectGraphBuilder } from '../../../project-graph/project-graph-builder';
|
import { ProjectGraphBuilder } from '../../../project-graph/project-graph-builder';
|
||||||
import { CreateDependenciesContext } from '../../../project-graph/plugins';
|
import { CreateDependenciesContext } from '../../../project-graph/plugins';
|
||||||
|
|
||||||
jest.mock('fs', () => {
|
jest.mock('node:fs', () => {
|
||||||
const memFs = require('memfs').fs;
|
const memFs = require('memfs').fs;
|
||||||
return {
|
return {
|
||||||
...memFs,
|
...memFs,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user