@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,4 +1,5 @@
1
1
  import findupSync from "findup-sync";
2
+ import semver from "semver";
2
3
  import { getParsedPackageJson } from "./npm-utils";
3
4
 
4
5
  export function detectTypescript() {
@@ -7,9 +8,13 @@ export function detectTypescript() {
7
8
 
8
9
  export function detectNextJs() {
9
10
  if (
10
- findupSync("next.config.js") ||
11
- findupSync(".next") ||
12
- findupSync("next-env.d.ts")
11
+ findupSync([
12
+ "next.config.js",
13
+ "next.config.ts",
14
+ "next.config.mjs",
15
+ ".next/",
16
+ "next-env.d.ts",
17
+ ])
13
18
  ) {
14
19
  return true;
15
20
  }
@@ -26,12 +31,44 @@ export function detectNextJs() {
26
31
  }
27
32
 
28
33
  export function detectNextJsAppDir() {
34
+ if (!detectNextJs()) {
35
+ return false;
36
+ }
37
+
29
38
  const nextConfigPath = findupSync("next.config.js");
30
- if (!nextConfigPath) {
39
+ // Legacy Next.js (<13.4): explicit opt-in
40
+ if (nextConfigPath && require(nextConfigPath)?.experimental?.appDir) {
41
+ return true;
42
+ }
43
+
44
+ if (!findupSync("app")) {
45
+ return false;
46
+ }
47
+
48
+ if (!findupSync("pages")) {
49
+ return true;
50
+ }
51
+
52
+ // Both app/ and pages/ exist - need to check Next.js version
53
+ try {
54
+ const packageJson = getParsedPackageJson();
55
+ const nextVersion: string | undefined = packageJson.dependencies?.next;
56
+ if (nextVersion) {
57
+ if (nextVersion === "latest") {
58
+ return true;
59
+ }
60
+ const coercedVersion = semver.coerce(nextVersion);
61
+ // For Next.js >= 13.4, app dir is the default
62
+ if (coercedVersion && semver.gte(coercedVersion, "13.4.0")) {
63
+ return true;
64
+ }
65
+ }
66
+ } catch {
67
+ // Can't read package.json - can't determine if App Router is enabled
31
68
  return false;
32
69
  }
33
70
 
34
- return require(nextConfigPath)?.experimental?.appDir || false;
71
+ return false;
35
72
  }
36
73
 
37
74
  export function detectGatsby() {
@@ -1,4 +1,5 @@
1
1
  import { ComponentBundle } from "../api";
2
+ import { maybeConvertTsxToJsx } from "./code-utils";
2
3
  import { ComponentConfig, PlasmicContext, ProjectConfig } from "./config-utils";
3
4
  import { defaultResourcePath, writeFileContent } from "./file-utils";
4
5
 
@@ -20,33 +21,49 @@ export async function syncRscFiles(
20
21
  };
21
22
  }
22
23
 
23
- const serverModuleFilePath = defaultResourcePath(
24
+ let serverModuleFilePath = defaultResourcePath(
24
25
  context,
25
26
  project,
26
27
  rscMetadata.pageWrappers.server.fileName
27
28
  );
29
+ let serverModuleContent = rscMetadata.pageWrappers.server.module;
30
+
31
+ if (context.config.code.lang === "js") {
32
+ const [convertedFileName, convertedContent] = await maybeConvertTsxToJsx(
33
+ serverModuleFilePath,
34
+ serverModuleContent
35
+ );
36
+ serverModuleFilePath = convertedFileName;
37
+ serverModuleContent = convertedContent;
38
+ }
28
39
  compConfig.rsc.serverModulePath = serverModuleFilePath;
29
40
 
30
- await writeFileContent(
31
- context,
32
- serverModuleFilePath,
33
- rscMetadata.pageWrappers.server.module,
34
- {
35
- force: true,
36
- }
37
- );
41
+ await writeFileContent(context, serverModuleFilePath, serverModuleContent, {
42
+ force: true,
43
+ });
38
44
 
39
- const clientModuleFilePath = compConfig.importSpec.modulePath.replace(
40
- /\.tsx$/,
45
+ let clientModuleFilePath = compConfig.importSpec.modulePath.replace(
46
+ /\.(tsx|jsx)$/,
41
47
  "-client.tsx"
42
48
  );
49
+ let clientModuleContent = rscMetadata.pageWrappers.client.module;
50
+
51
+ if (context.config.code.lang === "js") {
52
+ const [convertedFileName, convertedContent] = await maybeConvertTsxToJsx(
53
+ clientModuleFilePath,
54
+ clientModuleContent
55
+ );
56
+ clientModuleFilePath = convertedFileName;
57
+ clientModuleContent = convertedContent;
58
+ }
59
+
43
60
  compConfig.rsc.clientModulePath = clientModuleFilePath;
44
61
 
45
62
  if (opts.shouldRegenerate) {
46
63
  await writeFileContent(
47
64
  context,
48
65
  clientModuleFilePath,
49
- rscMetadata.pageWrappers.client.module,
66
+ clientModuleContent,
50
67
  {
51
68
  force: false,
52
69
  }