-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreinstall.task.ts
More file actions
45 lines (40 loc) · 1.82 KB
/
reinstall.task.ts
File metadata and controls
45 lines (40 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
37
38
39
40
41
42
43
44
45
import {z} from 'zod';
import {spawn} from '@fuzdev/fuz_util/process.js';
import {rm} from 'node:fs/promises';
import {TaskError, type Task} from './task.ts';
import {LOCKFILE_FILENAME, NODE_MODULES_DIRNAME} from './constants.ts';
/** @nodocs */
export const Args = z.strictObject({});
export type Args = z.infer<typeof Args>;
/** @nodocs */
export const task: Task<Args> = {
summary: `refreshes ${LOCKFILE_FILENAME} with the latest and cleanest deps`,
Args,
run: async ({log, config}): Promise<void> => {
log.info(`running the initial \`${config.pm_cli} install\``);
const initial_install_result = await spawn(config.pm_cli, ['install']);
if (!initial_install_result.ok) {
throw new TaskError(`Failed initial \`${config.pm_cli} install\``);
}
// Deleting both the lockfile and node_modules upgrades to the latest minor/patch versions.
await Promise.all([rm(LOCKFILE_FILENAME), rm(NODE_MODULES_DIRNAME, {recursive: true})]);
log.info(
`running \`${config.pm_cli} install\` after deleting ${LOCKFILE_FILENAME} and ${NODE_MODULES_DIRNAME}, this can take a while...`,
);
const second_install_result = await spawn(config.pm_cli, ['install']);
if (!second_install_result.ok) {
throw new TaskError(
`Failed \`${config.pm_cli} install\` after deleting ${LOCKFILE_FILENAME} and ${NODE_MODULES_DIRNAME}`,
);
}
// TODO @many this relies on npm behavior that changed in v11
// Deleting the lockfile and reinstalling cleans the lockfile of unnecessary dep noise,
// like esbuild's many packages for each platform.
await rm(LOCKFILE_FILENAME);
log.info(`running \`${config.pm_cli} install\` one last time to clean ${LOCKFILE_FILENAME}`);
const final_install_result = await spawn(config.pm_cli, ['install']);
if (!final_install_result.ok) {
throw new TaskError(`Failed \`${config.pm_cli} install\``);
}
},
};