@sanity/cli-core 0.0.0-20260505094248 → 0.0.0-20260507114823
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/_exports/index.d.ts
CHANGED
|
@@ -402,10 +402,6 @@ declare type Flags<T extends typeof Command> = Interfaces.InferredFlags<
|
|
|
402
402
|
*
|
|
403
403
|
* If loading fails the cached promise is evicted so the next call retries.
|
|
404
404
|
*
|
|
405
|
-
* Long-lived processes that need to observe edits to `sanity.cli.(ts|js)`
|
|
406
|
-
* (e.g. a dev-server watcher) should use {@link getCliConfigUncached}
|
|
407
|
-
* instead — it bypasses both this in-memory cache and Node's module cache.
|
|
408
|
-
*
|
|
409
405
|
* @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
|
|
410
406
|
* @returns The CLI config
|
|
411
407
|
* @internal
|
|
@@ -424,26 +420,6 @@ export declare function getCliConfig(rootPath: string): Promise<CliConfig>;
|
|
|
424
420
|
*/
|
|
425
421
|
export declare function getCliConfigSync(rootPath: string): CliConfig;
|
|
426
422
|
|
|
427
|
-
/**
|
|
428
|
-
* Read the CLI config for a project from disk, bypassing both the
|
|
429
|
-
* `getCliConfig` in-memory cache and Node's module cache. Each call locates
|
|
430
|
-
* `sanity.cli.(ts|js)`, drops any prior jiti compilation from `require.cache`,
|
|
431
|
-
* re-imports, and re-validates.
|
|
432
|
-
*
|
|
433
|
-
* Use this when the config file is expected to change during the process's
|
|
434
|
-
* lifetime — typically a dev-server watcher that needs the new values picked
|
|
435
|
-
* up after each save. One-shot CLI invocations should prefer
|
|
436
|
-
* {@link getCliConfig} so the prerun hook, SanityCommand helpers, and action
|
|
437
|
-
* files share a single load.
|
|
438
|
-
*
|
|
439
|
-
* @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
|
|
440
|
-
* @returns The freshly loaded CLI config
|
|
441
|
-
* @internal
|
|
442
|
-
*/
|
|
443
|
-
export declare function getCliConfigUncached(
|
|
444
|
-
rootPath: string,
|
|
445
|
-
): Promise<CliConfig>;
|
|
446
|
-
|
|
447
423
|
/**
|
|
448
424
|
* @public
|
|
449
425
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
1
|
import { debug } from '../../debug.js';
|
|
3
2
|
import { NotFoundError } from '../../errors/NotFoundError.js';
|
|
4
3
|
import { importModule } from '../../util/importModule.js';
|
|
@@ -16,10 +15,6 @@ const cache = new Map();
|
|
|
16
15
|
*
|
|
17
16
|
* If loading fails the cached promise is evicted so the next call retries.
|
|
18
17
|
*
|
|
19
|
-
* Long-lived processes that need to observe edits to `sanity.cli.(ts|js)`
|
|
20
|
-
* (e.g. a dev-server watcher) should use {@link getCliConfigUncached}
|
|
21
|
-
* instead — it bypasses both this in-memory cache and Node's module cache.
|
|
22
|
-
*
|
|
23
18
|
* @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
|
|
24
19
|
* @returns The CLI config
|
|
25
20
|
* @internal
|
|
@@ -28,29 +23,14 @@ const cache = new Map();
|
|
|
28
23
|
if (cached) {
|
|
29
24
|
return cached;
|
|
30
25
|
}
|
|
31
|
-
const promise =
|
|
26
|
+
const promise = loadCliConfig(rootPath).catch((err)=>{
|
|
32
27
|
cache.delete(rootPath);
|
|
33
28
|
throw err;
|
|
34
29
|
});
|
|
35
30
|
cache.set(rootPath, promise);
|
|
36
31
|
return promise;
|
|
37
32
|
}
|
|
38
|
-
|
|
39
|
-
* Read the CLI config for a project from disk, bypassing both the
|
|
40
|
-
* `getCliConfig` in-memory cache and Node's module cache. Each call locates
|
|
41
|
-
* `sanity.cli.(ts|js)`, drops any prior jiti compilation from `require.cache`,
|
|
42
|
-
* re-imports, and re-validates.
|
|
43
|
-
*
|
|
44
|
-
* Use this when the config file is expected to change during the process's
|
|
45
|
-
* lifetime — typically a dev-server watcher that needs the new values picked
|
|
46
|
-
* up after each save. One-shot CLI invocations should prefer
|
|
47
|
-
* {@link getCliConfig} so the prerun hook, SanityCommand helpers, and action
|
|
48
|
-
* files share a single load.
|
|
49
|
-
*
|
|
50
|
-
* @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
|
|
51
|
-
* @returns The freshly loaded CLI config
|
|
52
|
-
* @internal
|
|
53
|
-
*/ export async function getCliConfigUncached(rootPath) {
|
|
33
|
+
async function loadCliConfig(rootPath) {
|
|
54
34
|
const paths = await findPathForFiles(rootPath, [
|
|
55
35
|
'sanity.cli.ts',
|
|
56
36
|
'sanity.cli.js'
|
|
@@ -64,12 +44,6 @@ const cache = new Map();
|
|
|
64
44
|
}
|
|
65
45
|
const configPath = configPaths[0].path;
|
|
66
46
|
debug(`Loading CLI config from: ${configPath}`);
|
|
67
|
-
// Drop any cached compilation of this file from Node's CJS module cache
|
|
68
|
-
// (jiti compiles `sanity.cli.ts` to CJS and registers it via `require.cache`).
|
|
69
|
-
// Without this, repeated calls would receive the previously imported module
|
|
70
|
-
// even though the file on disk has changed. No-op on first load.
|
|
71
|
-
const cjsRequire = createRequire(import.meta.url);
|
|
72
|
-
delete cjsRequire.cache[configPath];
|
|
73
47
|
let cliConfig;
|
|
74
48
|
try {
|
|
75
49
|
const result = await importModule(configPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/cli/getCliConfig.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/config/cli/getCliConfig.ts"],"sourcesContent":["import {debug} from '../../debug.js'\nimport {NotFoundError} from '../../errors/NotFoundError.js'\nimport {importModule} from '../../util/importModule.js'\nimport {findPathForFiles} from '../util/findConfigsPaths.js'\nimport {cliConfigSchema} from './schemas.js'\nimport {type CliConfig} from './types/cliConfig.js'\n\nconst cache = new Map<string, Promise<CliConfig>>()\n\n/**\n * Get the CLI config for a project, given the root path.\n *\n * Results are cached in-memory keyed by rootPath for the lifetime of the\n * process. Since the CLI always runs from a single project root, the config\n * won't change during a command's execution, so caching avoids redundant\n * filesystem reads and jiti imports from the prerun hook, SanityCommand\n * helpers, and action files.\n *\n * If loading fails the cached promise is evicted so the next call retries.\n *\n * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.\n * @returns The CLI config\n * @internal\n */\nexport function getCliConfig(rootPath: string): Promise<CliConfig> {\n const cached = cache.get(rootPath)\n if (cached) {\n return cached\n }\n\n const promise = loadCliConfig(rootPath).catch((err) => {\n cache.delete(rootPath)\n throw err\n })\n\n cache.set(rootPath, promise)\n return promise\n}\n\nasync function loadCliConfig(rootPath: string): Promise<CliConfig> {\n const paths = await findPathForFiles(rootPath, ['sanity.cli.ts', 'sanity.cli.js'])\n const configPaths = paths.filter((path) => path.exists)\n\n if (configPaths.length === 0) {\n throw new NotFoundError(`No CLI config found at ${rootPath}/sanity.cli.(ts|js)`)\n }\n\n if (configPaths.length > 1) {\n throw new Error(\n `Multiple CLI config files found (${configPaths.map((path) => path.path).join(', ')})`,\n )\n }\n\n const configPath = configPaths[0].path\n\n debug(`Loading CLI config from: ${configPath}`)\n\n let cliConfig: CliConfig | undefined\n try {\n const result = await importModule<CliConfig>(configPath)\n\n debug('CLI config loaded: %o', result)\n\n cliConfig = result\n } catch (err) {\n debug('Failed to load CLI config in worker thread: %s', err)\n\n throw new Error('CLI config cannot be loaded', {cause: err})\n }\n\n const {data, error, success} = cliConfigSchema.safeParse(cliConfig)\n if (!success) {\n debug(`Invalid CLI config: ${error.message}`)\n throw new Error(`Invalid CLI config: ${error.message}`, {cause: error})\n }\n\n return data\n}\n"],"names":["debug","NotFoundError","importModule","findPathForFiles","cliConfigSchema","cache","Map","getCliConfig","rootPath","cached","get","promise","loadCliConfig","catch","err","delete","set","paths","configPaths","filter","path","exists","length","Error","map","join","configPath","cliConfig","result","cause","data","error","success","safeParse","message"],"mappings":"AAAA,SAAQA,KAAK,QAAO,iBAAgB;AACpC,SAAQC,aAAa,QAAO,gCAA+B;AAC3D,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,gBAAgB,QA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C,MAAM,CAAC,oBAAoB,EAAE+B,MAAMG,OAAO,EAAE;QAC5C,MAAM,IAAIX,MAAM,CAAC,oBAAoB,EAAEQ,MAAMG,OAAO,EAAE,EAAE;YAACL,OAAOE;QAAK;IACvE;IAEA,OAAOD;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-core",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20260507114823",
|
|
4
4
|
"description": "Sanity CLI core package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@sanity/pkg-utils": "^10.4.18",
|
|
78
78
|
"@sanity/telemetry": "^0.9.0",
|
|
79
79
|
"@swc/cli": "^0.8.1",
|
|
80
|
-
"@swc/core": "^1.15.
|
|
80
|
+
"@swc/core": "^1.15.33",
|
|
81
81
|
"@types/debug": "^4.1.13",
|
|
82
82
|
"@types/jsdom": "^28.0.1",
|
|
83
83
|
"@types/node": "^20.19.39",
|