Skip to content

Commit 4e975a1

Browse files
authored
ensure original-fs is used in all our AMD code (microsoft#54468)
1 parent cad1659 commit 4e975a1

6 files changed

Lines changed: 34 additions & 24 deletions

File tree

src/bootstrap-amd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ loader.config({
6969
nodeCachedDataDir: process.env['VSCODE_NODE_CACHED_DATA_DIR_' + process.pid]
7070
});
7171

72+
loader.define('fs', ['original-fs'], function (originalFS) { return originalFS; }); // replace the patched electron fs with the original node fs for all AMD code
73+
7274
if (nlsConfig.pseudo) {
7375
loader(['vs/nls'], function (nlsPlugin) {
7476
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo);

src/vs/code/electron-main/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { IRequestService } from 'vs/platform/request/node/request';
3535
import { RequestService } from 'vs/platform/request/electron-main/requestService';
3636
import { IURLService } from 'vs/platform/url/common/url';
3737
import { URLService } from 'vs/platform/url/common/urlService';
38-
import * as fs from 'original-fs';
38+
import * as fs from 'fs';
3939
import { CodeApplication } from 'vs/code/electron-main/app';
4040
import { HistoryMainService } from 'vs/platform/history/electron-main/historyMainService';
4141
import { IHistoryMainService } from 'vs/platform/history/common/history';

src/vs/code/electron-main/windows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import { basename, normalize, join, dirname } from 'path';
9-
import * as fs from 'original-fs';
9+
import * as fs from 'fs';
1010
import { localize } from 'vs/nls';
1111
import * as arrays from 'vs/base/common/arrays';
1212
import { assign, mixin, equals } from 'vs/base/common/objects';

src/vs/loader.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ var AMDLoader;
212212
return '===anonymous' + (Utilities.NEXT_ANONYMOUS_ID++) + '===';
213213
};
214214
Utilities.isAnonymousModule = function (id) {
215-
return /^===anonymous/.test(id);
215+
return Utilities.startsWith(id, '===anonymous');
216216
};
217217
Utilities.getHighPerformanceTimestamp = function () {
218218
if (!this.PERFORMANCE_NOW_PROBED) {
@@ -811,15 +811,17 @@ var AMDLoader;
811811
errorCode: 'cachedDataRejected',
812812
path: cachedDataPath
813813
});
814-
NodeScriptLoader._runSoon(function () { return _this._fs.unlink(cachedDataPath, function (err) {
815-
if (err) {
816-
moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
817-
errorCode: 'unlink',
818-
path: cachedDataPath,
819-
detail: err
820-
});
821-
}
822-
}); }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
814+
NodeScriptLoader._runSoon(function () {
815+
return _this._fs.unlink(cachedDataPath, function (err) {
816+
if (err) {
817+
moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
818+
errorCode: 'unlink',
819+
path: cachedDataPath,
820+
detail: err
821+
});
822+
}
823+
});
824+
}, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
823825
}
824826
else if (script.cachedDataProduced) {
825827
// data produced => tell outside world
@@ -828,15 +830,17 @@ var AMDLoader;
828830
length: script.cachedData.length
829831
});
830832
// data produced => write cache file
831-
NodeScriptLoader._runSoon(function () { return _this._fs.writeFile(cachedDataPath, script.cachedData, function (err) {
832-
if (err) {
833-
moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
834-
errorCode: 'writeFile',
835-
path: cachedDataPath,
836-
detail: err
837-
});
838-
}
839-
}); }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
833+
NodeScriptLoader._runSoon(function () {
834+
return _this._fs.writeFile(cachedDataPath, script.cachedData, function (err) {
835+
if (err) {
836+
moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
837+
errorCode: 'writeFile',
838+
path: cachedDataPath,
839+
detail: err
840+
});
841+
}
842+
});
843+
}, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
840844
}
841845
};
842846
NodeScriptLoader._runSoon = function (callback, minTimeout) {
@@ -1403,7 +1407,8 @@ var AMDLoader;
14031407
this._knownModules2[moduleId] = true;
14041408
var strModuleId = this._moduleIdProvider.getStrModuleId(moduleId);
14051409
var paths = this._config.moduleIdToPaths(strModuleId);
1406-
if (this._env.isNode && strModuleId.indexOf('/') === -1) {
1410+
var scopedPackageRegex = /^@[^\/]+\/[^\/]+$/; // matches @scope/package-name
1411+
if (this._env.isNode && (strModuleId.indexOf('/') === -1 || scopedPackageRegex.test(strModuleId))) {
14071412
paths.push('node|' + strModuleId);
14081413
}
14091414
var lastPathIndex = -1;
@@ -1649,6 +1654,9 @@ var AMDLoader;
16491654
RequireFunc.getStats = function () {
16501655
return moduleManager.getLoaderEvents();
16511656
};
1657+
RequireFunc.define = function () {
1658+
return DefineFunc.apply(null, arguments);
1659+
};
16521660
function init() {
16531661
if (typeof AMDLoader.global.require !== 'undefined' || typeof require !== 'undefined') {
16541662
var _nodeRequire_1 = (AMDLoader.global.require || require);

src/vs/platform/state/node/stateService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import * as path from 'path';
9-
import * as fs from 'original-fs';
9+
import * as fs from 'fs';
1010
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1111
import { writeFileAndFlushSync } from 'vs/base/node/extfs';
1212
import { isUndefined, isUndefinedOrNull } from 'vs/base/common/types';

src/vs/platform/update/electron-main/updateService.win32.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'use strict';
77

8-
import * as fs from 'original-fs';
8+
import * as fs from 'fs';
99
import * as path from 'path';
1010
import * as pfs from 'vs/base/node/pfs';
1111
import { memoize } from 'vs/base/common/decorators';

0 commit comments

Comments
 (0)