@plasmicapp/cli 0.1.353 → 0.1.355

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 (34) hide show
  1. package/dist/__tests__/envdetect.spec.d.ts +1 -0
  2. package/dist/actions/sync-components.d.ts +1 -1
  3. package/dist/actions/sync-data-tokens.d.ts +1 -1
  4. package/dist/actions/sync-global-contexts.d.ts +1 -1
  5. package/dist/actions/sync-global-variants.d.ts +1 -1
  6. package/dist/actions/sync-icons.d.ts +1 -1
  7. package/dist/actions/sync-project-module.d.ts +1 -1
  8. package/dist/actions/sync-splits-provider.d.ts +1 -1
  9. package/dist/actions/sync-style-tokens-provider.d.ts +1 -1
  10. package/dist/index.js +248 -262
  11. package/dist/lib.js +248 -262
  12. package/dist/utils/code-utils.d.ts +6 -6
  13. package/dist/utils/config-utils.d.ts +3 -3
  14. package/dist/utils/envdetect.d.ts +1 -1
  15. package/package.json +2 -2
  16. package/src/__tests__/code-utils-spec.ts +6 -9
  17. package/src/__tests__/envdetect.spec.ts +115 -0
  18. package/src/actions/export.ts +110 -120
  19. package/src/actions/fix-imports.ts +5 -3
  20. package/src/actions/init.ts +5 -4
  21. package/src/actions/sync-components.ts +2 -6
  22. package/src/actions/sync-data-tokens.ts +5 -10
  23. package/src/actions/sync-global-contexts.ts +5 -6
  24. package/src/actions/sync-global-variants.ts +3 -8
  25. package/src/actions/sync-icons.ts +3 -4
  26. package/src/actions/sync-project-module.ts +5 -6
  27. package/src/actions/sync-splits-provider.ts +5 -6
  28. package/src/actions/sync-style-tokens-provider.ts +5 -7
  29. package/src/actions/sync.ts +15 -30
  30. package/src/migrations/migrations.ts +3 -3
  31. package/src/utils/code-utils.ts +15 -44
  32. package/src/utils/config-utils.ts +7 -21
  33. package/src/utils/envdetect.ts +42 -5
  34. package/src/utils/rsc-config.ts +29 -12
@@ -1,14 +1,14 @@
1
1
  import { ImportDeclaration } from "@babel/types";
2
2
  import type { Options } from "prettier";
3
3
  import { CodeComponentConfig, ComponentConfig, CustomFunctionConfig, GlobalVariantGroupConfig, IconConfig, ImageConfig, PlasmicConfig, PlasmicContext, ProjectConfig } from "./config-utils";
4
- export declare function formatAsLocal(content: string, filePath: string, baseDir: string, defaultOpts?: Options): Promise<string>;
4
+ export declare function formatAsLocal(content: string, filePath: string, defaultOpts?: Options): Promise<string>;
5
5
  export declare function ensureImportSpecifierWithAlias(decl: ImportDeclaration, imported: string, alias: string): void;
6
6
  export declare function ensureImportDefaultSpecifier(decl: ImportDeclaration, defaultExport: string): void;
7
7
  /**
8
8
  * Given the argument `code` string, for module at `fromPath`, replaces all Plasmic imports
9
9
  * for modules found in `compConfigsMap`.
10
10
  */
11
- export declare function replaceImports(context: PlasmicContext, code: string, fromPath: string, fixImportContext: FixImportContext, removeImportDirective: boolean, baseDir: string, changed?: boolean): Promise<string>;
11
+ export declare function replaceImports(context: PlasmicContext, code: string, fromPath: string, fixImportContext: FixImportContext, removeImportDirective: boolean, changed?: boolean): Promise<string>;
12
12
  /**
13
13
  * Returns true if the argument ComponentConfig.importSpec.modulePath is referencing
14
14
  * a local file
@@ -32,8 +32,8 @@ export declare const mkFixImportContext: (config: PlasmicConfig) => FixImportCon
32
32
  * Assuming that all the files referenced in PlasmicConfig are correct, fixes import statements using PlasmicConfig
33
33
  * file locations as the source of truth.
34
34
  */
