Fix js quoted strings for Windows
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js
|
||||
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import java.io.StringWriter
|
||||
|
||||
fun String.jsQuoted(): String = StringWriter().also {
|
||||
JsonWriter(it).value(this)
|
||||
}.toString()
|
||||
+3
-2
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.targets.js.NpmPackageVersion
|
||||
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||
import org.jetbrains.kotlin.gradle.targets.js.appendConfigsFromDir
|
||||
import org.jetbrains.kotlin.gradle.targets.js.internal.parseNodeJsStackTraceAsJvm
|
||||
import org.jetbrains.kotlin.gradle.targets.js.jsQuoted
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.*
|
||||
@@ -238,10 +239,10 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
||||
val adapterJs = npmProject.dir.resolve("adapter.js")
|
||||
adapterJs.printWriter().use { writer ->
|
||||
val karmaRunner = npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js")
|
||||
writer.println("require('$karmaRunner')")
|
||||
writer.println("require(${karmaRunner.jsQuoted()})")
|
||||
|
||||
files.forEach { file ->
|
||||
writer.println("require('$file')")
|
||||
writer.println("require(${file.jsQuoted()})")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-10
@@ -8,10 +8,10 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import org.jetbrains.kotlin.gradle.targets.js.NpmPackageVersion
|
||||
import org.jetbrains.kotlin.gradle.targets.js.NpmVersions
|
||||
import org.jetbrains.kotlin.gradle.targets.js.appendConfigsFromDir
|
||||
import org.jetbrains.kotlin.gradle.targets.js.jsQuoted
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
import java.io.StringWriter
|
||||
@@ -127,7 +127,7 @@ data class KotlinWebpackConfig(
|
||||
private fun Appendable.appendEvaluatedFileReport() {
|
||||
if (reportEvaluatedConfigFile == null) return
|
||||
|
||||
val filePath = jsQuotedString(reportEvaluatedConfigFile.canonicalPath)
|
||||
val filePath = reportEvaluatedConfigFile.canonicalPath.jsQuoted()
|
||||
|
||||
//language=JavaScript 1.8
|
||||
appendln(
|
||||
@@ -210,10 +210,10 @@ data class KotlinWebpackConfig(
|
||||
"""
|
||||
// entry
|
||||
if (!config.entry) config.entry = [];
|
||||
config.entry.push(${jsQuotedString(entry.canonicalPath)});
|
||||
config.entry.push(${entry.canonicalPath.jsQuoted()});
|
||||
config.output = {
|
||||
path: ${jsQuotedString(outputPath.canonicalPath)},
|
||||
filename: ${jsQuotedString(outputFileName!!)}
|
||||
path: ${outputPath.canonicalPath.jsQuoted()},
|
||||
filename: ${outputFileName!!.jsQuoted()}
|
||||
};
|
||||
|
||||
""".trimIndent()
|
||||
@@ -232,7 +232,7 @@ data class KotlinWebpackConfig(
|
||||
const handler = (percentage, message, ...args) => {
|
||||
let msg = Math.trunc(percentage * 100) + '% ' + message + ' ' + args.join(' ');
|
||||
${if (progressReporterPathFilter == null) "" else """
|
||||
msg = msg.replace(new RegExp(${jsQuotedString(progressReporterPathFilter)}, 'g'), '');
|
||||
msg = msg.replace(new RegExp(${progressReporterPathFilter.jsQuoted()}, 'g'), '');
|
||||
""".trimIndent()};
|
||||
console.log(msg);
|
||||
};
|
||||
@@ -247,8 +247,4 @@ data class KotlinWebpackConfig(
|
||||
private fun json(obj: Any) = StringWriter().also {
|
||||
GsonBuilder().setPrettyPrinting().create().toJson(obj, it)
|
||||
}.toString()
|
||||
|
||||
private fun jsQuotedString(str: String) = StringWriter().also {
|
||||
JsonWriter(it).value(str)
|
||||
}.toString()
|
||||
}
|
||||
Reference in New Issue
Block a user