From f7457e69a00c72ded153378a6e85503501e3a576 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 8 Jun 2020 09:56:58 -0700 Subject: [PATCH] Stable way to get script path for split bundles --- src/client/datascience/notebook/renderer.ts | 2 -- src/datascience-ui/renderers/index.tsx | 13 ++++------- src/datascience-ui/renderers/main.ts | 26 --------------------- src/datascience-ui/renderers/pvscDummy.ts | 6 ----- 4 files changed, 5 insertions(+), 42 deletions(-) delete mode 100644 src/datascience-ui/renderers/main.ts delete mode 100644 src/datascience-ui/renderers/pvscDummy.ts diff --git a/src/client/datascience/notebook/renderer.ts b/src/client/datascience/notebook/renderer.ts index 46294018d56b..083c7b3a83f3 100644 --- a/src/client/datascience/notebook/renderer.ts +++ b/src/client/datascience/notebook/renderer.ts @@ -15,8 +15,6 @@ export class NotebookOutputRenderer implements VSCNotebookOutputRenderer { private _preloads: Uri[] = []; constructor() { const renderersFolder = path.join(EXTENSION_ROOT_DIR, 'out', 'datascience-ui', 'renderers'); - this._preloads.push(Uri.file(path.join(renderersFolder, 'pvscDummy.js'))); - this._preloads.push(Uri.file(path.join(renderersFolder, 'main.js'))); this._preloads.push(Uri.file(path.join(renderersFolder, 'renderers.js'))); } diff --git a/src/datascience-ui/renderers/index.tsx b/src/datascience-ui/renderers/index.tsx index 094281cc0d38..05ba26de0dc5 100644 --- a/src/datascience-ui/renderers/index.tsx +++ b/src/datascience-ui/renderers/index.tsx @@ -4,16 +4,13 @@ 'use strict'; // This must be on top, do not change. Required by webpack. -// tslint:disable-next-line: no-var-requires no-require-imports -// require('../common/main'); declare let __webpack_public_path__: string; +const getPublicPath = () => { + const currentDirname = (document.currentScript as HTMLScriptElement).src.replace(/[^/]+$/, ''); + return new URL(currentDirname).toString(); +}; -// tslint:disable-next-line: no-any -if ((window as any).__PVSC_Public_Path) { - // This variable tells Webpack to this as the root path used to request webpack bundles. - // tslint:disable-next-line: no-any - __webpack_public_path__ = (window as any).__PVSC_Public_Path; -} +__webpack_public_path__ = getPublicPath(); // This must be on top, do not change. Required by webpack. import type { nbformat } from '@jupyterlab/coreutils'; diff --git a/src/datascience-ui/renderers/main.ts b/src/datascience-ui/renderers/main.ts deleted file mode 100644 index df70985ff708..000000000000 --- a/src/datascience-ui/renderers/main.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// Temporary work around for https://github.com/microsoft/vscode/issues/98106 -// tslint:disable - -const scriptSrcs = Array.from(document.querySelectorAll('script')) - .map((item) => item.attributes.getNamedItem('src')) - .filter((item) => (item?.value || '').endsWith('pvscDummy.js')) - .map((item) => item?.value) - .filter((item) => !!item); - -if (scriptSrcs.length) { - try { - const src = scriptSrcs[0]!; - const paths = src.split('/'); - // Remove file name portion from path. - paths.pop(); - Object.assign(window, { __PVSC_Public_Path: `${paths.join('/')}/` }); - console.log(`window.__PVSC_Public_Path = ${(window as any).__PVSC_Public_Path}`); - } catch (ex) { - console.error('Unable to initialize window.__PVSC_Public_Path', ex); - } -} else { - console.error('Unable to initialize window.__PVSC_Public_Path'); -} diff --git a/src/datascience-ui/renderers/pvscDummy.ts b/src/datascience-ui/renderers/pvscDummy.ts deleted file mode 100644 index b0e3b7e17aa1..000000000000 --- a/src/datascience-ui/renderers/pvscDummy.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// Temporary work around for https://github.com/microsoft/vscode/issues/98106 -// tslint:disable-next-line: no-console -console.log('pvscDummy loaded for renderer');