-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreinstall.task.ts
More file actions
39 lines (34 loc) · 1.57 KB
/
Copy pathreinstall.task.ts
File metadata and controls
39 lines (34 loc) · 1.57 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
import { z } from 'zod';
import { rm } from 'node:fs/promises';
import type { Task } from './task.ts';
import { install_with_cache_healing_or_throw } from './npm_install_helpers.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\``);
await install_with_cache_healing_or_throw(config.pm_cli, { log, context: '(initial)' });
// 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...`
);
await install_with_cache_healing_or_throw(config.pm_cli, {
log,
context: `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}`);
await install_with_cache_healing_or_throw(config.pm_cli, { log });
}
};