{"version":3,"sources":["../../cli/next-dev.ts"],"names":["nextDev","argv","validArgs","Boolean","Number","String","args","error","code","message","console","log","process","exit","dir","_","preflight","getPackageVersion","sassVersion","nodeSassVersion","Promise","all","cwd","name","Log","warn","port","env","PORT","parseInt","host","appUrl","dev","isNextDevCommand","then","app","catch","prepare","err","errorMessage","pkgAppPath","require","sync","appPackage","scripts","nextScript","Object","entries","find","scriptLine","nextTick"],"mappings":"AAAA;4DACA,0BACA,8EACA,sBACA,+EACA,0CACA,gEACA,uC,w4BAGA,KAAMA,CAAAA,OAAmB,CAAIC,IAAD,EAAU,CACpC,KAAMC,CAAAA,SAAmB,CAAG,CAC1B;AACA,SAAUC,OAFgB,CAG1B,SAAUC,MAHgB,CAI1B,aAAcC,MAJY,CAM1B;AACA,KAAM,QAPoB,CAQ1B,KAAM,QARoB,CAS1B,KAAM,YAToB,CAA5B,CAWA,GAAIC,CAAAA,IAAJ,CACA,GAAI,CACFA,IAAI,CAAG,mBAAIJ,SAAJ,CAAe,CAAED,IAAF,CAAf,CAAP,CACD,CAAC,MAAOM,KAAP,CAAc,CACd,GAAIA,KAAK,CAACC,IAAN,GAAe,oBAAnB,CAAyC,CACvC,MAAO,wBAAaD,KAAK,CAACE,OAAnB,CAA4B,CAA5B,CAAP,CACD,CACD,KAAMF,CAAAA,KAAN,CACD,CACD,GAAID,IAAI,CAAC,QAAD,CAAR,CAAoB,CAClBI,OAAO,CAACC,GAAR,CAAa;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAfI,EAgBAC,OAAO,CAACC,IAAR,CAAa,CAAb,EACD,CAED,KAAMC,CAAAA,GAAG,CAAG,kBAAQR,IAAI,CAACS,CAAL,CAAO,CAAP,GAAa,GAArB,CAAZ,CAEA;AACA,GAAI,CAAC,mBAAWD,GAAX,CAAL,CAAsB,CACpB,wBAAc,mDAAkDA,GAAI,EAApE,EACD,CAED,cAAeE,CAAAA,SAAf,EAA2B,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AAI+B,CAAAA,YAAY,CAAI,QAAOb,IAAK,qBAAhC,CACA,KAAMc,CAAAA,UAAU,CAAGC,OAAO,CAAC,4BAAD,CAAP,CAAsCC,IAAtC,CACjB,cADiB,CAEjB,CACEpB,GAAG,CAAER,GADP,CAFiB,CAAnB,CAMA,KAAM6B,CAAAA,UAAU,CAAGF,OAAO,CAACD,UAAD,CAA1B,CACA,GAAIG,UAAU,CAACC,OAAf,CAAwB,CACtB,KAAMC,CAAAA,UAAU,CAAGC,MAAM,CAACC,OAAP,CAAeJ,UAAU,CAACC,OAA1B,EAAmCI,IAAnC,CAChBC,UAAD,EAAgBA,UAAU,CAAC,CAAD,CAAV,GAAkB,MADjB,CAAnB,CAGA,GAAIJ,UAAJ,CAAgB,CACdN,YAAY,EAAK,mBAAkBM,UAAU,CAAC,CAAD,CAAI,6BAAjD,CACD,CACF,CACDnC,OAAO,CAACH,KAAR,CAAcgC,YAAd,EACD,CAlBD,IAkBO,CACL7B,OAAO,CAACH,KAAR,CAAc+B,GAAd,EACD,CACD1B,OAAO,CAACsC,QAAR,CAAiB,IAAMtC,OAAO,CAACC,IAAR,CAAa,CAAb,CAAvB,EACD,CA/BH,EAgCD,CApGD,C","sourcesContent":["#!/usr/bin/env node\nimport { resolve } from 'path'\nimport arg from 'next/dist/compiled/arg/index.js'\nimport { existsSync } from 'fs'\nimport startServer from '../server/lib/start-server'\nimport { printAndExit } from '../server/lib/utils'\nimport * as Log from '../build/output/log'\nimport { startedDevelopmentServer } from '../build/output'\nimport { cliCommand } from '../bin/next'\n\nconst nextDev: cliCommand = (argv) => {\n  const validArgs: arg.Spec = {\n    // Types\n    '--help': Boolean,\n    '--port': Number,\n    '--hostname': String,\n\n    // Aliases\n    '-h': '--help',\n    '-p': '--port',\n    '-H': '--hostname',\n  }\n  let args: arg.Result<arg.Spec>\n  try {\n    args = arg(validArgs, { argv })\n  } catch (error) {\n    if (error.code === 'ARG_UNKNOWN_OPTION') {\n      return printAndExit(error.message, 1)\n    }\n    throw error\n  }\n  if (args['--help']) {\n    console.log(`\n      Description\n        Starts the application in development mode (hot-code reloading, error\n        reporting, etc)\n\n      Usage\n        $ next dev <dir> -p <port number>\n\n      <dir> represents the directory of the Next.js application.\n      If no directory is provided, the current directory will be used.\n\n      Options\n        --port, -p      A port number on which to start the application\n        --hostname, -H  Hostname on which to start the application (default: 0.0.0.0)\n        --help, -h      Displays this message\n    `)\n    process.exit(0)\n  }\n\n  const dir = resolve(args._[0] || '.')\n\n  // Check if pages dir exists and warn if not\n  if (!existsSync(dir)) {\n    printAndExit(`> No such directory exists as the project root: ${dir}`)\n  }\n\n  async function preflight() {\n    const { getPackageVersion } = await import('../lib/get-package-version')\n    const [sassVersion, nodeSassVersion] = await Promise.all([\n      getPackageVersion({ cwd: dir, name: 'sass' }),\n      getPackageVersion({ cwd: dir, name: 'node-sass' }),\n    ])\n    if (sassVersion && nodeSassVersion) {\n      Log.warn(\n        'Your project has both `sass` and `node-sass` installed as dependencies, but should only use one or the other. ' +\n          'Please remove the `node-sass` dependency from your project. ' +\n          ' Read more: https://nextjs.org/docs/messages/duplicate-sass'\n      )\n    }\n  }\n\n  const port =\n    args['--port'] || (process.env.PORT && parseInt(process.env.PORT)) || 3000\n  const host = args['--hostname'] || '0.0.0.0'\n  const appUrl = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`\n\n  startServer({ dir, dev: true, isNextDevCommand: true }, port, host)\n    .then(async (app) => {\n      startedDevelopmentServer(appUrl, `${host}:${port}`)\n      // Start preflight after server is listening and ignore errors:\n      preflight().catch(() => {})\n      // Finalize server bootup:\n      await app.prepare()\n    })\n    .catch((err) => {\n      if (err.code === 'EADDRINUSE') {\n        let errorMessage = `Port ${port} is already in use.`\n        const pkgAppPath = require('next/dist/compiled/find-up').sync(\n          'package.json',\n          {\n            cwd: dir,\n          }\n        )\n        const appPackage = require(pkgAppPath)\n        if (appPackage.scripts) {\n          const nextScript = Object.entries(appPackage.scripts).find(\n            (scriptLine) => scriptLine[1] === 'next'\n          )\n          if (nextScript) {\n            errorMessage += `\\nUse \\`npm run ${nextScript[0]} -- -p <some other port>\\`.`\n          }\n        }\n        console.error(errorMessage)\n      } else {\n        console.error(err)\n      }\n      process.nextTick(() => process.exit(1))\n    })\n}\n\nexport { nextDev }\n"]}