@plasmicapp/cli 0.1.232 → 0.1.234

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.
@@ -21,6 +21,12 @@ describe("defaultPagePath", () => {
21
21
  }, "/nested/index.tsx")).toBe("../pages/nested/index.tsx");
22
22
  });
23
23
  it("handles nextjs pagesDir", () => {
24
+ expect(file_utils_1.defaultPagePath({
25
+ config: {
26
+ platform: "nextjs",
27
+ nextjsConfig: { pagesDir: "../pages" },
28
+ },
29
+ }, "/index.jsx")).toBe("../pages/index.jsx");
24
30
  expect(file_utils_1.defaultPagePath({
25
31
  config: {
26
32
  platform: "nextjs",
@@ -35,6 +41,9 @@ describe("defaultPagePath", () => {
35
41
  }, "/nested/index.tsx")).toBe("../pages/nested/index.tsx");
36
42
  });
37
43
  it("handles nextjs pagesDir using app/ directory ", () => {
44
+ expect(file_utils_1.defaultPagePath({
45
+ config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
46
+ }, "/index.jsx")).toBe("../app/page.jsx");
38
47
  expect(file_utils_1.defaultPagePath({
39
48
  config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
40
49
  }, "/index.tsx")).toBe("../app/page.tsx");
@@ -57,17 +57,20 @@ function defaultPublicResourcePath(context, project, ...subpaths) {
57
57
  return upath_1.default.join(context.config.images.publicDir, "plasmic", lodash_1.default.snakeCase(project.projectName), ...subpaths);
58
58
  }
59
59
  exports.defaultPublicResourcePath = defaultPublicResourcePath;
60
+ const INDEX_EXT_REGEXP = /\/index\.(jsx|tsx)$/;
61
+ const EXT_REGEXP = /\.(jsx|tsx)$/;
60
62
  function defaultPagePath(context, fileName) {
61
63
  var _a, _b, _c, _d;
62
64
  if (context.config.platform === "nextjs") {
63
65
  if ((_b = (_a = context.config.nextjsConfig) === null || _a === void 0 ? void 0 : _a.pagesDir) === null || _b === void 0 ? void 0 : _b.endsWith("app")) {
64
- if (fileName.endsWith("/index.tsx")) {
66
+ const matchesIndex = fileName.match(INDEX_EXT_REGEXP);
67
+ if (matchesIndex) {
65
68
  // convert "/foo/index.tsx" to "/foo/page.tsx"
66
- return upath_1.default.join(context.config.nextjsConfig.pagesDir, fileName.replace(/\/index\.tsx$/, "/page.tsx"));
69
+ return upath_1.default.join(context.config.nextjsConfig.pagesDir, fileName.replace(INDEX_EXT_REGEXP, "/page.$1"));
67
70
  }
68
71
  else {
69
72
  // convert "/foo/bar.tsx" to "/foo/bar/page.tsx"
70
- return upath_1.default.join(context.config.nextjsConfig.pagesDir, fileName.replace(/\.tsx$/, "/page.tsx"));
73
+ return upath_1.default.join(context.config.nextjsConfig.pagesDir, fileName.replace(EXT_REGEXP, "/page.$1"));
71
74
  }
72
75
  }
73
76
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.232",
3
+ "version": "0.1.234",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/preset-typescript": "^7.12.1",
23
- "@plasmicapp/react-web": "0.2.175",
23
+ "@plasmicapp/react-web": "0.2.176",
24
24
  "@types/findup-sync": "^2.0.2",
25
25
  "@types/glob": "^7.1.3",
26
26
  "@types/inquirer": "^6.5.0",
@@ -77,5 +77,5 @@
77
77
  "wrap-ansi": "^7.0.0",
78
78
  "yargs": "^15.4.1"
79
79
  },
80
- "gitHead": "1d9e46447dea9fe47ae76c2e1a39e14dcab687e6"
80
+ "gitHead": "a1c72e430eeac84ef53622f2f7a4642e54657443"
81
81
  }
@@ -34,6 +34,17 @@ describe("defaultPagePath", () => {
34
34
  ).toBe("../pages/nested/index.tsx");
35
35
  });
36
36
  it("handles nextjs pagesDir", () => {
37
+ expect(
38
+ defaultPagePath(
39
+ {
40
+ config: {
41
+ platform: "nextjs",
42
+ nextjsConfig: { pagesDir: "../pages" },
43
+ },
44
+ },
45
+ "/index.jsx"
46
+ )
47
+ ).toBe("../pages/index.jsx");
37
48
  expect(
38
49
  defaultPagePath(
39
50
  {
@@ -58,6 +69,14 @@ describe("defaultPagePath", () => {
58
69
  ).toBe("../pages/nested/index.tsx");
59
70
  });
60
71
  it("handles nextjs pagesDir using app/ directory ", () => {
72
+ expect(
73
+ defaultPagePath(
74
+ {
75
+ config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
76
+ },
77
+ "/index.jsx"
78
+ )
79
+ ).toBe("../app/page.jsx");
61
80
  expect(
62
81
  defaultPagePath(
63
82
  {
@@ -78,6 +78,9 @@ export function defaultPublicResourcePath(
78
78
  );
79
79
  }
80
80
 
81
+ const INDEX_EXT_REGEXP = /\/index\.(jsx|tsx)$/;
82
+ const EXT_REGEXP = /\.(jsx|tsx)$/;
83
+
81
84
  export function defaultPagePath(
82
85
  context: {
83
86
  config: Pick<PlasmicConfig, "platform" | "gatsbyConfig" | "nextjsConfig">;
@@ -86,17 +89,18 @@ export function defaultPagePath(
86
89
  ) {
87
90
  if (context.config.platform === "nextjs") {
88
91
  if (context.config.nextjsConfig?.pagesDir?.endsWith("app")) {
89
- if (fileName.endsWith("/index.tsx")) {
92
+ const matchesIndex = fileName.match(INDEX_EXT_REGEXP);
93
+ if (matchesIndex) {
90
94
  // convert "/foo/index.tsx" to "/foo/page.tsx"
91
95
  return path.join(
92
96
  context.config.nextjsConfig.pagesDir,
93
- fileName.replace(/\/index\.tsx$/, "/page.tsx")
97
+ fileName.replace(INDEX_EXT_REGEXP, "/page.$1")
94
98
  );
95
99
  } else {
96
100
  // convert "/foo/bar.tsx" to "/foo/bar/page.tsx"
97
101
  return path.join(
98
102
  context.config.nextjsConfig.pagesDir,
99
- fileName.replace(/\.tsx$/, "/page.tsx")
103
+ fileName.replace(EXT_REGEXP, "/page.$1")
100
104
  );
101
105
  }
102
106
  } else {