@sanity/cli-core 0.1.0-alpha.18 → 0.1.0-alpha.19

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.d.ts CHANGED
@@ -646,8 +646,9 @@ export declare function importModule<T = unknown>(
646
646
  declare interface ImportModuleOptions {
647
647
  /**
648
648
  * Whether to return the default export of the module.
649
+ * Default: true
649
650
  */
650
- default?: true
651
+ default?: boolean
651
652
  /**
652
653
  * Path to the tsconfig file to use for the import. If not provided, the tsconfig
653
654
  * will be inferred from the nearest `tsconfig.json` file.
@@ -1,5 +1,5 @@
1
- import { CLIError } from '@oclif/core/errors';
2
- import { isTrueish } from './isTrueish.js';
1
+ import { ux } from '@oclif/core';
2
+ import { noopLogger } from '@sanity/telemetry';
3
3
  /**
4
4
  * @public
5
5
  * Symbol used to store the CLI telemetry store on globalThis.
@@ -9,12 +9,10 @@ import { isTrueish } from './isTrueish.js';
9
9
  * @public
10
10
  */ export function getCliTelemetry() {
11
11
  const global = globalThis;
12
- // This should never happen, but just in case.
13
- // Ignore this error in tests to avoid failing tests as tests don't run to
14
- if (!global[CLI_TELEMETRY_SYMBOL] && !isTrueish(process.env.TEST)) {
15
- throw new CLIError('CLI telemetry not initialized', {
16
- exit: 1
17
- });
12
+ // This should never happen, but if it does, we return a noop logger to avoid errors.
13
+ if (!global[CLI_TELEMETRY_SYMBOL]) {
14
+ ux.warn('CLI telemetry not initialized, returning noop logger');
15
+ return noopLogger;
18
16
  }
19
17
  return global[CLI_TELEMETRY_SYMBOL];
20
18
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/getCliTelemetry.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\n\nimport {type CLITelemetryStore} from '../telemetry/types.js'\nimport {isTrueish} from './isTrueish.js'\n\n/**\n * @public\n * Symbol used to store the CLI telemetry store on globalThis.\n * Use `getCliTelemetry()` to access the store instead of accessing this directly.\n */\nexport const CLI_TELEMETRY_SYMBOL = Symbol.for('sanity.cli.telemetry')\n\ntype GlobalWithTelemetry = typeof globalThis & {\n [CLI_TELEMETRY_SYMBOL]?: CLITelemetryStore\n}\n\n/**\n * @public\n */\nexport function getCliTelemetry(): CLITelemetryStore {\n const global = globalThis as GlobalWithTelemetry\n // This should never happen, but just in case.\n // Ignore this error in tests to avoid failing tests as tests don't run to\n if (!global[CLI_TELEMETRY_SYMBOL] && !isTrueish(process.env.TEST)) {\n throw new CLIError('CLI telemetry not initialized', {exit: 1})\n }\n\n return global[CLI_TELEMETRY_SYMBOL] as CLITelemetryStore\n}\n\n/**\n * Sets the global CLI telemetry store.\n * @internal\n */\nexport function setCliTelemetry(telemetry: CLITelemetryStore): void {\n const global = globalThis as GlobalWithTelemetry\n global[CLI_TELEMETRY_SYMBOL] = telemetry\n}\n\n/**\n * Clears the global CLI telemetry store.\n * @internal\n */\nexport function clearCliTelemetry(): void {\n const global = globalThis as GlobalWithTelemetry\n delete global[CLI_TELEMETRY_SYMBOL]\n}\n"],"names":["CLIError","isTrueish","CLI_TELEMETRY_SYMBOL","Symbol","for","getCliTelemetry","global","globalThis","process","env","TEST","exit","setCliTelemetry","telemetry","clearCliTelemetry"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,qBAAoB;AAG3C,SAAQC,SAAS,QAAO,iBAAgB;AAExC;;;;CAIC,GACD,OAAO,MAAMC,uBAAuBC,OAAOC,GAAG,CAAC,wBAAuB;AAMtE;;CAEC,GACD,OAAO,SAASC;IACd,MAAMC,SAASC;IACf,8CAA8C;IAC9C,0EAA0E;IAC1E,IAAI,CAACD,MAAM,CAACJ,qBAAqB,IAAI,CAACD,UAAUO,QAAQC,GAAG,CAACC,IAAI,GAAG;QACjE,MAAM,IAAIV,SAAS,iCAAiC;YAACW,MAAM;QAAC;IAC9D;IAEA,OAAOL,MAAM,CAACJ,qBAAqB;AACrC;AAEA;;;CAGC,GACD,OAAO,SAASU,gBAAgBC,SAA4B;IAC1D,MAAMP,SAASC;IACfD,MAAM,CAACJ,qBAAqB,GAAGW;AACjC;AAEA;;;CAGC,GACD,OAAO,SAASC;IACd,MAAMR,SAASC;IACf,OAAOD,MAAM,CAACJ,qBAAqB;AACrC"}
1
+ {"version":3,"sources":["../../src/util/getCliTelemetry.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {noopLogger} from '@sanity/telemetry'\n\nimport {type CLITelemetryStore} from '../telemetry/types.js'\n\n/**\n * @public\n * Symbol used to store the CLI telemetry store on globalThis.\n * Use `getCliTelemetry()` to access the store instead of accessing this directly.\n */\nexport const CLI_TELEMETRY_SYMBOL = Symbol.for('sanity.cli.telemetry')\n\ntype GlobalWithTelemetry = typeof globalThis & {\n [CLI_TELEMETRY_SYMBOL]?: CLITelemetryStore\n}\n\n/**\n * @public\n */\nexport function getCliTelemetry(): CLITelemetryStore {\n const global = globalThis as GlobalWithTelemetry\n // This should never happen, but if it does, we return a noop logger to avoid errors.\n if (!global[CLI_TELEMETRY_SYMBOL]) {\n ux.warn('CLI telemetry not initialized, returning noop logger')\n return noopLogger\n }\n\n return global[CLI_TELEMETRY_SYMBOL]\n}\n\n/**\n * Sets the global CLI telemetry store.\n * @internal\n */\nexport function setCliTelemetry(telemetry: CLITelemetryStore): void {\n const global = globalThis as GlobalWithTelemetry\n global[CLI_TELEMETRY_SYMBOL] = telemetry\n}\n\n/**\n * Clears the global CLI telemetry store.\n * @internal\n */\nexport function clearCliTelemetry(): void {\n const global = globalThis as GlobalWithTelemetry\n delete global[CLI_TELEMETRY_SYMBOL]\n}\n"],"names":["ux","noopLogger","CLI_TELEMETRY_SYMBOL","Symbol","for","getCliTelemetry","global","globalThis","warn","setCliTelemetry","telemetry","clearCliTelemetry"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAC9B,SAAQC,UAAU,QAAO,oBAAmB;AAI5C;;;;CAIC,GACD,OAAO,MAAMC,uBAAuBC,OAAOC,GAAG,CAAC,wBAAuB;AAMtE;;CAEC,GACD,OAAO,SAASC;IACd,MAAMC,SAASC;IACf,qFAAqF;IACrF,IAAI,CAACD,MAAM,CAACJ,qBAAqB,EAAE;QACjCF,GAAGQ,IAAI,CAAC;QACR,OAAOP;IACT;IAEA,OAAOK,MAAM,CAACJ,qBAAqB;AACrC;AAEA;;;CAGC,GACD,OAAO,SAASO,gBAAgBC,SAA4B;IAC1D,MAAMJ,SAASC;IACfD,MAAM,CAACJ,qBAAqB,GAAGQ;AACjC;AAEA;;;CAGC,GACD,OAAO,SAASC;IACd,MAAML,SAASC;IACf,OAAOD,MAAM,CAACJ,qBAAqB;AACrC"}
@@ -21,9 +21,12 @@ const debug = subdebug('importModule');
21
21
  debug(`Loading module: ${fileURLToPath(fileURL)}`, {
22
22
  tsconfigPath
23
23
  });
24
- return jiti.import(fileURLToPath(fileURL), {
25
- default: returnDefault
26
- });
24
+ const jitiOptions = {};
25
+ // If the default option is true, add it to the jiti options
26
+ if (returnDefault) {
27
+ jitiOptions.default = true;
28
+ }
29
+ return jiti.import(fileURLToPath(fileURL), jitiOptions);
27
30
  }
28
31
 
29
32
  //# sourceMappingURL=importModule.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/importModule.ts"],"sourcesContent":["import {fileURLToPath, pathToFileURL} from 'node:url'\n\nimport {createJiti} from '@rexxars/jiti'\n\nimport {subdebug} from '../debug.js'\n\ninterface ImportModuleOptions {\n /**\n * Whether to return the default export of the module.\n */\n default?: true\n\n /**\n * Path to the tsconfig file to use for the import. If not provided, the tsconfig\n * will be inferred from the nearest `tsconfig.json` file.\n */\n tsconfigPath?: string\n}\n\nconst debug = subdebug('importModule')\n\n/**\n * Imports a module using jiti and returns its exports.\n * This is a thin wrapper around tsx to allow swapping out the underlying implementation in the future if needed.\n *\n * @param filePath - Path to the module to import.\n * @param options - Options for the importModule function.\n * @returns The exported module.\n *\n * @internal\n */\nexport async function importModule<T = unknown>(\n filePath: string | URL,\n options: ImportModuleOptions = {},\n): Promise<T> {\n const {default: returnDefault = true, tsconfigPath} = options\n\n const jiti = createJiti(import.meta.url, {\n debug: debug.enabled,\n tsconfigPaths: typeof tsconfigPath === 'string' ? tsconfigPath : true,\n })\n\n const fileURL = typeof filePath === 'string' ? pathToFileURL(filePath) : filePath\n\n debug(`Loading module: ${fileURLToPath(fileURL)}`, {tsconfigPath})\n\n return jiti.import<T>(fileURLToPath(fileURL), {default: returnDefault})\n}\n"],"names":["fileURLToPath","pathToFileURL","createJiti","subdebug","debug","importModule","filePath","options","default","returnDefault","tsconfigPath","jiti","url","enabled","tsconfigPaths","fileURL","import"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,aAAa,QAAO,WAAU;AAErD,SAAQC,UAAU,QAAO,gBAAe;AAExC,SAAQC,QAAQ,QAAO,cAAa;AAepC,MAAMC,QAAQD,SAAS;AAEvB;;;;;;;;;CASC,GACD,OAAO,eAAeE,aACpBC,QAAsB,EACtBC,UAA+B,CAAC,CAAC;IAEjC,MAAM,EAACC,SAASC,gBAAgB,IAAI,EAAEC,YAAY,EAAC,GAAGH;IAEtD,MAAMI,OAAOT,WAAW,YAAYU,GAAG,EAAE;QACvCR,OAAOA,MAAMS,OAAO;QACpBC,eAAe,OAAOJ,iBAAiB,WAAWA,eAAe;IACnE;IAEA,MAAMK,UAAU,OAAOT,aAAa,WAAWL,cAAcK,YAAYA;IAEzEF,MAAM,CAAC,gBAAgB,EAAEJ,cAAce,UAAU,EAAE;QAACL;IAAY;IAEhE,OAAOC,KAAKK,MAAM,CAAIhB,cAAce,UAAU;QAACP,SAASC;IAAa;AACvE"}
1
+ {"version":3,"sources":["../../src/util/importModule.ts"],"sourcesContent":["import {fileURLToPath, pathToFileURL} from 'node:url'\n\nimport {createJiti, type JitiResolveOptions} from '@rexxars/jiti'\n\nimport {subdebug} from '../debug.js'\n\ninterface ImportModuleOptions {\n /**\n * Whether to return the default export of the module.\n * Default: true\n */\n default?: boolean\n\n /**\n * Path to the tsconfig file to use for the import. If not provided, the tsconfig\n * will be inferred from the nearest `tsconfig.json` file.\n */\n tsconfigPath?: string\n}\n\nconst debug = subdebug('importModule')\n\n/**\n * Imports a module using jiti and returns its exports.\n * This is a thin wrapper around tsx to allow swapping out the underlying implementation in the future if needed.\n *\n * @param filePath - Path to the module to import.\n * @param options - Options for the importModule function.\n * @returns The exported module.\n *\n * @internal\n */\nexport async function importModule<T = unknown>(\n filePath: string | URL,\n options: ImportModuleOptions = {},\n): Promise<T> {\n const {default: returnDefault = true, tsconfigPath} = options\n\n const jiti = createJiti(import.meta.url, {\n debug: debug.enabled,\n tsconfigPaths: typeof tsconfigPath === 'string' ? tsconfigPath : true,\n })\n\n const fileURL = typeof filePath === 'string' ? pathToFileURL(filePath) : filePath\n\n debug(`Loading module: ${fileURLToPath(fileURL)}`, {tsconfigPath})\n\n const jitiOptions: JitiResolveOptions & {default?: true} = {}\n\n // If the default option is true, add it to the jiti options\n if (returnDefault) {\n jitiOptions.default = true\n }\n\n return jiti.import<T>(fileURLToPath(fileURL), jitiOptions)\n}\n"],"names":["fileURLToPath","pathToFileURL","createJiti","subdebug","debug","importModule","filePath","options","default","returnDefault","tsconfigPath","jiti","url","enabled","tsconfigPaths","fileURL","jitiOptions","import"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,aAAa,QAAO,WAAU;AAErD,SAAQC,UAAU,QAAgC,gBAAe;AAEjE,SAAQC,QAAQ,QAAO,cAAa;AAgBpC,MAAMC,QAAQD,SAAS;AAEvB;;;;;;;;;CASC,GACD,OAAO,eAAeE,aACpBC,QAAsB,EACtBC,UAA+B,CAAC,CAAC;IAEjC,MAAM,EAACC,SAASC,gBAAgB,IAAI,EAAEC,YAAY,EAAC,GAAGH;IAEtD,MAAMI,OAAOT,WAAW,YAAYU,GAAG,EAAE;QACvCR,OAAOA,MAAMS,OAAO;QACpBC,eAAe,OAAOJ,iBAAiB,WAAWA,eAAe;IACnE;IAEA,MAAMK,UAAU,OAAOT,aAAa,WAAWL,cAAcK,YAAYA;IAEzEF,MAAM,CAAC,gBAAgB,EAAEJ,cAAce,UAAU,EAAE;QAACL;IAAY;IAEhE,MAAMM,cAAqD,CAAC;IAE5D,4DAA4D;IAC5D,IAAIP,eAAe;QACjBO,YAAYR,OAAO,GAAG;IACxB;IAEA,OAAOG,KAAKM,MAAM,CAAIjB,cAAce,UAAUC;AAChD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-core",
3
- "version": "0.1.0-alpha.18",
3
+ "version": "0.1.0-alpha.19",
4
4
  "description": "Sanity CLI core package",
5
5
  "keywords": [
6
6
  "sanity",
@@ -87,9 +87,9 @@
87
87
  "sanity": "^5.13.0",
88
88
  "typescript": "^5.9.3",
89
89
  "vitest": "^4.0.18",
90
- "@repo/tsconfig": "3.70.0",
91
90
  "@repo/package.config": "0.0.1",
92
- "@sanity/eslint-config-cli": "0.0.0-alpha.4"
91
+ "@sanity/eslint-config-cli": "0.0.0-alpha.4",
92
+ "@repo/tsconfig": "3.70.0"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "@sanity/telemetry": ">=0.8.1 <0.9.0"