ensure original-fs is used in all our AMD code (#54468)

This commit is contained in:
Benjamin Pasero
2018-07-17 12:53:27 +02:00
committed by GitHub
parent cad1659a76
commit 4e975a1beb
6 changed files with 34 additions and 24 deletions
+2
View File
@@ -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);
+1 -1
View File
@@ -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';
+1 -1
View File
@@ -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';
+28 -20
View File
@@ -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);
+1 -1
View File
@@ -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';
@@ -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';