@@ -2,7 +2,7 @@ import Arborist from "@npmcli/arborist";
2
2
import fs from "fs-extra" ;
3
3
import path from "node:path" ;
4
4
import { useLogger } from "~/lib/logger" ;
5
- import { getErrorMessage , inspectValue } from "~/lib/utils" ;
5
+ import { getErrorMessage } from "~/lib/utils" ;
6
6
7
7
/**
8
8
* Generate an isolated / pruned lockfile, based on the contents of installed
@@ -20,28 +20,15 @@ export async function generateNpmLockfile({
20
20
21
21
log . debug ( "Generating NPM lockfile..." ) ;
22
22
23
- const origRootNodeModulesPath = path . join ( workspaceRootDir , "node_modules" ) ;
24
- const tempRootNodeModulesPath = path . join ( isolateDir , "node_modules" ) ;
25
-
26
- let hasMovedNodeModules = false ;
27
-
28
- let hasError = false ;
23
+ const nodeModulesPath = path . join ( workspaceRootDir , "node_modules" ) ;
29
24
30
25
try {
31
- if ( ! fs . existsSync ( origRootNodeModulesPath ) ) {
32
- throw new Error (
33
- `Failed to find node_modules at ${ origRootNodeModulesPath } `
34
- ) ;
26
+ if ( ! fs . existsSync ( nodeModulesPath ) ) {
27
+ throw new Error ( `Failed to find node_modules at ${ nodeModulesPath } ` ) ;
35
28
}
36
29
37
- log . debug ( `Temporarily moving node_modules to the isolate output` ) ;
38
-
39
- await fs . move ( origRootNodeModulesPath , tempRootNodeModulesPath ) ;
40
- hasMovedNodeModules = true ;
41
-
42
30
const arborist = new Arborist ( { path : isolateDir } ) ;
43
31
44
- log . debug ( `Building tree...` ) ;
45
32
const { meta } = await arborist . buildIdealTree ( ) ;
46
33
47
34
meta ?. commit ( ) ;
@@ -52,18 +39,6 @@ export async function generateNpmLockfile({
52
39
53
40
log . debug ( "Created lockfile at" , lockfilePath ) ;
54
41
} catch ( err ) {
55
- console . error ( inspectValue ( err ) ) ;
56
- log . error ( `Failed to generate lockfile: ${ getErrorMessage ( err ) } ` ) ;
57
- hasError = true ;
58
- } finally {
59
- /** @todo We should be able to use the new "using" keyword for this I think. */
60
- if ( hasMovedNodeModules ) {
61
- log . debug ( `Restoring node_modules to the workspace root` ) ;
62
- await fs . move ( tempRootNodeModulesPath , origRootNodeModulesPath ) ;
63
- }
64
- }
65
-
66
- if ( hasError ) {
67
- throw new Error ( "Failed to generate lockfile" ) ;
42
+ throw new Error ( `Failed to generate lockfile: ${ getErrorMessage ( err ) } ` ) ;
68
43
}
69
44
}
0 commit comments