How to use the @parcel/utils/src/syncPromise function in @parcel/utils

To help you get started, we’ve selected a few @parcel/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 parcel-bundler / parcel / packages / core / register / src / hook.js View on Github external
}
  }

  let parcel = new Parcel({
    entries: [path.join(process.cwd(), 'index.js')],
    cliOpts: opts
  });

  let environment = new Environment({
    context: 'node',
    engines: {
      node: process.versions.node
    }
  });

  syncPromise(parcel.init());

  let isProcessing = false;

  // As Parcel is pretty much fully asynchronous, create an async function and wrap it in a syncPromise later...
  async function fileProcessor(code, filename) {
    if (isProcessing) {
      return code;
    }

    try {
      isProcessing = true;
      let result = await parcel.runTransform({
        filePath: filename,
        env: environment
      });
github parcel-bundler / parcel / packages / core / register / src / hook.js View on Github external
function resolveFile(currFile, targetFile) {
    try {
      isProcessing = true;
      let dep = new Dependency({
        moduleSpecifier: targetFile,
        sourcePath: currFile,
        env: environment
      });

      targetFile = syncPromise(parcel.resolverRunner.resolve(dep));

      let targetFileExtension = path.extname(targetFile);
      if (!hooks[targetFileExtension]) {
        hooks[targetFileExtension] = addHook(hookFunction, {
          exts: [targetFileExtension],
          ignoreNodeModules: false
        });
      }

      return targetFile;
    } finally {
      isProcessing = false;
    }
  }
github parcel-bundler / parcel / packages / core / register / src / hook.js View on Github external
  let hookFunction = (...args) => syncPromise(fileProcessor(...args));