@plasmicapp/cli 0.1.187 → 0.1.189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/__mocks__/api.d.ts +2 -0
  2. package/dist/__mocks__/api.js +16 -11
  3. package/dist/__tests__/project-api-token-spec.js +2 -2
  4. package/dist/__tests__/versioned-sync-spec.js +4 -4
  5. package/dist/actions/project-token.js +1 -1
  6. package/dist/actions/sync-components.js +1 -1
  7. package/dist/actions/sync-global-variants.d.ts +1 -1
  8. package/dist/actions/sync-global-variants.js +2 -2
  9. package/dist/actions/sync-icons.d.ts +1 -1
  10. package/dist/actions/sync-icons.js +2 -2
  11. package/dist/actions/sync-images.d.ts +1 -1
  12. package/dist/actions/sync-images.js +2 -2
  13. package/dist/actions/sync.js +23 -18
  14. package/dist/api.d.ts +10 -7
  15. package/dist/api.js +11 -10
  16. package/dist/plasmic.schema.json +4 -0
  17. package/dist/test-common/fixtures.js +3 -0
  18. package/dist/utils/auth-utils.js +2 -2
  19. package/dist/utils/config-utils.d.ts +4 -1
  20. package/dist/utils/config-utils.js +2 -1
  21. package/dist/utils/resolve-utils.js +11 -7
  22. package/package.json +2 -3
  23. package/src/__mocks__/api.ts +28 -7
  24. package/src/__tests__/project-api-token-spec.ts +2 -2
  25. package/src/__tests__/versioned-sync-spec.ts +4 -4
  26. package/src/actions/project-token.ts +1 -1
  27. package/src/actions/sync-components.ts +6 -1
  28. package/src/actions/sync-global-variants.ts +8 -3
  29. package/src/actions/sync-icons.ts +3 -2
  30. package/src/actions/sync-images.ts +2 -1
  31. package/src/actions/sync.ts +38 -21
  32. package/src/api.ts +15 -8
  33. package/src/test-common/fixtures.ts +3 -0
  34. package/src/utils/auth-utils.ts +3 -3
  35. package/src/utils/config-utils.ts +5 -0
  36. package/src/utils/resolve-utils.ts +25 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.187",
3
+ "version": "0.1.189",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -53,7 +53,6 @@
53
53
  "@babel/traverse": "^7.12.1",
54
54
  "@plasmicapp/code-merger": "^0.0.33",
55
55
  "@sentry/node": "^5.19.2",
56
- "@types/socket.io-client": "^1.4.34",
57
56
  "axios": "^0.21.1",
58
57
  "chalk": "^4.1.0",
59
58
  "fast-glob": "^3.2.4",
@@ -69,7 +68,7 @@
69
68
  "path": "^0.12.7",
70
69
  "prettier": "^2.0.5",
71
70
  "semver": "^7.3.2",
72
- "socket.io-client": "^3.0.3",
71
+ "socket.io-client": "^4.1.2",
73
72
  "typescript": "^3.9.6",
74
73
  "upath": "^1.2.0",
75
74
  "update-notifier": "^4.1.0",
@@ -26,6 +26,7 @@ const api: any = jest.genMockFromModule("../api");
26
26
  const PROJECTS: MockProject[] = [];
