@sanity/cli 3.74.2-canary.67 → 3.74.2-canary.89
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/lib/_chunks-cjs/cli.js +254 -268
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/_chunks-cjs/loadEnv.js +15 -73
- package/lib/_chunks-cjs/loadEnv.js.map +1 -1
- package/lib/index.d.mts +3 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.esm.js +12 -70
- package/lib/index.esm.js.map +1 -1
- package/lib/index.mjs +12 -70
- package/lib/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/actions/init-project/bootstrapLocalTemplate.ts +1 -4
- package/src/actions/init-project/createCoreAppCliConfig.ts +0 -3
- package/src/actions/init-project/createStudioConfig.ts +0 -1
- package/src/actions/init-project/initProject.ts +20 -25
- package/src/cli.ts +15 -5
- package/src/types.ts +3 -1
- package/src/util/resolveRootDir.ts +9 -8
package/lib/index.mjs
CHANGED
@@ -57,26 +57,26 @@ function warn(warning) {
|
|
57
57
|
typeof process.send == "function" ? process.send({ type: "warning", warning }) : console.warn(warning);
|
58
58
|
}
|
59
59
|
const debug = debugIt("sanity:cli");
|
60
|
-
function resolveRootDir(cwd) {
|
60
|
+
function resolveRootDir(cwd, isCoreApp = !1) {
|
61
61
|
try {
|
62
|
-
return resolveProjectRoot(cwd) || cwd;
|
62
|
+
return resolveProjectRoot(cwd, 0, isCoreApp) || cwd;
|
63
63
|
} catch (err) {
|
64
64
|
throw new Error(`Error occurred trying to resolve project root:
|
65
65
|
${err.message}`);
|
66
66
|
}
|
67
67
|
}
|
68
|
-
function
|
68
|
+
function hasSanityConfig(basePath, configName) {
|
69
69
|
return [
|
70
|
-
fileExists(path.join(basePath,
|
71
|
-
fileExists(path.join(basePath,
|
70
|
+
fileExists(path.join(basePath, `${configName}.js`)),
|
71
|
+
fileExists(path.join(basePath, `${configName}.ts`)),
|
72
72
|
isSanityV2StudioRoot(basePath)
|
73
73
|
].some(Boolean);
|
74
74
|
}
|
75
|
-
function resolveProjectRoot(basePath, iterations = 0) {
|
76
|
-
if (
|
75
|
+
function resolveProjectRoot(basePath, iterations = 0, isCoreApp = !1) {
|
76
|
+
if (hasSanityConfig(basePath, isCoreApp ? "sanity.cli" : "sanity.config"))
|
77
77
|
return basePath;
|
78
78
|
const parentDir = path.resolve(basePath, "..");
|
79
|
-
return parentDir === basePath || iterations > 30 ? !1 : resolveProjectRoot(parentDir, iterations + 1);
|
79
|
+
return parentDir === basePath || iterations > 30 ? !1 : resolveProjectRoot(parentDir, iterations + 1, isCoreApp);
|
80
80
|
}
|
81
81
|
function isSanityV2StudioRoot(basePath) {
|
82
82
|
try {
|
@@ -125,69 +125,11 @@ function defineCliConfig(config) {
|
|
125
125
|
function createCliConfig(config) {
|
126
126
|
return config;
|
127
127
|
}
|
128
|
-
var main$
|
129
|
-
|
130
|
-
types: "./lib/main.d.ts",
|
131
|
-
require: "./lib/main.js",
|
132
|
-
default: "./lib/main.js"
|
133
|
-
},
|
134
|
-
"./config": "./config.js",
|
135
|
-
"./config.js": "./config.js",
|
136
|
-
"./lib/env-options": "./lib/env-options.js",
|
137
|
-
"./lib/env-options.js": "./lib/env-options.js",
|
138
|
-
"./lib/cli-options": "./lib/cli-options.js",
|
139
|
-
"./lib/cli-options.js": "./lib/cli-options.js",
|
140
|
-
"./package.json": "./package.json"
|
141
|
-
}, scripts = {
|
142
|
-
"dts-check": "tsc --project tests/types/tsconfig.json",
|
143
|
-
lint: "standard",
|
144
|
-
pretest: "npm run lint && npm run dts-check",
|
145
|
-
test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
|
146
|
-
"test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov",
|
147
|
-
prerelease: "npm test",
|
148
|
-
release: "standard-version"
|
149
|
-
}, repository = {
|
150
|
-
type: "git",
|
151
|
-
url: "git://github.com/motdotla/dotenv.git"
|
152
|
-
}, funding = "https://dotenvx.com", keywords = [
|
153
|
-
"dotenv",
|
154
|
-
"env",
|
155
|
-
".env",
|
156
|
-
"environment",
|
157
|
-
"variables",
|
158
|
-
"config",
|
159
|
-
"settings"
|
160
|
-
], readmeFilename = "README.md", license = "BSD-2-Clause", devDependencies = {
|
161
|
-
"@types/node": "^18.11.3",
|
162
|
-
decache: "^4.6.2",
|
163
|
-
sinon: "^14.0.1",
|
164
|
-
standard: "^17.0.0",
|
165
|
-
"standard-version": "^9.5.0",
|
166
|
-
tap: "^19.2.0",
|
167
|
-
typescript: "^4.8.4"
|
168
|
-
}, engines = {
|
169
|
-
node: ">=12"
|
170
|
-
}, browser = {
|
171
|
-
fs: !1
|
172
|
-
}, require$$4 = {
|
173
|
-
name,
|
174
|
-
version,
|
175
|
-
description,
|
176
|
-
main: main$1,
|
177
|
-
types,
|
178
|
-
exports,
|
179
|
-
scripts,
|
180
|
-
repository,
|
181
|
-
funding,
|
182
|
-
keywords,
|
183
|
-
readmeFilename,
|
184
|
-
license,
|
185
|
-
devDependencies,
|
186
|
-
engines,
|
187
|
-
browser
|
128
|
+
var main$1 = { exports: {} }, version = "16.4.7", require$$4 = {
|
129
|
+
version
|
188
130
|
}, hasRequiredMain$1;
|
189
131
|
function requireMain$1() {
|
190
|
-
if (hasRequiredMain$1) return main$
|
132
|
+
if (hasRequiredMain$1) return main$1.exports;
|
191
133
|
hasRequiredMain$1 = 1;
|
192
134
|
const fs2 = require$$0, path2 = require$$1, os = require$$2, crypto = require$$3, version2 = require$$4.version, LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
193
135
|
function parse(src) {
|
@@ -356,7 +298,7 @@ function requireMain$1() {
|
|
356
298
|
parse,
|
357
299
|
populate
|
358
300
|
};
|
359
|
-
return main$
|
301
|
+
return main$1.exports.configDotenv = DotenvModule.configDotenv, main$1.exports._configVault = DotenvModule._configVault, main$1.exports._parseVault = DotenvModule._parseVault, main$1.exports.config = DotenvModule.config, main$1.exports.decrypt = DotenvModule.decrypt, main$1.exports.parse = DotenvModule.parse, main$1.exports.populate = DotenvModule.populate, main$1.exports = DotenvModule, main$1.exports;
|
360
302
|
}
|
361
303
|
var mainExports$1 = requireMain$1(), main = {}, hasRequiredMain;
|
362
304
|
function requireMain() {
|
package/lib/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/util/dynamicRequire.ts","../src/util/getCliConfig.ts","../src/debug.ts","../src/util/resolveRootDir.ts","../src/cliClient.ts","../src/config.ts","../../../../node_modules/.pnpm/dotenv@16.4.7/node_modules/dotenv/lib/main.js","../../../../node_modules/.pnpm/dotenv-expand@9.0.0/node_modules/dotenv-expand/lib/main.js","../src/util/loadEnv.ts"],"sourcesContent":["// Prevent webpack from bundling in webpack context,\n// use regular node require for unbundled context\n\n/* eslint-disable camelcase, no-undef */\ndeclare const __webpack_require__: boolean\ndeclare const __non_webpack_require__: typeof require\n\nconst requireFunc: typeof require =\n typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require\n/* eslint-enable camelcase, no-undef */\n\nexport function dynamicRequire<T = any>(request: string): T {\n const mod = requireFunc(request)\n return mod.__esModule && mod.default ? mod.default : mod\n}\n\ndynamicRequire.resolve = requireFunc.resolve\n","/* eslint-disable no-sync */\n\n/**\n * Reads the Sanity CLI config from one of the following files (in preferred order):\n * - sanity.cli.js\n * - sanity.cli.ts\n *\n * Note: There are two ways of using this:\n * a) `getCliConfig(cwd)`\n * b) `getCliConfig(cwd, {forked: true})`\n *\n * Approach a is generally a bit faster as it avoids the forking startup time, while\n * approach b could be considered \"safer\" since any side-effects of running the config\n * file will not bleed into the current CLI process directly.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport {Worker} from 'node:worker_threads'\n\nimport {type CliConfig, type SanityJson} from '../types'\nimport {getCliWorkerPath} from './cliWorker'\nimport {dynamicRequire} from './dynamicRequire'\n\nexport type CliMajorVersion = 2 | 3\n\nexport type CliConfigResult =\n | {config: SanityJson; path: string; version: 2}\n | {config: CliConfig; path: string; version: 3}\n | {config: null; path: string; version: CliMajorVersion}\n\nexport async function getCliConfig(\n cwd: string,\n {forked}: {forked?: boolean} = {},\n): Promise<CliConfigResult | null> {\n if (forked) {\n try {\n return await getCliConfigForked(cwd)\n } catch (err) {\n // Intentional noop - try unforked variant\n }\n }\n\n const {unregister} = __DEV__\n ? {unregister: () => undefined}\n : require('esbuild-register/dist/node').register({supported: {'dynamic-import': true}})\n\n try {\n const v3Config = getSanityCliConfig(cwd)\n if (v3Config) {\n return v3Config\n }\n\n return getSanityJsonConfig(cwd)\n } catch (err) {\n throw err\n } finally {\n unregister()\n }\n}\n\nexport function getCliConfigSync(cwd: string): CliConfigResult | null {\n const v3Config = getSanityCliConfig(cwd)\n return v3Config ? v3Config : getSanityJsonConfig(cwd)\n}\n\nasync function getCliConfigForked(cwd: string): Promise<CliConfigResult | null> {\n const workerPath = await getCliWorkerPath('getCliConfig')\n return new Promise((resolve, reject) => {\n const worker = new Worker(workerPath, {\n workerData: cwd,\n // eslint-disable-next-line no-process-env\n env: process.env,\n })\n worker.on('message', (message) => {\n if (message.type === 'config') {\n resolve(message.config)\n } else {\n const error = new Error(message.error)\n ;(error as any).type = message.errorType\n reject(new Error(message.error))\n }\n })\n worker.on('error', reject)\n worker.on('exit', (code) => {\n if (code !== 0) {\n reject(new Error(`Worker stopped with exit code ${code}`))\n }\n })\n })\n}\n\nfunction getSanityJsonConfig(cwd: string): CliConfigResult | null {\n const configPath = path.join(cwd, 'sanity.json')\n\n if (!fs.existsSync(configPath)) {\n return null\n }\n\n return {\n config: loadJsonConfig(configPath),\n path: configPath,\n version: 2,\n }\n}\n\nfunction getSanityCliConfig(cwd: string): CliConfigResult | null {\n const jsConfigPath = path.join(cwd, 'sanity.cli.js')\n const tsConfigPath = path.join(cwd, 'sanity.cli.ts')\n\n const [js, ts] = [fs.existsSync(jsConfigPath), fs.existsSync(tsConfigPath)]\n\n if (!js && !ts) {\n return null\n }\n\n if (!js && ts) {\n return {\n config: importConfig(tsConfigPath),\n path: tsConfigPath,\n version: 3,\n }\n }\n\n if (js && ts) {\n warn('Found both `sanity.cli.js` and `sanity.cli.ts` - using sanity.cli.js')\n }\n\n return {\n config: importConfig(jsConfigPath),\n path: jsConfigPath,\n version: 3,\n }\n}\n\nfunction loadJsonConfig(filePath: string): SanityJson | null {\n try {\n const content = fs.readFileSync(filePath, 'utf8')\n return JSON.parse(content)\n } catch (err) {\n console.error(`Error reading \"${filePath}\": ${err.message}`)\n return null\n }\n}\n\nfunction importConfig(filePath: string): CliConfig | null {\n try {\n const config = dynamicRequire<CliConfig | {default: CliConfig} | null>(filePath)\n if (config === null || typeof config !== 'object') {\n throw new Error('Module export is not a configuration object')\n }\n\n return 'default' in config ? config.default : config\n } catch (err) {\n // If attempting to import `defineCliConfig` or similar from `sanity/cli`,\n // accept the fact that it might not be installed. Instead, let the CLI\n // give a warning about the `sanity` module not being installed\n if (err.code === 'MODULE_NOT_FOUND' && err.message.includes('sanity/cli')) {\n return null\n }\n\n console.error(`Error reading \"${filePath}\": ${err.message}`)\n return null\n }\n}\n\nfunction warn(warning: string) {\n if (typeof process.send === 'function') {\n process.send({type: 'warning', warning})\n } else {\n console.warn(warning)\n }\n}\n","import debugIt from 'debug'\n\nexport const debug = debugIt('sanity:cli')\n","/* eslint-disable no-sync */\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport {debug} from '../debug'\n\n/**\n * Resolve project root directory, falling back to cwd if it cannot be found\n */\nexport function resolveRootDir(cwd: string): string {\n try {\n return resolveProjectRoot(cwd) || cwd\n } catch (err) {\n throw new Error(`Error occurred trying to resolve project root:\\n${err.message}`)\n }\n}\n\nfunction hasStudioConfig(basePath: string): boolean {\n const buildConfigs = [\n fileExists(path.join(basePath, 'sanity.config.js')),\n fileExists(path.join(basePath, 'sanity.config.ts')),\n isSanityV2StudioRoot(basePath),\n ]\n\n return buildConfigs.some(Boolean)\n}\n\nfunction resolveProjectRoot(basePath: string, iterations = 0): string | false {\n if (hasStudioConfig(basePath)) {\n return basePath\n }\n\n const parentDir = path.resolve(basePath, '..')\n if (parentDir === basePath || iterations > 30) {\n // Reached root (or max depth), give up\n return false\n }\n\n return resolveProjectRoot(parentDir, iterations + 1)\n}\n\nfunction isSanityV2StudioRoot(basePath: string): boolean {\n try {\n const content = fs.readFileSync(path.join(basePath, 'sanity.json'), 'utf8')\n const sanityJson = JSON.parse(content)\n const isRoot = Boolean(sanityJson?.root)\n if (isRoot) {\n debug('Found Sanity v2 studio root at %s', basePath)\n }\n return isRoot\n } catch (err) {\n return false\n }\n}\n\nfunction fileExists(filePath: string): boolean {\n return fs.existsSync(filePath)\n}\n","import {createClient, type SanityClient} from '@sanity/client'\n\nimport {getCliConfigSync} from './util/getCliConfig'\nimport {resolveRootDir} from './util/resolveRootDir'\n\nexport interface CliClientOptions {\n cwd?: string\n\n projectId?: string\n dataset?: string\n useCdn?: boolean\n token?: string\n apiVersion?: string\n}\n\nexport function getCliClient(options: CliClientOptions = {}): SanityClient {\n if (typeof process !== 'object') {\n throw new Error('getCliClient() should only be called from node.js scripts')\n }\n\n const {\n // eslint-disable-next-line no-process-env\n cwd = process.env.SANITY_BASE_PATH || process.cwd(),\n useCdn = false,\n apiVersion = '2022-06-06',\n projectId,\n dataset,\n token = getCliClient.__internal__getToken(),\n } = options\n\n if (projectId && dataset) {\n return createClient({projectId, dataset, apiVersion, useCdn, token})\n }\n\n const rootDir = resolveRootDir(cwd)\n const {config} = getCliConfigSync(rootDir) || {}\n if (!config) {\n throw new Error('Unable to resolve CLI configuration')\n }\n\n const apiConfig = config?.api || {}\n if (!apiConfig.projectId || !apiConfig.dataset) {\n throw new Error('Unable to resolve project ID/dataset from CLI configuration')\n }\n\n return createClient({\n projectId: apiConfig.projectId,\n dataset: apiConfig.dataset,\n apiVersion,\n useCdn,\n token,\n })\n}\n\n/* eslint-disable camelcase */\n/**\n * @internal\n * @deprecated This is only for INTERNAL use, and should not be relied upon outside of official Sanity modules\n * @returns A token to use when constructing a client without a `token` explicitly defined, or undefined\n */\ngetCliClient.__internal__getToken = (): string | undefined => undefined\n/* eslint-enable camelcase */\n","import {type CliConfig} from './types'\n\n/** @beta */\nexport function defineCliConfig(config: CliConfig): CliConfig {\n return config\n}\n\n/**\n * @deprecated Use `defineCliConfig` instead\n * @beta\n */\nexport function createCliConfig(config: CliConfig): CliConfig {\n return config\n}\n","const fs = require('fs')\nconst path = require('path')\nconst os = require('os')\nconst crypto = require('crypto')\nconst packageJson = require('../package.json')\n\nconst version = packageJson.version\n\nconst LINE = /(?:^|^)\\s*(?:export\\s+)?([\\w.-]+)(?:\\s*=\\s*?|:\\s+?)(\\s*'(?:\\\\'|[^'])*'|\\s*\"(?:\\\\\"|[^\"])*\"|\\s*`(?:\\\\`|[^`])*`|[^#\\r\\n]+)?\\s*(?:#.*)?(?:$|$)/mg\n\n// Parse src into an Object\nfunction parse (src) {\n const obj = {}\n\n // Convert buffer to string\n let lines = src.toString()\n\n // Convert line breaks to same format\n lines = lines.replace(/\\r\\n?/mg, '\\n')\n\n let match\n while ((match = LINE.exec(lines)) != null) {\n const key = match[1]\n\n // Default undefined or null to empty string\n let value = (match[2] || '')\n\n // Remove whitespace\n value = value.trim()\n\n // Check if double quoted\n const maybeQuote = value[0]\n\n // Remove surrounding quotes\n value = value.replace(/^(['\"`])([\\s\\S]*)\\1$/mg, '$2')\n\n // Expand newlines if double quoted\n if (maybeQuote === '\"') {\n value = value.replace(/\\\\n/g, '\\n')\n value = value.replace(/\\\\r/g, '\\r')\n }\n\n // Add to object\n obj[key] = value\n }\n\n return obj\n}\n\nfunction _parseVault (options) {\n const vaultPath = _vaultPath(options)\n\n // Parse .env.vault\n const result = DotenvModule.configDotenv({ path: vaultPath })\n if (!result.parsed) {\n const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`)\n err.code = 'MISSING_DATA'\n throw err\n }\n\n // handle scenario for comma separated keys - for use with key rotation\n // example: DOTENV_KEY=\"dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod\"\n const keys = _dotenvKey(options).split(',')\n const length = keys.length\n\n let decrypted\n for (let i = 0; i < length; i++) {\n try {\n // Get full key\n const key = keys[i].trim()\n\n // Get instructions for decrypt\n const attrs = _instructions(result, key)\n\n // Decrypt\n decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key)\n\n break\n } catch (error) {\n // last key\n if (i + 1 >= length) {\n throw error\n }\n // try next key\n }\n }\n\n // Parse decrypted .env string\n return DotenvModule.parse(decrypted)\n}\n\nfunction _log (message) {\n console.log(`[dotenv@${version}][INFO] ${message}`)\n}\n\nfunction _warn (message) {\n console.log(`[dotenv@${version}][WARN] ${message}`)\n}\n\nfunction _debug (message) {\n console.log(`[dotenv@${version}][DEBUG] ${message}`)\n}\n\nfunction _dotenvKey (options) {\n // prioritize developer directly setting options.DOTENV_KEY\n if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {\n return options.DOTENV_KEY\n }\n\n // secondary infra already contains a DOTENV_KEY environment variable\n if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {\n return process.env.DOTENV_KEY\n }\n\n // fallback to empty string\n return ''\n}\n\nfunction _instructions (result, dotenvKey) {\n // Parse DOTENV_KEY. Format is a URI\n let uri\n try {\n uri = new URL(dotenvKey)\n } catch (error) {\n if (error.code === 'ERR_INVALID_URL') {\n const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development')\n err.code = 'INVALID_DOTENV_KEY'\n throw err\n }\n\n throw error\n }\n\n // Get decrypt key\n const key = uri.password\n if (!key) {\n const err = new Error('INVALID_DOTENV_KEY: Missing key part')\n err.code = 'INVALID_DOTENV_KEY'\n throw err\n }\n\n // Get environment\n const environment = uri.searchParams.get('environment')\n if (!environment) {\n const err = new Error('INVALID_DOTENV_KEY: Missing environment part')\n err.code = 'INVALID_DOTENV_KEY'\n throw err\n }\n\n // Get ciphertext payload\n const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`\n const ciphertext = result.parsed[environmentKey] // DOTENV_VAULT_PRODUCTION\n if (!ciphertext) {\n const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`)\n err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT'\n throw err\n }\n\n return { ciphertext, key }\n}\n\nfunction _vaultPath (options) {\n let possibleVaultPath = null\n\n if (options && options.path && options.path.length > 0) {\n if (Array.isArray(options.path)) {\n for (const filepath of options.path) {\n if (fs.existsSync(filepath)) {\n possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`\n }\n }\n } else {\n possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`\n }\n } else {\n possibleVaultPath = path.resolve(process.cwd(), '.env.vault')\n }\n\n if (fs.existsSync(possibleVaultPath)) {\n return possibleVaultPath\n }\n\n return null\n}\n\nfunction _resolveHome (envPath) {\n return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath\n}\n\nfunction _configVault (options) {\n _log('Loading env from encrypted .env.vault')\n\n const parsed = DotenvModule._parseVault(options)\n\n let processEnv = process.env\n if (options && options.processEnv != null) {\n processEnv = options.processEnv\n }\n\n DotenvModule.populate(processEnv, parsed, options)\n\n return { parsed }\n}\n\nfunction configDotenv (options) {\n const dotenvPath = path.resolve(process.cwd(), '.env')\n let encoding = 'utf8'\n const debug = Boolean(options && options.debug)\n\n if (options && options.encoding) {\n encoding = options.encoding\n } else {\n if (debug) {\n _debug('No encoding is specified. UTF-8 is used by default')\n }\n }\n\n let optionPaths = [dotenvPath] // default, look for .env\n if (options && options.path) {\n if (!Array.isArray(options.path)) {\n optionPaths = [_resolveHome(options.path)]\n } else {\n optionPaths = [] // reset default\n for (const filepath of options.path) {\n optionPaths.push(_resolveHome(filepath))\n }\n }\n }\n\n // Build the parsed data in a temporary object (because we need to return it). Once we have the final\n // parsed data, we will combine it with process.env (or options.processEnv if provided).\n let lastError\n const parsedAll = {}\n for (const path of optionPaths) {\n try {\n // Specifying an encoding returns a string instead of a buffer\n const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }))\n\n DotenvModule.populate(parsedAll, parsed, options)\n } catch (e) {\n if (debug) {\n _debug(`Failed to load ${path} ${e.message}`)\n }\n lastError = e\n }\n }\n\n let processEnv = process.env\n if (options && options.processEnv != null) {\n processEnv = options.processEnv\n }\n\n DotenvModule.populate(processEnv, parsedAll, options)\n\n if (lastError) {\n return { parsed: parsedAll, error: lastError }\n } else {\n return { parsed: parsedAll }\n }\n}\n\n// Populates process.env from .env file\nfunction config (options) {\n // fallback to original dotenv if DOTENV_KEY is not set\n if (_dotenvKey(options).length === 0) {\n return DotenvModule.configDotenv(options)\n }\n\n const vaultPath = _vaultPath(options)\n\n // dotenvKey exists but .env.vault file does not exist\n if (!vaultPath) {\n _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`)\n\n return DotenvModule.configDotenv(options)\n }\n\n return DotenvModule._configVault(options)\n}\n\nfunction decrypt (encrypted, keyStr) {\n const key = Buffer.from(keyStr.slice(-64), 'hex')\n let ciphertext = Buffer.from(encrypted, 'base64')\n\n const nonce = ciphertext.subarray(0, 12)\n const authTag = ciphertext.subarray(-16)\n ciphertext = ciphertext.subarray(12, -16)\n\n try {\n const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce)\n aesgcm.setAuthTag(authTag)\n return `${aesgcm.update(ciphertext)}${aesgcm.final()}`\n } catch (error) {\n const isRange = error instanceof RangeError\n const invalidKeyLength = error.message === 'Invalid key length'\n const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data'\n\n if (isRange || invalidKeyLength) {\n const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)')\n err.code = 'INVALID_DOTENV_KEY'\n throw err\n } else if (decryptionFailed) {\n const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY')\n err.code = 'DECRYPTION_FAILED'\n throw err\n } else {\n throw error\n }\n }\n}\n\n// Populate process.env with parsed values\nfunction populate (processEnv, parsed, options = {}) {\n const debug = Boolean(options && options.debug)\n const override = Boolean(options && options.override)\n\n if (typeof parsed !== 'object') {\n const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate')\n err.code = 'OBJECT_REQUIRED'\n throw err\n }\n\n // Set process.env\n for (const key of Object.keys(parsed)) {\n if (Object.prototype.hasOwnProperty.call(processEnv, key)) {\n if (override === true) {\n processEnv[key] = parsed[key]\n }\n\n if (debug) {\n if (override === true) {\n _debug(`\"${key}\" is already defined and WAS overwritten`)\n } else {\n _debug(`\"${key}\" is already defined and was NOT overwritten`)\n }\n }\n } else {\n processEnv[key] = parsed[key]\n }\n }\n}\n\nconst DotenvModule = {\n configDotenv,\n _configVault,\n _parseVault,\n config,\n decrypt,\n parse,\n populate\n}\n\nmodule.exports.configDotenv = DotenvModule.configDotenv\nmodule.exports._configVault = DotenvModule._configVault\nmodule.exports._parseVault = DotenvModule._parseVault\nmodule.exports.config = DotenvModule.config\nmodule.exports.decrypt = DotenvModule.decrypt\nmodule.exports.parse = DotenvModule.parse\nmodule.exports.populate = DotenvModule.populate\n\nmodule.exports = DotenvModule\n","'use strict'\n\nfunction _interpolate (envValue, environment, config) {\n const matches = envValue.match(/(.?\\${*[\\w]*(?::-[\\w/]*)?}*)/g) || []\n\n return matches.reduce(function (newEnv, match, index) {\n const parts = /(.?)\\${*([\\w]*(?::-[\\w/]*)?)?}*/g.exec(match)\n if (!parts || parts.length === 0) {\n return newEnv\n }\n\n const prefix = parts[1]\n\n let value, replacePart\n\n if (prefix === '\\\\') {\n replacePart = parts[0]\n value = replacePart.replace('\\\\$', '$')\n } else {\n const keyParts = parts[2].split(':-')\n const key = keyParts[0]\n replacePart = parts[0].substring(prefix.length)\n // process.env value 'wins' over .env file's value\n value = Object.prototype.hasOwnProperty.call(environment, key)\n ? environment[key]\n : (config.parsed[key] || keyParts[1] || '')\n\n // If the value is found, remove nested expansions.\n if (keyParts.length > 1 && value) {\n const replaceNested = matches[index + 1]\n matches[index + 1] = ''\n\n newEnv = newEnv.replace(replaceNested, '')\n }\n // Resolve recursive interpolations\n value = _interpolate(value, environment, config)\n }\n\n return newEnv.replace(replacePart, value)\n }, envValue)\n}\n\nfunction expand (config) {\n // if ignoring process.env, use a blank object\n const environment = config.ignoreProcessEnv ? {} : process.env\n\n for (const configKey in config.parsed) {\n const value = Object.prototype.hasOwnProperty.call(environment, configKey) ? environment[configKey] : config.parsed[configKey]\n\n config.parsed[configKey] = _interpolate(value, environment, config)\n }\n\n for (const processKey in config.parsed) {\n environment[processKey] = config.parsed[processKey]\n }\n\n return config\n}\n\nmodule.exports.expand = expand\n","/**\n * This is an \"inlined\" version of Vite's `loadEnv` function,\n * simplified somewhat to only support our use case.\n *\n * Ideally we'd just use `loadEnv` from Vite, but importing it\n * causes bundling issues due to node APIs and downstream dependencies.\n *\n * Vite is MIT licensed, copyright (c) Yuxi (Evan) You and Vite contributors.\n */\n\n/* eslint-disable no-process-env */\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport {parse} from 'dotenv'\nimport {expand} from 'dotenv-expand'\n\nexport function loadEnv(\n mode: string,\n envDir: string,\n prefixes: string[] = ['VITE_'],\n): Record<string, string> {\n if (mode === 'local') {\n throw new Error(\n `\"local\" cannot be used as a mode name because it conflicts with ` +\n `the .local postfix for .env files.`,\n )\n }\n\n const env: Record<string, string> = {}\n const envFiles = [\n /** default file */ `.env`,\n /** local file */ `.env.local`,\n /** mode file */ `.env.${mode}`,\n /** mode local file */ `.env.${mode}.local`,\n ]\n\n const parsed = Object.fromEntries(\n envFiles.flatMap((file) => {\n const envPath = lookupFile(envDir, [file], {\n rootDir: envDir,\n })\n if (!envPath) return []\n return Object.entries(parse(fs.readFileSync(envPath)))\n }),\n )\n\n // test NODE_ENV override before expand as otherwise process.env.NODE_ENV would override this\n if (parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === undefined) {\n process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV\n }\n // support BROWSER and BROWSER_ARGS env variables\n if (parsed.BROWSER && process.env.BROWSER === undefined) {\n process.env.BROWSER = parsed.BROWSER\n }\n if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === undefined) {\n process.env.BROWSER_ARGS = parsed.BROWSER_ARGS\n }\n\n try {\n // let environment variables use each other\n expand({parsed})\n } catch (e) {\n // custom error handling until https://github.com/motdotla/dotenv-expand/issues/65 is fixed upstream\n // check for message \"TypeError: Cannot read properties of undefined (reading 'split')\"\n if (e.message.includes('split')) {\n throw new Error('dotenv-expand failed to expand env vars. Maybe you need to escape `$`?')\n }\n throw e\n }\n\n // only keys that start with prefix are exposed to client\n for (const [key, value] of Object.entries(parsed)) {\n if (prefixes.some((prefix) => key.startsWith(prefix))) {\n env[key] = value\n }\n }\n\n // check if there are actual env variables starting with VITE_*\n // these are typically provided inline and should be prioritized\n for (const key in process.env) {\n if (prefixes.some((prefix) => key.startsWith(prefix))) {\n env[key] = process.env[key] as string\n }\n }\n\n return env\n}\n\nfunction lookupFile(\n dir: string,\n formats: string[],\n options?: {\n rootDir?: string\n },\n): string | undefined {\n for (const format of formats) {\n const fullPath = path.join(dir, format)\n // eslint-disable-next-line no-sync\n if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile()) {\n return fullPath\n }\n }\n const parentDir = path.dirname(dir)\n if (parentDir !== dir && (!options?.rootDir || parentDir.startsWith(options?.rootDir))) {\n return lookupFile(parentDir, formats, options)\n }\n\n return undefined\n}\n"],"names":["fs","path","version","debug","mainModule","parse","expand"],"mappings":";;;;;;;;AAOA,MAAM,cACJ,OAAO,uBAAwB,aAAa,0BAA0B;AAGjE,SAAS,eAAwB,SA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CAAA;AAAA,EACH;AAGI,SAAO,YAAY,QAAQ,IAAI,uBAAuB,WACxD,QAAQ,IAAI,qBAAqB,OAAO,WAGtC,OAAO,WAAW,QAAQ,IAAI,YAAY,WAC5C,QAAQ,IAAI,UAAU,OAAO,UAE3B,OAAO,gBAAgB,QAAQ,IAAI,iBAAiB,WACtD,QAAQ,IAAI,eAAe,OAAO;AAGhC,MAAA;AAEKC,gBAAA,OAAA,EAAC,QAAO;AAAA,WACR,GAAG;AAGN,UAAA,EAAE,QAAQ,SAAS,OAAO,IACtB,IAAI,MAAM,wEAAwE,IAEpF;AAAA,EAAA;AAIR,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM;AAC1C,aAAS,KAAK,CAAC,WAAW,IAAI,WAAW,MAAM,CAAC,MAClD,IAAI,GAAG,IAAI;AAMf,aAAW,OAAO,QAAQ;AACpB,aAAS,KAAK,CAAC,WAAW,IAAI,WAAW,MAAM,CAAC,MAClD,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG;AAIvB,SAAA;AACT;AAEA,SAAS,WACP,KACA,SACA,SAGoB;AACpB,aAAW,UAAU,SAAS;AAC5B,UAAM,WAAW,KAAK,KAAK,KAAK,MAAM;AAElC,QAAA,GAAG,WAAW,QAAQ,KAAK,GAAG,SAAS,QAAQ,EAAE,OAAO;AACnD,aAAA;AAAA,EAAA;AAGL,QAAA,YAAY,KAAK,QAAQ,GAAG;AAC9B,MAAA,cAAc,QAAQ,CAAC,SAAS,WAAW,UAAU,WAAW,SAAS,OAAO;AAC3E,WAAA,WAAW,WAAW,SAAS,OAAO;AAIjD;","x_google_ignoreList":[6,7]}
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/util/dynamicRequire.ts","../src/util/getCliConfig.ts","../src/debug.ts","../src/util/resolveRootDir.ts","../src/cliClient.ts","../src/config.ts","../../../../node_modules/.pnpm/dotenv@16.4.7/node_modules/dotenv/lib/main.js","../../../../node_modules/.pnpm/dotenv-expand@9.0.0/node_modules/dotenv-expand/lib/main.js","../src/util/loadEnv.ts"],"sourcesContent":["// Prevent webpack from bundling in webpack context,\n// use regular node require for unbundled context\n\n/* eslint-disable camelcase, no-undef */\ndeclare const __webpack_require__: boolean\ndeclare const __non_webpack_require__: typeof require\n\nconst requireFunc: typeof require =\n typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require\n/* eslint-enable camelcase, no-undef */\n\nexport function dynamicRequire<T = any>(request: string): T {\n const mod = requireFunc(request)\n return mod.__esModule && mod.default ? mod.default : mod\n}\n\ndynamicRequire.resolve = requireFunc.resolve\n","/* eslint-disable no-sync */\n\n/**\n * Reads the Sanity CLI config from one of the following files (in preferred order):\n * - sanity.cli.js\n * - sanity.cli.ts\n *\n * Note: There are two ways of using this:\n * a) `getCliConfig(cwd)`\n * b) `getCliConfig(cwd, {forked: true})`\n *\n * Approach a is generally a bit faster as it avoids the forking startup time, while\n * approach b could be considered \"safer\" since any side-effects of running the config\n * file will not bleed into the current CLI process directly.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport {Worker} from 'node:worker_threads'\n\nimport {type CliConfig, type SanityJson} from '../types'\nimport {getCliWorkerPath} from './cliWorker'\nimport {dynamicRequire} from './dynamicRequire'\n\nexport type CliMajorVersion = 2 | 3\n\nexport type CliConfigResult =\n | {config: SanityJson; path: string; version: 2}\n | {config: CliConfig; path: string; version: 3}\n | {config: null; path: string; version: CliMajorVersion}\n\nexport async function getCliConfig(\n cwd: string,\n {forked}: {forked?: boolean} = {},\n): Promise<CliConfigResult | null> {\n if (forked) {\n try {\n return await getCliConfigForked(cwd)\n } catch (err) {\n // Intentional noop - try unforked variant\n }\n }\n\n const {unregister} = __DEV__\n ? {unregister: () => undefined}\n : require('esbuild-register/dist/node').register({supported: {'dynamic-import': true}})\n\n try {\n const v3Config = getSanityCliConfig(cwd)\n if (v3Config) {\n return v3Config\n }\n\n return getSanityJsonConfig(cwd)\n } catch (err) {\n throw err\n } finally {\n unregister()\n }\n}\n\nexport function getCliConfigSync(cwd: string): CliConfigResult | null {\n const v3Config = getSanityCliConfig(cwd)\n return v3Config ? v3Config : getSanityJsonConfig(cwd)\n}\n\nasync function getCliConfigForked(cwd: string): Promise<CliConfigResult | null> {\n const workerPath = await getCliWorkerPath('getCliConfig')\n return new Promise((resolve, reject) => {\n const worker = new Worker(workerPath, {\n workerData: cwd,\n // eslint-disable-next-line no-process-env\n env: process.env,\n })\n worker.on('message', (message) => {\n if (message.type === 'config') {\n resolve(message.config)\n } else {\n const error = new Error(message.error)\n ;(error as any).type = message.errorType\n reject(new Error(message.error))\n }\n })\n worker.on('error', reject)\n worker.on('exit', (code) => {\n if (code !== 0) {\n reject(new Error(`Worker stopped with exit code ${code}`))\n }\n })\n })\n}\n\nfunction getSanityJsonConfig(cwd: string): CliConfigResult | null {\n const configPath = path.join(cwd, 'sanity.json')\n\n if (!fs.existsSync(configPath)) {\n return null\n }\n\n return {\n config: loadJsonConfig(configPath),\n path: configPath,\n version: 2,\n }\n}\n\nfunction getSanityCliConfig(cwd: string): CliConfigResult | null {\n const jsConfigPath = path.join(cwd, 'sanity.cli.js')\n const tsConfigPath = path.join(cwd, 'sanity.cli.ts')\n\n const [js, ts] = [fs.existsSync(jsConfigPath), fs.existsSync(tsConfigPath)]\n\n if (!js && !ts) {\n return null\n }\n\n if (!js && ts) {\n return {\n config: importConfig(tsConfigPath),\n path: tsConfigPath,\n version: 3,\n }\n }\n\n if (js && ts) {\n warn('Found both `sanity.cli.js` and `sanity.cli.ts` - using sanity.cli.js')\n }\n\n return {\n config: importConfig(jsConfigPath),\n path: jsConfigPath,\n version: 3,\n }\n}\n\nfunction loadJsonConfig(filePath: string): SanityJson | null {\n try {\n const content = fs.readFileSync(filePath, 'utf8')\n return JSON.parse(content)\n } catch (err) {\n console.error(`Error reading \"${filePath}\": ${err.message}`)\n return null\n }\n}\n\nfunction importConfig(filePath: string): CliConfig | null {\n try {\n const config = dynamicRequire<CliConfig | {default: CliConfig} | null>(filePath)\n if (config === null || typeof config !== 'object') {\n throw new Error('Module export is not a configuration object')\n }\n\n return 'default' in config ? config.default : config\n } catch (err) {\n // If attempting to import `defineCliConfig` or similar from `sanity/cli`,\n // accept the fact that it might not be installed. Instead, let the CLI\n // give a warning about the `sanity` module not being installed\n if (err.code === 'MODULE_NOT_FOUND' && err.message.includes('sanity/cli')) {\n return null\n }\n\n console.error(`Error reading \"${filePath}\": ${err.message}`)\n return null\n }\n}\n\nfunction warn(warning: string) {\n if (typeof process.send === 'function') {\n process.send({type: 'warning', warning})\n } else {\n console.warn(warning)\n }\n}\n","import debugIt from 'debug'\n\nexport const debug = debugIt('sanity:cli')\n","/* eslint-disable no-sync */\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport {debug} from '../debug'\n\n/**\n * Resolve project root directory, falling back to cwd if it cannot be found\n */\nexport function resolveRootDir(cwd: string, isCoreApp = false): string {\n try {\n return resolveProjectRoot(cwd, 0, isCoreApp) || cwd\n } catch (err) {\n throw new Error(`Error occurred trying to resolve project root:\\n${err.message}`)\n }\n}\n\nfunction hasSanityConfig(basePath: string, configName: string): boolean {\n const buildConfigs = [\n fileExists(path.join(basePath, `${configName}.js`)),\n fileExists(path.join(basePath, `${configName}.ts`)),\n isSanityV2StudioRoot(basePath),\n ]\n\n return buildConfigs.some(Boolean)\n}\n\nfunction resolveProjectRoot(basePath: string, iterations = 0, isCoreApp = false): string | false {\n const configName = isCoreApp ? 'sanity.cli' : 'sanity.config'\n if (hasSanityConfig(basePath, configName)) {\n return basePath\n }\n\n const parentDir = path.resolve(basePath, '..')\n if (parentDir === basePath || iterations > 30) {\n // Reached root (or max depth), give up\n return false\n }\n\n return resolveProjectRoot(parentDir, iterations + 1, isCoreApp)\n}\n\nfunction isSanityV2StudioRoot(basePath: string): boolean {\n try {\n const content = fs.readFileSync(path.join(basePath, 'sanity.json'), 'utf8')\n const sanityJson = JSON.parse(content)\n const isRoot = Boolean(sanityJson?.root)\n if (isRoot) {\n debug('Found Sanity v2 studio root at %s', basePath)\n }\n return isRoot\n } catch (err) {\n return false\n }\n}\n\nfunction fileExists(filePath: string): boolean {\n return fs.existsSync(filePath)\n}\n","import {createClient, type SanityClient} from '@sanity/client'\n\nimport {getCliConfigSync} from './util/getCliConfig'\nimport {resolveRootDir} from './util/resolveRootDir'\n\nexport interface CliClientOptions {\n cwd?: string\n\n projectId?: string\n dataset?: string\n useCdn?: boolean\n token?: string\n apiVersion?: string\n}\n\nexport function getCliClient(options: CliClientOptions = {}): SanityClient {\n if (typeof process !== 'object') {\n throw new Error('getCliClient() should only be called from node.js scripts')\n }\n\n const {\n // eslint-disable-next-line no-process-env\n cwd = process.env.SANITY_BASE_PATH || process.cwd(),\n useCdn = false,\n apiVersion = '2022-06-06',\n projectId,\n dataset,\n token = getCliClient.__internal__getToken(),\n } = options\n\n if (projectId && dataset) {\n return createClient({projectId, dataset, apiVersion, useCdn, token})\n }\n\n const rootDir = resolveRootDir(cwd)\n const {config} = getCliConfigSync(rootDir) || {}\n if (!config) {\n throw new Error('Unable to resolve CLI configuration')\n }\n\n const apiConfig = config?.api || {}\n if (!apiConfig.projectId || !apiConfig.dataset) {\n throw new Error('Unable to resolve project ID/dataset from CLI configuration')\n }\n\n return createClient({\n projectId: apiConfig.projectId,\n dataset: apiConfig.dataset,\n apiVersion,\n useCdn,\n token,\n })\n}\n\n/* eslint-disable camelcase */\n/**\n * @internal\n * @deprecated This is only for INTERNAL use, and should not be relied upon outside of official Sanity modules\n * @returns A token to use when constructing a client without a `token` explicitly defined, or undefined\n */\ngetCliClient.__internal__getToken = (): string | undefined => undefined\n/* eslint-enable camelcase */\n","import {type CliConfig} from './types'\n\n/** @beta */\nexport function defineCliConfig(config: CliConfig): CliConfig {\n return config\n}\n\n/**\n * @deprecated Use `defineCliConfig` instead\n * @beta\n */\nexport function createCliConfig(config: CliConfig): CliConfig {\n return config\n}\n","const fs = require('fs')\nconst path = require('path')\nconst os = require('os')\nconst crypto = require('crypto')\nconst packageJson = require('../package.json')\n\nconst version = packageJson.version\n\nconst LINE = /(?:^|^)\\s*(?:export\\s+)?([\\w.-]+)(?:\\s*=\\s*?|:\\s+?)(\\s*'(?:\\\\'|[^'])*'|\\s*\"(?:\\\\\"|[^\"])*\"|\\s*`(?:\\\\`|[^`])*`|[^#\\r\\n]+)?\\s*(?:#.*)?(?:$|$)/mg\n\n// Parse src into an Object\nfunction parse (src) {\n const obj = {}\n\n // Convert buffer to string\n let lines = src.toString()\n\n // Convert line breaks to same format\n lines = lines.replace(/\\r\\n?/mg, '\\n')\n\n let match\n while ((match = LINE.exec(lines)) != null) {\n const key = match[1]\n\n // Default undefined or null to empty string\n let value = (match[2] || '')\n\n // Remove whitespace\n value = value.trim()\n\n // Check if double quoted\n const maybeQuote = value[0]\n\n // Remove surrounding quotes\n value = value.replace(/^(['\"`])([\\s\\S]*)\\1$/mg, '$2')\n\n // Expand newlines if double quoted\n if (maybeQuote === '\"') {\n value = value.replace(/\\\\n/g, '\\n')\n value = value.replace(/\\\\r/g, '\\r')\n }\n\n // Add to object\n obj[key] = value\n }\n\n return obj\n}\n\nfunction _parseVault (options) {\n const vaultPath = _vaultPath(options)\n\n // Parse .env.vault\n const result = DotenvModule.configDotenv({ path: vaultPath })\n if (!result.parsed) {\n const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`)\n err.code = 'MISSING_DATA'\n throw err\n }\n\n // handle scenario for comma separated keys - for use with key rotation\n // example: DOTENV_KEY=\"dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod\"\n const keys = _dotenvKey(options).split(',')\n const length = keys.length\n\n let decrypted\n for (let i = 0; i < length; i++) {\n try {\n // Get full key\n const key = keys[i].trim()\n\n // Get instructions for decrypt\n const attrs = _instructions(result, key)\n\n // Decrypt\n decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key)\n\n break\n } catch (error) {\n // last key\n if (i + 1 >= length) {\n throw error\n }\n // try next key\n }\n }\n\n // Parse decrypted .env string\n return DotenvModule.parse(decrypted)\n}\n\nfunction _log (message) {\n console.log(`[dotenv@${version}][INFO] ${message}`)\n}\n\nfunction _warn (message) {\n console.log(`[dotenv@${version}][WARN] ${message}`)\n}\n\nfunction _debug (message) {\n console.log(`[dotenv@${version}][DEBUG] ${message}`)\n}\n\nfunction _dotenvKey (options) {\n // prioritize developer directly setting options.DOTENV_KEY\n if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {\n return options.DOTENV_KEY\n }\n\n // secondary infra already contains a DOTENV_KEY environment variable\n if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {\n return process.env.DOTENV_KEY\n }\n\n // fallback to empty string\n return ''\n}\n\nfunction _instructions (result, dotenvKey) {\n // Parse DOTENV_KEY. Format is a URI\n let uri\n try {\n uri = new URL(dotenvKey)\n } catch (error) {\n if (error.code === 'ERR_INVALID_URL') {\n const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development')\n err.code = 'INVALID_DOTENV_KEY'\n throw err\n }\n\n throw error\n }\n\n // Get decrypt key\n const key = uri.password\n if (!key) {\n const err = new Error('INVALID_DOTENV_KEY: Missing key part')\n err.code = 'INVALID_DOTENV_KEY'\n throw err\n }\n\n // Get environment\n const environment = uri.searchParams.get('environment')\n if (!environment) {\n const err = new Error('INVALID_DOTENV_KEY: Missing environment part')\n err.code = 'INVALID_DOTENV_KEY'\n throw err\n }\n\n // Get ciphertext payload\n const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`\n const ciphertext = result.parsed[environmentKey] // DOTENV_VAULT_PRODUCTION\n if (!ciphertext) {\n const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`)\n err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT'\n throw err\n }\n\n return { ciphertext, key }\n}\n\nfunction _vaultPath (options) {\n let possibleVaultPath = null\n\n if (options && options.path && options.path.length > 0) {\n if (Array.isArray(options.path)) {\n for (const filepath of options.path) {\n if (fs.existsSync(filepath)) {\n possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`\n }\n }\n } else {\n possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`\n }\n } else {\n possibleVaultPath = path.resolve(process.cwd(), '.env.vault')\n }\n\n if (fs.existsSync(possibleVaultPath)) {\n return possibleVaultPath\n }\n\n return null\n}\n\nfunction _resolveHome (envPath) {\n return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath\n}\n\nfunction _configVault (options) {\n _log('Loading env from encrypted .env.vault')\n\n const parsed = DotenvModule._parseVault(options)\n\n let processEnv = process.env\n if (options && options.processEnv != null) {\n processEnv = options.processEnv\n }\n\n DotenvModule.populate(processEnv, parsed, options)\n\n return { parsed }\n}\n\nfunction configDotenv (options) {\n const dotenvPath = path.resolve(process.cwd(), '.env')\n let encoding = 'utf8'\n const debug = Boolean(options && options.debug)\n\n if (options && options.encoding) {\n encoding = options.encoding\n } else {\n if (debug) {\n _debug('No encoding is specified. UTF-8 is used by default')\n }\n }\n\n let optionPaths = [dotenvPath] // default, look for .env\n if (options && options.path) {\n if (!Array.isArray(options.path)) {\n optionPaths = [_resolveHome(options.path)]\n } else {\n optionPaths = [] // reset default\n for (const filepath of options.path) {\n optionPaths.push(_resolveHome(filepath))\n }\n }\n }\n\n // Build the parsed data in a temporary object (because we need to return it). Once we have the final\n // parsed data, we will combine it with process.env (or options.processEnv if provided).\n let lastError\n const parsedAll = {}\n for (const path of optionPaths) {\n try {\n // Specifying an encoding returns a string instead of a buffer\n const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }))\n\n DotenvModule.populate(parsedAll, parsed, options)\n } catch (e) {\n if (debug) {\n _debug(`Failed to load ${path} ${e.message}`)\n }\n lastError = e\n }\n }\n\n let processEnv = process.env\n if (options && options.processEnv != null) {\n processEnv = options.processEnv\n }\n\n DotenvModule.populate(processEnv, parsedAll, options)\n\n if (lastError) {\n return { parsed: parsedAll, error: lastError }\n } else {\n return { parsed: parsedAll }\n }\n}\n\n// Populates process.env from .env file\nfunction config (options) {\n // fallback to original dotenv if DOTENV_KEY is not set\n if (_dotenvKey(options).length === 0) {\n return DotenvModule.configDotenv(options)\n }\n\n const vaultPath = _vaultPath(options)\n\n // dotenvKey exists but .env.vault file does not exist\n if (!vaultPath) {\n _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`)\n\n return DotenvModule.configDotenv(options)\n }\n\n return DotenvModule._configVault(options)\n}\n\nfunction decrypt (encrypted, keyStr) {\n const key = Buffer.from(keyStr.slice(-64), 'hex')\n let ciphertext = Buffer.from(encrypted, 'base64')\n\n const nonce = ciphertext.subarray(0, 12)\n const authTag = ciphertext.subarray(-16)\n ciphertext = ciphertext.subarray(12, -16)\n\n try {\n const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce)\n aesgcm.setAuthTag(authTag)\n return `${aesgcm.update(ciphertext)}${aesgcm.final()}`\n } catch (error) {\n const isRange = error instanceof RangeError\n const invalidKeyLength = error.message === 'Invalid key length'\n const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data'\n\n if (isRange || invalidKeyLength) {\n const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)')\n err.code = 'INVALID_DOTENV_KEY'\n throw err\n } else if (decryptionFailed) {\n const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY')\n err.code = 'DECRYPTION_FAILED'\n throw err\n } else {\n throw error\n }\n }\n}\n\n// Populate process.env with parsed values\nfunction populate (processEnv, parsed, options = {}) {\n const debug = Boolean(options && options.debug)\n const override = Boolean(options && options.override)\n\n if (typeof parsed !== 'object') {\n const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate')\n err.code = 'OBJECT_REQUIRED'\n throw err\n }\n\n // Set process.env\n for (const key of Object.keys(parsed)) {\n if (Object.prototype.hasOwnProperty.call(processEnv, key)) {\n if (override === true) {\n processEnv[key] = parsed[key]\n }\n\n if (debug) {\n if (override === true) {\n _debug(`\"${key}\" is already defined and WAS overwritten`)\n } else {\n _debug(`\"${key}\" is already defined and was NOT overwritten`)\n }\n }\n } else {\n processEnv[key] = parsed[key]\n }\n }\n}\n\nconst DotenvModule = {\n configDotenv,\n _configVault,\n _parseVault,\n config,\n decrypt,\n parse,\n populate\n}\n\nmodule.exports.configDotenv = DotenvModule.configDotenv\nmodule.exports._configVault = DotenvModule._configVault\nmodule.exports._parseVault = DotenvModule._parseVault\nmodule.exports.config = DotenvModule.config\nmodule.exports.decrypt = DotenvModule.decrypt\nmodule.exports.parse = DotenvModule.parse\nmodule.exports.populate = DotenvModule.populate\n\nmodule.exports = DotenvModule\n","'use strict'\n\nfunction _interpolate (envValue, environment, config) {\n const matches = envValue.match(/(.?\\${*[\\w]*(?::-[\\w/]*)?}*)/g) || []\n\n return matches.reduce(function (newEnv, match, index) {\n const parts = /(.?)\\${*([\\w]*(?::-[\\w/]*)?)?}*/g.exec(match)\n if (!parts || parts.length === 0) {\n return newEnv\n }\n\n const prefix = parts[1]\n\n let value, replacePart\n\n if (prefix === '\\\\') {\n replacePart = parts[0]\n value = replacePart.replace('\\\\$', '$')\n } else {\n const keyParts = parts[2].split(':-')\n const key = keyParts[0]\n replacePart = parts[0].substring(prefix.length)\n // process.env value 'wins' over .env file's value\n value = Object.prototype.hasOwnProperty.call(environment, key)\n ? environment[key]\n : (config.parsed[key] || keyParts[1] || '')\n\n // If the value is found, remove nested expansions.\n if (keyParts.length > 1 && value) {\n const replaceNested = matches[index + 1]\n matches[index + 1] = ''\n\n newEnv = newEnv.replace(replaceNested, '')\n }\n // Resolve recursive interpolations\n value = _interpolate(value, environment, config)\n }\n\n return newEnv.replace(replacePart, value)\n }, envValue)\n}\n\nfunction expand (config) {\n // if ignoring process.env, use a blank object\n const environment = config.ignoreProcessEnv ? {} : process.env\n\n for (const configKey in config.parsed) {\n const value = Object.prototype.hasOwnProperty.call(environment, configKey) ? environment[configKey] : config.parsed[configKey]\n\n config.parsed[configKey] = _interpolate(value, environment, config)\n }\n\n for (const processKey in config.parsed) {\n environment[processKey] = config.parsed[processKey]\n }\n\n return config\n}\n\nmodule.exports.expand = expand\n","/**\n * This is an \"inlined\" version of Vite's `loadEnv` function,\n * simplified somewhat to only support our use case.\n *\n * Ideally we'd just use `loadEnv` from Vite, but importing it\n * causes bundling issues due to node APIs and downstream dependencies.\n *\n * Vite is MIT licensed, copyright (c) Yuxi (Evan) You and Vite contributors.\n */\n\n/* eslint-disable no-process-env */\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport {parse} from 'dotenv'\nimport {expand} from 'dotenv-expand'\n\nexport function loadEnv(\n mode: string,\n envDir: string,\n prefixes: string[] = ['VITE_'],\n): Record<string, string> {\n if (mode === 'local') {\n throw new Error(\n `\"local\" cannot be used as a mode name because it conflicts with ` +\n `the .local postfix for .env files.`,\n )\n }\n\n const env: Record<string, string> = {}\n const envFiles = [\n /** default file */ `.env`,\n /** local file */ `.env.local`,\n /** mode file */ `.env.${mode}`,\n /** mode local file */ `.env.${mode}.local`,\n ]\n\n const parsed = Object.fromEntries(\n envFiles.flatMap((file) => {\n const envPath = lookupFile(envDir, [file], {\n rootDir: envDir,\n })\n if (!envPath) return []\n return Object.entries(parse(fs.readFileSync(envPath)))\n }),\n )\n\n // test NODE_ENV override before expand as otherwise process.env.NODE_ENV would override this\n if (parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === undefined) {\n process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV\n }\n // support BROWSER and BROWSER_ARGS env variables\n if (parsed.BROWSER && process.env.BROWSER === undefined) {\n process.env.BROWSER = parsed.BROWSER\n }\n if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === undefined) {\n process.env.BROWSER_ARGS = parsed.BROWSER_ARGS\n }\n\n try {\n // let environment variables use each other\n expand({parsed})\n } catch (e) {\n // custom error handling until https://github.com/motdotla/dotenv-expand/issues/65 is fixed upstream\n // check for message \"TypeError: Cannot read properties of undefined (reading 'split')\"\n if (e.message.includes('split')) {\n throw new Error('dotenv-expand failed to expand env vars. Maybe you need to escape `$`?')\n }\n throw e\n }\n\n // only keys that start with prefix are exposed to client\n for (const [key, value] of Object.entries(parsed)) {\n if (prefixes.some((prefix) => key.startsWith(prefix))) {\n env[key] = value\n }\n }\n\n // check if there are actual env variables starting with VITE_*\n // these are typically provided inline and should be prioritized\n for (const key in process.env) {\n if (prefixes.some((prefix) => key.startsWith(prefix))) {\n env[key] = process.env[key] as string\n }\n }\n\n return env\n}\n\nfunction lookupFile(\n dir: string,\n formats: string[],\n options?: {\n rootDir?: string\n },\n): string | undefined {\n for (const format of formats) {\n const fullPath = path.join(dir, format)\n // eslint-disable-next-line no-sync\n if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile()) {\n return fullPath\n }\n }\n const parentDir = path.dirname(dir)\n if (parentDir !== dir && (!options?.rootDir || parentDir.startsWith(options?.rootDir))) {\n return lookupFile(parentDir, formats, options)\n }\n\n return undefined\n}\n"],"names":["fs","path","version","debug","mainModule","parse","expand"],"mappings":";;;;;;;;AAOA,MAAM,cACJ,OAAO,uBAAwB,aAAa,0BAA0B;AAGjE,SAAS,eAAwB,SAAoB;AACpD,QAAA,MAAM,YAAY,OAAO;AAC/B,SAAO,IAAI,cAAc,IAAI,UAAU,IAAI,UAAU;AACvD;AAEA,eAAe,UAAU,YAAY;AC4C9B,SAAS,iBAAiB,KAAqC;AAE7D,SADU,mBAAmB,GAAG,KACV,oBAAoB,GAAG;AACtD;AA4BA,SAAS,oBAAoB,KAAqC;AAChE,QAAM,aAAa,KAAK,KAAK,KAAK,aAAa;AAE1C,SAAA,GAAG,WAAW,UAAU,IAItB;AAAA,IACL,QAAQ,eAAe,UAAU;AAAA,IACjC,MAAM;AAAA,IACN,SAAS;AAAA,EAAA,IANF;AAQX;AAEA,SAAS,mBAAmB,KAAqC;AACzD,QAAA,eAAe,KA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MAAM;AAC1C,aAAS,KAAK,CAAC,WAAW,IAAI,WAAW,MAAM,CAAC,MAClD,IAAI,GAAG,IAAI;AAMf,aAAW,OAAO,QAAQ;AACpB,aAAS,KAAK,CAAC,WAAW,IAAI,WAAW,MAAM,CAAC,MAClD,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG;AAIvB,SAAA;AACT;AAEA,SAAS,WACP,KACA,SACA,SAGoB;AACpB,aAAW,UAAU,SAAS;AAC5B,UAAM,WAAW,KAAK,KAAK,KAAK,MAAM;AAElC,QAAA,GAAG,WAAW,QAAQ,KAAK,GAAG,SAAS,QAAQ,EAAE,OAAO;AACnD,aAAA;AAAA,EAAA;AAGL,QAAA,YAAY,KAAK,QAAQ,GAAG;AAC9B,MAAA,cAAc,QAAQ,CAAC,SAAS,WAAW,UAAU,WAAW,SAAS,OAAO;AAC3E,WAAA,WAAW,WAAW,SAAS,OAAO;AAIjD;","x_google_ignoreList":[6,7]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sanity/cli",
|
3
|
-
"version": "3.74.2-canary.
|
3
|
+
"version": "3.74.2-canary.89+98ef8b83c9",
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -57,11 +57,11 @@
|
|
57
57
|
},
|
58
58
|
"dependencies": {
|
59
59
|
"@babel/traverse": "^7.23.5",
|
60
|
-
"@sanity/client": "^6.
|
61
|
-
"@sanity/codegen": "3.74.2-canary.
|
60
|
+
"@sanity/client": "^6.28.0",
|
61
|
+
"@sanity/codegen": "3.74.2-canary.89+98ef8b83c9",
|
62
62
|
"@sanity/telemetry": "^0.7.7",
|
63
63
|
"@sanity/template-validator": "^2.4.0",
|
64
|
-
"@sanity/util": "3.74.2-canary.
|
64
|
+
"@sanity/util": "3.74.2-canary.89+98ef8b83c9",
|
65
65
|
"chalk": "^4.1.2",
|
66
66
|
"debug": "^4.3.4",
|
67
67
|
"decompress": "^4.2.0",
|
@@ -75,13 +75,13 @@
|
|
75
75
|
"validate-npm-package-name": "^3.0.0"
|
76
76
|
},
|
77
77
|
"devDependencies": {
|
78
|
-
"@repo/package.config": "3.
|
79
|
-
"@repo/test-config": "3.
|
78
|
+
"@repo/package.config": "3.75.0",
|
79
|
+
"@repo/test-config": "3.75.0",
|
80
80
|
"@rexxars/gitconfiglocal": "^3.0.1",
|
81
81
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
82
82
|
"@sanity/eslint-config-studio": "^4.0.0",
|
83
83
|
"@sanity/generate-help-url": "^3.0.0",
|
84
|
-
"@sanity/types": "3.74.2-canary.
|
84
|
+
"@sanity/types": "3.74.2-canary.89+98ef8b83c9",
|
85
85
|
"@types/babel__traverse": "^7.20.5",
|
86
86
|
"@types/configstore": "^5.0.1",
|
87
87
|
"@types/cpx": "^1.5.2",
|
@@ -133,5 +133,5 @@
|
|
133
133
|
"engines": {
|
134
134
|
"node": ">=18"
|
135
135
|
},
|
136
|
-
"gitHead": "
|
136
|
+
"gitHead": "98ef8b83c9427e03fad51b581d0339c6dea0a463"
|
137
137
|
}
|
@@ -130,10 +130,7 @@ export async function bootstrapLocalTemplate(
|
|
130
130
|
|
131
131
|
// ...and a CLI config (`sanity.cli.[ts|js]`)
|
132
132
|
const cliConfig = isCoreAppTemplate
|
133
|
-
? createCoreAppCliConfig({
|
134
|
-
appLocation: template.appLocation!,
|
135
|
-
organizationId: variables.organizationId,
|
136
|
-
})
|
133
|
+
? createCoreAppCliConfig({appLocation: template.appLocation!})
|
137
134
|
: createCliConfig({
|
138
135
|
projectId: variables.projectId,
|
139
136
|
dataset: variables.dataset,
|
@@ -266,20 +266,23 @@ export default async function initSanity(
|
|
266
266
|
await getOrCreateUser()
|
267
267
|
}
|
268
268
|
|
269
|
+
// skip project / dataset prompting
|
270
|
+
const isCoreAppTemplate = cliFlags.template ? determineCoreAppTemplate(cliFlags.template) : false // Default to false
|
271
|
+
|
269
272
|
let introMessage = 'Fetching existing projects'
|
270
273
|
if (cliFlags.quickstart) {
|
271
274
|
introMessage = "Eject your existing project's Sanity configuration"
|
272
275
|
}
|
273
|
-
|
274
|
-
|
276
|
+
|
277
|
+
if (!isCoreAppTemplate) {
|
278
|
+
success(introMessage)
|
279
|
+
print('')
|
280
|
+
}
|
275
281
|
|
276
282
|
const flags = await prepareFlags()
|
277
|
-
// skip project / dataset prompting
|
278
|
-
const isCoreAppTemplate = cliFlags.template ? determineCoreAppTemplate(cliFlags.template) : false // Default to false
|
279
283
|
|
280
|
-
// We're authenticated, now lets select or create a project
|
281
|
-
const {projectId, displayName, isFirstProject, datasetName, schemaUrl
|
282
|
-
await getProjectDetails()
|
284
|
+
// We're authenticated, now lets select or create a project
|
285
|
+
const {projectId, displayName, isFirstProject, datasetName, schemaUrl} = await getProjectDetails()
|
283
286
|
|
284
287
|
const sluggedName = deburr(displayName.toLowerCase())
|
285
288
|
.replace(/\s+/g, '-')
|
@@ -716,7 +719,6 @@ export default async function initSanity(
|
|
716
719
|
displayName: string
|
717
720
|
isFirstProject: boolean
|
718
721
|
schemaUrl?: string
|
719
|
-
organizationId?: string
|
720
722
|
}> {
|
721
723
|
// If we're doing a quickstart, we don't need to prompt for project details
|
722
724
|
if (flags.quickstart) {
|
@@ -733,17 +735,11 @@ export default async function initSanity(
|
|
733
735
|
}
|
734
736
|
|
735
737
|
if (isCoreAppTemplate) {
|
736
|
-
const client = apiClient({requireUser: true, requireProject: false})
|
737
|
-
const organizations = await client.request({uri: '/organizations'})
|
738
|
-
|
739
|
-
const coreAppOrganizationId = await getOrganizationId(organizations)
|
740
|
-
|
741
738
|
return {
|
742
739
|
projectId: '',
|
743
740
|
displayName: '',
|
744
|
-
datasetName: '',
|
745
741
|
isFirstProject: false,
|
746
|
-
|
742
|
+
datasetName: '',
|
747
743
|
}
|
748
744
|
}
|
749
745
|
|
@@ -1099,7 +1095,6 @@ export default async function initSanity(
|
|
1099
1095
|
dataset: datasetName,
|
1100
1096
|
projectId,
|
1101
1097
|
projectName: displayName || answers.projectName,
|
1102
|
-
organizationId,
|
1103
1098
|
}
|
1104
1099
|
|
1105
1100
|
if (remoteTemplateInfo) {
|
@@ -1239,12 +1234,12 @@ export default async function initSanity(
|
|
1239
1234
|
}
|
1240
1235
|
|
1241
1236
|
async function getOrganizationId(organizations: ProjectOrganization[]) {
|
1242
|
-
let
|
1237
|
+
let organizationId = flags.organization
|
1243
1238
|
if (unattended) {
|
1244
|
-
return
|
1239
|
+
return organizationId || undefined
|
1245
1240
|
}
|
1246
1241
|
|
1247
|
-
const shouldPrompt = organizations.length > 0 && !
|
1242
|
+
const shouldPrompt = organizations.length > 0 && !organizationId
|
1248
1243
|
if (shouldPrompt) {
|
1249
1244
|
debug(`User has ${organizations.length} organization(s), checking attach access`)
|
1250
1245
|
const withGrant = await getOrganizationsWithAttachGrant(organizations)
|
@@ -1270,18 +1265,18 @@ export default async function initSanity(
|
|
1270
1265
|
})
|
1271
1266
|
|
1272
1267
|
if (chosenOrg && chosenOrg !== 'none') {
|
1273
|
-
|
1268
|
+
organizationId = chosenOrg
|
1274
1269
|
}
|
1275
|
-
} else if (
|
1276
|
-
debug(`User has defined organization flag explicitly (%s)`,
|
1270
|
+
} else if (organizationId) {
|
1271
|
+
debug(`User has defined organization flag explicitly (%s)`, organizationId)
|
1277
1272
|
} else if (organizations.length === 0) {
|
1278
1273
|
debug('User has no organizations, skipping selection prompt')
|
1279
1274
|
}
|
1280
1275
|
|
1281
|
-
return
|
1276
|
+
return organizationId || undefined
|
1282
1277
|
}
|
1283
1278
|
|
1284
|
-
async function hasProjectAttachGrant(
|
1279
|
+
async function hasProjectAttachGrant(organizationId: string) {
|
1285
1280
|
const requiredGrantGroup = 'sanity.organization.projects'
|
1286
1281
|
const requiredGrant = 'attach'
|
1287
1282
|
|
@@ -1289,7 +1284,7 @@ export default async function initSanity(
|
|
1289
1284
|
.clone()
|
1290
1285
|
.config({apiVersion: 'v2021-06-07'})
|
1291
1286
|
|
1292
|
-
const grants = await client.request({uri: `organizations/${
|
1287
|
+
const grants = await client.request({uri: `organizations/${organizationId}/grants`})
|
1293
1288
|
const group: {grants: {name: string}[]}[] = grants[requiredGrantGroup] || []
|
1294
1289
|
return group.some(
|
1295
1290
|
(resource) =>
|
package/src/cli.ts
CHANGED
@@ -47,16 +47,17 @@ export async function runCli(cliRoot: string, {cliVersion}: {cliVersion: string}
|
|
47
47
|
|
48
48
|
const args = parseArguments()
|
49
49
|
const isInit = args.groupOrCommand === 'init' && args.argsWithoutOptions[0] !== 'plugin'
|
50
|
+
const isCoreApp = args.groupOrCommand === 'app'
|
50
51
|
const cwd = getCurrentWorkingDirectory()
|
51
52
|
let workDir: string | undefined
|
52
53
|
try {
|
53
|
-
workDir = isInit ? process.cwd() : resolveRootDir(cwd)
|
54
|
+
workDir = isInit ? process.cwd() : resolveRootDir(cwd, isCoreApp)
|
54
55
|
} catch (err) {
|
55
56
|
console.error(chalk.red(err.message))
|
56
57
|
process.exit(1)
|
57
58
|
}
|
58
59
|
|
59
|
-
loadAndSetEnvFromDotEnvFiles({workDir, cmd: args.groupOrCommand})
|
60
|
+
loadAndSetEnvFromDotEnvFiles({workDir, cmd: args.groupOrCommand, isCoreApp})
|
60
61
|
maybeFixMissingWindowsEnvVar()
|
61
62
|
|
62
63
|
// Check if there are updates available for the CLI, and notify if there is
|
@@ -99,6 +100,7 @@ export async function runCli(cliRoot: string, {cliVersion}: {cliVersion: string}
|
|
99
100
|
corePath: await getCoreModulePath(workDir, cliConfig),
|
100
101
|
cliConfig,
|
101
102
|
telemetry,
|
103
|
+
isCoreApp,
|
102
104
|
}
|
103
105
|
|
104
106
|
warnOnNonProductionEnvironment()
|
@@ -274,14 +276,22 @@ function warnOnNonProductionEnvironment(): void {
|
|
274
276
|
)
|
275
277
|
}
|
276
278
|
|
277
|
-
function loadAndSetEnvFromDotEnvFiles({
|
279
|
+
function loadAndSetEnvFromDotEnvFiles({
|
280
|
+
workDir,
|
281
|
+
cmd,
|
282
|
+
isCoreApp,
|
283
|
+
}: {
|
284
|
+
workDir: string
|
285
|
+
cmd: string
|
286
|
+
isCoreApp: boolean
|
287
|
+
}) {
|
278
288
|
/* eslint-disable no-process-env */
|
279
289
|
|
280
290
|
// Do a cheap lookup for a sanity.json file. If there is one, assume it is a v2 project,
|
281
291
|
// and apply the old behavior for environment variables. Otherwise, use the Vite-style
|
282
292
|
// behavior. We need to do this "cheap" lookup because when loading the v3 config, env vars
|
283
293
|
// may be used in the configuration file, meaning we'd have to load the config twice.
|
284
|
-
if (existsSync(path.join(workDir, 'sanity.json'))) {
|
294
|
+
if (existsSync(path.join(workDir, 'sanity.json')) && !isCoreApp) {
|
285
295
|
// v2
|
286
296
|
debug('sanity.json exists, assuming v2 project and loading .env files using old behavior')
|
287
297
|
const env = process.env.SANITY_ACTIVE_ENV || process.env.NODE_ENV || 'development'
|
@@ -309,7 +319,7 @@ function loadAndSetEnvFromDotEnvFiles({workDir, cmd}: {workDir: string; cmd: str
|
|
309
319
|
|
310
320
|
debug('Loading environment files using %s mode', mode)
|
311
321
|
|
312
|
-
const studioEnv = loadEnv(mode, workDir, ['SANITY_STUDIO_'])
|
322
|
+
const studioEnv = loadEnv(mode, workDir, isCoreApp ? ['VITE_'] : ['SANITY_STUDIO_'])
|
313
323
|
process.env = {...process.env, ...studioEnv}
|
314
324
|
/* eslint-disable no-process-env */
|
315
325
|
}
|
package/src/types.ts
CHANGED
@@ -147,6 +147,7 @@ export interface CommandRunnerOptions {
|
|
147
147
|
workDir: string
|
148
148
|
corePath: string | undefined
|
149
149
|
telemetry: TelemetryLogger<TelemetryUserProperties>
|
150
|
+
isCoreApp: boolean
|
150
151
|
}
|
151
152
|
|
152
153
|
export interface CliOutputter {
|
@@ -182,8 +183,8 @@ export type CliStubbedYarn = (args: string[], options?: CliYarnOptions) => Promi
|
|
182
183
|
|
183
184
|
export interface CliApiConfig {
|
184
185
|
projectId?: string
|
185
|
-
organizationId?: string
|
186
186
|
dataset?: string
|
187
|
+
organizationId?: string
|
187
188
|
}
|
188
189
|
|
189
190
|
export interface SanityJson {
|
@@ -354,6 +355,7 @@ export interface CliConfig {
|
|
354
355
|
*/
|
355
356
|
__experimental_coreAppConfiguration?: {
|
356
357
|
appLocation?: string
|
358
|
+
appHost?: string
|
357
359
|
}
|
358
360
|
}
|
359
361
|
|
@@ -7,26 +7,27 @@ import {debug} from '../debug'
|
|
7
7
|
/**
|
8
8
|
* Resolve project root directory, falling back to cwd if it cannot be found
|
9
9
|
*/
|
10
|
-
export function resolveRootDir(cwd: string): string {
|
10
|
+
export function resolveRootDir(cwd: string, isCoreApp = false): string {
|
11
11
|
try {
|
12
|
-
return resolveProjectRoot(cwd) || cwd
|
12
|
+
return resolveProjectRoot(cwd, 0, isCoreApp) || cwd
|
13
13
|
} catch (err) {
|
14
14
|
throw new Error(`Error occurred trying to resolve project root:\n${err.message}`)
|
15
15
|
}
|
16
16
|
}
|
17
17
|
|
18
|
-
function
|
18
|
+
function hasSanityConfig(basePath: string, configName: string): boolean {
|
19
19
|
const buildConfigs = [
|
20
|
-
fileExists(path.join(basePath,
|
21
|
-
fileExists(path.join(basePath,
|
20
|
+
fileExists(path.join(basePath, `${configName}.js`)),
|
21
|
+
fileExists(path.join(basePath, `${configName}.ts`)),
|
22
22
|
isSanityV2StudioRoot(basePath),
|
23
23
|
]
|
24
24
|
|
25
25
|
return buildConfigs.some(Boolean)
|
26
26
|
}
|
27
27
|
|
28
|
-
function resolveProjectRoot(basePath: string, iterations = 0): string | false {
|
29
|
-
|
28
|
+
function resolveProjectRoot(basePath: string, iterations = 0, isCoreApp = false): string | false {
|
29
|
+
const configName = isCoreApp ? 'sanity.cli' : 'sanity.config'
|
30
|
+
if (hasSanityConfig(basePath, configName)) {
|
30
31
|
return basePath
|
31
32
|
}
|
32
33
|
|
@@ -36,7 +37,7 @@ function resolveProjectRoot(basePath: string, iterations = 0): string | false {
|
|
36
37
|
return false
|
37
38
|
}
|
38
39
|
|
39
|
-
return resolveProjectRoot(parentDir, iterations + 1)
|
40
|
+
return resolveProjectRoot(parentDir, iterations + 1, isCoreApp)
|
40
41
|
}
|
41
42
|
|
42
43
|
function isSanityV2StudioRoot(basePath: string): boolean {
|