Skip to content

Commit f98dcfa

Browse files
committed
tidying, fixing tests...
1 parent 1d4dd39 commit f98dcfa

File tree

3 files changed

+36
-106
lines changed

3 files changed

+36
-106
lines changed

src/main/kotlin/com/github/gradle/node/npm/exec/NpmExecSource.kt

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,9 @@ abstract class NpmExecSource @Inject internal constructor(
3232
) : ValueSource<NpmExecResult, NpmExecSource.Parameters> {
3333

3434
abstract class Parameters internal constructor() : NpmExecSpec(), ValueSourceParameters {
35-
// /**
36-
// * The `npm` executable.
37-
// *
38-
// * This could either be a path to the `npm` executable file,
39-
// * or the name of the `PATH` executable.
40-
// */
41-
// abstract val executable: Property<String>
4235
abstract val ignoreExitValue: Property<Boolean>
4336
abstract val workingDir: DirectoryProperty
4437
abstract val npmCommand: ListProperty<String>
45-
// abstract val args: ListProperty<String>
4638
}
4739

4840

@@ -66,8 +58,6 @@ abstract class NpmExecSource @Inject internal constructor(
6658
command = command,
6759
environment = parameters.environment.orNull.orEmpty(),
6860
workingDir = parameters.workingDir.asFile.orNull,
69-
// ignoreExitValue = ignoreExitValue.get(),
70-
// execOverrides = execOverrides.orNull,
7161
)
7262
return executeNpmCommand(nodeExecConfiguration)
7363
}
@@ -76,7 +66,7 @@ abstract class NpmExecSource @Inject internal constructor(
7666
execConfiguration: ExecConfiguration
7767
): Map<String, String> {
7868
return mutableMapOf<String, String>().apply {
79-
if (parameters.includeSystemEnvironment.orNull == true) {
69+
if (parameters.includeSystemEnvironment.getOrElse(true)) {
8070
putAll(System.getenv())
8171
}
8272
putAll(parameters.environment.get())
@@ -94,10 +84,7 @@ abstract class NpmExecSource @Inject internal constructor(
9484

9585

9686
private fun executeNpmCommand(
97-
// project: ProjectApiHelper,
98-
// extension: NodeExtension,
9987
nodeExecConfiguration: NodeExecConfiguration,
100-
// variants: VariantComputer,
10188
): NpmExecResult {
10289
val npmExecConfiguration = NpmExecConfiguration(
10390
command = "npm",
@@ -116,53 +103,26 @@ abstract class NpmExecSource @Inject internal constructor(
116103
val proxiedNodeExecConfiguration = nodeExecConfiguration.copy(environment = proxiedEnvVars)
117104

118105
return executeCommand(
119-
// project = project,
120-
// extension = extension,
121106
nodeExecConfiguration = proxiedNodeExecConfiguration,
122107
npmExecConfiguration = npmExecConfiguration,
123-
// variantComputer = variants
124108
)
125109
}
126110

127-
//private fun executeNpxCommand(
128-
// project: ProjectApiHelper,
129-
// extension: NodeExtension,
130-
// nodeExecConfiguration: NodeExecConfiguration,
131-
// variants: VariantComputer
132-
// ): ExecResult {
133-
// val npxExecConfiguration = NpmExecConfiguration("npx") { variantComputer, parameters, npmBinDir ->
134-
// variantComputer.computeNpxExec(parameters, npmBinDir)
135-
// }
136-
//
137-
// return executeCommand(project, extension, nodeExecConfiguration, npxExecConfiguration, variants)
138-
// }
139-
140111
private fun executeCommand(
141-
// project: ProjectApiHelper? = null,
142-
// extension: NodeExtension,
143112
nodeExecConfiguration: NodeExecConfiguration,
144113
npmExecConfiguration: NpmExecConfiguration,
145-
// variants: VariantComputer,
146114
): NpmExecResult {
147115
val execConfiguration =
148116
computeExecConfiguration(npmExecConfiguration, nodeExecConfiguration)
149-
// val execRunner = ExecRunner()
150-
// return execRunner.execute(project, extension, execConfiguration)
151117

152118
ByteArrayOutputStream().use { capturedOutput ->
153119
val result = execOps.exec {
154120

155121
executable = execConfiguration.executable
156122
args = execConfiguration.args
157123
environment = computeEnvironment(execConfiguration)
158-
// isIgnoreExitValue = execConfiguration.ignoreExitValue
159124
workingDir = computeWorkingDir(nodeProjectDir, execConfiguration)
160-
161-
// executable = parameters.executable.get()
162-
// args = parameters.arguments.orNull.orEmpty()
163-
// environment = computeEnvironment()
164-
isIgnoreExitValue = parameters.ignoreExitValue.getOrElse(false)
165-
// workingDir = parameters.workingDir.get().asFile
125+
isIgnoreExitValue = parameters.ignoreExitValue.getOrElse(true)
166126
standardOutput = capturedOutput
167127
errorOutput = capturedOutput
168128
}
@@ -183,15 +143,11 @@ abstract class NpmExecSource @Inject internal constructor(
183143
}
184144

185145
private fun computeExecConfiguration(
186-
// extension: NodeExtension,
187146
npmExecConfiguration: NpmExecConfiguration,
188147
nodeExecConfiguration: NodeExecConfiguration,
189148
): ExecConfiguration {
190149
val additionalBinPath = computeAdditionalBinPath()
191150
val executableAndScript = computeExecutable(npmExecConfiguration)
192-
// return zip(additionalBinPathProvider, executableAndScriptProvider)
193-
// .map { (additionalBinPath, executableAndScript) ->
194-
// }
195151
val argsPrefix =
196152
if (executableAndScript.script != null) listOf(executableAndScript.script) else listOf()
197153
val args = argsPrefix.plus(nodeExecConfiguration.command)
@@ -201,15 +157,12 @@ abstract class NpmExecSource @Inject internal constructor(
201157
additionalBinPaths = additionalBinPath,
202158
environment = nodeExecConfiguration.environment,
203159
workingDir = nodeExecConfiguration.workingDir,
204-
// ignoreExitValue = nodeExecConfiguration.ignoreExitValue,
205160
execOverrides = nodeExecConfiguration.execOverrides,
206161
)
207162
}
208163

209164
private fun computeExecutable(
210-
// parameters: NodeExtension,
211165
npmExecConfiguration: NpmExecConfiguration,
212-
// variantComputer: VariantComputer
213166
): ExecutableAndScript {
214167
val nodeDirProvider = parameters.resolvedNodeDir.get()
215168
val npmDirProvider = computeNpmDir(nodeDirProvider)
@@ -316,25 +269,11 @@ abstract class NpmExecSource @Inject internal constructor(
316269
*/
317270
private fun computeNpmExec(npmBinDirProvider: Directory): String {
318271
return computeExec(
319-
// nodeExtension = nodeExtension,
320272
binDirProvider = npmBinDirProvider,
321273
configurationCommand = npmCommand.single(),
322274
)
323275
}
324276

325-
// /**
326-
// * Get the expected node binary name, npx.cmd on Windows and npx everywhere else.
327-
// *
328-
// * Can be overridden by setting npxCommand.
329-
// */
330-
//private fun computeNpxExec(nodeExtension: NodeExtension, npmBinDirProvider: Directory): Provider<String> {
331-
// return computeExec(
332-
// nodeExtension,
333-
// npmBinDirProvider,
334-
// parameters.npxCommand, "npx", "npx.cmd"
335-
// )
336-
// }
337-
338277
/**
339278
* Compute the path for a given command, from a given binary directory, taking Windows into account
340279
*/
@@ -374,21 +313,12 @@ abstract class NpmExecSource @Inject internal constructor(
374313
val additionalBinPaths: List<String> = listOf(),
375314
val environment: Map<String, String> = mapOf(),
376315
val workingDir: File? = null,
377-
// val ignoreExitValue: Boolean = false,
378316
val execOverrides: Action<ExecSpec>? = null
379317
)
380318

381-
// internal typealias CommandExecComputer = (
382-
// variantComputer: VariantComputer,
383-
// nodeExtension: NodeExtension,
384-
// npmBinDir: Provider<Directory>,
385-
// ) -> Provider<String>
386-
387319
private data class NpmExecConfiguration(
388320
val command: String,
389321
val commandExecComputer: (
390-
// variantComputer: VariantComputer,
391-
// nodeExtension: NodeExtension,
392322
npmBinDir: Directory,
393323
) -> String,
394324
)
@@ -414,13 +344,10 @@ abstract class NpmExecSource @Inject internal constructor(
414344
}
415345
}
416346

417-
418347
private data class NodeExecConfiguration(
419348
val command: List<String> = listOf(),
420349
val environment: Map<String, String> = mapOf(),
421350
val workingDir: File? = null,
422-
// val ignoreExitValue: Boolean = false,
423351
val execOverrides: Action<ExecSpec>? = null
424352
)
425-
426353
}

src/main/kotlin/com/github/gradle/node/npm/task/NpmTask.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ abstract class NpmTask : BaseTask() {
8282
// parameters.npmCommand.set(nodeExtension.npmCommand)
8383
// parameters.args.set(args)
8484
}
85-
val result = npmExec.get().asExecResult()
86-
result.rethrowFailure()
87-
this.result = result
85+
val result = npmExec.get()
86+
if (result.failure != null) {
87+
logger.error(result.capturedOutput)
88+
throw RuntimeException("$path failed to execute npm command.", result.failure)
89+
}
90+
this.result = result.asExecResult()
8891
// val command = npmCommand.get().plus(args.get())
8992
// val nodeExecConfiguration =
9093
// NodeExecConfiguration(

0 commit comments

Comments
 (0)