Skip to content

Commit

Permalink
More tree shaking (#10355)
Browse files Browse the repository at this point in the history
* More tree shaking

* revert unnecessary change

* validate moment js in prehook.

* move validation to CI.
  • Loading branch information
rebornix authored Jun 8, 2022
1 parent cf7da9f commit cb7c2f3
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ module.exports = {
],
'react/jsx-uses-vars': 'error',
'react/jsx-uses-react': 'error',
'no-restricted-imports': ['error', { paths: ['lodash'] }],
'no-restricted-imports': ['error', { paths: ['lodash', 'rxjs'] }],
'import/no-restricted-paths': [
'error',
{
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ jobs:
- name: Verify Translation files
run: npm run validateTranslationFiles

- name: Validate npm dependencies
run: npm run validateDependencies

- name: Run linting on TypeScript code (eslint)
run: npm run lint

Expand Down
2 changes: 1 addition & 1 deletion build/webpack/webpack.extension.web.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const config = {
}
]
},
externals: ['vscode', 'commonjs', 'electron'], // Don't bundle these
externals: ['vscode', 'commonjs', 'electron', 'moment'], // Don't bundle these
plugins: [
// Work around for Buffer is undefined:
new webpack.ProvidePlugin({
Expand Down
24 changes: 24 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,27 @@ gulp.task('validateTelemetryMD', async () => {
throw new Error('Telemetry MD is not valid, please re-run `npm run generateTelemetry`');
}
});

gulp.task('validateDependencies', async () => {
const packageLock = fs.readFileSync(path.join(__dirname, 'package-lock.json'), 'utf-8');
const dependencies = JSON.parse(packageLock).dependencies;
const modules = [];
Object.keys(dependencies).forEach((key) => {
const value = dependencies[key];
const requires = value.requires;

if (requires && requires['moment']) {
modules.push(key);
}
});

if (modules.length > 0) {
console.log(modules);
if (modules.length > 1 || modules[0] !== '@jupyterlab/coreutils') {
// we already validate that we are not using moment in @jupyterlab/coreutils
const message = `The following modules require moment: ${modules.join(', ')}. Please validate if moment is being used.`;
console.error(message);
throw new Error(message);
}
}
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,7 @@
"download-api": "vscode-dts dev",
"postdownload-api": "vscode-dts main",
"generateTelemetry": "gulp generateTelemetryMd",
"validateDependencies": "gulp validateDependencies",
"openInBrowser": "vscode-test-web --extensionDevelopmentPath=. ./src/test/datascience",
"startJupyterServer": "node build/preDebugWebTest.js",
"stopJupyterServer": "node build/postDebugWebTest.js",
Expand Down
2 changes: 1 addition & 1 deletion src/kernels/jupyter/launcher/jupyterConnection.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import '../../../platform/common/extensions';

import { ChildProcess } from 'child_process';
import { Subscription } from 'rxjs';
import { Subscription } from 'rxjs/Subscription';
import { CancellationError, CancellationToken, Disposable, Event, EventEmitter, Uri } from 'vscode';
import { IConfigurationService, IDisposable } from '../../../platform/common/types';
import { Cancellation } from '../../../platform/common/cancellation';
Expand Down
2 changes: 1 addition & 1 deletion src/platform/api/pythonApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './types';
import * as localize from '../common/utils/localize';
import { injectable, inject } from 'inversify';
import { noop } from 'rxjs';
import { noop } from 'rxjs/util/noop';
import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
import { IWorkspaceService, IApplicationShell, ICommandManager } from '../common/application/types';
import { isCI, PythonExtension, Telemetry } from '../common/constants';
Expand Down
3 changes: 2 additions & 1 deletion src/test/datascience/kernelProcess.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { IDisposable, IJupyterSettings, IOutputChannel } from '../../platform/co
import { CancellationTokenSource, Uri } from 'vscode';
import { disposeAllDisposables } from '../../platform/common/helpers';
import { noop } from '../core';
import { Observable, Subject } from 'rxjs';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { ChildProcess } from 'child_process';
import { EventEmitter } from 'stream';
import { PythonKernelInterruptDaemon } from '../../kernels/raw/finder/pythonKernelInterruptDaemon.node';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { PreferredRemoteKernelIdProvider } from '../../../kernels/jupyter/preferredRemoteKernelIdProvider';
import { RemoteKernelConnectionHandler } from '../../../kernels/jupyter/remoteKernelConnectionHandler';
import { INotebookControllerManager } from '../../../notebooks/types';
import { Subject } from 'rxjs';
import { Subject } from 'rxjs/Subject';
import { IVSCodeNotebookController } from '../../../notebooks/controllers/types';

use(chaiAsPromised);
Expand Down

0 comments on commit cb7c2f3

Please sign in to comment.