Skip to content

Commit 6b208d8

Browse files
authored
Migrate to ESM & update the Vega libraries (#214)
* chore(deps): bump vega-expression and vega-lite Bumps [vega-expression](https://github.com/vega/vega) to 5.2.1 and updates ancestor dependency [vega-lite](https://github.com/vega/vega-lite). These dependencies need to be updated together. Updates `vega-expression` from 5.2.0 to 5.2.1 - [Release notes](https://github.com/vega/vega/releases) - [Commits](https://github.com/vega/vega/commits) Updates `vega-lite` from 5.23.0 to 6.4.1 - [Release notes](https://github.com/vega/vega-lite/releases) - [Changelog](https://github.com/vega/vega-lite/blob/main/CHANGELOG.md) - [Commits](vega/vega-lite@v5.23.0...v6.4.1) --- updated-dependencies: - dependency-name: vega-expression dependency-version: 5.2.1 dependency-type: indirect - dependency-name: vega-lite dependency-version: 6.4.1 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
1 parent 1cc979d commit 6b208d8

File tree

178 files changed

+4437
-3263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+4437
-3263
lines changed

.eslintrc.js renamed to .eslintrc.cjs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = {
4747
'@typescript-eslint/no-explicit-any': 'error',
4848
'@typescript-eslint/no-non-null-assertion': 'off',
4949
'no-unused-vars': 'off',
50-
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '_\\w*' }],
50+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '_\\w*', varsIgnorePattern: '_\\w*' }],
5151
'no-use-before-define': 'off',
5252
'@typescript-eslint/no-use-before-define': [
5353
'error',
@@ -74,7 +74,14 @@ module.exports = {
7474
'import/no-unresolved': [
7575
'error',
7676
{
77-
ignore: ['monaco-editor', 'vscode', 'react-error-boundary']
77+
ignore: [
78+
'monaco-editor',
79+
'vscode',
80+
'react-error-boundary',
81+
'vega-lite',
82+
'vega-embed',
83+
'why-is-node-running'
84+
]
7885
}
7986
],
8087
'import/prefer-default-export': 'off',
@@ -225,18 +232,32 @@ module.exports = {
225232
'import/no-restricted-paths': ['off']
226233
}
227234
},
235+
{
236+
files: ['src/kernels/**/*.ts'],
237+
rules: {
238+
'@typescript-eslint/no-restricted-imports': 'off'
239+
}
240+
},
241+
{
242+
files: ['src/notebooks/**/*.ts', 'src/webviews/**/*.ts'],
243+
rules: {
244+
'@typescript-eslint/no-restricted-imports': 'off'
245+
}
246+
},
228247
{
229248
files: ['**/*.test.ts'],
230249
rules: {
231250
'@typescript-eslint/no-explicit-any': 'off',
232-
'@typescript-eslint/no-restricted-imports': 'off'
251+
'@typescript-eslint/no-restricted-imports': 'off',
252+
'@typescript-eslint/no-empty-function': 'off'
233253
}
234254
},
235255
{
236256
files: ['src/test/**/*.ts'],
237257
rules: {
238258
'@typescript-eslint/no-explicit-any': 'off',
239-
'@typescript-eslint/no-restricted-imports': 'off'
259+
'@typescript-eslint/no-restricted-imports': 'off',
260+
'@typescript-eslint/no-empty-function': 'off'
240261
}
241262
},
242263
{

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ tmp
7373
vscode.d.ts
7474
vscode.proposed.*.d.ts
7575
xunit-test-results.xml
76+
tsconfig.tsbuildinfo
File renamed without changes.

build/.mocha-multi-reporters.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"reporterEnabled": "./build/ci/scripts/spec_with_pid,mocha-junit-reporter",
2+
"reporterEnabled": "./build/ci/scripts/spec_with_pid.js,mocha-junit-reporter",
33
"mochaJunitReporterReporterOptions": {
44
"includePending": true
55
}

build/.mocha.unittests.js.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"spec": "./out/**/*.unit.test.js",
3-
"require": ["source-map-support/register", "out/test/unittests.js"],
4-
"reporter": "mocha-multi-reporters",
5-
"reporter-option": "configFile=build/.mocha-multi-reporters.config",
3+
"loader": ["./build/mocha-esm-loader.js"],
4+
"require": ["./out/test/unittests.js"],
5+
"reporter": "spec",
66
"ui": "tdd",
77
"recursive": true,
8-
"colors": true
8+
"colors": true,
9+
"node-option": ["no-warnings=ExperimentalWarning", "loader=./build/mocha-esm-loader.js"]
910
}

build/.mocha.unittests.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"spec": "./out/**/*.unit.test.js",
3-
"require": ["out/test/unittests.js"],
3+
"loader": ["./build/mocha-esm-loader.js"],
44
"reporter": "mocha-multi-reporters",
55
"reporter-option": "configFile=build/.mocha-multi-reporters.config",
66
"ui": "tdd",
77
"recursive": true,
8-
"colors": true
8+
"colors": true,
9+
"node-option": ["--no-warnings=ExperimentalWarning"]
910
}

