Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
44 lines (42 loc) · 1.76 KB

File metadata and controls

44 lines (42 loc) · 1.76 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
namespace pxt.patching {
export function computePatches(version: string, kind?: string): ts.pxtc.UpgradePolicy[] {
const patches = pxt.appTarget.compile ? pxt.appTarget.compile.patches : undefined;
if (!patches) return undefined;
const v = pxt.semver.tryParse(version || "0.0.0") || pxt.semver.tryParse("0.0.0");
let r: ts.pxtc.UpgradePolicy[] = [];
Object.keys(patches)
.filter(rng => pxt.semver.inRange(rng, v))
.forEach(rng => r = r.concat(patches[rng]));
if (kind)
r = r.filter(p => p.type == kind);
return r.length ? r : undefined;
}
export function upgradePackageReference(pkgTargetVersion: string, pkg: string, val: string): string {
if (val != "*") return pkg;
const upgrades = pxt.patching.computePatches(pkgTargetVersion, "package");
let newPackage = pkg;
if (upgrades) {
upgrades.forEach(rule => {
Object.keys(rule.map).forEach(match => {
if (newPackage == match) {
newPackage = rule.map[match];
}
});
});
}
return newPackage;
}
export function patchJavaScript(pkgTargetVersion: string, fileContents: string): string {
const upgrades = pxt.patching.computePatches(pkgTargetVersion, "api");
let updatedContents = fileContents;
if (upgrades) {
upgrades.forEach(rule => {
for (const match in rule.map) {
const regex = new RegExp(match, 'g');
updatedContents = updatedContents.replace(regex, rule.map[match]);
}
});
}
return updatedContents;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.