forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostInstall.js
More file actions
36 lines (36 loc) · 1.82 KB
/
postInstall.js
File metadata and controls
36 lines (36 loc) · 1.82 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';
Object.defineProperty(exports, "__esModule", { value: true });
const colors = require("colors/safe");
const fs = require("fs");
const path = require("path");
const constants_1 = require("../constants");
/**
* In order to compile the extension in strict mode, one of the dependencies (@jupyterlab) has some files that
* just won't compile in strict mode.
* Unfortunately we cannot fix it by overriding their type definitions
* Note: that has been done for a few of the JupyterLabl files (see typings/index.d.ts).
* The solution is to modify the type definition file after `npm install`.
*/
function fixJupyterLabDTSFiles() {
const relativePath = path.join('node_modules', '@jupyterlab', 'coreutils', 'lib', 'settingregistry.d.ts');
const filePath = path.join(constants_1.ExtensionRootDir, relativePath);
if (!fs.existsSync(filePath)) {
throw new Error(`Type Definition file from JupyterLab not found '${filePath}' (pvsc post install script)`);
}
const fileContents = fs.readFileSync(filePath, { encoding: 'utf8' });
if (fileContents.indexOf('[key: string]: ISchema | undefined;') > 0) {
// tslint:disable-next-line:no-console
console.log(colors.blue(`${relativePath} file already updated (by Python VSC)`));
return;
}
const replacedText = fileContents.replace('[key: string]: ISchema;', '[key: string]: ISchema | undefined;');
if (fileContents === replacedText) {
throw new Error('Fix for JupyterLabl file \'settingregistry.d.ts\' failed (pvsc post install script)');
}
fs.writeFileSync(filePath, replacedText);
// tslint:disable-next-line:no-console
console.log(colors.green(`${relativePath} file updated (by Python VSC)`));
}
fixJupyterLabDTSFiles();