import { c as consola } from '../shared/cli.61828232.mjs';
import { d as defineRemixCommand } from '../shared/cli.d1d97f34.mjs';
import { r as resolve, a as loadRemix, d as relative, k as getBuilder } from '../shared/cli.bf96fb69.mjs';
import 'events';
import 'fs';
import 'path';
import 'util';
import 'stream';
import 'os';
import 'node:fs';
import 'node:module';
import 'node:url';
import 'node:fs/promises';
import 'node:os';
import 'crypto';
import 'module';
import 'perf_hooks';
import 'vm';
import 'url';
import 'assert';
import 'buffer';
import 'tty';
import 'node:path';
import 'constants';
import 'net';
import 'child_process';

const preview = defineRemixCommand({
  meta: {
    name: "preview",
    usage: "npx remix preview|start [--dotenv] [rootDir]",
    description: "Launches a server for local testing after `remix build`."
  },
  async invoke(args) {
    process.env.NODE_ENV = process.env.NODE_ENV || "production";
    const cwd = resolve(args._[0] || ".");
    const remix = await loadRemix({
      cwd,
      dotenv: {
        cwd,
        fileName: args.dotenv
      }
    });
    remix.hook("build:error", (err) => {
      consola.error("Remix Preview Error:", err);
      process.exit(1);
    });
    consola.info("Node.js version:", process.versions.node);
    consola.info("Working dir:", relative(cwd, remix.options.buildDir));
    consola.log("");
    consola.info("Starting preview.");
    consola.log("");
    const builder = await getBuilder(remix);
    await builder.preview(remix);
    return "wait";
  }
});

export { preview as default };
