Files
vercel/build.js
Nathan Rajlich 1988f820bf [now dev] Use chokidar for file watching (#2350)
* [now dev] Use `chokidar` for file watching

`nsfw` is not suitable for very large projects because it does not
have any "ignore" functionality implemented.

For macOS, the `useFsEvents` option is _disabled_, so that the
`fsevents.node` binary file does not need to be cached onto the
filesystem, which simplifies things for use with `pkg` binaries.

* Delete the `fsevents` module during build

* Add proper `.nowignore` logic to the chokidar watcher
2019-05-20 19:15:06 +00:00

48 lines
1.9 KiB
JavaScript

const cpy = require('cpy');
const execa = require('execa');
const { join } = require('path');
const { remove } = require('fs-extra');
async function main() {
const isDev = process.argv[2] === '--dev';
// `now dev` uses chokidar to watch the filesystem, but opts-out of the
// `fsevents` feature using `useFsEvents: false`, so delete the module here so
// that it is not compiled by ncc, which makes the pkg'd binary size larger
// than necessary.
await remove(join(__dirname, 'node_modules/fsevents'));
// Do the initial `ncc` build
const src = join(__dirname, 'src');
const ncc = join(__dirname, 'node_modules/@zeit/ncc/dist/ncc/cli.js');
const args = [ ncc, 'build', '--source-map' ];
if (!isDev) {
args.push('--minify');
}
args.push(src);
await execa(process.execPath, args, { stdio: 'inherit' });
// `ncc` has some issues with `@zeit/fun`'s runtime files:
// - Executable bits on the `bootstrap` files appear to be lost:
// https://github.com/zeit/ncc/pull/182
// - The `bootstrap.js` asset does not get copied into the output dir:
// https://github.com/zeit/ncc/issues/278
//
// Aside from those issues, all the same files from the `runtimes` directory
// should be copied into the output runtimes dir, specifically the `index.js`
// files (correctly) do not get copied into the output bundle because they
// get compiled into the final ncc bundle file, however, we want them to be
// present on pkg's snapshot fs because the contents of those files are involved
// with `fun`'s cache invalidation mechanism and they need to be shasum'd.
const runtimes = join(__dirname, 'node_modules/@zeit/fun/dist/src/runtimes');
const dest = join(__dirname, 'dist/runtimes');
await cpy('**/*', dest, { parents: true, cwd: runtimes });
console.log('Finished building `now-cli`');
}
main().catch(err => {
console.error(err);
process.exit(1);
});