35
- export declare function fixAllImportStatements(context: PlasmicContext, baseDir: string, summary?: Map<string, ComponentUpdateSummary>): Promise<void>;
35
+ export declare function fixAllImportStatements(context: PlasmicContext, summary?: Map<string, ComponentUpdateSummary>): Promise<void>;
36
36
  export declare const tsxToJsx: (code: string) => string;
37
- export declare function maybeConvertTsxToJsx(fileName: string, content: string, baseDir: string): Promise<[string, string]>;
38
- export declare function formatScript(code: string, baseDir: string): Promise<string>;
39
- export declare function fixRscModulesImports(context: PlasmicContext, baseDir: string, fixImportContext: FixImportContext, compConfig: ComponentConfig): Promise<void>;
37
+ export declare function maybeConvertTsxToJsx(fileName: string, content: string): Promise<[string, string]>;
38
+ export declare function formatScript(code: string): Promise<string>;
39
+ export declare function fixRscModulesImports(context: PlasmicContext, fixImportContext: FixImportContext, compConfig: ComponentConfig): Promise<void>;
@@ -336,9 +336,9 @@ export declare function findConfigFile(dir: string, opts: {
336
336
  */
337
337
  export declare function fillDefaults(config: DeepPartial<PlasmicConfig>): PlasmicConfig;
338
338
  export declare function readConfig(configFile: string, autoFillDefaults: boolean): PlasmicConfig;
339
- export declare function writeConfig(configFile: string, config: PlasmicConfig, baseDir: string): Promise<void>;
340
- export declare function writeLock(lockFile: string, lock: PlasmicLock, baseDir: string): Promise<void>;
341
- export declare function updateConfig(context: PlasmicContext, newConfig: PlasmicConfig, baseDir: string): Promise<void>;
339
+ export declare function writeConfig(configFile: string, config: PlasmicConfig): Promise<void>;
340
+ export declare function writeLock(lockFile: string, lock: PlasmicLock): Promise<void>;
341
+ export declare function updateConfig(context: PlasmicContext, newConfig: PlasmicConfig): Promise<void>;
342
342
  export declare function getOrAddProjectConfig(context: PlasmicContext, projectId: string, base?: ProjectConfig): ProjectConfig;
343
343
  export declare function getOrAddProjectLock(context: PlasmicContext, projectId: string, branchName: string, base?: ProjectLock): ProjectLock;
344
344
  export declare function isPageAwarePlatform(platform: string): boolean;
@@ -1,6 +1,6 @@
1
1
  export declare function detectTypescript(): string | null;
2
2
  export declare function detectNextJs(): boolean;
3
- export declare function detectNextJsAppDir(): any;
3
+ export declare function detectNextJsAppDir(): boolean;
4
4
  export declare function detectGatsby(): string | null;
5
5
  export declare function detectCreateReactApp(): boolean;
6
6
  export declare function detectTanStackApp(): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.353",
3
+ "version": "0.1.355",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -82,5 +82,5 @@
82
82
  "wrap-ansi": "^7.0.0",
83
83
  "yargs": "^15.4.1"
84
84
  },
85
- "gitHead": "dd6c2185b54eaf9af4c74118575c4e912486a5ae"
85
+ "gitHead": "8afb52a3ecc24be9eb5f5170264b1e8473310898"
86
86
  }
@@ -268,7 +268,7 @@ export const CodeSandboxDialogContent = observer(
268
268
  CodeSandboxDialogContentProps
269
269
  >
270
270
  );`;
271
- expect((await formatScript(tsxToJsx(code), process.cwd())).trim()).toEqual(
271
+ expect((await formatScript(tsxToJsx(code))).trim()).toEqual(
272
272
  `
273
273
  // This is a skeleton starter React component generated by Plasmic.
274
274
  // @jsx helper
@@ -541,8 +541,7 @@ function _CodeSandboxDialogContent(props) {
541
541
  code,
542
542
  "/tmp/CodeSandbox.tsx",
543
543
  fixImportContext,
544
- false,
545
- process.cwd()
544
+ false
546
545
  );
547
546
  const expectedCode = `// This is a skeleton starter React component generated by Plasmic.
548
547
  import React, { ReactNode } from "react";
@@ -620,8 +619,7 @@ function _CodeSandboxDialogContent(props) {
620
619
  code,
621
620
  "/tmp/CodeSandbox.tsx",
622
621
  fixImportContext,
623
- true,
624
- process.cwd()
622
+ true
625
623
  );
626
624
  const expectedCode = `// This is a skeleton starter React component generated by Plasmic.
