create-plasmic-app 0.0.168 → 0.0.170

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 (86) hide show
  1. package/README.internal.md +6 -4
  2. package/README.md +23 -0
  3. package/cpa-out/gatsby-codegen-js/package.json +3 -2
  4. package/cpa-out/gatsby-codegen-js/plasmic.json +5 -8
  5. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicButton.jsx +12 -12
  6. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +18 -18
  7. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +12 -16
  8. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.jsx +1 -0
  9. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.jsx +2 -2
  10. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/{plasmic.module.css → plasmic.css} +89 -73
  11. package/cpa-out/gatsby-codegen-js/src/components/plasmic/{plasmic__default_style.module.css → plasmic__default_style.css} +16 -0
  12. package/cpa-out/gatsby-codegen-ts/package.json +3 -2
  13. package/cpa-out/gatsby-codegen-ts/plasmic.json +5 -8
  14. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.tsx +12 -12
  15. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +18 -18
  16. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +12 -16
  17. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +1 -1
  18. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.tsx +2 -2
  19. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/{plasmic.module.css → plasmic.css} +89 -73
  20. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/{plasmic__default_style.module.css → plasmic__default_style.css} +16 -0
  21. package/cpa-out/gatsby-loader-js/package.json +1 -1
  22. package/cpa-out/gatsby-loader-ts/package.json +1 -1
  23. package/cpa-out/nextjs-app-codegen-js/package.json +1 -0
  24. package/cpa-out/nextjs-app-codegen-js/plasmic.json +2 -1
  25. package/cpa-out/nextjs-app-codegen-ts/package.json +1 -0
  26. package/cpa-out/nextjs-app-codegen-ts/plasmic.json +2 -1
  27. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +2 -2
  28. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/plasmic.css +16 -0
  29. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/plasmic__default_style.css +16 -0
  30. package/cpa-out/nextjs-pages-codegen-js/package.json +7 -6
  31. package/cpa-out/nextjs-pages-codegen-js/plasmic.json +3 -6
  32. package/cpa-out/nextjs-pages-codegen-js/styles/Home.module.css +8 -0
  33. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +2 -2
  34. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/plasmic.css +16 -0
  35. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/plasmic__default_style.css +16 -0
  36. package/cpa-out/nextjs-pages-codegen-ts/package.json +7 -6
  37. package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +3 -6
  38. package/cpa-out/nextjs-pages-codegen-ts/styles/Home.module.css +8 -0
  39. package/cpa-out/nextjs-pages-loader-js/package.json +5 -5
  40. package/cpa-out/nextjs-pages-loader-js/styles/Home.module.css +8 -0
  41. package/cpa-out/nextjs-pages-loader-ts/package.json +5 -5
  42. package/cpa-out/nextjs-pages-loader-ts/styles/Home.module.css +8 -0
  43. package/cpa-out/react-codegen-js/package.json +3 -2
  44. package/cpa-out/react-codegen-js/plasmic.json +3 -6
  45. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +2 -2
  46. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/plasmic.css +16 -0
  47. package/cpa-out/react-codegen-js/src/components/plasmic/plasmic__default_style.css +16 -0
  48. package/cpa-out/react-codegen-ts/package.json +3 -2
  49. package/cpa-out/react-codegen-ts/plasmic.json +3 -6
  50. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +2 -2
  51. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.css +16 -0
  52. package/cpa-out/react-codegen-ts/src/components/plasmic/plasmic__default_style.css +16 -0
  53. package/cpa-out/tanstack-codegen-ts/package.json +8 -13
  54. package/cpa-out/tanstack-codegen-ts/plasmic.json +3 -6
  55. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +3 -3
  56. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/plasmic__default_style.css +16 -0
  57. package/cpa-out/tanstack-codegen-ts/src/routeTree.gen.ts +13 -13
  58. package/cpa-out/tanstack-codegen-ts/src/routes/dynamic/$slug/index.tsx +2 -2
  59. package/dist/gatsby/gatsby.js +23 -17
  60. package/dist/index.js +6 -0
  61. package/dist/lib.d.ts +2 -1
  62. package/dist/lib.js +9 -4
  63. package/dist/nextjs/nextjs.js +16 -6
  64. package/dist/react/react.js +9 -4
  65. package/dist/tanstack/tanstack.js +12 -5
  66. package/dist/utils/codegen.d.ts +3 -0
  67. package/dist/utils/codegen.js +17 -4
  68. package/dist/utils/file-utils.d.ts +2 -2
  69. package/dist/utils/file-utils.js +2 -1
  70. package/dist/utils/npm-utils.d.ts +24 -9
  71. package/dist/utils/npm-utils.js +66 -21
  72. package/dist/utils/strategy.d.ts +5 -1
  73. package/dist/utils/types.d.ts +1 -0
  74. package/package.json +2 -4
  75. package/run-cpa.ts +17 -6
  76. package/src/gatsby/gatsby.ts +40 -22
  77. package/src/index.ts +9 -0
  78. package/src/lib.ts +18 -6
  79. package/src/nextjs/nextjs.ts +39 -7
  80. package/src/react/react.ts +11 -4
  81. package/src/tanstack/tanstack.ts +19 -6
  82. package/src/utils/codegen.ts +28 -6
  83. package/src/utils/file-utils.ts +6 -2
  84. package/src/utils/npm-utils.ts +76 -23
  85. package/src/utils/strategy.ts +10 -1
  86. package/src/utils/types.ts +1 -0
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.detectPackageManager = exports.installUpgrade = exports.spawn = exports.checkEngineStrict = exports.updateNotify = void 0;
38
+ exports.initYarnBerryProject = exports.packageManagerExec = exports.packageManagerCommand = exports.resolvePackageManager = exports.installUpgrade = exports.spawn = exports.checkEngineStrict = exports.updateNotify = void 0;
39
39
  /*eslint
40
40
  @typescript-eslint/no-var-requires: 0,
41
41
  */
