How to use @now/build-utils - 10 common examples

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 juicyfx / now-builders / src / php-bridge / index.js View on Github external
return [];
  }

  if (configuration.getVersion(config) === '7.4') {
    console.log('🐘 Skip Composer (calling PHP 7.4 is not supported at this moment)');
    return [];
  }

  console.log('🐘 Installing Composer deps.');

  // Install composer dependencies
  await runComposerInstall({ workPath, config });

  console.log('🐘 Installing Composer deps OK.');

  return await glob('vendor/**', workPath);
}
github juicyfx / now-builders / src / php-next / index.js View on Github external
exports.build = async ({
  files, entrypoint, workPath, config, meta,
}) => {
  // Download all files to workPath
  const downloadedFiles = await download(files, workPath, meta);

  console.log('Config:', config);

  let includedFiles = {};
  if (config && config.includeFiles) {
    // Find files for each glob
    // eslint-disable-next-line no-restricted-syntax
    for (const pattern of config.includeFiles) {
      // eslint-disable-next-line no-await-in-loop
      const matchedFiles = await glob(pattern, workPath);
      Object.assign(includedFiles, matchedFiles);
    }
    // explicit and always include the entrypoint
    Object.assign(includedFiles, {
      [entrypoint]: files[entrypoint],
    });
github zeit / now / packages / now-go / index.ts View on Github external
Learn more: https://github.com/golang/go/wiki/Modules
`);
  }

  const entrypointArr = entrypoint.split(sep);

  // eslint-disable-next-line prefer-const
  let [goPath, outDir] = await Promise.all([
    getWriteableDirectory(),
    getWriteableDirectory(),
  ]);

  const srcPath = join(goPath, 'src', 'lambda');
  let downloadedFiles;
  if (meta.isDev) {
    downloadedFiles = await download(files, workPath, meta);
  } else {
    downloadedFiles = await download(files, srcPath);
  }

  debug(`Parsing AST for "${entrypoint}"`);
  let analyzed: string;
  try {
    let goModAbsPathDir = '';
    for (const file of Object.keys(downloadedFiles)) {
      if (file === 'go.mod') {
        goModAbsPathDir = dirname(downloadedFiles[file].fsPath);
      }
    }
    analyzed = await getAnalyzedEntrypoint(
      downloadedFiles[entrypoint].fsPath,
      goModAbsPathDir
github juicyfx / now-builders / src / php-bridge / index.js View on Github external
async function installPhp({ workPath, config }) {
  console.log(`🐘 Installing PHP ${configuration.getVersion(config)} lib.`);

  // Install defined PHP version on the fly into the tmp folder
  const packageJson = {
    dependencies: {
      [configuration.getPhpNpm(config)]: 'canary',
    }
  };

  const packageJsonPath = path.join(workPath, 'package.json');
  await writeFile(packageJsonPath, JSON.stringify(packageJson));

  await runNpmInstall(path.dirname(packageJsonPath), [
    '--prod',
    '--prefer-offline',
  ]);

  console.log(`🐘 Installing PHP ${configuration.getVersion(config)} lib OK.`);
}
github zeit / now / src / util / dev / server.ts View on Github external
} else {
        throw err;
      }
    }

    // no builds -> zero config
    if (!config.builds || config.builds.length === 0) {
      const allFiles = await getAllProjectFiles(this.cwd, this.output);
      const files = allFiles.filter(this.filter);

      this.output.debug(
        `Found ${allFiles.length} and ` +
          `filtered out ${allFiles.length - files.length} files`
      );

      const { builders, errors } = await detectBuilders(files, pkg);

      if (errors) {
        this.output.error(errors[0].message);
        await this.exit();
      }

      if (builders) {
        const { defaultRoutes, error: routesError } = await detectRoutes(
          files,
          builders
        );

        config.builds = config.builds || [];
        config.builds.push(...builders);

        if (routesError) {
github zeit / now / packages / now-cli / src / util / dev / server.ts View on Github external
} else {
        throw err;
      }
    }

    // no builds -> zero config
    if (!config.builds || config.builds.length === 0) {
      const allFiles = await getAllProjectFiles(this.cwd, this.output);
      const files = allFiles.filter(this.filter);

      this.output.debug(
        `Found ${allFiles.length} and ` +
          `filtered out ${allFiles.length - files.length} files`
      );

      const { builders, warnings, errors } = await detectBuilders(files, pkg, {
        tag: getDistTag(cliVersion) === 'canary' ? 'canary' : 'latest',
      });

      if (errors) {
        this.output.error(errors[0].message);
        await this.exit();
      }

      if (warnings && warnings.length > 0) {
        warnings.forEach(warning => this.output.warn(warning.message));
      }

      if (builders) {
        const { defaultRoutes, error: routesError } = await detectRoutes(
          files,
          builders
github zeit / now / packages / now-cli / src / util / dev / server.ts View on Github external
await this.validateNowConfig(config);
    const { error: routeError, routes: maybeRoutes } = getTransformedRoutes({
      nowConfig: config,
    });
    if (routeError) {
      this.output.error(routeError.message);
      await this.exit();
    }
    config.routes = maybeRoutes || [];

    // no builds -> zero config
    if (!config.builds || config.builds.length === 0) {
      const { projectSettings } = config;

      const { builders, warnings, errors } = await detectBuilders(files, pkg, {
        tag: getDistTag(cliVersion) === 'canary' ? 'canary' : 'latest',
        functions: config.functions,
        ...(projectSettings ? { projectSettings } : {}),
      });

      if (errors) {
        this.output.error(errors[0].message);
        await this.exit();
      }

      if (warnings && warnings.length > 0) {
        warnings.forEach(warning => this.output.warn(warning.message));
      }

      if (builders) {
        const { defaultRoutes, error: routesError } = await detectRoutes(
github zeit / now / packages / now-go / index.ts View on Github external
debug('Running `go build`...');
    const destPath = join(outDir, 'handler');
    try {
      const src = [
        join(entrypointDirname, mainGoFileName),
        downloadedFiles[entrypoint].fsPath,
      ];
      await go.build(src, destPath);
    } catch (err) {
      console.log('failed to `go build`');
      throw err;
    }
  }

  const lambda = await createLambda({
    files: { ...(await glob('**', outDir)), ...includedFiles },
    handler: 'handler',
    runtime: 'go1.x',
    environment: {},
  });

  const watch = parsedAnalyzed.watch;
  let watchSub: string[] = [];
  // if `entrypoint` located in subdirectory
  // we will need to concat it with return watch array
  if (entrypointArr.length > 1) {
    entrypointArr.pop();
    watchSub = parsedAnalyzed.watch.map(file => join(...entrypointArr, file));
  }

  return {
github transitive-bullshit / functional-typescript / packages / now-fts / index.js View on Github external
console.log(`using default ${tsconfig}`)
    fs.outputJsonSync(ftsTsConfigPath, {
      compilerOptions: {
        target: 'es2015',
        moduleResolution: 'node'
      }
    })
  }

  // TODO: for local testing purposes
  // console.log('linking dependencies for fts...')
  // execa.shellSync('yarn link fts fts-http', { cwd: ftsPath, stdio: 'inherit' })

  console.log()
  console.log('installing dependencies for fts...')
  await runNpmInstall(ftsPath, npmArguments)

  return [downloadedFiles, nccPath, ftsPath, entrypointFsDirname]
}
github transitive-bullshit / functional-typescript / packages / now-fts / index.js View on Github external
fs.writeFileSync(handlerPath, handler, 'utf8')

  console.log()
  console.log('compiling entrypoint with ncc...')
  const ncc = require(path.join(nccPath, 'node_modules/@zeit/ncc'))
  const { code, assets } = await ncc(handlerPath)
  const outputHandlerPath = path.join('user', 'fts-handler.js')

  const blob = new FileBlob({ data: code })
  // move all user code to 'user' subdirectory
  preparedFiles[outputHandlerPath] = blob
  // eslint-disable-next-line no-restricted-syntax
  for (const assetName of Object.keys(assets)) {
    const { source: data, permissions: mode } = assets[assetName]
    const blob2 = new FileBlob({ data, mode })

    preparedFiles[
      path.join('user', path.dirname(entrypoint), assetName)
    ] = blob2
  }

  return {
    preparedFiles,
    handlerPath: outputHandlerPath
  }
}