How to use @parcel/watcher - 5 common examples

To help you get started, we’ve selected a few @parcel/watcher 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 parcel-bundler / parcel / packages / core / parcel-bundler / src / Bundler.js View on Github external
if (this.farm) {
      return;
    }

    await this.loadPlugins();

    if (!this.options.env) {
      await loadEnv(Path.join(this.options.rootDir, 'index'));
      this.options.env = process.env;
    }

    this.options.extensions = Object.assign({}, this.parser.extensions);
    this.options.bundleLoaders = this.bundleLoaders;

    if (this.options.watch) {
      this.watcher = new Watcher();
      // Wait for ready event for reliable testing on watcher
      if (process.env.NODE_ENV === 'test' && !this.watcher.ready) {
        await new Promise(resolve => this.watcher.once('ready', resolve));
      }
      this.watchedGlobs.forEach(glob => {
        this.watcher.add(glob);
      });
      this.watcher.on('add', this.onAdd.bind(this));
      this.watcher.on('change', this.onChange.bind(this));
      this.watcher.on('unlink', this.onUnlink.bind(this));
    }

    if (this.options.hmr) {
      this.hmr = new HMRServer();
      this.options.hmrPort = await this.hmr.start(this.options);
    }
github astronomersiva / lego / lib / tasks / copyMinorStaticAssets.js View on Github external
// This watcher needs a newer version of libc6

        parcelWatcher = require('@parcel/watcher');
        await parcelWatcher.writeSnapshot(STATIC, snapshotPath);
      }

      minorStaticFiles = staticFiles.filter((path) => !['css', 'js'].includes(path));
    } else {
      if (['add', 'change'].includes(event)) {
        minorStaticFiles = [path.replace(`${STATIC}/`, '')];
      } else if (event === 'unlink') {
        fs.remove(`${BUILD}/${path}`);
      }

      let parcelWatcher = require('@parcel/watcher');
      await parcelWatcher.writeSnapshot(STATIC, snapshotPath);
    }

    let copyPromises = [];
    for (const asset of minorStaticFiles) {
      copyPromises.push(
        fs.copy(
          `${STATIC}/${asset}`,
          `${BUILD}/${STATIC}/${asset}`
        )
      );
    }

    await Promise.all(copyPromises);
    logger.timeEnd(message);
  } catch (error) {
    throw error;
github parcel-bundler / parcel / packages / core / fs / src / NodeFS.js View on Github external
async writeSnapshot(
    dir: FilePath,
    snapshot: FilePath,
    opts: WatcherOptions,
  ): Promise {
    await watcher.writeSnapshot(dir, snapshot, opts);
  }
github parcel-bundler / parcel / packages / core / fs / src / NodeFS.js View on Github external
getEventsSince(
    dir: FilePath,
    snapshot: FilePath,
    opts: WatcherOptions,
  ): Promise> {
    return watcher.getEventsSince(dir, snapshot, opts);
  }
github parcel-bundler / parcel / packages / core / fs / src / NodeFS.js View on Github external
watch(
    dir: FilePath,
    fn: (err: ?Error, events: Array) => mixed,
    opts: WatcherOptions,
  ): Promise {
    return watcher.subscribe(dir, fn, opts);
  }

@parcel/watcher

A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.

MIT
Latest version published 3 months ago

Package Health Score

82 / 100
Full package analysis

Similar packages