627
625
  import React, { ReactNode } from "react";
@@ -700,8 +698,7 @@ function _CodeSandboxDialogContent(props) {
700
698
  code,
701
699
  "/tmp/CodeSandbox.tsx",
702
700
  fixImportContext,
703
- false,
704
- process.cwd()
701
+ false
705
702
  );
706
703
  const expectedCode = `// This is a skeleton starter React component generated by Plasmic.
707
704
  import React, { ReactNode } from "react";
@@ -815,7 +812,7 @@ export default PlasmicButton;
815
812
  // This class is auto-generated by Plasmic; please do not edit!
816
813
  // Plasmic Project: aBwbYpvCqht4V3F8CJNJX3
817
814
  // Component: 4SYnkOQLd5
818
- import React from \"react\";
815
+ import React from "react";
819
816
  import { createPlasmicElementProxy } from "@plasmicapp/react-web";
820
817
  import "@plasmicapp/react-web/lib/plasmic.css";
821
818
  import "../plasmic__default_style.css"; // plasmic-import: global/defaultcss
@@ -854,7 +851,7 @@ export default PlasmicButton;
854
851
  {"2" : "2}]
855
852
  */
856
853
  `;
857
- expect(await formatScript(input, process.cwd())).toEqual(
854
+ expect(await formatScript(input)).toEqual(
858
855
  `import React, { ReactNode } from "react";
859
856
  import "@plasmicapp/react-web/lib/plasmic.css";
860
857
 
@@ -0,0 +1,115 @@
1
+ /* eslint-disable no-restricted-properties */
2
+ /* eslint-disable no-restricted-syntax */
3
+ import fs from "fs";
4
+ import os from "os";
5
+ import path from "path";
6
+ import { detectNextJsAppDir } from "../utils/envdetect";
7
+
8
+ describe("detectNextJsAppDir", () => {
9
+ let tempDir: string;
10
+ let originalCwd: string;
11
+
12
+ beforeEach(() => {
13
+ originalCwd = process.cwd();
14
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "envdetect-test-"));
15
+ console.log("Added temp dir at ", tempDir);
16
+ process.chdir(tempDir);
17
+ });
18
+
19
+ afterEach(() => {
20
+ process.chdir(originalCwd);
21
+ fs.rmSync(tempDir, { recursive: true, force: true });
22
+ });
23
+
24
+ it("returns false when not a Next.js project", () => {
25
+ // Empty directory, no next.config.js
26
+ expect(detectNextJsAppDir()).toBe(false);
27
+ });
28
+
29
+ it("returns true with experimental appDir flag", () => {
30
+ fs.writeFileSync(
31
+ path.join(tempDir, "next.config.js"),
32
+ "module.exports = { experimental: { appDir: true } };"
33
+ );
34
+ fs.mkdirSync(path.join(tempDir, "app"));
35
+ fs.writeFileSync(path.join(tempDir, "app/page.tsx"), "");
36
+
37
+ expect(detectNextJsAppDir()).toBe(true);
38
+ });
39
+
40
+ it("returns false with pages router only", () => {
41
+ fs.writeFileSync(
42
+ path.join(tempDir, "next.config.js"),
43
+ "module.exports = {};"
44
+ );
45
+ fs.mkdirSync(path.join(tempDir, "pages"));
46
+ fs.writeFileSync(path.join(tempDir, "pages/index.tsx"), "");
47
+
48
+ expect(detectNextJsAppDir()).toBe(false);
49
+ });
50
+
51
+ it("returns false with pages router only", () => {
52
+ fs.writeFileSync(
53
+ path.join(tempDir, "next.config.js"),
54
+ "module.exports = {};"
55
+ );
56
+ fs.mkdirSync(path.join(tempDir, "pages"));
57
+ fs.writeFileSync(path.join(tempDir, "pages/index.tsx"), "");
58
+
59
+ expect(detectNextJsAppDir()).toBe(false);
60
+ });
61
+
62
+ it("returns true with app router only", () => {
63
+ fs.writeFileSync(
64
+ path.join(tempDir, "next.config.js"),
65
+ "module.exports = {};"
66
+ );
67
+ fs.mkdirSync(path.join(tempDir, "app"));
68
+ fs.writeFileSync(path.join(tempDir, "app/page.tsx"), "");
69
+
70
+ expect(detectNextJsAppDir()).toBe(true);
71
+ });
72
+
73
+ describe("app + pages router", () => {
74
+ function setupHybridRouterDir(nextVersion: string) {
75
+ fs.writeFileSync(
76
+ path.join(tempDir, "next.config.js"),
77
+ "module.exports = {};"
78
+ );
79
+
80
+ // Create package.json with Next.js version
81
+ fs.writeFileSync(
82
+ path.join(tempDir, "package.json"),
83
+ JSON.stringify({
84
+ dependencies: { next: nextVersion },
85
+ })
86
+ );
87
+
88
+ // Create both app and pages directories
89
+ fs.mkdirSync(path.join(tempDir, "app"));
90
+ fs.writeFileSync(path.join(tempDir, "app/page.tsx"), "");
91
+ fs.mkdirSync(path.join(tempDir, "pages"));
92
+ fs.writeFileSync(path.join(tempDir, "pages/index.tsx"), "");
93
+ }
94
+
95
+ it("returns true when Next.js > 13.4.0 with hybrid routing", () => {
96
+ setupHybridRouterDir("^14.0.0");
97
+ expect(detectNextJsAppDir()).toBe(true);
98
+ });
99
+
100
+ it("returns false when Next.js < 13.4.0 with hybrid routing", () => {
101
+ setupHybridRouterDir("^12.0.0");
102
+ expect(detectNextJsAppDir()).toBe(false);
103
+ });
104
+
105
+ it("returns true when Next.js === 13.4.0 with hybrid routing", () => {
106
+ setupHybridRouterDir("13.4.0");
107
+ expect(detectNextJsAppDir()).toBe(true);
108
+ });
109
+
110
+ it("should handle prerelease versions like 14.0.0-canary.1", () => {
111
+ setupHybridRouterDir("14.0.0-canary.1");
112
+ expect(detectNextJsAppDir()).toBe(true);
113
+ });
114
+ });
115
+ });
@@ -99,7 +99,7 @@ export async function exportProjectsCli(opts: ExportArgs): Promise<void> {
99
99
  const outPath = path.resolve(opts.outDir);
100
100
  const writeFile = async (fileName: string, content: string | Buffer) => {
101
101
  if (typeof content === "string" && !opts.skipFormatting) {
102
- content = await formatAsLocal(content, fileName, opts.outDir);
102
+ content = await formatAsLocal(content, fileName);
103
103
  }
104
104
  const projectName = snakeCase(bundle.projectConfig.projectName);
105
105
  await fs.mkdir(path.join(outPath, projectName), { recursive: true });
@@ -161,116 +161,113 @@ export async function exportProjectsCli(opts: ExportArgs): Promise<void> {
161
161
 
162
162
  await Promise.all(result.map((res) => writeProj(res)));
163
163
 
164
- await fixAllImportStatements(
165
- {
166
- configFile: "",
167
- lockFile: "",
168
- rootDir: path.resolve(opts.outDir),
169
- absoluteSrcDir: path.resolve(opts.outDir),
170
- config: {
171
- platform: opts.platform || "react",
172
- srcDir: "./",
173
- defaultPlasmicDir: "./",
174
- preserveJsImportExtensions: false,
175
- code: {
176
- lang: opts.codeLang || "ts",
177
- scheme: "blackbox",
178
- reactRuntime: "classic",
179
- },
180
- images: {
181
- scheme: opts.imagesScheme || "files",
182
- },
183
- style: {
184
- scheme: opts.styleScheme || "css-modules",
185
- defaultStyleCssFilePath: "",
186
- },
187
- tokens: {} as any,
188
- globalVariants: {
189
- variantGroups: result.flatMap((bundle) => {
190
- const projectName = snakeCase(bundle.projectConfig.projectName);
191
- return bundle.globalVariants.map((gv) => ({
192
- id: gv.id,
193
- name: gv.name,
194
- projectId: bundle.projectConfig.projectId,
195
- contextFilePath: `./${projectName}/${gv.contextFileName}`,
196
- }));
197
- }),
198
- },
199
- projects: result.map((bundle) => {
164
+ await fixAllImportStatements({
165
+ configFile: "",
166
+ lockFile: "",
167
+ rootDir: path.resolve(opts.outDir),
168
+ absoluteSrcDir: path.resolve(opts.outDir),
169
+ config: {
170
+ platform: opts.platform || "react",
171
+ srcDir: "./",
172
+ defaultPlasmicDir: "./",
173
+ preserveJsImportExtensions: false,
174
+ code: {
175
+ lang: opts.codeLang || "ts",
176
+ scheme: "blackbox",
177
+ reactRuntime: "classic",
178
+ },
179
+ images: {
180
+ scheme: opts.imagesScheme || "files",
181
+ },
182
+ style: {
183
+ scheme: opts.styleScheme || "css-modules",
184
+ defaultStyleCssFilePath: "",
185
+ },
186
+ tokens: {} as any,
187
+ globalVariants: {
188
+ variantGroups: result.flatMap((bundle) => {
200
189
  const projectName = snakeCase(bundle.projectConfig.projectName);
201
- return {
190
+ return bundle.globalVariants.map((gv) => ({
191
+ id: gv.id,
192
+ name: gv.name,
202
193
  projectId: bundle.projectConfig.projectId,
203
- projectName: bundle.projectConfig.projectName,
204
- version: "latest",
205
- cssFilePath: `${projectName}/${bundle.projectConfig.cssFileName}`,
206
- globalContextsFilePath: bundle.projectConfig.globalContextBundle
207
- ? `${projectName}/${DEFAULT_GLOBAL_CONTEXTS_NAME}.${extx}`
208
- : "",
209
- splitsProviderFilePath: bundle.projectConfig.splitsProviderBundle
210
- ? `${projectName}/${DEFAULT_SPLITS_PROVIDER_NAME}.${extx}`
211
- : "",
212
- styleTokensProviderFilePath: bundle.projectConfig
213
- .styleTokensProviderBundle
214
- ? `${projectName}/${DEFAULT_STYLE_TOKENS_PROVIDER_NAME}.${extx}`
215
- : "",
216
- dataTokensFilePath: bundle.projectConfig.dataTokensBundle
217
- ? `${projectName}/${DEFAULT_DATA_TOKENS_NAME}.${opts.codeLang}`
218
- : "",
219
- projectModuleFilePath: bundle.projectConfig.projectModuleBundle
220
- ? `${projectName}/${DEFAULT_PROJECT_MODULE_NAME}.${extx}`
221
- : "",
222
- components: bundle.components.map((comp) => ({
223
- id: comp.id,
224
- name: comp.componentName,
225
- projectId: bundle.projectConfig.projectId,
226
- type: "managed",
227
- importSpec: {
228
- modulePath: `${projectName}/${comp.skeletonModuleFileName}`,
229
- },
230
- renderModuleFilePath: `${projectName}/${comp.skeletonModuleFileName}`,
231
- cssFilePath: `${projectName}/${comp.cssFileName}`,
232
- scheme: "blackbox",
233
- componentType: `${comp.isPage ? "page" : "component"}`,
234
- plumeType: comp.plumeType,
235
- })),
236
- codeComponents: bundle.codeComponentMetas.map((comp) => ({
237
- id: comp.id,
238
- name: comp.name,
239
- displayName: comp.displayName,
240
- componentImportPath: comp.importPath,
241
- helper: comp.helper,
242
- })),
243
- customFunctionMetas: (bundle.customFunctionMetas ?? []).map(
244
- (meta) => ({
245
- id: meta.id,
246
- name: meta.name,
247
- importPath: meta.importPath,
248
- defaultExport: meta.defaultExport,
249
- namespace: meta.namespace ?? null,
250
- })
251
- ),
252
- icons: bundle.iconAssets.map((icon) => ({
253
- id: icon.id,
254
- name: icon.name,
255
- moduleFilePath: `${projectName}/${icon.fileName}`,
256
- })),
257
- images: bundle.imageAssets.map((image) => ({
258
- id: image.id,
259
- name: image.name,
260
- filePath: `${projectName}/${image.fileName}`,
261
- })),
262
- indirect: false,
263
- };
194
+ contextFilePath: `./${projectName}/${gv.contextFileName}`,
195
+ }));
264
196
  }),
265
- wrapPagesWithGlobalContexts: true,
266
197
  },
267
- lock: {} as any,
268
- auth: {} as any,
269
- api: api,
270
- cliArgs: {} as any,
198
+ projects: result.map((bundle) => {
199
+ const projectName = snakeCase(bundle.projectConfig.projectName);
200
+ return {
201
+ projectId: bundle.projectConfig.projectId,
202
+ projectName: bundle.projectConfig.projectName,
203
+ version: "latest",
204
+ cssFilePath: `${projectName}/${bundle.projectConfig.cssFileName}`,
205
+ globalContextsFilePath: bundle.projectConfig.globalContextBundle
206
+ ? `${projectName}/${DEFAULT_GLOBAL_CONTEXTS_NAME}.${extx}`
207
+ : "",
208
+ splitsProviderFilePath: bundle.projectConfig.splitsProviderBundle
209
+ ? `${projectName}/${DEFAULT_SPLITS_PROVIDER_NAME}.${extx}`
210
+ : "",
211
+ styleTokensProviderFilePath: bundle.projectConfig
212
+ .styleTokensProviderBundle
213
+ ? `${projectName}/${DEFAULT_STYLE_TOKENS_PROVIDER_NAME}.${extx}`
214
+ : "",
215
+ dataTokensFilePath: bundle.projectConfig.dataTokensBundle
216
+ ? `${projectName}/${DEFAULT_DATA_TOKENS_NAME}.${opts.codeLang}`
217
+ : "",
218
+ projectModuleFilePath: bundle.projectConfig.projectModuleBundle
219
+ ? `${projectName}/${DEFAULT_PROJECT_MODULE_NAME}.${extx}`
220
+ : "",
221
+ components: bundle.components.map((comp) => ({
222
+ id: comp.id,
223
+ name: comp.componentName,
224
+ projectId: bundle.projectConfig.projectId,
225
+ type: "managed",
226
+ importSpec: {
227
+ modulePath: `${projectName}/${comp.skeletonModuleFileName}`,
228
+ },
229
+ renderModuleFilePath: `${projectName}/${comp.skeletonModuleFileName}`,
230
+ cssFilePath: `${projectName}/${comp.cssFileName}`,
231
+ scheme: "blackbox",
232
+ componentType: `${comp.isPage ? "page" : "component"}`,
233
+ plumeType: comp.plumeType,
234
+ })),
235
+ codeComponents: bundle.codeComponentMetas.map((comp) => ({
236
+ id: comp.id,
237
+ name: comp.name,
238
+ displayName: comp.displayName,
239
+ componentImportPath: comp.importPath,
240
+ helper: comp.helper,
241
+ })),
242
+ customFunctionMetas: (bundle.customFunctionMetas ?? []).map(
243
+ (meta) => ({
244
+ id: meta.id,
245
+ name: meta.name,
246
+ importPath: meta.importPath,
247
+ defaultExport: meta.defaultExport,
248
+ namespace: meta.namespace ?? null,
249
+ })
250
+ ),
251
+ icons: bundle.iconAssets.map((icon) => ({
252
+ id: icon.id,
253
+ name: icon.name,
254
+ moduleFilePath: `${projectName}/${icon.fileName}`,
255
+ })),
256
+ images: bundle.imageAssets.map((image) => ({
257
+ id: image.id,
258
+ name: image.name,
259
+ filePath: `${projectName}/${image.fileName}`,
260
+ })),
261
+ indirect: false,
262
+ };
263
+ }),
264
+ wrapPagesWithGlobalContexts: true,
271
265
  },
272
- opts.outDir
273
- );
266
+ lock: {} as any,
267
+ auth: {} as any,
268
+ api: api,
269
+ cliArgs: {} as any,
270
+ });
274
271
  }
275
272
 
276
273
  interface ExportOpts {
@@ -340,53 +337,46 @@ async function exportProjects(api: PlasmicApi, opts: ExportOpts) {
340
337
  [comp.skeletonModuleFileName, comp.skeletonModule] =
341
338
  await maybeConvertTsxToJsx(
342
339
  comp.skeletonModuleFileName,
343
- comp.skeletonModule,
344
- "."
340
+ comp.skeletonModule
345
341
  );
346
342
  }
347
343
  for (const icon of proj.iconAssets) {
348
344
  [icon.fileName, icon.module] = await maybeConvertTsxToJsx(
349
345
  icon.fileName,
350
- icon.module,
351
- "."
346
+ icon.module
352
347
  );
353
348
  }
354
349
  for (const gv of proj.globalVariants) {
355
350
  [gv.contextFileName, gv.contextModule] = await maybeConvertTsxToJsx(
356
351
  gv.contextFileName,
357
- gv.contextModule,
358
- "."
352
+ gv.contextModule
359
353
  );
360
354
  }
361
355
  if (proj.projectConfig.globalContextBundle) {
362
356
  const res = await maybeConvertTsxToJsx(
363
357
  `${DEFAULT_GLOBAL_CONTEXTS_NAME}.tsx`,
364
- proj.projectConfig.globalContextBundle.contextModule,
365
- "."
358
+ proj.projectConfig.globalContextBundle.contextModule
366
359
  );
367
360
  proj.projectConfig.globalContextBundle.contextModule = res[1];
368
361
  }
369
362
  if (proj.projectConfig.splitsProviderBundle) {
370
363
  const res = await maybeConvertTsxToJsx(
371
364
  `${DEFAULT_SPLITS_PROVIDER_NAME}.tsx`,
372
- proj.projectConfig.splitsProviderBundle.module,
373
- "."
365
+ proj.projectConfig.splitsProviderBundle.module
374
366
  );
375
367
  proj.projectConfig.splitsProviderBundle.module = res[1];
376
368
  }
377
369
  if (proj.projectConfig.styleTokensProviderBundle) {
378
370
  const res = await maybeConvertTsxToJsx(
379
371
  `${DEFAULT_STYLE_TOKENS_PROVIDER_NAME}.tsx`,
380
- proj.projectConfig.styleTokensProviderBundle.module,
381
- "."
372
+ proj.projectConfig.styleTokensProviderBundle.module
382
373
  );
383
374
  proj.projectConfig.styleTokensProviderBundle.module = res[1];
384
375
  }
385
376
  if (proj.projectConfig.projectModuleBundle) {
386
377
  const res = await maybeConvertTsxToJsx(
387
378
  `${DEFAULT_PROJECT_MODULE_NAME}.tsx`,
388
- proj.projectConfig.projectModuleBundle.module,
389
- "."
379
+ proj.projectConfig.projectModuleBundle.module
390
380
  );
391
381
  proj.projectConfig.projectModuleBundle.module = res[1];
392
382
  }
@@ -8,11 +8,13 @@ export interface FixImportsArgs extends CommonArgs {
8
8
  skipFormatting?: boolean;
9
9
  }
10
10
  export async function fixImports(opts: FixImportsArgs) {
11
- if (!opts.baseDir) opts.baseDir = process.cwd();
11
+ if (!opts.baseDir) {
12
+ opts.baseDir = process.cwd();
13
+ }
12
14
  if (opts.skipFormatting) {
13
15
  GLOBAL_SETTINGS.skipFormatting = true;
14
16
  }
15
17
  const context = await getContext(opts, { enableSkipAuth: true });
16
- await updateConfig(context, context.config, opts.baseDir);
17
- await fixAllImportStatements(context, opts.baseDir);
18
+ await updateConfig(context, context.config);
19
+ await fixAllImportStatements(context);
18
20
  }
@@ -51,7 +51,9 @@ export interface InitArgs extends CommonArgs {
51
51
  export async function initPlasmic(
52
52
  opts: InitArgs & { enableSkipAuth?: boolean }
53
53
  ) {
54
- if (!opts.baseDir) opts.baseDir = process.cwd();
54
+ if (!opts.baseDir) {
55
+ opts.baseDir = process.cwd();
56
+ }
55
57
  await getOrStartAuth(opts);
56
58
 
57
59
  const configFile =
@@ -69,7 +71,7 @@ export async function initPlasmic(
69
71
 
70
72
  const answers = await deriveInitAnswers(opts);
71
73
  const initConfig = createInitConfig(answers);
72
- await writeConfig(newConfigFile, initConfig, opts.baseDir);
74
+ await writeConfig(newConfigFile, initConfig);
73
75
 
74
76
  if (!process.env.QUIET) {
75
77
  logger.info("Successfully created plasmic.json.\n");
@@ -169,7 +171,7 @@ async function deriveInitAnswers(
169
171
  ) {
170
172
  const plasmicRootDir = opts.config ? path.dirname(opts.config) : opts.baseDir;
171
173
 
172
- const platform = !!opts.platform
174
+ const platform = opts.platform
173
175
  ? opts.platform
174
176
  : detectNextJs()
175
177
  ? "nextjs"
@@ -267,7 +269,6 @@ async function deriveInitAnswers(
267
269
  pagesDir: getDefaultAnswer("pagesDir", undefined) as any,
268
270
  reactRuntime: getDefaultAnswer("reactRuntime", "classic") as any,
269
271
  };
270
- const prominentAnswers = L.omit(answers, "codeScheme");
271
272
 
272
273
  if (process.env.QUIET) {
273
274
  return answers;
@@ -32,8 +32,7 @@ export async function syncProjectComponents(
32
32
  forceOverwrite: boolean,
33
33
  summary: Map<string, ComponentUpdateSummary>,
34
34
  projectLock: ProjectLock,
35
- checksums: ChecksumBundle,
36
- baseDir: string
35
+ checksums: ChecksumBundle
37
36
  ) {
38
37
  const componentsFromChecksums = new Set([
39
38
  ...checksums.cssRulesChecksums.map(([id, _]) => id),
@@ -107,7 +106,6 @@ export async function syncProjectComponents(
107
106
  componentName,
108
107
  id,
109
108
  scheme,
110
- nameInIdToUuid,
111
109
  isPage,
112
110
  path: pagePath,
113
111
  plumeType,
@@ -163,7 +161,6 @@ export async function syncProjectComponents(
163
161
  await writeFileContent(context, skeletonPath, skeletonModule, {
164
162
  force: false,
165
163
  });
166
- } else if (compConfig.type === "mapped") {
167
164
  } else if (compConfig.type === "managed") {
168
165
  // This is an existing component.
169
166
  // We only bother touching files on disk if this component is managed.
@@ -312,8 +309,7 @@ export async function syncProjectComponents(
312
309
  );
313
310
  const formattedCssRules = await formatAsLocal(
314
311
  cssRules,
315
- compConfig.cssFilePath,
316
- baseDir
312
+ compConfig.cssFilePath
317
313
  );
318
314
  await writeFileContent(
319
315
  context,
@@ -22,8 +22,7 @@ export async function syncDataTokens(
22
22
  projectMeta: ProjectMetaBundle,
23
23
  projectConfig: ProjectConfig,
24
24
  projectLock: ProjectLock,
25
- checksums: ChecksumBundle,
26
- baseDir: string
25
+ checksums: ChecksumBundle
27
26
  ) {
28
27
  const resourcePath = getDataTokensResourcePath(context, projectConfig);
29
28
  if (checksums.dataTokensChecksum && projectMeta.dataTokensBundle) {
@@ -34,8 +33,7 @@ export async function syncDataTokens(
34
33
  }
35
34
  if (context.config.code.lang === "js") {
36
35
  projectMeta.dataTokensBundle.module = await formatScript(
37
- tsxToJsx(projectMeta.dataTokensBundle.module),
38
- baseDir
36
+ tsxToJsx(projectMeta.dataTokensBundle.module)
39
37
  );
40
38
  }
41
39
  writeFileContent(
@@ -59,13 +57,10 @@ export async function syncDataTokens(
59
57
  });
60
58
  }
61
59
  } else if (!checksums.dataTokensChecksum && !projectMeta.dataTokensBundle) {
62
- // Only try to delete if there was a previously configured path
63
- if (projectConfig.dataTokensFilePath) {
64
- if (fileExists(context, projectConfig.dataTokensFilePath)) {
65
- deleteFile(context, projectConfig.dataTokensFilePath);
66
- }
67
- projectConfig.dataTokensFilePath = "";
60
+ if (fileExists(context, resourcePath)) {
61
+ deleteFile(context, resourcePath);
68
62
  }
63
+ projectConfig.dataTokensFilePath = "";
69
64
  L.remove(
70
65
  projectLock.fileLocks,
71
66
  (fl) => fl.assetId === projectConfig.projectId && fl.type === "dataTokens"