From ca8090c810faa84962edfbc55466dadaa9d79f2a Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Fri, 3 Jun 2022 17:38:51 -0700 Subject: [PATCH] Avoid loading full lodash (#10308) * Avoid loading full lodash. * esModuleInterop * Revert "esModuleInterop" This reverts commit f3ebb12b830f3662de5ea56d50da7268ca6773b4. * force require for modules no default export * Use direct import in webview. --- .eslintrc.js | 1 + src/kernels/jupyter/preferredRemoteKernelIdProvider.ts | 3 ++- src/kernels/jupyter/serverSelector.ts | 2 +- src/notebooks/controllers/remoteSwitcher.ts | 2 +- src/notebooks/execution/notebookUpdater.ts | 2 +- .../editor-integration/hoverProvider.vscode.test.ts | 2 +- src/test/datascience/helpers.ts | 2 +- src/test/datascience/mockCommandManager.ts | 2 +- src/webviews/extension-side/dataviewer/dataViewerFactory.ts | 2 +- src/webviews/webview-side/data-explorer/mainPanel.tsx | 2 +- 10 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8e8fb3c572e..7b6235cf983 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -265,6 +265,7 @@ module.exports = { ], 'react/jsx-uses-vars': 'error', 'react/jsx-uses-react': 'error', + 'no-restricted-imports': ['error', { "paths": ["lodash"] }], 'import/no-restricted-paths': [ 'error', { diff --git a/src/kernels/jupyter/preferredRemoteKernelIdProvider.ts b/src/kernels/jupyter/preferredRemoteKernelIdProvider.ts index e129bf41f99..5aa195fa267 100644 --- a/src/kernels/jupyter/preferredRemoteKernelIdProvider.ts +++ b/src/kernels/jupyter/preferredRemoteKernelIdProvider.ts @@ -2,7 +2,8 @@ // Licensed under the MIT License. import { inject, injectable, named } from 'inversify'; -import { cloneDeep } from 'lodash'; +/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-require-imports */ +import cloneDeep = require('lodash/cloneDeep'); import { Memento, Uri } from 'vscode'; import { traceInfo, traceVerbose } from '../../platform/logging'; import { getDisplayPath } from '../../platform/common/platform/fs-paths'; diff --git a/src/kernels/jupyter/serverSelector.ts b/src/kernels/jupyter/serverSelector.ts index 017de9c087d..f1ac8e0f334 100644 --- a/src/kernels/jupyter/serverSelector.ts +++ b/src/kernels/jupyter/serverSelector.ts @@ -4,7 +4,7 @@ 'use strict'; import { inject, injectable } from 'inversify'; -import { isNil } from 'lodash'; +import isNil = require('lodash/isNil'); import { EventEmitter, QuickPickItem, ThemeIcon, Uri } from 'vscode'; import { IApplicationShell, IClipboard } from '../../platform/common/application/types'; import { traceDecoratorError, traceError, traceWarning } from '../../platform/logging'; diff --git a/src/notebooks/controllers/remoteSwitcher.ts b/src/notebooks/controllers/remoteSwitcher.ts index 77a7484d1bb..eef1ad33506 100644 --- a/src/notebooks/controllers/remoteSwitcher.ts +++ b/src/notebooks/controllers/remoteSwitcher.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import { noop } from 'lodash'; +import noop = require('lodash/noop'); import { StatusBarAlignment, StatusBarItem } from 'vscode'; import { IExtensionSingleActivationService } from '../../platform/activation/types'; import { diff --git a/src/notebooks/execution/notebookUpdater.ts b/src/notebooks/execution/notebookUpdater.ts index 9665fdb6283..6d263497f0e 100644 --- a/src/notebooks/execution/notebookUpdater.ts +++ b/src/notebooks/execution/notebookUpdater.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import { noop } from 'lodash'; +import noop = require('lodash/noop'); import { isPromise } from 'rxjs/internal-compatibility'; import { NotebookDocument, NotebookEditor, workspace, WorkspaceEdit, window } from 'vscode'; import { createDeferred } from '../../platform/common/utils/async'; diff --git a/src/test/datascience/editor-integration/hoverProvider.vscode.test.ts b/src/test/datascience/editor-integration/hoverProvider.vscode.test.ts index 58fc087efed..0473d1011e7 100644 --- a/src/test/datascience/editor-integration/hoverProvider.vscode.test.ts +++ b/src/test/datascience/editor-integration/hoverProvider.vscode.test.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { cloneDeep } from 'lodash'; +import cloneDeep = require('lodash/cloneDeep'); import * as sinon from 'sinon'; import * as path from '../../../platform/vscode-path/path'; import * as vscode from 'vscode'; diff --git a/src/test/datascience/helpers.ts b/src/test/datascience/helpers.ts index e2dcaafa362..d390e036dd7 100644 --- a/src/test/datascience/helpers.ts +++ b/src/test/datascience/helpers.ts @@ -5,7 +5,7 @@ import * as vscode from 'vscode'; import { getFilePath } from '../../platform/common/platform/fs-paths'; import { traceInfo } from '../../platform/logging'; -import { noop } from 'lodash'; +import noop = require('lodash/noop'); import { IPythonApiProvider } from '../../platform/api/types'; import { IJupyterSettings, Resource } from '../../platform/common/types'; import { InteractiveWindow } from '../../interactive-window/interactiveWindow'; diff --git a/src/test/datascience/mockCommandManager.ts b/src/test/datascience/mockCommandManager.ts index eb9b5a1adf0..e0aafa6ef19 100644 --- a/src/test/datascience/mockCommandManager.ts +++ b/src/test/datascience/mockCommandManager.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. 'use strict'; -import { noop } from 'lodash'; +import noop = require('lodash/noop'); import { Disposable, TextEditor, TextEditorEdit } from 'vscode'; import { ICommandNameArgumentTypeMapping } from '../../platform/common/application/commands'; diff --git a/src/webviews/extension-side/dataviewer/dataViewerFactory.ts b/src/webviews/extension-side/dataviewer/dataViewerFactory.ts index c1b36de28d1..16cba85de5e 100644 --- a/src/webviews/extension-side/dataviewer/dataViewerFactory.ts +++ b/src/webviews/extension-side/dataviewer/dataViewerFactory.ts @@ -7,7 +7,7 @@ import { inject, injectable } from 'inversify'; import { captureTelemetry } from '../../../telemetry'; import { IDataViewer, IDataViewerDataProvider, IDataViewerFactory } from './types'; -import { debounce } from 'lodash'; +import debounce = require('lodash/debounce'); import { ICommandManager } from '../../../platform/common/application/types'; import { ContextKey } from '../../../platform/common/contextKey'; import { IAsyncDisposable, IAsyncDisposableRegistry, IDisposableRegistry } from '../../../platform/common/types'; diff --git a/src/webviews/webview-side/data-explorer/mainPanel.tsx b/src/webviews/webview-side/data-explorer/mainPanel.tsx index d645950655c..d5a4e504885 100644 --- a/src/webviews/webview-side/data-explorer/mainPanel.tsx +++ b/src/webviews/webview-side/data-explorer/mainPanel.tsx @@ -16,7 +16,7 @@ import { generateTestData } from './testData'; import '../react-common/codicon/codicon.css'; import '../react-common/seti/seti.less'; import { SliceControl } from './sliceControl'; -import { debounce } from 'lodash'; +import debounce from 'lodash/debounce'; import * as uuid from 'uuid/v4'; import { initializeIcons } from '@fluentui/react';