From 6bb62005cb202177544ee9751fbdba17828812ce Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 1 Feb 2019 19:55:32 -0600 Subject: [PATCH] Fix require.toUrl and walkthroughs --- packages/vscode/src/client.ts | 1 - packages/vscode/src/fill/amd.ts | 2 +- packages/vscode/src/fill/dom.ts | 1 + packages/vscode/src/fill/require.ts | 7 --- packages/web/webpack.common.config.js | 6 ++- scripts/vscode.patch | 69 ++++++++++++++++++++++----- scripts/webpack.general.config.js | 7 ++- 7 files changed, 68 insertions(+), 25 deletions(-) delete mode 100644 packages/vscode/src/fill/require.ts diff --git a/packages/vscode/src/client.ts b/packages/vscode/src/client.ts index 3266e6ed..e0ba5484 100644 --- a/packages/vscode/src/client.ts +++ b/packages/vscode/src/client.ts @@ -1,4 +1,3 @@ -import "./fill/require"; import * as paths from "./fill/paths"; import "./fill/platform"; import "./fill/storageDatabase"; diff --git a/packages/vscode/src/fill/amd.ts b/packages/vscode/src/fill/amd.ts index 56c21084..8d322bc1 100644 --- a/packages/vscode/src/fill/amd.ts +++ b/packages/vscode/src/fill/amd.ts @@ -7,5 +7,5 @@ export const getPathFromAmdModule = (_: typeof require, relativePath: string): s return process.mainModule.filename.slice(0, index); } - return relativePath ? URI.parse(require.toUrl(relativePath)).fsPath : ""; + return relativePath ? URI.file(relativePath).fsPath : ""; }; diff --git a/packages/vscode/src/fill/dom.ts b/packages/vscode/src/fill/dom.ts index a97e5973..c68d7320 100644 --- a/packages/vscode/src/fill/dom.ts +++ b/packages/vscode/src/fill/dom.ts @@ -22,6 +22,7 @@ if (!("toElement" in MouseEvent.prototype)) { } const _addDisposableListener = dom.addDisposableListener; +// tslint:disable-next-line no-any const addDisposableListener = (node: Element | Window | Document, type: string, handler: (event: any) => void, useCapture?: boolean): IDisposable => { return _addDisposableListener(node, type === "mousewheel" ? "wheel" : type, handler, useCapture); }; diff --git a/packages/vscode/src/fill/require.ts b/packages/vscode/src/fill/require.ts deleted file mode 100644 index 92853b94..00000000 --- a/packages/vscode/src/fill/require.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { join } from "path"; - -// tslint:disable-next-line no-any -(global as any).requireToUrl = (path: string): string => { - // TODO: can start with vs/... - return join(`${location.protocol}//${location.host}/resource`, path); -}; diff --git a/packages/web/webpack.common.config.js b/packages/web/webpack.common.config.js index 271e5099..5a63f724 100644 --- a/packages/web/webpack.common.config.js +++ b/packages/web/webpack.common.config.js @@ -22,8 +22,10 @@ module.exports = merge({ test: /\.(j|t)s/, options: { multiple: [{ - search: "require\\.toUrl\\(", - replace: "requireToUrl(", + // These will be handled by file-loader. We need the location because + // they are parsed as URIs and will throw errors if not fully formed. + search: "require\\.toUrl", + replace: "location.protocol + '//' + location.host + '/' + require", flags: "g", }, { search: "require\\.__\\$__nodeRequire", diff --git a/scripts/vscode.patch b/scripts/vscode.patch index 82192aa7..baa56223 100644 --- a/scripts/vscode.patch +++ b/scripts/vscode.patch @@ -109,14 +109,14 @@ index 2bf7fe37d7..81cc668f12 100644 catch (err) { errorback(err); diff --git a/src/vs/workbench/api/electron-browser/mainThreadHeapService.ts b/src/vs/workbench/api/electron-browser/mainThreadHeapService.ts -index e3efb95b75..03e85113a0 100644 +index e3efb95b75..163bc4c994 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadHeapService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadHeapService.ts @@ -55,6 +55,9 @@ export class HeapService implements IHeapService { private _doTrackRecursive(obj: any): Promise { -+ // cannot control GC in the browser. ++ // Cannot control GC in the browser. + return Promise.resolve(obj); + if (isNullOrUndefined(obj)) { @@ -144,10 +144,10 @@ index 38bf337a61..aae3a68ff5 100644 // Make the window active to handle the drop properly within diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts -index a43d63aa51..4c6df2fcd9 100644 +index a43d63aa51..438d0a8245 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts -@@ -147,13 +147,14 @@ function openWorkbench(configuration: IWindowConfiguration): Promise { +@@ -147,13 +147,13 @@ function openWorkbench(configuration: IWindowConfiguration): Promise { shell.open(); // Inform user about loading issues from the loader @@ -158,7 +158,6 @@ index a43d63aa51..4c6df2fcd9 100644 - } - } - }); -+ // TODO: how to make this work + // (self).require.config({ + // onError: err => { + // if (err.errorCode === 'load') { @@ -269,20 +268,66 @@ index 2975294e75..73ffb6362d 100644 // Don't use ctrl+a by default as that would override the common go to start // of prompt shell binding diff --git a/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts b/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts -index 7b4e8721ac..8f26dc2f28 100644 +index 7b4e8721ac..96d612f940 100644 --- a/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts +++ b/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts -@@ -28,7 +28,9 @@ export class WalkThroughContentProvider implements ITextModelContentProvider, IW +@@ -28,14 +28,16 @@ export class WalkThroughContentProvider implements ITextModelContentProvider, IW public provideTextContent(resource: URI): Thenable { const query = resource.query ? JSON.parse(resource.query) : {}; const content: Thenable = (query.moduleId ? new Promise((resolve, reject) => { - require([query.moduleId], content => { -+ // Webpack needs this to be static or it can't include it. +- try { +- resolve(content.default()); +- } catch (err) { +- reject(err); +- } ++ // This works because the only walkthrough that is a module is the welcome page. ++ // We have to explicitly import it or Webpack won't pick it up. + import("vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page").then((content) => { -+ // require([query.moduleId], content => { - try { - resolve(content.default()); - } catch (err) { ++ resolve(content.default()); ++ }).catch((err) => { ++ reject(err); + }); +- }) : this.textFileService.resolveTextContent(URI.file(resource.fsPath)).then(content => content.value)); ++ }) : (resource.scheme !== "file" ++ ? fetch(resource.path).then((res) => res.text()) ++ : this.textFileService.resolveTextContent(URI.file(resource.fsPath)).then(content => content.value))); + return content.then(content => { + let codeEditorModel = this.modelService.getModel(resource); + if (!codeEditorModel) { +@@ -61,7 +63,7 @@ export class WalkThroughSnippetContentProvider implements ITextModelContentProvi + } + + public provideTextContent(resource: URI): Thenable { +- return this.textFileService.resolveTextContent(URI.file(resource.fsPath)).then(content => { ++ return fetch(resource.path).then((res) => res.text()).then((content) => { + let codeEditorModel = this.modelService.getModel(resource); + if (!codeEditorModel) { + const j = parseInt(resource.fragment); +@@ -78,17 +80,17 @@ export class WalkThroughSnippetContentProvider implements ITextModelContentProvi + return ''; + }; + +- const textBuffer = content.value.create(DefaultEndOfLine.LF); +- const lineCount = textBuffer.getLineCount(); +- const range = new Range(1, 1, lineCount, textBuffer.getLineLength(lineCount) + 1); +- const markdown = textBuffer.getValueInRange(range, EndOfLinePreference.TextDefined); +- marked(markdown, { renderer }); ++ // const textBuffer = content.value.create(DefaultEndOfLine.LF); ++ // const lineCount = textBuffer.getLineCount(); ++ // const range = new Range(1, 1, lineCount, textBuffer.getLineLength(lineCount) + 1); ++ // const markdown = textBuffer.getValueInRange(range, EndOfLinePreference.TextDefined); ++ marked(content, { renderer }); + + const languageId = this.modeService.getModeIdForLanguageName(languageName); + const languageSelection = this.modeService.create(languageId); + codeEditorModel = this.modelService.createModel(codeSnippet, languageSelection, resource); + } else { +- this.modelService.updateModel(codeEditorModel, content.value); ++ this.modelService.updateModel(codeEditorModel, content); + } + + return codeEditorModel; diff --git a/src/vs/workbench/services/themes/electron-browser/fileIconThemeData.ts b/src/vs/workbench/services/themes/electron-browser/fileIconThemeData.ts index 5b4136989f..25ccc0fe9e 100644 --- a/src/vs/workbench/services/themes/electron-browser/fileIconThemeData.ts diff --git a/scripts/webpack.general.config.js b/scripts/webpack.general.config.js index 13bf8753..1e853867 100644 --- a/scripts/webpack.general.config.js +++ b/scripts/webpack.general.config.js @@ -17,7 +17,7 @@ module.exports = (options = {}) => ({ test: /\.(js)/, exclude: /test/, }, { - test: /\.(txt|d\.ts|test.ts|perf.data.js|jxs|md|scpt|exe|sh|less)$/, + test: /\.(txt|d\.ts|test.ts|perf.data.js|jxs|scpt|exe|sh|less)$/, use: [{ loader: "ignore-loader", }], @@ -49,9 +49,12 @@ module.exports = (options = {}) => ({ loader: "sass-loader", }], }, { - test: /\.(svg|png|ttf|woff|eot)$/, + test: /\.(svg|png|ttf|woff|eot|md)$/, use: [{ loader: "file-loader", + options: { + name: "[path][name].[ext]", + }, }], }, { test: /\.wasm$/,