Skip to content

Commit f7f67a5

Browse files
committed
chore: Migrate to ESM
1 parent b937920 commit f7f67a5

File tree

140 files changed

+2975
-2040
lines changed

Some content is hidden

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

140 files changed

+2975
-2040
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
{
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: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
import { dirname } from 'path';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = dirname(__filename);
12+
13+
const rootDir = path.join(__dirname, '..');
14+
const srcDir = path.join(rootDir, 'src');
15+
16+
// Regex patterns to match import statements with relative paths
17+
const importPatterns = [
18+
// import ... from './path' or '../path'
19+
/^(\s*import\s+.+\s+from\s+['"])(\.\/.+?|\.\.?\/.+?)(['"])/gm,
20+
// export ... from './path' or '../path'
21+
/^(\s*export\s+.+\s+from\s+['"])(\.\/.+?|\.\.?\/.+?)(['"])/gm,
22+
// import('./path') or import('../path')
23+
/(\bimport\s*\(\s*['"])(\.\/.+?|\.\.?\/.+?)(['"])/gm,
24+
// await import('./path')
25+
/(\bawait\s+import\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')) {
41+
files.push(fullPath);
42+
}
43+
}
44+
45+
return files;
46+
}
47+
48+
function addJsExtension(content) {
49+
let modified = content;
50+
let changeCount = 0;
51+
52+
for (const pattern of importPatterns) {
53+
modified = modified.replace(pattern, (match, before, importPath, after) => {
54+
// Skip if already has an extension
55+
if (/\.(js|ts|tsx|json|css|less|svg|png|jpg)$/i.test(importPath)) {
56+
return match;
57+
}
58+
59+
changeCount++;
60+
return `${before}${importPath}.js${after}`;
61+
});
62+
}
63+
64+
return { content: modified, changed: changeCount > 0, changeCount };
65+
}
66+
67+
async function main() {
68+
console.log('🔍 Finding all TypeScript files in src/...');
69+
const tsFiles = await getAllTsFiles(srcDir);
70+
console.log(`📁 Found ${tsFiles.length} TypeScript files\n`);
71+
72+
let totalFilesChanged = 0;
73+
let totalImportsChanged = 0;
74+
75+
for (const file of tsFiles) {
76+
const content = await fs.readFile(file, 'utf-8');
77+
const { content: newContent, changed, changeCount } = addJsExtension(content);
78+
79+
if (changed) {
80+
await fs.writeFile(file, newContent, 'utf-8');
81+
totalFilesChanged++;
82+
totalImportsChanged += changeCount;
83+
const relativePath = path.relative(rootDir, file);
84+
console.log(`✅ ${relativePath} (${changeCount} import${changeCount > 1 ? 's' : ''})`);
85+
}
86+
}
87+
88+
console.log(`\n✨ Done!`);
89+
console.log(`📊 Modified ${totalFilesChanged} files`);
90+
console.log(`🔗 Updated ${totalImportsChanged} import statements`);
91+
}
92+
93+
main().catch(error => {
94+
console.error('❌ Error:', error);
95+
process.exit(1);
96+
});

build/ci/postInstall.js

Lines changed: 16 additions & 12 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 'os';
5+
import colors from 'colors/safe';
6+
import fs from 'fs-extra';
7+
import path from '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 'url';
12+
import { dirname } from '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
}
@@ -167,7 +171,7 @@ function verifyMomentIsOnlyUsedByJupyterLabCoreUtils() {
167171
}
168172
}
169173
async function downloadZmqBinaries() {
170-
if (common.getBundleConfiguration() === common.bundleConfiguration.web) {
174+
if (getBundleConfiguration() === bundleConfiguration.web) {
171175
// No need to download zmq binaries for web.
172176
return;
173177
}

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;

build/constants.js

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

5-
const util = require('./util');
6-
exports.ExtensionRootDir = util.ExtensionRootDir;
7-
exports.isWindows = /^win/.test(process.platform);
8-
exports.isCI = process.env.TF_BUILD !== undefined || process.env.GITHUB_ACTIONS === 'true';
4+
import { ExtensionRootDir as _ExtensionRootDir } from './util.js';
5+
6+
export const ExtensionRootDir = _ExtensionRootDir;
7+
export const isWindows = /^win/.test(process.platform);
8+
export const isCI = process.env.TF_BUILD !== undefined || process.env.GITHUB_ACTIONS === 'true';

0 commit comments

Comments
 (0)