27
27
  export interface MockProject {
28
28
  projectId: string;
29
+ branchName: string;
29
30
  projectApiToken: string;
30
31
  version: string;
31
32
  projectName: string;
@@ -38,6 +39,7 @@ export interface MockComponent {
38
39
  id: string;
39
40
  name: string;
40
41
  projectId?: string;
42
+ branchName?: string;
41
43
  version?: string;
42
44
  }
43
45
 
@@ -72,6 +74,7 @@ function mockProjectToProjectVersionMeta(
72
74
  */
73
75
  function addMockProject(proj: MockProject) {
74
76
  const projectId = proj.projectId;
77
+ const branchName = proj.branchName;
75
78
  const version = proj.version;
76
79
  // Populate projectId and version into each component
77
80
  // will be useful when reading / writing components to files
@@ -79,11 +82,12 @@ function addMockProject(proj: MockProject) {
79
82
  return {
80
83
  ...c,
81
84
  projectId,
85
+ branchName,
82
86
  version,
83
87
  };
84
88
  });
85
89
 
86
- const existing = getMockProject(projectId, version);
90
+ const existing = getMockProject(projectId, branchName, version);
87
91
  if (!existing) {
88
92
  PROJECTS.push(proj);
89
93
  } else {
@@ -117,10 +121,14 @@ function mockComponentToString(component: MockComponent): string {
117
121
 
118
122
  function getMockProject(
119
123
  projectId: string,
124
+ branchName: string,
120
125
  version: string
121
126
  ): MockProject | undefined {
122
127
  return PROJECTS.find(
123
- (m) => m.projectId === projectId && m.version === version
128
+ (m) =>
129
+ m.projectId === projectId &&
130
+ m.branchName === branchName &&
131
+ m.version === version
124
132
  );
125
133
  }
126
134
 
@@ -128,15 +136,17 @@ function getMockProject(
128
136
  * Only fetch top-level components that match the projectId (optionally also componentIdOrNames + version)
129
137
  * Does not crawl the dependency tree
130
138
  * @param projectId
139
+ * @param branchName
131
140
  * @param componentIdOrNames
132
141
  * @param versionRange
133
142
  */
134
143
  function getMockComponents(
135
144
  projectId: string,
145
+ branchName: string,
136
146
  version: string,
137
147
  componentIdOrNames: readonly string[] | undefined
138
148
  ): MockComponent[] {
139
- const project = getMockProject(projectId, version);
149
+ const project = getMockProject(projectId, branchName, version);
140
150
  return !project
141
151
  ? []
142
152
  : project.components.filter(
@@ -193,7 +203,7 @@ function* getDeps(projects: ProjectVersionMeta[]) {
193
203
  while (queue.length > 0) {
194
204
  const curr = ensure(queue.shift());
195
205
  for (const [projectId, version] of L.toPairs(curr.dependencies)) {
196
- const mockProject = ensure(getMockProject(projectId, version));
206
+ const mockProject = ensure(getMockProject(projectId, "main", version));
197
207
  const projectMeta = mockProjectToProjectVersionMeta(mockProject);
198
208
  yield projectMeta;
199
209
  queue.push(projectMeta);
@@ -215,6 +225,7 @@ class PlasmicApi {
215
225
  async resolveSync(
216
226
  projects: {
217
227
  projectId: string;
228
+ branchName: string;
218
229
  versionRange: string;
219
230
  componentIdOrNames: readonly string[] | undefined;
220
231
  projectApiToken?: string;
@@ -248,7 +259,9 @@ class PlasmicApi {
248
259
  proj.versionRange
249
260
  );
250
261
  if (version) {
251
- const mockProject = ensure(getMockProject(proj.projectId, version));
262
+ const mockProject = ensure(
263
+ getMockProject(proj.projectId, proj.branchName, version)
264
+ );
252
265
  const projectMeta = mockProjectToProjectVersionMeta(
253
266
  mockProject,
254
267
  proj.componentIdOrNames
@@ -272,6 +285,7 @@ class PlasmicApi {
272
285
 
273
286
  async projectComponents(
274
287
  projectId: string,
288
+ branchName: string,
275
289
  opts: {
276
290
  platform: string;
277
291
  newCompScheme: "blackbox" | "direct";
@@ -310,6 +324,7 @@ class PlasmicApi {
310
324
  }
311
325
  const mockComponents = getMockComponents(
312
326
  projectId,
327
+ branchName,
313
328
  version,
314
329
  componentIdOrNames
315
330
  );
@@ -357,11 +372,17 @@ class PlasmicApi {
357
372
  throw new Error("Unimplemented");
358
373
  }
359
374
 
360
- async projectStyleTokens(projectId: string): Promise<StyleTokensMap> {
375
+ async projectStyleTokens(
376
+ projectId: string,
377
+ branchName: string
378
+ ): Promise<StyleTokensMap> {
361
379
  throw new Error("Unimplemented");
362
380
  }
363
381
 
364
- async projectIcons(projectId: string): Promise<ProjectIconsResponse> {
382
+ async projectIcons(
383
+ projectId: string,
384
+ branchName: string
385
+ ): Promise<ProjectIconsResponse> {
365
386
  throw new Error("Unimplemented");
366
387
  }
367
388
 
@@ -145,7 +145,7 @@ describe("Project API tokens", () => {
145
145
  // We sync project1 which got updated, but the dependency is still same version.
146
146
  opts.force = false;
147
147
  removeAuth();
148
- mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
148
+ mockApi.getMockProject("projectId1", "main", "1.2.3").version = "1.2.4";
149
149
  await expect(sync(opts)).resolves.toBeUndefined();
150
150
  });
151
151
 
@@ -196,7 +196,7 @@ describe("Project API tokens", () => {
196
196
  // We sync project1 which got updated, but the dependency is still same version.
197
197
  opts.force = false;
198
198
  removeAuth();
199
- mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
199
+ mockApi.getMockProject("projectId1", "main", "1.2.3").version = "1.2.4";
200
200
  await expect(sync(opts)).resolves.toBeUndefined();
201
201
  });
202
202
 
@@ -54,7 +54,7 @@ describe("versioned-sync", () => {
54
54
  opts.projects = ["projectId1"];
55
55
  await expect(sync(opts)).resolves.toBeUndefined();
56
56
  // Change component name server-side
57
- const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
57
+ const mockProject = mockApi.getMockProject("projectId1", "main", "1.2.3");
58
58
  const buttonData = mockProject.components.find(
59
59
  (c: MockComponent) => c.id === "buttonId"
60
60
  );
@@ -79,7 +79,7 @@ describe("versioned-sync", () => {
79
79
  opts.projects = ["projectId1"];
80
80
  await expect(sync(opts)).resolves.toBeUndefined();
81
81
  // Change component version server-side
82
- const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
82
+ const mockProject = mockApi.getMockProject("projectId1", "main", "1.2.3");
83
83
  mockProject.version = "1.3.4";
84
84
  mockApi.addMockProject(mockProject);
85
85
  // Try syncing again and see if things show up
@@ -97,7 +97,7 @@ describe("versioned-sync", () => {
97
97
  opts.nonRecursive = true;
98
98
  await expect(sync(opts)).resolves.toBeUndefined();
99
99
  // Change component version server-side
100
- const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
100
+ const mockProject = mockApi.getMockProject("projectId1", "main", "1.2.3");
101
101
  mockProject.version = "2.0.0";
102
102
  mockApi.addMockProject(mockProject);
103
103
  // Read in updated plasmic.json post-sync
@@ -125,7 +125,7 @@ describe("versioned-sync", () => {
125
125
  opts.nonRecursive = true;
126
126
  await expect(sync(opts)).resolves.toBeUndefined();
127
127
  // Change component version server-side
128
- const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
128
+ const mockProject = mockApi.getMockProject("projectId1", "main", "1.2.3");
129
129
  mockProject.version = "1.10.1";
130
130
  mockApi.addMockProject(mockProject);
131
131
  // Update plasmic.json to use semver
@@ -18,7 +18,7 @@ export const getProjectApiToken = async (projectId: string, host?: string) => {
18
18
  if (auth) {
19
19
  const api = new PlasmicApi(auth);
20
20
  const versionResolution = await api.resolveSync([
21
- { projectId, componentIdOrNames: undefined },
21
+ { projectId, branchName: "main", componentIdOrNames: undefined },
22
22
  ]);
23
23
  return versionResolution.projects[0]?.projectApiToken;
24
24
  }
@@ -64,7 +64,12 @@ const updateDirectSkeleton = async (
64
64
  compConfig.projectId,
65
65
  makeCachedProjectSyncDataProvider(async (projectId, revision) => {
66
66
  try {
67
- return await context.api.projectSyncMetadata(projectId, revision, true);
67
+ return await context.api.projectSyncMetadata(
68
+ projectId,
69
+ "main",
70
+ revision,
71
+ true
72
+ );
68
73
  } catch (e) {
69
74
  if (
70
75
  e instanceof AppServerError &&
@@ -18,10 +18,11 @@ export async function syncGlobalVariants(
18
18
  projectMeta: ProjectMetaBundle,
19
19
  bundles: GlobalVariantBundle[],
20
20
  checksums: ChecksumBundle,
21
- baseDir: string,
21
+ branchName: string,
22
+ baseDir: string
22
23
  ) {
23
24
  const projectId = projectMeta.projectId;
24
- const projectLock = getOrAddProjectLock(context, projectId);
25
+ const projectLock = getOrAddProjectLock(context, projectId, branchName);
25
26
  const existingVariantConfigs = L.keyBy(
26
27
  context.config.globalVariants.variantGroups.filter(
27
28
  (group) => group.projectId === projectId
@@ -100,7 +101,11 @@ export async function syncGlobalVariants(
100
101
  await writeFileContent(
101
102
  context,
102
103
  variantConfig.contextFilePath,
103
- formatAsLocal(bundle.contextModule, variantConfig.contextFilePath, baseDir),
104
+ formatAsLocal(
105
+ bundle.contextModule,
106
+ variantConfig.contextFilePath,
107
+ baseDir
108
+ ),
104
109
  { force: !isNew }
105
110
  );
106
111
  }
@@ -25,17 +25,18 @@ export interface SyncIconsArgs extends CommonArgs {
25
25
  export async function syncProjectIconAssets(
26
26
  context: PlasmicContext,
27
27
  projectId: string,
28
+ branchName: string,
28
29
  version: string,
29
30
  iconBundles: IconBundle[],
30
31
  checksums: ChecksumBundle,
31
- baseDir: string,
32
+ baseDir: string
32
33
  ) {
33
34
  const project = getOrAddProjectConfig(context, projectId);
34
35
  if (!project.icons) {
35
36
  project.icons = [];
36
37
  }
37
38
 
38
- const projectLock = getOrAddProjectLock(context, projectId);
39
+ const projectLock = getOrAddProjectLock(context, projectId, branchName);
39
40
  const knownIconConfigs = L.keyBy(project.icons, (i) => i.id);
40
41
  const iconFileLocks = L.keyBy(
41
42
  projectLock.fileLocks.filter((fileLock) => fileLock.type === "icon"),
@@ -22,12 +22,13 @@ import { ensure } from "../utils/lang-utils";
22
22
  export async function syncProjectImageAssets(
23
23
  context: PlasmicContext,
24
24
  projectId: string,
25
+ branchName: string,
25
26
  version: string,
26
27
  imageBundles: ImageBundle[],
27
28
  checksums: ChecksumBundle
28
29
  ) {
29
30
  const project = getOrAddProjectConfig(context, projectId);
30
- const projectLock = getOrAddProjectLock(context, projectId);
31
+ const projectLock = getOrAddProjectLock(context, projectId, branchName);
31
32
  const knownImageConfigs = L.keyBy(project.images, (i) => i.id);
32
33
  const imageBundleIds = L.keyBy(imageBundles, (i) => i.id);
33
34
  const imageFileLocks = L.keyBy(
@@ -243,6 +243,7 @@ export async function sync(
243
243
  const [projectId, projectApiToken] = projectIdToken.split(":");
244
244
  return {
245
245
  projectId,
246
+ branchName: projectConfigMap[projectId]?.projectBranchName ?? "main",
246
247
  versionRange:
247
248
  versionRange || projectConfigMap[projectId]?.version || "latest",
248
249
  componentIdOrNames: undefined, // Get all components!
@@ -255,6 +256,7 @@ export async function sync(
255
256
  ? projectWithVersion
256
257
  : context.config.projects.map((p) => ({
257
258
  projectId: p.projectId,
259
+ branchName: p.projectBranchName ?? "main",
258
260
  versionRange: p.version,
259
261
  componentIdOrNames: undefined, // Get all components!
260
262
  projectApiToken: p.projectApiToken,
@@ -341,6 +343,7 @@ export async function sync(
341
343
  opts,
342
344
  projectIdsAndTokens,
343
345
  projectMeta.projectId,
346
+ projectMeta.branchName,
344
347
  projectMeta.componentIds,
345
348
  projectMeta.version,
346
349
  projectMeta.dependencies,
@@ -557,6 +560,7 @@ async function syncProject(
557
560
  opts: SyncArgs,
558
561
  projectIdsAndTokens: ProjectIdAndToken[],
559
562
  projectId: string,
563
+ branchName: string,
560
564
  componentIds: string[],
561
565
  projectVersion: string,
562
566
  dependencies: { [projectId: string]: string },
@@ -591,26 +595,30 @@ async function syncProject(
591
595
  );
592
596
 
593
597
  // Server-side code-gen
594
- const projectBundle = await context.api.projectComponents(projectId, {
595
- platform: context.config.platform,
596
- newCompScheme: newComponentScheme,
597
- existingCompScheme,
598
- componentIdOrNames: componentIds,
599
- version: projectVersion,
600
- imageOpts: context.config.images,
601
- stylesOpts: context.config.style,
602
- checksums: existingChecksums,
603
- codeOpts: context.config.code,
604
- metadata: generateMetadata(
605
- {
606
- ...metadataDefaults,
607
- platform: context.config.platform,
608
- },
609
- opts.metadata
610
- ),
611
- indirect,
612
- wrapPagesWithGlobalContexts: context.config.wrapPagesWithGlobalContexts,
613
- });
598
+ const projectBundle = await context.api.projectComponents(
599
+ projectId,
600
+ branchName,
601
+ {
602
+ platform: context.config.platform,
603
+ newCompScheme: newComponentScheme,
604
+ existingCompScheme,
605
+ componentIdOrNames: componentIds,
606
+ version: projectVersion,
607
+ imageOpts: context.config.images,
608
+ stylesOpts: context.config.style,
609
+ checksums: existingChecksums,
610
+ codeOpts: context.config.code,
611
+ metadata: generateMetadata(
612
+ {
613
+ ...metadataDefaults,
614
+ platform: context.config.platform,
615
+ },
616
+ opts.metadata
617
+ ),
618
+ indirect,
619
+ wrapPagesWithGlobalContexts: context.config.wrapPagesWithGlobalContexts,
620
+ }
621
+ );
614
622
 
615
623
  // Convert from TSX => JSX
616
624
  if (context.config.code.lang === "js") {
@@ -653,6 +661,7 @@ async function syncProject(
653
661
  projectBundle.projectConfig,
654
662
  projectBundle.globalVariants,
655
663
  projectBundle.checksums,
664
+ branchName,
656
665
  opts.baseDir
657
666
  );
658
667
 
@@ -660,6 +669,7 @@ async function syncProject(
660
669
  context,
661
670
  projectBundle.projectConfig,
662
671
  projectApiToken,
672
+ branchName,
663
673
  projectVersion,
664
674
  dependencies,
665
675
  projectBundle.components,
@@ -680,6 +690,7 @@ async function syncProject(
680
690
  await syncProjectIconAssets(
681
691
  context,
682
692
  projectId,
693
+ branchName,
683
694
  projectVersion,
684
695
  projectBundle.iconAssets,
685
696
  projectBundle.checksums,
@@ -688,6 +699,7 @@ async function syncProject(
688
699
  await syncProjectImageAssets(
689
700
  context,
690
701
  projectId,
702
+ branchName,
691
703
  projectVersion,
692
704
  projectBundle.imageAssets,
693
705
  projectBundle.checksums
@@ -720,6 +732,7 @@ async function syncProjectConfig(
720
732
  context: PlasmicContext,
721
733
  projectBundle: ProjectMetaBundle,
722
734
  projectApiToken: string,
735
+ branchName: string,
723
736
  version: string,
724
737
  dependencies: { [projectId: string]: string },
725
738
  componentBundles: ComponentBundle[],
@@ -760,7 +773,11 @@ async function syncProjectConfig(
760
773
  }
761
774
 
762
775
  // plasmic.lock
763
- const projectLock = getOrAddProjectLock(context, projectConfig.projectId);
776
+ const projectLock = getOrAddProjectLock(
777
+ context,
778
+ projectConfig.projectId,
779
+ branchName
780
+ );
764
781
  projectLock.version = version;
765
782
  projectLock.dependencies = dependencies;
766
783
  projectLock.lang = context.config.code.lang;
package/src/api.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ProjectSyncMetadataModel } from "@plasmicapp/code-merger";
2
2
  import axios, { AxiosError } from "axios";
3
- import socketio from "socket.io-client";
3
+ import socketio, { Socket } from "socket.io-client";
4
4
  import {
5
5
  AuthConfig,
6
6
  CodeConfig,
@@ -75,6 +75,7 @@ export interface ImageBundle {
75
75
 
76
76
  export interface ProjectVersionMeta {
77
77
  projectId: string;
78
+ branchName: string;
78
79
  projectApiToken: string;
79
80
  version: string;
80
81
  projectName: string;
@@ -201,6 +202,7 @@ export class PlasmicApi {
201
202
  async resolveSync(
202
203
  projects: {
203
204
  projectId: string;
205
+ branchName: string;
204
206
  versionRange?: string;
205
207
  componentIdOrNames: readonly string[] | undefined;
206
208
  projectApiToken?: string;
@@ -243,9 +245,10 @@ export class PlasmicApi {
243
245
 
244
246
  /**
245
247
  * Code-gen endpoint.
246
- * This will fetch components at an exact specified version.
248
+ * This will fetch components from a given branch at an exact specified version.
247
249
  * If you don't know what version should be used, call `resolveSync` first.
248
250
  * @param projectId
251
+ * @param branchName
249
252
  * @param cliVersion
250
253
  * @param reactWebVersion
251
254
  * @param newCompScheme
@@ -255,6 +258,7 @@ export class PlasmicApi {
255
258
  */
256
259
  async projectComponents(
257
260
  projectId: string,
261
+ branchName: string,
258
262
  opts: {
259
263
  platform: string;
260
264
  newCompScheme: "blackbox" | "direct";
@@ -272,7 +276,7 @@ export class PlasmicApi {
272
276
  }
273
277
  ): Promise<ProjectBundle> {
274
278
  const result = await this.post(
275
- `${this.codegenHost}/api/v1/projects/${projectId}/code/components`,
279
+ `${this.codegenHost}/api/v1/projects/${projectId}/code/components?branchName=${branchName}`,
276
280
  {
277
281
  ...opts,
278
282
  }
@@ -345,10 +349,11 @@ export class PlasmicApi {
345
349
 
346
350
  async projectStyleTokens(
347
351
  projectId: string,
352
+ branchName: string,
348
353
  versionRange?: string
349
354
  ): Promise<StyleTokensMap> {
350
355
  const result = await this.post(
351
- `${this.codegenHost}/api/v1/projects/${projectId}/code/tokens`,
356
+ `${this.codegenHost}/api/v1/projects/${projectId}/code/tokens?branchName=${branchName}`,
352
357
  { versionRange }
353
358
  );
354
359
  return result.data as StyleTokensMap;
@@ -356,11 +361,12 @@ export class PlasmicApi {
356
361
 
357
362
  async projectIcons(
358
363
  projectId: string,
364
+ branchName: string,
359
365
  versionRange?: string,
360
366
  iconIds?: string[]
361
367
  ): Promise<ProjectIconsResponse> {
362
368
  const result = await this.post(
363
- `${this.codegenHost}/api/v1/projects/${projectId}/code/icons`,
369
+ `${this.codegenHost}/api/v1/projects/${projectId}/code/icons?branchName=${branchName}`,
364
370
  { versionRange, iconIds }
365
371
  );
366
372
  return result.data as ProjectIconsResponse;
@@ -368,19 +374,20 @@ export class PlasmicApi {
368
374
 
369
375
  async projectSyncMetadata(
370
376
  projectId: string,
377
+ branchName: string,
371
378
  revision: number,
372
379
  rethrowAppError: boolean
373
380
  ): Promise<ProjectSyncMetadataModel> {
374
381
  const result = await this.post(
375
- `${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata`,
382
+ `${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata?branchName=${branchName}`,
376
383
  { revision },
377
384
  rethrowAppError
378
385
  );
379
386
  return ProjectSyncMetadataModel.fromJson(result.data);
380
387
  }
381
388
 
382
- connectSocket(): SocketIOClient.Socket {
383
- const socket = socketio.connect(this.studioHost, {
389
+ connectSocket(): Socket {
390
+ const socket = socketio(this.studioHost, {
384
391
  path: `/api/v1/socket`,
385
392
  transportOptions: {
386
393
  polling: {
@@ -43,6 +43,7 @@ export function standardTestSetup(includeDep = true) {
43
43
  // Setup server-side mock data
44
44
  const project1: MockProject = {
45
45
  projectId: "projectId1",
46
+ branchName: "main",
46
47
  projectApiToken: "abc",
47
48
  version: "1.2.3",
48
49
  projectName: "project1",
@@ -64,6 +65,7 @@ export function standardTestSetup(includeDep = true) {
64
65
  };
65
66
  const dependency: MockProject = {
66
67
  projectId: "dependencyId1",
68
+ branchName: "main",
67
69
  projectApiToken: "def",
68
70
  version: "2.3.4",
69
71
  projectName: "dependency1",
@@ -128,6 +130,7 @@ export function expectProject1Components() {
128
130
  export const project1Config: ProjectConfig = {
129
131
  projectId: "projectId1",
130
132
  projectName: "Project 1",
133
+ projectBranchName: "main",
131
134
  version: "latest",
132
135
  cssFilePath: "plasmic/PP__demo.css",
133
136
  components: [
@@ -38,7 +38,7 @@ export function authByPolling(
38
38
  host: string,
39
39
  initToken: string
40
40
  ): CancellablePromise<AuthData> {
41
- const socket = socketio.connect(host, {
41
+ const socket = socketio(host, {
42
42
  path: `/api/v1/init-token`,
43
43
  transportOptions: {
44
44
  polling: {
@@ -50,7 +50,7 @@ export function authByPolling(
50
50
  });
51
51
 
52
52
  const promise = new Promise<AuthData>((resolve, reject) => {
53
- socket.on("connect", (reason: string) => {
53
+ socket.on("connect", () => {
54
54
  logger.info("Waiting for token...");
55
55
  });
56
56
 
@@ -219,7 +219,7 @@ export async function getCurrentAuth(authPath?: string) {
219
219
  await api.getCurrentUser();
220
220
  return auth;
221
221
  } catch (e) {
222
- if (e.response?.status === 401) {
222
+ if ((e as any).response?.status === 401) {
223
223
  logger.error(`The current credentials expired or are not valid.`);
224
224
  return undefined;
225
225
  }
@@ -155,6 +155,8 @@ export interface ProjectConfig {
155
155
  projectApiToken?: string;
156
156
  /** Project name synced down from Studio */
157
157
  projectName: string;
158
+ /** Project branch to be synced */
159
+ projectBranchName?: string;
158
160
  /**
159
161
  * A version range for syncing this project. Can be:
160
162
  * * "latest" - always syncs down whatever has been saved in the project.
@@ -317,6 +319,7 @@ export interface FileLock {
317
319
 
318
320
  export interface ProjectLock {
319
321
  projectId: string;
322
+ branchName: string;
320
323
  // The exact version that was last synced
321
324
  version: string;
322
325
  dependencies: {
@@ -550,6 +553,7 @@ export function getOrAddProjectConfig(
550
553
  export function getOrAddProjectLock(
551
554
  context: PlasmicContext,
552
555
  projectId: string,
556
+ branchName: string,
553
557
  base?: ProjectLock // if one doesn't exist, start with this
554
558
  ): ProjectLock {
555
559
  let project = context.lock.projects.find((p) => p.projectId === projectId);
@@ -558,6 +562,7 @@ export function getOrAddProjectLock(
558
562
  ? L.cloneDeep(base)
559
563
  : {
560
564
  projectId,
565
+ branchName,
561
566
  version: "",
562
567
  dependencies: {},
563
568
  lang: context.config.code.lang,