{"version":3,"file":"devScript.mjs","names":[],"sources":["../../../../src/init/utils/devScript.ts"],"sourcesContent":["/**\n * Frameworks with no Intlayer bundler plugin to host the content watcher.\n *\n * Their dev server is a plain Node process, so the only way to rebuild\n * `.intlayer` on a content change is to run the watcher next to it.\n */\nexport const BACKEND_INTLAYER_PACKAGES = [\n  'express-intlayer',\n  'fastify-intlayer',\n  'adonis-intlayer',\n  'hono-intlayer',\n  'elysia-intlayer',\n  'remix-intlayer',\n];\n\nexport type ResolveDevScriptParams = {\n  /** The project's current `dev` script, if it has one. */\n  devScript?: string;\n  /** Combined prod + dev dependencies of the project. */\n  allDeps: Record<string, string>;\n  /** Whether a `next.config.*` file was found in the project. */\n  isNextJsProject: boolean;\n};\n\n/**\n * Resolves the `dev` script `intlayer init` should write, or `null` when the\n * project's script must be left alone.\n *\n * A Next.js app is always left alone: `withIntlayer` starts the content watcher\n * itself on both bundlers, so wrapping the dev server in `intlayer watch --with`\n * would only add a second watcher rebuilding the same dictionaries. This is checked on the\n * `next` dependency as well as on the config file, since `next.config.*` is\n * optional, and it takes precedence over the backend list, which a Next.js app\n * with a custom server (or a monorepo root) can match too.\n *\n * @example a backend project gets its dev server wrapped\n * ```ts\n * resolveDevScript({\n *   devScript: 'node ./src/index.ts',\n *   allDeps: { 'express-intlayer': '9.0.0' },\n *   isNextJsProject: false,\n * }); // → \"intlayer watch --with 'node ./src/index.ts'\"\n * ```\n *\n * @example a Next.js project keeps its own script\n * ```ts\n * resolveDevScript({\n *   devScript: 'next dev',\n *   allDeps: { next: '16.0.0' },\n *   isNextJsProject: true,\n * }); // → null\n * ```\n */\nexport const resolveDevScript = ({\n  devScript,\n  allDeps,\n  isNextJsProject,\n}: ResolveDevScriptParams): string | null => {\n  if (!devScript) return null;\n\n  const isNextJsApp = isNextJsProject || Boolean(allDeps.next);\n\n  if (isNextJsApp) return null;\n\n  const hasBackendIntlayerPackage = BACKEND_INTLAYER_PACKAGES.some(\n    (packageName) => allDeps[packageName]\n  );\n\n  if (!hasBackendIntlayerPackage) return null;\n\n  // Re-running init must not nest one wrapper inside another.\n  if (devScript.includes('intlayer watch')) return null;\n\n  return `intlayer watch --with '${devScript}'`;\n};\n"],"mappings":";;;;;;;AAMA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,oBAAoB,EAC/B,WACA,SACA,sBAC2C;CAC3C,IAAI,CAAC,WAAW,OAAO;CAIvB,IAFoB,mBAAmB,QAAQ,QAAQ,IAAI,GAE1C,OAAO;CAMxB,IAAI,CAJ8B,0BAA0B,MACzD,gBAAgB,QAAQ,YAGE,GAAG,OAAO;CAGvC,IAAI,UAAU,SAAS,gBAAgB,GAAG,OAAO;CAEjD,OAAO,0BAA0B,UAAU;AAC7C"}