@@ -44,7 +44,7 @@ abstract class NpmFormatterStepStateBase implements Serializable {
4444 private static final long serialVersionUID = 1460749955865959948L ;
4545
4646 @ SuppressWarnings ("unused" )
47- private final FileSignature nodeModulesSignature ;
47+ private final FileSignature packageJsonSignature ;
4848
4949 @ SuppressFBWarnings ("SE_TRANSIENT_FIELD_NOT_RESTORED" )
5050 public final transient File nodeModulesDir ;
@@ -56,22 +56,26 @@ abstract class NpmFormatterStepStateBase implements Serializable {
5656
5757 private final String stepName ;
5858
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 {
6061 this .stepName = requireNonNull (stepName );
6162 this .npmConfig = requireNonNull (npmConfig );
6263 this .npmExecutable = resolveNpm (npm );
6364
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 ());
6668 }
6769
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 ;
7579 }
7680
7781 private void runNpmInstall (File npmProjectDir ) throws IOException {
0 commit comments