Archived
1
0

Fix require.toUrl and walkthroughs

This commit is contained in:
Asher 2019-02-01 19:55:32 -06:00 committed by Kyle Carberry
parent a353a59945
commit 6bb62005cb
No known key found for this signature in database
GPG Key ID: A0409BDB6B0B3EDB
7 changed files with 68 additions and 25 deletions

View File

@ -1,4 +1,3 @@
import "./fill/require";
import * as paths from "./fill/paths"; import * as paths from "./fill/paths";
import "./fill/platform"; import "./fill/platform";
import "./fill/storageDatabase"; import "./fill/storageDatabase";

View File

@ -7,5 +7,5 @@ export const getPathFromAmdModule = (_: typeof require, relativePath: string): s
return process.mainModule.filename.slice(0, index); return process.mainModule.filename.slice(0, index);
} }
return relativePath ? URI.parse(require.toUrl(relativePath)).fsPath : ""; return relativePath ? URI.file(relativePath).fsPath : "";
}; };

View File

@ -22,6 +22,7 @@ if (!("toElement" in MouseEvent.prototype)) {
} }
const _addDisposableListener = dom.addDisposableListener; 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 => { const addDisposableListener = (node: Element | Window | Document, type: string, handler: (event: any) => void, useCapture?: boolean): IDisposable => {
return _addDisposableListener(node, type === "mousewheel" ? "wheel" : type, handler, useCapture); return _addDisposableListener(node, type === "mousewheel" ? "wheel" : type, handler, useCapture);
}; };

View File

@ -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);
};

View File

@ -22,8 +22,10 @@ module.exports = merge({
test: /\.(j|t)s/, test: /\.(j|t)s/,
options: { options: {
multiple: [{ multiple: [{
search: "require\\.toUrl\\(", // These will be handled by file-loader. We need the location because
replace: "requireToUrl(", // they are parsed as URIs and will throw errors if not fully formed.
search: "require\\.toUrl",
replace: "location.protocol + '//' + location.host + '/' + require",
flags: "g", flags: "g",
}, { }, {
search: "require\\.__\\$__nodeRequire", search: "require\\.__\\$__nodeRequire",

View File

@ -109,14 +109,14 @@ index 2bf7fe37d7..81cc668f12 100644
catch (err) { catch (err) {
errorback(err); errorback(err);
diff --git a/src/vs/workbench/api/electron-browser/mainThreadHeapService.ts b/src/vs/workbench/api/electron-browser/mainThreadHeapService.ts 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 --- a/src/vs/workbench/api/electron-browser/mainThreadHeapService.ts
+++ b/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 { @@ -55,6 +55,9 @@ export class HeapService implements IHeapService {
private _doTrackRecursive(obj: any): Promise<any> { private _doTrackRecursive(obj: any): Promise<any> {
+ // cannot control GC in the browser. + // Cannot control GC in the browser.
+ return Promise.resolve(obj); + return Promise.resolve(obj);
+ +
if (isNullOrUndefined(obj)) { if (isNullOrUndefined(obj)) {
@ -144,10 +144,10 @@ index 38bf337a61..aae3a68ff5 100644
// Make the window active to handle the drop properly within // 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 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 --- a/src/vs/workbench/electron-browser/main.ts
+++ b/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts
@@ -147,13 +147,14 @@ function openWorkbench(configuration: IWindowConfiguration): Promise<void> { @@ -147,13 +147,13 @@ function openWorkbench(configuration: IWindowConfiguration): Promise<void> {
shell.open(); shell.open();
// Inform user about loading issues from the loader // Inform user about loading issues from the loader
@ -158,7 +158,6 @@ index a43d63aa51..4c6df2fcd9 100644
- } - }
- } - }
- }); - });
+ // TODO: how to make this work
+ // (<any>self).require.config({ + // (<any>self).require.config({
+ // onError: err => { + // onError: err => {
+ // if (err.errorCode === 'load') { + // 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 // Don't use ctrl+a by default as that would override the common go to start
// of prompt shell binding // 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 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 --- a/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts
+++ b/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<ITextModel> { public provideTextContent(resource: URI): Thenable<ITextModel> {
const query = resource.query ? JSON.parse(resource.query) : {}; const query = resource.query ? JSON.parse(resource.query) : {};
const content: Thenable<string | ITextBufferFactory> = (query.moduleId ? new Promise<string>((resolve, reject) => { const content: Thenable<string | ITextBufferFactory> = (query.moduleId ? new Promise<string>((resolve, reject) => {
- require([query.moduleId], content => { - 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) => { + import("vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page").then((content) => {
+ // require([query.moduleId], content => { + resolve(content.default());
try { + }).catch((err) => {
resolve(content.default()); + reject(err);
} catch (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<ITextModel> {
- 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 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 index 5b4136989f..25ccc0fe9e 100644
--- a/src/vs/workbench/services/themes/electron-browser/fileIconThemeData.ts --- a/src/vs/workbench/services/themes/electron-browser/fileIconThemeData.ts

View File

@ -17,7 +17,7 @@ module.exports = (options = {}) => ({
test: /\.(js)/, test: /\.(js)/,
exclude: /test/, 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: [{ use: [{
loader: "ignore-loader", loader: "ignore-loader",
}], }],
@ -49,9 +49,12 @@ module.exports = (options = {}) => ({
loader: "sass-loader", loader: "sass-loader",
}], }],
}, { }, {
test: /\.(svg|png|ttf|woff|eot)$/, test: /\.(svg|png|ttf|woff|eot|md)$/,
use: [{ use: [{
loader: "file-loader", loader: "file-loader",
options: {
name: "[path][name].[ext]",
},
}], }],
}, { }, {
test: /\.wasm$/, test: /\.wasm$/,