-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathreact-navigation-versions.mjs
More file actions
96 lines (84 loc) · 2.64 KB
/
react-navigation-versions.mjs
File metadata and controls
96 lines (84 loc) · 2.64 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
const CACHE_DIR = join(
process.cwd(),
'node_modules',
'.cache',
'react-navigation-versions'
);
const query = async (name, tag) => {
const cached = join(CACHE_DIR, `${name}-${tag}.json`);
let pkg;
try {
pkg = await fetch(`https://registry.npmjs.org/${name}/${tag}`).then((res) =>
res.json()
);
await mkdir(dirname(cached), { recursive: true });
await writeFile(cached, JSON.stringify(pkg));
} catch (e) {
const data = await readFile(cached, 'utf-8');
pkg = JSON.parse(data);
}
return pkg;
};
export default function reactNavigationVersionsPlugin(context, options) {
return {
name: 'react-navigation-versions',
async contentLoaded({ content, actions }) {
const queries = {
'8.x': {
tag: 'next',
packages: [
'@react-navigation/bottom-tabs',
'@react-navigation/core',
'@react-navigation/drawer',
'@react-navigation/elements',
'@react-navigation/material-top-tabs',
'@react-navigation/native-stack',
'@react-navigation/native',
'@react-navigation/routers',
'@react-navigation/stack',
'react-native-drawer-layout',
'react-native-tab-view',
],
},
'7.x': {
tag: 'latest',
packages: [
'@react-navigation/bottom-tabs',
'@react-navigation/core',
'@react-navigation/drawer',
'@react-navigation/elements',
'@react-navigation/material-top-tabs',
'@react-navigation/native-stack',
'@react-navigation/native',
'@react-navigation/routers',
'@react-navigation/stack',
'react-native-drawer-layout',
'react-native-tab-view',
],
},
};
const versions = Object.fromEntries(
await Promise.all(
Object.entries(queries).map(async ([version, { tag, packages }]) => {
const items = await Promise.all(
packages.map(async (name) => {
const pkg = await query(name, tag);
const peers = Object.fromEntries(
Object.entries(pkg.peerDependencies || {}).map(([name]) => [
name,
'*',
])
);
return [name, [pkg.version, peers]];
})
);
return [version, Object.fromEntries(items)];
})
)
);
actions.setGlobalData({ versions });
},
};
}