How to use the @rollup/pluginutils.createFilter function in @rollup/pluginutils

To help you get started, we’ve selected a few @rollup/pluginutils 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 rollup / plugins / packages / node-resolve / src / index.js View on Github external
// eslint-disable-next-line no-prototype-builtins
      browserMap.hasOwnProperty(pkg.main)
    ) {
      packageInfo.resolvedEntryPoint = browserMap[pkg.main];
      packageInfo.browserMappedMain = true;
    } else {
      // index.node is technically a valid default entrypoint as well...
      packageInfo.resolvedEntryPoint = resolve(pkgRoot, pkg.main || 'index.js');
      packageInfo.browserMappedMain = false;
    }

    const packageSideEffects = pkg.sideEffects;
    if (typeof packageSideEffects === 'boolean') {
      internalPackageInfo.hasModuleSideEffects = () => packageSideEffects;
    } else if (Array.isArray(packageSideEffects)) {
      internalPackageInfo.hasModuleSideEffects = createFilter(packageSideEffects, null, {
        resolve: pkgRoot
      });
    }

    packageInfoCache.set(pkgPath, internalPackageInfo);
    return internalPackageInfo;
  }
github rollup / plugins / packages / typescript / src / index.ts View on Github external
export default function typescript(options: RollupTypescriptOptions = {}): Plugin {
  const opts = Object.assign({}, options);

  const filter = createFilter(
    opts.include || ['*.ts+(|x)', '**/*.ts+(|x)'],
    opts.exclude || ['*.d.ts', '**/*.d.ts']
  );
  delete opts.include;
  delete opts.exclude;

  // Allow users to override the TypeScript version used for transpilation and tslib version used for helpers.
  const ts: typeof import('typescript') = opts.typescript || defaultTs;
  delete opts.typescript;

  const tslib = getTsLibCode(opts);
  delete opts.tslib;

  // Load options from `tsconfig.json` unless explicitly asked not to.
  const tsConfig =
    opts.tsconfig === false ? { compilerOptions: {} } : readTsConfig(ts, opts.tsconfig);
github rollup / plugins / packages / json / src / index.js View on Github external
export default function json(options = {}) {
  const filter = createFilter(options.include, options.exclude);
  const indent = 'indent' in options ? options.indent : '\t';

  return {
    name: 'json',

    // eslint-disable-next-line no-shadow
    transform(json, id) {
      if (id.slice(-5) !== '.json' || !filter(id)) return null;

      return {
        code: dataToEsm(JSON.parse(json), {
          preferConst: options.preferConst,
          compact: options.compact,
          namedExports: options.namedExports,
          indent
        }),
github rollup / plugins / packages / image / src / index.js View on Github external
export default function image(opts = {}) {
  const options = Object.assign({}, defaults, opts);
  const filter = createFilter(options.include, options.exclude);

  return {
    name: 'image',

    load(id) {
      if (!filter(id)) {
        return null;
      }

      const mime = mimeTypes[extname(id)];
      if (!mime) {
        // not an image
        return null;
      }

      const format = mime === mimeTypes['.svg'] ? 'utf-8' : 'base64';
github rollup / plugins / packages / inject / src / index.js View on Github external
export default function inject(options) {
  if (!options) throw new Error('Missing options');

  const filter = createFilter(options.include, options.exclude);

  let { modules } = options;

  if (!modules) {
    modules = Object.assign({}, options);
    delete modules.include;
    delete modules.exclude;
    delete modules.sourceMap;
    delete modules.sourcemap;
  }

  const modulesMap = new Map(Object.entries(modules));

  // Fix paths on Windows
  if (sep !== '/') {
    modulesMap.forEach((mod, key) => {
github rollup / plugins / packages / babel / src / index.js View on Github external
const { customOptions, pluginOptionsWithOverrides } = getOptionsWithOverrides(
      pluginOptions,
      overrides
    );

    const {
      exclude,
      extensions,
      babelHelpers,
      include,
      skipPreflightCheck,
      ...babelOptions
    } = unpackInputPluginOptions(pluginOptionsWithOverrides);

    const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);
    const includeExcludeFilter = createFilter(include, exclude);
    const filter = (id) => extensionRegExp.test(id) && includeExcludeFilter(id);

    return {
      name: 'babel',

      resolveId(id) {
        if (id !== HELPERS) {
          return null;
        }
        return id;
      },

      load(id) {
        if (id !== HELPERS) {
          return null;
        }
github rollup / plugins / packages / strip / src / index.js View on Github external
export default function strip(options = {}) {
  const include = options.include || '**/*.js';
  const { exclude } = options;
  const filter = createFilter(include, exclude);
  const sourceMap = options.sourceMap !== false;

  const removeDebuggerStatements = options.debugger !== false;
  const functions = (options.functions || ['console.*', 'assert.*']).map((keypath) =>
    keypath.replace(/\./g, '\\.').replace(/\*/g, '\\w+')
  );

  const labels = options.labels || [];

  const firstpass = new RegExp(`\\b(?:${functions.join('|')}|debugger)\\b`);
  const pattern = new RegExp(`^(?:${functions.join('|')})$`);

  return {
    name: 'strip',

    transform(code, id) {
github rollup / plugins / packages / yaml / src / index.js View on Github external
export default function yamll(opts = {}) {
  const options = Object.assign({}, defaults, opts);
  const { documentMode, safe } = options;
  const filter = createFilter(options.include, options.exclude);
  let loadMethod = null;

  if (documentMode === 'single') {
    loadMethod = safe ? YAML.load : YAML.safeLoad;
  } else if (documentMode === 'multi') {
    loadMethod = safe ? YAML.loadAll : YAML.safeLoadAll;
  } else {
    this.error(
      `plugin-yaml → documentMode: '${documentMode}' is not a valid value. Please choose 'single' or 'multi'`
    );
  }

  return {
    name: 'yaml',

    transform(content, id) {
github rollup / plugins / packages / buble / src / index.js View on Github external
export default function buble(options = {}) {
  const filter = createFilter(options.include, options.exclude);
  const transformOptions = { ...options, transforms: { ...options.transforms, modules: false } };

  return {
    name: 'buble',

    transform(code, id) {
      if (!filter(id)) return null;

      try {
        return transform(code, transformOptions);
      } catch (e) {
        e.plugin = 'buble';
        if (!e.loc) e.loc = {};
        e.loc.file = id;
        e.frame = e.snippet;
        throw e;
github rollup / plugins / packages / dsv / src / index.js View on Github external
export default function dsv(options = {}) {
  const filter = createFilter(options.include, options.exclude);

  return {
    name: 'dsv',

    transform(code, id) {
      if (!filter(id)) return null;

      const ext = extname(id);
      if (!(ext in parsers)) return null;

      let rows = parsers[ext](code);

      if (options.processRow) {
        rows = rows.map((row) => options.processRow(row, id) || row);
      }

@rollup/pluginutils

A set of utility functions commonly used by Rollup plugins

MIT
Latest version published 29 days ago

Package Health Score

100 / 100
Full package analysis