Skip to content

Commit

Permalink
fix(misc): safely iterate over package.json scripts in nx init command (
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Apr 24, 2023
1 parent 26ad8eb commit dffb3d3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/nx/src/nx-init/add-nx-to-nest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function addNxToNest(options: Options, packageJson: PackageJson) {
'test:watch',
];

const scripts = Object.keys(packageJson.scripts).filter((s) => {
const scripts = Object.keys(packageJson.scripts ?? {}).filter((s) => {
if (nestCacheableScripts.includes(s) || nestIgnoreScripts.includes(s)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/nx-init/add-nx-to-npm-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function addNxToNpmRepo(options: Options) {
let useNxCloud: boolean;

const packageJson = readJsonFile('package.json');
const scripts = Object.keys(packageJson.scripts).filter(
const scripts = Object.keys(packageJson.scripts ?? {}).filter(
(s) => !s.startsWith('pre') && !s.startsWith('post')
);

Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/nx-init/angular/standalone-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function setupStandaloneWorkspace(
// convert workspace config format to standalone project configs
// update its targets outputs and delete angular.json
const projects = toNewFormat(angularJson).projects;
for (const [projectName, project] of Object.entries(projects)) {
for (const [projectName, project] of Object.entries(projects ?? {})) {
updateProjectOutputs(repoRoot, project);
writeJsonFile(join(project.root, 'project.json'), {
$schema: normalizePath(
Expand Down Expand Up @@ -162,7 +162,7 @@ function getWorkspaceCapabilities(
karmaProjectConfigFile: false,
};

for (const project of Object.values(projects)) {
for (const project of Object.values(projects ?? {})) {
if (
!capabilities.eslintProjectConfigFile &&
projectHasEslintConfig(project)
Expand Down

1 comment on commit dffb3d3

@vercel
Copy link

@vercel vercel bot commented on dffb3d3 Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.