Repository navigation
Expand file tree
/
Copy pathupdate.ts
More file actions
91 lines (75 loc) · 2.76 KB
/
Copy pathupdate.ts
File metadata and controls
91 lines (75 loc) · 2.76 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
import type { Context } from '../../models/context';
import type { CommandResult } from '../../models/command';
import { getLatestPackageVersion } from '../../utils/commands/dependencies/getLatestPackageVersion';
import { migrate } from '../../utils/commands/dependencies/migrate';
import { updatePackageJson } from './updatePackageJson';
import { checkVersions } from '../../utils/commands/dependencies/checkVersions';
import moduleVersion from '../../utils/moduleVersion';
import { findTramvaiVersion } from '../../utils/commands/dependencies/findTramvaiVersion';
export type Params = {
to: string;
tag?: boolean;
};
export default async (
context: Context,
{ to: version = 'latest', tag }: Params
): Promise<CommandResult> => {
const registry = await context.packageManager.getRegistryUrl();
const resolvedVersion = tag
? version
: await getLatestPackageVersion('@tramvai/cli', registry, version);
const currentVersion = await findTramvaiVersion();
if (!currentVersion) {
throw new Error(
'Could not resolve tramvai version from package.json. Do you have @tramvai/core installed?'
);
}
if (currentVersion === version || currentVersion === resolvedVersion) {
throw new Error(
'The installed version is equal to the current version, no update is required.'
);
}
context.logger.event({
type: 'info',
event: 'resolving-version',
message: `Next tramvai version resolved to ${tag ? 'tag' : 'version'} "${resolvedVersion}", current version is "${currentVersion}"`,
});
if (context.packageManager.workspaces) {
await Promise.all(
context.packageManager.workspaces.map((directory) =>
updatePackageJson(version, resolvedVersion, currentVersion, registry, tag, directory)
)
);
}
await updatePackageJson(version, resolvedVersion, currentVersion, registry, tag);
context.logger.event({
type: 'info',
event: 'install',
message: 'Installing dependencies',
});
await context.packageManager.install({ stdio: 'inherit' });
// todo если с --tag то для npm надо запустить `npm update --no-save`
if (context.packageManager.name !== 'npm') {
// npm dedupe is extremely slow in most cases
// so execute it only for yarn
context.logger.event({
type: 'info',
event: 'dedupe',
message: 'Deduplicate dependencies',
});
await context.packageManager.dedupe({ stdio: 'inherit' });
}
await migrate(context);
await checkVersions(context);
if (context.packageManager.name === 'npm') {
context.logger.event({
type: 'warning',
event: 'dedupe',
message:
'To make sure the node_modules tree is optimized you can additionaly run `npm dedupe` command',
});
}
return Promise.resolve({
status: 'ok',
});
};