How to use the @now/build-utils.runPackageJsonScript 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 zeit / now / packages / now-static-build / src / index.ts View on Github external
'See the local development docs: https://zeit.co/docs/v2/deployments/official-builders/static-build-now-static-build/#local-development'
        );
      }

      const buildScript = pkg ? getCommand(pkg, 'build', config) : null;
      debug(
        `Running "${buildCommand || buildScript}" script in "${entrypoint}"`
      );

      const found =
        typeof buildCommand === 'string'
          ? await execCommand(buildCommand, {
              ...spawnOpts,
              cwd: entrypointDir,
            })
          : await runPackageJsonScript(entrypointDir, buildScript!, spawnOpts);

      if (!found) {
        throw new Error(
          `Missing required "${buildCommand ||
            buildScript}" script in "${entrypoint}"`
        );
      }

      const outputDirPrefix = path.join(workPath, path.dirname(entrypoint));

      if (framework) {
        const outputDirName = await framework.getOutputDirName(outputDirPrefix);

        distPath = path.join(outputDirPrefix, outputDirName);
      } else if (!config || !config.distDir) {
        // Select either `dist` or `public` as directory
github zeit / now / packages / now-next / src / index.ts View on Github external
.version;

    debug(`Detected Next.js version: ${realNextVersion}`);
  } catch (_ignored) {
    debug(`Could not identify real Next.js version, that's OK!`);
  }

  if (!isLegacy) {
    await createServerlessConfig(workPath, entryPath, realNextVersion);
  }

  debug('Running user script...');
  const memoryToConsume = Math.floor(os.totalmem() / 1024 ** 2) - 128;
  const env: { [key: string]: string | undefined } = { ...spawnOpts.env };
  env.NODE_OPTIONS = `--max_old_space_size=${memoryToConsume}`;
  await runPackageJsonScript(entryPath, shouldRunScript, { ...spawnOpts, env });

  const routesManifest = await getRoutesManifest(entryPath, realNextVersion);
  const rewrites: Route[] = [];
  const redirects: Route[] = [];

  if (routesManifest) {
    switch (routesManifest.version) {
      case 1:
      case 2: {
        redirects.push(...convertRedirects(routesManifest.redirects));
        rewrites.push(...convertRewrites(routesManifest.rewrites));
        break;
      }
      default: {
        // update MIN_ROUTES_MANIFEST_VERSION in ./utils.ts
        throw new Error(
github frontity / now-builder / dist / index.js View on Github external
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")
            }),
            "now__launcher.js": new build_utils_1.FileFsRef({
                fsPath: path_1.default.join(__dirname, "launcher.js")
            })
github zeit / now / packages / now-node / src / index.ts View on Github external
const {
    entrypointPath,
    entrypointFsDirname,
    nodeVersion,
    spawnOpts,
  } = await downloadInstallAndBundle({
    files,
    entrypoint,
    workPath,
    config,
    meta,
  });

  debug('Running user script...');
  const runScriptTime = Date.now();
  await runPackageJsonScript(entrypointFsDirname, 'now-build', spawnOpts);
  debug(`Script complete [${Date.now() - runScriptTime}ms]`);

  debug('Tracing input files...');
  const traceTime = Date.now();
  const { preparedFiles, shouldAddSourcemapSupport, watch } = await compile(
    workPath,
    entrypointPath,
    entrypoint,
    config
  );
  debug(`Trace complete [${Date.now() - traceTime}ms]`);

  const makeLauncher = awsLambdaHandler ? makeAwsLauncher : makeNowLauncher;

  const launcherFiles: Files = {
    [`${LAUNCHER_FILENAME}.js`]: new FileBlob({
github thgh / now-sapper / lib / npm.js View on Github external
exports.npmBuild = async function npmBuild (config, entrypointDir, meta) {
  if (config.build) {
    await runNpmInstall(entrypointDir, ['--prefer-offline'], {}, meta)
    await runPackageJsonScript(
      entrypointDir,
      'build',
      {}
    )

    const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'now-'))

    await fs.copy(
      path.join(entrypointDir, 'package.json'),
      path.join(tempDir, 'package.json')
    )
    
    const originalDir = process.cwd()
    process.chdir(tempDir)
    await runNpmInstall(tempDir, ['--prefer-offline', '--production'], {}, meta)
    process.chdir(originalDir)