Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃彈 Replace globby with fast-glob #35846

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ validator/**/dist
validator/export

# Files and directories explicitly ignored by eslint
**/node_modules/**
build-system/babel-plugins/**/fixtures/**/*.js
build-system/babel-plugins/**/fixtures/**/*.mjs
build-system/tasks/make-extension/template/**/*
Expand Down
9 changes: 4 additions & 5 deletions build-system/common/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const argv = require('minimist')(process.argv.slice(2));
const experimentsConfig = require('../global-configs/experiments-config.json');
const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const {clean} = require('../tasks/clean');
const {cyan, green, red, yellow} = require('./colors');
const {default: ignore} = require('ignore');
Expand Down Expand Up @@ -49,7 +49,7 @@ function getExperimentConfig(experiment) {
* @return {!Array<string>}
*/
function getFilesChanged(globs, options) {
const allFiles = globby.sync(globs, options).map(String);
const allFiles = fastGlob.sync(globs, options).map(String);
return gitDiffNameOnlyMain().filter((changedFile) => {
return fs.existsSync(changedFile) && allFiles.includes(changedFile);
});
Expand Down Expand Up @@ -79,12 +79,11 @@ function getFilesFromArgv() {
if (!argv.files) {
return [];
}
// TODO(#30223): globby only takes posix globs. Find a Windows alternative.
const toPosix = (str) => str.replace(/\\\\?/g, '/');
const globs = Array.isArray(argv.files) ? argv.files : argv.files.split(',');
const allFiles = [];
for (const glob of globs) {
const files = globby.sync(toPosix(glob.trim()));
const files = fastGlob.sync(toPosix(glob.trim()));
if (files.length == 0) {
log(red('ERROR:'), 'Argument', cyan(glob), 'matched zero files.');
throw new Error('Argument matched zero files.');
Expand Down Expand Up @@ -133,7 +132,7 @@ function getFilesToCheck(globs, options = {}, ignoreFile = undefined) {
}
return logFiles(filesChanged);
}
return ignored.filter(globby.sync(globs, options).map(String));
return ignored.filter(fastGlob.sync(globs, options).map(String));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions build-system/compile/compile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
const argv = require('minimist')(process.argv.slice(2));
const del = require('del');
const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');
const {checkForUnknownDeps} = require('./check-for-unknown-deps');
const {CLOSURE_SRC_GLOBS} = require('./sources');
Expand Down Expand Up @@ -195,8 +195,8 @@ function generateCompilerOptions(outputFilename, options) {
'third_party/web-animations-externs/web_animations.js',
'third_party/react-externs/externs.js',
'third_party/moment/moment.extern.js',
...globby.sync('src/core{,/**}/*.extern.js'),
...globby.sync('build-system/externs/*.extern.js'),
...fastGlob.sync('src/core{,/**}/*.extern.js'),
...fastGlob.sync('build-system/externs/*.extern.js'),
...externs,
];
}
Expand Down Expand Up @@ -405,7 +405,7 @@ async function compile(
? entryModuleFilenames.concat(options.extraGlobs || [])
: getSrcs(entryModuleFilenames, options);
const transformedSrcFiles = await Promise.all(
globby
fastGlob
.sync(srcs)
.map((src) => preClosureBabel(src, outputFilename, options))
);
Expand Down
8 changes: 6 additions & 2 deletions build-system/compile/pre-closure-babel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const babel = require('@babel/core');
const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');
const tempy = require('tempy');
const {BABEL_SRC_GLOBS} = require('./sources');
Expand Down Expand Up @@ -47,7 +47,11 @@ function getBabelOutputDir() {
* @return {!Array<string>}
*/
function getFilesToTransform() {
return globby.sync([...BABEL_SRC_GLOBS, '!node_modules/', '!third_party/']);
return fastGlob.sync([
...BABEL_SRC_GLOBS,
'!node_modules/**',
'!third_party/**',
]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions build-system/pr-check/build-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* determine which tasks are required to run for pull request builds.
*/
const config = require('../test-configs/config');
const globby = require('globby');
const fastGlob = require('fast-glob');
const minimatch = require('minimatch');
const path = require('path');
const {cyan} = require('../common/colors');
Expand Down Expand Up @@ -393,7 +393,7 @@ function expandFileLists() {
];
for (const globName of globNames) {
const fileListName = globName.replace('Globs', 'Files');
fileLists[fileListName] = globby.sync(config[globName], {dot: true});
fileLists[fileListName] = fastGlob.sync(config[globName], {dot: true});
}
}

Expand Down
4 changes: 2 additions & 2 deletions build-system/pr-check/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');
const {
ciPullRequestSha,
Expand Down Expand Up @@ -245,7 +245,7 @@ function storeBuildToWorkspace_(containerDirectory) {
}
}
// Bento components are compiled inside the extension source file.
for (const componentFile of globby.sync('extensions/*/?.?/dist/*.js')) {
for (const componentFile of fastGlob.sync('extensions/*/?.?/dist/*.js')) {
fs.ensureDirSync(
`/tmp/workspace/builds/${containerDirectory}/${path.dirname(
componentFile
Expand Down
4 changes: 2 additions & 2 deletions build-system/server/typescript-compile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const esbuild = require('esbuild');
const globby = require('globby');
const fastGlob = require('fast-glob');
const path = require('path');
const {accessSync} = require('fs-extra');
const {cyan, green} = require('../common/colors');
Expand Down Expand Up @@ -30,7 +30,7 @@ async function buildNewServer() {
green('at'),
cyan(outdir) + green('...')
);
const entryPoints = await globby(`${SERVER_TRANSFORM_PATH}/**/*.ts`);
const entryPoints = await fastGlob(`${SERVER_TRANSFORM_PATH}/**/*.ts`);
const startTime = Date.now();
await esbuild.build({
...esbuildOptions,
Expand Down
4 changes: 2 additions & 2 deletions build-system/tasks/3p-vendor-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const debounce = require('../common/debounce');
const globby = require('globby');
const fastGlob = require('fast-glob');
const {cyan, red} = require('../common/colors');
const {endBuildStep} = require('./helpers');
const {esbuildCompile} = require('./helpers');
Expand Down Expand Up @@ -104,7 +104,7 @@ function generateBundles() {
* @return {!Array<string>}
*/
function listVendors() {
const filesToBuild = globby.sync(SRCPATH);
const filesToBuild = fastGlob.sync(SRCPATH);
const srcMatcher = /^3p\/vendors\/(.*)\.js/;
const results = [];

Expand Down
6 changes: 3 additions & 3 deletions build-system/tasks/analytics-vendor-configs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const minimist = require('minimist');
const argv = minimist(process.argv.slice(2));
const debounce = require('../common/debounce');
const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const jsonminify = require('jsonminify');
const {basename, dirname, extname, join} = require('path');
const {endBuildStep} = require('./helpers');
Expand Down Expand Up @@ -37,7 +37,7 @@ async function analyticsVendorConfigs(opt_options) {

const startTime = Date.now();

const srcFiles = await globby(srcPath);
const srcFiles = await fastGlob(srcPath);
await fs.ensureDir(destPath);
for (const srcFile of srcFiles) {
let destFile = join(destPath, basename(srcFile));
Expand All @@ -63,7 +63,7 @@ async function analyticsVendorConfigs(opt_options) {
}
await fs.writeFile(destFile, contents, 'utf-8');
}
if ((await globby(srcPath)).length > 0) {
if ((await fastGlob(srcPath)).length > 0) {
endBuildStep(
'Compiled all analytics vendor configs into',
destPath,
Expand Down
4 changes: 2 additions & 2 deletions build-system/tasks/bundle-size/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const argv = require('minimist')(process.argv.slice(2));
const fastGlob = require('fast-glob');
const fetch = require('node-fetch');
const globby = require('globby');
const path = require('path');
const url = require('url');
const {
Expand Down Expand Up @@ -226,7 +226,7 @@ async function reportBundleSize() {
* @return {Promise<void>}
*/
async function getLocalBundleSize() {
if ((await globby(fileGlobs)).length === 0) {
if ((await fastGlob(fileGlobs)).length === 0) {
log('Could not find runtime files.');
log('Run', cyan('amp dist --noextensions'), 'and re-run this task.');
process.exitCode = 1;
Expand Down
4 changes: 2 additions & 2 deletions build-system/tasks/check-analytics-vendors-list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const globby = require('globby');
const fastGlob = require('fast-glob');
const {basename} = require('path');
const {readFile} = require('fs-extra');
const {writeDiffOrFail} = require('../common/diff');
Expand Down Expand Up @@ -32,7 +32,7 @@ const blockRegExp = (name) =>
* @return {Promise<void>}
*/
async function checkAnalyticsVendorsList() {
const vendors = globby
const vendors = fastGlob
.sync(vendorsGlob)
.map((path) => basename(path, '.json'))
.sort();
Expand Down
4 changes: 2 additions & 2 deletions build-system/tasks/check-build-system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const globby = require('globby');
const fastGlob = require('fast-glob');
const path = require('path');
const {cyan, green} = require('../common/colors');
const {execOrThrow} = require('../common/exec');
Expand All @@ -10,7 +10,7 @@ const {updateSubpackages} = require('../common/update-packages');
* Skips npm checks during CI (already done while running each task).
*/
function updateBuildSystemSubpackages() {
const packageFiles = globby.sync('build-system/tasks/*/package.json');
const packageFiles = fastGlob.sync('build-system/tasks/*/package.json');
for (const packageFile of packageFiles) {
const packageDir = path.dirname(packageFile);
updateSubpackages(packageDir, /* skipNpmChecks */ true);
Expand Down
6 changes: 3 additions & 3 deletions build-system/tasks/check-exact-versions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const semver = require('semver');
const {cyan, green, red} = require('../common/colors');
const {gitDiffFileMain} = require('../common/git');
Expand Down Expand Up @@ -35,9 +35,9 @@ function check(file) {
* @return {!Promise}
*/
async function checkExactVersions() {
const packageJsonFiles = await globby([
const packageJsonFiles = await fastGlob([
'**/package.json',
'!**/node_modules',
'!**/node_modules/**',
rsimha marked this conversation as resolved.
Show resolved Hide resolved
]);
packageJsonFiles.forEach((file) => {
if (check(file)) {
Expand Down
8 changes: 4 additions & 4 deletions build-system/tasks/check-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const argv = require('minimist')(process.argv.slice(2));
const globby = require('globby');
const fastGlob = require('fast-glob');
const {
createCtrlcHandler,
exitCtrlcHandler,
Expand Down Expand Up @@ -135,12 +135,12 @@ const TYPE_CHECK_TARGETS = {
'ads/inabox/inabox-host.js',
'src/web-worker/web-worker.js',
],
extraGlobs: ['src/inabox/*.js', '!node_modules/preact'],
extraGlobs: ['src/inabox/*.js', '!node_modules/preact/**'],
warningLevel: 'QUIET',
},
'extensions': () => ({
entryPoints: getExtensionSrcPaths(),
extraGlobs: ['src/inabox/*.js', '!node_modules/preact'],
extraGlobs: ['src/inabox/*.js', '!node_modules/preact/**'],
warningLevel: 'QUIET',
}),
'integration': {
Expand Down Expand Up @@ -204,7 +204,7 @@ async function typeCheck(targetName) {

// If srcGlobs and externGlobs are defined, determine the externs/extraGlobs
if (srcGlobs.length || externGlobs.length) {
opts.externs = externGlobs.flatMap(globby.sync);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated note: we should go through all our usages of globby.sync and switch to async

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with file I/O, we do a looot of readFileSync etc iirc

opts.externs = externGlobs.flatMap(fastGlob.sync);

// Included globs should explicitly exclude any externs
const excludedExterns = externGlobs.map((glob) => `!${glob}`);
Expand Down
4 changes: 2 additions & 2 deletions build-system/tasks/check-video-interface-list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const globby = require('globby');
const fastGlob = require('fast-glob');
const {getStdout} = require('../common/process');
const {readFile} = require('fs-extra');
const {writeDiffOrFail} = require('../common/diff');
Expand Down Expand Up @@ -29,7 +29,7 @@ const entry = (name) =>
*/
const generateList = () =>
getStdout(
['grep -lr', `"${grepJsContent}"`, ...globby.sync(grepJsFiles)].join(' ')
['grep -lr', `"${grepJsContent}"`, ...fastGlob.sync(grepJsFiles)].join(' ')
)
.trim()
.split('\n')
Expand Down
4 changes: 2 additions & 2 deletions build-system/tasks/compile-jison.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const jison = require('jison');
const path = require('path');
const {jisonPath} = require('../test-configs/config');
Expand All @@ -28,7 +28,7 @@ const imports = new Map([
* @return {!Promise}
*/
async function compileJison(searchDir = jisonPath) {
const jisonFiles = await globby(searchDir);
const jisonFiles = await fastGlob(searchDir);
await Promise.all(
jisonFiles.map((jisonFile) => {
const jsFile = path.basename(jisonFile, '.jison');
Expand Down
4 changes: 2 additions & 2 deletions build-system/tasks/css/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const debounce = require('../../common/debounce');
const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');
const {buildExtensions} = require('../extension-helpers');
const {endBuildStep, watchDebounceDelay} = require('../helpers');
Expand Down Expand Up @@ -77,7 +77,7 @@ async function copyCss() {
for (const {outCss} of cssEntryPoints) {
await fs.copy(`build/css/${outCss}`, `dist/${outCss}`);
}
const cssFiles = await globby('build/css/amp-*.css');
const cssFiles = await fastGlob('build/css/amp-*.css');
await Promise.all(
cssFiles.map((cssFile) => {
return fs.copy(cssFile, `dist/v0/${path.basename(cssFile)}`);
Expand Down
8 changes: 4 additions & 4 deletions build-system/tasks/dist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const colors = require('../common/colors');
const fastGlob = require('fast-glob');
const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');
const {
bootstrapThirdPartyFrames,
Expand Down Expand Up @@ -241,7 +241,7 @@ async function preBuildWebPushPublisherFiles() {
const js = await fs.readFile(`${srcPath}/${fileName}.js`, 'utf8');
const builtName = `${fileName}.js`;
await fs.outputFile(`${destPath}/${builtName}`, js);
const jsFiles = await globby(`${srcPath}/*.js`);
const jsFiles = await fastGlob(`${srcPath}/*.js`);
await Promise.all(
jsFiles.map((jsFile) => {
return fs.copy(jsFile, `${destPath}/${path.basename(jsFile)}`);
Expand Down Expand Up @@ -304,7 +304,7 @@ async function preBuildExperiments() {
const js = await fs.readFile(jsSrcPath, 'utf8');
const builtName = 'experiments.max.js';
await fs.outputFile(`${jsDir}/${builtName}`, js);
const jsFiles = await globby(`${expDir}/*.js`);
const jsFiles = await fastGlob(`${expDir}/*.js`);
await Promise.all(
jsFiles.map((jsFile) => {
return fs.copy(jsFile, `${jsDir}/${path.basename(jsFile)}`);
Expand Down Expand Up @@ -346,7 +346,7 @@ async function preBuildLoginDoneVersion(version) {
const js = await fs.readFile(jsPath, 'utf8');
const builtName = `amp-login-done-${version}.max.js`;
await fs.outputFile(`${buildDir}/${builtName}`, js);
const jsFiles = await globby(`${srcDir}/*.js`);
const jsFiles = await fastGlob(`${srcDir}/*.js`);
await Promise.all(
jsFiles.map((jsFile) => {
return fs.copy(jsFile, `${buildDir}/${path.basename(jsFile)}`);
Expand Down
Loading