@@ -97,7 +97,7 @@ exports.spawn = spawn;
97
97
  * @param opts
98
98
  * @returns
99
99
  */
100
- function installUpgrade(pkg, opts = {}) {
100
+ function installUpgrade(pkg, opts) {
101
101
  return __awaiter(this, void 0, void 0, function* () {
102
102
  const cmd = installCommand(pkg, opts);
103
103
  const r = yield spawn(cmd, opts.workingDir);
@@ -118,8 +118,8 @@ exports.installUpgrade = installUpgrade;
118
118
  * @param opts
119
119
  * @returns
120
120
  */
121
- function installCommand(pkg, opts = {}) {
122
- const mgr = detectPackageManager(opts.workingDir);
121
+ function installCommand(pkg, opts) {
122
+ const mgr = opts.packageManager;
123
123
  if (mgr === "yarn") {
124
124
  if (opts.global) {
125
125
  return `yarn global add ${pkg}`;
@@ -131,6 +131,17 @@ function installCommand(pkg, opts = {}) {
131
131
  return `yarn add --ignore-scripts -W ${pkg}`;
132
132
  }
133
133
  }
134
+ else if (mgr === "yarn2") {
135
+ if (opts.global) {
136
+ return `npm install -g ${pkg}`;
137
+ }
138
+ else if (opts.dev) {
139
+ return `yarn add -D ${pkg}`;
140
+ }
141
+ else {
142
+ return `yarn add ${pkg}`;
143
+ }
144
+ }
134
145
  else if (mgr === "pnpm") {
135
146
  if (opts.global) {
136
147
  return `pnpm add -g ${pkg}`;
@@ -155,25 +166,59 @@ function installCommand(pkg, opts = {}) {
155
166
  }
156
167
  }
157
168
  /**
158
- * Detect if you should use `npm` or `yarn`
159
- * @param dir
160
- * @returns
169
+ * The package manager to install with: the one requested, else the one we were run
170
+ * with. `npx` overwrites npm_config_user_agent, so this must be read before spawning
171
+ * nested create commands.
161
172
  */
162
- function detectPackageManager(dir) {
163
- // We should look only inside the directory instead of looking to the ancestors
164
- // with findupSync, the reason for this is that the current gatsby template
165
- // uses npm, so if the user has some yarn.lock in a parent directory it's
166
- // going to run yarn commands, this is going to trigger an error with sharp
167
- const yarnLock = (0, fs_1.existsSync)(path_1.default.join(dir ? dir : "", "yarn.lock"));
168
- const pnpmLock = (0, fs_1.existsSync)(path_1.default.join(dir ? dir : "", "pnpm-lock.yaml"));
169
- if (yarnLock) {
170
- return "yarn";
173
+ function resolvePackageManager(requested) {
174
+ var _a;
175
+ if (requested) {
176
+ return requested === "yarn"
177
+ ? yarnVariant(installedYarnVersion())
178
+ : requested;
171
179
  }
172
- else if (pnpmLock) {
173
- return "pnpm";
180
+ const [name, version] = ((_a = process.env.npm_config_user_agent) !== null && _a !== void 0 ? _a : "")
181
+ .split(" ")[0]
182
+ .split("/");
183
+ if (name === "yarn") {
184
+ return yarnVariant(version);
174
185
  }
175
- else {
176
- return "npm";
186
+ return name === "pnpm" ? "pnpm" : "npm";
187
+ }
188
+ exports.resolvePackageManager = resolvePackageManager;
189
+ function yarnVariant(version) {
190
+ const parsed = version ? semver.coerce(version) : null;
191
+ return parsed && parsed.major >= 2 ? "yarn2" : "yarn";
192
+ }
193
+ function installedYarnVersion() {
194
+ try {
195
+ return execa.commandSync("yarn --version").stdout.trim();
196
+ }
197
+ catch (_a) {
198
+ return undefined;
177
199
  }
178
200
  }
179
- exports.detectPackageManager = detectPackageManager;
201
+ /** Scaffolders and run scripts only know the `yarn` command. */
202
+ function packageManagerCommand(mgr) {
203
+ return mgr === "yarn2" ? "yarn" : mgr;
204
+ }
205
+ exports.packageManagerCommand = packageManagerCommand;
206
+ /** Run a locally installed bin. `npx` can't see Yarn Berry's PnP installs. */
207
+ function packageManagerExec(mgr) {
208
+ const cmd = packageManagerCommand(mgr);
209
+ return cmd === "yarn" ? "yarn" : cmd === "pnpm" ? "pnpm exec" : "npx";
210
+ }
211
+ exports.packageManagerExec = packageManagerExec;
212
+ /**
213
+ * Make a freshly scaffolded app its own Yarn Berry project. Without a lockfile Berry
214
+ * claims the app for the nearest ancestor project, and its default PnP linker can't
215
+ * load CommonJS from Node 24's ESM resolver (EBADF), which breaks every framework we
216
+ * scaffold. Must run before anything invokes yarn in `projectPath`.
217
+ */
218
+ function initYarnBerryProject(projectPath) {
219
+ return __awaiter(this, void 0, void 0, function* () {
220
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, "yarn.lock"), "");
221
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, ".yarnrc.yml"), "nodeLinker: node-modules\n");
222
+ });
223
+ }
224
+ exports.initYarnBerryProject = initYarnBerryProject;
@@ -1,9 +1,11 @@
1
- import { JsOrTs, PlatformOptions, SchemeType } from "./types";
1
+ import { JsOrTs, PackageManagerType, PlatformOptions, SchemeType } from "./types";
2
2
  export interface CreateArgs {
3
3
  projectPath: string;
4
+ projectId: string;
4
5
  template?: string;
5
6
  jsOrTs: JsOrTs;
6
7
  platformOptions: PlatformOptions;
8
+ packageManager: PackageManagerType;
7
9
  }
8
10
  export interface ConfigArgs {
9
11
  projectId: string;
@@ -20,6 +22,7 @@ export interface GenerateFilesArgs {
20
22
  projectId: string;
21
23
  projectApiToken: string | undefined;
22
24
  platformOptions: PlatformOptions;
25
+ packageManager: PackageManagerType;
23
26
  }
24
27
  export interface BuildArgs {
25
28
  projectPath: string;
@@ -29,6 +32,7 @@ export interface InstallArgs {
29
32
  scheme: SchemeType;
30
33
  projectPath: string;
31
34
  jsOrTs: JsOrTs;
35
+ packageManager: PackageManagerType;
32
36
  }
33
37
  export interface CPAStrategy {
34
38
  create: (args: CreateArgs) => Promise<void>;
@@ -6,6 +6,7 @@ export type PlatformOptions = {
6
6
  };
7
7
  };
8
8
  export type SchemeType = "codegen" | "loader";
9
+ export type PackageManagerType = "npm" | "yarn" | "yarn2" | "pnpm";
9
10
  export type PlasmicCssImport = {
10
11
  projectId: string;
11
12
  importPath: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.168",
3
+ "version": "0.0.170",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "homepage": "https://www.plasmic.app",
6
6
  "repository": {
@@ -26,7 +26,6 @@
26
26
  "prepublishOnly": "npm run build"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/findup-sync": "^2.0.2",
30
29
  "@types/glob": "^7.2.0",
31
30
  "@types/inquirer": "^8.2.13",
32
31
  "@types/jest": "^26.0.24",
@@ -43,7 +42,6 @@
43
42
  "@sentry/node": "^6.2.2",
44
43
  "chalk": "^4.1.0",
45
44
  "execa": "^5.0.0",
46
- "findup-sync": "^4.0.0",
47
45
  "glob": "^7.1.6",
48
46
  "inquirer": "^8.2.7",
49
47
  "lodash": "^4.17.21",
@@ -53,5 +51,5 @@
53
51
  "validate-npm-package-name": "^3.0.0",
54
52
  "yargs": "^16.2.2"
55
53
  },
56
- "gitHead": "f63ae177f15f845faf191d62b25fc3e3e3cfdb95"
54
+ "gitHead": "8ab1bc413667e338190dcfc7d072de0d1eefe50f"
57
55
  }
package/run-cpa.ts CHANGED
@@ -3,7 +3,11 @@ import * as inquirer from "inquirer";
3
3
  import * as path from "path";
4
4
  import yargs from "yargs";
5
5
  import { spawnOrFail } from "./src/utils/cmd-utils";
6
- import { PlatformType, SchemeType } from "./src/utils/types";
6
+ import {
7
+ PackageManagerType,
8
+ PlatformType,
9
+ SchemeType,
10
+ } from "./src/utils/types";
7
11
 
8
12
  // https://studio.plasmic.app/projects/47tFXWjN2C4NyHFGGpaYQ3
9
13
  const projectId = "47tFXWjN2C4NyHFGGpaYQ3";
@@ -60,12 +64,17 @@ async function run() {
60
64
  `Runs create-plasmic-app with predefined sets of args for you.
61
65
 
62
66
  Valid arg sets:\n\tall\n\t${allArgSetNames.join("\n\t")}`,
63
- (yargs2) => yargs2
67
+ (yargs2) =>
68
+ yargs2.option("package-manager", {
69
+ describe: "Package manager to scaffold and build with",
70
+ choices: ["npm", "yarn", "pnpm"],
71
+ default: "npm",
72
+ })
64
73
  );
65
74
 
66
- const cliArgSetNames = yargsCommand.strict().argv["arg-sets"] as
67
- | string[]
68
- | undefined;
75
+ const cliArgv = yargsCommand.strict().argv;
76
+ const packageManager = cliArgv["package-manager"] as PackageManagerType;
77
+ const cliArgSetNames = cliArgv["arg-sets"] as string[] | undefined;
69
78
 
70
79
  // If arg sets were not passed in via CLI args, prompt for them.
71
80
  const selectedArgSetNames =
@@ -123,11 +132,13 @@ Valid arg sets:\n\tall\n\t${allArgSetNames.join("\n\t")}`,
123
132
  `--scheme=${argSet.scheme}`,
124
133
  `--typescript=${argSet.typescript}`,
125
134
  `--projectId=${projectId}`,
135
+ `--packageManager=${packageManager}`,
126
136
  ].join(" ");
127
137
 
128
138
  const cpa = path.resolve("dist/index.js");
129
139
  // this probably only works on *nix systems, sorry :(
130
- const cmd = `mkdir -p ${tmpOutDir} && cd ${tmpOutDir} && node ${cpa} ${projectName} ${options} && cd ${projectName} && yarn build`;
140
+ const runCmd = packageManager === "yarn" ? "yarn" : `${packageManager} run`;
141
+ const cmd = `mkdir -p ${tmpOutDir} && cd ${tmpOutDir} && node ${cpa} ${projectName} ${options} && cd ${projectName} && ${runCmd} build`;
131
142
  await spawnOrFail(cmd);
132
143
 
133
144
  const tmpProjectDir = path.join(tmpOutDir, projectName);
@@ -9,7 +9,7 @@ import {
9
9
  getPlasmicConfig,
10
10
  } from "../utils/file-utils";
11
11
  import { ensure } from "../utils/lang-utils";
12
- import { installUpgrade } from "../utils/npm-utils";
12
+ import { initYarnBerryProject, installUpgrade } from "../utils/npm-utils";
13
13
  import { CPAStrategy } from "../utils/strategy";
14
14
  import {
15
15
  GATSBY_404,
@@ -29,7 +29,7 @@ export const GATSBY_TEMPLATES = {
29
29
 
30
30
  export const gatsbyStrategy: CPAStrategy = {
31
31
  create: async (args) => {
32
- const { projectPath, template, jsOrTs } = args;
32
+ const { projectPath, projectId, template, jsOrTs, packageManager } = args;
33
33
  if (template) {
34
34
  console.log(
35
35
  `Warning: Ignoring template '${template}' (argument is not supported by Gatsby).`
@@ -38,24 +38,47 @@ export const gatsbyStrategy: CPAStrategy = {
38
38
  const gatsbyTemplate = GATSBY_TEMPLATES[jsOrTs];
39
39
  const createCommand = `git clone ${gatsbyTemplate} ${projectPath} --recursive --depth 1 --quiet`;
40
40
  await spawnOrFail(`${createCommand}`);
41
- // Remove .git and LICENSE so that we don't generate linked outputs
42
- await spawnOrFail(`rm -rf ${projectPath}/.git`);
43
- await spawnOrFail(`rm -rf ${projectPath}/LICENSE`);
41
+ // Remove package-lock.json since the user might be using a different package manager
42
+ await spawnOrFail(
43
+ `rm -rf ${projectPath}/.git ${projectPath}/LICENSE ${projectPath}/package-lock.json`
44
+ );
45
+
46
+ // Rename before installing; Yarn Berry rejects `yarn run` once the lockfile's
47
+ // workspace name no longer matches package.json
48
+ const packageJsonPath = path.join(projectPath, "package.json");
49
+ const packageJsonObject = JSON.parse(
50
+ await fs.readFile(packageJsonPath, "utf8")
51
+ );
52
+ packageJsonObject.name = path.basename(projectPath);
53
+ packageJsonObject.description = `Plasmic app for ${projectId}`;
54
+ delete packageJsonObject.license;
55
+ delete packageJsonObject.author;
56
+ await fs.writeFile(
57
+ packageJsonPath,
58
+ JSON.stringify(packageJsonObject, null, 2)
59
+ );
60
+
61
+ if (packageManager === "yarn2") {
62
+ await initYarnBerryProject(projectPath);
63
+ }
44
64
  },
45
- installDeps: async ({ projectPath, scheme, jsOrTs }) => {
65
+ installDeps: async ({ projectPath, scheme, jsOrTs, packageManager }) => {
46
66
  const installedHelmet = await installUpgrade("react-helmet", {
47
67
  workingDir: projectPath,
68
+ packageManager,
48
69
  });
49
70
  const installedHelmetTypes =
50
71
  jsOrTs === "js" ||
51
72
  (await installUpgrade("@types/react-helmet", {
52
73
  workingDir: projectPath,
53
74
  dev: true,
75
+ packageManager,
54
76
  }));
55
77
  const installedHelmetPlugin = await installUpgrade(
56
78
  "gatsby-plugin-react-helmet",
57
79
  {
58
80
  workingDir: projectPath,
81
+ packageManager,
59
82
  }
60
83
  );
61
84
  if (!installedHelmet || !installedHelmetPlugin || !installedHelmetTypes) {
@@ -65,27 +88,14 @@ export const gatsbyStrategy: CPAStrategy = {
65
88
  if (scheme === "loader") {
66
89
  return await installUpgrade("@plasmicapp/loader-gatsby", {
67
90
  workingDir: projectPath,
91
+ packageManager,
68
92
  });
69
93
  } else {
70
- return await installCodegenDeps({ projectPath });
94
+ return await installCodegenDeps({ projectPath, packageManager });
71
95
  }
72
96
  },
73
97
  overwriteConfig: async (args) => {
74
98
  const { projectId, projectPath, projectApiToken, jsOrTs, scheme } = args;
75
- const packageName = path.basename(projectPath);
76
-
77
- // Update package.json: adding name and description, removing license and author
78
- const packageJsonPath = path.join(projectPath, "package.json");
79
- const packageJson = await fs.readFile(packageJsonPath, "utf8");
80
- const packageJsonObject = JSON.parse(packageJson);
81
- packageJsonObject.name = packageName;
82
- packageJsonObject.description = `Plasmic app for ${projectId}`;
83
- delete packageJsonObject.license;
84
- delete packageJsonObject.author;
85
- await fs.writeFile(
86
- packageJsonPath,
87
- JSON.stringify(packageJsonObject, null, 2)
88
- );
89
99
 
90
100
  if (scheme === "loader") {
91
101
  const gatsbyConfigFile = path.join(
@@ -105,7 +115,14 @@ export const gatsbyStrategy: CPAStrategy = {
105
115
  generateFiles: async (args) => {
106
116
  // in gatsby we can delete all existing pages/components, since all pages are going
107
117
  // to be handled by templates/defaultPlasmicPage
108
- const { projectId, projectApiToken, projectPath, jsOrTs, scheme } = args;
118
+ const {
119
+ projectId,
120
+ projectApiToken,
121
+ projectPath,
122
+ jsOrTs,
123
+ scheme,
124
+ packageManager,
125
+ } = args;
109
126
 
110
127
  deleteGlob(path.join(projectPath, "src/@(pages|components|templates)/*.*"));
111
128
 
@@ -157,6 +174,7 @@ export const gatsbyStrategy: CPAStrategy = {
157
174
  projectId,
158
175
  projectApiToken,
159
176
  projectPath,
177
+ packageManager,
160
178
  });
161
179
 
162
180
  // Special case: remove all Gatsby components (due to conflicting file names)
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ import { ensure } from "./utils/lang-utils";
10
10
  import { checkEngineStrict, updateNotify } from "./utils/npm-utils";
11
11
  import {
12
12
  JsOrTs,
13
+ PackageManagerType,
13
14
  PlatformOptions,
14
15
  PlatformType,
15
16
  SchemeType,
@@ -64,6 +65,10 @@ const argv = yargs
64
65
  describe: "(Next.js) Use app directory?",
65
66
  boolean: true,
66
67
  })
68
+ .option("packageManager", {
69
+ describe: "Package manager to scaffold and install with",
70
+ choices: ["", "npm", "yarn", "pnpm"],
71
+ })
67
72
  .strict()
68
73
  .help("h")
69
74
  .alias("h", "help")
@@ -256,6 +261,9 @@ What is the URL of your project?`,
256
261
 
257
262
  const template = argv["template"];
258
263
  const projectApiToken = argv["projectApiToken"];
264
+ const packageManager = (argv["packageManager"] || undefined) as
265
+ | PackageManagerType
266
+ | undefined;
259
267
 
260
268
  // Set the metadata environment variable to tag the future Segment codegen event
261
269
  setMetadataEnv({
@@ -270,6 +278,7 @@ What is the URL of your project?`,
270
278
  jsOrTs,
271
279
  projectApiToken,
272
280
  template,
281
+ packageManager,
273
282
  });
274
283
  }
275
284
 
package/src/lib.ts CHANGED
@@ -3,10 +3,15 @@ import chalk from "chalk";
3
3
  import * as path from "upath";
4
4
  import validateProjectName from "validate-npm-package-name";
5
5
  import { ensureTsconfig, overwriteReadme } from "./utils/file-utils";
6
- import { detectPackageManager } from "./utils/npm-utils";
6
+ import {
7
+ packageManagerCommand,
8
+ packageManagerExec,
9
+ resolvePackageManager,
10
+ } from "./utils/npm-utils";
7
11
  import { CPAStrategy } from "./utils/strategy";
8
12
  import {
9
13
  JsOrTs,
14
+ PackageManagerType,
10
15
  PlatformOptions,
11
16
  PlatformType,
12
17
  SchemeType,
@@ -34,6 +39,7 @@ export interface CreatePlasmicAppArgs {
34
39
  jsOrTs: JsOrTs;
35
40
  projectApiToken?: string;
36
41
  template?: string;
42
+ packageManager?: PackageManagerType;
37
43
  }
38
44
 
39
45
  export async function create(args: CreatePlasmicAppArgs): Promise<void> {
@@ -47,6 +53,7 @@ export async function create(args: CreatePlasmicAppArgs): Promise<void> {
47
53
  template,
48
54
  } = args;
49
55
  let { projectApiToken } = args;
56
+ const packageManager = resolvePackageManager(args.packageManager);
50
57
  console.log("Let's get started! Here's what we'll do: ");
51
58
  console.log("1. Authenticate with Plasmic");
52
59
  console.log("2. Create a React/Next/Gatsby repo");
@@ -87,16 +94,18 @@ export async function create(args: CreatePlasmicAppArgs): Promise<void> {
87
94
  // Create project using strategy for platform
88
95
  await cpaStrategy.create({
89
96
  projectPath: resolvedProjectPath,
97
+ projectId,
90
98
  jsOrTs,
91
99
  template,
92
100
  platformOptions,
101
+ packageManager,
93
102
  });
94
103
 
95
104
  // Ensure that we have a empty tsconfig and @types packages.
96
105
  // Gatsby and Next.js by default support typescript handling internally
97
106
  // tsconfig so we don't have to ensure it.
98
107
  if (jsOrTs === "ts" && platform === "react") {
99
- await ensureTsconfig(resolvedProjectPath);
108
+ await ensureTsconfig(resolvedProjectPath, packageManager);
100
109
  }
101
110
 
102
111
  // Make sure we have an api token for loader
@@ -113,6 +122,7 @@ export async function create(args: CreatePlasmicAppArgs): Promise<void> {
113
122
  scheme,
114
123
  projectPath: resolvedProjectPath,
115
124
  jsOrTs,
125
+ packageManager,
116
126
  });
117
127
 
118
128
  if (!installResult) {
@@ -137,14 +147,14 @@ export async function create(args: CreatePlasmicAppArgs): Promise<void> {
137
147
  projectId,
138
148
  projectApiToken,
139
149
  platformOptions,
150
+ packageManager,
140
151
  });
141
152
 
142
153
  /**
143
154
  * INSTRUCT USER ON NEXT STEPS
144
155
  */
145
- const pkgMgr = detectPackageManager(resolvedProjectPath);
146
- const npmRunCmd =
147
- pkgMgr === "yarn" ? "yarn" : pkgMgr === "pnpm" ? "pnpm run" : "npm run";
156
+ const pmCmd = packageManagerCommand(packageManager);
157
+ const npmRunCmd = pmCmd === "yarn" ? "yarn" : `${pmCmd} run`;
148
158
  const command =
149
159
  platform === "nextjs"
150
160
  ? `${npmRunCmd} dev`
@@ -183,7 +193,9 @@ export async function create(args: CreatePlasmicAppArgs): Promise<void> {
183
193
  console.log(
184
194
  "To watch for changes in Plasmic components, in a separate terminal run:"
185
195
  );
186
- console.log(chalk.bold(`npx plasmic watch`));
196
+ console.log(
197
+ chalk.bold(`${packageManagerExec(packageManager)} plasmic watch`)
198
+ );
187
199
  }
188
200
  }
189
201
 
@@ -10,7 +10,11 @@ import {
10
10
  getPlasmicConfig,
11
11
  } from "../utils/file-utils";
12
12
  import { ensure } from "../utils/lang-utils";
13
- import { installUpgrade } from "../utils/npm-utils";
13
+ import {
14
+ initYarnBerryProject,
15
+ installUpgrade,
16
+ packageManagerCommand,
17
+ } from "../utils/npm-utils";
14
18
  import { CPAStrategy, GenerateFilesArgs } from "../utils/strategy";
15
19
  import { PlasmicCssImport } from "../utils/types";
16
20
  import { makeLayout_app_codegen } from "./templates/app-codegen/layout";
@@ -38,28 +42,40 @@ import {
38
42
 
39
43
  export const nextjsStrategy: CPAStrategy = {
40
44
  create: async (args) => {
41
- const { projectPath, template, jsOrTs, platformOptions } = args;
45
+ const { projectPath, template, jsOrTs, platformOptions, packageManager } =
46
+ args;
42
47
  const typescriptArg = `--${jsOrTs}`;
43
48
  const experimentalAppArg = platformOptions.nextjs?.appDir
44
49
  ? "--app"
45
50
  : "--no-app";
46
51
  const templateArg = template ? ` --example ${template}` : "";
52
+ const isYarnBerry = packageManager === "yarn2";
47
53
  // NOTE: Not using create-next-app@latest to keep major version bumps deliberate
48
54
  const createCommand =
49
55
  `npx create-next-app@16 ${projectPath} ${typescriptArg} ${experimentalAppArg} ${templateArg}` +
50
- ` --eslint --no-src-dir --import-alias "@/*" --no-tailwind`;
56
+ ` --use-${packageManagerCommand(
57
+ packageManager
58
+ )} --eslint --no-src-dir --import-alias "@/*" --no-tailwind` +
59
+ // Berry must install into the project we set up below, not the default PnP one
60
+ (isYarnBerry ? " --skip-install" : "");
51
61
 
52
62
  // Default Next.js starter already supports Typescript
53
63
  // See where we `touch tsconfig.json` later on
54
64
  await spawnOrFail(createCommand);
65
+
66
+ if (isYarnBerry) {
67
+ await initYarnBerryProject(projectPath);
68
+ await spawnOrFail("yarn install", projectPath);
69
+ }
55
70
  },
56
- installDeps: async ({ scheme, projectPath }) => {
71
+ installDeps: async ({ scheme, projectPath, packageManager }) => {
57
72
  if (scheme === "loader") {
58
73
  return await installUpgrade("@plasmicapp/loader-nextjs", {
59
74
  workingDir: projectPath,
75
+ packageManager,
60
76
  });
61
77
  } else {
62
- return await installCodegenDeps({ projectPath });
78
+ return await installCodegenDeps({ projectPath, packageManager });
63
79
  }
64
80
  },
65
81
  overwriteConfig: async (args) => {
@@ -129,7 +145,14 @@ a {
129
145
  }
130
146
 
131
147
  async function generateFilesAppDir(args: GenerateFilesArgs) {
132
- const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
148
+ const {
149
+ projectPath,
150
+ scheme,
151
+ jsOrTs,
152
+ projectId,
153
+ projectApiToken,
154
+ packageManager,
155
+ } = args;
133
156
 
134
157
  // Delete existing pages
135
158
  deleteGlob(path.join(projectPath, "app", "page.*"));
@@ -197,6 +220,7 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
197
220
  projectId,
198
221
  projectApiToken,
199
222
  projectPath,
223
+ packageManager,
200
224
  });
201
225
 
202
226
  // ./app/sitemap.ts
@@ -239,7 +263,14 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
239
263
  }
240
264
 
241
265
  async function generateFilesPagesDir(args: GenerateFilesArgs) {
242
- const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
266
+ const {
267
+ projectPath,
268
+ scheme,
269
+ jsOrTs,
270
+ projectId,
271
+ projectApiToken,
272
+ packageManager,
273
+ } = args;
243
274
 
244
275
  // Delete existing pages
245
276
  deleteGlob(path.join(projectPath, "pages", "*.*"));
@@ -292,6 +323,7 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
292
323
  projectId,
293
324
  projectApiToken,
294
325
  projectPath,
326
+ packageManager,
295
327
  });
296
328
 
297
329
  // ./pages/sitemap.xml.ts
@@ -9,12 +9,12 @@ import {
9
9
  generateWelcomePage,
10
10
  getPlasmicConfig,
11
11
  } from "../utils/file-utils";
12
- import { installUpgrade } from "../utils/npm-utils";
12
+ import { initYarnBerryProject, installUpgrade } from "../utils/npm-utils";
13
13
  import { CPAStrategy } from "../utils/strategy";
14
14
 
15
15
  export const reactStrategy: CPAStrategy = {
16
16
  create: async (args) => {
17
- const { projectPath, jsOrTs } = args;
17
+ const { projectPath, jsOrTs, packageManager } = args;
18
18
  let { template } = args;
19
19
 
20
20
  /* create-vite package checks if the targetDir doesn't exist then it creates the targetDir in the
@@ -45,14 +45,19 @@ export const reactStrategy: CPAStrategy = {
45
45
 
46
46
  const templateArg = template ? ` --template ${template}` : "";
47
47
  await spawnOrFail(`${createCommand}${templateArg}`);
48
+
49
+ if (packageManager === "yarn2") {
50
+ await initYarnBerryProject(fullProjectPath);
51
+ }
48
52
  },
49
- installDeps: async ({ projectPath, scheme }) => {
53
+ installDeps: async ({ projectPath, scheme, packageManager }) => {
50
54
  if (scheme === "loader") {
51
55
  return await installUpgrade("@plasmicapp/loader-react", {
52
56
  workingDir: projectPath,
57
+ packageManager,
53
58
  });
54
59
  } else {
55
- return await installCodegenDeps({ projectPath });
60
+ return await installCodegenDeps({ projectPath, packageManager });
56
61
  }
57
62
  },
58
63
  overwriteConfig: async (args) => {
@@ -81,6 +86,7 @@ export const reactStrategy: CPAStrategy = {
81
86
  projectId,
82
87
  projectPath,
83
88
  jsOrTs,
89
+ packageManager,
84
90
  }) => {
85
91
  if (scheme === "loader") {
86
92
  // Nothing to do
@@ -92,6 +98,7 @@ export const reactStrategy: CPAStrategy = {
92
98
  projectId,
93
99
  projectApiToken,
94
100
  projectPath,
101
+ packageManager,
95
102
  });
96
103
 
97
104
  // Pick a page for the entry point App.tsx page