How to use the @now/build-utils.getNodeVersion 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 thgh / now-sapper / index.js View on Github external
exports.build = async ({
  files,
  entrypoint,
  workPath,
  config: rawConfig,
  meta = {}
}) => {
  const mountpoint = getMountPoint(entrypoint)
  const entrypointDir = path.join(workPath, mountpoint)
  await download(files, workPath, meta)

  process.chdir(entrypointDir)

  const config = getConfig(rawConfig)
  const nodeVersion = await getNodeVersion(
    entrypointDir,
    null,
    config
  )
  const spawnOpts = getSpawnOptions(meta, nodeVersion)
  const prodDependencies = await npmBuild(config, entrypointDir, spawnOpts, meta)

  const launcherFiles = getLauncherFiles(mountpoint)
  const staticFiles = await globAndPrefix(entrypointDir, 'static')
  const applicationFiles = await globAndPrefix(entrypointDir, '__sapper__')

  // Use the system-installed version of `node` when running via `now dev`
  const runtime = meta.isDev ? 'nodejs' : nodeVersion.runtime

  const lambda = await createLambda({
    files: {
github nuxt / now-builder / src / build.ts View on Github external
await download(files, workPath, meta)

  // Change cwd to rootDir
  process.chdir(rootDir)
  consola.log('Working directory:', process.cwd())

  // Read package.json
  let pkg: PackageJson
  try {
    pkg = await fs.readJson('package.json')
  } catch (e) {
    throw new Error(`Can not read package.json from ${rootDir}`)
  }

  // Node version
  const nodeVersion = await getNodeVersion(rootDir)
  const spawnOpts = getSpawnOptions(meta, nodeVersion)

  // Prepare TypeScript environment if required.
  const usesTypescript = (pkg.devDependencies && Object.keys(pkg.devDependencies).includes('@nuxt/typescript-build')) || (pkg.dependencies && Object.keys(pkg.dependencies).includes('@nuxt/typescript'))
  const needsTypescriptBuild = getNuxtConfigName(rootDir) === 'nuxt.config.ts'

  if (usesTypescript) {
    await prepareTypescriptEnvironment({
      pkg, spawnOpts, rootDir
    })
  }

  // Detect npm (prefer yarn)
  const isYarn = !fs.existsSync('package-lock.json')
  consola.log('Using', isYarn ? 'yarn' : 'npm')
github zeit / now / packages / now-node / src / index.ts View on Github external
async function downloadInstallAndBundle({
  files,
  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
framework,
          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"`;