@plasmicapp/cli 0.1.251 → 0.1.253

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.
@@ -38,13 +38,14 @@ function initPlasmic(opts) {
38
38
  // path to plasmic.json
39
39
  const newConfigFile = opts.config || upath_1.default.join(opts.baseDir, config_utils_1.CONFIG_FILE_NAME);
40
40
  const answers = yield deriveInitAnswers(opts);
41
- yield config_utils_1.writeConfig(newConfigFile, createInitConfig(answers), opts.baseDir);
41
+ const initConfig = createInitConfig(answers);
42
+ yield config_utils_1.writeConfig(newConfigFile, initConfig, opts.baseDir);
42
43
  if (!process.env.QUIET) {
43
44
  deps_1.logger.info("Successfully created plasmic.json.\n");
44
45
  }
45
46
  const answer = yield user_utils_1.confirmWithUser("@plasmicapp/react-web is a small runtime required by Plasmic-generated code.\n Do you want to add them now?", opts.yes);
46
47
  if (answer) {
47
- npm_utils_1.installUpgrade("@plasmicapp/react-web", opts.baseDir);
48
+ npm_utils_1.installUpgrade(initConfig, "@plasmicapp/react-web", opts.baseDir);
48
49
  }
49
50
  });
50
51
  }
@@ -60,10 +60,10 @@ function ensureRequiredPackages(context, baseDir, yes) {
60
60
  const requireds = yield context.api.requiredPackages();
61
61
  const confirmInstall = (pkg, requiredVersion, opts) => __awaiter(this, void 0, void 0, function* () {
62
62
  let success = false;
63
- const command = npm_utils_1.installCommand(pkg, baseDir, opts);
63
+ const command = npm_utils_1.installCommand(context.config, pkg, baseDir, opts);
64
64
  const upgrade = yield user_utils_1.confirmWithUser(`A more recent version of ${pkg} >=${requiredVersion} is required. Would you like to upgrade via "${command}"?`, yes);
65
65
  if (upgrade) {
66
- success = npm_utils_1.installUpgrade(pkg, baseDir, opts);
66
+ success = npm_utils_1.installUpgrade(context.config, pkg, baseDir, opts);
67
67
  }
68
68
  else {
69
69
  success = false;
@@ -83,14 +83,14 @@ function ensureRequiredPackages(context, baseDir, yes) {
83
83
  // Exit so the user can run again with the new cli
84
84
  throw new error_1.HandledError();
85
85
  }
86
- const reactWebVersion = npm_utils_1.findInstalledVersion(context, baseDir, "@plasmicapp/react-web");
86
+ const reactWebVersion = npm_utils_1.findInstalledVersion(context.config, baseDir, "@plasmicapp/react-web");
87
87
  if (!reactWebVersion ||
88
88
  semver.gt(requireds["@plasmicapp/react-web"], reactWebVersion)) {
89
89
  yield confirmInstall("@plasmicapp/react-web", requireds["@plasmicapp/react-web"], { global: false, dev: false });
90
90
  }
91
91
  if (context.config.code.reactRuntime === "automatic") {
92
92
  // Using automatic runtime requires installing the @plasmicapp/react-web-runtime package
93
- const runtimeVersion = npm_utils_1.findInstalledVersion(context, baseDir, "@plasmicapp/react-web-runtime");
93
+ const runtimeVersion = npm_utils_1.findInstalledVersion(context.config, baseDir, "@plasmicapp/react-web-runtime");
94
94
  if (!runtimeVersion ||
95
95
  semver.gt(requireds["@plasmicapp/react-web-runtime"], runtimeVersion)) {
96
96
  yield confirmInstall("@plasmicapp/react-web-runtime", requireds["@plasmicapp/react-web-runtime"], { global: false, dev: false });
@@ -288,13 +288,13 @@ exports.sync = sync;
288
288
  function checkExternalPkgs(context, baseDir, opts, pkgs) {
289
289
  return __awaiter(this, void 0, void 0, function* () {
290
290
  const missingPkgs = pkgs.filter((pkg) => {
291
- const installedPkg = npm_utils_1.findInstalledVersion(context, baseDir, pkg);
291
+ const installedPkg = npm_utils_1.findInstalledVersion(context.config, baseDir, pkg);
292
292
  return !installedPkg;
293
293
  });
294
294
  if (missingPkgs.length > 0) {
295
295
  const upgrade = yield user_utils_1.confirmWithUser(`The following packages aren't installed but are required by some projects, would you like to install them? ${missingPkgs.join(", ")}`, opts.yes);
296
296
  if (upgrade) {
297
- npm_utils_1.installUpgrade(missingPkgs.join(" "), baseDir);
297
+ npm_utils_1.installUpgrade(context.config, missingPkgs.join(" "), baseDir);
298
298
  }
299
299
  }
300
300
  });
@@ -79,7 +79,7 @@ function runNecessaryMigrations(configFile, lockFile, baseDir, yes) {
79
79
  if (!confirm) {
80
80
  throw new error_1.HandledError("Upgrading is required to continue.");
81
81
  }
82
- const success = npm_utils_1.installUpgrade("@plasmicapp/cli", baseDir, {
82
+ const success = npm_utils_1.installUpgrade(cur, "@plasmicapp/cli", baseDir, {
83
83
  global: npm_utils_1.isCliGloballyInstalled(upath_1.default.dirname(configFile)),
84
84
  dev: true,
85
85
  });
@@ -447,6 +447,16 @@
447
447
  },
448
448
  "type": "object"
449
449
  },
450
+ "packageManager": {
451
+ "description": "Package manager to use when installing or upgrading required\npackages. If not specified, then it is best-effort automatically\nderived.",
452
+ "enum": [
453
+ "npm",
454
+ "pnpm",
455
+ "yarn",
456
+ "yarn2"
457
+ ],
458
+ "type": "string"
459
+ },
450
460
  "platform": {
451
461
  "description": "Target platform to generate code for",
452
462
  "enum": [
@@ -64,6 +64,12 @@ export interface PlasmicConfig {
64
64
  i18n?: I18NConfig;
65
65
  /** Arbitrary command to run after `plasmic sync` has run; useful for linting and code formatting synced files */
66
66
  postSyncCommands?: string[];
67
+ /**
68
+ * Package manager to use when installing or upgrading required
69
+ * packages. If not specified, then it is best-effort automatically
70
+ * derived.
71
+ */
72
+ packageManager?: "npm" | "yarn" | "yarn2" | "pnpm";
67
73
  }
68
74
  export interface CodeConfig {
69
75
  /** Language to generate code in */
@@ -1,4 +1,4 @@
1
- import { PlasmicContext } from "./config-utils";
1
+ import { PlasmicConfig } from "./config-utils";
2
2
  export declare function getParsedCliPackageJson(): any;
3
3
  export declare function getCliVersion(): string;
4
4
  /**
@@ -6,19 +6,19 @@ export declare function getCliVersion(): string;
6
6
  */
7
7
  export declare function checkEngineStrict(): boolean;
8
8
  export declare function getParsedPackageJson(): any;
9
- export declare function findInstalledVersion(context: PlasmicContext, baseDir: string, pkg: string): any;
9
+ export declare function findInstalledVersion(config: PlasmicConfig, baseDir: string, pkg: string): any;
10
10
  /**
11
11
  * Detects if the cli is globally installed. `rootDir` is the folder
12
12
  * where plasmic.json is
13
13
  */
14
14
  export declare function isCliGloballyInstalled(rootDir: string): boolean;
15
15
  export declare function findPackageJsonDir(rootDir: string): string | undefined;
16
- export declare function installUpgrade(pkg: string, baseDir: string, opts?: {
16
+ export declare function installUpgrade(config: PlasmicConfig, pkg: string, baseDir: string, opts?: {
17
17
  global?: boolean;
18
18
  dev?: boolean;
19
19
  }): boolean;
20
- export declare function installCommand(pkg: string, baseDir: string, opts?: {
20
+ export declare function installCommand(config: PlasmicConfig, pkg: string, baseDir: string, opts?: {
21
21
  global?: boolean;
22
22
  dev?: boolean;
23
23
  }): string;
24
- export declare function detectPackageManager(baseDir: string): "yarn2" | "yarn" | "npm" | "unknown";
24
+ export declare function detectPackageManager(config: PlasmicConfig, baseDir: string): "npm" | "yarn" | "yarn2" | "pnpm" | "unknown";
@@ -45,9 +45,9 @@ function getParsedPackageJson() {
45
45
  return parsePackageJson(packageJson);
46
46
  }
47
47
  exports.getParsedPackageJson = getParsedPackageJson;
48
- function findInstalledVersion(context, baseDir, pkg) {
48
+ function findInstalledVersion(config, baseDir, pkg) {
49
49
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
50
- const pm = detectPackageManager(baseDir);
50
+ const pm = detectPackageManager(config, baseDir);
51
51
  try {
52
52
  if (pm === "yarn2") {
53
53
  const output = child_process_1.execSync(`yarn info --json ${pkg}`).toString().trim();
@@ -121,8 +121,8 @@ function parsePackageJson(path) {
121
121
  return undefined;
122
122
  }
123
123
  }
124
- function installUpgrade(pkg, baseDir, opts = {}) {
125
- const cmd = installCommand(pkg, baseDir, opts);
124
+ function installUpgrade(config, pkg, baseDir, opts = {}) {
125
+ const cmd = installCommand(config, pkg, baseDir, opts);
126
126
  if (!process.env.QUIET) {
127
127
  deps_1.logger.info(cmd);
128
128
  }
@@ -143,8 +143,8 @@ function installUpgrade(pkg, baseDir, opts = {}) {
143
143
  }
144
144
  }
145
145
  exports.installUpgrade = installUpgrade;
146
- function installCommand(pkg, baseDir, opts = {}) {
147
- const mgr = detectPackageManager(baseDir);
146
+ function installCommand(config, pkg, baseDir, opts = {}) {
147
+ const mgr = detectPackageManager(config, baseDir);
148
148
  if (mgr === "yarn") {
149
149
  if (opts.global) {
150
150
  return `yarn global add ${pkg}`;
@@ -181,7 +181,10 @@ function installCommand(pkg, baseDir, opts = {}) {
181
181
  }
182
182
  }
183
183
  exports.installCommand = installCommand;
184
- function detectPackageManager(baseDir) {
184
+ function detectPackageManager(config, baseDir) {
185
+ if (config.packageManager) {
186
+ return config.packageManager;
187
+ }
185
188
  const yarnLock = findup_sync_1.default("yarn.lock", { cwd: baseDir });
186
189
  if (yarnLock) {
187
190
  const yarnVersion = child_process_1.execSync(`yarn --version`).toString().trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.251",
3
+ "version": "0.1.253",
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.189",
23
+ "@plasmicapp/react-web": "0.2.190",
24
24
  "@types/cli-progress": "^3.11.0",
25
25
  "@types/findup-sync": "^2.0.2",
26
26
  "@types/glob": "^7.1.3",
@@ -81,5 +81,5 @@
81
81
  "wrap-ansi": "^7.0.0",
82
82
  "yargs": "^15.4.1"
83
83
  },
84
- "gitHead": "a9fb9ed8d9fb397f60a30f9078e0c05912130a7c"
84
+ "gitHead": "96b7db457fb8ad72167bc8a793d2718406d763a5"
85
85
  }
@@ -67,7 +67,8 @@ export async function initPlasmic(
67
67
  opts.config || path.join(opts.baseDir, CONFIG_FILE_NAME);
68
68
 
69
69
  const answers = await deriveInitAnswers(opts);
70
- await writeConfig(newConfigFile, createInitConfig(answers), opts.baseDir);
70
+ const initConfig = createInitConfig(answers);
71
+ await writeConfig(newConfigFile, initConfig, opts.baseDir);
71
72
 
72
73
  if (!process.env.QUIET) {
73
74
  logger.info("Successfully created plasmic.json.\n");
@@ -78,7 +79,7 @@ export async function initPlasmic(
78
79
  opts.yes
79
80
  );
80
81
  if (answer) {
81
- installUpgrade("@plasmicapp/react-web", opts.baseDir);
82
+ installUpgrade(initConfig, "@plasmicapp/react-web", opts.baseDir);
82
83
  }
83
84
  }
84
85
 
@@ -88,13 +88,13 @@ async function ensureRequiredPackages(
88
88
  opts: { global: boolean; dev: boolean }
89
89
  ) => {
90
90
  let success = false;
91
- const command = installCommand(pkg, baseDir, opts);
91
+ const command = installCommand(context.config, pkg, baseDir, opts);
92
92
  const upgrade = await confirmWithUser(
93
93
  `A more recent version of ${pkg} >=${requiredVersion} is required. Would you like to upgrade via "${command}"?`,
94
94
  yes
95
95
  );
96
96
  if (upgrade) {
97
- success = installUpgrade(pkg, baseDir, opts);
97
+ success = installUpgrade(context.config, pkg, baseDir, opts);
98
98
  } else {
99
99
  success = false;
100
100
  }
@@ -121,7 +121,7 @@ async function ensureRequiredPackages(
121
121
  }
122
122
 
123
123
  const reactWebVersion = findInstalledVersion(
124
- context,
124
+ context.config,
125
125
  baseDir,
126
126
  "@plasmicapp/react-web"
127
127
  );
@@ -139,7 +139,7 @@ async function ensureRequiredPackages(
139
139
  if (context.config.code.reactRuntime === "automatic") {
140
140
  // Using automatic runtime requires installing the @plasmicapp/react-web-runtime package
141
141
  const runtimeVersion = findInstalledVersion(
142
- context,
142
+ context.config,
143
143
  baseDir,
144
144
  "@plasmicapp/react-web-runtime"
145
145
  );
@@ -443,7 +443,7 @@ async function checkExternalPkgs(
443
443
  pkgs: string[]
444
444
  ) {
445
445
  const missingPkgs = pkgs.filter((pkg) => {
446
- const installedPkg = findInstalledVersion(context, baseDir, pkg);
446
+ const installedPkg = findInstalledVersion(context.config, baseDir, pkg);
447
447
  return !installedPkg;
448
448
  });
449
449
  if (missingPkgs.length > 0) {
@@ -455,7 +455,7 @@ async function checkExternalPkgs(
455
455
  );
456
456
 
457
457
  if (upgrade) {
458
- installUpgrade(missingPkgs.join(" "), baseDir);
458
+ installUpgrade(context.config, missingPkgs.join(" "), baseDir);
459
459
  }
460
460
  }
461
461
  }
@@ -98,7 +98,7 @@ export async function runNecessaryMigrations(
98
98
  throw new HandledError("Upgrading is required to continue.");
99
99
  }
100
100
 
101
- const success = installUpgrade("@plasmicapp/cli", baseDir, {
101
+ const success = installUpgrade(cur, "@plasmicapp/cli", baseDir, {
102
102
  global: isCliGloballyInstalled(path.dirname(configFile)),
103
103
  dev: true,
104
104
  });
@@ -96,6 +96,13 @@ export interface PlasmicConfig {
96
96
 
97
97
  /** Arbitrary command to run after `plasmic sync` has run; useful for linting and code formatting synced files */
98
98
  postSyncCommands?: string[];
99
+
100
+ /**
101
+ * Package manager to use when installing or upgrading required
102
+ * packages. If not specified, then it is best-effort automatically
103
+ * derived.
104
+ */
105
+ packageManager?: "npm" | "yarn" | "yarn2" | "pnpm";
99
106
  }
100
107
 
101
108
  export interface CodeConfig {
@@ -3,7 +3,7 @@ import findupSync from "findup-sync";
3
3
  import path from "path";
4
4
  import semver from "semver";
5
5
  import { logger } from "../deps";
6
- import { PlasmicContext } from "./config-utils";
6
+ import { PlasmicConfig } from "./config-utils";
7
7
  import { findFile, readFileText } from "./file-utils";
8
8
 
9
9
  export function getParsedCliPackageJson() {
@@ -41,11 +41,11 @@ export function getParsedPackageJson() {
41
41
  }
42
42
 
43
43
  export function findInstalledVersion(
44
- context: PlasmicContext,
44
+ config: PlasmicConfig,
45
45
  baseDir: string,
46
46
  pkg: string
47
47
  ) {
48
- const pm = detectPackageManager(baseDir);
48
+ const pm = detectPackageManager(config, baseDir);
49
49
  try {
50
50
  if (pm === "yarn2") {
51
51
  const output = execSync(`yarn info --json ${pkg}`).toString().trim();
@@ -124,11 +124,12 @@ function parsePackageJson(path: string) {
124
124
  }
125
125
 
126
126
  export function installUpgrade(
127
+ config: PlasmicConfig,
127
128
  pkg: string,
128
129
  baseDir: string,
129
130
  opts: { global?: boolean; dev?: boolean } = {}
130
131
  ) {
131
- const cmd = installCommand(pkg, baseDir, opts);
132
+ const cmd = installCommand(config, pkg, baseDir, opts);
132
133
  if (!process.env.QUIET) {
133
134
  logger.info(cmd);
134
135
  }
@@ -151,11 +152,12 @@ export function installUpgrade(
151
152
  }
152
153
 
153
154
  export function installCommand(
155
+ config: PlasmicConfig,
154
156
  pkg: string,
155
157
  baseDir: string,
156
158
  opts: { global?: boolean; dev?: boolean } = {}
157
159
  ) {
158
- const mgr = detectPackageManager(baseDir);
160
+ const mgr = detectPackageManager(config, baseDir);
159
161
  if (mgr === "yarn") {
160
162
  if (opts.global) {
161
163
  return `yarn global add ${pkg}`;
@@ -184,7 +186,10 @@ export function installCommand(
184
186
  }
185
187
  }
186
188
 
187
- export function detectPackageManager(baseDir: string) {
189
+ export function detectPackageManager(config: PlasmicConfig, baseDir: string) {
190
+ if (config.packageManager) {
191
+ return config.packageManager;
192
+ }
188
193
  const yarnLock = findupSync("yarn.lock", { cwd: baseDir });
189
194
  if (yarnLock) {
190
195
  const yarnVersion = execSync(`yarn --version`).toString().trim();