-
Notifications
You must be signed in to change notification settings - Fork 1
v10.0.9 #38
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v10.0.9 #38
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,19 @@ const path = require('path'); | |
| const fs = require('fs'); | ||
| const { getComponentsRoot, getComponentTypes } = require('./vnextConfig'); | ||
|
|
||
| /** | ||
| * Builds a glob pattern with forward slashes. | ||
| * glob treats backslashes as escape characters, so on Windows a pattern built | ||
| * with path.join (which uses "\") breaks "**" recursion and nested files are | ||
| * never matched. Always feed glob forward-slash separators. | ||
| * @param {string} dir - Base directory | ||
| * @param {string} suffix - Glob suffix, e.g. "**\/*.json" | ||
| * @returns {string} Forward-slash glob pattern | ||
| */ | ||
| function toGlobPattern(dir, suffix) { | ||
|
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Normalize backslashes in The example Suggested implementation: * @param {string} suffix - Glob suffix, e.g. "**/*.json"function toGlobPattern(dir, suffix) {
// Normalize all path separators (including any backslashes in `suffix`) to forward slashes
return path.join(dir, suffix).replace(/\\/g, '/');
} |
||
| return path.join(dir, suffix).split(path.sep).join('/'); | ||
| } | ||
|
|
||
| /** | ||
| * Discovers component folders based on vnext.config.json paths | ||
| * Only scans folders defined in paths, ignores everything else | ||
|
|
@@ -35,8 +48,8 @@ async function discoverComponents(projectRoot) { | |
| * @returns {Promise<string[]>} JSON file paths | ||
| */ | ||
| async function findJsonInComponent(componentDir) { | ||
| const pattern = path.join(componentDir, '**/*.json'); | ||
| const pattern = toGlobPattern(componentDir, '**/*.json'); | ||
|
|
||
| const files = await glob(pattern, { | ||
| ignore: [ | ||
| '**/.meta/**', | ||
|
|
@@ -90,7 +103,7 @@ async function findAllCsxInComponents(projectRoot) { | |
| // Only scan folders that were discovered from paths | ||
| for (const [type, componentDir] of Object.entries(discovered)) { | ||
| if (componentDir) { | ||
| const pattern = path.join(componentDir, '**/*.csx'); | ||
| const pattern = toGlobPattern(componentDir, '**/*.csx'); | ||
| const files = await glob(pattern, { | ||
| ignore: [ | ||
| '**/.meta/**', | ||
|
|
@@ -157,6 +170,7 @@ function detectComponentTypeFromPath(filePath, componentTypes) { | |
| } | ||
|
|
||
| module.exports = { | ||
| toGlobPattern, | ||
| discoverComponents, | ||
| findJsonInComponent, | ||
| findAllJsonFiles, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
obj.encodingis not a string (for example, if it is a boolean, number, or null), calling.toUpperCase()directly will throw aTypeErrorand crash the process.\n\nTo prevent runtime crashes when processing unexpected JSON structures, we should defensively check thatobj.encodingis a non-empty string before calling string methods on it.