How to use the @now/build-utils.FileFsRef 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-cli / src / util / dev / server.ts View on Github external
const nowConfigBuild = nowConfig.build || {};
    const [env, buildEnv] = await Promise.all([
      this.getLocalEnv('.env', nowConfig.env),
      this.getLocalEnv('.env.build', nowConfigBuild.env),
    ]);
    Object.assign(process.env, buildEnv);
    this.env = env;
    this.buildEnv = buildEnv;

    const opts = { output: this.output, isBuilds: true };
    const files = await getFiles(this.cwd, nowConfig, opts);
    const results: { [filePath: string]: FileFsRef } = {};
    for (const fsPath of files) {
      const path = relative(this.cwd, fsPath);
      const { mode } = await fs.stat(fsPath);
      results[path] = new FileFsRef({ mode, fsPath });
    }
    this.files = results;

    const builders: Set = new Set(
      (nowConfig.builds || [])
        .filter((b: Builder) => b.use)
        .map((b: Builder) => b.use as string)
    );

    await installBuilders(builders, this.yarnPath, this.output);
    await this.updateBuildMatches(nowConfig, true);

    // Updating builders happens lazily, and any builders that were updated
    // get their "build matches" invalidated so that the new version is used.
    this.updateBuildersPromise = updateBuilders(
      builders,
github nuxt / now-builder / src / build.ts View on Github external
// node_modules_prod
  const nodeModulesDir = path.join(rootDir, 'node_modules_prod')
  const nodeModules = await globAndPrefix('**', nodeModulesDir, 'node_modules')

  // Lambdas
  const lambdas: Record = {}

  const launcherPath = path.join(__dirname, 'launcher.js')
  const launcherSrc = (await fs.readFile(launcherPath, 'utf8'))
    .replace(/__NUXT_SUFFIX__/g, nuxtDep.suffix)
    .replace(/__NUXT_CONFIG__/g, './' + nuxtConfigName)

  const launcherFiles = {
    'now__launcher.js': new FileBlob({ data: launcherSrc }),
    'now__bridge.js': new FileFsRef({ fsPath: require('@now/node-bridge') }),
    [nuxtConfigName]: new FileFsRef({ fsPath: path.resolve(rootDir, nuxtConfigName) }),
    ...serverDistFiles,
    ...compiledTypescriptFiles,
    ...nodeModules
  }

  // Extra files to be included in lambda
  const serverFiles = [
    ...(Array.isArray(config.serverFiles) ? config.serverFiles : []),
    'package.json'
  ]

  for (const pattern of serverFiles) {
    const files = await glob(pattern, rootDir)
    Object.assign(launcherFiles, files)
  }
github frontity / now-builder / dist / index.js View on Github external
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")
            })
        };
        const lambda = await build_utils_1.createLambda({
            runtime: "nodejs8.10",
            handler: "now__launcher.launcher",
            files: {
                ...launcherFiles,
                "index.js": new build_utils_1.FileFsRef({
                    fsPath: statics["server.js"].fsPath
                })
            }
        });
        const output = {
            ...statics,
            "main.js": lambda
        };
        console.log("Finished!");
        return { routes, output };
    }
    throw new Error(`Build "src" is "${entrypoint}" but expected "package.json"`);
}
exports.build = build;
github frontity / now-builder / dist / index.js View on Github external
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")
            })
        };
        const lambda = await build_utils_1.createLambda({
            runtime: "nodejs8.10",
            handler: "now__launcher.launcher",
            files: {
                ...launcherFiles,
                "index.js": new build_utils_1.FileFsRef({
                    fsPath: statics["server.js"].fsPath
                })
            }
        });
github frontity / now-builder / dist / index.js View on Github external
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")
            })
        };
        const lambda = await build_utils_1.createLambda({
            runtime: "nodejs8.10",
            handler: "now__launcher.launcher",
            files: {
                ...launcherFiles,
                "index.js": new build_utils_1.FileFsRef({
                    fsPath: statics["server.js"].fsPath
                })
            }
        });
        const output = {
            ...statics,
            "main.js": lambda
github zeit / now / src / commands / dev / lib / glob.ts View on Github external
throw new Error(
        `statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
      );
    }
    if (stat.isFile()) {
      const isSymlink = options.symlinks[fsPath];
      if (isSymlink) {
        stat = await lstat(fsPath);
      }

      let finalPath = relativePath;
      if (mountpoint) {
        finalPath = join(mountpoint, finalPath);
      }

      results[finalPath] = new FileFsRef({ mode: stat.mode, fsPath });
    }
  }

  return results;
}