From ea97409394092f043acb6b155df63cab7e1e2318 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 1 Dec 2024 15:45:16 -0800 Subject: [PATCH 1/4] chore(js): switch from fast-glob to tinyglobby --- packages/js/package.json | 2 +- packages/js/src/executors/swc/swc.impl.ts | 3 ++- packages/js/src/utils/assets/assets.ts | 5 +++-- packages/js/src/utils/assets/copy-assets-handler.ts | 9 +++++---- .../js/src/utils/package-json/create-entry-points.ts | 7 +++++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/js/package.json b/packages/js/package.json index d35a9818a3145..d5e88b0dacff7 100644 --- a/packages/js/package.json +++ b/packages/js/package.json @@ -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", @@ -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" diff --git a/packages/js/src/executors/swc/swc.impl.ts b/packages/js/src/executors/swc/swc.impl.ts index 7062498090107..3f96d743a8168 100644 --- a/packages/js/src/executors/swc/swc.impl.ts +++ b/packages/js/src/executors/swc/swc.impl.ts @@ -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'; @@ -254,6 +254,7 @@ function createEntryPoints( if (!options.additionalEntryPoints?.length) return []; return globSync(options.additionalEntryPoints, { cwd: context.root, + expandDirectories: false, }); } diff --git a/packages/js/src/utils/assets/assets.ts b/packages/js/src/utils/assets/assets.ts index 2bf9650101dc8..3a634b7a495c2 100644 --- a/packages/js/src/utils/assets/assets.ts +++ b/packages/js/src/utils/assets/assets.ts @@ -1,4 +1,4 @@ -import * as fastGlob from 'fast-glob'; +import { globSync } from 'tinyglobby'; import { basename, join } from 'path'; export type FileInputOutput = { @@ -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, }); }; diff --git a/packages/js/src/utils/assets/copy-assets-handler.ts b/packages/js/src/utils/assets/copy-assets-handler.ts index 1a1545cbf2bc6..96a455000676e 100644 --- a/packages/js/src/utils/assets/copy-assets-handler.ts +++ b/packages/js/src/utils/assets/copy-assets-handler.ts @@ -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'; @@ -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 @@ -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)); diff --git a/packages/js/src/utils/package-json/create-entry-points.ts b/packages/js/src/utils/package-json/create-entry-points.ts index 6f907aa92760d..a4cd384e04c80 100644 --- a/packages/js/src/utils/package-json/create-entry-points.ts +++ b/packages/js/src/utils/package-json/create-entry-points.ts @@ -1,4 +1,4 @@ -import { sync as globSync } from 'fast-glob'; +import { globSync } from 'tinyglobby'; import { logger } from '@nx/devkit'; export function createEntryPoints( @@ -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); From 5dabe6654514d2b87b5ceebd01a363f7f054dd00 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 7 Dec 2024 07:33:08 -0800 Subject: [PATCH 2/4] fix(js): duplicate dependency in root package.json --- package.json | 1 + pnpm-lock.yaml | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 41f937ea25b0c..377c5e26519fd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a996bcc63f5bb..d15ef934bb2ca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -952,6 +952,9 @@ importers: terser-webpack-plugin: specifier: ^5.3.3 version: 5.3.10(@swc/core@1.5.7(@swc/helpers@0.5.11))(esbuild@0.19.5)(webpack@5.88.0) + tinyglobby: + specifier: ^0.2.10 + version: 0.2.10 tmp: specifier: ~0.2.1 version: 0.2.3 @@ -10383,6 +10386,14 @@ packages: picomatch: optional: true + fdir@6.4.2: + resolution: {integrity: sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ==} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + fflate@0.6.10: resolution: {integrity: sha512-IQrh3lEPM93wVCEczc9SaAOvkmcoQn/G8Bo1e8ZPlY3X3bnAxWaBdvTdvM1hP62iZp0BXWDy4vTAy4fF0+Dlpg==} @@ -16225,6 +16236,10 @@ packages: tinybench@2.9.0: resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==} + tinyglobby@0.2.10: + resolution: {integrity: sha512-Zc+8eJlFMvgatPZTl6A9L/yht8QqdmUNtURHaKZLmKBE12hNPSrqNkUp2cs3M/UKmNVVAMFQYSjYIVHDjW5zew==} + engines: {node: '>=12.0.0'} + tinyglobby@0.2.6: resolution: {integrity: sha512-NbBoFBpqfcgd1tCiO8Lkfdk+xrA7mlLR9zgvZcZWQQwU63XAfUePyd6wZBaU93Hqw347lHnwFzttAkemHzzz4g==} engines: {node: '>=12.0.0'} @@ -22038,7 +22053,7 @@ snapshots: semver: 7.6.3 simple-git: 3.27.0 sirv: 2.0.4 - tinyglobby: 0.2.6 + tinyglobby: 0.2.10 unimport: 3.12.0(rollup@4.22.0)(webpack-sources@3.2.3) vite: 5.0.8(@types/node@20.16.10)(less@4.1.3)(sass@1.55.0)(stylus@0.64.0)(terser@5.36.0) vite-plugin-inspect: 0.8.7(@nuxt/kit@3.13.2(magicast@0.3.5)(rollup@4.22.0)(webpack-sources@3.2.3))(rollup@4.22.0)(vite@5.0.8(@types/node@20.16.10)(less@4.1.3)(sass@1.55.0)(stylus@0.64.0)(terser@5.36.0)) @@ -29374,6 +29389,10 @@ snapshots: optionalDependencies: picomatch: 4.0.2 + fdir@6.4.2(picomatch@4.0.2): + optionalDependencies: + picomatch: 4.0.2 + fflate@0.6.10: {} fflate@0.8.2: {} @@ -36655,6 +36674,11 @@ snapshots: tinybench@2.9.0: {} + tinyglobby@0.2.10: + dependencies: + fdir: 6.4.2(picomatch@4.0.2) + picomatch: 4.0.2 + tinyglobby@0.2.6: dependencies: fdir: 6.3.0(picomatch@4.0.2) From 4adb1c11b4921d43e34f696361207f4ed458928a Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 7 Dec 2024 08:00:22 -0800 Subject: [PATCH 3/4] fix(js): missed updating a place --- packages/js/src/utils/assets/copy-assets-handler.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/js/src/utils/assets/copy-assets-handler.ts b/packages/js/src/utils/assets/copy-assets-handler.ts index 96a455000676e..6a2ae08d25ebe 100644 --- a/packages/js/src/utils/assets/copy-assets-handler.ts +++ b/packages/js/src/utils/assets/copy-assets-handler.ts @@ -116,9 +116,10 @@ export class CopyAssetsHandler { const pattern = this.normalizeAssetPattern(ag); // globbing only supports Unix paths - const files = await fg(pattern.replace(/\\/g, '/'), { + const files = await globSync(pattern.replace(/\\/g, '/'), { cwd: this.rootDir, dot: true, // enable hidden files + expandDirectories: false, }); this.callback(this.filesToEvent(files, ag)); From 5848e0f485121f79f8d3a87ba2c7f07e3adbf251 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:41:02 -0800 Subject: [PATCH 4/4] fix(js): update eslint config --- packages/js/.eslintrc.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/js/.eslintrc.json b/packages/js/.eslintrc.json index 3b0e42dd2a4c6..e91aaefb34b9d 100644 --- a/packages/js/.eslintrc.json +++ b/packages/js/.eslintrc.json @@ -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."