How to use watchpack - 7 common examples

To help you get started, we’ve selected a few watchpack 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 Yoctol / bottender / packages / bottender / src / cli / providers / sh / dev.ts View on Github external
childProcess.spawn(
      `npx bottender start ${isConsole ? '--console' : ''} --port ${port}`,
      {
        stdio: 'inherit',
      }
    );

  let cp = createProcess();

  const handleExit = (code: number | null) => {
    process.exit(code || undefined);
  };

  cp.on('exit', handleExit);

  const wp = new Watchpack({
    aggregateTimeout: 1000,
    poll: true,
    ignored: ['**/.git', '**/node_modules'],
  });

  wp.watch([], ['.']);

  wp.on('aggregated', (changes, removals) => {
    console.log('App restarted due to: ', changes, removals);
    cp.off('exit', handleExit);
    cp.kill('SIGTERM');

    cp = createProcess();
  });

  const useTypeScript = false; // FIXME
github zeit / next.js / packages / next / server / next-dev-server.ts View on Github external
return new Promise(resolve => {
      const pagesDir = this.pagesDir

      // Watchpack doesn't emit an event for an empty directory
      fs.readdir(pagesDir!, (_, files) => {
        if (files && files.length) {
          return
        }

        if (!resolved) {
          resolve()
          resolved = true
        }
      })

      let wp = (this.webpackWatcher = new Watchpack())
      wp.watch([], [pagesDir!], 0)

      wp.on('aggregated', () => {
        const dynamicRoutedPages = []
        const knownFiles = wp.getTimeInfoEntries()
        for (const [fileName, { accuracy }] of knownFiles) {
          if (accuracy === undefined) {
            continue
          }

          let pageName =
            '/' + relative(pagesDir!, fileName).replace(/\\+/g, '/')

          pageName = pageName.replace(
            new RegExp(`\\.+(?:${this.nextConfig.pageExtensions.join('|')})$`),
            ''
github mozilla / web-ext / src / watcher.js View on Github external
export default function onSourceChange(
  {sourceDir, artifactsDir, onChange, shouldWatchFile}: OnSourceChangeParams
): Watchpack {
  // TODO: For network disks, we would need to add {poll: true}.
  const watcher = new Watchpack();

  const executeImmediately = true;
  onChange = debounce(onChange, 1000, executeImmediately);

  watcher.on('change', (filePath) => {
    proxyFileChanges({artifactsDir, onChange, filePath, shouldWatchFile});
  });

  log.debug(`Watching for file changes in ${sourceDir}`);
  watcher.watch([], [sourceDir], Date.now());

  // TODO: support interrupting the watcher on Windows.
  // https://github.com/mozilla/web-ext/issues/225
  process.on('SIGINT', () => watcher.close());
  return watcher;
}
github itgalaxy / webfont-webpack-plugin / src / WebfontPlugin.js View on Github external
const doneFn = () => {
      if (this.watching && !this.watching.closed) {
        const oldWatcher = this.watcher;

        this.watcher = new Watchpack(
          this.watching.watchFileSystem
            ? this.watching.watchFileSystem.watcherOptions
            : {}
        );
        this.watcher.watch(
          this.fileDependencies,
          this.contextDependencies,
          Date.now()
        );
        this.watcher.once("change", () => {
          if (!this.needRegenerate) {
            this.needRegenerate = true;
            hookFn(() => {
              this.needRegenerate = false;
            });
          }
github ra-gg / Delir / packages / delir / src / domain / Renderer / operations.ts View on Github external
export const watchDevelopmentPlugins = keepAliveOperation(({ getStore, dispatch, executeOperation }) => {
  interface ErrorEntry {
    package: string
    reasons: string[]
  }

  const developmentPluginDirs = getDevelopPluginDirs(getStore)

  const wp = new Watchpack({
    aggregateTimeout: 1000,
  })
  wp.watch([], developmentPluginDirs, Date.now())

  wp.on('aggregated', async (changes: string[]) => {
    const updatedPackages: any[] = []
    const failedPackages: ErrorEntry[] = []

    for (const packageDir of changes) {
      try {
        const packageJsonPath = join(packageDir, 'package.json')
        if (!(await (exists as any)(packageJsonPath))) return

        const packageInfo = await FSPluginLoader.loadPackage(packageDir)

        const valid = Delir.PluginRegistry.validateEffectPluginPackageJSON(packageInfo.packageJson)
github takefumi-yoshii / vuex-guardian / src / index.ts View on Github external
}
  fs.removeSync(distDir)

  function onChange(filePath: string) {
    if (!fs.existsSync(filePath)) {
      fs.removeSync(
        `${distDir}${filePath.replace(storeDir, '')}`
      )
    }
    emitFiles(storeDir, distDir, config, constants)
  }

  if (config.build) {
    emitFiles(storeDir, distDir, config, constants)
  } else {
    const wp = new Watchpack({})
    wp.watch([], [storeDir])
    wp.on('change', onChange)
  }
}

watchpack

Wrapper library for directory and file watching.

MIT
Latest version published 4 months ago

Package Health Score

84 / 100
Full package analysis

Popular watchpack functions