@plasmicapp/cli 0.1.233 → 0.1.235

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.
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
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;
16
16
  const child_process_1 = require("child_process");
17
- const fast_glob_1 = __importDefault(require("fast-glob"));
18
17
  const findup_sync_1 = __importDefault(require("findup-sync"));
19
18
  const latest_version_1 = __importDefault(require("latest-version"));
20
19
  const path_1 = __importDefault(require("path"));
@@ -102,23 +101,36 @@ function checkVersion(context, baseDir, pkg) {
102
101
  });
103
102
  }
104
103
  function findInstalledVersion(context, baseDir, pkg) {
105
- var _a;
104
+ var _a, _b, _c, _d, _e, _f, _g;
106
105
  const pm = detectPackageManager(baseDir);
107
- if (pm === "yarn2") {
108
- try {
109
- const pkgInfo = JSON.parse(child_process_1.execSync(`yarn info --json ${pkg}`).toString().trim());
110
- return (_a = pkgInfo === null || pkgInfo === void 0 ? void 0 : pkgInfo.children) === null || _a === void 0 ? void 0 : _a.Version;
106
+ try {
107
+ if (pm === "yarn2") {
108
+ const output = child_process_1.execSync(`yarn info --json ${pkg}`).toString().trim();
109
+ const info = JSON.parse(output);
110
+ return (_a = info === null || info === void 0 ? void 0 : info.children) === null || _a === void 0 ? void 0 : _a.Version;
111
+ }
112
+ else if (pm === "yarn") {
113
+ const output = child_process_1.execSync(`yarn list --json --pattern ${pkg}`)
114
+ .toString()
115
+ .trim()
116
+ .split("\n");
117
+ for (const line of output) {
118
+ const info = JSON.parse(line);
119
+ if ((info === null || info === void 0 ? void 0 : info.type) === "tree" && ((_e = (_d = (_c = (_b = info === null || info === void 0 ? void 0 : info.data) === null || _b === void 0 ? void 0 : _b.trees) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.startsWith(`${pkg}@`))) {
120
+ return info.data.trees[0].name.replace(`${pkg}@`, "");
121
+ }
122
+ }
111
123
  }
112
- catch (_) {
113
- return undefined;
124
+ else {
125
+ const output = child_process_1.execSync(`npm list --package-lock-only --json ${pkg}`)
126
+ .toString()
127
+ .trim();
128
+ const info = JSON.parse(output);
129
+ 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;
114
130
  }
115
131
  }
116
- const filename = findInstalledPackageJsonFile(context, pkg);
117
- if (filename) {
118
- const json = parsePackageJson(filename);
119
- if (json && json.name === pkg) {
120
- return json.version;
121
- }
132
+ catch (err) {
133
+ deps_1.logger.warn(`Could not detect installed version of ${pkg} using ${pm}: ${err}`);
122
134
  }
123
135
  return undefined;
124
136
  }
@@ -150,16 +162,6 @@ function findPackageJsonDir(rootDir) {
150
162
  return filePath ? path_1.default.dirname(filePath) : undefined;
151
163
  }
152
164
  exports.findPackageJsonDir = findPackageJsonDir;
153
- function findInstalledPackageJsonFile(context, pkg) {
154
- const packageJsonPath = findPackageJsonPath(context.rootDir);
155
- const rootDir = packageJsonPath
156
- ? path_1.default.dirname(packageJsonPath)
157
- : context.rootDir;
158
- const files = fast_glob_1.default.sync(`${rootDir}/**/node_modules/${pkg}/package.json`, {
159
- ignore: [`**/node_modules/**/node_modules/**`],
160
- });
161
- return files.length > 0 ? files[0] : undefined;
162
- }
163
165
  function parsePackageJson(path) {
164
166
  try {
165
167
  return JSON.parse(file_utils_1.readFileText(path));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.233",
3
+ "version": "0.1.235",
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": "411aa3e27a221f2a3a88578bc108905e424b4a8c"
80
+ "gitHead": "29193a15e9341b80f6f588c5583ef8446bbc87b1"
81
81
  }
@@ -1,5 +1,4 @@
1
1
  import { execSync, spawnSync } from "child_process";
2
- import glob from "fast-glob";
3
2
  import findupSync from "findup-sync";
4
3
  import latest from "latest-version";
5
4
  import path from "path";
@@ -114,24 +113,38 @@ export function findInstalledVersion(
114
113
  pkg: string
115
114
  ) {
116
115
  const pm = detectPackageManager(baseDir);
117
- if (pm === "yarn2") {
118
- try {
119
- const pkgInfo = JSON.parse(
120
- execSync(`yarn info --json ${pkg}`).toString().trim()
121
- );
122
- return pkgInfo?.children?.Version;
123
- } catch (_) {
124
- return undefined;
116
+ try {
117
+ if (pm === "yarn2") {
118
+ const output = execSync(`yarn info --json ${pkg}`).toString().trim();
119
+ const info = JSON.parse(output);
120
+ return info?.children?.Version;
121
+ } else if (pm === "yarn") {
122
+ const output = execSync(`yarn list --json --pattern ${pkg}`)
123
+ .toString()
124
+ .trim()
125
+ .split("\n");
126
+ for (const line of output) {
127
+ const info = JSON.parse(line);
128
+ if (
129
+ info?.type === "tree" &&
130
+ info?.data?.trees?.[0]?.name?.startsWith(`${pkg}@`)
131
+ ) {
132
+ return info.data.trees[0].name.replace(`${pkg}@`, "");
133
+ }
134
+ }
135
+ } else {
136
+ const output = execSync(`npm list --package-lock-only --json ${pkg}`)
137
+ .toString()
138
+ .trim();
139
+ const info = JSON.parse(output);
140
+ return info?.dependencies?.[pkg]?.version;
125
141
  }
142
+ } catch (err) {
143
+ logger.warn(
144
+ `Could not detect installed version of ${pkg} using ${pm}: ${err}`
145
+ );
126
146
  }
127
147
 
128
- const filename = findInstalledPackageJsonFile(context, pkg);
129
- if (filename) {
130
- const json = parsePackageJson(filename);
131
- if (json && json.name === pkg) {
132
- return json.version as string;
133
- }
134
- }
135
148
  return undefined;
136
149
  }
137
150
 
@@ -164,17 +177,6 @@ export function findPackageJsonDir(rootDir: string) {
164
177
  return filePath ? path.dirname(filePath) : undefined;
165
178
  }
166
179
 
167
- function findInstalledPackageJsonFile(context: PlasmicContext, pkg: string) {
168
- const packageJsonPath = findPackageJsonPath(context.rootDir);
169
- const rootDir = packageJsonPath
170
- ? path.dirname(packageJsonPath)
171
- : context.rootDir;
172
- const files = glob.sync(`${rootDir}/**/node_modules/${pkg}/package.json`, {
173
- ignore: [`**/node_modules/**/node_modules/**`],
174
- });
175
- return files.length > 0 ? files[0] : undefined;
176
- }
177
-
178
180
  function parsePackageJson(path: string) {
179
181
  try {
180
182
  return JSON.parse(readFileText(path));