From 45229588c2a63e8e8013e93e3b46d50a85b9ddaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjeramysoucy=E2=80=9D?= Date: Thu, 31 Oct 2024 18:05:13 +0100 Subject: [PATCH 1/5] Moves glob to dev deps --- package.json | 2 +- .../console/server/services/spec_definitions_service.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a6921604af4c3..e01a8427f03eb 100644 --- a/package.json +++ b/package.json @@ -241,7 +241,6 @@ "get-port": "^5.0.0", "getopts": "^2.2.5", "getos": "^3.1.0", - "glob": "^7.1.2", "glob-all": "^3.2.1", "globby": "^11.0.3", "handlebars": "4.7.7", @@ -720,6 +719,7 @@ "find-cypress-specs": "^1.35.1", "form-data": "^4.0.0", "geckodriver": "^4.4.2", + "glob": "^7.1.2", "glob-watcher": "5.0.3", "gulp": "4.0.2", "gulp-babel": "^8.0.0", diff --git a/src/plugins/console/server/services/spec_definitions_service.ts b/src/plugins/console/server/services/spec_definitions_service.ts index e0af9422666af..b5515ed1308fa 100644 --- a/src/plugins/console/server/services/spec_definitions_service.ts +++ b/src/plugins/console/server/services/spec_definitions_service.ts @@ -7,7 +7,7 @@ */ import _, { merge } from 'lodash'; -import glob from 'glob'; +import globby from 'globby'; import { basename, join, resolve } from 'path'; import { readFileSync } from 'fs'; @@ -115,8 +115,8 @@ export class SpecDefinitionsService { } private loadJSONSpecInDir(dirname: string) { - const generatedFiles = glob.sync(join(dirname, 'generated', '*.json')); - const overrideFiles = glob.sync(join(dirname, 'overrides', '*.json')); + const generatedFiles = globby.sync(join(dirname, 'generated', '*.json')); + const overrideFiles = globby.sync(join(dirname, 'overrides', '*.json')); return generatedFiles.reduce((acc, file) => { const overrideFile = overrideFiles.find((f) => basename(f) === basename(file)); From 686a3e6522a23dc7c73b83ec1275145fe5b53817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjeramysoucy=E2=80=9D?= Date: Mon, 4 Nov 2024 14:04:00 +0100 Subject: [PATCH 2/5] Replaces glob with globby in two more files --- packages/kbn-spec-to-console/bin/spec_to_console.js | 4 ++-- .../vis_types/timelion/server/lib/load_functions.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/kbn-spec-to-console/bin/spec_to_console.js b/packages/kbn-spec-to-console/bin/spec_to_console.js index 21922054696f1..f50e8b5015d8f 100644 --- a/packages/kbn-spec-to-console/bin/spec_to_console.js +++ b/packages/kbn-spec-to-console/bin/spec_to_console.js @@ -9,7 +9,7 @@ const fs = require('fs'); const path = require('path'); const program = require('commander'); -const glob = require('glob'); +const globby = require('globby'); const chalk = require('chalk'); const packageJSON = require('../package.json'); @@ -26,7 +26,7 @@ if (!program.glob) { process.exit(1); } -const files = glob.sync(program.glob); +const files = globby.sync(program.glob); const totalFilesCount = files.length; let convertedFilesCount = 0; diff --git a/src/plugins/vis_types/timelion/server/lib/load_functions.js b/src/plugins/vis_types/timelion/server/lib/load_functions.js index 890c5b1df5cdc..cb765c1cb7dca 100644 --- a/src/plugins/vis_types/timelion/server/lib/load_functions.js +++ b/src/plugins/vis_types/timelion/server/lib/load_functions.js @@ -7,7 +7,7 @@ */ import _ from 'lodash'; -import glob from 'glob'; +import globby from 'globby'; import path from 'path'; import processFunctionDefinition from './process_function_definition'; @@ -18,7 +18,7 @@ export default function (directory) { // Get a list of all files and use the filename as the object key const files = _.map( - glob + globby .sync(path.resolve(__dirname, '../' + directory + '/*.js')) .filter((filename) => !filename.includes('.test')), function (file) { @@ -28,7 +28,9 @@ export default function (directory) { ); // Get a list of all directories with an index.js, use the directory name as the key in the object - const directories = _.chain(glob.sync(path.resolve(__dirname, '../' + directory + '/*/index.js'))) + const directories = _.chain( + globby.sync(path.resolve(__dirname, '../' + directory + '/*/index.js')) + ) .map(function (file) { const parts = file.split('/'); const name = parts[parts.length - 2]; From 2afa705a032710a17fc3f7237e56a0ba1efa33cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjeramysoucy=E2=80=9D?= Date: Mon, 4 Nov 2024 18:11:48 +0100 Subject: [PATCH 3/5] Update from review feedback --- .../vis_types/timelion/server/lib/load_functions.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/vis_types/timelion/server/lib/load_functions.js b/src/plugins/vis_types/timelion/server/lib/load_functions.js index cb765c1cb7dca..70014be1816f4 100644 --- a/src/plugins/vis_types/timelion/server/lib/load_functions.js +++ b/src/plugins/vis_types/timelion/server/lib/load_functions.js @@ -8,7 +8,6 @@ import _ from 'lodash'; import globby from 'globby'; -import path from 'path'; import processFunctionDefinition from './process_function_definition'; export default function (directory) { @@ -19,7 +18,7 @@ export default function (directory) { // Get a list of all files and use the filename as the object key const files = _.map( globby - .sync(path.resolve(__dirname, '../' + directory + '/*.js')) + .sync('../' + directory + '/*.js', { cwd: __dirname }) .filter((filename) => !filename.includes('.test')), function (file) { const name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.')); @@ -29,7 +28,9 @@ export default function (directory) { // Get a list of all directories with an index.js, use the directory name as the key in the object const directories = _.chain( - globby.sync(path.resolve(__dirname, '../' + directory + '/*/index.js')) + globby.sync('../' + directory + '/*/index.js', { + cwd: __dirname, + }) ) .map(function (file) { const parts = file.split('/'); From 3a7b34cb96278cd376578f9d7dab9b0210264c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjeramysoucy=E2=80=9D?= Date: Tue, 5 Nov 2024 09:37:12 +0100 Subject: [PATCH 4/5] Adds normalizePath to spec def service --- src/plugins/console/server/services/spec_definitions_service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/console/server/services/spec_definitions_service.ts b/src/plugins/console/server/services/spec_definitions_service.ts index b5515ed1308fa..64900d6b670e1 100644 --- a/src/plugins/console/server/services/spec_definitions_service.ts +++ b/src/plugins/console/server/services/spec_definitions_service.ts @@ -10,6 +10,7 @@ import _, { merge } from 'lodash'; import globby from 'globby'; import { basename, join, resolve } from 'path'; import { readFileSync } from 'fs'; +import normalizePath from 'normalize-path'; import { jsSpecLoaders } from '../lib'; From 2377f754fc1d37b7f788b3d1766e16d842f0a6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjeramysoucy=E2=80=9D?= Date: Tue, 5 Nov 2024 09:42:38 +0100 Subject: [PATCH 5/5] Really added path normalization --- .../console/server/services/spec_definitions_service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/console/server/services/spec_definitions_service.ts b/src/plugins/console/server/services/spec_definitions_service.ts index 64900d6b670e1..952e2947a07e8 100644 --- a/src/plugins/console/server/services/spec_definitions_service.ts +++ b/src/plugins/console/server/services/spec_definitions_service.ts @@ -116,8 +116,9 @@ export class SpecDefinitionsService { } private loadJSONSpecInDir(dirname: string) { - const generatedFiles = globby.sync(join(dirname, 'generated', '*.json')); - const overrideFiles = globby.sync(join(dirname, 'overrides', '*.json')); + // we need to normalize paths otherwise they don't work on windows, see https://github.com/elastic/kibana/issues/151032 + const generatedFiles = globby.sync(normalizePath(join(dirname, 'generated', '*.json'))); + const overrideFiles = globby.sync(normalizePath(join(dirname, 'overrides', '*.json'))); return generatedFiles.reduce((acc, file) => { const overrideFile = overrideFiles.find((f) => basename(f) === basename(file));