Skip to content

Commit f706e63

Browse files
authored
[cli] Store projectName in project.json when linking to a project (vercel#13611)
This PR adds `projectName` to `project.json` when you link or pull project settings. This will be used by microfrontends in local development to find the right microfrontends configuration and/or suggest a better error message to the user.
1 parent 380dd85 commit f706e63

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

.changeset/twelve-terms-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vercel': patch
3+
---
4+
5+
Save projectName in project.json when linking a Project.

internals/types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ export interface ProjectLink {
421421
* to the selected project root directory.
422422
*/
423423
projectRootDirectory?: string;
424+
/**
425+
* Name of the Vercel Project.
426+
*/
427+
projectName?: string;
424428
}
425429

426430
export interface PaginationOptions {

packages/cli/src/util/projects/link.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const linkSchema = {
4747
type: 'string',
4848
minLength: 1,
4949
},
50+
projectName: {
51+
type: 'string',
52+
minLength: 1,
53+
},
5054
},
5155
};
5256

@@ -318,7 +322,10 @@ export async function linkFolderToProject(
318322

319323
await writeFile(
320324
join(path, VERCEL_DIR, VERCEL_DIR_PROJECT),
321-
JSON.stringify(projectLink)
325+
JSON.stringify({
326+
...projectLink,
327+
projectName,
328+
})
322329
);
323330

324331
await writeReadme(path);

packages/cli/src/util/projects/project-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export async function writeProjectSettings(
4343
const projectLinkAndSettings: ProjectLinkAndSettings = {
4444
projectId: isRepoLinked ? undefined : project.id,
4545
orgId: isRepoLinked ? undefined : org.id,
46+
projectName: isRepoLinked ? undefined : project.name,
4647
settings: {
4748
createdAt: project.createdAt,
4849
framework: project.framework,

packages/cli/test/unit/commands/link/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ describe('link', () => {
313313
const projectJson = await readJSON(join(cwd, '.vercel/project.json'));
314314
expect(projectJson.orgId).toEqual(user.id);
315315
expect(projectJson.projectId).toEqual(project.id);
316+
expect(projectJson.projectName).toEqual(project.name);
316317
});
317318

318319
it('should track use of redacted `--project` option', async () => {
@@ -373,6 +374,7 @@ describe('link', () => {
373374
const projectJson = await readJSON(join(cwd, '.vercel/project.json'));
374375
expect(projectJson.orgId).toEqual(user.id);
375376
expect(projectJson.projectId).toEqual(project.id);
377+
expect(projectJson.projectName).toEqual(project.name);
376378

377379
const gitignore = await readFile(join(cwd, '.gitignore'), 'utf8');
378380
expect(gitignore).toBe(`.vercel${EOL}`);
@@ -465,6 +467,7 @@ describe('link', () => {
465467
const projectJson = await readJSON(join(cwd, '.vercel/project.json'));
466468
expect(projectJson.orgId).toEqual(user.id);
467469
expect(projectJson.projectId).toEqual(project.id);
470+
expect(projectJson.projectName).toEqual(project.name);
468471
});
469472

470473
it('should create new Project', async () => {
@@ -539,6 +542,7 @@ describe('link', () => {
539542
let projectJson = await readJSON(join(cwd, '.vercel/project.json'));
540543
expect(projectJson.orgId).toEqual(user.id);
541544
expect(projectJson.projectId).toEqual(proj1.id);
545+
expect(projectJson.projectName).toEqual(proj1.name);
542546

543547
client.setArgv('--project', proj2.name!, '--yes');
544548
const exitCodeLink2 = await link(client);
@@ -547,6 +551,7 @@ describe('link', () => {
547551
projectJson = await readJSON(join(cwd, '.vercel/project.json'));
548552
expect(projectJson.orgId).toEqual(user.id);
549553
expect(projectJson.projectId).toEqual(proj2.id);
554+
expect(projectJson.projectName).toEqual(proj2.name);
550555
});
551556

552557
it('should track use of deprecated `cwd` positional argument', async () => {

packages/cli/test/unit/commands/pull/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ describe('pull', () => {
133133
{
134134
"orgId": "team_dummy",
135135
"projectId": "vercel-pull-next",
136+
"projectName": "vercel-pull-next",
136137
"settings": {
137138
"createdAt": 1555413045188,
138139
},

0 commit comments

Comments
 (0)