build/.mocha.unittests.ts.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"require": ["ts-node/register", "out/test/unittests.js"],
2+
"loader": ["ts-node/esm", "./build/mocha-esm-loader.js"],
33
"reporter": "mocha-multi-reporters",
44
"reporter-option": "configFile=build/.mocha-multi-reporters.config",
55
"ui": "tdd",
66
"recursive": true,
7-
"colors": true
7+
"colors": true,
8+
"node-option": ["--no-warnings=ExperimentalWarning"]
89
}

build/add-js-extensions.mjs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env node
2+
// Script to add .js extensions to all relative imports in TypeScript files
3+
// This is required for ESM compatibility
4+
5+
import { promises as fs } from 'fs';
6+
import path from 'path';
7+
import { fileURLToPath } from 'url';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = path.dirname(__filename);
11+
12+
const rootDir = path.join(__dirname, '..');
13+
const srcDir = path.join(rootDir, 'src');
14+
15+
// Regex patterns to match import statements with relative paths
16+
// Updated to handle multi-line imports/exports by using [\s\S] to match newlines
17+
const importPatterns = [
18+
// import ... from './path' or '../path' (supports multi-line named imports)
19+
/^(\s*import\s+[\s\S]+?from\s+['"])(\.\/.+?|\.\.?\/.+?)(['"])/gm,
20+
// export ... from './path' or '../path' (supports multi-line named exports)
21+
/^(\s*export\s+[\s\S]+?from\s+['"])(\.\/.+?|\.\.?\/.+?)(['"])/gm,
22+
// import('./path') or import('../path') (supports newlines before parentheses and quotes)
23+
/(\bimport[\s\S]*?\([\s\S]*?['"])(\.\/.+?|\.\.?\/.+?)(['"])/gm,
24+
// await import('./path') (supports newlines in await import statements)
25+
/(\bawait\s+import[\s\S]*?\([\s\S]*?['"])(\.\/.+?|\.\.?\/.+?)(['"])/gm,
26+
];
27+
28+
async function getAllTsFiles(dir) {
29+
const files = [];
30+
const entries = await fs.readdir(dir, { withFileTypes: true });
31+
32+
for (const entry of entries) {
33+
const fullPath = path.join(dir, entry.name);
34+
35+
if (entry.isDirectory()) {
36+
// Skip node_modules, out, dist, etc.
37+
if (!['node_modules', 'out', 'dist', '.git', '.vscode', 'resources'].includes(entry.name)) {
38+
files.push(...(await getAllTsFiles(fullPath)));
39+
}
40+
} else if ((entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) && !entry.name.endsWith('.d.ts')) {
41+
// Include .ts and .tsx files, but exclude .d.ts declaration files
42+
files.push(fullPath);
43+
}
44+
}
45+
46+
return files;
47+
}
48+
49+
function addJsExtension(content) {
50+
let modified = content;
51+
let changeCount = 0;
52+
53+
for (const pattern of importPatterns) {
54+
modified = modified.replace(pattern, (match, before, importPath, after) => {
55+
// Skip if already has an extension
56+
if (/\.(js|ts|tsx|json|css|less|svg|png|jpg)$/i.test(importPath)) {
57+
return match;
58+
}
59+
60+
changeCount++;
61+
return `${before}${importPath}.js${after}`;
62+
});
63+
}
64+
65+
return { content: modified, changed: changeCount > 0, changeCount };
66+
}
67+
68+
async function main() {
69+
console.log('🔍 Finding all TypeScript files in src/...');
70+
const tsFiles = await getAllTsFiles(srcDir);
71+
console.log(`📁 Found ${tsFiles.length} TypeScript files\n`);
72+
73+
let totalFilesChanged = 0;
74+
let totalImportsChanged = 0;
75+
76+
for (const file of tsFiles) {
77+
const content = await fs.readFile(file, 'utf-8');
78+
const { content: newContent, changed, changeCount } = addJsExtension(content);
79+
80+
if (changed) {
81+
await fs.writeFile(file, newContent, 'utf-8');
82+
totalFilesChanged++;
83+
totalImportsChanged += changeCount;
84+
const relativePath = path.relative(rootDir, file);
85+
console.log(`✅ ${relativePath} (${changeCount} import${changeCount > 1 ? 's' : ''})`);
86+
}
87+
}
88+
89+
console.log(`\n✨ Done!`);
90+
console.log(`📊 Modified ${totalFilesChanged} files`);
91+
console.log(`🔗 Updated ${totalImportsChanged} import statements`);
92+
}
93+
94+
main().catch(error => {
95+
console.error('❌ Error:', error);
96+
process.exit(1);
97+
});

build/ci/postInstall.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
3-
'use strict';
43

5-
const { EOL } = require('os');
6-
const colors = require('colors/safe');
7-
const fs = require('fs-extra');
8-
const path = require('path');
9-
const constants = require('../constants');
10-
const common = require('../webpack/common');
11-
const { downloadZMQ } = require('@vscode/zeromq');
4+
import { EOL } from 'node:os';
5+
import colors from 'colors/safe.js';
6+
import fs from 'fs-extra';
7+
import path from 'node:path';
8+
import { ExtensionRootDir } from '../constants.js';
9+
import { getBundleConfiguration, bundleConfiguration } from '../webpack/common.js';
10+
import { downloadZMQ } from '@vscode/zeromq';
11+
import { fileURLToPath } from 'node:url';
12+
import { dirname } from 'node:path';
13+
14+
const __filename = fileURLToPath(import.meta.url);
15+
const __dirname = dirname(__filename);
1216

1317
function fixVariableNameInKernelDefaultJs() {
1418
var relativePath = path.join('node_modules', '@jupyterlab', 'services', 'lib', 'kernel', 'default.js');
15-
var filePath = path.join(constants.ExtensionRootDir, relativePath);
19+
var filePath = path.join(ExtensionRootDir, relativePath);
1620
if (!fs.existsSync(filePath)) {
1721
throw new Error(
1822
"Jupyter lab default kernel not found '" + filePath + "' (Jupyter Extension post install script)"
@@ -32,7 +36,7 @@ function fixVariableNameInKernelDefaultJs() {
3236
}
3337
function removeUnnecessaryLoggingFromKernelDefault() {
3438
var relativePath = path.join('node_modules', '@jupyterlab', 'services', 'lib', 'kernel', 'default.js');
35-
var filePath = path.join(constants.ExtensionRootDir, relativePath);
39+
var filePath = path.join(ExtensionRootDir, relativePath);
3640
if (!fs.existsSync(filePath)) {
3741
throw new Error(
3842
"Jupyter lab default kernel not found '" + filePath + "' (Jupyter Extension post install script)"
@@ -61,7 +65,7 @@ function makeVariableExplorerAlwaysSorted() {
6165
'case g.NONE:e=r?g.DESC:g.ASC;break;case g.ASC:e=r?g.NONE:g.DESC;break;case g.DESC:e=r?g.ASC:g.NONE';
6266
for (const fileName of fileNames) {
6367
var relativePath = path.join('node_modules', 'react-data-grid', 'dist', fileName);
64-
var filePath = path.join(constants.ExtensionRootDir, relativePath);
68+
var filePath = path.join(ExtensionRootDir, relativePath);
6569
if (!fs.existsSync(filePath)) {
6670
throw new Error("react-data-grid dist file not found '" + filePath + "' (pvsc post install script)");
6771
}
@@ -134,7 +138,8 @@ exports.javascript = {
134138
* See comments here build/webpack/moment.js
135139
*/
136140
function verifyMomentIsOnlyUsedByJupyterLabCoreUtils() {
137-
const packageLock = require(path.join(__dirname, '..', '..', 'package-lock.json'));
141+
const packageLockPath = path.join(__dirname, '..', '..', 'package-lock.json');
142+
const packageLock = JSON.parse(fs.readFileSync(packageLockPath, 'utf8'));
138143
const packagesAllowedToUseMoment = ['node_modules/@jupyterlab/coreutils', '@jupyterlab/coreutils'];
139144
const otherPackagesUsingMoment = [];
140145
['packages', 'dependencies'].forEach((key) => {
@@ -167,7 +172,7 @@ function verifyMomentIsOnlyUsedByJupyterLabCoreUtils() {
167172
}
168173
}
169174
async function downloadZmqBinaries() {
170-
if (common.getBundleConfiguration() === common.bundleConfiguration.web) {
175+
if (getBundleConfiguration() === bundleConfiguration.web) {
171176
// No need to download zmq binaries for web.
172177
return;
173178
}

build/ci/scripts/spec_with_pid.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
'use strict';
21
/**
32
* @module Spec
43
*/
54
/**
65
* Module dependencies.
76
*/
87

9-
var Base = require('mocha/lib/reporters/base');
10-
var constants = require('mocha/lib/runner').constants;
11-
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
12-
var EVENT_RUN_END = constants.EVENT_RUN_END;
13-
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
14-
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
15-
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
16-
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
17-
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
18-
var inherits = require('mocha/lib/utils').inherits;
19-
var color = Base.color;
8+
import Base from 'mocha/lib/reporters/base';
9+
import { constants } from 'mocha/lib/runner';
10+
import { inherits } from 'mocha/lib/utils';
11+
12+
const EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
13+
const EVENT_RUN_END = constants.EVENT_RUN_END;
14+
const EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
15+
const EVENT_SUITE_END = constants.EVENT_SUITE_END;
16+
const EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
17+
const EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
18+
const EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
19+
const color = Base.color;
2020

2121
/**
2222
* Expose `Spec`.
2323
*/
2424

25-
exports = module.exports = Spec;
26-
2725
const prefix = process.env.VSC_JUPYTER_CI_TEST_PARALLEL ? `${process.pid} ` : '';
2826

2927
/**
@@ -96,3 +94,5 @@ function Spec(runner, options) {
9694
inherits(Spec, Base);
9795

9896
Spec.description = 'hierarchical & verbose [default]';
97+
98+
export default Spec;

0 commit comments

Comments
 (0)