@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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LOCAL_LINKED_CLI_VERSION } from '@mintlify/previewing';
|
|
2
|
+
|
|
3
|
+
import { getCliVersion } from '../src/helpers.js';
|
|
4
|
+
|
|
5
|
+
describe('getCliVersion', () => {
|
|
6
|
+
const originalTestMode = process.env.CLI_TEST_MODE;
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
if (originalTestMode === undefined) {
|
|
10
|
+
delete process.env.CLI_TEST_MODE;
|
|
11
|
+
} else {
|
|
12
|
+
process.env.CLI_TEST_MODE = originalTestMode;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('returns a test marker when CLI_TEST_MODE is enabled', () => {
|
|
17
|
+
process.env.CLI_TEST_MODE = 'true';
|
|
18
|
+
expect(getCliVersion()).toBe('test-cli');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it(
|
|
22
|
+
'returns LOCAL_LINKED_CLI_VERSION when running from the monorepo source ' +
|
|
23
|
+
'(not inside node_modules)',
|
|
24
|
+
() => {
|
|
25
|
+
// Source lives outside node_modules, mirroring `npm link` / `yarn dev`. See #7121.
|
|
26
|
+
delete process.env.CLI_TEST_MODE;
|
|
27
|
+
expect(getCliVersion()).toBe(LOCAL_LINKED_CLI_VERSION);
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
});
|
package/bin/helpers.js
CHANGED
|
@@ -14,13 +14,14 @@ import { addLog, ErrorLog, getClientVersion, SuccessLog, InfoLog, SpinnerLog, re
|
|
|
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
|
-
import yargs from 'yargs';
|
|
24
25
|
import { shutdownPostHog } from './telemetry/client.js';
|
|
25
26
|
export const CMD_EXEC_PATH = process.cwd();
|
|
26
27
|
export const checkPort = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -109,22 +110,41 @@ export const upgradeConfig = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
109
110
|
addLog(_jsx(ErrorLog, { message: err instanceof Error ? err.message : 'an unknown error occurred' }));
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
// Resolve the CLI's own package.json via `import.meta.url` so the version is
|
|
114
|
+
// always the one shipped with this package, regardless of cwd. See #7121.
|
|
115
|
+
const CLI_PACKAGE_JSON_PATH = (() => {
|
|
116
|
+
try {
|
|
117
|
+
return fileURLToPath(new URL('../package.json', import.meta.url));
|
|
118
|
+
}
|
|
119
|
+
catch (_a) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
const readCliPackageVersion = () => {
|
|
124
|
+
if (!CLI_PACKAGE_JSON_PATH)
|
|
125
|
+
return undefined;
|
|
126
|
+
try {
|
|
127
|
+
const pkg = JSON.parse(readFileSync(CLI_PACKAGE_JSON_PATH, 'utf8'));
|
|
128
|
+
return typeof pkg.version === 'string' ? pkg.version : undefined;
|
|
129
|
+
}
|
|
130
|
+
catch (_a) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
// Outside `node_modules` means `yarn dev` or `npm link`: treat as linked. See #7121.
|
|
135
|
+
const isRunningFromLinkedBuild = () => {
|
|
136
|
+
if (!CLI_PACKAGE_JSON_PATH)
|
|
117
137
|
return false;
|
|
118
|
-
|
|
138
|
+
return !CLI_PACKAGE_JSON_PATH.split(path.sep).includes('node_modules');
|
|
139
|
+
};
|
|
140
|
+
export const getCliVersion = () => {
|
|
119
141
|
if (process.env.CLI_TEST_MODE === 'true') {
|
|
120
142
|
return 'test-cli';
|
|
121
143
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (version === 'unknown') {
|
|
125
|
-
version = LOCAL_LINKED_CLI_VERSION;
|
|
144
|
+
if (isRunningFromLinkedBuild()) {
|
|
145
|
+
return LOCAL_LINKED_CLI_VERSION;
|
|
126
146
|
}
|
|
127
|
-
return
|
|
147
|
+
return readCliPackageVersion();
|
|
128
148
|
};
|
|
129
149
|
export const getVersions = () => {
|
|
130
150
|
const cli = getCliVersion();
|