-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
ensure-repo.ts
45 lines (37 loc) · 1.2 KB
/
ensure-repo.ts
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
37
38
39
40
41
42
43
44
45
import * as path from 'path';
import * as fs from 'fs-extra';
import { writePackageData } from '@jupyterlab/buildutils';
/**
* Ensure the application package resolutions.
*/
function ensureResolutions(): string[] {
const basePath = path.resolve('.');
const corePath = path.join(basePath, 'app', 'package.json');
const corePackage = fs.readJSONSync(corePath);
corePackage.resolutions = {};
const packages = Object.keys(corePackage.dependencies).concat(
corePackage.jupyterlab.singletonPackages
);
packages.forEach(async (name) => {
let version = '';
try {
const data = require(`${name}/package.json`);
version = data.version;
} catch {
const modulePath = require.resolve(name);
const parentDir = path.dirname(path.dirname(modulePath));
const data = require(path.join(parentDir, 'package.json'));
version = data.version;
}
// Insist on a restricted version in the yarn resolution.
corePackage.resolutions[name] = `~${version}`;
});
// Write the package.json back to disk.
if (writePackageData(corePath, corePackage)) {
return ['Updated dev mode'];
}
return [];
}
if (require.main === module) {
void ensureResolutions();
}