@sanity/cli 6.2.0 → 6.3.0
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/README.md +299 -303
- package/dist/SanityHelp.js +38 -0
- package/dist/SanityHelp.js.map +1 -1
- package/dist/actions/auth/login/getProvider.js +9 -4
- package/dist/actions/auth/login/getProvider.js.map +1 -1
- package/dist/actions/auth/login/getSSOProvider.js +21 -2
- package/dist/actions/auth/login/getSSOProvider.js.map +1 -1
- package/dist/actions/auth/login/login.js +5 -4
- package/dist/actions/auth/login/login.js.map +1 -1
- package/dist/actions/build/buildApp.js +1 -0
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStaticFiles.js +2 -1
- package/dist/actions/build/buildStaticFiles.js.map +1 -1
- package/dist/actions/build/renderDocument.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js +2 -2
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/types.js.map +1 -1
- package/dist/actions/build/writeSanityRuntime.js +3 -2
- package/dist/actions/build/writeSanityRuntime.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +53 -3
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/findUserApplicationForStudio.js +10 -4
- package/dist/actions/deploy/findUserApplicationForStudio.js.map +1 -1
- package/dist/actions/dev/startAppDevServer.js +2 -0
- package/dist/actions/dev/startAppDevServer.js.map +1 -1
- package/dist/actions/init/git.js +5 -2
- package/dist/actions/init/git.js.map +1 -1
- package/dist/actions/init/remoteTemplate.js +3 -1
- package/dist/actions/init/remoteTemplate.js.map +1 -1
- package/dist/actions/init/templates/nextjs/index.js +1 -1
- package/dist/actions/init/templates/nextjs/index.js.map +1 -1
- package/dist/actions/manifest/extractAppManifest.js +3 -1
- package/dist/actions/manifest/extractAppManifest.js.map +1 -1
- package/dist/actions/manifest/schemaTypeTransformer.js +2 -1
- package/dist/actions/manifest/schemaTypeTransformer.js.map +1 -1
- package/dist/actions/telemetry/setConsent.js +6 -2
- package/dist/actions/telemetry/setConsent.js.map +1 -1
- package/dist/commands/datasets/alias/create.js +0 -4
- package/dist/commands/datasets/alias/create.js.map +1 -1
- package/dist/commands/datasets/alias/delete.js +1 -5
- package/dist/commands/datasets/alias/delete.js.map +1 -1
- package/dist/commands/datasets/alias/link.js +0 -4
- package/dist/commands/datasets/alias/link.js.map +1 -1
- package/dist/commands/datasets/alias/unlink.js +0 -4
- package/dist/commands/datasets/alias/unlink.js.map +1 -1
- package/dist/commands/datasets/copy.js +1 -1
- package/dist/commands/datasets/copy.js.map +1 -1
- package/dist/commands/datasets/import.js +45 -15
- package/dist/commands/datasets/import.js.map +1 -1
- package/dist/commands/deploy.js +3 -0
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.js +10 -9
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +14 -2
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +6 -8
- package/dist/commands/logout.js.map +1 -1
- package/dist/hooks/prerun/setupTelemetry.js +1 -1
- package/dist/hooks/prerun/setupTelemetry.js.map +1 -1
- package/dist/server/devServer.js +2 -1
- package/dist/server/devServer.js.map +1 -1
- package/dist/services/telemetry.js +23 -2
- package/dist/services/telemetry.js.map +1 -1
- package/dist/util/compareDependencyVersions.js +3 -1
- package/dist/util/compareDependencyVersions.js.map +1 -1
- package/dist/util/createExpiringConfig.js +0 -3
- package/dist/util/createExpiringConfig.js.map +1 -1
- package/dist/util/getCliVersion.js +3 -1
- package/dist/util/getCliVersion.js.map +1 -1
- package/dist/util/packageManager/packageManagerChoice.js +1 -2
- package/dist/util/packageManager/packageManagerChoice.js.map +1 -1
- package/dist/util/telemetry/logger.js +13 -0
- package/dist/util/telemetry/logger.js.map +1 -1
- package/oclif.manifest.json +282 -272
- package/package.json +27 -27
- package/dist/actions/graphql/__tests__/fixtures/many-self-refs.js +0 -540
- package/dist/actions/graphql/__tests__/fixtures/many-self-refs.js.map +0 -1
- package/dist/actions/graphql/__tests__/fixtures/test-studio.js +0 -1143
- package/dist/actions/graphql/__tests__/fixtures/test-studio.js.map +0 -1
- package/dist/actions/graphql/__tests__/fixtures/union-refs.js +0 -591
- package/dist/actions/graphql/__tests__/fixtures/union-refs.js.map +0 -1
- package/dist/actions/graphql/__tests__/helpers.js +0 -23
- package/dist/actions/graphql/__tests__/helpers.js.map +0 -1
- package/dist/actions/manifest/__tests__/resolveSchemaIcon.test.js +0 -157
- package/dist/actions/manifest/__tests__/resolveSchemaIcon.test.js.map +0 -1
- package/dist/actions/media/__tests__/createMockClient.js +0 -32
- package/dist/actions/media/__tests__/createMockClient.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/logout.ts"],"sourcesContent":["import {getCliToken, SanityCommand, setCliUserConfig} from '@sanity/cli-core'\nimport {isHttpError} from '@sanity/client'\n\nimport {logout} from '../services/auth.js'\n\nexport class LogoutCommand extends SanityCommand<typeof LogoutCommand> {\n static override description = 'Logs out the CLI from the current user session'\n\n public async run(): Promise<void> {\n await this.parse(LogoutCommand)\n\n const previousToken = await getCliToken()\n if (!previousToken) {\n this.log('No login credentials found')\n return\n }\n\n try {\n await logout()\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/commands/logout.ts"],"sourcesContent":["import {getCliToken, getUserConfig, SanityCommand, setCliUserConfig} from '@sanity/cli-core'\nimport {isHttpError} from '@sanity/client'\n\nimport {logout} from '../services/auth.js'\n\nexport class LogoutCommand extends SanityCommand<typeof LogoutCommand> {\n static override description = 'Logs out the CLI from the current user session'\n\n public async run(): Promise<void> {\n await this.parse(LogoutCommand)\n\n const previousToken = await getCliToken()\n if (!previousToken) {\n this.log('No login credentials found')\n return\n }\n\n try {\n await logout()\n\n this.clearConfig()\n } catch (error) {\n // In the case of session timeouts or missing sessions, we'll get a 401\n // This is an acceptable situation seen from a logout perspective - all we\n // need to do in this case is clear the session from the view of the CLI\n if (isHttpError(error) && error.response.statusCode === 401) {\n this.clearConfig()\n return\n }\n const err = error instanceof Error ? error : new Error(`${error}`)\n this.error(`Failed to logout: ${err.message}`, {exit: 1})\n }\n }\n\n private clearConfig() {\n setCliUserConfig('authToken', undefined)\n getUserConfig().delete('telemetryConsent')\n\n this.log('Logged out successfully')\n }\n}\n"],"names":["getCliToken","getUserConfig","SanityCommand","setCliUserConfig","isHttpError","logout","LogoutCommand","description","run","parse","previousToken","log","clearConfig","error","response","statusCode","err","Error","message","exit","undefined","delete"],"mappings":"AAAA,SAAQA,WAAW,EAAEC,aAAa,EAAEC,aAAa,EAAEC,gBAAgB,QAAO,mBAAkB;AAC5F,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,MAAM,QAAO,sBAAqB;AAE1C,OAAO,MAAMC,sBAAsBJ;IACjC,OAAgBK,cAAc,iDAAgD;IAE9E,MAAaC,MAAqB;QAChC,MAAM,IAAI,CAACC,KAAK,CAACH;QAEjB,MAAMI,gBAAgB,MAAMV;QAC5B,IAAI,CAACU,eAAe;YAClB,IAAI,CAACC,GAAG,CAAC;YACT;QACF;QAEA,IAAI;YACF,MAAMN;YAEN,IAAI,CAACO,WAAW;QAClB,EAAE,OAAOC,OAAO;YACd,uEAAuE;YACvE,0EAA0E;YAC1E,wEAAwE;YACxE,IAAIT,YAAYS,UAAUA,MAAMC,QAAQ,CAACC,UAAU,KAAK,KAAK;gBAC3D,IAAI,CAACH,WAAW;gBAChB;YACF;YACA,MAAMI,MAAMH,iBAAiBI,QAAQJ,QAAQ,IAAII,MAAM,GAAGJ,OAAO;YACjE,IAAI,CAACA,KAAK,CAAC,CAAC,kBAAkB,EAAEG,IAAIE,OAAO,EAAE,EAAE;gBAACC,MAAM;YAAC;QACzD;IACF;IAEQP,cAAc;QACpBT,iBAAiB,aAAaiB;QAC9BnB,gBAAgBoB,MAAM,CAAC;QAEvB,IAAI,CAACV,GAAG,CAAC;IACX;AACF"}
|
|
@@ -70,7 +70,7 @@ export const setupTelemetry = async function({ config }) {
|
|
|
70
70
|
SANITY_TELEMETRY_PROJECT_ID: cliConfig?.api?.projectId || ''
|
|
71
71
|
},
|
|
72
72
|
// If debug is enabled, spawn the worker with stdio inherit to see the output
|
|
73
|
-
stdio: debug.enabled ? 'inherit' : 'ignore'
|
|
73
|
+
stdio: debug.enabled || telemetryDebug.enabled ? 'inherit' : 'ignore'
|
|
74
74
|
}).unref();
|
|
75
75
|
});
|
|
76
76
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/prerun/setupTelemetry.ts"],"sourcesContent":["import {spawn} from 'node:child_process'\nimport {fileURLToPath} from 'node:url'\n\nimport {type Hook} from '@oclif/core'\nimport {\n type CliConfig,\n debug,\n findProjectRoot,\n getCliConfig,\n setCliTelemetry,\n} from '@sanity/cli-core'\nimport {createSessionId} from '@sanity/telemetry'\n\nimport {resolveConsent} from '../../actions/telemetry/resolveConsent.js'\nimport {telemetryDebug} from '../../actions/telemetry/telemetryDebug.js'\nimport {telemetryDisclosure} from '../../actions/telemetry/telemetryDisclosure.js'\nimport {CliCommandTelemetry, type CLITraceData} from '../../telemetry/cli.telemetry.js'\nimport {detectRuntime} from '../../util/detectRuntime.js'\nimport {parseArguments} from '../../util/parseArguments.js'\nimport {createTelemetryStore} from '../../util/telemetry/createTelemetryStore.js'\n\nexport const setupTelemetry: Hook.Prerun = async function ({config}) {\n // Show telemetry disclosure\n telemetryDisclosure()\n\n const sessionId = createSessionId()\n\n const telemetry = createTelemetryStore(sessionId, {\n resolveConsent,\n })\n\n let cliConfig: CliConfig | undefined\n try {\n const projectRoot = await findProjectRoot(process.cwd())\n cliConfig = await getCliConfig(projectRoot.directory)\n } catch {\n // Accept not finding a project root and/or CLI config\n }\n\n telemetry.updateUserProperties({\n cliVersion: config.version,\n cpuArchitecture: process.arch,\n dataset: cliConfig?.api?.dataset,\n machinePlatform: process.platform,\n projectId: cliConfig?.api?.projectId,\n runtime: detectRuntime(),\n runtimeVersion: process.version,\n })\n\n const args = parseArguments()\n\n const traceOptions: CLITraceData = {\n commandArguments: args.argsWithoutOptions,\n coreOptions: {\n debug: args.coreOptions.debug ?? undefined,\n help: args.coreOptions.help ?? undefined,\n version: args.coreOptions.version ?? undefined,\n },\n extraArguments: args.extraArguments,\n groupOrCommand: args.groupOrCommand,\n }\n\n telemetryDebug('Starting command trace', traceOptions)\n\n const cliCommandTrace = telemetry.trace(CliCommandTelemetry, traceOptions)\n cliCommandTrace.start()\n\n // Set the global telemetry store and trace error reporter\n setCliTelemetry(cliCommandTrace.newContext(args.groupOrCommand), {\n reportTraceError: (error) => cliCommandTrace.error(error),\n })\n\n // Handle process exit - complete trace on success, spawn worker to flush telemetry.\n // On non-zero exit, the trace is either already errored (from SanityCommand.catch)\n // or it was a user abort (SIGINT/ctrl+c) — left incomplete, matching old CLI behavior.\n process.once('exit', (status) => {\n if (status === 0) {\n cliCommandTrace.complete()\n }\n\n const workerPath = fileURLToPath(new URL('flushTelemetry.worker.js', import.meta.url))\n telemetryDebug(`Spawning \"${process.execPath} ${workerPath}\"`)\n\n // Spawn detached worker to flush all telemetry files\n // unref will ensure the child process can keep doing work even after the parent process exits\n spawn(process.execPath, [workerPath], {\n detached: true,\n env: {\n ...process.env,\n SANITY_TELEMETRY_PROJECT_ID: cliConfig?.api?.projectId || '',\n },\n // If debug is enabled, spawn the worker with stdio inherit to see the output\n stdio: debug.enabled ? 'inherit' : 'ignore',\n }).unref()\n })\n}\n"],"names":["spawn","fileURLToPath","debug","findProjectRoot","getCliConfig","setCliTelemetry","createSessionId","resolveConsent","telemetryDebug","telemetryDisclosure","CliCommandTelemetry","detectRuntime","parseArguments","createTelemetryStore","setupTelemetry","config","sessionId","telemetry","cliConfig","projectRoot","process","cwd","directory","updateUserProperties","cliVersion","version","cpuArchitecture","arch","dataset","api","machinePlatform","platform","projectId","runtime","runtimeVersion","args","traceOptions","commandArguments","argsWithoutOptions","coreOptions","undefined","help","extraArguments","groupOrCommand","cliCommandTrace","trace","start","newContext","reportTraceError","error","once","status","complete","workerPath","URL","url","execPath","detached","env","SANITY_TELEMETRY_PROJECT_ID","stdio","enabled","unref"],"mappings":"AAAA,SAAQA,KAAK,QAAO,qBAAoB;AACxC,SAAQC,aAAa,QAAO,WAAU;AAGtC,SAEEC,KAAK,EACLC,eAAe,EACfC,YAAY,EACZC,eAAe,QACV,mBAAkB;AACzB,SAAQC,eAAe,QAAO,oBAAmB;AAEjD,SAAQC,cAAc,QAAO,4CAA2C;AACxE,SAAQC,cAAc,QAAO,4CAA2C;AACxE,SAAQC,mBAAmB,QAAO,iDAAgD;AAClF,SAAQC,mBAAmB,QAA0B,mCAAkC;AACvF,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,cAAc,QAAO,+BAA8B;AAC3D,SAAQC,oBAAoB,QAAO,+CAA8C;AAEjF,OAAO,MAAMC,iBAA8B,eAAgB,EAACC,MAAM,EAAC;IACjE,4BAA4B;IAC5BN;IAEA,MAAMO,YAAYV;IAElB,MAAMW,YAAYJ,qBAAqBG,WAAW;QAChDT;IACF;IAEA,IAAIW;IACJ,IAAI;QACF,MAAMC,cAAc,MAAMhB,gBAAgBiB,QAAQC,GAAG;QACrDH,YAAY,MAAMd,aAAae,YAAYG,SAAS;IACtD,EAAE,OAAM;IACN,sDAAsD;IACxD;IAEAL,UAAUM,oBAAoB,CAAC;QAC7BC,YAAYT,OAAOU,OAAO;QAC1BC,iBAAiBN,QAAQO,IAAI;QAC7BC,SAASV,WAAWW,KAAKD;QACzBE,iBAAiBV,QAAQW,QAAQ;QACjCC,WAAWd,WAAWW,KAAKG;QAC3BC,SAAStB;QACTuB,gBAAgBd,QAAQK,OAAO;IACjC;IAEA,MAAMU,OAAOvB;IAEb,MAAMwB,eAA6B;QACjCC,kBAAkBF,KAAKG,kBAAkB;QACzCC,aAAa;YACXrC,OAAOiC,KAAKI,WAAW,CAACrC,KAAK,IAAIsC;YACjCC,MAAMN,KAAKI,WAAW,CAACE,IAAI,IAAID;YAC/Bf,SAASU,KAAKI,WAAW,CAACd,OAAO,IAAIe;QACvC;QACAE,gBAAgBP,KAAKO,cAAc;QACnCC,gBAAgBR,KAAKQ,cAAc;IACrC;IAEAnC,eAAe,0BAA0B4B;IAEzC,MAAMQ,kBAAkB3B,UAAU4B,KAAK,CAACnC,qBAAqB0B;IAC7DQ,gBAAgBE,KAAK;IAErB,0DAA0D;IAC1DzC,gBAAgBuC,gBAAgBG,UAAU,CAACZ,KAAKQ,cAAc,GAAG;QAC/DK,kBAAkB,CAACC,QAAUL,gBAAgBK,KAAK,CAACA;IACrD;IAEA,oFAAoF;IACpF,mFAAmF;IACnF,uFAAuF;IACvF7B,QAAQ8B,IAAI,CAAC,QAAQ,CAACC;QACpB,IAAIA,WAAW,GAAG;YAChBP,gBAAgBQ,QAAQ;QAC1B;QAEA,MAAMC,aAAapD,cAAc,IAAIqD,IAAI,4BAA4B,YAAYC,GAAG;QACpF/C,eAAe,CAAC,UAAU,EAAEY,QAAQoC,QAAQ,CAAC,CAAC,EAAEH,WAAW,CAAC,CAAC;QAE7D,qDAAqD;QACrD,8FAA8F;QAC9FrD,MAAMoB,QAAQoC,QAAQ,EAAE;YAACH;SAAW,EAAE;YACpCI,UAAU;YACVC,KAAK;gBACH,GAAGtC,QAAQsC,GAAG;gBACdC,6BAA6BzC,WAAWW,KAAKG,aAAa;YAC5D;YACA,6EAA6E;YAC7E4B,OAAO1D,MAAM2D,OAAO,GAAG,YAAY;
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/prerun/setupTelemetry.ts"],"sourcesContent":["import {spawn} from 'node:child_process'\nimport {fileURLToPath} from 'node:url'\n\nimport {type Hook} from '@oclif/core'\nimport {\n type CliConfig,\n debug,\n findProjectRoot,\n getCliConfig,\n setCliTelemetry,\n} from '@sanity/cli-core'\nimport {createSessionId} from '@sanity/telemetry'\n\nimport {resolveConsent} from '../../actions/telemetry/resolveConsent.js'\nimport {telemetryDebug} from '../../actions/telemetry/telemetryDebug.js'\nimport {telemetryDisclosure} from '../../actions/telemetry/telemetryDisclosure.js'\nimport {CliCommandTelemetry, type CLITraceData} from '../../telemetry/cli.telemetry.js'\nimport {detectRuntime} from '../../util/detectRuntime.js'\nimport {parseArguments} from '../../util/parseArguments.js'\nimport {createTelemetryStore} from '../../util/telemetry/createTelemetryStore.js'\n\nexport const setupTelemetry: Hook.Prerun = async function ({config}) {\n // Show telemetry disclosure\n telemetryDisclosure()\n\n const sessionId = createSessionId()\n\n const telemetry = createTelemetryStore(sessionId, {\n resolveConsent,\n })\n\n let cliConfig: CliConfig | undefined\n try {\n const projectRoot = await findProjectRoot(process.cwd())\n cliConfig = await getCliConfig(projectRoot.directory)\n } catch {\n // Accept not finding a project root and/or CLI config\n }\n\n telemetry.updateUserProperties({\n cliVersion: config.version,\n cpuArchitecture: process.arch,\n dataset: cliConfig?.api?.dataset,\n machinePlatform: process.platform,\n projectId: cliConfig?.api?.projectId,\n runtime: detectRuntime(),\n runtimeVersion: process.version,\n })\n\n const args = parseArguments()\n\n const traceOptions: CLITraceData = {\n commandArguments: args.argsWithoutOptions,\n coreOptions: {\n debug: args.coreOptions.debug ?? undefined,\n help: args.coreOptions.help ?? undefined,\n version: args.coreOptions.version ?? undefined,\n },\n extraArguments: args.extraArguments,\n groupOrCommand: args.groupOrCommand,\n }\n\n telemetryDebug('Starting command trace', traceOptions)\n\n const cliCommandTrace = telemetry.trace(CliCommandTelemetry, traceOptions)\n cliCommandTrace.start()\n\n // Set the global telemetry store and trace error reporter\n setCliTelemetry(cliCommandTrace.newContext(args.groupOrCommand), {\n reportTraceError: (error) => cliCommandTrace.error(error),\n })\n\n // Handle process exit - complete trace on success, spawn worker to flush telemetry.\n // On non-zero exit, the trace is either already errored (from SanityCommand.catch)\n // or it was a user abort (SIGINT/ctrl+c) — left incomplete, matching old CLI behavior.\n process.once('exit', (status) => {\n if (status === 0) {\n cliCommandTrace.complete()\n }\n\n const workerPath = fileURLToPath(new URL('flushTelemetry.worker.js', import.meta.url))\n telemetryDebug(`Spawning \"${process.execPath} ${workerPath}\"`)\n\n // Spawn detached worker to flush all telemetry files\n // unref will ensure the child process can keep doing work even after the parent process exits\n spawn(process.execPath, [workerPath], {\n detached: true,\n env: {\n ...process.env,\n SANITY_TELEMETRY_PROJECT_ID: cliConfig?.api?.projectId || '',\n },\n // If debug is enabled, spawn the worker with stdio inherit to see the output\n stdio: debug.enabled || telemetryDebug.enabled ? 'inherit' : 'ignore',\n }).unref()\n })\n}\n"],"names":["spawn","fileURLToPath","debug","findProjectRoot","getCliConfig","setCliTelemetry","createSessionId","resolveConsent","telemetryDebug","telemetryDisclosure","CliCommandTelemetry","detectRuntime","parseArguments","createTelemetryStore","setupTelemetry","config","sessionId","telemetry","cliConfig","projectRoot","process","cwd","directory","updateUserProperties","cliVersion","version","cpuArchitecture","arch","dataset","api","machinePlatform","platform","projectId","runtime","runtimeVersion","args","traceOptions","commandArguments","argsWithoutOptions","coreOptions","undefined","help","extraArguments","groupOrCommand","cliCommandTrace","trace","start","newContext","reportTraceError","error","once","status","complete","workerPath","URL","url","execPath","detached","env","SANITY_TELEMETRY_PROJECT_ID","stdio","enabled","unref"],"mappings":"AAAA,SAAQA,KAAK,QAAO,qBAAoB;AACxC,SAAQC,aAAa,QAAO,WAAU;AAGtC,SAEEC,KAAK,EACLC,eAAe,EACfC,YAAY,EACZC,eAAe,QACV,mBAAkB;AACzB,SAAQC,eAAe,QAAO,oBAAmB;AAEjD,SAAQC,cAAc,QAAO,4CAA2C;AACxE,SAAQC,cAAc,QAAO,4CAA2C;AACxE,SAAQC,mBAAmB,QAAO,iDAAgD;AAClF,SAAQC,mBAAmB,QAA0B,mCAAkC;AACvF,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,cAAc,QAAO,+BAA8B;AAC3D,SAAQC,oBAAoB,QAAO,+CAA8C;AAEjF,OAAO,MAAMC,iBAA8B,eAAgB,EAACC,MAAM,EAAC;IACjE,4BAA4B;IAC5B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,UAAU,EAAEY,QAAQoC,QAAQ,CAAC,CAAC,EAAEH,WAAW,CAAC,CAAC;QAE7D,qDAAqD;QACrD,8FAA8F;QAC9FrD,MAAMoB,QAAQoC,QAAQ,EAAE;YAACH;SAAW,EAAE;YACpCI,UAAU;YACVC,KAAK;gBACH,GAAGtC,QAAQsC,GAAG;gBACdC,6BAA6BzC,WAAWW,KAAKG,aAAa;YAC5D;YACA,6EAA6E;YAC7E4B,OAAO1D,MAAM2D,OAAO,IAAIrD,eAAeqD,OAAO,GAAG,YAAY;QAC/D,GAAGC,KAAK;IACV;AACF,EAAC"}
|
package/dist/server/devServer.js
CHANGED
|
@@ -4,9 +4,10 @@ import { writeSanityRuntime } from '../actions/build/writeSanityRuntime.js';
|
|
|
4
4
|
import { serverDebug } from './serverDebug.js';
|
|
5
5
|
const debug = serverDebug.extend('dev');
|
|
6
6
|
export async function startDevServer(options) {
|
|
7
|
-
const { basePath, cwd, entry, httpHost, httpPort, isApp, reactCompiler, reactStrictMode, schemaExtraction, typegen, vite: extendViteConfig } = options;
|
|
7
|
+
const { appTitle, basePath, cwd, entry, httpHost, httpPort, isApp, reactCompiler, reactStrictMode, schemaExtraction, typegen, vite: extendViteConfig } = options;
|
|
8
8
|
debug('Writing Sanity runtime files');
|
|
9
9
|
const watcher = await writeSanityRuntime({
|
|
10
|
+
appTitle,
|
|
10
11
|
basePath,
|
|
11
12
|
cwd,
|
|
12
13
|
entry,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/server/devServer.ts"],"sourcesContent":["import {CliConfig, type UserViteConfig} from '@sanity/cli-core'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {type FSWatcher} from 'chokidar'\nimport {createServer, type InlineConfig, type ViteDevServer} from 'vite'\n\nimport {extendViteConfigWithUserConfig, getViteConfig} from '../actions/build/getViteConfig.js'\nimport {writeSanityRuntime} from '../actions/build/writeSanityRuntime.js'\nimport {serverDebug} from './serverDebug.js'\n\nconst debug = serverDebug.extend('dev')\n\nexport interface DevServerOptions {\n basePath: string\n cwd: string\n httpPort: number\n\n reactCompiler: ReactCompilerConfig | undefined\n reactStrictMode: boolean\n\n staticPath: string\n\n entry?: string\n httpHost?: string\n isApp?: boolean\n projectName?: string\n schemaExtraction?: CliConfig['schemaExtraction']\n typegen?: CliConfig['typegen']\n vite?: UserViteConfig\n}\n\ninterface DevServer {\n close(): Promise<void>\n server: ViteDevServer\n\n watcher?: FSWatcher\n}\n\nexport async function startDevServer(options: DevServerOptions): Promise<DevServer> {\n const {\n basePath,\n cwd,\n entry,\n httpHost,\n httpPort,\n isApp,\n reactCompiler,\n reactStrictMode,\n schemaExtraction,\n typegen,\n vite: extendViteConfig,\n } = options\n\n debug('Writing Sanity runtime files')\n const watcher = await writeSanityRuntime({\n basePath,\n cwd,\n entry,\n isApp,\n reactStrictMode,\n watch: true,\n })\n\n debug('Resolving vite config')\n const mode = 'development'\n\n let viteConfig: InlineConfig = await getViteConfig({\n basePath,\n cwd,\n isApp,\n mode: 'development',\n reactCompiler,\n schemaExtraction,\n server: {host: httpHost, port: httpPort},\n typegen,\n })\n\n // Extend Vite configuration with user-provided config\n if (extendViteConfig) {\n viteConfig = await extendViteConfigWithUserConfig(\n {command: 'serve', mode},\n viteConfig,\n extendViteConfig,\n )\n }\n\n debug('Creating vite server')\n const server = await createServer(viteConfig)\n\n debug('Listening on specified port')\n await server.listen()\n\n return {\n close: async () => {\n if (watcher) {\n await watcher.close()\n }\n await server.close()\n },\n server,\n watcher,\n }\n}\n"],"names":["createServer","extendViteConfigWithUserConfig","getViteConfig","writeSanityRuntime","serverDebug","debug","extend","startDevServer","options","basePath","cwd","entry","httpHost","httpPort","isApp","reactCompiler","reactStrictMode","schemaExtraction","typegen","vite","extendViteConfig","watcher","watch","mode","viteConfig","server","host","port","command","listen","close"],"mappings":"AAGA,SAAQA,YAAY,QAA8C,OAAM;AAExE,SAAQC,8BAA8B,EAAEC,aAAa,QAAO,oCAAmC;AAC/F,SAAQC,kBAAkB,QAAO,yCAAwC;AACzE,SAAQC,WAAW,QAAO,mBAAkB;AAE5C,MAAMC,QAAQD,YAAYE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/server/devServer.ts"],"sourcesContent":["import {CliConfig, type UserViteConfig} from '@sanity/cli-core'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {type FSWatcher} from 'chokidar'\nimport {createServer, type InlineConfig, type ViteDevServer} from 'vite'\n\nimport {extendViteConfigWithUserConfig, getViteConfig} from '../actions/build/getViteConfig.js'\nimport {writeSanityRuntime} from '../actions/build/writeSanityRuntime.js'\nimport {serverDebug} from './serverDebug.js'\n\nconst debug = serverDebug.extend('dev')\n\nexport interface DevServerOptions {\n basePath: string\n cwd: string\n httpPort: number\n\n reactCompiler: ReactCompilerConfig | undefined\n reactStrictMode: boolean\n\n staticPath: string\n\n appTitle?: string\n entry?: string\n httpHost?: string\n isApp?: boolean\n projectName?: string\n schemaExtraction?: CliConfig['schemaExtraction']\n typegen?: CliConfig['typegen']\n vite?: UserViteConfig\n}\n\ninterface DevServer {\n close(): Promise<void>\n server: ViteDevServer\n\n watcher?: FSWatcher\n}\n\nexport async function startDevServer(options: DevServerOptions): Promise<DevServer> {\n const {\n appTitle,\n basePath,\n cwd,\n entry,\n httpHost,\n httpPort,\n isApp,\n reactCompiler,\n reactStrictMode,\n schemaExtraction,\n typegen,\n vite: extendViteConfig,\n } = options\n\n debug('Writing Sanity runtime files')\n const watcher = await writeSanityRuntime({\n appTitle,\n basePath,\n cwd,\n entry,\n isApp,\n reactStrictMode,\n watch: true,\n })\n\n debug('Resolving vite config')\n const mode = 'development'\n\n let viteConfig: InlineConfig = await getViteConfig({\n basePath,\n cwd,\n isApp,\n mode: 'development',\n reactCompiler,\n schemaExtraction,\n server: {host: httpHost, port: httpPort},\n typegen,\n })\n\n // Extend Vite configuration with user-provided config\n if (extendViteConfig) {\n viteConfig = await extendViteConfigWithUserConfig(\n {command: 'serve', mode},\n viteConfig,\n extendViteConfig,\n )\n }\n\n debug('Creating vite server')\n const server = await createServer(viteConfig)\n\n debug('Listening on specified port')\n await server.listen()\n\n return {\n close: async () => {\n if (watcher) {\n await watcher.close()\n }\n await server.close()\n },\n server,\n watcher,\n }\n}\n"],"names":["createServer","extendViteConfigWithUserConfig","getViteConfig","writeSanityRuntime","serverDebug","debug","extend","startDevServer","options","appTitle","basePath","cwd","entry","httpHost","httpPort","isApp","reactCompiler","reactStrictMode","schemaExtraction","typegen","vite","extendViteConfig","watcher","watch","mode","viteConfig","server","host","port","command","listen","close"],"mappings":"AAGA,SAAQA,YAAY,QAA8C,OAAM;AAExE,SAAQC,8BAA8B,EAAEC,aAAa,QAAO,oCAAmC;AAC/F,SAAQC,kBAAkB,QAAO,yCAAwC;AACzE,SAAQC,WAAW,QAAO,mBAAkB;AAE5C,MAAMC,QAAQD,YAAYE,MAAM,CAAC;AA6BjC,OAAO,eAAeC,eAAeC,OAAyB;IAC5D,MAAM,EACJC,QAAQ,EACRC,QAAQ,EACRC,GAAG,EACHC,KAAK,EACLC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,aAAa,EACbC,eAAe,EACfC,gBAAgB,EAChBC,OAAO,EACPC,MAAMC,gBAAgB,EACvB,GAAGb;IAEJH,MAAM;IACN,MAAMiB,UAAU,MAAMnB,mBAAmB;QACvCM;QACAC;QACAC;QACAC;QACAG;QACAE;QACAM,OAAO;IACT;IAEAlB,MAAM;IACN,MAAMmB,OAAO;IAEb,IAAIC,aAA2B,MAAMvB,cAAc;QACjDQ;QACAC;QACAI;QACAS,MAAM;QACNR;QACAE;QACAQ,QAAQ;YAACC,MAAMd;YAAUe,MAAMd;QAAQ;QACvCK;IACF;IAEA,sDAAsD;IACtD,IAAIE,kBAAkB;QACpBI,aAAa,MAAMxB,+BACjB;YAAC4B,SAAS;YAASL;QAAI,GACvBC,YACAJ;IAEJ;IAEAhB,MAAM;IACN,MAAMqB,SAAS,MAAM1B,aAAayB;IAElCpB,MAAM;IACN,MAAMqB,OAAOI,MAAM;IAEnB,OAAO;QACLC,OAAO;YACL,IAAIT,SAAS;gBACX,MAAMA,QAAQS,KAAK;YACrB;YACA,MAAML,OAAOK,KAAK;QACpB;QACAL;QACAJ;IACF;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { getCliToken, getGlobalCliClient, getUserConfig } from '@sanity/cli-core';
|
|
2
3
|
import { telemetryDebug } from '../actions/telemetry/telemetryDebug.js';
|
|
3
4
|
import { createExpiringConfig } from '../util/createExpiringConfig.js';
|
|
4
5
|
export const TELEMETRY_API_VERSION = 'v2026-01-22';
|
|
@@ -53,15 +54,35 @@ async function getTelemetryConsent() {
|
|
|
53
54
|
}
|
|
54
55
|
export const TELEMETRY_CONSENT_CONFIG_KEY = 'telemetryConsent';
|
|
55
56
|
const FIVE_MINUTES = 1000 * 60 * 5;
|
|
57
|
+
/**
|
|
58
|
+
* Get a token-scoped cache key for telemetry consent. This ensures that switching
|
|
59
|
+
* users (via login/logout) always results in a cache miss, preventing one user
|
|
60
|
+
* from inheriting another user's cached consent status.
|
|
61
|
+
*
|
|
62
|
+
* @param token - The current auth token, or undefined if not logged in
|
|
63
|
+
* @returns A cache key scoped to the token
|
|
64
|
+
*/ export function getTelemetryConsentCacheKey(token) {
|
|
65
|
+
if (!token) {
|
|
66
|
+
return TELEMETRY_CONSENT_CONFIG_KEY;
|
|
67
|
+
}
|
|
68
|
+
const hash = createHash('sha256').update(token).digest('hex').slice(0, 12);
|
|
69
|
+
return `${TELEMETRY_CONSENT_CONFIG_KEY}:${hash}`;
|
|
70
|
+
}
|
|
56
71
|
/**
|
|
57
72
|
* Fetch the telemetry consent status for the current user
|
|
58
73
|
* @returns The telemetry consent status
|
|
59
74
|
*
|
|
60
75
|
* @internal
|
|
61
76
|
*/ export async function fetchTelemetryConsent() {
|
|
77
|
+
const token = await getCliToken();
|
|
78
|
+
const cacheKey = getTelemetryConsentCacheKey(token);
|
|
79
|
+
// NOTE: createExpiringConfig is instantiated on every call, so in-flight request
|
|
80
|
+
// deduplication (via currentFetch) does not work across concurrent calls to
|
|
81
|
+
// fetchTelemetryConsent(). Two concurrent callers will make two HTTP requests.
|
|
82
|
+
// Consider moving to module-level instance if this becomes a bottleneck.
|
|
62
83
|
const telemetryConsentConfig = createExpiringConfig({
|
|
63
84
|
fetchValue: ()=>getTelemetryConsent(),
|
|
64
|
-
key:
|
|
85
|
+
key: cacheKey,
|
|
65
86
|
onCacheHit () {
|
|
66
87
|
telemetryDebug('Retrieved telemetry consent status from cache');
|
|
67
88
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/telemetry.ts"],"sourcesContent":["import {getGlobalCliClient, getUserConfig} from '@sanity/cli-core'\nimport {type TelemetryEvent} from '@sanity/telemetry'\n\nimport {telemetryDebug} from '../actions/telemetry/telemetryDebug.js'\nimport {createExpiringConfig} from '../util/createExpiringConfig.js'\n\nexport const TELEMETRY_API_VERSION = 'v2026-01-22'\n\nexport const VALID_API_STATUSES = ['granted', 'denied', 'unset'] as const\nexport type ValidApiConsentStatus = (typeof VALID_API_STATUSES)[number]\n\nexport async function sendEvents(batch: TelemetryEvent[]) {\n const client = await getGlobalCliClient({\n apiVersion: TELEMETRY_API_VERSION,\n requireUser: true,\n })\n\n const projectId = process.env.SANITY_TELEMETRY_PROJECT_ID\n\n return client.request({\n body: {batch, projectId},\n json: true,\n method: 'POST',\n uri: '/intake/batch',\n })\n}\n\nasync function getTelemetryConsent(): Promise<{\n status: ValidApiConsentStatus\n}> {\n const client = await getGlobalCliClient({\n apiVersion: TELEMETRY_API_VERSION,\n requireUser: false,\n })\n\n return client.request({tag: 'telemetry-consent', uri: '/intake/telemetry-status'})\n}\n\n/**\n * Check if the given status is a valid consent status\n *\n * @param status - The status to check\n * @returns True if the status is valid, false otherwise\n * @internal\n */\nexport function isValidApiConsentStatus(status: string): status is ValidApiConsentStatus {\n return VALID_API_STATUSES.includes(status as ValidApiConsentStatus)\n}\n\n/**\n * Check if the given response is a valid API consent response\n *\n * @param response - The response to check\n * @returns True if the response is valid, false otherwise\n * @internal\n */\nfunction isValidApiConsentResponse(response: unknown): response is {status: ValidApiConsentStatus} {\n return (\n typeof response === 'object' &&\n response !== null &&\n 'status' in response &&\n typeof response.status === 'string' &&\n isValidApiConsentStatus(response.status)\n )\n}\n\nexport const TELEMETRY_CONSENT_CONFIG_KEY = 'telemetryConsent'\nconst FIVE_MINUTES = 1000 * 60 * 5\n\n/**\n * Fetch the telemetry consent status for the current user\n * @returns The telemetry consent status\n *\n * @internal\n */\nexport async function fetchTelemetryConsent(): Promise<{\n status: ValidApiConsentStatus\n}> {\n const telemetryConsentConfig = createExpiringConfig<{\n status: ValidApiConsentStatus\n }>({\n fetchValue: () => getTelemetryConsent(),\n key:
|
|
1
|
+
{"version":3,"sources":["../../src/services/telemetry.ts"],"sourcesContent":["import {createHash} from 'node:crypto'\n\nimport {getCliToken, getGlobalCliClient, getUserConfig} from '@sanity/cli-core'\nimport {type TelemetryEvent} from '@sanity/telemetry'\n\nimport {telemetryDebug} from '../actions/telemetry/telemetryDebug.js'\nimport {createExpiringConfig} from '../util/createExpiringConfig.js'\n\nexport const TELEMETRY_API_VERSION = 'v2026-01-22'\n\nexport const VALID_API_STATUSES = ['granted', 'denied', 'unset'] as const\nexport type ValidApiConsentStatus = (typeof VALID_API_STATUSES)[number]\n\nexport async function sendEvents(batch: TelemetryEvent[]) {\n const client = await getGlobalCliClient({\n apiVersion: TELEMETRY_API_VERSION,\n requireUser: true,\n })\n\n const projectId = process.env.SANITY_TELEMETRY_PROJECT_ID\n\n return client.request({\n body: {batch, projectId},\n json: true,\n method: 'POST',\n uri: '/intake/batch',\n })\n}\n\nasync function getTelemetryConsent(): Promise<{\n status: ValidApiConsentStatus\n}> {\n const client = await getGlobalCliClient({\n apiVersion: TELEMETRY_API_VERSION,\n requireUser: false,\n })\n\n return client.request({tag: 'telemetry-consent', uri: '/intake/telemetry-status'})\n}\n\n/**\n * Check if the given status is a valid consent status\n *\n * @param status - The status to check\n * @returns True if the status is valid, false otherwise\n * @internal\n */\nexport function isValidApiConsentStatus(status: string): status is ValidApiConsentStatus {\n return VALID_API_STATUSES.includes(status as ValidApiConsentStatus)\n}\n\n/**\n * Check if the given response is a valid API consent response\n *\n * @param response - The response to check\n * @returns True if the response is valid, false otherwise\n * @internal\n */\nfunction isValidApiConsentResponse(response: unknown): response is {status: ValidApiConsentStatus} {\n return (\n typeof response === 'object' &&\n response !== null &&\n 'status' in response &&\n typeof response.status === 'string' &&\n isValidApiConsentStatus(response.status)\n )\n}\n\nexport const TELEMETRY_CONSENT_CONFIG_KEY = 'telemetryConsent'\nconst FIVE_MINUTES = 1000 * 60 * 5\n\n/**\n * Get a token-scoped cache key for telemetry consent. This ensures that switching\n * users (via login/logout) always results in a cache miss, preventing one user\n * from inheriting another user's cached consent status.\n *\n * @param token - The current auth token, or undefined if not logged in\n * @returns A cache key scoped to the token\n */\nexport function getTelemetryConsentCacheKey(token: string | undefined): string {\n if (!token) {\n return TELEMETRY_CONSENT_CONFIG_KEY\n }\n\n const hash = createHash('sha256').update(token).digest('hex').slice(0, 12)\n return `${TELEMETRY_CONSENT_CONFIG_KEY}:${hash}`\n}\n\n/**\n * Fetch the telemetry consent status for the current user\n * @returns The telemetry consent status\n *\n * @internal\n */\nexport async function fetchTelemetryConsent(): Promise<{\n status: ValidApiConsentStatus\n}> {\n const token = await getCliToken()\n const cacheKey = getTelemetryConsentCacheKey(token)\n\n // NOTE: createExpiringConfig is instantiated on every call, so in-flight request\n // deduplication (via currentFetch) does not work across concurrent calls to\n // fetchTelemetryConsent(). Two concurrent callers will make two HTTP requests.\n // Consider moving to module-level instance if this becomes a bottleneck.\n const telemetryConsentConfig = createExpiringConfig<{\n status: ValidApiConsentStatus\n }>({\n fetchValue: () => getTelemetryConsent(),\n key: cacheKey,\n onCacheHit() {\n telemetryDebug('Retrieved telemetry consent status from cache')\n },\n onFetch() {\n telemetryDebug('Fetching telemetry consent status...')\n },\n onRevalidate() {\n telemetryDebug('Revalidating cached telemetry consent status...')\n },\n store: getUserConfig(),\n ttl: FIVE_MINUTES,\n validateValue: isValidApiConsentResponse,\n })\n\n return telemetryConsentConfig.get()\n}\n"],"names":["createHash","getCliToken","getGlobalCliClient","getUserConfig","telemetryDebug","createExpiringConfig","TELEMETRY_API_VERSION","VALID_API_STATUSES","sendEvents","batch","client","apiVersion","requireUser","projectId","process","env","SANITY_TELEMETRY_PROJECT_ID","request","body","json","method","uri","getTelemetryConsent","tag","isValidApiConsentStatus","status","includes","isValidApiConsentResponse","response","TELEMETRY_CONSENT_CONFIG_KEY","FIVE_MINUTES","getTelemetryConsentCacheKey","token","hash","update","digest","slice","fetchTelemetryConsent","cacheKey","telemetryConsentConfig","fetchValue","key","onCacheHit","onFetch","onRevalidate","store","ttl","validateValue","get"],"mappings":"AAAA,SAAQA,UAAU,QAAO,cAAa;AAEtC,SAAQC,WAAW,EAAEC,kBAAkB,EAAEC,aAAa,QAAO,mBAAkB;AAG/E,SAAQC,cAAc,QAAO,yCAAwC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AAEpE,OAAO,MAAMC,wBAAwB,cAAa;AAElD,OAAO,MAAMC,qBAAqB;IAAC;IAAW;IAAU;CAAQ,CAAS;AAGzE,OAAO,eAAeC,WAAWC,KAAuB;IACtD,MAAMC,SAAS,MAAMR,mBAAmB;QACtCS,YAAYL;QACZM,aAAa;IACf;IAEA,MAAMC,YAAYC,QAAQC,GAAG,CAACC,2BAA2B;IAEzD,OAAON,OAAOO,OAAO,CAAC;QACpBC,MAAM;YAACT;YAAOI;QAAS;QACvBM,MAAM;QACNC,QAAQ;QACRC,KAAK;IACP;AACF;AAEA,eAAeC;IAGb,MAAMZ,SAAS,MAAMR,mBAAmB;QACtCS,YAAYL;QACZM,aAAa;IACf;IAEA,OAAOF,OAAOO,OAAO,CAAC;QAACM,KAAK;QAAqBF,KAAK;IAA0B;AAClF;AAEA;;;;;;CAMC,GACD,OAAO,SAASG,wBAAwBC,MAAc;IACpD,OAAOlB,mBAAmBmB,QAAQ,CAACD;AACrC;AAEA;;;;;;CAMC,GACD,SAASE,0BAA0BC,QAAiB;IAClD,OACE,OAAOA,aAAa,YACpBA,aAAa,QACb,YAAYA,YACZ,OAAOA,SAASH,MAAM,KAAK,YAC3BD,wBAAwBI,SAASH,MAAM;AAE3C;AAEA,OAAO,MAAMI,+BAA+B,mBAAkB;AAC9D,MAAMC,eAAe,OAAO,KAAK;AAEjC;;;;;;;CAOC,GACD,OAAO,SAASC,4BAA4BC,KAAyB;IACnE,IAAI,CAACA,OAAO;QACV,OAAOH;IACT;IAEA,MAAMI,OAAOjC,WAAW,UAAUkC,MAAM,CAACF,OAAOG,MAAM,CAAC,OAAOC,KAAK,CAAC,GAAG;IACvE,OAAO,GAAGP,6BAA6B,CAAC,EAAEI,MAAM;AAClD;AAEA;;;;;CAKC,GACD,OAAO,eAAeI;IAGpB,MAAML,QAAQ,MAAM/B;IACpB,MAAMqC,WAAWP,4BAA4BC;IAE7C,iFAAiF;IACjF,4EAA4E;IAC5E,+EAA+E;IAC/E,yEAAyE;IACzE,MAAMO,yBAAyBlC,qBAE5B;QACDmC,YAAY,IAAMlB;QAClBmB,KAAKH;QACLI;YACEtC,eAAe;QACjB;QACAuC;YACEvC,eAAe;QACjB;QACAwC;YACExC,eAAe;QACjB;QACAyC,OAAO1C;QACP2C,KAAKhB;QACLiB,eAAepB;IACjB;IAEA,OAAOY,uBAAuBS,GAAG;AACnC"}
|
|
@@ -90,7 +90,9 @@ async function getRemoteResolvedVersion(url, request) {
|
|
|
90
90
|
});
|
|
91
91
|
} catch (err) {
|
|
92
92
|
const message = err instanceof Error ? err.message : String(err);
|
|
93
|
-
throw new Error(`Failed to fetch remote version for ${url}: ${message}
|
|
93
|
+
throw new Error(`Failed to fetch remote version for ${url}: ${message}`, {
|
|
94
|
+
cause: err
|
|
95
|
+
});
|
|
94
96
|
}
|
|
95
97
|
// 302 is expected, but lets also handle 2xx
|
|
96
98
|
if (response.statusCode < 400) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/compareDependencyVersions.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {readPackageJson} from '@sanity/cli-core'\nimport {createRequester} from '@sanity/cli-core/request'\nimport semver from 'semver'\n\nimport {getModuleUrl} from '../actions/build/getAutoUpdatesImportMap.js'\nimport {getLocalPackageVersion} from './getLocalPackageVersion.js'\n\nconst defaultRequester = createRequester({\n middleware: {httpErrors: false, promise: {onlyBody: false}},\n})\n\ninterface CompareDependencyVersions {\n installed: string\n pkg: string\n remote: string\n}\n\nexport interface UnresolvedPrerelease {\n pkg: string\n version: string\n}\n\ninterface CompareDependencyVersionsResult {\n mismatched: Array<CompareDependencyVersions>\n unresolvedPrerelease: Array<UnresolvedPrerelease>\n}\n\ninterface CompareDependencyVersionsOptions {\n /** When provided, uses the app-specific module endpoint instead of the default endpoint. */\n appId?: string\n /** Optional requester for dependency injection (primarily for testing). */\n requester?: typeof defaultRequester\n}\n\n/**\n * @internal\n *\n * Compares the versions of dependencies in the studio or app with their remote versions.\n *\n * This function reads the package.json file in the provided working directory, and compares the versions of the dependencies\n * specified in the `autoUpdatesImports` parameter with their remote versions. If the versions do not match, the dependency is\n * added to a list of failed dependencies, which is returned by the function.\n *\n * The failed dependencies are anything that does not strictly match the remote version.\n * This means that if a version is lower or greater by even a patch it will be marked as failed.\n *\n * @param packages - An array of packages with their name and version to compare against remote.\n * @param workDir - The path to the working directory containing the package.json file.\n * @param options - Optional configuration for version comparison.\n *\n * @returns A promise that resolves to an object containing `mismatched` (packages whose local and remote versions differ)\n * and `unresolvedPrerelease` (packages with prerelease versions that could not be resolved remotely).\n *\n * @throws Throws an error if the remote version of a non-prerelease package cannot be fetched, or if the local version\n * of a package cannot be parsed.\n */\nexport async function compareDependencyVersions(\n packages: {name: string; version: string}[],\n workDir: string,\n {appId, requester = defaultRequester}: CompareDependencyVersionsOptions = {},\n): Promise<CompareDependencyVersionsResult> {\n const manifest = await readPackageJson(path.join(workDir, 'package.json'), {\n skipSchemaValidation: true,\n })\n const dependencies = {...manifest?.dependencies, ...manifest?.devDependencies}\n\n const mismatched: Array<CompareDependencyVersions> = []\n const unresolvedPrerelease: Array<UnresolvedPrerelease> = []\n\n for (const pkg of packages) {\n // Skip packages that are not declared in the local package.json\n if (!dependencies[pkg.name]) {\n continue\n }\n\n const resolvedVersion = await getRemoteResolvedVersion(getModuleUrl(pkg, {appId}), requester)\n\n if (resolvedVersion === null) {\n if (semver.prerelease(pkg.version)) {\n unresolvedPrerelease.push({pkg: pkg.name, version: pkg.version})\n continue\n }\n throw new Error(\n `Failed to resolve remote version for ${pkg.name}@${pkg.version}: package not found`,\n )\n }\n\n const packageVersion = await getLocalPackageVersion(pkg.name, workDir)\n\n const manifestVersion = dependencies[pkg.name]\n\n const installed = semver.coerce(\n packageVersion ? semver.parse(packageVersion) : semver.coerce(manifestVersion),\n )\n\n if (!installed) {\n throw new Error(`Failed to parse installed version for ${pkg.name}`)\n }\n\n if (!semver.eq(resolvedVersion, installed.version)) {\n mismatched.push({\n installed: installed.version,\n pkg: pkg.name,\n remote: resolvedVersion,\n })\n }\n }\n\n return {mismatched, unresolvedPrerelease}\n}\n\nasync function getRemoteResolvedVersion(\n url: string,\n request: typeof defaultRequester,\n): Promise<string | null> {\n let response\n try {\n response = await request({\n maxRedirects: 0,\n method: 'HEAD',\n url,\n })\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`Failed to fetch remote version for ${url}: ${message}
|
|
1
|
+
{"version":3,"sources":["../../src/util/compareDependencyVersions.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {readPackageJson} from '@sanity/cli-core'\nimport {createRequester} from '@sanity/cli-core/request'\nimport semver from 'semver'\n\nimport {getModuleUrl} from '../actions/build/getAutoUpdatesImportMap.js'\nimport {getLocalPackageVersion} from './getLocalPackageVersion.js'\n\nconst defaultRequester = createRequester({\n middleware: {httpErrors: false, promise: {onlyBody: false}},\n})\n\ninterface CompareDependencyVersions {\n installed: string\n pkg: string\n remote: string\n}\n\nexport interface UnresolvedPrerelease {\n pkg: string\n version: string\n}\n\ninterface CompareDependencyVersionsResult {\n mismatched: Array<CompareDependencyVersions>\n unresolvedPrerelease: Array<UnresolvedPrerelease>\n}\n\ninterface CompareDependencyVersionsOptions {\n /** When provided, uses the app-specific module endpoint instead of the default endpoint. */\n appId?: string\n /** Optional requester for dependency injection (primarily for testing). */\n requester?: typeof defaultRequester\n}\n\n/**\n * @internal\n *\n * Compares the versions of dependencies in the studio or app with their remote versions.\n *\n * This function reads the package.json file in the provided working directory, and compares the versions of the dependencies\n * specified in the `autoUpdatesImports` parameter with their remote versions. If the versions do not match, the dependency is\n * added to a list of failed dependencies, which is returned by the function.\n *\n * The failed dependencies are anything that does not strictly match the remote version.\n * This means that if a version is lower or greater by even a patch it will be marked as failed.\n *\n * @param packages - An array of packages with their name and version to compare against remote.\n * @param workDir - The path to the working directory containing the package.json file.\n * @param options - Optional configuration for version comparison.\n *\n * @returns A promise that resolves to an object containing `mismatched` (packages whose local and remote versions differ)\n * and `unresolvedPrerelease` (packages with prerelease versions that could not be resolved remotely).\n *\n * @throws Throws an error if the remote version of a non-prerelease package cannot be fetched, or if the local version\n * of a package cannot be parsed.\n */\nexport async function compareDependencyVersions(\n packages: {name: string; version: string}[],\n workDir: string,\n {appId, requester = defaultRequester}: CompareDependencyVersionsOptions = {},\n): Promise<CompareDependencyVersionsResult> {\n const manifest = await readPackageJson(path.join(workDir, 'package.json'), {\n skipSchemaValidation: true,\n })\n const dependencies = {...manifest?.dependencies, ...manifest?.devDependencies}\n\n const mismatched: Array<CompareDependencyVersions> = []\n const unresolvedPrerelease: Array<UnresolvedPrerelease> = []\n\n for (const pkg of packages) {\n // Skip packages that are not declared in the local package.json\n if (!dependencies[pkg.name]) {\n continue\n }\n\n const resolvedVersion = await getRemoteResolvedVersion(getModuleUrl(pkg, {appId}), requester)\n\n if (resolvedVersion === null) {\n if (semver.prerelease(pkg.version)) {\n unresolvedPrerelease.push({pkg: pkg.name, version: pkg.version})\n continue\n }\n throw new Error(\n `Failed to resolve remote version for ${pkg.name}@${pkg.version}: package not found`,\n )\n }\n\n const packageVersion = await getLocalPackageVersion(pkg.name, workDir)\n\n const manifestVersion = dependencies[pkg.name]\n\n const installed = semver.coerce(\n packageVersion ? semver.parse(packageVersion) : semver.coerce(manifestVersion),\n )\n\n if (!installed) {\n throw new Error(`Failed to parse installed version for ${pkg.name}`)\n }\n\n if (!semver.eq(resolvedVersion, installed.version)) {\n mismatched.push({\n installed: installed.version,\n pkg: pkg.name,\n remote: resolvedVersion,\n })\n }\n }\n\n return {mismatched, unresolvedPrerelease}\n}\n\nasync function getRemoteResolvedVersion(\n url: string,\n request: typeof defaultRequester,\n): Promise<string | null> {\n let response\n try {\n response = await request({\n maxRedirects: 0,\n method: 'HEAD',\n url,\n })\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`Failed to fetch remote version for ${url}: ${message}`, {cause: err})\n }\n\n // 302 is expected, but lets also handle 2xx\n if (response.statusCode < 400) {\n const resolved = response.headers['x-resolved-version']\n if (!resolved) {\n throw new Error(`Missing 'x-resolved-version' header on response from HEAD ${url}`)\n }\n return resolved\n }\n\n if (response.statusCode === 404) {\n return null\n }\n\n throw new Error(`Unexpected HTTP response: ${response.statusCode} ${response.statusMessage}`)\n}\n"],"names":["path","readPackageJson","createRequester","semver","getModuleUrl","getLocalPackageVersion","defaultRequester","middleware","httpErrors","promise","onlyBody","compareDependencyVersions","packages","workDir","appId","requester","manifest","join","skipSchemaValidation","dependencies","devDependencies","mismatched","unresolvedPrerelease","pkg","name","resolvedVersion","getRemoteResolvedVersion","prerelease","version","push","Error","packageVersion","manifestVersion","installed","coerce","parse","eq","remote","url","request","response","maxRedirects","method","err","message","String","cause","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
1
1
|
/**
|
|
2
|
-
* Minimal interface for a config store that supports get/set/delete operations.
|
|
3
|
-
* Compatible with the `configstore` package.
|
|
4
|
-
*/ /**
|
|
5
2
|
* Create a config in the provided config store that expires after the provided TTL.
|
|
6
3
|
*/ export function createExpiringConfig({ fetchValue, key, onCacheHit = ()=>null, onFetch = ()=>null, onRevalidate = ()=>null, store, ttl, validateValue = (value)=>true }) {
|
|
7
4
|
let currentFetch = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/createExpiringConfig.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/util/createExpiringConfig.ts"],"sourcesContent":["import {type ConfigStore} from '@sanity/cli-core'\n\ninterface ExpiringConfigValue {\n updatedAt: number\n value: unknown\n}\n\ninterface ExpiringConfigOptions<Type> {\n /** Fetch value */\n fetchValue: () => Promise<Type> | Type\n /** Config key */\n key: string\n /** Config store */\n store: ConfigStore\n /** TTL (milliseconds) */\n ttl: number\n\n /** Subscribe to cache hit event */\n onCacheHit?: () => void\n /** Subscribe to fetch event */\n onFetch?: () => void\n /** Subscribe to revalidate event */\n onRevalidate?: () => void\n\n /**\n * Assert the fetched value is valid, or throw if invalid.\n * If none is provided, it will always accept the fetched value.\n */\n validateValue?: (value: unknown) => value is Type\n}\n\ninterface ExpiringConfigApi<Type> {\n /**\n * Delete the cached value.\n */\n delete: () => void\n /**\n * Attempt to get the cached value. If there is no cached value, or the cached value has expired,\n * fetch, cache, and return the value.\n */\n get: () => Promise<Type>\n}\n\n/**\n * Create a config in the provided config store that expires after the provided TTL.\n */\nexport function createExpiringConfig<Type>({\n fetchValue,\n key,\n onCacheHit = () => null,\n onFetch = () => null,\n onRevalidate = () => null,\n store,\n ttl,\n validateValue = (value: unknown): value is Type => true,\n}: ExpiringConfigOptions<Type>): ExpiringConfigApi<Type> {\n let currentFetch: Promise<Type> | null = null\n return {\n delete() {\n store.delete(key)\n },\n async get(): Promise<Type> {\n const stored = store.get(key)\n\n if (isExpiringValue(stored)) {\n const {updatedAt, value} = stored\n if (!validateValue(value)) {\n throw new Error('Stored value is invalid')\n }\n\n const hasExpired = Date.now() - updatedAt > ttl\n\n if (!hasExpired) {\n onCacheHit()\n return value\n }\n\n onRevalidate()\n }\n\n // Return existing fetch if one is already in progress\n if (currentFetch) {\n return currentFetch\n }\n\n onFetch()\n\n currentFetch = Promise.resolve(fetchValue())\n const nextValue = await currentFetch\n if (!validateValue(nextValue)) {\n throw new Error('Fetched value is invalid')\n }\n\n currentFetch = null\n\n store.set(key, {\n updatedAt: Date.now(),\n value: nextValue,\n })\n\n return nextValue\n },\n }\n}\n\n/**\n * Checks if the given stored value is valid (does not check if expired, only verified shape)\n *\n * @param stored - The stored value to check\n * @returns True if the stored value is valid\n * @internal\n */\nfunction isExpiringValue(stored: unknown): stored is ExpiringConfigValue {\n if (typeof stored !== 'object' || stored === null || Array.isArray(stored)) {\n return false\n }\n\n if (!('updatedAt' in stored) || typeof stored.updatedAt !== 'number') {\n return false\n }\n\n if (!('value' in stored)) {\n return false\n }\n\n return true\n}\n"],"names":["createExpiringConfig","fetchValue","key","onCacheHit","onFetch","onRevalidate","store","ttl","validateValue","value","currentFetch","delete","get","stored","isExpiringValue","updatedAt","Error","hasExpired","Date","now","Promise","resolve","nextValue","set","Array","isArray"],"mappings":"AA2CA;;CAEC,GACD,OAAO,SAASA,qBAA2B,EACzCC,UAAU,EACVC,GAAG,EACHC,aAAa,IAAM,IAAI,EACvBC,UAAU,IAAM,IAAI,EACpBC,eAAe,IAAM,IAAI,EACzBC,KAAK,EACLC,GAAG,EACHC,gBAAgB,CAACC,QAAkC,IAAI,EAC3B;IAC5B,IAAIC,eAAqC;IACzC,OAAO;QACLC;YACEL,MAAMK,MAAM,CAACT;QACf;QACA,MAAMU;YACJ,MAAMC,SAASP,MAAMM,GAAG,CAACV;YAEzB,IAAIY,gBAAgBD,SAAS;gBAC3B,MAAM,EAACE,SAAS,EAAEN,KAAK,EAAC,GAAGI;gBAC3B,IAAI,CAACL,cAAcC,QAAQ;oBACzB,MAAM,IAAIO,MAAM;gBAClB;gBAEA,MAAMC,aAAaC,KAAKC,GAAG,KAAKJ,YAAYR;gBAE5C,IAAI,CAACU,YAAY;oBACfd;oBACA,OAAOM;gBACT;gBAEAJ;YACF;YAEA,sDAAsD;YACtD,IAAIK,cAAc;gBAChB,OAAOA;YACT;YAEAN;YAEAM,eAAeU,QAAQC,OAAO,CAACpB;YAC/B,MAAMqB,YAAY,MAAMZ;YACxB,IAAI,CAACF,cAAcc,YAAY;gBAC7B,MAAM,IAAIN,MAAM;YAClB;YAEAN,eAAe;YAEfJ,MAAMiB,GAAG,CAACrB,KAAK;gBACba,WAAWG,KAAKC,GAAG;gBACnBV,OAAOa;YACT;YAEA,OAAOA;QACT;IACF;AACF;AAEA;;;;;;CAMC,GACD,SAASR,gBAAgBD,MAAe;IACtC,IAAI,OAAOA,WAAW,YAAYA,WAAW,QAAQW,MAAMC,OAAO,CAACZ,SAAS;QAC1E,OAAO;IACT;IAEA,IAAI,CAAE,CAAA,eAAeA,MAAK,KAAM,OAAOA,OAAOE,SAAS,KAAK,UAAU;QACpE,OAAO;IACT;IAEA,IAAI,CAAE,CAAA,WAAWF,MAAK,GAAI;QACxB,OAAO;IACT;IAEA,OAAO;AACT"}
|
|
@@ -20,7 +20,9 @@ import { packageDirectory } from 'package-directory';
|
|
|
20
20
|
try {
|
|
21
21
|
pkg = await readPackageJson(path.join(cliPath, 'package.json'));
|
|
22
22
|
} catch (err) {
|
|
23
|
-
throw new Error(`Unable to read @sanity/cli/package.json: ${err.message}
|
|
23
|
+
throw new Error(`Unable to read @sanity/cli/package.json: ${err.message}`, {
|
|
24
|
+
cause: err
|
|
25
|
+
});
|
|
24
26
|
}
|
|
25
27
|
return pkg.version;
|
|
26
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/getCliVersion.ts"],"sourcesContent":["import path from 'node:path'\nimport {fileURLToPath} from 'node:url'\n\nimport {type PackageJson, readPackageJson} from '@sanity/cli-core'\nimport {packageDirectory} from 'package-directory'\n\n/**\n * Get the version of the `@sanity/cli` package.\n *\n * @internal\n * @returns The version of the `@sanity/cli` package.\n */\nexport async function getCliVersion(): Promise<string> {\n // using the meta.url will resolve to the code running from the cli\n // this will find the package.json in cli package.\n const cliPath = await packageDirectory({cwd: fileURLToPath(import.meta.url)})\n if (!cliPath) {\n throw new Error('Unable to resolve root of @sanity/cli module')\n }\n\n let pkg: PackageJson | undefined\n try {\n pkg = await readPackageJson(path.join(cliPath, 'package.json'))\n } catch (err) {\n throw new Error(`Unable to read @sanity/cli/package.json: ${(err as Error).message}
|
|
1
|
+
{"version":3,"sources":["../../src/util/getCliVersion.ts"],"sourcesContent":["import path from 'node:path'\nimport {fileURLToPath} from 'node:url'\n\nimport {type PackageJson, readPackageJson} from '@sanity/cli-core'\nimport {packageDirectory} from 'package-directory'\n\n/**\n * Get the version of the `@sanity/cli` package.\n *\n * @internal\n * @returns The version of the `@sanity/cli` package.\n */\nexport async function getCliVersion(): Promise<string> {\n // using the meta.url will resolve to the code running from the cli\n // this will find the package.json in cli package.\n const cliPath = await packageDirectory({cwd: fileURLToPath(import.meta.url)})\n if (!cliPath) {\n throw new Error('Unable to resolve root of @sanity/cli module')\n }\n\n let pkg: PackageJson | undefined\n try {\n pkg = await readPackageJson(path.join(cliPath, 'package.json'))\n } catch (err) {\n throw new Error(`Unable to read @sanity/cli/package.json: ${(err as Error).message}`, {\n cause: err,\n })\n }\n\n return pkg.version\n}\n"],"names":["path","fileURLToPath","readPackageJson","packageDirectory","getCliVersion","cliPath","cwd","url","Error","pkg","join","err","message","cause","version"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAC5B,SAAQC,aAAa,QAAO,WAAU;AAEtC,SAA0BC,eAAe,QAAO,mBAAkB;AAClE,SAAQC,gBAAgB,QAAO,oBAAmB;AAElD;;;;;CAKC,GACD,OAAO,eAAeC;IACpB,mEAAmE;IACnE,kDAAkD;IAClD,MAAMC,UAAU,MAAMF,iBAAiB;QAACG,KAAKL,cAAc,YAAYM,GAAG;IAAC;IAC3E,IAAI,CAACF,SAAS;QACZ,MAAM,IAAIG,MAAM;IAClB;IAEA,IAAIC;IACJ,IAAI;QACFA,MAAM,MAAMP,gBAAgBF,KAAKU,IAAI,CAACL,SAAS;IACjD,EAAE,OAAOM,KAAK;QACZ,MAAM,IAAIH,MAAM,CAAC,yCAAyC,EAAE,AAACG,IAAcC,OAAO,EAAE,EAAE;YACpFC,OAAOF;QACT;IACF;IAEA,OAAOF,IAAIK,OAAO;AACpB"}
|
|
@@ -2,8 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { isInteractive } from '@sanity/cli-core';
|
|
3
3
|
import { getRunningPackageManager } from '@sanity/cli-core/package-manager';
|
|
4
4
|
import { select } from '@sanity/cli-core/ux';
|
|
5
|
-
|
|
6
|
-
import { default as preferredPM } from 'preferred-pm';
|
|
5
|
+
import { preferredPM } from 'preferred-pm';
|
|
7
6
|
import which from 'which';
|
|
8
7
|
const EXPERIMENTAL = new Set([
|
|
9
8
|
'bun'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/util/packageManager/packageManagerChoice.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {isInteractive} from '@sanity/cli-core'\nimport {getRunningPackageManager} from '@sanity/cli-core/package-manager'\nimport {select} from '@sanity/cli-core/ux'\n// eslint-disable-next-line unicorn/no-named-default\nimport {default as preferredPM} from 'preferred-pm'\nimport which from 'which'\n\nexport type PackageManager = 'bun' | 'manual' | 'npm' | 'pnpm' | 'yarn'\n\nconst EXPERIMENTAL = new Set(['bun'])\n\nexport const ALLOWED_PACKAGE_MANAGERS: readonly PackageManager[] = [\n 'npm',\n 'yarn',\n 'pnpm',\n 'bun',\n 'manual',\n] as const\n\nexport const allowedPackageManagersString = ALLOWED_PACKAGE_MANAGERS.join(' | ')\n\n/**\n * Attempts to resolve the most optimal package manager to use to install/upgrade\n * packages/dependencies at a given path. It does so by looking for package manager\n * specific lockfiles. If it finds a lockfile belonging to a certain package manager,\n * it prioritizes this one. However, if that package manager is not installed, it will\n * prompt the user for which one they want to use and hint at the most optimal one\n * not being installed.\n *\n * Note that this function also takes local npm binary paths into account - for instance,\n * `yarn` can be installed as a dependency of the project instead of globally, and it\n * will use that is available.\n *\n * The user can also select 'manual' to skip the process and run their preferred package\n * manager manually. Commands using this function must take this `manual` choice into\n * account and act accordingly if chosen.\n *\n * @param workDir - The working directory where a lockfile is most likely to be present\n * @param options - Pass `interactive: false` to fall back to npm if most optimal is\n * not available, instead of prompting\n * @returns Object of `chosen` and, if a lockfile is found, the `mostOptimal` choice\n */\nexport async function getPackageManagerChoice(\n workDir: string,\n options: {interactive: boolean},\n): Promise<{chosen: PackageManager; mostOptimal?: PackageManager}> {\n const rootDir = workDir || process.cwd()\n const preferred = (await preferredPM(rootDir))?.name\n\n if (preferred && (await hasCommand(preferred, rootDir))) {\n // There is an optimal/preferred package manager, and the user has it installed!\n return {chosen: preferred, mostOptimal: preferred}\n }\n\n const mostLikelyPM = await getMostLikelyInstalledPackageManager(rootDir)\n const interactive =\n typeof options.interactive === 'boolean' ? options.interactive : isInteractive()\n if (!interactive) {\n // We can't ask the user for their preference, so fall back to either the one that is being run\n // or whatever is installed on the system (npm being the preferred choice).\n // Note that the most optimal choice is already picked above if available.\n return {chosen: mostLikelyPM || (await getFallback(rootDir)), mostOptimal: preferred}\n }\n\n // We can ask the user for their preference, hurray!\n const messageSuffix = preferred ? ` (preferred is ${preferred}, but is not installed)` : ''\n const installed = await getAvailablePackageManagers(rootDir)\n const chosen = await select<PackageManager>({\n choices: installed.map((pm) => ({\n name: EXPERIMENTAL.has(pm) ? `${pm} (experimental)` : pm,\n value: pm,\n })),\n default: preferred || mostLikelyPM,\n message: `Package manager to use for installing dependencies?${messageSuffix}`,\n })\n\n return {chosen, mostOptimal: preferred}\n}\n\nasync function getFallback(cwd: string): Promise<PackageManager> {\n if (await hasNpmInstalled(cwd)) {\n return 'npm'\n }\n\n if (await hasYarnInstalled(cwd)) {\n return 'yarn'\n }\n\n if (await hasPnpmInstalled(cwd)) {\n return 'pnpm'\n }\n\n if (await hasBunInstalled(cwd)) {\n return 'bun'\n }\n\n return 'manual'\n}\n\nasync function getAvailablePackageManagers(cwd: string): Promise<PackageManager[]> {\n const [npm, yarn, pnpm, bun] = await Promise.all([\n hasNpmInstalled(cwd),\n hasYarnInstalled(cwd),\n hasPnpmInstalled(cwd),\n hasBunInstalled(cwd),\n ])\n\n const choices = [npm && 'npm', yarn && 'yarn', pnpm && 'pnpm', bun && 'bun', 'manual']\n return choices.filter((pm): pm is PackageManager => pm !== false)\n}\n\nfunction hasNpmInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('npm', cwd)\n}\n\nfunction hasYarnInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('yarn', cwd)\n}\n\nfunction hasPnpmInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('pnpm', cwd)\n}\n\nfunction hasBunInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('bun', cwd)\n}\n\nfunction getNpmRunPath(cwd: string): string {\n let previous\n let cwdPath = path.resolve(cwd)\n const result: string[] = []\n\n while (previous !== cwdPath) {\n result.push(path.join(cwdPath, 'node_modules', '.bin'))\n previous = cwdPath\n cwdPath = path.resolve(cwdPath, '..')\n }\n\n result.push(path.resolve(cwd, process.execPath, '..'))\n\n const pathEnv = process.env[getPathEnvVarKey()]\n return [...result, pathEnv].join(path.delimiter)\n}\n\nexport function getPartialEnvWithNpmPath(cwd: string): NodeJS.ProcessEnv {\n const key = getPathEnvVarKey()\n return {[key]: getNpmRunPath(cwd)}\n}\n\nfunction getPathEnvVarKey(): string {\n if (process.platform !== 'win32') {\n return 'PATH'\n }\n\n return (\n Object.keys(process.env)\n .toReversed()\n .find((key) => key.toUpperCase() === 'PATH') || 'Path'\n )\n}\n\nfunction getCommandPath(cmd: string, cwd?: string): Promise<string | null> {\n const options = cwd ? {path: getNpmRunPath(cwd)} : undefined\n return which(cmd, options).catch(() => null)\n}\n\nfunction hasCommand(cmd: string, cwd?: string): Promise<boolean> {\n return getCommandPath(cmd, cwd).then((cmdPath) => cmdPath !== null)\n}\n\nasync function getMostLikelyInstalledPackageManager(\n rootDir: string,\n): Promise<PackageManager | undefined> {\n const installed = await getAvailablePackageManagers(rootDir)\n const running = getRunningPackageManager()\n return running && installed.includes(running) ? running : undefined\n}\n"],"names":["path","isInteractive","getRunningPackageManager","select","default","preferredPM","which","EXPERIMENTAL","Set","ALLOWED_PACKAGE_MANAGERS","allowedPackageManagersString","join","getPackageManagerChoice","workDir","options","rootDir","process","cwd","preferred","name","hasCommand","chosen","mostOptimal","mostLikelyPM","getMostLikelyInstalledPackageManager","interactive","getFallback","messageSuffix","installed","getAvailablePackageManagers","choices","map","pm","has","value","message","hasNpmInstalled","hasYarnInstalled","hasPnpmInstalled","hasBunInstalled","npm","yarn","pnpm","bun","Promise","all","filter","getNpmRunPath","previous","cwdPath","resolve","result","push","execPath","pathEnv","env","getPathEnvVarKey","delimiter","getPartialEnvWithNpmPath","key","platform","Object","keys","toReversed","find","toUpperCase","getCommandPath","cmd","undefined","catch","then","cmdPath","running","includes"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,aAAa,QAAO,mBAAkB;AAC9C,SAAQC,wBAAwB,QAAO,mCAAkC;AACzE,SAAQC,MAAM,QAAO,sBAAqB;AAC1C,oDAAoD;AACpD,SAAQC,WAAWC,WAAW,QAAO,eAAc;AACnD,OAAOC,WAAW,QAAO;AAIzB,MAAMC,eAAe,IAAIC,IAAI;IAAC;CAAM;AAEpC,OAAO,MAAMC,2BAAsD;IACjE;IACA;IACA;IACA;IACA;CACD,CAAS;AAEV,OAAO,MAAMC,+BAA+BD,yBAAyBE,IAAI,CAAC,OAAM;AAEhF;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,eAAeC,wBACpBC,OAAe,EACfC,OAA+B;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AG,EACpBQ,UAAU,GACVC,IAAI,CAAC,CAACL,MAAQA,IAAIM,WAAW,OAAO,WAAW;AAEtD;AAEA,SAASC,eAAeC,GAAW,EAAElD,GAAY;IAC/C,MAAMH,UAAUG,MAAM;QAACjB,MAAM+C,cAAc9B;IAAI,IAAImD;IACnD,OAAO9D,MAAM6D,KAAKrD,SAASuD,KAAK,CAAC,IAAM;AACzC;AAEA,SAASjD,WAAW+C,GAAW,EAAElD,GAAY;IAC3C,OAAOiD,eAAeC,KAAKlD,KAAKqD,IAAI,CAAC,CAACC,UAAYA,YAAY;AAChE;AAEA,eAAe/C,qCACbT,OAAe;IAEf,MAAMa,YAAY,MAAMC,4BAA4Bd;IACpD,MAAMyD,UAAUtE;IAChB,OAAOsE,WAAW5C,UAAU6C,QAAQ,CAACD,WAAWA,UAAUJ;AAC5D"}
|
|
1
|
+
{"version":3,"sources":["../../../src/util/packageManager/packageManagerChoice.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {isInteractive} from '@sanity/cli-core'\nimport {getRunningPackageManager} from '@sanity/cli-core/package-manager'\nimport {select} from '@sanity/cli-core/ux'\nimport {preferredPM} from 'preferred-pm'\nimport which from 'which'\n\nexport type PackageManager = 'bun' | 'manual' | 'npm' | 'pnpm' | 'yarn'\n\nconst EXPERIMENTAL = new Set(['bun'])\n\nexport const ALLOWED_PACKAGE_MANAGERS: readonly PackageManager[] = [\n 'npm',\n 'yarn',\n 'pnpm',\n 'bun',\n 'manual',\n] as const\n\nexport const allowedPackageManagersString = ALLOWED_PACKAGE_MANAGERS.join(' | ')\n\n/**\n * Attempts to resolve the most optimal package manager to use to install/upgrade\n * packages/dependencies at a given path. It does so by looking for package manager\n * specific lockfiles. If it finds a lockfile belonging to a certain package manager,\n * it prioritizes this one. However, if that package manager is not installed, it will\n * prompt the user for which one they want to use and hint at the most optimal one\n * not being installed.\n *\n * Note that this function also takes local npm binary paths into account - for instance,\n * `yarn` can be installed as a dependency of the project instead of globally, and it\n * will use that is available.\n *\n * The user can also select 'manual' to skip the process and run their preferred package\n * manager manually. Commands using this function must take this `manual` choice into\n * account and act accordingly if chosen.\n *\n * @param workDir - The working directory where a lockfile is most likely to be present\n * @param options - Pass `interactive: false` to fall back to npm if most optimal is\n * not available, instead of prompting\n * @returns Object of `chosen` and, if a lockfile is found, the `mostOptimal` choice\n */\nexport async function getPackageManagerChoice(\n workDir: string,\n options: {interactive: boolean},\n): Promise<{chosen: PackageManager; mostOptimal?: PackageManager}> {\n const rootDir = workDir || process.cwd()\n const preferred = (await preferredPM(rootDir))?.name\n\n if (preferred && (await hasCommand(preferred, rootDir))) {\n // There is an optimal/preferred package manager, and the user has it installed!\n return {chosen: preferred, mostOptimal: preferred}\n }\n\n const mostLikelyPM = await getMostLikelyInstalledPackageManager(rootDir)\n const interactive =\n typeof options.interactive === 'boolean' ? options.interactive : isInteractive()\n if (!interactive) {\n // We can't ask the user for their preference, so fall back to either the one that is being run\n // or whatever is installed on the system (npm being the preferred choice).\n // Note that the most optimal choice is already picked above if available.\n return {chosen: mostLikelyPM || (await getFallback(rootDir)), mostOptimal: preferred}\n }\n\n // We can ask the user for their preference, hurray!\n const messageSuffix = preferred ? ` (preferred is ${preferred}, but is not installed)` : ''\n const installed = await getAvailablePackageManagers(rootDir)\n const chosen = await select<PackageManager>({\n choices: installed.map((pm) => ({\n name: EXPERIMENTAL.has(pm) ? `${pm} (experimental)` : pm,\n value: pm,\n })),\n default: preferred || mostLikelyPM,\n message: `Package manager to use for installing dependencies?${messageSuffix}`,\n })\n\n return {chosen, mostOptimal: preferred}\n}\n\nasync function getFallback(cwd: string): Promise<PackageManager> {\n if (await hasNpmInstalled(cwd)) {\n return 'npm'\n }\n\n if (await hasYarnInstalled(cwd)) {\n return 'yarn'\n }\n\n if (await hasPnpmInstalled(cwd)) {\n return 'pnpm'\n }\n\n if (await hasBunInstalled(cwd)) {\n return 'bun'\n }\n\n return 'manual'\n}\n\nasync function getAvailablePackageManagers(cwd: string): Promise<PackageManager[]> {\n const [npm, yarn, pnpm, bun] = await Promise.all([\n hasNpmInstalled(cwd),\n hasYarnInstalled(cwd),\n hasPnpmInstalled(cwd),\n hasBunInstalled(cwd),\n ])\n\n const choices = [npm && 'npm', yarn && 'yarn', pnpm && 'pnpm', bun && 'bun', 'manual']\n return choices.filter((pm): pm is PackageManager => pm !== false)\n}\n\nfunction hasNpmInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('npm', cwd)\n}\n\nfunction hasYarnInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('yarn', cwd)\n}\n\nfunction hasPnpmInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('pnpm', cwd)\n}\n\nfunction hasBunInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('bun', cwd)\n}\n\nfunction getNpmRunPath(cwd: string): string {\n let previous\n let cwdPath = path.resolve(cwd)\n const result: string[] = []\n\n while (previous !== cwdPath) {\n result.push(path.join(cwdPath, 'node_modules', '.bin'))\n previous = cwdPath\n cwdPath = path.resolve(cwdPath, '..')\n }\n\n result.push(path.resolve(cwd, process.execPath, '..'))\n\n const pathEnv = process.env[getPathEnvVarKey()]\n return [...result, pathEnv].join(path.delimiter)\n}\n\nexport function getPartialEnvWithNpmPath(cwd: string): NodeJS.ProcessEnv {\n const key = getPathEnvVarKey()\n return {[key]: getNpmRunPath(cwd)}\n}\n\nfunction getPathEnvVarKey(): string {\n if (process.platform !== 'win32') {\n return 'PATH'\n }\n\n return (\n Object.keys(process.env)\n .toReversed()\n .find((key) => key.toUpperCase() === 'PATH') || 'Path'\n )\n}\n\nfunction getCommandPath(cmd: string, cwd?: string): Promise<string | null> {\n const options = cwd ? {path: getNpmRunPath(cwd)} : undefined\n return which(cmd, options).catch(() => null)\n}\n\nfunction hasCommand(cmd: string, cwd?: string): Promise<boolean> {\n return getCommandPath(cmd, cwd).then((cmdPath) => cmdPath !== null)\n}\n\nasync function getMostLikelyInstalledPackageManager(\n rootDir: string,\n): Promise<PackageManager | undefined> {\n const installed = await getAvailablePackageManagers(rootDir)\n const running = getRunningPackageManager()\n return running && installed.includes(running) ? running : undefined\n}\n"],"names":["path","isInteractive","getRunningPackageManager","select","preferredPM","which","EXPERIMENTAL","Set","ALLOWED_PACKAGE_MANAGERS","allowedPackageManagersString","join","getPackageManagerChoice","workDir","options","rootDir","process","cwd","preferred","name","hasCommand","chosen","mostOptimal","mostLikelyPM","getMostLikelyInstalledPackageManager","interactive","getFallback","messageSuffix","installed","getAvailablePackageManagers","choices","map","pm","has","value","default","message","hasNpmInstalled","hasYarnInstalled","hasPnpmInstalled","hasBunInstalled","npm","yarn","pnpm","bun","Promise","all","filter","getNpmRunPath","previous","cwdPath","resolve","result","push","execPath","pathEnv","env","getPathEnvVarKey","delimiter","getPartialEnvWithNpmPath","key","platform","Object","keys","toReversed","find","toUpperCase","getCommandPath","cmd","undefined","catch","then","cmdPath","running","includes"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,aAAa,QAAO,mBAAkB;AAC9C,SAAQC,wBAAwB,QAAO,mCAAkC;AACzE,SAAQC,MAAM,QAAO,sBAAqB;AAC1C,SAAQC,WAAW,QAAO,eAAc;AACxC,OAAOC,WAAW,QAAO;AAIzB,MAAMC,eAAe,IAAIC,IAAI;IAAC;CAAM;AAEpC,OAAO,MAAMC,2BAAsD;IACjE;IACA;IACA;IACA;IACA;CACD,CAAS;AAEV,OAAO,MAAMC,+BAA+BD,yBAAyBE,IAAI,CAAC,OAAM;AAEhF;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,eAAeC,wBACpBC,OAAe,EACfC,OAA+B;IAE/B,MAAMC,UAAUF,WAAWG,QAAQC,GAAG;IACtC,MAAMC,YAAa,CAAA,MAAMb,YAAYU,QAAO,GAAII;IAEhD,IAAID,aAAc,MAAME,WAAWF,WAAWH,UAAW;QACvD,gFAAgF;QAChF,OAAO;YAACM,QAAQH;YAAWI,aAAaJ;QAAS;IACnD;IAEA,MAAMK,eAAe,MAAMC,qCAAqCT;I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AACzC;AAEA,SAASlD,WAAWgD,GAAW,EAAEnD,GAAY;IAC3C,OAAOkD,eAAeC,KAAKnD,KAAKsD,IAAI,CAAC,CAACC,UAAYA,YAAY;AAChE;AAEA,eAAehD,qCACbT,OAAe;IAEf,MAAMa,YAAY,MAAMC,4BAA4Bd;IACpD,MAAM0D,UAAUtE;IAChB,OAAOsE,WAAW7C,UAAU8C,QAAQ,CAACD,WAAWA,UAAUJ;AAC5D"}
|
|
@@ -49,8 +49,21 @@ const logSampleTracker = new Map();
|
|
|
49
49
|
};
|
|
50
50
|
emit(userPropsEvent);
|
|
51
51
|
};
|
|
52
|
+
const resume = (events)=>{
|
|
53
|
+
for (const event of events){
|
|
54
|
+
emit({
|
|
55
|
+
createdAt: event.createdAt,
|
|
56
|
+
data: event.data ?? null,
|
|
57
|
+
name: event.event.name,
|
|
58
|
+
sessionId,
|
|
59
|
+
type: 'log',
|
|
60
|
+
version: event.event.version
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
52
64
|
return {
|
|
53
65
|
log,
|
|
66
|
+
resume,
|
|
54
67
|
trace,
|
|
55
68
|
updateUserProperties
|
|
56
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/util/telemetry/logger.ts"],"sourcesContent":["import {\n type DefinedTelemetryLog,\n type DefinedTelemetryTrace,\n type TelemetryEvent,\n type TelemetryLogger,\n type TelemetryTrace,\n} from '@sanity/telemetry'\n\nimport {telemetryStoreDebug} from './telemetryStoreDebug.js'\nimport {createTrace} from './trace.js'\n\n// Process-wide sample rate tracking for log events, shared across all logger instances\n// to deduplicate events regardless of which logger emits them.\n// Use resetLogSampleTracker() in tests to prevent state leaking between test runs.\nconst logSampleTracker = new Map<string, number>()\n\n/** @public Reset sample rate tracking state. Intended for use in tests only. */\nexport function resetLogSampleTracker(): void {\n logSampleTracker.clear()\n}\n\n/**\n * Creates a telemetry logger that emits events via the provided emit function\n * @internal\n */\nexport function createLogger<UserProperties>(\n sessionId: string,\n emit: (event: TelemetryEvent) => void,\n): TelemetryLogger<UserProperties> {\n telemetryStoreDebug('Creating logger for session: %s', sessionId)\n\n const log = <Data>(event: DefinedTelemetryLog<Data>, data?: Data) => {\n telemetryStoreDebug('Logging event: %s', event.name)\n\n // Handle sampling if maxSampleRate is specified\n if (event.maxSampleRate && event.maxSampleRate > 0) {\n const now = Date.now()\n const lastEmit = logSampleTracker.get(event.name) || 0\n\n if (now - lastEmit < event.maxSampleRate) {\n telemetryStoreDebug(\n 'Skipping event %s due to sampling (maxSampleRate: %d)',\n event.name,\n event.maxSampleRate,\n )\n return // Skip due to sampling\n }\n\n logSampleTracker.set(event.name, now)\n telemetryStoreDebug('Event %s passed sampling check', event.name)\n }\n\n const logEvent: TelemetryEvent = {\n createdAt: new Date().toISOString(),\n data: data ?? null,\n name: event.name,\n sessionId,\n type: 'log',\n version: event.version,\n }\n\n emit(logEvent)\n }\n\n const trace = <Data, Context = unknown>(\n event: DefinedTelemetryTrace<Data, Context>,\n context?: Context,\n ): TelemetryTrace<UserProperties, Data> => {\n telemetryStoreDebug('Creating trace: %s', event.name)\n return createTrace(event, context, sessionId, emit, createLogger)\n }\n\n const updateUserProperties = (properties: UserProperties) => {\n telemetryStoreDebug('Updating user properties: %o', properties)\n const userPropsEvent: TelemetryEvent = {\n createdAt: new Date().toISOString(),\n properties,\n sessionId,\n type: 'userProperties',\n }\n\n emit(userPropsEvent)\n }\n\n return {\n log,\n trace,\n updateUserProperties,\n }\n}\n"],"names":["telemetryStoreDebug","createTrace","logSampleTracker","Map","resetLogSampleTracker","clear","createLogger","sessionId","emit","log","event","data","name","maxSampleRate","now","Date","lastEmit","get","set","logEvent","createdAt","toISOString","type","version","trace","context","updateUserProperties","properties","userPropsEvent"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/util/telemetry/logger.ts"],"sourcesContent":["import {\n type DeferredEvent,\n type DefinedTelemetryLog,\n type DefinedTelemetryTrace,\n type TelemetryEvent,\n type TelemetryLogger,\n type TelemetryTrace,\n} from '@sanity/telemetry'\n\nimport {telemetryStoreDebug} from './telemetryStoreDebug.js'\nimport {createTrace} from './trace.js'\n\n// Process-wide sample rate tracking for log events, shared across all logger instances\n// to deduplicate events regardless of which logger emits them.\n// Use resetLogSampleTracker() in tests to prevent state leaking between test runs.\nconst logSampleTracker = new Map<string, number>()\n\n/** @public Reset sample rate tracking state. Intended for use in tests only. */\nexport function resetLogSampleTracker(): void {\n logSampleTracker.clear()\n}\n\n/**\n * Creates a telemetry logger that emits events via the provided emit function\n * @internal\n */\nexport function createLogger<UserProperties>(\n sessionId: string,\n emit: (event: TelemetryEvent) => void,\n): TelemetryLogger<UserProperties> {\n telemetryStoreDebug('Creating logger for session: %s', sessionId)\n\n const log = <Data>(event: DefinedTelemetryLog<Data>, data?: Data) => {\n telemetryStoreDebug('Logging event: %s', event.name)\n\n // Handle sampling if maxSampleRate is specified\n if (event.maxSampleRate && event.maxSampleRate > 0) {\n const now = Date.now()\n const lastEmit = logSampleTracker.get(event.name) || 0\n\n if (now - lastEmit < event.maxSampleRate) {\n telemetryStoreDebug(\n 'Skipping event %s due to sampling (maxSampleRate: %d)',\n event.name,\n event.maxSampleRate,\n )\n return // Skip due to sampling\n }\n\n logSampleTracker.set(event.name, now)\n telemetryStoreDebug('Event %s passed sampling check', event.name)\n }\n\n const logEvent: TelemetryEvent = {\n createdAt: new Date().toISOString(),\n data: data ?? null,\n name: event.name,\n sessionId,\n type: 'log',\n version: event.version,\n }\n\n emit(logEvent)\n }\n\n const trace = <Data, Context = unknown>(\n event: DefinedTelemetryTrace<Data, Context>,\n context?: Context,\n ): TelemetryTrace<UserProperties, Data> => {\n telemetryStoreDebug('Creating trace: %s', event.name)\n return createTrace(event, context, sessionId, emit, createLogger)\n }\n\n const updateUserProperties = (properties: UserProperties) => {\n telemetryStoreDebug('Updating user properties: %o', properties)\n const userPropsEvent: TelemetryEvent = {\n createdAt: new Date().toISOString(),\n properties,\n sessionId,\n type: 'userProperties',\n }\n\n emit(userPropsEvent)\n }\n\n const resume = (events: DeferredEvent[]) => {\n for (const event of events) {\n emit({\n createdAt: event.createdAt,\n data: event.data ?? null,\n name: event.event.name,\n sessionId,\n type: 'log',\n version: event.event.version,\n })\n }\n }\n\n return {\n log,\n resume,\n trace,\n updateUserProperties,\n }\n}\n"],"names":["telemetryStoreDebug","createTrace","logSampleTracker","Map","resetLogSampleTracker","clear","createLogger","sessionId","emit","log","event","data","name","maxSampleRate","now","Date","lastEmit","get","set","logEvent","createdAt","toISOString","type","version","trace","context","updateUserProperties","properties","userPropsEvent","resume","events"],"mappings":"AASA,SAAQA,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,WAAW,QAAO,aAAY;AAEtC,uFAAuF;AACvF,+DAA+D;AAC/D,mFAAmF;AACnF,MAAMC,mBAAmB,IAAIC;AAE7B,8EAA8E,GAC9E,OAAO,SAASC;IACdF,iBAAiBG,KAAK;AACxB;AAEA;;;CAGC,GACD,OAAO,SAASC,aACdC,SAAiB,EACjBC,IAAqC;IAErCR,oBAAoB,mCAAmCO;IAEvD,MAAME,MAAM,CAAOC,OAAkCC;QACnDX,oBAAoB,qBAAqBU,MAAME,IAAI;QAEnD,gDAAgD;QAChD,IAAIF,MAAMG,aAAa,IAAIH,MAAMG,aAAa,GAAG,GAAG;YAClD,MAAMC,MAAMC,KAAKD,GAAG;YACpB,MAAME,WAAWd,iBAAiBe,GAAG,CAACP,MAAME,IAAI,KAAK;YAErD,IAAIE,MAAME,WAAWN,MAAMG,aAAa,EAAE;gBACxCb,oBACE,yDACAU,MAAME,IAAI,EACVF,MAAMG,aAAa;gBAErB,QAAO,uBAAuB;YAChC;YAEAX,iBAAiBgB,GAAG,CAACR,MAAME,IAAI,EAAEE;YACjCd,oBAAoB,kCAAkCU,MAAME,IAAI;QAClE;QAEA,MAAMO,WAA2B;YAC/BC,WAAW,IAAIL,OAAOM,WAAW;YACjCV,MAAMA,QAAQ;YACdC,MAAMF,MAAME,IA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