@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.
- package/dist/__tests__/envdetect.spec.d.ts +1 -0
- package/dist/actions/sync-components.d.ts +1 -1
- package/dist/actions/sync-data-tokens.d.ts +1 -1
- package/dist/actions/sync-global-contexts.d.ts +1 -1
- package/dist/actions/sync-global-variants.d.ts +1 -1
- package/dist/actions/sync-icons.d.ts +1 -1
- package/dist/actions/sync-project-module.d.ts +1 -1
- package/dist/actions/sync-splits-provider.d.ts +1 -1
- package/dist/actions/sync-style-tokens-provider.d.ts +1 -1
- package/dist/index.js +248 -262
- package/dist/lib.js +248 -262
- package/dist/utils/code-utils.d.ts +6 -6
- package/dist/utils/config-utils.d.ts +3 -3
- package/dist/utils/envdetect.d.ts +1 -1
- package/package.json +2 -2
- package/src/__tests__/code-utils-spec.ts +6 -9
- package/src/__tests__/envdetect.spec.ts +115 -0
- package/src/actions/export.ts +110 -120
- package/src/actions/fix-imports.ts +5 -3
- package/src/actions/init.ts +5 -4
- package/src/actions/sync-components.ts +2 -6
- package/src/actions/sync-data-tokens.ts +5 -10
- package/src/actions/sync-global-contexts.ts +5 -6
- package/src/actions/sync-global-variants.ts +3 -8
- package/src/actions/sync-icons.ts +3 -4
- package/src/actions/sync-project-module.ts +5 -6
- package/src/actions/sync-splits-provider.ts +5 -6
- package/src/actions/sync-style-tokens-provider.ts +5 -7
- package/src/actions/sync.ts +15 -30
- package/src/migrations/migrations.ts +3 -3
- package/src/utils/code-utils.ts +15 -44
- package/src/utils/config-utils.ts +7 -21
- package/src/utils/envdetect.ts +42 -5
- package/src/utils/rsc-config.ts +29 -12
package/src/utils/envdetect.ts
CHANGED
|
@@ -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(
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
|
71
|
+
return false;
|
|
35
72
|
}
|
|
36
73
|
|
|
37
74
|
export function detectGatsby() {
|
package/src/utils/rsc-config.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
rscMetadata.pageWrappers.server.module,
|
|
34
|
-
{
|
|
35
|
-
force: true,
|
|
36
|
-
}
|
|
37
|
-
);
|
|
41
|
+
await writeFileContent(context, serverModuleFilePath, serverModuleContent, {
|
|
42
|
+
force: true,
|
|
43
|
+
});
|
|
38
44
|
|
|
39
|
-
|
|
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
|
-
|
|
66
|
+
clientModuleContent,
|
|
50
67
|
{
|
|
51
68
|
force: false,
|
|
52
69
|
}
|