How to use the @now/build-utils.getSpawnOptions function in @now/build-utils

To help you get started, we’ve selected a few @now/build-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frontity / now-builder / dist / index.js View on Github external
const pkg = JSON.parse(fs_1.readFileSync(pkgPath, "utf8"));
        const minNodeRange = undefined;
        const routes = [
            {
                src: `/static/(.*)`,
                headers: { "cache-control": "s-maxage=31536000, immutable" },
                dest: `/static/$1`
            },
            {
                src: "/(.*)",
                headers: { "cache-control": "s-maxage=1,stale-while-revalidate" },
                dest: "/main.js"
            }
        ];
        const nodeVersion = await build_utils_1.getNodeVersion(entrypointDir, minNodeRange);
        const spawnOpts = build_utils_1.getSpawnOptions(meta, nodeVersion);
        await build_utils_1.runNpmInstall(entrypointDir, ["--prefer-offline"], spawnOpts);
        const buildScript = getCommand(pkg, "build", config);
        console.log(`Running "${buildScript}" script in "${entrypoint}"`);
        const found = await build_utils_1.runPackageJsonScript(entrypointDir, buildScript, spawnOpts);
        if (!found) {
            throw new Error(`Missing required "${buildScript}" script in "${entrypoint}"`);
        }
        console.log("Mountpoint is: " + JSON.stringify(mountpoint));
        console.log("Routes are: " + JSON.stringify(routes));
        validateDistDir(distPath, meta.isDev, config);
        const statics = await build_utils_1.glob("**", distPath, mountpoint);
        console.log("Output files are: " + JSON.stringify(statics));
        console.log("Server.js is: " + JSON.stringify(statics["server.js"]));
        const launcherFiles = {
            "now__bridge.js": new build_utils_1.FileFsRef({
                fsPath: require("@now/node-bridge")
github zeit / now / packages / now-node / src / index.ts View on Github external
entrypoint,
  workPath,
  config,
  meta,
}: DownloadOptions) {
  const downloadedFiles = await download(files, workPath, meta);

  console.log('Installing dependencies...');
  const installTime = Date.now();
  const entrypointFsDirname = join(workPath, dirname(entrypoint));
  const nodeVersion = await getNodeVersion(
    entrypointFsDirname,
    undefined,
    config
  );
  const spawnOpts = getSpawnOptions(meta, nodeVersion);
  await runNpmInstall(
    entrypointFsDirname,
    ['--prefer-offline'],
    spawnOpts,
    meta
  );
  debug(`Install complete [${Date.now() - installTime}ms]`);

  const entrypointPath = downloadedFiles[entrypoint].fsPath;
  return { entrypointPath, entrypointFsDirname, nodeVersion, spawnOpts };
}
github frontity / now-builder / src / index.ts View on Github external
const routes: Route[] = [
      {
        src: `${prefix}/static/(.*)`,
        headers: { "cache-control": "public,max-age=31536000,immutable" },
        dest: `/static/$1`
      },
      { src: `${prefix}/favicon.ico`, dest: "favicon.ico" },
      {
        src: `${prefix}($|/.*)`,
        headers: { "cache-control": "s-maxage=1,stale-while-revalidate" },
        dest: `/server.js`
      }
    ];

    const nodeVersion = await getNodeVersion(entrypointDir, minNodeRange);
    const spawnOpts = getSpawnOptions(meta, nodeVersion);

    await runNpmInstall(entrypointDir, ["--prefer-offline"], spawnOpts);

    const buildScript = getCommand(pkg, "build");
    console.log(`Running "${buildScript}" script in "${entrypoint}"`);

    const found = await runPackageJsonScript(
      entrypointDir,
      buildScript,
      spawnOpts
    );

    if (!found) {
      throw new Error(
        `Missing required "${buildScript}" script in "${entrypoint}"`
      );
github zeit / now / packages / now-static-build / src / index.ts View on Github external
outputDirPrefix
        );
        routes.push(...frameworkRoutes);
      }

      output = await glob('**', distPath, mountpoint);
    }

    const watch = [path.join(mountpoint.replace(/^\.\/?/, ''), '**/*')];
    return { routes, watch, output, distPath };
  }

  if (!config.zeroConfig && entrypoint.endsWith('.sh')) {
    debug(`Running build script "${entrypoint}"`);
    const nodeVersion = await getNodeVersion(entrypointDir, undefined, config);
    const spawnOpts = getSpawnOptions(meta, nodeVersion);
    await runShellScript(path.join(workPath, entrypoint), [], spawnOpts);
    validateDistDir(distPath, meta.isDev, config);

    const output = await glob('**', distPath, mountpoint);

    return {
      output,
      routes: [],
      watch: [],
      distPath,
    };
  }

  let message = `Build "src" is "${entrypoint}" but expected "package.json"`;

  if (!config.zeroConfig) {