Sfoglia il codice sorgente

feat: add experimental dev build

paoloanzn 2 mesi fa
parent
commit
a8b18d910c
4 ha cambiato i file con 65 aggiunte e 6 eliminazioni
  1. 1 0
      .gitignore
  2. 1 0
      package.json
  3. 53 3
      scripts/build.ts
  4. 10 3
      src/constants/keys.ts

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 node_modules/
 dist/
 cli
+cli-dev

+ 1 - 0
package.json

@@ -14,6 +14,7 @@
   },
   "scripts": {
     "build": "bun run ./scripts/build.ts",
+    "build:dev": "bun run ./scripts/build.ts --dev",
     "compile": "bun run ./scripts/build.ts --compile",
     "dev": "bun run ./src/entrypoints/cli.tsx"
   },

+ 53 - 3
scripts/build.ts

@@ -8,6 +8,37 @@ const pkg = await Bun.file(new URL('../package.json', import.meta.url)).json() a
 
 const args = process.argv.slice(2)
 const compile = args.includes('--compile')
+const dev = args.includes('--dev')
+
+function runCommand(cmd: string[]): string | null {
+  const proc = Bun.spawnSync({
+    cmd,
+    cwd: process.cwd(),
+    stdout: 'pipe',
+    stderr: 'pipe',
+  })
+
+  if (proc.exitCode !== 0) {
+    return null
+  }
+
+  return new TextDecoder().decode(proc.stdout).trim() || null
+}
+
+function getDevVersion(baseVersion: string): string {
+  const timestamp = new Date().toISOString()
+  const date = timestamp.slice(0, 10).replaceAll('-', '')
+  const time = timestamp.slice(11, 19).replaceAll(':', '')
+  const sha = runCommand(['git', 'rev-parse', '--short=8', 'HEAD']) ?? 'unknown'
+  return `${baseVersion}-dev.${date}.t${time}.sha${sha}`
+}
+
+function getVersionChangelog(): string {
+  return (
+    runCommand(['git', 'log', '--format=%h %s', '-20']) ??
+    'Local development build'
+  )
+}
 
 const features: string[] = []
 for (let i = 0; i < args.length; i += 1) {
@@ -22,8 +53,15 @@ for (let i = 0; i < args.length; i += 1) {
   }
 }
 
-const outfile = compile ? './dist/cli' : './cli'
+const outfile = compile
+  ? dev
+    ? './dist/cli-dev'
+    : './dist/cli'
+  : dev
+    ? './cli-dev'
+    : './cli'
 const buildTime = new Date().toISOString()
+const version = dev ? getDevVersion(pkg.version) : pkg.version
 
 mkdirSync(dirname(outfile), { recursive: true })
 
@@ -37,8 +75,16 @@ const externals = [
 
 const defines = {
   'process.env.USER_TYPE': JSON.stringify('external'),
+  ...(dev
+    ? { 'process.env.NODE_ENV': JSON.stringify('development') }
+    : {}),
+  ...(dev
+    ? {
+        'process.env.CLAUDE_CODE_EXPERIMENTAL_BUILD': JSON.stringify('true'),
+      }
+    : {}),
   'process.env.CLAUDE_CODE_VERIFY_PLAN': JSON.stringify('false'),
-  'MACRO.VERSION': JSON.stringify(pkg.version),
+  'MACRO.VERSION': JSON.stringify(version),
   'MACRO.BUILD_TIME': JSON.stringify(buildTime),
   'MACRO.PACKAGE_URL': JSON.stringify(pkg.name),
   'MACRO.NATIVE_PACKAGE_URL': 'undefined',
@@ -47,7 +93,7 @@ const defines = {
     'This reconstructed source snapshot does not include Anthropic internal issue routing.',
   ),
   'MACRO.VERSION_CHANGELOG': JSON.stringify(
-    'https://github.com/paoloanzn/claude-code',
+    dev ? getVersionChangelog() : 'https://github.com/paoloanzn/claude-code',
   ),
 } as const
 
@@ -74,6 +120,10 @@ for (const external of externals) {
   cmd.push('--external', external)
 }
 
+for (const feature of features) {
+  cmd.push(`--feature=${feature}`)
+}
+
 for (const [key, value] of Object.entries(defines)) {
   cmd.push('--define', `${key}=${value}`)
 }

+ 10 - 3
src/constants/keys.ts

@@ -3,9 +3,16 @@ import { isEnvTruthy } from '../utils/envUtils.js'
 // Lazy read so ENABLE_GROWTHBOOK_DEV from globalSettings.env (applied after
 // module load) is picked up. USER_TYPE is a build-time define so it's safe.
 export function getGrowthBookClientKey(): string {
+  const useExperimentalClientKey =
+    isEnvTruthy(process.env.CLAUDE_CODE_EXPERIMENTAL_BUILD) ||
+    (process.env.USER_TYPE === 'ant' &&
+      isEnvTruthy(process.env.ENABLE_GROWTHBOOK_DEV))
+
+  if (useExperimentalClientKey) {
+    return 'sdk-yZQvlplybuXjYh6L'
+  }
+
   return process.env.USER_TYPE === 'ant'
-    ? isEnvTruthy(process.env.ENABLE_GROWTHBOOK_DEV)
-      ? 'sdk-yZQvlplybuXjYh6L'
-      : 'sdk-xRVcrliHIlrg4og4'
+    ? 'sdk-xRVcrliHIlrg4og4'
     : 'sdk-zAZezfDKGoZuXXKe'
 }