Skip to content

Commit

Permalink
fix(js): switch from fast-glob to tinyglobby (#29141)
Browse files Browse the repository at this point in the history
(cherry picked from commit e3f8c81)
  • Loading branch information
benmccann authored and FrozenPandaz committed Dec 10, 2024
1 parent 9f28983 commit 6f50e2f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
"tar-stream": "~2.2.0",
"tcp-port-used": "^1.0.2",
"terser-webpack-plugin": "^5.3.3",
"tinyglobby": "^0.2.10",
"tmp": "~0.2.1",
"tree-kill": "1.2.2",
"ts-jest": "29.1.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/js/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"rules": {
"no-restricted-imports": [
"error",
{
"name": "fast-glob",
"message": "Please use `tinyglobby` instead."
},
{
"name": "fs-extra",
"message": "Please use equivalent utilities from `node:fs` instead."
Expand Down
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"columnify": "^1.6.0",
"detect-port": "^1.5.1",
"enquirer": "~2.3.6",
"fast-glob": "3.2.7",
"ignore": "^5.0.4",
"js-tokens": "^4.0.0",
"jsonc-parser": "3.2.0",
Expand All @@ -59,6 +58,7 @@
"ora": "5.3.0",
"semver": "^7.5.3",
"source-map-support": "0.5.19",
"tinyglobby": "^0.2.10",
"ts-node": "10.9.1",
"tsconfig-paths": "^4.1.2",
"tslib": "^2.3.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/js/src/executors/swc/swc.impl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorContext, output, readJsonFile } from '@nx/devkit';
import { sync as globSync } from 'fast-glob';
import { globSync } from 'tinyglobby';
import { rmSync } from 'node:fs';
import { dirname, join, normalize, relative, resolve } from 'path';
import { copyAssets } from '../../utils/assets';
Expand Down Expand Up @@ -254,6 +254,7 @@ function createEntryPoints(
if (!options.additionalEntryPoints?.length) return [];
return globSync(options.additionalEntryPoints, {
cwd: context.root,
expandDirectories: false,
});
}

Expand Down
5 changes: 3 additions & 2 deletions packages/js/src/utils/assets/assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fastGlob from 'fast-glob';
import { globSync } from 'tinyglobby';
import { basename, join } from 'path';

export type FileInputOutput = {
Expand All @@ -24,10 +24,11 @@ export function assetGlobsToFiles(
ignore: string[] = [],
dot: boolean = false
) => {
return fastGlob.sync(pattern, {
return globSync(pattern, {
cwd: input,
onlyFiles: true,
dot,
expandDirectories: false,
ignore,
});
};
Expand Down
12 changes: 7 additions & 5 deletions packages/js/src/utils/assets/copy-assets-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import * as pathPosix from 'node:path/posix';
import * as path from 'node:path';
import ignore from 'ignore';
import * as fg from 'fast-glob';
import { globSync } from 'tinyglobby';
import { AssetGlob } from './assets';
import { logger } from '@nx/devkit';
import { ChangedFile, daemonClient } from 'nx/src/daemon/client/client';
Expand Down Expand Up @@ -115,10 +115,11 @@ export class CopyAssetsHandler {
this.assetGlobs.map(async (ag) => {
const pattern = this.normalizeAssetPattern(ag);

// fast-glob only supports Unix paths
const files = await fg(pattern.replace(/\\/g, '/'), {
// globbing only supports Unix paths
const files = await globSync(pattern.replace(/\\/g, '/'), {
cwd: this.rootDir,
dot: true, // enable hidden files
expandDirectories: false,
});

this.callback(this.filesToEvent(files, ag));
Expand All @@ -130,10 +131,11 @@ export class CopyAssetsHandler {
this.assetGlobs.forEach((ag) => {
const pattern = this.normalizeAssetPattern(ag);

// fast-glob only supports Unix paths
const files = fg.sync(pattern.replace(/\\/g, '/'), {
// globbing only supports Unix paths
const files = globSync(pattern.replace(/\\/g, '/'), {
cwd: this.rootDir,
dot: true, // enable hidden files
expandDirectories: false,
});

this.callback(this.filesToEvent(files, ag));
Expand Down
7 changes: 5 additions & 2 deletions packages/js/src/utils/package-json/create-entry-points.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sync as globSync } from 'fast-glob';
import { globSync } from 'tinyglobby';
import { logger } from '@nx/devkit';

export function createEntryPoints(
Expand All @@ -13,7 +13,10 @@ export function createEntryPoints(
// Performance impact should be negligible since there shouldn't be that many entry points.
// Benchmarks show only 1-3% difference in execution time.
for (const pattern of additionalEntryPoints) {
const matched = globSync([pattern], { cwd: root });
const matched = globSync([pattern], {
cwd: root,
expandDirectories: false,
});
if (!matched.length)
logger.warn(`The pattern ${pattern} did not match any files.`);
files.push(...matched);
Expand Down
26 changes: 25 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f50e2f

Please sign in to comment.