@plasmicapp/cli 0.1.336 → 0.1.338

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.
@@ -46,3 +46,12 @@ export function detectCreateReactApp() {
46
46
  return false;
47
47
  }
48
48
  }
49
+
50
+ export function detectTanStackApp() {
51
+ try {
52
+ const packageJsonContent = getParsedPackageJson();
53
+ return "@tanstack/react-router" in packageJsonContent.dependencies;
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
@@ -81,7 +81,10 @@ const EXT_REGEXP = /\.(jsx|tsx)$/;
81
81
 
82
82
  export function defaultPagePath(
83
83
  context: {
84
- config: Pick<PlasmicConfig, "platform" | "gatsbyConfig" | "nextjsConfig">;
84
+ config: Pick<
85
+ PlasmicConfig,
86
+ "platform" | "gatsbyConfig" | "nextjsConfig" | "tanstackConfig"
87
+ >;
85
88
  },
86
89
  fileName: string
87
90
  ) {
@@ -106,6 +109,20 @@ export function defaultPagePath(
106
109
  }
107
110
  } else if (context.config.platform === "gatsby") {
108
111
  return path.join(context.config.gatsbyConfig?.pagesDir || "", fileName);
112
+ } else if (context.config.platform === "tanstack") {
113
+ // use $ for dynamic paths, convert "/posts/[postId]" to "/posts/$postId"
114
+ let renamedFileName = fileName.replace(/\[(\w+)\]/g, "$$$1");
115
+
116
+ const matchesIndex = fileName.match(INDEX_EXT_REGEXP);
117
+ if (!matchesIndex) {
118
+ // convert "/foo/bar.tsx" to "/foo/bar/index.tsx"
119
+ renamedFileName = renamedFileName.replace(EXT_REGEXP, "/index.$1");
120
+ }
121
+
122
+ return path.join(
123
+ context.config.tanstackConfig?.pagesDir || "",
124
+ renamedFileName
125
+ );
109
126
  } else {
110
127
  return fileName;
111
128
  }
@@ -351,6 +368,9 @@ function getAllPaths(context: PlasmicContext): BundleKeyPair[] {
351
368
  if (config.nextjsConfig) {
352
369
  pushPath(config.nextjsConfig, "pagesDir");
353
370
  }
371
+ if (config.tanstackConfig) {
372
+ pushPath(config.tanstackConfig, "pagesDir");
373
+ }
354
374
 
355
375
  return pairs;
356
376
  }
@@ -463,11 +483,18 @@ export function readFileText(path: string): string {
463
483
  case "create":
464
484
  return ensureString(action.content);
465
485
  case "rename":
466
- return readFileText(action.newPath);
486
+ // eslint-disable-next-line no-restricted-properties
487
+ return fs.readFileSync(path, "utf8");
467
488
  case "delete":
468
489
  throw new HandledError("File does not exists");
469
490
  }
470
491
  }
492
+ // If we are buffering files and the file has been renamed, only the old file path
493
+ // exists in disk, so we need to read the content from the old file path.
494
+ const renamedFilePath = renamedFiles.get(path);
495
+ if (renamedFilePath) {
496
+ return readFileText(renamedFilePath);
497
+ }
471
498
  }
472
499
 
473
500
  // eslint-disable-next-line no-restricted-properties
@@ -503,7 +530,6 @@ export function renameFileBuffered(oldPath: string, newPath: string) {
503
530
  if (renamedFile !== undefined) {
504
531
  oldPath = renamedFile;
505
532
  }
506
-
507
533
  buffer.set(oldPath, { type: "rename", newPath });
508
534
  renamedFiles.set(newPath, oldPath);
509
535
  } else {
@@ -6,7 +6,10 @@ export async function syncRscFiles(
6
6
  context: PlasmicContext,
7
7
  project: ProjectConfig,
8
8
  bundle: ComponentBundle,
9
- compConfig: ComponentConfig
9
+ compConfig: ComponentConfig,
10
+ opts: {
11
+ shouldRegenerate: boolean;
12
+ }
10
13
  ) {
11
14
  const rscMetadata = bundle.rscMetadata;
12
15
  if (rscMetadata) {
@@ -39,13 +42,15 @@ export async function syncRscFiles(
39
42
  );
40
43
  compConfig.rsc.clientModulePath = clientModuleFilePath;
41
44
 
42
- await writeFileContent(
43
- context,
44
- clientModuleFilePath,
45
- rscMetadata.pageWrappers.client.module,
46
- {
47
- force: false,
48
- }
49
- );
45
+ if (opts.shouldRegenerate) {
46
+ await writeFileContent(
47
+ context,
48
+ clientModuleFilePath,
49
+ rscMetadata.pageWrappers.client.module,
50
+ {
51
+ force: false,
52
+ }
53
+ );
54
+ }
50
55
  }
51
56
  }