forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixNodeFetch.js
More file actions
36 lines (32 loc) · 1.13 KB
/
fixNodeFetch.js
File metadata and controls
36 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
const path = require('path');
const constants = require('../../constants');
const nodeFetchIndexFile = path.join(
constants.ExtensionRootDir,
'node_modules',
'@jupyterlab',
'services',
'node_modules',
'node-fetch',
'lib',
'index.js'
);
// On windows replace `\` with `\\`, else we get an error in webpack (Module parse failed: Octal literal in strict mode).
const nodeFetchFile = constants.isWindows ? nodeFetchIndexFile.replace(/\\/g, '\\\\') : nodeFetchIndexFile;
/**
* Node fetch has an es6 module file. That gets bundled into @jupyterlab/services.
* However @jupyterlab/services/serverconnection.js is written such that it uses fetch from either node or browser.
* We need to force the browser version for things to work correctly.
*
* @export
* @param {string} source
* @returns
*/
exports.default = function (source) {
if (source.indexOf("require('node-fetch')") > 0) {
source = source.replace(/require\('node-fetch'\)/g, `require('${nodeFetchFile}')`);
}
return source;
};