Skip to content

Commit 370ee45

Browse files
delanniniros1
authored andcommitted
Normalize resulting paths to unix paths after glob usage (#236044)
## Summary Fixes #236004 After #233481 the resulting glob paths are yielded as windows paths, but probably processed as unix paths (since `globby` always returned paths with unix separators). This PR applies a normalization on resulting paths.
1 parent fce788e commit 370ee45

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

src/core/packages/i18n/server-internal/src/get_translation_paths.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import { resolve, dirname } from 'path';
1111
import { readFile, glob } from 'fs/promises';
12+
import normalizePath from 'normalize-path';
1213

1314
interface I18NRCFileStructure {
1415
translations?: string[];
@@ -21,7 +22,7 @@ export async function getTranslationPaths({ cwd, nested }: { cwd: string; nested
2122
const translationPaths: string[] = [];
2223

2324
for await (const entry of glob(globPattern, { cwd })) {
24-
const entryFullPath = resolve(cwd, entry);
25+
const entryFullPath = resolve(cwd, normalizePath(entry));
2526
const pluginBasePath = dirname(entryFullPath);
2627
try {
2728
const content = await readFile(entryFullPath, 'utf8');

src/platform/plugins/private/vis_types/timelion/server/lib/load_functions.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@
99

1010
import _ from 'lodash';
1111
import { globSync } from 'fs';
12+
import normalizePath from 'normalize-path';
1213
import processFunctionDefinition from './process_function_definition';
1314

1415
export default function (directory) {
1516
function getTuple(directory, name) {
16-
return [name, require('../' + directory + '/' + name)]; // eslint-disable-line import/no-dynamic-require
17+
return [name, require(`../${directory}/${name}`)]; // eslint-disable-line import/no-dynamic-require
1718
}
1819

1920
// Get a list of all files and use the filename as the object key
2021
const files = _.map(
21-
globSync('../' + directory + '/*.js', { cwd: __dirname }).filter(
22-
(filename) => !filename.includes('.test')
23-
),
22+
globSync(`../${directory}/*.js`, { cwd: __dirname })
23+
.filter((filename) => !filename.includes('.test'))
24+
.map((p) => normalizePath(p)),
25+
2426
function (file) {
2527
const name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.'));
2628
return getTuple(directory, name);
@@ -29,12 +31,12 @@ export default function (directory) {
2931

3032
// Get a list of all directories with an index.js, use the directory name as the key in the object
3133
const directories = _.chain(
32-
globSync('../' + directory + '/*/index.js', {
34+
globSync(`../${directory}/*/index.js`, {
3335
cwd: __dirname,
3436
})
3537
)
3638
.map(function (file) {
37-
const parts = file.split('/');
39+
const parts = normalizePath(file).split('/');
3840
const name = parts[parts.length - 2];
3941
return getTuple(directory, name);
4042
})

src/platform/plugins/shared/console/server/services/spec_definitions_service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ export class SpecDefinitionsService {
110110
// we need to normalize paths otherwise they don't work on windows, see https://github.com/elastic/kibana/issues/151032
111111
const generatedFiles = globSync(
112112
normalizePath(join(AUTOCOMPLETE_DEFINITIONS_FOLDER, GENERATED_SUBFOLDER, '*.json'))
113-
);
113+
).map((p) => normalizePath(p));
114114
const overrideFiles = globSync(
115115
normalizePath(join(AUTOCOMPLETE_DEFINITIONS_FOLDER, OVERRIDES_SUBFOLDER, '*.json'))
116-
);
116+
).map((p) => normalizePath(p));
117117
const manualFiles = globSync(
118118
normalizePath(join(AUTOCOMPLETE_DEFINITIONS_FOLDER, MANUAL_SUBFOLDER, '*.json'))
119-
);
119+
).map((p) => normalizePath(p));
120120

121121
// definitions files contain only 1 definition per endpoint name { "endpointName": { endpointDescription }}
122122
// all endpoints need to be merged into 1 object with endpoint names as keys and endpoint definitions as values

x-pack/solutions/security/plugins/elastic_assistant/server/lib/langchain/content_loaders/defend_insights_loader.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import type { Document } from 'langchain/document';
99
import type { Logger } from '@kbn/core/server';
1010
import type { Metadata } from '@kbn/elastic-assistant-common';
11-
import { glob } from 'fs/promises';
11+
import { globSync } from 'fs';
1212
import { DirectoryLoader } from 'langchain/document_loaders/fs/directory';
1313
import { TextLoader } from 'langchain/document_loaders/fs/text';
1414
import { resolve } from 'path';
1515
import pMap from 'p-map';
16+
import normalizePath from 'normalize-path';
1617

1718
import type { AIAssistantKnowledgeBaseDataClient } from '../../../ai_assistant_data_clients/knowledge_base';
1819
import { DEFEND_INSIGHTS_POLICY_RESPONSE_FAILURE } from '../../../routes/knowledge_base/constants';
@@ -104,12 +105,9 @@ export const getDefendInsightsDocsCount = async ({
104105
logger: Logger;
105106
}): Promise<number> => {
106107
try {
107-
// @ts-expect-error missing type for Array.fromAsync
108-
const files = await Array.fromAsync(
109-
glob('**/*.{md,txt}', {
110-
cwd: resolve(__dirname, '../../../knowledge_base/defend_insights'),
111-
})
112-
);
108+
const files = globSync('**/*.{md,txt}', {
109+
cwd: resolve(__dirname, '../../../knowledge_base/defend_insights'),
110+
}).map((p) => normalizePath(p));
113111

114112
return files.length;
115113
} catch (e) {

x-pack/solutions/security/plugins/elastic_assistant/server/lib/langchain/content_loaders/security_labs_loader.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* 2.0.
66
*/
77

8-
import { glob } from 'fs/promises';
8+
import { globSync } from 'fs';
9+
import normalizePath from 'normalize-path';
910
import type { Logger } from '@kbn/core/server';
1011
import { DirectoryLoader } from 'langchain/document_loaders/fs/directory';
1112
import { resolve } from 'path';
@@ -73,12 +74,9 @@ export const loadSecurityLabs = async (
7374

7475
export const getSecurityLabsDocsCount = async ({ logger }: { logger: Logger }): Promise<number> => {
7576
try {
76-
// @ts-expect-error incorrect type for Array.fromAsync
77-
const files = await Array.fromAsync(
78-
glob(ENCODED_FILE_MICROMATCH_PATTERN, {
79-
cwd: resolve(__dirname, '../../../knowledge_base/security_labs'),
80-
})
81-
);
77+
const files = globSync(ENCODED_FILE_MICROMATCH_PATTERN, {
78+
cwd: resolve(__dirname, '../../../knowledge_base/security_labs'),
79+
}).map((p) => normalizePath(p));
8280

8381
return files.length;
8482
} catch (e) {

0 commit comments

Comments
 (0)