Exemplo n.º 1
0
function buildFile(file, silent) {
  const destPath = getBuildPath(file, BUILD_DIR);

  if (micromatch.isMatch(file, IGNORE_PATTERN)) {
    silent ||
      process.stdout.write(
        chalk.dim('  \u2022 ') +
          path.relative(PACKAGES_DIR, file) +
          ' (ignore)\n'
      );
    return;
  }

  mkdirp.sync(path.dirname(destPath));
  if (!micromatch.isMatch(file, JS_FILES_PATTERN)) {
    fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
    silent ||
      process.stdout.write(
        chalk.red('  \u2022 ') +
          path.relative(PACKAGES_DIR, file) +
          chalk.red(' \u21D2 ') +
          path.relative(PACKAGES_DIR, destPath) +
          ' (copy)' +
          '\n'
      );
  } else {
    const options = Object.assign({}, transformOptions);
    options.plugins = options.plugins.slice();

    if (!INLINE_REQUIRE_BLACKLIST.test(file)) {
      // Remove normal plugin.
      options.plugins = options.plugins.filter(
        plugin =>
          !(
            Array.isArray(plugin) &&
            plugin[0] === 'transform-es2015-modules-commonjs'
          )
      );
      options.plugins.push([
        'transform-inline-imports-commonjs',
        {
          allowTopLevelThis: true,
        },
      ]);
    }

    const transformed = babel.transformFileSync(file, options).code;
    const prettyCode = prettier.format(transformed, prettierConfig);
    fs.writeFileSync(destPath, prettyCode);
    silent ||
      process.stdout.write(
        chalk.green('  \u2022 ') +
          path.relative(PACKAGES_DIR, file) +
          chalk.green(' \u21D2 ') +
          path.relative(PACKAGES_DIR, destPath) +
          '\n'
      );
  }
}
Exemplo n.º 2
0
 function defaultFileEvent (file) {
   var filename = path.basename(file)
   if (typeof opts.live === 'string' && !isMatch(filename, opts.live)) {
     return
   }
   emitter.reload(file)
 }
Exemplo n.º 3
0
fs.readdirSync(__dirname + '/code').forEach(function (fp) {
  if (mm.isMatch(fp, '*.js')) {
    var fn = require(path.resolve(__dirname, 'code', fp));
    var name = path.basename(fp, path.extname(fp));

    fs.readdirSync(__dirname + '/fixtures').forEach(function (fixture) {
      if (mm.isMatch(fixture, '*.js')) {
        fixture = path.resolve(__dirname, 'fixtures', fixture);
        console.log(chalk.bold(name) + ':', fn.apply(null, require(fixture)));
      }
    });
  }
});
Exemplo n.º 4
0
Arquivo: build.js Projeto: jRiest/jest
function buildFile(file, silent) {
  const packageName = path.relative(PACKAGES_DIR, file).split(path.sep)[0];
  const packageSrcPath = path.resolve(PACKAGES_DIR, packageName, 'src');
  const packageBuildPath = path.resolve(PACKAGES_DIR, packageName, 'build');
  const relativeToSrcPath = path.relative(packageSrcPath, file);
  const destPath = path.resolve(packageBuildPath, relativeToSrcPath);

  spawnSync('mkdir', ['-p', path.dirname(destPath)]);
  if (micromatch.isMatch(file, IGNORE_PATTERN)) {
    silent || process.stdout.write(
      chalk.dim('  \u2022 ') +
      path.relative(PACKAGES_DIR, file) +
      ' (ignore)\n'
    );
  } else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) {
    fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
    silent || process.stdout.write(
      chalk.red('  \u2022 ') +
      path.relative(PACKAGES_DIR, file) +
      chalk.red(' \u21D2 ') +
      path.relative(PACKAGES_DIR, destPath) +
      ' (copy)' +
      '\n'
    );
  } else {
    const transformed = babel.transformFileSync(file, babelOptions).code;
    spawnSync('mkdir', ['-p', path.dirname(destPath)]);
    fs.writeFileSync(destPath, transformed);
    silent || process.stdout.write(
      chalk.green('  \u2022 ') +
      path.relative(PACKAGES_DIR, file) +
      chalk.green(' \u21D2 ') +
      path.relative(PACKAGES_DIR, destPath) +
      '\n'
    );
  }
}
Exemplo n.º 5
0
export function matchesFilter(filter: IgnoreFilter, basename: string, loc: string): boolean {
  let filterByBasename = true;
  if (filter.base && filter.base !== '.') {
    loc = path.relative(filter.base, loc);
    filterByBasename = false;
  }
  // the micromatch regex expects unix path separators
  loc = loc.replace('\\', '/');

  return (
    filter.regex.test(loc) ||
    filter.regex.test(`/${loc}`) ||
    (filterByBasename && filter.regex.test(basename)) ||
    mm.isMatch(loc, filter.pattern)
  );
}
Exemplo n.º 6
0
    proxies.forEach((p) => {
      if (mm.isMatch(req.url, convertToGlob(p.src))) {
        routeMatched = true

        const newUrl = parseUrl(req.url, p.src, p.dest)
        const parsed = url.parse(newUrl)

        /* does this still mess crap up? */
        // delete req.headers['accept-encoding']

        req.url = parsed.path

        proxyServer.on('error', next)
        proxyServer.web(req, res, {
          target: `${parsed.protocol}//${parsed.host}`,
        }, next)
      }
    })
