How to use pirates - 9 common examples

To help you get started, we’ve selected a few pirates 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 datawrapper / datawrapper / test / helpers / setup-svelte-compiler.js View on Github external
// component name, useful for debugging
        name: path.basename(filename, SVELTE_EXTENSION),

        // explicitly set parser for svelte-upgrade
        // TODO: Properly upgrade to v2 (or v3?!)
        parser: 'v2'
    });

    // make the sourcemap available to be retrieved via "source-map-support"
    sourcemaps[filename] = js.map;

    return js.code;
};

addHook(compileSvelte, { exts: [SVELTE_EXTENSION], ignoreNodeModules: false });
github parcel-bundler / parcel / packages / core / register / src / register.js View on Github external
let targetFileExtension = path.extname(resolved);
      if (!hooks[targetFileExtension]) {
        hooks[targetFileExtension] = addHook(hookFunction, {
          exts: [targetFileExtension],
          ignoreNodeModules: false,
        });
      }

      return resolved;
    } finally {
      isProcessing = false;
    }
  }

  hooks.js = addHook(hookFunction, {
    exts: ['.js'],
    ignoreNodeModules: false,
  });

  let disposed;

  // Patching Module._resolveFilename takes care of patching the underlying
  // resolver in both `require` and `require.resolve`:
  // https://github.com/nodejs/node-v0.x-archive/issues/1125#issuecomment-10748203
  const originalResolveFilename = Module._resolveFilename;
  Module._resolveFilename = function parcelResolveFilename(to, from, ...rest) {
    return isProcessing || disposed
      ? originalResolveFilename(to, from, ...rest)
      : resolveFile(from?.filename, to);
  };
github parcel-bundler / parcel / packages / core / register / src / register.js View on Github external
function resolveFile(currFile, targetFile) {
    try {
      isProcessing = true;

      let resolved = syncPromise(
        // $FlowFixMe
        parcel[INTERNAL_RESOLVE]({
          moduleSpecifier: targetFile,
          sourcePath: currFile,
          env,
        }),
      );

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

      return resolved;
    } finally {
      isProcessing = false;
    }
  }
github maxrolon / store-locator / test / helpers / dependency-interceptor.js View on Github external
Size: Size,
      InfoWindow: InfoWindow
    }
  }
  const Loader = {
    load: function load (callback) {
      callback(Google)
    },
    release: function release () {},
    happenings
  }

  module.exports = Loader`
}

addHook(mutate, {
  exts: ['.js'],
  ignoreNodeModules: false,
  matcher
})
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 babel / babel / packages / babel-register / src / node.js View on Github external
function hookExtensions(exts) {
  if (piratesRevert) piratesRevert();
  piratesRevert = addHook(compile, { exts, ignoreNodeModules: false });
}
github babel / babel / packages / babel-register / src / node.js View on Github external
function hookExtensions(exts) {
  if (piratesRevert) piratesRevert();
  piratesRevert = addHook(compileHook, { exts, ignoreNodeModules: false });
}
github alangpierce / sucrase / src / register.ts View on Github external
export function addHook(extension: string, options: Options): void {
  pirates.addHook(
    (code: string, filePath: string): string => {
      const {code: transformedCode, sourceMap} = transform(code, {
        ...options,
        sourceMapOptions: {compiledFilename: filePath},
        filePath,
      });
      const mapBase64 = Buffer.from(JSON.stringify(sourceMap)).toString("base64");
      const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
      return `${transformedCode}\n${suffix}`;
    },
    {exts: [extension]},
  );
}
github keystonejs / keystone / packages / build-field-types / src / hook.js View on Github external
sourceMapSupport.install({
    environment: 'node',
    retrieveSourceMap(source) {
      let map = sourceMaps[source];
      if (map !== undefined) {
        return {
          url: source,
          map,
        };
      } else {
        return null;
      }
    },
  });

  return addHook(compileHook, {
    exts: EXTENSIONS,
  });
};

pirates

Properly hijack require, i.e., properly define require hooks and customizations

MIT
Latest version published 1 year ago

Package Health Score

77 / 100
Full package analysis

Popular pirates functions

Similar packages