@@ -44,7 +44,7 @@ abstract class NpmFormatterStepStateBase implements Serializable {
44
44
private static final long serialVersionUID = 1460749955865959948L ;
45
45
46
46
@ SuppressWarnings ("unused" )
47
- private final FileSignature nodeModulesSignature ;
47
+ private final FileSignature packageJsonSignature ;
48
48
49
49
@ SuppressFBWarnings ("SE_TRANSIENT_FIELD_NOT_RESTORED" )
50
50
public final transient File nodeModulesDir ;
@@ -56,22 +56,26 @@ abstract class NpmFormatterStepStateBase implements Serializable {
56
56
57
57
private final String stepName ;
58
58
59
- protected NpmFormatterStepStateBase (String stepName , NpmConfig npmConfig , File buildDir , @ Nullable File npm ) throws IOException {
59
+ protected NpmFormatterStepStateBase (String stepName , NpmConfig npmConfig , File buildDir ,
60
+ @ Nullable File npm ) throws IOException {
60
61
this .stepName = requireNonNull (stepName );
61
62
this .npmConfig = requireNonNull (npmConfig );
62
63
this .npmExecutable = resolveNpm (npm );
63
64
64
- this .nodeModulesDir = prepareNodeServer (buildDir );
65
- this .nodeModulesSignature = FileSignature .signAsList (this .nodeModulesDir );
65
+ NodeServerLayout layout = prepareNodeServer (buildDir );
66
+ this .nodeModulesDir = layout .nodeModulesDir ();
67
+ this .packageJsonSignature = FileSignature .signAsList (layout .packageJsonFile ());
66
68
}
67
69
68
- private File prepareNodeServer (File buildDir ) throws IOException {
69
- File targetDir = new File (buildDir , "spotless-node-modules-" + stepName );
70
- NpmResourceHelper .assertDirectoryExists (targetDir );
71
- NpmResourceHelper .writeUtf8StringToFile (targetDir , "package.json" , this .npmConfig .getPackageJsonContent ());
72
- NpmResourceHelper .writeUtf8StringToFile (targetDir , "serve.js" , this .npmConfig .getServeScriptContent ());
73
- runNpmInstall (targetDir );
74
- return targetDir ;
70
+ private NodeServerLayout prepareNodeServer (File buildDir ) throws IOException {
71
+ NodeServerLayout layout = new NodeServerLayout (buildDir , stepName );
72
+ NpmResourceHelper .assertDirectoryExists (layout .nodeModulesDir ());
73
+ NpmResourceHelper .writeUtf8StringToFile (layout .packageJsonFile (),
74
+ this .npmConfig .getPackageJsonContent ());
75
+ NpmResourceHelper
76
+ .writeUtf8StringToFile (layout .serveJsFile (), this .npmConfig .getServeScriptContent ());
77
+ runNpmInstall (layout .nodeModulesDir ());
78
+ return layout ;
75
79
}
76
80
77
81
private void runNpmInstall (File npmProjectDir ) throws IOException {
0 commit comments