gt 2.25.2 → 2.26.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/api/downloadFileBatch.js +8 -9
  3. package/dist/api/downloadFileBatch.js.map +1 -1
  4. package/dist/bin/bin-entry.js +1 -1
  5. package/dist/cli/base.js +9 -7
  6. package/dist/cli/base.js.map +1 -1
  7. package/dist/generated/version.d.ts +1 -1
  8. package/dist/generated/version.js +1 -1
  9. package/dist/generated/version.js.map +1 -1
  10. package/dist/main.js +1 -1
  11. package/dist/setup/buildTools/index.d.ts +6 -0
  12. package/dist/setup/buildTools/index.js +6 -1
  13. package/dist/setup/buildTools/index.js.map +1 -1
  14. package/dist/setup/buildTools/reactRouter/index.d.ts +2 -0
  15. package/dist/setup/buildTools/reactRouter/index.js +127 -0
  16. package/dist/setup/buildTools/reactRouter/index.js.map +1 -0
  17. package/dist/setup/buildTools/reactRouter/root.d.ts +23 -0
  18. package/dist/setup/buildTools/reactRouter/root.js +218 -0
  19. package/dist/setup/buildTools/reactRouter/root.js.map +1 -0
  20. package/dist/setup/buildTools/reactRouter/source.d.ts +8 -0
  21. package/dist/setup/buildTools/reactRouter/source.js +106 -0
  22. package/dist/setup/buildTools/reactRouter/source.js.map +1 -0
  23. package/dist/setup/buildTools/shared/document.d.ts +29 -0
  24. package/dist/setup/buildTools/shared/document.js +76 -0
  25. package/dist/setup/buildTools/shared/document.js.map +1 -0
  26. package/dist/setup/buildTools/shared/edits.d.ts +1 -2
  27. package/dist/setup/buildTools/shared/edits.js.map +1 -1
  28. package/dist/setup/buildTools/shared/initializeGT.d.ts +21 -0
  29. package/dist/setup/buildTools/shared/initializeGT.js +50 -0
  30. package/dist/setup/buildTools/shared/initializeGT.js.map +1 -0
  31. package/dist/setup/buildTools/shared/loader.d.ts +6 -0
  32. package/dist/setup/buildTools/shared/loader.js +24 -0
  33. package/dist/setup/buildTools/shared/loader.js.map +1 -0
  34. package/dist/setup/buildTools/shared/source.d.ts +29 -3
  35. package/dist/setup/buildTools/shared/source.js +44 -7
  36. package/dist/setup/buildTools/shared/source.js.map +1 -1
  37. package/dist/setup/buildTools/tanstackStart/index.js +17 -12
  38. package/dist/setup/buildTools/tanstackStart/index.js.map +1 -1
  39. package/dist/setup/buildTools/tanstackStart/root.d.ts +1 -4
  40. package/dist/setup/buildTools/tanstackStart/root.js +17 -57
  41. package/dist/setup/buildTools/tanstackStart/root.js.map +1 -1
  42. package/dist/setup/buildTools/tanstackStart/router.d.ts +1 -9
  43. package/dist/setup/buildTools/tanstackStart/router.js +7 -39
  44. package/dist/setup/buildTools/tanstackStart/router.js.map +1 -1
  45. package/dist/setup/buildTools/vite.js +3 -11
  46. package/dist/setup/buildTools/vite.js.map +1 -1
  47. package/dist/setup/detectFramework.d.ts +1 -1
  48. package/dist/setup/detectFramework.js +5 -1
  49. package/dist/setup/detectFramework.js.map +1 -1
  50. package/dist/setup/developmentCredentials.js +39 -8
  51. package/dist/setup/developmentCredentials.js.map +1 -1
  52. package/dist/setup/frameworkUtils.js +1 -0
  53. package/dist/setup/frameworkUtils.js.map +1 -1
  54. package/dist/setup/wizard.js +4 -0
  55. package/dist/setup/wizard.js.map +1 -1
  56. package/dist/types/index.d.ts +1 -1
  57. package/dist/types/index.js +2 -1
  58. package/dist/types/index.js.map +1 -1
  59. package/dist/utils/constants.d.ts +1 -0
  60. package/dist/utils/constants.js +2 -1
  61. package/dist/utils/constants.js.map +1 -1
  62. package/dist/utils/credentials.js +2 -1
  63. package/dist/utils/credentials.js.map +1 -1
  64. package/dist/utils/loadEnv.d.ts +2 -0
  65. package/dist/utils/loadEnv.js +10 -9
  66. package/dist/utils/loadEnv.js.map +1 -1
  67. package/dist/utils/reactPackageCompatibility.d.ts +5 -0
  68. package/dist/utils/reactPackageCompatibility.js +11 -7
  69. package/dist/utils/reactPackageCompatibility.js.map +1 -1
  70. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../../src/utils/constants.ts"],"sourcesContent":["import { hashStringSync } from './hash.js';\n\nexport const GT_DASHBOARD_URL = 'https://dash.generaltranslation.com';\n\nexport const REACT_QUICKSTART_URL =\n 'https://generaltranslation.com/docs/react/tutorials/quickstart';\n\nexport const GT_CONFIG_SCHEMA_URL = 'https://assets.gtx.dev/config-schema.json';\n\nexport const TEMPLATE_FILE_NAME = '__INTERNAL_GT_TEMPLATE_NAME__';\nexport const TEMPLATE_FILE_ID = hashStringSync(TEMPLATE_FILE_NAME);\n\nexport const DEFAULT_GIT_REMOTE_NAME = 'origin';\n\nexport const DEFAULT_TIMEOUT_SECONDS = 900;\n\n// Number of source code lines to capture above and below a translation site\nexport const SURROUNDING_LINE_COUNT = 5;\n\n// Default translations directory paths\nexport const DEFAULT_TRANSLATIONS_DIR = './public/_gt';\nexport const DEFAULT_VITE_TRANSLATIONS_DIR = './src/_gt';\n"],"mappings":";;AAEA,MAAa,mBAAmB;AAEhC,MAAa,uBACX;AAEF,MAAa,uBAAuB;AAEpC,MAAa,qBAAqB;AAClC,MAAa,mBAAmB,eAAe,mBAAmB;AAElE,MAAa,0BAA0B;AAEvC,MAAa,0BAA0B;AAGvC,MAAa,yBAAyB;AAGtC,MAAa,2BAA2B;AACxC,MAAa,gCAAgC"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../src/utils/constants.ts"],"sourcesContent":["import { hashStringSync } from './hash.js';\n\nexport const GT_DASHBOARD_URL = 'https://dash.generaltranslation.com';\n\nexport const REACT_QUICKSTART_URL =\n 'https://generaltranslation.com/docs/react/tutorials/quickstart';\n\nexport const GT_CONFIG_SCHEMA_URL = 'https://assets.gtx.dev/config-schema.json';\n\nexport const TEMPLATE_FILE_NAME = '__INTERNAL_GT_TEMPLATE_NAME__';\nexport const TEMPLATE_FILE_ID = hashStringSync(TEMPLATE_FILE_NAME);\n\nexport const DEFAULT_GIT_REMOTE_NAME = 'origin';\n\nexport const DEFAULT_TIMEOUT_SECONDS = 900;\n\n// Number of source code lines to capture above and below a translation site\nexport const SURROUNDING_LINE_COUNT = 5;\n\n// Default translations directory paths\nexport const DEFAULT_TRANSLATIONS_DIR = './public/_gt';\nexport const DEFAULT_VITE_TRANSLATIONS_DIR = './src/_gt';\nexport const DEFAULT_REACT_ROUTER_TRANSLATIONS_DIR = './app/_gt';\n"],"mappings":";;AAEA,MAAa,mBAAmB;AAEhC,MAAa,uBACX;AAEF,MAAa,uBAAuB;AAEpC,MAAa,qBAAqB;AAClC,MAAa,mBAAmB,eAAe,mBAAmB;AAElE,MAAa,0BAA0B;AAEvC,MAAa,0BAA0B;AAGvC,MAAa,yBAAyB;AAGtC,MAAa,2BAA2B;AACxC,MAAa,gCAAgC;AAC7C,MAAa,wCAAwC"}
