Skip to content

Commit 21f3c20

Browse files
committed
[deps] Update vega to 6.x (elastic#238618)
## Summary Update Vega dependencies to 6.x. This pull request updates the project's Vega and Vega-Lite dependencies to their latest major versions. **Dependency Upgrades and Import Handling** - Upgraded `vega`, `vega-lite`, `vega-interpreter`, `vega-tooltip`, and related libraries to their latest major versions in `package.json`, and updated their import paths throughout the codebase. - Removed legacy Webpack and Storybook configuration for the old `vega` build, including `noParse` rules and aliases, and updated the import resolver to point to the new `vega-lite` and `vega-tooltip` build directories. **Testing and TypeScript Support** - Added a Jest setup mock for `vega` and `vega-lite` to ensure tests run correctly with the new versions, and updated Jest transform ignore patterns to support new Vega-related packages. - Updated `tsconfig.base.json` to include type definitions for `vega-lite` and `vega-tooltip`. **Babel and Build Tools** - Added `@babel/plugin-syntax-import-attributes` to dependencies and Babel preset to enable the new import attributes syntax. **Test Snapshots** - Updated Vega visualization test snapshots to reflect the new rendering/output from upgraded dependencies. --------- Co-authored-by: Tiago Costa <tiago.costa@elastic.co> (cherry picked from commit d8c23ae) # Conflicts: # package.json # packages/kbn-babel-preset/common_preset.js # src/platform/packages/shared/kbn-test/jest-preset.js
1 parent 03fdd40 commit 21f3c20

16 files changed

Lines changed: 457 additions & 359 deletions

File tree

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,8 +2020,10 @@ x-pack/platform/plugins/shared/ml/server/models/data_recognizer/modules/security
20202020
/config/serverless.security.essentials.yml @elastic/security-solution @elastic/kibana-security
20212021
/config/serverless.security.complete.yml @elastic/security-solution @elastic/kibana-security
20222022
/typings/ @elastic/kibana-core
2023+
/typings/vega/ @elastic/kibana-visualizations
20232024
/src/platform/test/analytics @elastic/kibana-core
20242025
/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.kbn_i18n_react.js @elastic/kibana-core
2026+
/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.vega.js @elastic/kibana-visualizations
20252027
/x-pack/platform/test/saved_objects_field_count/ @elastic/kibana-core
20262028
/x-pack/platform/test/serverless/**/test_suites/saved_objects_management/ @elastic/kibana-core
20272029
/x-pack/platform/test/serverless/api_integration/test_suites/core/ @elastic/kibana-core

package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@
105105
"@xstate5/react/**/xstate": "^5.19.2",
106106
"apache-arrow": "20.x - 21.x",
107107
"globby/fast-glob": "^3.3.2",
108-
"pkce-challenge": "3.1.0",
109-
"vega-expression": "5.2.1",
110-
"vega-interpreter": "1.2.1",
111-
"vega-util": "1.17.4"
108+
"pkce-challenge": "3.1.0"
112109
},
113110
"dependencies": {
114111
"@apidevtools/json-schema-ref-parser": "^14.1.1",
@@ -1360,12 +1357,12 @@
13601357
"usng.js": "^0.4.5",
13611358
"utility-types": "^3.10.0",
13621359
"uuid": "11.1.0",
1363-
"vega": "^5.33.0",
1364-
"vega-interpreter": "1.2.1",
1365-
"vega-lite": "^5.21.0",
1366-
"vega-schema-url-parser": "^2.2.0",
1367-
"vega-spec-injector": "^0.0.2",
1368-
"vega-tooltip": "^0.34.0",
1360+
"vega": "6.2.0",
1361+
"vega-interpreter": "2.2.1",
1362+
"vega-lite": "6.4.1",
1363+
"vega-schema-url-parser": "3.0.2",
1364+
"vega-spec-injector": "0.0.2",
1365+
"vega-tooltip": "1.1.0",
13691366
"vinyl": "^3.0.0",
13701367
"wellknown": "^0.5.0",
13711368
"xml2js": "^0.6.2",

packages/kbn-babel-preset/common_preset.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
*/
99

1010
module.exports = () => ({
11+
// Enables import-attributes syntax on imports
12+
generatorOpts: {
13+
importAttributesKeyword: 'with',
14+
},
1115
presets: [
1216
// plugins always run before presets, but in this case we need the
1317
// @babel/preset-typescript preset to run first so we have to move

packages/kbn-eslint-config/javascript.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ module.exports = {
2929
ecmaVersion: 2018,
3030
requireConfigFile: false,
3131
babelOptions: {
32-
presets: ['@kbn/babel-preset/node_preset']
32+
presets: ['@kbn/babel-preset/node_preset'],
33+
parserOpts: {
34+
plugins: ['importAttributes']
35+
}
3336
},
3437
},
3538

packages/kbn-optimizer/src/worker/webpack.config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ export function getWebpackConfig(
118118
// no parse rules for a few known large packages which have no require() statements
119119
// or which have require() statements that should be ignored because the file is
120120
// already bundled with all its necessary dependencies
121-
noParse: [
122-
/[\/\\]node_modules[\/\\]lodash[\/\\]index\.js$/,
123-
/[\/\\]node_modules[\/\\]vega[\/\\]build-es5[\/\\]vega\.js$/,
124-
],
121+
noParse: [/[\/\\]node_modules[\/\\]lodash[\/\\]index\.js$/],
125122

126123
rules: [
127124
{
@@ -294,7 +291,6 @@ export function getWebpackConfig(
294291
extensions: ['.js', '.ts', '.tsx', '.json'],
295292
mainFields: ['browser', 'module', 'main'],
296293
alias: {
297-
vega: Path.resolve(worker.repoRoot, 'node_modules/vega/build-es5/vega.js'),
298294
'react-dom$': 'react-dom/profiling',
299295
'scheduler/tracing': 'scheduler/tracing-profiling',
300296
buffer: [

src/platform/packages/private/kbn-import-resolver/src/import_resolver.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ export class ImportResolver {
165165
return Path.resolve(REPO_ROOT, `node_modules/zod/v3/index.cjs`);
166166
}
167167

168+
if (req.startsWith('vega-lite')) {
169+
return Path.resolve(REPO_ROOT, `node_modules/vega-lite/build`);
170+
}
171+
172+
if (req.startsWith('vega-tooltip')) {
173+
return Path.resolve(REPO_ROOT, `node_modules/vega-tooltip/build`);
174+
}
175+
168176
// turn root-relative paths into relative paths
169177
if (
170178
req.startsWith('src/') ||

src/platform/packages/shared/kbn-storybook/src/webpack.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ export default ({ config: storybookConfig }: { config: Configuration }) => {
2626
},
2727
externals,
2828
module: {
29-
// no parse rules for a few known large packages which have no require() statements
30-
// or which have require() statements that should be ignored because the file is
31-
// already bundled with all its necessary dependencies
32-
noParse: [/[\/\\]node_modules[\/\\]vega[\/\\]build-es5[\/\\]vega\.js$/],
3329
rules: [
3430
{
3531
test: /\.mjs$/,
@@ -54,7 +50,6 @@ export default ({ config: storybookConfig }: { config: Configuration }) => {
5450
mainFields: ['browser', 'main'],
5551
alias: {
5652
core_styles: resolve(REPO_ROOT, 'src/core/public/index.scss'),
57-
vega: resolve(REPO_ROOT, 'node_modules/vega/build-es5/vega.js'),
5853
},
5954
},
6055
stats: 'errors-only',

src/platform/packages/shared/kbn-test/jest-preset.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module.exports = {
7676
'<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.eui.js',
7777
'<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/react_testing_library.js',
7878
'<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.kbn_i18n_react.js',
79+
'<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.vega.js',
7980
process.env.CI
8081
? '<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/disable_console_logs.js'
8182
: [],
@@ -119,7 +120,7 @@ module.exports = {
119120
transformIgnorePatterns: [
120121
// ignore all node_modules except monaco-editor, monaco-yaml which requires babel transforms to handle dynamic import()
121122
// since ESM modules are not natively supported in Jest yet (https://github.com/facebook/jest/issues/4842)
122-
'[/\\\\]node_modules(?![\\/\\\\](byte-size|monaco-editor|monaco-yaml|monaco-languageserver-types|monaco-marker-data-provider|monaco-worker-manager|vscode-languageserver-types|d3-interpolate|d3-color|langchain|langsmith|@cfworker|gpt-tokenizer|flat|@langchain|eventsource-parser|fast-check|@fast-check/jest|@assemblyscript|quickselect|rbush))[/\\\\].+\\.js$',
123+
'[/\\\\]node_modules(?![\\/\\\\](byte-size|monaco-editor|monaco-yaml|monaco-languageserver-types|monaco-marker-data-provider|monaco-worker-manager|vscode-languageserver-types|d3-interpolate|d3-color|langchain|langsmith|@cfworker|gpt-tokenizer|flat|@langchain|eventsource-parser|fast-check|@fast-check/jest|@assemblyscript|quickselect|rbush|vega-interpreter|vega-util|vega-tooltip))[/\\\\].+\\.js$',
123124
'packages/kbn-pm/dist/index.js',
124125
'[/\\\\]node_modules(?![\\/\\\\](langchain|langsmith|@langchain))/dist/[/\\\\].+\\.js$',
125126
'[/\\\\]node_modules(?![\\/\\\\](langchain|langsmith|@langchain))/dist/util/[/\\\\].+\\.js$',
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
/* eslint-env jest */
11+
12+
const fs = require('fs');
13+
const vm = require('vm');
14+
const path = require('path');
15+
16+
let cached = null;
17+
18+
const loadVegaAndVegaLite = () => {
19+
if (cached) return cached;
20+
21+
const sandbox = {
22+
window: {},
23+
globalThis: {},
24+
structuredClone: (obj) => JSON.parse(JSON.stringify(obj)),
25+
};
26+
27+
// vega
28+
const vegaPath = path.resolve('node_modules/vega/build/vega.min.js');
29+
const vegaCode = fs.readFileSync(vegaPath, 'utf8');
30+
vm.createContext(sandbox);
31+
vm.runInContext(vegaCode, sandbox);
32+
33+
sandbox.window.vega = sandbox.globalThis.vega = sandbox.window.vega || sandbox.globalThis.vega;
34+
35+
// vega-lite
36+
const litePath = path.resolve('node_modules/vega-lite/build/vega-lite.min.js');
37+
const liteCode = fs.readFileSync(litePath, 'utf8');
38+
vm.runInContext(liteCode, sandbox);
39+
40+
cached = {
41+
vega: sandbox.window.vega || sandbox.globalThis.vega,
42+
vegaLite: sandbox.window.vegaLite || sandbox.globalThis.vegaLite,
43+
};
44+
45+
// both Vega and Vega-Lite
46+
return cached;
47+
};
48+
49+
jest.mock('vega', () => {
50+
const { vega } = loadVegaAndVegaLite();
51+
return { ...vega };
52+
});
53+
54+
jest.mock('vega-lite', () => {
55+
const { vegaLite } = loadVegaAndVegaLite();
56+
return { ...vegaLite };
57+
});

src/platform/plugins/private/vis_types/vega/public/__snapshots__/vega_visualization.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)