Skip to content

Commit 84b2362

Browse files
Artur-claude
andauthored
chore: replace glob package with Node.js built-in glob (#22417)
* chore: replace glob package with Node.js built-in glob Replace the external glob package dependency with Node.js built-in globSync functionality (available since Node.js 22). Changes: - Remove glob dependency from 3 package.json files - Update imports from 'glob' to 'node:fs' in theme plugins - All glob usage patterns are compatible with built-in implementation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: remove unused glob dependency from default package.json Remove glob from devDependencies in the default frontend dependencies package.json. * fix: use exclude option instead of nodir for fs.globSync Node.js built-in fs.globSync doesn't support the 'nodir' option from the glob package. Replace it with the 'exclude' option using statSync to filter out directories. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: use withFileTypes instead of exclude callback for filtering directories The exclude callback in fs.globSync receives relative path segments during pattern matching, not full paths. Calling statSync() on these segments fails with ENOENT errors because they don't exist relative to the current working directory. Using withFileTypes: true returns Dirent objects that already contain type information via isDirectory(), avoiding the need for additional statSync() calls. This is both correct and efficient. Fixes asset copying from theme.json (FontAwesome icons, Line Awesome, etc.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: replace nodir option with withFileTypes in theme-generator.js Complete the migration from glob package to Node.js built-in fs.globSync by replacing the unsupported nodir option with withFileTypes + filtering. While the *.css pattern wouldn't match directories anyway, this ensures consistency across all globSync usage and fully completes the migration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: handle undefined path in Dirent when using withFileTypes Filter out any Dirent entries that don't have parentPath defined. If parentPath is undefined, we can't construct a valid file path anyway, so it makes more sense to filter those entries out early. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * spotless:apply --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9b6969f commit 84b2362

File tree

8 files changed

+22
-25
lines changed

8 files changed

+22
-25
lines changed

flow-polymer2lit/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
"a-node-html-parser": "^6.0.0-4",
2020
"acorn": "^7.1.0",
2121
"acorn-walk": "^8.2.0",
22-
"glob": "^8.0.3",
2322
"magic-string": "^0.26.3",
2423
"patch-package": "^6.4.7",
2524
"prettier": "^2.1.2",
2625
"typescript": "^4.8.4"
2726
},
2827
"devDependencies": {
29-
"@types/glob": "^8.0.0",
3028
"@types/node": "^13.7.4"
3129
}
3230
}

flow-server/src/main/resources/com/vaadin/flow/server/frontend/dependencies/default/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"lit": "3.3.1"
88
},
99
"devDependencies": {
10-
"glob": "11.0.3",
1110
"typescript": "5.9.3",
1211
"strip-css-comments": "5.0.0"
1312
}

