-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Gradle][K/JS] skip npm install task execution while in offline mode #5410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,12 +141,12 @@ class Npm internal constructor( | |
) { | ||
val progressLogger = objects.newBuildOpLogger() | ||
execWithProgress(progressLogger, description, execOps = execOps) { execSpec -> | ||
val arguments: List<String> = mutableListOf<String>().apply { | ||
val arguments = buildList { | ||
add("install") | ||
addAll(args) | ||
addAll(args.filter(String::isNotEmpty)) | ||
if (logger.isDebugEnabled) add("--verbose") | ||
if (environment.ignoreScripts) add("--ignore-scripts") | ||
}.filter { it.isNotEmpty() } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we leave it there for cases when someone will pass empty arguments in the list? Before, it was used so we can write code like this: listOf(
if (something) test else ""
) Later, it was migrated to the approach with mutableList, but filter is still in place. |
||
} | ||
|
||
if (!environment.standalone) { | ||
val nodeExecutable = nodeJs.nodeExecutable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,15 @@ abstract class KotlinNpmInstallTask : | |
@get:Internal | ||
abstract val nodeModules: DirectoryProperty | ||
|
||
private val isOffline = project.gradle.startParameter.isOffline() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
@TaskAction | ||
fun resolve() { | ||
val args = buildList { | ||
addAll(args) | ||
if (isOffline) add("--offline") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I also ask you to introduce a test for this logic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I would love to cover this with tests, but where can I see some examples? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have integration tests for the Gradle plugin. You can explore the JS-specific here: https://github.com/JetBrains/kotlin/blob/master/libraries%2Ftools%2Fkotlin-gradle-plugin-integration-tests%2Fsrc%2Ftest%2Fkotlin%2Forg%2Fjetbrains%2Fkotlin%2Fgradle%2FKotlin2JsGradlePluginIT.kt The rest of the integration tests are located in the same Gradle sub-project |
||
} | ||
|
||
npmResolutionManager.get() | ||
.installIfNeeded( | ||
args = args, | ||
|
@@ -56,4 +63,4 @@ abstract class KotlinNpmInstallTask : | |
companion object { | ||
const val NAME = "kotlinNpmInstall" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are quite unrelated to what I generally do in this PR, so I can either revert them or submit a different PR, or leave them