From 4e975a1bebd8e346a511339c8d177d8bf35a945a Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 17 Jul 2018 12:53:27 +0200 Subject: [PATCH] ensure original-fs is used in all our AMD code (#54468) --- src/bootstrap-amd.js | 2 + src/vs/code/electron-main/main.ts | 2 +- src/vs/code/electron-main/windows.ts | 2 +- src/vs/loader.js | 48 +++++++++++-------- src/vs/platform/state/node/stateService.ts | 2 +- .../electron-main/updateService.win32.ts | 2 +- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/bootstrap-amd.js b/src/bootstrap-amd.js index 98bc02c22cd..c8e5800ab5b 100644 --- a/src/bootstrap-amd.js +++ b/src/bootstrap-amd.js @@ -69,6 +69,8 @@ loader.config({ nodeCachedDataDir: process.env['VSCODE_NODE_CACHED_DATA_DIR_' + process.pid] }); +loader.define('fs', ['original-fs'], function (originalFS) { return originalFS; }); // replace the patched electron fs with the original node fs for all AMD code + if (nlsConfig.pseudo) { loader(['vs/nls'], function (nlsPlugin) { nlsPlugin.setPseudoTranslation(nlsConfig.pseudo); diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 4349d32b4f8..134f4379fb3 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -35,7 +35,7 @@ import { IRequestService } from 'vs/platform/request/node/request'; import { RequestService } from 'vs/platform/request/electron-main/requestService'; import { IURLService } from 'vs/platform/url/common/url'; import { URLService } from 'vs/platform/url/common/urlService'; -import * as fs from 'original-fs'; +import * as fs from 'fs'; import { CodeApplication } from 'vs/code/electron-main/app'; import { HistoryMainService } from 'vs/platform/history/electron-main/historyMainService'; import { IHistoryMainService } from 'vs/platform/history/common/history'; diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index 6e6fbed43cd..13036393211 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -6,7 +6,7 @@ 'use strict'; import { basename, normalize, join, dirname } from 'path'; -import * as fs from 'original-fs'; +import * as fs from 'fs'; import { localize } from 'vs/nls'; import * as arrays from 'vs/base/common/arrays'; import { assign, mixin, equals } from 'vs/base/common/objects'; diff --git a/src/vs/loader.js b/src/vs/loader.js index 291f0e8b6b3..d2b9f26ab38 100644 --- a/src/vs/loader.js +++ b/src/vs/loader.js @@ -212,7 +212,7 @@ var AMDLoader; return '===anonymous' + (Utilities.NEXT_ANONYMOUS_ID++) + '==='; }; Utilities.isAnonymousModule = function (id) { - return /^===anonymous/.test(id); + return Utilities.startsWith(id, '===anonymous'); }; Utilities.getHighPerformanceTimestamp = function () { if (!this.PERFORMANCE_NOW_PROBED) { @@ -811,15 +811,17 @@ var AMDLoader; errorCode: 'cachedDataRejected', path: cachedDataPath }); - NodeScriptLoader._runSoon(function () { return _this._fs.unlink(cachedDataPath, function (err) { - if (err) { - moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({ - errorCode: 'unlink', - path: cachedDataPath, - detail: err - }); - } - }); }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay); + NodeScriptLoader._runSoon(function () { + return _this._fs.unlink(cachedDataPath, function (err) { + if (err) { + moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({ + errorCode: 'unlink', + path: cachedDataPath, + detail: err + }); + } + }); + }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay); } else if (script.cachedDataProduced) { // data produced => tell outside world @@ -828,15 +830,17 @@ var AMDLoader; length: script.cachedData.length }); // data produced => write cache file - NodeScriptLoader._runSoon(function () { return _this._fs.writeFile(cachedDataPath, script.cachedData, function (err) { - if (err) { - moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({ - errorCode: 'writeFile', - path: cachedDataPath, - detail: err - }); - } - }); }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay); + NodeScriptLoader._runSoon(function () { + return _this._fs.writeFile(cachedDataPath, script.cachedData, function (err) { + if (err) { + moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({ + errorCode: 'writeFile', + path: cachedDataPath, + detail: err + }); + } + }); + }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay); } }; NodeScriptLoader._runSoon = function (callback, minTimeout) { @@ -1403,7 +1407,8 @@ var AMDLoader; this._knownModules2[moduleId] = true; var strModuleId = this._moduleIdProvider.getStrModuleId(moduleId); var paths = this._config.moduleIdToPaths(strModuleId); - if (this._env.isNode && strModuleId.indexOf('/') === -1) { + var scopedPackageRegex = /^@[^\/]+\/[^\/]+$/; // matches @scope/package-name + if (this._env.isNode && (strModuleId.indexOf('/') === -1 || scopedPackageRegex.test(strModuleId))) { paths.push('node|' + strModuleId); } var lastPathIndex = -1; @@ -1649,6 +1654,9 @@ var AMDLoader; RequireFunc.getStats = function () { return moduleManager.getLoaderEvents(); }; + RequireFunc.define = function () { + return DefineFunc.apply(null, arguments); + }; function init() { if (typeof AMDLoader.global.require !== 'undefined' || typeof require !== 'undefined') { var _nodeRequire_1 = (AMDLoader.global.require || require); diff --git a/src/vs/platform/state/node/stateService.ts b/src/vs/platform/state/node/stateService.ts index 77d9c406d30..5238541eac1 100644 --- a/src/vs/platform/state/node/stateService.ts +++ b/src/vs/platform/state/node/stateService.ts @@ -6,7 +6,7 @@ 'use strict'; import * as path from 'path'; -import * as fs from 'original-fs'; +import * as fs from 'fs'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { writeFileAndFlushSync } from 'vs/base/node/extfs'; import { isUndefined, isUndefinedOrNull } from 'vs/base/common/types'; diff --git a/src/vs/platform/update/electron-main/updateService.win32.ts b/src/vs/platform/update/electron-main/updateService.win32.ts index 53b4f047dc6..0f211dd226b 100644 --- a/src/vs/platform/update/electron-main/updateService.win32.ts +++ b/src/vs/platform/update/electron-main/updateService.win32.ts @@ -5,7 +5,7 @@ 'use strict'; -import * as fs from 'original-fs'; +import * as fs from 'fs'; import * as path from 'path'; import * as pfs from 'vs/base/node/pfs'; import { memoize } from 'vs/base/common/decorators';