Skip to content

Commit 3770b84

Browse files
author
Ethan Arrowood
authored
[cli] add support for JSON5 and skip when no rootDirectory (vercel#8913)
### Related Issues Adds support for comments in JSON configs and skips operation when root directory is null or `'.'` ### πŸ“‹ Checklist <!-- Please keep your PR as a Draft until the checklist is complete --> #### Tests - [ ] The code changed/added as part of this PR has been covered with tests - [ ] All tests pass locally with `yarn test-unit` #### Code Review - [ ] This PR has a concise title and thorough description useful to a reviewer - [ ] Issue from task tracker has a link to this PR
1 parent 91bc2e6 commit 3770b84

File tree

11 files changed

+111
-6
lines changed

11 files changed

+111
-6
lines changed

β€Žpackages/cli/package.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@vercel/remix": "1.0.35",
5252
"@vercel/ruby": "1.3.41",
5353
"@vercel/static-build": "1.0.36",
54+
"json5": "2.2.1",
5455
"update-notifier": "5.1.0"
5556
},
5657
"devDependencies": {

β€Žpackages/cli/src/commands/build.tsβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ async function doBuild(
304304
...pickOverrides(localConfig),
305305
};
306306

307-
await setMonorepoDefaultSettings(cwd, workPath, projectSettings, output);
307+
if (
308+
projectSettings.rootDirectory !== null &&
309+
projectSettings.rootDirectory !== '.'
310+
) {
311+
await setMonorepoDefaultSettings(cwd, workPath, projectSettings, output);
312+
}
308313

309314
// Get a list of source files
310315
const files = (await getFiles(workPath, client)).map(f =>

β€Žpackages/cli/src/util/build/monorepo.tsβ€Ž

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { ProjectLinkAndSettings } from '../projects/project-settings';
1010
import { Output } from '../output';
1111
import title from 'title';
12+
import JSON5 from 'json5';
1213

1314
export async function setMonorepoDefaultSettings(
1415
cwd: string,
@@ -55,7 +56,7 @@ export async function setMonorepoDefaultSettings(
5556

5657
if (monorepoManager === 'turbo') {
5758
// No ENOENT handling required here since conditional wouldn't be `true` unless `turbo.json` was found.
58-
const turboJSON = JSON.parse(
59+
const turboJSON = JSON5.parse(
5960
fs.readFileSync(join(cwd, 'turbo.json'), 'utf-8')
6061
);
6162

@@ -76,7 +77,7 @@ export async function setMonorepoDefaultSettings(
7677
);
7778
} else if (monorepoManager === 'nx') {
7879
// No ENOENT handling required here since conditional wouldn't be `true` unless `nx.json` was found.
79-
const nxJSON = JSON.parse(fs.readFileSync(join(cwd, 'nx.json'), 'utf-8'));
80+
const nxJSON = JSON5.parse(fs.readFileSync(join(cwd, 'nx.json'), 'utf-8'));
8081

8182
if (!nxJSON?.targetDefaults?.build) {
8283
output.log(
@@ -92,14 +93,14 @@ export async function setMonorepoDefaultSettings(
9293

9394
if (projectJSONBuf) {
9495
output.log('Found project.json Nx configuration.');
95-
const projectJSON = JSON.parse(projectJSONBuf.toString('utf-8'));
96+
const projectJSON = JSON5.parse(projectJSONBuf.toString('utf-8'));
9697
if (projectJSON?.targets?.build) {
9798
hasBuildTarget = true;
9899
}
99100
}
100101

101102
if (packageJsonBuf) {
102-
const packageJSON = JSON.parse(packageJsonBuf.toString('utf-8'));
103+
const packageJSON = JSON5.parse(packageJsonBuf.toString('utf-8'));
103104
if (packageJSON?.nx) {
104105
output.log('Found package.json Nx configuration.');
105106
if (packageJSON.nx.targets?.build) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('node:path');
2+
const fs = require('node:fs');
3+
4+
const public = path.join(__dirname, 'public');
5+
fs.rmSync(public, { recursive: true, force: true });
6+
fs.mkdirSync(public);
7+
fs.writeFileSync(path.join(public, 'index.txt'), `Hello, world`);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('node:path');
2+
const fs = require('node:fs');
3+
4+
const public = path.join(__dirname, 'public');
5+
fs.rmSync(public, { recursive: true, force: true });
6+
fs.mkdirSync(public);
7+
fs.writeFileSync(path.join(public, 'index.txt'), `Hello, world`);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('node:path');
2+
const fs = require('node:fs');
3+
4+
const public = path.join(__dirname, 'public');
5+
fs.rmSync(public, { recursive: true, force: true });
6+
fs.mkdirSync(public);
7+
fs.writeFileSync(path.join(public, 'index.txt'), `Hello, world`);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('node:path');
2+
const fs = require('node:fs');
3+
4+
const public = path.join(__dirname, 'public');
5+
fs.rmSync(public, { recursive: true, force: true });
6+
fs.mkdirSync(public);
7+
fs.writeFileSync(path.join(public, 'index.txt'), `Hello, world`);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('node:path');
2+
const fs = require('node:fs');
3+
4+
const public = path.join(__dirname, 'public');
5+
fs.rmSync(public, { recursive: true, force: true });
6+
fs.mkdirSync(public);
7+
fs.writeFileSync(path.join(public, 'index.txt'), `Hello, world`);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('node:path');
2+
const fs = require('node:fs');
3+
4+
const public = path.join(__dirname, 'public');
5+
fs.rmSync(public, { recursive: true, force: true });
6+
fs.mkdirSync(public);
7+
fs.writeFileSync(path.join(public, 'index.txt'), `Hello, world`);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// TEST COMMENT TO VERIFY JSON5 SUPPORT
12
{ "pipeline": { "build": { "dependsOn": ["^build"], "outputs": ["dist/**"] } } }

0 commit comments

Comments
Β (0)