@@ -74,7 +74,8 @@ const FRAMEWORK_ENV_PREFIXES = {
74
74
  gatsby: "GATSBY_",
75
75
  react: "REACT_APP_",
76
76
  redwood: "REDWOOD_ENV_",
77
- "tanstack-start": "VITE_"
77
+ "tanstack-start": "VITE_",
78
+ "react-router": "VITE_"
78
79
  };
79
80
  /** Names of the runtime variables init writes for this framework. */
80
81
  function getDevelopmentEnvNames(framework) {
@@ -1 +1 @@
1
- {"version":3,"file":"credentials.js","names":[],"sources":["../../src/utils/credentials.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { randomUUID } from 'node:crypto';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport { promisify } from 'node:util';\nimport dotenv from 'dotenv';\nimport { Settings, SupportedFrameworks } from '../types/index.js';\nimport {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\n\nconst execFileAsync = promisify(execFile);\n\nconst unsafeCredentialsEnvError = createDiagnosticMessage({\n whatHappened: 'Cannot safely update .env.local',\n reassurance: 'The existing .env.local file was not changed',\n fix: 'Move multiline values away from project/key assignments or set the development credentials manually, then retry',\n});\n\nfunction unwritableEnvFileError(envFile: string): string {\n return createDiagnosticMessage({\n whatHappened: `${envFile} is not a regular file`,\n reassurance: 'Nothing was changed',\n fix: 'Replace it with a regular file or a symlink to one, or set the development credentials manually, then retry',\n });\n}\n\nfunction trackedEnvFileError(file: string): string {\n return createDiagnosticMessage({\n whatHappened: `${file} is tracked by Git`,\n why: 'development credentials saved there would be committed',\n reassurance: 'Nothing was changed',\n fix: `Run \\`git rm --cached ${path.basename(file)}\\` in ${path.dirname(file)} and add the file to .gitignore, then retry`,\n });\n}\n\nfunction unignoredEnvFileError(file: string): string {\n return createDiagnosticMessage({\n whatHappened: `${file} is not ignored by Git`,\n why: 'development credentials saved there could be committed',\n reassurance: 'Nothing was changed',\n fix: `Add the file to a .gitignore that applies to ${path.dirname(file)}, then retry`,\n });\n}\n\nfunction unignoredEnvFileReferentError(envFile: string, referent: string) {\n return createDiagnosticMessage({\n whatHappened: `${envFile} links to ${referent}, which Git does not ignore`,\n why: 'development credentials saved there could be committed',\n reassurance: 'Nothing was changed',\n fix: `Add ${referent} to a .gitignore in its repository or set the development credentials manually, then retry`,\n });\n}\n\nfunction gitUnavailableError(file: string, error: unknown): string {\n return createDiagnosticMessage({\n whatHappened: `Could not run Git to verify that ${file} is untracked and ignored`,\n reassurance: 'Nothing was changed',\n fix: 'Install Git or make it available on PATH, then retry',\n details: formatDiagnosticErrorDetails(error),\n });\n}\n\nfunction gitOverrideError(file: string, names: string[]): string {\n return createDiagnosticMessage({\n whatHappened: `Git repository overrides are set in the environment: ${names.join(', ')}`,\n why: `they could point the untracked and ignore checks for ${file} at a different repository or index`,\n reassurance: 'Nothing was changed',\n fix: 'Unset them (for example, run outside a Git hook), then retry',\n });\n}\n\nfunction gitCheckFailedError(file: string, stderr: string): string {\n return createDiagnosticMessage({\n whatHappened: `Git could not check whether ${file} is untracked and ignored`,\n reassurance: 'Nothing was changed',\n fix: 'Fix the reported Git problem, then retry',\n details: stderr.trim(),\n });\n}\n\nexport type Credentials = { apiKey: string; projectId: string };\n\n// Include server-rendered frameworks with client-side development translation.\nconst FRAMEWORK_ENV_PREFIXES: Partial<\n Record<NonNullable<SupportedFrameworks>, string>\n> = {\n 'next-app': 'NEXT_PUBLIC_',\n 'next-pages': 'NEXT_PUBLIC_',\n vite: 'VITE_',\n gatsby: 'GATSBY_',\n react: 'REACT_APP_',\n redwood: 'REDWOOD_ENV_',\n 'tanstack-start': 'VITE_',\n};\n\n/** Names of the runtime variables init writes for this framework. */\nexport function getDevelopmentEnvNames(framework?: SupportedFrameworks) {\n const prefix = (framework && FRAMEWORK_ENV_PREFIXES[framework]) ?? '';\n return {\n projectId: `${prefix}GT_PROJECT_ID`,\n devApiKey: `${prefix}GT_DEV_API_KEY`,\n };\n}\n\n/**\n * Whether the project has the framework's development key, or an explicit\n * API key for a server-only runtime. A tooling key cannot enable client-side\n * hot reload, including in Next.js App Router. `settings.projectId` already\n * resolves every framework prefix. Login is checked separately.\n */\nexport function areCredentialsSet(\n settings: Pick<Settings, 'projectId' | 'apiKey'>,\n framework?: SupportedFrameworks\n): boolean {\n const { devApiKey } = getDevelopmentEnvNames(framework);\n const needsPublicKey = Boolean(\n framework && FRAMEWORK_ENV_PREFIXES[framework]\n );\n return Boolean(\n settings.projectId &&\n (process.env[devApiKey] || (!needsPublicKey && settings.apiKey))\n );\n}\n\nfunction assignedName(line: string): string | undefined {\n return /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=/.exec(line)?.[1];\n}\n\n/**\n * dotenv continues a quoted value onto later lines until its closing quote.\n * Replacing such a line would orphan the continuation, even when a later\n * duplicate hides the multiline value from dotenv's effective values.\n */\nfunction opensMultilineValue(line: string): boolean {\n const value = line.slice(line.indexOf('=') + 1).trim();\n const quote = value[0];\n return (\n ['\"', \"'\", '`'].includes(quote) &&\n !value.slice(1).replaceAll(`\\\\${quote}`, '').includes(quote)\n );\n}\n\nfunction upsertEnvAssignment(\n content: string,\n name: string,\n value: string\n): string {\n const assignsName = (line: string) => assignedName(line) === name;\n const lines = content.split('\\n');\n const first = lines.findIndex(assignsName);\n if (first === -1) {\n const separator = content && !content.endsWith('\\n') ? '\\n' : '';\n return `${content}${separator}${name}=${value}\\n`;\n }\n // Replace the first assignment in place and drop stale duplicates.\n return lines\n .map((line, index) => (index === first ? `${name}=${value}` : line))\n .filter((line, index) => index === first || !assignsName(line))\n .join('\\n');\n}\n\n/**\n * Where .env.local content lives and its mode. Follows an existing symlink so\n * its referent is replaced, never the link itself; anything but a regular\n * file (dangling link, directory) fails before any write.\n */\nasync function resolveEnvFile(\n envFile: string\n): Promise<{ target: string; mode: number } | undefined> {\n const entry = await fs.promises.lstat(envFile).catch((error) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (!entry) return undefined;\n // stat follows the link and fails on a dangling one.\n const stat = await fs.promises.stat(envFile).catch((error) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (!stat?.isFile()) throw new Error(unwritableEnvFileError(envFile));\n return {\n target: entry.isSymbolicLink()\n ? await fs.promises.realpath(envFile)\n : envFile,\n mode: stat.mode & 0o777,\n };\n}\n\ntype GitExposure = 'no-repository' | 'tracked' | 'ignored' | 'unignored';\n\n// Git honors these over discovering the repository from the working\n// directory, so an inherited value could select another repository, hide this\n// one, or substitute an empty index. Configuration variables stay in effect.\nconst GIT_LOCATION_OVERRIDES = [\n 'GIT_DIR',\n 'GIT_WORK_TREE',\n 'GIT_INDEX_FILE',\n 'GIT_COMMON_DIR',\n 'GIT_CEILING_DIRECTORIES',\n];\n\n/**\n * How Git in the file's own repository treats the path, using Git's real\n * index and effective ignore rules (comments, negations, nested .gitignore,\n * excludes). Only a Git-confirmed non-repository counts as no repository;\n * a missing binary, a repository override, or any other Git error fails\n * closed.\n */\nasync function inspectGitExposure(file: string): Promise<GitExposure> {\n const overrides = GIT_LOCATION_OVERRIDES.filter(\n (name) => process.env[name] !== undefined\n );\n if (overrides.length > 0) throw new Error(gitOverrideError(file, overrides));\n const cwd = path.dirname(file);\n const run = async (args: string[]) => {\n try {\n await execFileAsync('git', args, {\n cwd,\n encoding: 'utf8',\n windowsHide: true,\n // The no-repository check reads Git's untranslated message.\n env: { ...process.env, LC_ALL: 'C' },\n });\n return { code: 0, stderr: '' };\n } catch (error) {\n const { code, stderr } = error as { code?: unknown; stderr?: unknown };\n if (typeof code !== 'number')\n throw new Error(gitUnavailableError(file, error));\n return { code, stderr: typeof stderr === 'string' ? stderr : '' };\n }\n };\n\n const toplevel = await run(['rev-parse', '--show-toplevel']);\n if (toplevel.code === 128 && /not a git repository/i.test(toplevel.stderr)) {\n return 'no-repository';\n }\n if (toplevel.code !== 0) {\n throw new Error(gitCheckFailedError(file, toplevel.stderr));\n }\n // check-ignore ignores tracked files, so the index is consulted first.\n const tracked = await run(['ls-files', '--error-unmatch', '--', file]);\n if (tracked.code === 0) return 'tracked';\n if (tracked.code !== 1)\n throw new Error(gitCheckFailedError(file, tracked.stderr));\n const ignored = await run(['check-ignore', '-q', '--', file]);\n if (ignored.code === 0) return 'ignored';\n if (ignored.code === 1) return 'unignored';\n throw new Error(gitCheckFailedError(file, ignored.stderr));\n}\n\ntype CredentialsEnvFile = {\n envFile: string;\n existing: Awaited<ReturnType<typeof resolveEnvFile>>;\n exposure: GitExposure;\n};\n\n/**\n * Everything that must hold before credentials may be saved to .env.local,\n * so callers can fail before minting a key: the path is a regular file (or a\n * link to one) or absent, and neither it nor a link's referent is tracked by\n * Git. A referent inside any worktree must already be ignored there; only\n * .env.local itself gets an ignore rule added, by setCredentials.\n */\nexport async function inspectCredentialsEnvFile(\n cwd: string = process.cwd(),\n /** Also checks that the framework's credentials can be saved safely. */\n contentCheck?: { framework?: SupportedFrameworks }\n): Promise<CredentialsEnvFile> {\n const envFile = path.resolve(cwd, '.env.local');\n const existing = await resolveEnvFile(envFile);\n if (existing && contentCheck) {\n updateCredentialsEnvContent(\n await fs.promises.readFile(existing.target, 'utf8'),\n { projectId: 'gt-preflight', apiKey: 'gt-preflight' },\n contentCheck.framework\n );\n }\n const exposure = await inspectGitExposure(envFile);\n if (exposure === 'tracked') throw new Error(trackedEnvFileError(envFile));\n if (existing && existing.target !== envFile) {\n const referentExposure = await inspectGitExposure(existing.target);\n if (referentExposure === 'tracked') {\n throw new Error(trackedEnvFileError(existing.target));\n }\n if (referentExposure === 'unignored') {\n throw new Error(unignoredEnvFileReferentError(envFile, existing.target));\n }\n }\n return { envFile, existing, exposure };\n}\n\nasync function appendGitignoreRule(cwd: string): Promise<void> {\n const gitignoreFile = path.join(cwd, '.gitignore');\n const content = await fs.promises\n .readFile(gitignoreFile, 'utf8')\n .catch((error) => {\n if (error.code === 'ENOENT') return '';\n throw error;\n });\n const separator = content && !content.endsWith('\\n') ? '\\n' : '';\n await fs.promises.appendFile(\n gitignoreFile,\n `${separator}.env.local\\n`,\n 'utf8'\n );\n}\n\n// Same-directory temporary file and rename, as in auth/credentialStore.ts:\n// a failed write never truncates the existing file.\nasync function writeEnvFileAtomically(\n target: string,\n content: string,\n mode: number\n): Promise<void> {\n const temporaryPath = path.join(\n path.dirname(target),\n `.env.local.${randomUUID()}.tmp`\n );\n try {\n await fs.promises.writeFile(temporaryPath, content, {\n encoding: 'utf8',\n flag: 'wx',\n mode,\n });\n await fs.promises.chmod(temporaryPath, mode);\n await fs.promises.rename(temporaryPath, target);\n } catch (error) {\n await fs.promises.rm(temporaryPath, { force: true });\n throw error;\n }\n}\n\n/**\n * .env.local content with the runtime credentials set. Only the hot-reload\n * key: the CLI itself acts as the signed-in user, and CI keys are created\n * deliberately rather than dropped into .env.local. Other lines, comments,\n * and any GT_API_KEY are left untouched. Throws when the edit could corrupt\n * a multiline value.\n */\nfunction updateCredentialsEnvContent(\n envContent: string,\n credentials: Credentials,\n framework?: SupportedFrameworks\n): string {\n const names = getDevelopmentEnvNames(framework);\n const targetNames = Object.values(names);\n const targetOpensMultiline = envContent\n .split('\\n')\n .some(\n (line) =>\n targetNames.includes(assignedName(line) ?? '') &&\n opensMultilineValue(line)\n );\n const original = dotenv.parse(envContent);\n const expected = {\n ...original,\n [names.projectId]: credentials.projectId,\n [names.devApiKey]: credentials.apiKey,\n };\n let updatedContent = upsertEnvAssignment(\n envContent,\n names.projectId,\n credentials.projectId\n );\n updatedContent = upsertEnvAssignment(\n updatedContent,\n names.devApiKey,\n credentials.apiKey\n );\n\n const updated = dotenv.parse(updatedContent);\n if (\n targetOpensMultiline ||\n targetNames.some((name) => original[name]?.includes('\\n')) ||\n Object.keys(updated).length !== Object.keys(expected).length ||\n Object.entries(expected).some(([name, value]) => updated[name] !== value)\n ) {\n throw new Error(unsafeCredentialsEnvError);\n }\n return updatedContent;\n}\n\n// Sets the credentials in .env.local file\nexport async function setCredentials(\n credentials: Credentials,\n framework?: SupportedFrameworks,\n cwd: string = process.cwd()\n) {\n const {\n envFile,\n existing: existingEnvFile,\n exposure,\n } = await inspectCredentialsEnvFile(cwd);\n // Rechecked here: the file may have changed since the setup preflight.\n const envContent = updateCredentialsEnvContent(\n existingEnvFile\n ? await fs.promises.readFile(existingEnvFile.target, 'utf8')\n : '',\n credentials,\n framework\n );\n\n if (exposure === 'unignored') {\n // A rule appended to the same-directory .gitignore is the last match at\n // the deepest level, so it wins over earlier negations; verify anyway.\n await appendGitignoreRule(cwd);\n if ((await inspectGitExposure(envFile)) !== 'ignored') {\n throw new Error(unignoredEnvFileError(envFile));\n }\n } else if (exposure === 'no-repository') {\n // Without a repository there are no effective rules to consult, so this\n // is unverified: seed a .gitignore so a later `git init` ignores the file.\n const gitignoreFile = path.join(cwd, '.gitignore');\n if (\n !fs.existsSync(gitignoreFile) ||\n (await fs.promises.readFile(gitignoreFile, 'utf8'))\n .trimEnd()\n .split(/\\r?\\n/)\n .at(-1) !== '.env.local'\n ) {\n await appendGitignoreRule(cwd);\n }\n }\n\n await writeEnvFileAtomically(\n existingEnvFile?.target ?? envFile,\n envContent,\n existingEnvFile?.mode ?? 0o600\n );\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,gBAAgB,UAAU,SAAS;AAEzC,MAAM,4BAA4B,wBAAwB;CACxD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B,aACA,WACA,MAAc,QAAQ,KAAK,EAC3B;CACA,MAAM,EACJ,SACA,UAAU,iBACV,aACE,MAAM,0BAA0B,IAAI;CAExC,MAAM,aAAa,4BACjB,kBACI,MAAM,GAAG,SAAS,SAAS,gBAAgB,QAAQ,OAAO,GAC1D,IACJ,aACA,UACD;AAED,KAAI,aAAa,aAAa;AAG5B,QAAM,oBAAoB,IAAI;AAC9B,MAAK,MAAM,mBAAmB,QAAQ,KAAM,UAC1C,OAAM,IAAI,MAAM,sBAAsB,QAAQ,CAAC;YAExC,aAAa,iBAAiB;EAGvC,MAAM,gBAAgB,KAAK,KAAK,KAAK,aAAa;AAClD,MACE,CAAC,GAAG,WAAW,cAAc,KAC5B,MAAM,GAAG,SAAS,SAAS,eAAe,OAAO,EAC/C,SAAS,CACT,MAAM,QAAQ,CACd,GAAG,GAAG,KAAK,aAEd,OAAM,oBAAoB,IAAI;;AAIlC,OAAM,uBACJ,iBAAiB,UAAU,SAC3B,YACA,iBAAiB,QAAQ,IAC1B"}
1
+ {"version":3,"file":"credentials.js","names":[],"sources":["../../src/utils/credentials.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { randomUUID } from 'node:crypto';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport { promisify } from 'node:util';\nimport dotenv from 'dotenv';\nimport { Settings, SupportedFrameworks } from '../types/index.js';\nimport {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\n\nconst execFileAsync = promisify(execFile);\n\nconst unsafeCredentialsEnvError = createDiagnosticMessage({\n whatHappened: 'Cannot safely update .env.local',\n reassurance: 'The existing .env.local file was not changed',\n fix: 'Move multiline values away from project/key assignments or set the development credentials manually, then retry',\n});\n\nfunction unwritableEnvFileError(envFile: string): string {\n return createDiagnosticMessage({\n whatHappened: `${envFile} is not a regular file`,\n reassurance: 'Nothing was changed',\n fix: 'Replace it with a regular file or a symlink to one, or set the development credentials manually, then retry',\n });\n}\n\nfunction trackedEnvFileError(file: string): string {\n return createDiagnosticMessage({\n whatHappened: `${file} is tracked by Git`,\n why: 'development credentials saved there would be committed',\n reassurance: 'Nothing was changed',\n fix: `Run \\`git rm --cached ${path.basename(file)}\\` in ${path.dirname(file)} and add the file to .gitignore, then retry`,\n });\n}\n\nfunction unignoredEnvFileError(file: string): string {\n return createDiagnosticMessage({\n whatHappened: `${file} is not ignored by Git`,\n why: 'development credentials saved there could be committed',\n reassurance: 'Nothing was changed',\n fix: `Add the file to a .gitignore that applies to ${path.dirname(file)}, then retry`,\n });\n}\n\nfunction unignoredEnvFileReferentError(envFile: string, referent: string) {\n return createDiagnosticMessage({\n whatHappened: `${envFile} links to ${referent}, which Git does not ignore`,\n why: 'development credentials saved there could be committed',\n reassurance: 'Nothing was changed',\n fix: `Add ${referent} to a .gitignore in its repository or set the development credentials manually, then retry`,\n });\n}\n\nfunction gitUnavailableError(file: string, error: unknown): string {\n return createDiagnosticMessage({\n whatHappened: `Could not run Git to verify that ${file} is untracked and ignored`,\n reassurance: 'Nothing was changed',\n fix: 'Install Git or make it available on PATH, then retry',\n details: formatDiagnosticErrorDetails(error),\n });\n}\n\nfunction gitOverrideError(file: string, names: string[]): string {\n return createDiagnosticMessage({\n whatHappened: `Git repository overrides are set in the environment: ${names.join(', ')}`,\n why: `they could point the untracked and ignore checks for ${file} at a different repository or index`,\n reassurance: 'Nothing was changed',\n fix: 'Unset them (for example, run outside a Git hook), then retry',\n });\n}\n\nfunction gitCheckFailedError(file: string, stderr: string): string {\n return createDiagnosticMessage({\n whatHappened: `Git could not check whether ${file} is untracked and ignored`,\n reassurance: 'Nothing was changed',\n fix: 'Fix the reported Git problem, then retry',\n details: stderr.trim(),\n });\n}\n\nexport type Credentials = { apiKey: string; projectId: string };\n\n// Include server-rendered frameworks with client-side development translation.\nconst FRAMEWORK_ENV_PREFIXES: Partial<\n Record<NonNullable<SupportedFrameworks>, string>\n> = {\n 'next-app': 'NEXT_PUBLIC_',\n 'next-pages': 'NEXT_PUBLIC_',\n vite: 'VITE_',\n gatsby: 'GATSBY_',\n react: 'REACT_APP_',\n redwood: 'REDWOOD_ENV_',\n 'tanstack-start': 'VITE_',\n 'react-router': 'VITE_',\n};\n\n/** Names of the runtime variables init writes for this framework. */\nexport function getDevelopmentEnvNames(framework?: SupportedFrameworks) {\n const prefix = (framework && FRAMEWORK_ENV_PREFIXES[framework]) ?? '';\n return {\n projectId: `${prefix}GT_PROJECT_ID`,\n devApiKey: `${prefix}GT_DEV_API_KEY`,\n };\n}\n\n/**\n * Whether the project has the framework's development key, or an explicit\n * API key for a server-only runtime. A tooling key cannot enable client-side\n * hot reload, including in Next.js App Router. `settings.projectId` already\n * resolves every framework prefix. Login is checked separately.\n */\nexport function areCredentialsSet(\n settings: Pick<Settings, 'projectId' | 'apiKey'>,\n framework?: SupportedFrameworks\n): boolean {\n const { devApiKey } = getDevelopmentEnvNames(framework);\n const needsPublicKey = Boolean(\n framework && FRAMEWORK_ENV_PREFIXES[framework]\n );\n return Boolean(\n settings.projectId &&\n (process.env[devApiKey] || (!needsPublicKey && settings.apiKey))\n );\n}\n\nfunction assignedName(line: string): string | undefined {\n return /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=/.exec(line)?.[1];\n}\n\n/**\n * dotenv continues a quoted value onto later lines until its closing quote.\n * Replacing such a line would orphan the continuation, even when a later\n * duplicate hides the multiline value from dotenv's effective values.\n */\nfunction opensMultilineValue(line: string): boolean {\n const value = line.slice(line.indexOf('=') + 1).trim();\n const quote = value[0];\n return (\n ['\"', \"'\", '`'].includes(quote) &&\n !value.slice(1).replaceAll(`\\\\${quote}`, '').includes(quote)\n );\n}\n\nfunction upsertEnvAssignment(\n content: string,\n name: string,\n value: string\n): string {\n const assignsName = (line: string) => assignedName(line) === name;\n const lines = content.split('\\n');\n const first = lines.findIndex(assignsName);\n if (first === -1) {\n const separator = content && !content.endsWith('\\n') ? '\\n' : '';\n return `${content}${separator}${name}=${value}\\n`;\n }\n // Replace the first assignment in place and drop stale duplicates.\n return lines\n .map((line, index) => (index === first ? `${name}=${value}` : line))\n .filter((line, index) => index === first || !assignsName(line))\n .join('\\n');\n}\n\n/**\n * Where .env.local content lives and its mode. Follows an existing symlink so\n * its referent is replaced, never the link itself; anything but a regular\n * file (dangling link, directory) fails before any write.\n */\nasync function resolveEnvFile(\n envFile: string\n): Promise<{ target: string; mode: number } | undefined> {\n const entry = await fs.promises.lstat(envFile).catch((error) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (!entry) return undefined;\n // stat follows the link and fails on a dangling one.\n const stat = await fs.promises.stat(envFile).catch((error) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (!stat?.isFile()) throw new Error(unwritableEnvFileError(envFile));\n return {\n target: entry.isSymbolicLink()\n ? await fs.promises.realpath(envFile)\n : envFile,\n mode: stat.mode & 0o777,\n };\n}\n\ntype GitExposure = 'no-repository' | 'tracked' | 'ignored' | 'unignored';\n\n// Git honors these over discovering the repository from the working\n// directory, so an inherited value could select another repository, hide this\n// one, or substitute an empty index. Configuration variables stay in effect.\nconst GIT_LOCATION_OVERRIDES = [\n 'GIT_DIR',\n 'GIT_WORK_TREE',\n 'GIT_INDEX_FILE',\n 'GIT_COMMON_DIR',\n 'GIT_CEILING_DIRECTORIES',\n];\n\n/**\n * How Git in the file's own repository treats the path, using Git's real\n * index and effective ignore rules (comments, negations, nested .gitignore,\n * excludes). Only a Git-confirmed non-repository counts as no repository;\n * a missing binary, a repository override, or any other Git error fails\n * closed.\n */\nasync function inspectGitExposure(file: string): Promise<GitExposure> {\n const overrides = GIT_LOCATION_OVERRIDES.filter(\n (name) => process.env[name] !== undefined\n );\n if (overrides.length > 0) throw new Error(gitOverrideError(file, overrides));\n const cwd = path.dirname(file);\n const run = async (args: string[]) => {\n try {\n await execFileAsync('git', args, {\n cwd,\n encoding: 'utf8',\n windowsHide: true,\n // The no-repository check reads Git's untranslated message.\n env: { ...process.env, LC_ALL: 'C' },\n });\n return { code: 0, stderr: '' };\n } catch (error) {\n const { code, stderr } = error as { code?: unknown; stderr?: unknown };\n if (typeof code !== 'number')\n throw new Error(gitUnavailableError(file, error));\n return { code, stderr: typeof stderr === 'string' ? stderr : '' };\n }\n };\n\n const toplevel = await run(['rev-parse', '--show-toplevel']);\n if (toplevel.code === 128 && /not a git repository/i.test(toplevel.stderr)) {\n return 'no-repository';\n }\n if (toplevel.code !== 0) {\n throw new Error(gitCheckFailedError(file, toplevel.stderr));\n }\n // check-ignore ignores tracked files, so the index is consulted first.\n const tracked = await run(['ls-files', '--error-unmatch', '--', file]);\n if (tracked.code === 0) return 'tracked';\n if (tracked.code !== 1)\n throw new Error(gitCheckFailedError(file, tracked.stderr));\n const ignored = await run(['check-ignore', '-q', '--', file]);\n if (ignored.code === 0) return 'ignored';\n if (ignored.code === 1) return 'unignored';\n throw new Error(gitCheckFailedError(file, ignored.stderr));\n}\n\ntype CredentialsEnvFile = {\n envFile: string;\n existing: Awaited<ReturnType<typeof resolveEnvFile>>;\n exposure: GitExposure;\n};\n\n/**\n * Everything that must hold before credentials may be saved to .env.local,\n * so callers can fail before minting a key: the path is a regular file (or a\n * link to one) or absent, and neither it nor a link's referent is tracked by\n * Git. A referent inside any worktree must already be ignored there; only\n * .env.local itself gets an ignore rule added, by setCredentials.\n */\nexport async function inspectCredentialsEnvFile(\n cwd: string = process.cwd(),\n /** Also checks that the framework's credentials can be saved safely. */\n contentCheck?: { framework?: SupportedFrameworks }\n): Promise<CredentialsEnvFile> {\n const envFile = path.resolve(cwd, '.env.local');\n const existing = await resolveEnvFile(envFile);\n if (existing && contentCheck) {\n updateCredentialsEnvContent(\n await fs.promises.readFile(existing.target, 'utf8'),\n { projectId: 'gt-preflight', apiKey: 'gt-preflight' },\n contentCheck.framework\n );\n }\n const exposure = await inspectGitExposure(envFile);\n if (exposure === 'tracked') throw new Error(trackedEnvFileError(envFile));\n if (existing && existing.target !== envFile) {\n const referentExposure = await inspectGitExposure(existing.target);\n if (referentExposure === 'tracked') {\n throw new Error(trackedEnvFileError(existing.target));\n }\n if (referentExposure === 'unignored') {\n throw new Error(unignoredEnvFileReferentError(envFile, existing.target));\n }\n }\n return { envFile, existing, exposure };\n}\n\nasync function appendGitignoreRule(cwd: string): Promise<void> {\n const gitignoreFile = path.join(cwd, '.gitignore');\n const content = await fs.promises\n .readFile(gitignoreFile, 'utf8')\n .catch((error) => {\n if (error.code === 'ENOENT') return '';\n throw error;\n });\n const separator = content && !content.endsWith('\\n') ? '\\n' : '';\n await fs.promises.appendFile(\n gitignoreFile,\n `${separator}.env.local\\n`,\n 'utf8'\n );\n}\n\n// Same-directory temporary file and rename, as in auth/credentialStore.ts:\n// a failed write never truncates the existing file.\nasync function writeEnvFileAtomically(\n target: string,\n content: string,\n mode: number\n): Promise<void> {\n const temporaryPath = path.join(\n path.dirname(target),\n `.env.local.${randomUUID()}.tmp`\n );\n try {\n await fs.promises.writeFile(temporaryPath, content, {\n encoding: 'utf8',\n flag: 'wx',\n mode,\n });\n await fs.promises.chmod(temporaryPath, mode);\n await fs.promises.rename(temporaryPath, target);\n } catch (error) {\n await fs.promises.rm(temporaryPath, { force: true });\n throw error;\n }\n}\n\n/**\n * .env.local content with the runtime credentials set. Only the hot-reload\n * key: the CLI itself acts as the signed-in user, and CI keys are created\n * deliberately rather than dropped into .env.local. Other lines, comments,\n * and any GT_API_KEY are left untouched. Throws when the edit could corrupt\n * a multiline value.\n */\nfunction updateCredentialsEnvContent(\n envContent: string,\n credentials: Credentials,\n framework?: SupportedFrameworks\n): string {\n const names = getDevelopmentEnvNames(framework);\n const targetNames = Object.values(names);\n const targetOpensMultiline = envContent\n .split('\\n')\n .some(\n (line) =>\n targetNames.includes(assignedName(line) ?? '') &&\n opensMultilineValue(line)\n );\n const original = dotenv.parse(envContent);\n const expected = {\n ...original,\n [names.projectId]: credentials.projectId,\n [names.devApiKey]: credentials.apiKey,\n };\n let updatedContent = upsertEnvAssignment(\n envContent,\n names.projectId,\n credentials.projectId\n );\n updatedContent = upsertEnvAssignment(\n updatedContent,\n names.devApiKey,\n credentials.apiKey\n );\n\n const updated = dotenv.parse(updatedContent);\n if (\n targetOpensMultiline ||\n targetNames.some((name) => original[name]?.includes('\\n')) ||\n Object.keys(updated).length !== Object.keys(expected).length ||\n Object.entries(expected).some(([name, value]) => updated[name] !== value)\n ) {\n throw new Error(unsafeCredentialsEnvError);\n }\n return updatedContent;\n}\n\n// Sets the credentials in .env.local file\nexport async function setCredentials(\n credentials: Credentials,\n framework?: SupportedFrameworks,\n cwd: string = process.cwd()\n) {\n const {\n envFile,\n existing: existingEnvFile,\n exposure,\n } = await inspectCredentialsEnvFile(cwd);\n // Rechecked here: the file may have changed since the setup preflight.\n const envContent = updateCredentialsEnvContent(\n existingEnvFile\n ? await fs.promises.readFile(existingEnvFile.target, 'utf8')\n : '',\n credentials,\n framework\n );\n\n if (exposure === 'unignored') {\n // A rule appended to the same-directory .gitignore is the last match at\n // the deepest level, so it wins over earlier negations; verify anyway.\n await appendGitignoreRule(cwd);\n if ((await inspectGitExposure(envFile)) !== 'ignored') {\n throw new Error(unignoredEnvFileError(envFile));\n }\n } else if (exposure === 'no-repository') {\n // Without a repository there are no effective rules to consult, so this\n // is unverified: seed a .gitignore so a later `git init` ignores the file.\n const gitignoreFile = path.join(cwd, '.gitignore');\n if (\n !fs.existsSync(gitignoreFile) ||\n (await fs.promises.readFile(gitignoreFile, 'utf8'))\n .trimEnd()\n .split(/\\r?\\n/)\n .at(-1) !== '.env.local'\n ) {\n await appendGitignoreRule(cwd);\n }\n }\n\n await writeEnvFileAtomically(\n existingEnvFile?.target ?? envFile,\n envContent,\n existingEnvFile?.mode ?? 0o600\n );\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,gBAAgB,UAAU,SAAS;AAEzC,MAAM,4BAA4B,wBAAwB;CACxD,cAAc;CACd,aAAa;CACb,KAAK;CACN,CAAC;AAEF,SAAS,uBAAuB,SAAyB;AACvD,QAAO,wBAAwB;EAC7B,cAAc,GAAG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IAAI;CAExC,MAAM,aAAa,4BACjB,kBACI,MAAM,GAAG,SAAS,SAAS,gBAAgB,QAAQ,OAAO,GAC1D,IACJ,aACA,UACD;AAED,KAAI,aAAa,aAAa;AAG5B,QAAM,oBAAoB,IAAI;AAC9B,MAAK,MAAM,mBAAmB,QAAQ,KAAM,UAC1C,OAAM,IAAI,MAAM,sBAAsB,QAAQ,CAAC;YAExC,aAAa,iBAAiB;EAGvC,MAAM,gBAAgB,KAAK,KAAK,KAAK,aAAa;AAClD,MACE,CAAC,GAAG,WAAW,cAAc,KAC5B,MAAM,GAAG,SAAS,SAAS,eAAe,OAAO,EAC/C,SAAS,CACT,MAAM,QAAQ,CACd,GAAG,GAAG,KAAK,aAEd,OAAM,oBAAoB,IAAI;;AAIlC,OAAM,uBACJ,iBAAiB,UAAU,SAC3B,YACA,iBAAiB,QAAQ,IAC1B"}
@@ -1,2 +1,4 @@
1
+ /** Env files read at startup, in order; each one after the first overrides the shell. */
2
+ export declare const envFiles: readonly [".env", ".env.local", ".env.production"];
1
3
  /** Load executable startup env files without contaminating command stdout. */
2
4
  export declare function loadEnv(): void;
@@ -1,24 +1,25 @@
1
1
  import dotenv from "dotenv";
2
2
  //#region src/utils/loadEnv.ts
3
+ /** Env files read at startup, in order; each one after the first overrides the shell. */
4
+ const envFiles = [
5
+ ".env",
6
+ ".env.local",
7
+ ".env.production"
8
+ ];
3
9
  /** Load executable startup env files without contaminating command stdout. */
4
10
  function loadEnv() {
5
11
  const log = console.log;
6
12
  console.log = console.error;
7
13
  try {
8
- dotenv.config({ path: ".env" });
9
- dotenv.config({
10
- path: ".env.local",
11
- override: true
12
- });
13
- dotenv.config({
14
- path: ".env.production",
15
- override: true
14
+ for (const [index, path] of envFiles.entries()) dotenv.config({
15
+ path,
16
+ override: index > 0
16
17
  });
17
18
  } finally {
18
19
  console.log = log;
19
20
  }
20
21
  }
21
22
  //#endregion
22
- export { loadEnv };
23
+ export { envFiles, loadEnv };
23
24
 
24
25
  //# sourceMappingURL=loadEnv.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadEnv.js","names":[],"sources":["../../src/utils/loadEnv.ts"],"sourcesContent":["import dotenv from 'dotenv';\n\n/** Load executable startup env files without contaminating command stdout. */\nexport function loadEnv(): void {\n /* eslint-disable no-console -- dotenv 16's vault warnings bypass quiet via console.log. */\n const log = console.log;\n // Keep this override synchronous; remove it when dotenv supports stderr diagnostics.\n console.log = console.error;\n try {\n dotenv.config({ path: '.env' });\n dotenv.config({ path: '.env.local', override: true });\n dotenv.config({ path: '.env.production', override: true });\n } finally {\n console.log = log;\n }\n /* eslint-enable no-console */\n}\n"],"mappings":";;;AAGA,SAAgB,UAAgB;CAE9B,MAAM,MAAM,QAAQ;AAEpB,SAAQ,MAAM,QAAQ;AACtB,KAAI;AACF,SAAO,OAAO,EAAE,MAAM,QAAQ,CAAC;AAC/B,SAAO,OAAO;GAAE,MAAM;GAAc,UAAU;GAAM,CAAC;AACrD,SAAO,OAAO;GAAE,MAAM;GAAmB,UAAU;GAAM,CAAC;WAClD;AACR,UAAQ,MAAM"}
1
+ {"version":3,"file":"loadEnv.js","names":[],"sources":["../../src/utils/loadEnv.ts"],"sourcesContent":["import dotenv from 'dotenv';\n\n/** Env files read at startup, in order; each one after the first overrides the shell. */\nexport const envFiles = ['.env', '.env.local', '.env.production'] as const;\n\n/** Load executable startup env files without contaminating command stdout. */\nexport function loadEnv(): void {\n /* eslint-disable no-console -- dotenv 16's vault warnings bypass quiet via console.log. */\n const log = console.log;\n // Keep this override synchronous; remove it when dotenv supports stderr diagnostics.\n console.log = console.error;\n try {\n for (const [index, path] of envFiles.entries()) {\n dotenv.config({ path, override: index > 0 });\n }\n } finally {\n console.log = log;\n }\n /* eslint-enable no-console */\n}\n"],"mappings":";;;AAGA,MAAa,WAAW;CAAC;CAAQ;CAAc;CAAkB;;AAGjE,SAAgB,UAAgB;CAE9B,MAAM,MAAM,QAAQ;AAEpB,SAAQ,MAAM,QAAQ;AACtB,KAAI;AACF,OAAK,MAAM,CAAC,OAAO,SAAS,SAAS,SAAS,CAC5C,QAAO,OAAO;GAAE;GAAM,UAAU,QAAQ;GAAG,CAAC;WAEtC;AACR,UAAQ,MAAM"}
@@ -1 +1,6 @@
1
+ /**
2
+ * Whether a dependency range permits any version below `minimum`. Invalid
3
+ * ranges (workspace:*, tags, URLs) fail open.
4
+ */
5
+ export declare function permitsVersionBelow(range: string, minimum: string): boolean;
1
6
  export declare function warnReactPackageCompatibility(suppressWarning?: boolean, cwd?: string): Promise<void>;
@@ -2,13 +2,17 @@ import { logger } from "../console/logger.js";
2
2
  import { getPackageJson, getPackageVersion } from "./packageJson.js";
3
3
  import { REACT_LIBRARIES } from "../types/libraries.js";
4
4
  import { createDiagnosticMessage } from "generaltranslation/diagnostics";
5
- import { minVersion } from "semver";
5
+ import { lt, minVersion } from "semver";
6
6
  //#region src/utils/reactPackageCompatibility.ts
7
- const MINIMUM_REACT_PACKAGE_MAJOR = 11;
8
- function permitsVersionBelowMinimum(version) {
7
+ const MINIMUM_REACT_PACKAGE_VERSION = "11.0.0";
8
+ /**
9
+ * Whether a dependency range permits any version below `minimum`. Invalid
10
+ * ranges (workspace:*, tags, URLs) fail open.
11
+ */
12
+ function permitsVersionBelow(range, minimum) {
9
13
  try {
10
- const minimumVersion = minVersion(version);
11
- return minimumVersion !== null && minimumVersion.major < MINIMUM_REACT_PACKAGE_MAJOR;
14
+ const lowest = minVersion(range);
15
+ return lowest !== null && lt(lowest, minimum);
12
16
  } catch {
13
17
  return false;
14
18
  }
@@ -21,7 +25,7 @@ async function warnReactPackageCompatibility(suppressWarning = false, cwd = proc
21
25
  const incompatiblePackages = REACT_LIBRARIES.flatMap((packageName) => {
22
26
  const version = getPackageVersion(packageName, packageJson);
23
27
  if (!version) return [];
24
- return permitsVersionBelowMinimum(version) ? [`${packageName}@${version}`] : [];
28
+ return permitsVersionBelow(version, MINIMUM_REACT_PACKAGE_VERSION) ? [`${packageName}@${version}`] : [];
25
29
  });
26
30
  if (incompatiblePackages.length === 0) return;
27
31
  logger.warn(createDiagnosticMessage({
@@ -36,6 +40,6 @@ async function warnReactPackageCompatibility(suppressWarning = false, cwd = proc
36
40
  } catch {}
37
41
  }
38
42
  //#endregion
39
- export { warnReactPackageCompatibility };
43
+ export { permitsVersionBelow, warnReactPackageCompatibility };
40
44
 
41
45
  //# sourceMappingURL=reactPackageCompatibility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reactPackageCompatibility.js","names":[],"sources":["../../src/utils/reactPackageCompatibility.ts"],"sourcesContent":["import { createDiagnosticMessage } from 'generaltranslation/diagnostics';\nimport { minVersion } from 'semver';\nimport { logger } from '../console/logger.js';\nimport { REACT_LIBRARIES } from '../types/libraries.js';\nimport { getPackageJson, getPackageVersion } from './packageJson.js';\n\nconst MINIMUM_REACT_PACKAGE_MAJOR = 11;\n\nfunction permitsVersionBelowMinimum(version: string): boolean {\n // A range is potentially incompatible if it permits any version below the\n // minimum; invalid ranges (workspace:*, tags, URLs) fail open\n try {\n const minimumVersion = minVersion(version);\n return (\n minimumVersion !== null &&\n minimumVersion.major < MINIMUM_REACT_PACKAGE_MAJOR\n );\n } catch {\n return false;\n }\n}\n\nexport async function warnReactPackageCompatibility(\n suppressWarning: boolean = false,\n cwd: string = process.cwd()\n): Promise<void> {\n if (suppressWarning) return;\n\n try {\n const packageJson = await getPackageJson(cwd);\n if (!packageJson) return;\n\n const incompatiblePackages = REACT_LIBRARIES.flatMap((packageName) => {\n const version = getPackageVersion(packageName, packageJson);\n if (!version) return [];\n\n return permitsVersionBelowMinimum(version)\n ? [`${packageName}@${version}`]\n : [];\n });\n if (incompatiblePackages.length === 0) return;\n\n logger.warn(\n createDiagnosticMessage({\n source: 'gt',\n severity: 'Warning',\n whatHappened:\n 'This GT CLI may be incompatible with the listed React packages',\n why: 'versions before 11 include the ID parameter in translation keys and may cause retranslation',\n fix: 'Upgrade the listed packages to version 11 or later or install gt@2.14.58',\n wayOut:\n 'rerun with --suppress-id-compatibility-warning to hide this warning',\n details: incompatiblePackages,\n })\n );\n } catch {\n // Compatibility detection is best-effort and must not block the CLI.\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,8BAA8B;AAEpC,SAAS,2BAA2B,SAA0B;AAG5D,KAAI;EACF,MAAM,iBAAiB,WAAW,QAAQ;AAC1C,SACE,mBAAmB,QACnB,eAAe,QAAQ;SAEnB;AACN,SAAO;;;AAIX,eAAsB,8BACpB,kBAA2B,OAC3B,MAAc,QAAQ,KAAK,EACZ;AACf,KAAI,gBAAiB;AAErB,KAAI;EACF,MAAM,cAAc,MAAM,eAAe,IAAI;AAC7C,MAAI,CAAC,YAAa;EAElB,MAAM,uBAAuB,gBAAgB,SAAS,gBAAgB;GACpE,MAAM,UAAU,kBAAkB,aAAa,YAAY;AAC3D,OAAI,CAAC,QAAS,QAAO,EAAE;AAEvB,UAAO,2BAA2B,QAAQ,GACtC,CAAC,GAAG,YAAY,GAAG,UAAU,GAC7B,EAAE;IACN;AACF,MAAI,qBAAqB,WAAW,EAAG;AAEvC,SAAO,KACL,wBAAwB;GACtB,QAAQ;GACR,UAAU;GACV,cACE;GACF,KAAK;GACL,KAAK;GACL,QACE;GACF,SAAS;GACV,CAAC,CACH;SACK"}
1
+ {"version":3,"file":"reactPackageCompatibility.js","names":[],"sources":["../../src/utils/reactPackageCompatibility.ts"],"sourcesContent":["import { createDiagnosticMessage } from 'generaltranslation/diagnostics';\nimport { lt, minVersion } from 'semver';\nimport { logger } from '../console/logger.js';\nimport { REACT_LIBRARIES } from '../types/libraries.js';\nimport { getPackageJson, getPackageVersion } from './packageJson.js';\n\nconst MINIMUM_REACT_PACKAGE_VERSION = '11.0.0';\n\n/**\n * Whether a dependency range permits any version below `minimum`. Invalid\n * ranges (workspace:*, tags, URLs) fail open.\n */\nexport function permitsVersionBelow(range: string, minimum: string): boolean {\n try {\n const lowest = minVersion(range);\n return lowest !== null && lt(lowest, minimum);\n } catch {\n return false;\n }\n}\n\nexport async function warnReactPackageCompatibility(\n suppressWarning: boolean = false,\n cwd: string = process.cwd()\n): Promise<void> {\n if (suppressWarning) return;\n\n try {\n const packageJson = await getPackageJson(cwd);\n if (!packageJson) return;\n\n const incompatiblePackages = REACT_LIBRARIES.flatMap((packageName) => {\n const version = getPackageVersion(packageName, packageJson);\n if (!version) return [];\n\n return permitsVersionBelow(version, MINIMUM_REACT_PACKAGE_VERSION)\n ? [`${packageName}@${version}`]\n : [];\n });\n if (incompatiblePackages.length === 0) return;\n\n logger.warn(\n createDiagnosticMessage({\n source: 'gt',\n severity: 'Warning',\n whatHappened:\n 'This GT CLI may be incompatible with the listed React packages',\n why: 'versions before 11 include the ID parameter in translation keys and may cause retranslation',\n fix: 'Upgrade the listed packages to version 11 or later or install gt@2.14.58',\n wayOut:\n 'rerun with --suppress-id-compatibility-warning to hide this warning',\n details: incompatiblePackages,\n })\n );\n } catch {\n // Compatibility detection is best-effort and must not block the CLI.\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,gCAAgC;;;;;AAMtC,SAAgB,oBAAoB,OAAe,SAA0B;AAC3E,KAAI;EACF,MAAM,SAAS,WAAW,MAAM;AAChC,SAAO,WAAW,QAAQ,GAAG,QAAQ,QAAQ;SACvC;AACN,SAAO;;;AAIX,eAAsB,8BACpB,kBAA2B,OAC3B,MAAc,QAAQ,KAAK,EACZ;AACf,KAAI,gBAAiB;AAErB,KAAI;EACF,MAAM,cAAc,MAAM,eAAe,IAAI;AAC7C,MAAI,CAAC,YAAa;EAElB,MAAM,uBAAuB,gBAAgB,SAAS,gBAAgB;GACpE,MAAM,UAAU,kBAAkB,aAAa,YAAY;AAC3D,OAAI,CAAC,QAAS,QAAO,EAAE;AAEvB,UAAO,oBAAoB,SAAS,8BAA8B,GAC9D,CAAC,GAAG,YAAY,GAAG,UAAU,GAC7B,EAAE;IACN;AACF,MAAI,qBAAqB,WAAW,EAAG;AAEvC,SAAO,KACL,wBAAwB;GACtB,QAAQ;GACR,UAAU;GACV,cACE;GACF,KAAK;GACL,KAAK;GACL,QACE;GACF,SAAS;GACV,CAAC,CACH;SACK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt",
3
- "version": "2.25.2",
3
+ "version": "2.26.0",
4
4
  "main": "dist/index.js",
5
5
  "bin": "bin/main.js",
6
6
  "files": [
@@ -117,10 +117,10 @@
117
117
  "yaml": "^2.8.0",
118
118
  "@generaltranslation/format": "0.1.9",
119
119
  "@generaltranslation/icu": "0.1.2",
120
- "@generaltranslation/python-extractor": "0.2.60",
121
- "@generaltranslation/supported-locales": "2.1.41",
122
- "@generaltranslation/vue-extractor": "0.1.19",
123
- "generaltranslation": "9.5.5",
120
+ "@generaltranslation/python-extractor": "0.2.61",
121
+ "@generaltranslation/supported-locales": "2.1.42",
122
+ "@generaltranslation/vue-extractor": "0.1.20",
123
+ "generaltranslation": "9.5.6",
124
124
  "gt-remark": "1.0.12"
125
125
  },
126
126
  "devDependencies": {