Skip to content

Commit

Permalink
chore(js): switch from fast-glob to tinyglobby
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Dec 2, 2024
1 parent 06d549b commit 2668d97
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
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
9 changes: 5 additions & 4 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,7 +115,7 @@ export class CopyAssetsHandler {
this.assetGlobs.map(async (ag) => {
const pattern = this.normalizeAssetPattern(ag);

// fast-glob only supports Unix paths
// globbing only supports Unix paths
const files = await fg(pattern.replace(/\\/g, '/'), {
cwd: this.rootDir,
dot: true, // enable hidden files
Expand All @@ -130,10 +130,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

0 comments on commit 2668d97

Please sign in to comment.