@plasmicapp/cli 0.1.241 → 0.1.243

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/index.js CHANGED
@@ -261,6 +261,11 @@ function configureSyncArgs(yags, includeQuietOption = true) {
261
261
  type: "boolean",
262
262
  describe: "Ignore post-sync commands in plasmic.json",
263
263
  default: false,
264
+ })
265
+ .option("skip-upgrade-check", {
266
+ type: "boolean",
267
+ describe: "Skip upgrade check for Plasmic dependencies",
268
+ default: false,
264
269
  })
265
270
  .option("metadata", {
266
271
  type: "string",
@@ -6,10 +6,6 @@ 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 warnLatest(context: PlasmicContext, pkg: string, baseDir: string, msgs: {
10
- requiredMsg: () => string;
11
- updateMsg: (curVersion: string, latestVersion: string) => string;
12
- }, yes?: boolean): Promise<void>;
13
9
  export declare function findInstalledVersion(context: PlasmicContext, baseDir: string, pkg: string): any;
14
10
  /**
15
11
  * Detects if the cli is globally installed. `rootDir` is the folder
@@ -25,4 +21,4 @@ export declare function installCommand(pkg: string, baseDir: string, opts?: {
25
21
  global?: boolean;
26
22
  dev?: boolean;
27
23
  }): string;
28
- export declare function detectPackageManager(baseDir: string): "yarn2" | "yarn" | "npm";
24
+ export declare function detectPackageManager(baseDir: string): "yarn2" | "yarn" | "npm" | "unknown";
@@ -1,26 +1,15 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.detectPackageManager = exports.installCommand = exports.installUpgrade = exports.findPackageJsonDir = exports.isCliGloballyInstalled = exports.findInstalledVersion = exports.warnLatest = exports.getParsedPackageJson = exports.checkEngineStrict = exports.getCliVersion = exports.getParsedCliPackageJson = void 0;
6
+ exports.detectPackageManager = exports.installCommand = exports.installUpgrade = exports.findPackageJsonDir = exports.isCliGloballyInstalled = exports.findInstalledVersion = exports.getParsedPackageJson = exports.checkEngineStrict = exports.getCliVersion = exports.getParsedCliPackageJson = void 0;
16
7
  const child_process_1 = require("child_process");
17
8
  const findup_sync_1 = __importDefault(require("findup-sync"));
18
- const latest_version_1 = __importDefault(require("latest-version"));
19
9
  const path_1 = __importDefault(require("path"));
20
10
  const semver_1 = __importDefault(require("semver"));
21
11
  const deps_1 = require("../deps");
22
12
  const file_utils_1 = require("./file-utils");
23
- const user_utils_1 = require("./user-utils");
24
13
  function getParsedCliPackageJson() {
25
14
  const packageJson = findup_sync_1.default("package.json", { cwd: __dirname });
26
15
  if (!packageJson) {
@@ -56,52 +45,8 @@ function getParsedPackageJson() {
56
45
  return parsePackageJson(packageJson);
57
46
  }
58
47
  exports.getParsedPackageJson = getParsedPackageJson;
59
- // @TODO: is this function still used?
60
- function warnLatest(context, pkg, baseDir, msgs, yes) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const check = yield checkVersion(context, baseDir, pkg);
63
- if (check.type === "up-to-date") {
64
- return;
65
- }
66
- else if (check.type === "wrong-npm-registry") {
67
- deps_1.logger.warn(`${msgs.requiredMsg()} Unable to find this package in your npm registry. Please update this dependency manually.`);
68
- return;
69
- }
70
- if (yield user_utils_1.confirmWithUser(`${check.type === "not-installed"
71
- ? msgs.requiredMsg()
72
- : msgs.updateMsg(check.current, check.latest)} Do you want to ${check.type === "not-installed" ? "add" : "update"} it now?`, yes)) {
73
- installUpgrade(pkg, baseDir);
74
- }
75
- });
76
- }
77
- exports.warnLatest = warnLatest;
78
- function checkVersion(context, baseDir, pkg) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- // Try to get the latest version from npm
81
- let last = null;
82
- try {
83
- last = yield latest_version_1.default(pkg);
84
- }
85
- catch (e) {
86
- // This is likely because .npmrc is set to a different registry
87
- return { type: "wrong-npm-registry" };
88
- }
89
- const cur = findInstalledVersion(context, baseDir, pkg);
90
- if (!cur) {
91
- return { type: "not-installed" };
92
- }
93
- if (semver_1.default.gt(last, cur)) {
94
- return {
95
- type: "obsolete",
96
- latest: last,
97
- current: cur,
98
- };
99
- }
100
- return { type: "up-to-date" };
101
- });
102
- }
103
48
  function findInstalledVersion(context, baseDir, pkg) {
104
- var _a, _b, _c, _d, _e, _f, _g;
49
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
105
50
  const pm = detectPackageManager(baseDir);
106
51
  try {
107
52
  if (pm === "yarn2") {
@@ -121,13 +66,19 @@ function findInstalledVersion(context, baseDir, pkg) {
121
66
  }
122
67
  }
123
68
  }
124
- else {
69
+ else if (pm === "npm") {
125
70
  const output = child_process_1.execSync(`npm list --package-lock-only --json ${pkg}`)
126
71
  .toString()
127
72
  .trim();
128
73
  const info = JSON.parse(output);
129
74
  return (_g = (_f = info === null || info === void 0 ? void 0 : info.dependencies) === null || _f === void 0 ? void 0 : _f[pkg]) === null || _g === void 0 ? void 0 : _g.version;
130
75
  }
76
+ else {
77
+ // Unknown package manager (e.g. pnpm).
78
+ const output = child_process_1.execSync(`npm list --json ${pkg}`).toString().trim();
79
+ const info = JSON.parse(output);
80
+ return (_j = (_h = info === null || info === void 0 ? void 0 : info.dependencies) === null || _h === void 0 ? void 0 : _h[pkg]) === null || _j === void 0 ? void 0 : _j.version;
81
+ }
131
82
  }
132
83
  catch (err) {
133
84
  deps_1.logger.warn(`Could not detect installed version of ${pkg} using ${pm}: ${err}`);
@@ -234,8 +185,17 @@ function detectPackageManager(baseDir) {
234
185
  const yarnLock = findup_sync_1.default("yarn.lock", { cwd: baseDir });
235
186
  if (yarnLock) {
236
187
  const yarnVersion = child_process_1.execSync(`yarn --version`).toString().trim();
237
- return semver_1.default.gte(yarnVersion, "2.0.0") ? "yarn2" : "yarn";
188
+ if (semver_1.default.gte(yarnVersion, "2.0.0")) {
189
+ return "yarn2";
190
+ }
191
+ else {
192
+ return "yarn";
193
+ }
194
+ }
195
+ const npmLock = findup_sync_1.default("package-lock.json", { cwd: baseDir });
196
+ if (npmLock) {
197
+ return "npm";
238
198
  }
239
- return "npm";
199
+ return "unknown";
240
200
  }
241
201
  exports.detectPackageManager = detectPackageManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.241",
3
+ "version": "0.1.243",
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.180",
23
+ "@plasmicapp/react-web": "0.2.182",
24
24
  "@types/cli-progress": "^3.11.0",
25
25
  "@types/findup-sync": "^2.0.2",
26
26
  "@types/glob": "^7.1.3",
@@ -80,5 +80,5 @@
80
80
  "wrap-ansi": "^7.0.0",
81
81
  "yargs": "^15.4.1"
82
82
  },
83
- "gitHead": "36bd188ff81eca470799daa15bc7f002afa33b7b"
83
+ "gitHead": "dff00ecdf8a21a7e4744bcfd80efc4d5478fd00d"
84
84
  }
package/src/index.ts CHANGED
@@ -322,6 +322,11 @@ function configureSyncArgs(
322
322
  describe: "Ignore post-sync commands in plasmic.json",
323
323
  default: false,
324
324
  })
325
+ .option("skip-upgrade-check", {
326
+ type: "boolean",
327
+ describe: "Skip upgrade check for Plasmic dependencies",
328
+ default: false,
329
+ })
325
330
  .option("metadata", {
326
331
  type: "string",
327
332
  describe:
@@ -1,12 +1,10 @@
1
1
  import { execSync, spawnSync } from "child_process";
2
2
  import findupSync from "findup-sync";
3
- import latest from "latest-version";
4
3
  import path from "path";
5
4
  import semver from "semver";
6
5
  import { logger } from "../deps";
7
6
  import { PlasmicContext } from "./config-utils";
8
7
  import { findFile, readFileText } from "./file-utils";
9
- import { confirmWithUser } from "./user-utils";
10
8
 
11
9
  export function getParsedCliPackageJson() {
12
10
  const packageJson = findupSync("package.json", { cwd: __dirname });
@@ -42,71 +40,6 @@ export function getParsedPackageJson() {
42
40
  return parsePackageJson(packageJson);
43
41
  }
44
42
 
45
- // @TODO: is this function still used?
46
- export async function warnLatest(
47
- context: PlasmicContext,
48
- pkg: string,
49
- baseDir: string,
50
- msgs: {
51
- requiredMsg: () => string;
52
- updateMsg: (curVersion: string, latestVersion: string) => string;
53
- },
54
- yes?: boolean
55
- ) {
56
- const check = await checkVersion(context, baseDir, pkg);
57
- if (check.type === "up-to-date") {
58
- return;
59
- } else if (check.type === "wrong-npm-registry") {
60
- logger.warn(
61
- `${msgs.requiredMsg()} Unable to find this package in your npm registry. Please update this dependency manually.`
62
- );
63
- return;
64
- }
65
-
66
- if (
67
- await confirmWithUser(
68
- `${
69
- check.type === "not-installed"
70
- ? msgs.requiredMsg()
71
- : msgs.updateMsg(check.current, check.latest)
72
- } Do you want to ${
73
- check.type === "not-installed" ? "add" : "update"
74
- } it now?`,
75
- yes
76
- )
77
- ) {
78
- installUpgrade(pkg, baseDir);
79
- }
80
- }
81
-
82
- async function checkVersion(
83
- context: PlasmicContext,
84
- baseDir: string,
85
- pkg: string
86
- ) {
87
- // Try to get the latest version from npm
88
- let last = null;
89
- try {
90
- last = await latest(pkg);
91
- } catch (e) {
92
- // This is likely because .npmrc is set to a different registry
93
- return { type: "wrong-npm-registry" } as const;
94
- }
95
-
96
- const cur = findInstalledVersion(context, baseDir, pkg);
97
- if (!cur) {
98
- return { type: "not-installed" } as const;
99
- }
100
- if (semver.gt(last, cur)) {
101
- return {
102
- type: "obsolete",
103
- latest: last,
104
- current: cur,
105
- } as const;
106
- }
107
- return { type: "up-to-date" } as const;
108
- }
109
-
110
43
  export function findInstalledVersion(
111
44
  context: PlasmicContext,
112
45
  baseDir: string,
@@ -132,12 +65,17 @@ export function findInstalledVersion(
132
65
  return info.data.trees[0].name.replace(`${pkg}@`, "");
133
66
  }
134
67
  }
135
- } else {
68
+ } else if (pm === "npm") {
136
69
  const output = execSync(`npm list --package-lock-only --json ${pkg}`)
137
70
  .toString()
138
71
  .trim();
139
72
  const info = JSON.parse(output);
140
73
  return info?.dependencies?.[pkg]?.version;
74
+ } else {
75
+ // Unknown package manager (e.g. pnpm).
76
+ const output = execSync(`npm list --json ${pkg}`).toString().trim();
77
+ const info = JSON.parse(output);
78
+ return info?.dependencies?.[pkg]?.version;
141
79
  }
142
80
  } catch (err) {
143
81
  logger.warn(
@@ -250,8 +188,17 @@ export function detectPackageManager(baseDir: string) {
250
188
  const yarnLock = findupSync("yarn.lock", { cwd: baseDir });
251
189
  if (yarnLock) {
252
190
  const yarnVersion = execSync(`yarn --version`).toString().trim();
253
- return semver.gte(yarnVersion, "2.0.0") ? "yarn2" : "yarn";
191
+ if (semver.gte(yarnVersion, "2.0.0")) {
192
+ return "yarn2";
193
+ } else {
194
+ return "yarn";
195
+ }
196
+ }
197
+
198
+ const npmLock = findupSync("package-lock.json", { cwd: baseDir });
199
+ if (npmLock) {
200
+ return "npm";
254
201
  }
255
202
 
256
- return "npm";
203
+ return "unknown";
257
204
  }