@mintlify/cli 4.0.1124 → 4.0.1125
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/__test__/helpers.test.ts +30 -0
- package/bin/helpers.js +33 -13
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/helpers.tsx +32 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1125",
|
|
4
4
|
"description": "The Mintlify CLI",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"vitest": "2.1.9",
|
|
94
94
|
"vitest-mock-process": "1.0.4"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "9af367eef1aa11828c01c926c4a1cd7d3ba6b28a"
|
|
97
97
|
}
|
package/src/helpers.tsx
CHANGED
|
@@ -14,14 +14,15 @@ import {
|
|
|
14
14
|
import { upgradeToDocsConfig, validatePathWithinCwd } from '@mintlify/validation';
|
|
15
15
|
import detect from 'detect-port';
|
|
16
16
|
import fse from 'fs-extra';
|
|
17
|
-
import fs from 'fs/promises';
|
|
18
17
|
import inquirer from 'inquirer';
|
|
19
18
|
import yaml from 'js-yaml';
|
|
20
19
|
import { exec, execSync } from 'node:child_process';
|
|
20
|
+
import { readFileSync } from 'node:fs';
|
|
21
|
+
import fs from 'node:fs/promises';
|
|
22
|
+
import { fileURLToPath } from 'node:url';
|
|
21
23
|
import { promisify } from 'node:util';
|
|
22
24
|
import path from 'path';
|
|
23
25
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
24
|
-
import yargs from 'yargs';
|
|
25
26
|
|
|
26
27
|
import { shutdownPostHog } from './telemetry/client.js';
|
|
27
28
|
|
|
@@ -128,22 +129,40 @@ export const upgradeConfig = async () => {
|
|
|
128
129
|
}
|
|
129
130
|
};
|
|
130
131
|
|
|
132
|
+
// Resolve the CLI's own package.json via `import.meta.url` so the version is
|
|
133
|
+
// always the one shipped with this package, regardless of cwd. See #7121.
|
|
134
|
+
const CLI_PACKAGE_JSON_PATH = (() => {
|
|
135
|
+
try {
|
|
136
|
+
return fileURLToPath(new URL('../package.json', import.meta.url));
|
|
137
|
+
} catch {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
})();
|
|
141
|
+
|
|
142
|
+
const readCliPackageVersion = (): string | undefined => {
|
|
143
|
+
if (!CLI_PACKAGE_JSON_PATH) return undefined;
|
|
144
|
+
try {
|
|
145
|
+
const pkg = JSON.parse(readFileSync(CLI_PACKAGE_JSON_PATH, 'utf8')) as { version?: string };
|
|
146
|
+
return typeof pkg.version === 'string' ? pkg.version : undefined;
|
|
147
|
+
} catch {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// Outside `node_modules` means `yarn dev` or `npm link`: treat as linked. See #7121.
|
|
153
|
+
const isRunningFromLinkedBuild = (): boolean => {
|
|
154
|
+
if (!CLI_PACKAGE_JSON_PATH) return false;
|
|
155
|
+
return !CLI_PACKAGE_JSON_PATH.split(path.sep).includes('node_modules');
|
|
156
|
+
};
|
|
157
|
+
|
|
131
158
|
export const getCliVersion = (): string | undefined => {
|
|
132
|
-
const y = yargs();
|
|
133
|
-
let version = undefined;
|
|
134
|
-
y.showVersion((s) => {
|
|
135
|
-
version = s;
|
|
136
|
-
return false;
|
|
137
|
-
});
|
|
138
159
|
if (process.env.CLI_TEST_MODE === 'true') {
|
|
139
160
|
return 'test-cli';
|
|
140
161
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (version === 'unknown') {
|
|
144
|
-
version = LOCAL_LINKED_CLI_VERSION;
|
|
162
|
+
if (isRunningFromLinkedBuild()) {
|
|
163
|
+
return LOCAL_LINKED_CLI_VERSION;
|
|
145
164
|
}
|
|
146
|
-
return
|
|
165
|
+
return readCliPackageVersion();
|
|
147
166
|
};
|
|
148
167
|
|
|
149
168
|
export const getVersions = (): {
|