Exemplo n.º 7
0
module.exports = function any(fp, patterns, options) {
  options = options || {};
  var res = {is: [], isnt: []};
  res.file = fp;
  var len = patterns.length;
  var i = -1;

  while (++i < len) {
    var pattern = patterns[i];
    if (mm.isMatch(fp, pattern, {dot: true, contains: true})) {
      res.is.push(pattern);
      break;
    } else {
      res.isnt.push(pattern);
    }
  }
  return res;
};
	static moduleHasSideEffects(moduleName, flagValue) {
		switch (typeof flagValue) {
			case "undefined":
				return true;
			case "boolean":
				return flagValue;
			case "string":
				if (process.platform === "win32") {
					flagValue = flagValue.replace(/\\/g, "/");
				}
				return mm.isMatch(moduleName, flagValue, {
					matchBase: true
				});
			case "object":
				return flagValue.some(glob =>
					SideEffectsFlagPlugin.moduleHasSideEffects(moduleName, glob)
				);
		}
	}
Exemplo n.º 9
0
 function testCriteria (criterion, index) {
   var result;
   switch (toString.call(criterion)) {
   case '[object String]':
     result = string === criterion || altString && altString === criterion;
     result = result || micromatch.isMatch(string, criterion);
     break;
   case '[object RegExp]':
     result = criterion.test(string) || altString && criterion.test(altString);
     break;
   case '[object Function]':
     result = criterion.apply(null, value);
     break;
   default:
     result = false;
   }
   if (result) {
     matchIndex = index + startIndex;
   }
   return result;
 }
 (filename) =>
   hasFileChanged.call(this, filename, fileTimestamps[filename]) &&
   micromatch.isMatch(filename, glob)
Exemplo n.º 11
0
Arquivo: build.js Projeto: Volune/jest
function buildFile(file, silent) {
  const destPath = getBuildPath(file, BUILD_DIR);

  if (micromatch.isMatch(file, IGNORE_PATTERN)) {
    silent ||
      process.stdout.write(
        chalk.dim('  \u2022 ') +
          path.relative(PACKAGES_DIR, file) +
          ' (ignore)\n'
      );
    return;
  }

  mkdirp.sync(path.dirname(destPath), '777');
  if (
    !micromatch.isMatch(file, JS_FILES_PATTERN) &&
    !micromatch.isMatch(file, TS_FILES_PATTERN)
  ) {
    fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
    silent ||
      process.stdout.write(
        chalk.red('  \u2022 ') +
          path.relative(PACKAGES_DIR, file) +
          chalk.red(' \u21D2 ') +
          path.relative(PACKAGES_DIR, destPath) +
          ' (copy)' +
          '\n'
      );
  } else {
    const options = Object.assign({}, transformOptions);
    options.plugins = options.plugins.slice();

    if (INLINE_REQUIRE_BLACKLIST.test(file)) {
      // The modules in the blacklist are injected into the user's sandbox
      // We need to guard some globals there.
      options.plugins.push(
        require.resolve('./babel-plugin-jest-native-globals')
      );
    } else {
      options.plugins = options.plugins.map(plugin => {
        if (
          Array.isArray(plugin) &&
          plugin[0] === '@babel/plugin-transform-modules-commonjs'
        ) {
          return [plugin[0], Object.assign({}, plugin[1], {lazy: true})];
        }

        return plugin;
      });
    }

    const transformed = babel.transformFileSync(file, options).code;
    const prettyCode = prettier.format(transformed, prettierConfig);

    fs.writeFileSync(destPath, prettyCode);

    silent ||
      process.stdout.write(
        chalk.green('  \u2022 ') +
          path.relative(PACKAGES_DIR, file) +
          chalk.green(' \u21D2 ') +
          path.relative(PACKAGES_DIR, destPath) +
          '\n'
      );
  }
}
Exemplo n.º 12
0
 match (filePath) {
   const opts = { nocase: true }
   return micromatch.any(filePath, this.includeList, opts) &&
          micromatch.any(filePath, this.excludeList, opts) === false &&
          micromatch.isMatch(filePath, this.extensions, opts)
 }
Exemplo n.º 13
0
 const shouldSkip = !fileFilters.some(file =>
   micromatch.isMatch(htmlPluginData.outputName, file),
Exemplo n.º 14
0
 /**
  * @method isIgnore
  * @param {string} path
  * @private
  */
 [isIgnore](path) {
   return this.ignore.length && micromatch.isMatch(path, this.ignore, this[glob]);
 }
Exemplo n.º 15
0
 fs.readdirSync(__dirname + '/fixtures').forEach(function (fixture) {
   if (mm.isMatch(fixture, '*.js')) {
     fixture = path.resolve(__dirname, 'fixtures', fixture);
     console.log(chalk.bold(name) + ':', fn.apply(null, require(fixture)));
   }
 });