Remove references to noderequire (#8101)

* remove references to nodequire

* change promise handling
This commit is contained in:
Anthony Dresser
2019-10-30 10:04:52 -07:00
committed by GitHub
parent a89788a020
commit f7b8a019cd
2 changed files with 10 additions and 21 deletions

View File

@@ -17,9 +17,6 @@ import { BackupComponent } from 'sql/workbench/parts/backup/browser/backup.compo
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IBootstrapParams, ISelector } from 'sql/platform/bootstrap/common/bootstrapParams'; import { IBootstrapParams, ISelector } from 'sql/platform/bootstrap/common/bootstrapParams';
// work around
const BrowserAnimationsModule = (<any>require.__$__nodeRequire('@angular/platform-browser/animations')).BrowserAnimationsModule;
// Backup wizard main angular module // Backup wizard main angular module
export const BackupModule = (params: IBootstrapParams, selector: string, instantiationService: IInstantiationService): Type<any> => { export const BackupModule = (params: IBootstrapParams, selector: string, instantiationService: IInstantiationService): Type<any> => {
@NgModule({ @NgModule({
@@ -30,8 +27,7 @@ export const BackupModule = (params: IBootstrapParams, selector: string, instant
imports: [ imports: [
FormsModule, FormsModule,
CommonModule, CommonModule,
BrowserModule, BrowserModule
BrowserAnimationsModule,
], ],
providers: [ providers: [
{ provide: APP_BASE_HREF, useValue: '/' }, { provide: APP_BASE_HREF, useValue: '/' },

View File

@@ -17,8 +17,8 @@ import { getErrorMessage } from 'vs/base/common/errors';
type ObjectType = object; type ObjectType = object;
interface FigureLayout extends ObjectType { interface FigureLayout extends ObjectType {
width?: string | number; width?: number;
height?: string; height?: number;
autosize?: boolean; autosize?: boolean;
} }
@@ -43,14 +43,7 @@ declare class PlotlyHTMLElement extends HTMLDivElement {
export class PlotlyOutputComponent extends AngularDisposable implements IMimeComponent, OnInit { export class PlotlyOutputComponent extends AngularDisposable implements IMimeComponent, OnInit {
public static readonly SELECTOR: string = 'plotly-output'; public static readonly SELECTOR: string = 'plotly-output';
Plotly!: { private static Plotly?: Promise<typeof import('plotly.js-dist')>;
newPlot: (
div: PlotlyHTMLElement | null | undefined,
data: object,
layout: FigureLayout
) => void;
redraw: (div?: PlotlyHTMLElement) => void;
};
@ViewChild('output', { read: ElementRef }) private output: ElementRef; @ViewChild('output', { read: ElementRef }) private output: ElementRef;
@@ -88,7 +81,9 @@ export class PlotlyOutputComponent extends AngularDisposable implements IMimeCom
} }
ngOnInit() { ngOnInit() {
this.Plotly = require.__$__nodeRequire('plotly.js-dist'); if (!PlotlyOutputComponent.Plotly) {
PlotlyOutputComponent.Plotly = import('plotly.js-dist');
}
this._plotDiv = this.output.nativeElement; this._plotDiv = this.output.nativeElement;
this.renderPlotly(); this.renderPlotly();
this._initialized = true; this._initialized = true;
@@ -116,11 +111,9 @@ export class PlotlyOutputComponent extends AngularDisposable implements IMimeCom
// Workaround: to avoid filling up the entire cell, use plotly's default // Workaround: to avoid filling up the entire cell, use plotly's default
figure.layout.width = Math.min(700, this._plotDiv.clientWidth); figure.layout.width = Math.min(700, this._plotDiv.clientWidth);
} }
try { PlotlyOutputComponent.Plotly.then(plotly => {
this.Plotly.newPlot(this._plotDiv, figure.data, figure.layout); return plotly.newPlot(this._plotDiv, figure.data, figure.layout);
} catch (error) { }).catch(e => this.displayError(e));
this.displayError(error);
}
} }
this._rendered = true; this._rendered = true;
} }