{"version":3,"file":"react-scripts-intlayer.cjs","names":[],"sources":["../../../src/cli/react-scripts-intlayer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * To make the setup easier, we are using craco to override the webpack configuration.\n * This script is used to run the craco scripts with the custom configuration.\n *\n * The script is based on the original craco script from create-react-app.\n */\n\nimport { spawnSync } from 'node:child_process';\nimport { logger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\n\nconst args = process.argv.slice(2);\nconst scriptIndex = args.findIndex(\n  (index) => index === 'build' || index === 'start' || index === 'test'\n);\nconst script = scriptIndex === -1 ? args[0] : args[scriptIndex];\n\n/**\n * Build the Intlayer dictionaries (i.e. populate the `.intlayer` folder that\n * backs the `@intlayer/dictionaries-entry` alias) before craco/webpack starts.\n *\n * Unlike the webpack `IntlayerPlugin` — whose `beforeCompile` hook fires only\n * after webpack has already begun resolving modules — this runs ahead of the\n * compiler so the dictionaries entry exists the moment resolution starts.\n * Mirrors the async `withIntlayer` flow used by the Next.js integration.\n */\nconst prepareDictionaries = async (\n  currentScript: string | undefined\n): Promise<void> => {\n  // `start` runs the dev server, `build` a production bundle, `test` the suite.\n  const isBuild = currentScript === 'build';\n  const isDev = currentScript === 'start';\n\n  const { prepareIntlayer } = await import('@intlayer/engine/build');\n  const intlayerConfig = getConfiguration();\n\n  // `prepareIntlayer` uses `runOnce`, so a redundant call from the webpack\n  // plugin later in the pipeline is a cheap no-op.\n  await prepareIntlayer(intlayerConfig, {\n    clean: isBuild,\n    env: isBuild ? 'prod' : 'dev',\n    cacheTimeoutMs: isDev\n      ? 1000 * 60 * 60 // 1 hour for dev (default cache timeout)\n      : 1000 * 30, // 30 seconds for build/test (ensure dictionaries are fresh)\n  });\n};\n\nconst runScript = async (): Promise<void> => {\n  if (script !== 'build' && script !== 'start' && script !== 'test') {\n    logger(`Unknown script \"${script}\".`);\n    logger('Perhaps you need to update craco?');\n    return;\n  }\n\n  await prepareDictionaries(script);\n\n  const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];\n  const scriptPath = getProjectRequire().resolve(\n    `@craco/craco/dist/scripts/${script}`\n  );\n\n  const scriptArgs = args.slice(scriptIndex + 1);\n  const processArgs = nodeArgs\n    .concat(scriptPath)\n    .concat([\n      ...scriptArgs,\n      '--config',\n      './node_modules/react-scripts-intlayer/dist/cjs/craco.config.cjs',\n    ]);\n\n  const child = spawnSync('node', processArgs, {\n    stdio: 'inherit',\n  });\n\n  if (child.signal) {\n    if (child.signal === 'SIGKILL') {\n      logger(`\n                The build failed because the process exited too early.\n                This probably means the system ran out of memory or someone called\n                \\`kill -9\\` on the process.\n            `);\n    } else if (child.signal === 'SIGTERM') {\n      logger(`\n                The build failed because the process exited too early.\n                Someone might have called  \\`kill\\` or \\`killall\\`, or the system could\n                be shutting down.\n            `);\n    }\n\n    process.exit(1);\n  }\n\n  process.exit(child.status ?? undefined);\n};\n\nrunScript();\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,MAAM,cAAc,KAAK,WACtB,UAAU,UAAU,WAAW,UAAU,WAAW,UAAU,MACjE;AACA,MAAM,SAAS,gBAAgB,KAAK,KAAK,KAAK,KAAK;;;;;;;;;;AAWnD,MAAM,sBAAsB,OAC1B,kBACkB;CAElB,MAAM,UAAU,kBAAkB;CAClC,MAAM,QAAQ,kBAAkB;CAEhC,MAAM,EAAE,oBAAoB,MAAM,OAAO;CAKzC,MAAM,4DAA6B,GAAG;EACpC,OAAO;EACP,KAAK,UAAU,SAAS;EACxB,gBAAgB,QACZ,MAAO,KAAK,KACZ,MAAO;CACb,CAAC;AACH;AAEA,MAAM,YAAY,YAA2B;CAC3C,IAAI,WAAW,WAAW,WAAW,WAAW,WAAW,QAAQ;EACjE,oCAAO,mBAAmB,OAAO,GAAG;EACpC,oCAAO,mCAAmC;EAC1C;CACF;CAEA,MAAM,oBAAoB,MAAM;CAEhC,MAAM,WAAW,cAAc,IAAI,KAAK,MAAM,GAAG,WAAW,IAAI,CAAC;CACjE,MAAM,2DAA+B,CAAC,CAAC,QACrC,6BAA6B,QAC/B;CAEA,MAAM,aAAa,KAAK,MAAM,cAAc,CAAC;CAS7C,MAAM,0CAAkB,QARJ,SACjB,OAAO,UAAU,CAAC,CAClB,OAAO;EACN,GAAG;EACH;EACA;CACF,CAEwC,GAAG,EAC3C,OAAO,UACT,CAAC;CAED,IAAI,MAAM,QAAQ;EAChB,IAAI,MAAM,WAAW,WACnB,oCAAO;;;;aAIA;OACF,IAAI,MAAM,WAAW,WAC1B,oCAAO;;;;aAIA;EAGT,QAAQ,KAAK,CAAC;CAChB;CAEA,QAAQ,KAAK,MAAM,UAAU,MAAS;AACxC;AAEA,UAAU"}