flow-server/src/main/resources/plugins/application-theme-plugin/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
},
1616
"type": "module",
1717
"dependencies": {
18-
"mkdirp": "0.5.6",
19-
"glob": "10.3.3"
18+
"mkdirp": "0.5.6"
2019
},
2120
"files": [
2221
"application-theme-plugin.js",

flow-server/src/main/resources/plugins/application-theme-plugin/theme-copy.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
* This contains functions and features used to copy theme files.
1919
*/
2020

21-
import { readdirSync, statSync, mkdirSync, existsSync, copyFileSync } from 'fs';
22-
import { resolve, basename, relative, extname } from 'path';
23-
import { globSync } from 'glob';
21+
import { readdirSync, statSync, mkdirSync, existsSync, copyFileSync, globSync } from 'fs';
22+
import { resolve, basename, relative, extname, join } from 'path';
2423

2524
const ignoredFileExtensions = ['.css', '.js', '.json'];
2625

@@ -144,7 +143,9 @@ function copyStaticAssets(themeName, themeProperties, projectStaticAssetsOutputF
144143
Object.keys(copyRules).forEach((copyRule) => {
145144
// Glob doesn't work with windows path separator so replacing it here.
146145
const nodeSources = resolve('node_modules/', module, copyRule).replace(/\\/g, '/');
147-
const files = globSync(nodeSources, { nodir: true });
146+
const files = globSync(nodeSources, { withFileTypes: true })
147+
.filter((dirent) => !dirent.isDirectory() && dirent.parentPath)
148+
.map((dirent) => join(dirent.parentPath, dirent.name));
148149
const targetFolder = resolve(projectStaticAssetsOutputFolder, 'themes', themeName, copyRules[copyRule]);
149150

150151
mkdirSync(targetFolder, {

flow-server/src/main/resources/plugins/application-theme-plugin/theme-generator.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* This file handles the generation of the '[theme-name].js' to
1919
* the themes/[theme-name] folder according to properties from 'theme.json'.
2020
*/
21-
import { globSync } from 'glob';
21+
import { globSync } from 'node:fs';
2222
import { resolve, basename } from 'path';
2323
import { existsSync, readFileSync, writeFileSync } from 'fs';
2424
import { checkModules } from './theme-copy.js';
@@ -62,8 +62,10 @@ function writeThemeFiles(themeFolder, themeName, themeProperties, options) {
6262
if (autoInjectComponents) {
6363
componentsFiles = globSync('*.css', {
6464
cwd: resolve(themeFolder, themeComponentsFolder),
65-
nodir: true
66-
});
65+
withFileTypes: true
66+
})
67+
.filter((dirent) => !dirent.isDirectory())
68+
.map((dirent) => dirent.name);
6769

6870
if (componentsFiles.length > 0) {
6971
componentsFileContent +=

flow-server/src/main/resources/plugins/theme-loader/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@
1616
"files": [
1717
"theme-loader.js",
1818
"theme-loader-utils.js"
19-
],
20-
"dependencies": {
21-
"glob": "10.3.3"
22-
}
19+
]
2320
}

flow-server/src/main/resources/plugins/theme-loader/theme-loader-utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { existsSync, readFileSync } from 'fs';
2-
import { resolve, basename } from 'path';
3-
import { globSync } from 'glob';
1+
import { existsSync, readFileSync, globSync } from 'fs';
2+
import { resolve, basename, join } from 'path';
43

54
// Collect groups [url(] ['|"]optional './|../', other '../' segments optional, file part and end of url
65
// The additional dot segments could be URL referencing assets in nested imported CSS
@@ -28,7 +27,9 @@ function assetsContains(fileUrl, themeFolder, logger) {
2827
// if file starts with copyRule target check if file with path after copy target can be found
2928
if (fileUrl.startsWith(copyRules[copyRule])) {
3029
const targetFile = fileUrl.replace(copyRules[copyRule], '');
31-
const files = globSync(resolve('node_modules/', module, copyRule), { nodir: true });
30+
const files = globSync(resolve('node_modules/', module, copyRule), { withFileTypes: true })
31+
.filter((dirent) => !dirent.isDirectory() && dirent.parentPath)
32+
.map((dirent) => join(dirent.parentPath, dirent.name));
3233

3334
for (let file of files) {
3435
if (file.endsWith(targetFile)) return true;

flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeUpdaterTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ public void getDefaultDevDependencies_includesAllDependencies_whenUsingVite() {
174174
private Set<String> getCommonDevDeps() {
175175
Set<String> expectedDependencies = new HashSet<>();
176176
expectedDependencies.add("typescript");
177-
expectedDependencies.add("glob");
178177
return expectedDependencies;
179178
}
180179

@@ -228,12 +227,13 @@ public void updateDefaultDependencies_olderVersionsAreUpdated()
228227
JacksonUtils.createObjectNode());
229228
packageJson.set(NodeUpdater.DEV_DEPENDENCIES,
230229
JacksonUtils.createObjectNode());
231-
((ObjectNode) packageJson.get(NodeUpdater.DEV_DEPENDENCIES)).put("glob",
232-
"7.0.0");
230+
((ObjectNode) packageJson.get(NodeUpdater.DEV_DEPENDENCIES))
231+
.put("typescript", "1.0.0");
233232
nodeUpdater.updateDefaultDependencies(packageJson);
234233

235-
Assert.assertEquals("11.0.3", packageJson
236-
.get(NodeUpdater.DEV_DEPENDENCIES).get("glob").asString());
234+
Assert.assertNotEquals("1.0.0",
235+
packageJson.get(NodeUpdater.DEV_DEPENDENCIES).get("typescript")
236+
.stringValue());
237237
}
238238

239239
@Test // #6907 test when user has set newer versions

0 commit comments

Comments
 (0)