Skip to content

Commit 1203fdc

Browse files
committed
[deps] Update vega to 6.x (#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 # src/platform/packages/shared/kbn-test/jest-preset.js
1 parent 0d0b873 commit 1203fdc

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
@@ -2096,8 +2096,10 @@ x-pack/platform/test/plugin_api_integration/test_suites/platform/ @elastic/kiban
20962096
/config/serverless.security.essentials.yml @elastic/security-solution @elastic/kibana-security
20972097
/config/serverless.security.complete.yml @elastic/security-solution @elastic/kibana-security
20982098
/typings/ @elastic/kibana-core
2099+
/typings/vega/ @elastic/kibana-visualizations
20992100
/src/platform/test/analytics @elastic/kibana-core
21002101
/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.kbn_i18n_react.js @elastic/kibana-core
2102+
/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.vega.js @elastic/kibana-visualizations
21012103
/x-pack/platform/test/saved_objects_field_count/ @elastic/kibana-core
21022104
/x-pack/platform/test/serverless/**/test_suites/saved_objects_management/ @elastic/kibana-core
21032105
/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
"@a2a-js/sdk": "^0.3.0",
@@ -1418,12 +1415,12 @@
14181415
"usng.js": "^0.4.5",
14191416
"utility-types": "^3.10.0",
14201417
"uuid": "11.1.0",
1421-
"vega": "^5.33.0",
1422-
"vega-interpreter": "1.2.1",
1423-
"vega-lite": "^5.21.0",
1424-
"vega-schema-url-parser": "^2.2.0",
1425-
"vega-spec-injector": "^0.0.2",
1426-
"vega-tooltip": "^0.34.0",
1418+
"vega": "6.2.0",
1419+
"vega-interpreter": "2.2.1",
1420+
"vega-lite": "6.4.1",
1421+
"vega-schema-url-parser": "3.0.2",
1422+
"vega-spec-injector": "0.0.2",
1423+
"vega-tooltip": "1.1.0",
14271424
"vinyl": "^3.0.0",
14281425
"wellknown": "^0.5.0",
14291426
"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 = (api) => ({
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
@@ -119,10 +119,7 @@ export function getWebpackConfig(
119119
// no parse rules for a few known large packages which have no require() statements
120120
// or which have require() statements that should be ignored because the file is
121121
// already bundled with all its necessary dependencies
122-
noParse: [
123-
/[\/\\]node_modules[\/\\]lodash[\/\\]index\.js$/,
124-
/[\/\\]node_modules[\/\\]vega[\/\\]build-es5[\/\\]vega\.js$/,
125-
],
122+
noParse: [/[\/\\]node_modules[\/\\]lodash[\/\\]index\.js$/],
126123

127124
rules: [
128125
{
@@ -299,7 +296,6 @@ export function getWebpackConfig(
299296
extensions: ['.js', '.ts', '.tsx', '.json'],
300297
mainFields: ['browser', 'module', 'main'],
301298
alias: {
302-
vega: Path.resolve(worker.repoRoot, 'node_modules/vega/build-es5/vega.js'),
303299
'react-dom$': 'react-dom/profiling',
304300
'scheduler/tracing': 'scheduler/tracing-profiling',
305301
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
@@ -167,6 +167,14 @@ export class ImportResolver {
167167
return Path.resolve(REPO_ROOT, `node_modules/zod/v3/index.cjs`);
168168
}
169169

170+
if (req.startsWith('vega-lite')) {
171+
return Path.resolve(REPO_ROOT, `node_modules/vega-lite/build`);
172+
}
173+
174+
if (req.startsWith('vega-tooltip')) {
175+
return Path.resolve(REPO_ROOT, `node_modules/vega-tooltip/build`);
176+
}
177+
170178
// turn root-relative paths into relative paths
171179
if (
172180
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$/,
@@ -60,7 +56,6 @@ export default ({ config: storybookConfig }: { config: Configuration }) => {
6056
mainFields: ['browser', 'main'],
6157
alias: {
6258
core_styles: resolve(REPO_ROOT, 'src/core/public/index.scss'),
63-
vega: resolve(REPO_ROOT, 'node_modules/vega/build-es5/vega.js'),
6459
},
6560
},
6661
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
@@ -79,6 +79,7 @@ module.exports = {
7979
'<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.eui.js',
8080
'<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/react_testing_library.js',
8181
'<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.kbn_i18n_react.js',
82+
'<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/mocks.vega.js',
8283
process.env.CI
8384
? '<rootDir>/src/platform/packages/shared/kbn-test/src/jest/setup/disable_console_logs.js'
8485
: [],
@@ -124,7 +125,7 @@ module.exports = {
124125
transformIgnorePatterns: [
125126
// ignore all node_modules except monaco-editor, monaco-yaml which requires babel transforms to handle dynamic import()
126127
// since ESM modules are not natively supported in Jest yet (https://github.com/facebook/jest/issues/4842)
127-
'[/\\\\]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$',
128+
'[/\\\\]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$',
128129
'packages/kbn-pm/dist/index.js',
129130
'[/\\\\]node_modules(?![\\/\\\\](langchain|langsmith|@langchain))/dist/[/\\\\].+\\.js$',
130131
'[/\\\\]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)