[Gradle, JS] Use default browsers for wasm
^KT-56585 fixed
This commit is contained in:
committed by
Space Team
parent
b7370f0156
commit
2de4f471e9
+8
-21
@@ -17,12 +17,12 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.distsDirectory
|
||||
import org.jetbrains.kotlin.gradle.report.BuildMetricsService
|
||||
import org.jetbrains.kotlin.gradle.targets.js.addWasmExperimentalArguments
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalDceDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.Companion.kotlinNodeJsExtension
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.karma.KotlinKarma
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackDevtool
|
||||
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
||||
import org.jetbrains.kotlin.gradle.utils.doNotTrackStateCompat
|
||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
||||
import org.jetbrains.kotlin.gradle.utils.relativeOrAbsolute
|
||||
import org.jetbrains.kotlin.gradle.utils.relativeToRoot
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
@@ -60,7 +62,7 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
if (test.testFramework == null) {
|
||||
test.useKarma {
|
||||
if (compilation.platformType == KotlinPlatformType.wasm) {
|
||||
useChromeCanaryHeadlessWasmGc()
|
||||
useChromeHeadlessWasmGc()
|
||||
} else {
|
||||
useChromeHeadless()
|
||||
}
|
||||
@@ -128,27 +130,12 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
task.args.add(0, "serve")
|
||||
task.description = "start ${mode.name.toLowerCaseAsciiOnly()} webpack dev server"
|
||||
|
||||
val openValue = if (compilation.platformType == KotlinPlatformType.wasm) {
|
||||
KotlinWebpackConfig.DevServer.App(
|
||||
KotlinWebpackConfig.DevServer.App.Browser(
|
||||
"chrome canary",
|
||||
listOf(
|
||||
"--js-flags=" +
|
||||
mutableListOf<String>()
|
||||
.apply { addWasmExperimentalArguments() }
|
||||
.joinToString(" ")
|
||||
)
|
||||
),
|
||||
)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
||||
val npmProject = compilation.npmProject
|
||||
task.devServer = KotlinWebpackConfig.DevServer(
|
||||
open = openValue,
|
||||
open = true,
|
||||
static = mutableListOf(
|
||||
"./kotlin",
|
||||
compilation.output.resourcesDir.canonicalPath
|
||||
npmProject.dist.normalize().relativeOrAbsolute(npmProject.dir),
|
||||
compilation.output.resourcesDir.relativeOrAbsolute(npmProject.dir),
|
||||
),
|
||||
client = KotlinWebpackConfig.DevServer.Client(
|
||||
KotlinWebpackConfig.DevServer.Client.Overlay(
|
||||
|
||||
+2
-2
@@ -196,10 +196,10 @@ class KotlinKarma(
|
||||
|
||||
fun useChromeCanaryHeadless() = useChromeLike("ChromeCanaryHeadless")
|
||||
|
||||
fun useChromeCanaryHeadlessWasmGc() {
|
||||
fun useChromeHeadlessWasmGc() {
|
||||
val chromeCanaryHeadlessWasmGc = "ChromeHeadlessWasmGc"
|
||||
|
||||
config.customLaunchers[chromeCanaryHeadlessWasmGc] = CustomLauncher("ChromeCanaryHeadless").apply {
|
||||
config.customLaunchers[chromeCanaryHeadlessWasmGc] = CustomLauncher("ChromeHeadless").apply {
|
||||
flags.add("--js-flags=--experimental-wasm-gc")
|
||||
}
|
||||
|
||||
|
||||
+3
-46
@@ -7,10 +7,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.work.NormalizeLineEndings
|
||||
@@ -142,15 +141,6 @@ data class KotlinWebpackConfig(
|
||||
var warnings: Boolean
|
||||
) : Serializable
|
||||
}
|
||||
|
||||
data class App(
|
||||
var browser: Browser
|
||||
) : Serializable {
|
||||
data class Browser(
|
||||
var name: String,
|
||||
var args: List<String>
|
||||
) : Serializable
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@@ -220,40 +210,7 @@ data class KotlinWebpackConfig(
|
||||
if (devServer == null) return
|
||||
|
||||
appendLine("// dev server")
|
||||
|
||||
if (devServer!!.open !is DevServer.App) {
|
||||
appendLine("config.devServer = ${json(devServer!!)};")
|
||||
} else {
|
||||
val open = devServer!!.open as DevServer.App
|
||||
|
||||
val jsonO = Gson().toJsonTree(devServer!!).asJsonObject
|
||||
|
||||
jsonO.add(
|
||||
"open",
|
||||
JsonObject().apply {
|
||||
add(
|
||||
"app",
|
||||
JsonObject().apply {
|
||||
addProperty("name", "${"$"}browserName${"$"}")
|
||||
add("arguments", Gson().toJsonTree(open.browser.args).asJsonArray)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
//language=ES6
|
||||
appendLine(
|
||||
"""
|
||||
// noinspection JSUnnecessarySemicolon
|
||||
;(function(config) {
|
||||
const apps = require('kotlin-test-js-runner/detect-correct-browser');
|
||||
const browserName = apps[${open.browser.name.jsQuoted()}]
|
||||
config.devServer = ${json(jsonO).replace("\"${"$"}browserName${"$"}\"", "browserName.bin")}
|
||||
})(config);
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
appendLine("config.devServer = ${json(devServer!!)};")
|
||||
appendLine()
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ tasks {
|
||||
"tc-log-appender.js",
|
||||
"tc-log-error-webpack.js",
|
||||
"webpack-5-debug.js",
|
||||
"detect-correct-browser.js",
|
||||
"package.json",
|
||||
"rollup.config.js",
|
||||
"tsconfig.json",
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const isWsl = require('is-wsl');
|
||||
const {platform, arch} = process;
|
||||
|
||||
function detectArchBinary(binary) {
|
||||
if (typeof binary === 'string' || Array.isArray(binary)) {
|
||||
return binary;
|
||||
}
|
||||
|
||||
const {[arch]: archBinary} = binary;
|
||||
|
||||
if (!archBinary) {
|
||||
throw new Error(`${arch} is not supported`);
|
||||
}
|
||||
|
||||
return archBinary;
|
||||
}
|
||||
|
||||
// Return location of chrome.exe file for a given Chrome directory (available: "Chrome", "Chrome SxS").
|
||||
function getChromeExe(chromeDirName) {
|
||||
// Only run these checks on win32
|
||||
if (process.platform !== 'win32') {
|
||||
return null
|
||||
}
|
||||
let windowsChromeDirectory, i, prefix;
|
||||
const suffix = '\\Google\\' + chromeDirName + '\\Application\\chrome.exe';
|
||||
const prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']];
|
||||
|
||||
for (i = 0; i < prefixes.length; i++) {
|
||||
prefix = prefixes[i]
|
||||
try {
|
||||
windowsChromeDirectory = path.join(prefix, suffix)
|
||||
fs.accessSync(windowsChromeDirectory)
|
||||
return windowsChromeDirectory
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
return windowsChromeDirectory
|
||||
}
|
||||
|
||||
function detectPlatformBinary({[platform]: platformBinary}, {wsl}) {
|
||||
if (wsl && isWsl) {
|
||||
return detectArchBinary(wsl);
|
||||
}
|
||||
|
||||
if (!platformBinary) {
|
||||
throw new Error(`${platform} is not supported`);
|
||||
}
|
||||
|
||||
return detectArchBinary(platformBinary);
|
||||
}
|
||||
|
||||
const apps = {};
|
||||
|
||||
function define(browserName, platforms, wsl) {
|
||||
Object.defineProperty(apps, browserName, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: {
|
||||
bin: detectPlatformBinary(platforms, wsl)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
define(
|
||||
'chrome',
|
||||
{
|
||||
darwin: 'google chrome',
|
||||
win32: getChromeExe("Chrome"),
|
||||
linux: ['google-chrome', 'google-chrome-stable']
|
||||
},
|
||||
{
|
||||
wsl: {
|
||||
ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe',
|
||||
x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe']
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
define(
|
||||
'chrome canary',
|
||||
{
|
||||
darwin: 'google chrome canary',
|
||||
win32: getChromeExe("Chrome SxS"),
|
||||
linux: ['google-chrome-canary', 'google-chrome-unstable']
|
||||
},
|
||||
{
|
||||
wsl: {
|
||||
ia32: '/mnt/c/Program Files (x86)/Google/Chrome SxS/Application/chrome.exe',
|
||||
x64: ['/mnt/c/Program Files/Google/Chrome SxS/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome SxS/Application/chrome.exe']
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = apps
|
||||
@@ -14,6 +14,7 @@
|
||||
"build": "rimraf lib/* && copyfiles static/* lib && rollup -c rollup.config.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"format-util": "^1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.12.14",
|
||||
@@ -26,8 +27,6 @@
|
||||
"@rollup/plugin-typescript": "^8.3.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"typescript": "^3.7.2",
|
||||
"format-util": "^1.0.5",
|
||||
"tslib": "^2.3.1",
|
||||
"is-wsl": "^2.2.0"
|
||||
"tslib": "^2.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,14 +97,7 @@ export default [
|
||||
file: 'lib/mocha-kotlin-reporter.js',
|
||||
format: 'cjs'
|
||||
}
|
||||
},
|
||||
{
|
||||
input: './detect-correct-browser.js',
|
||||
output: {
|
||||
file: 'lib/detect-correct-browser.js',
|
||||
format: 'esm'
|
||||
}
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
function plugins() {
|
||||
|
||||
@@ -380,11 +380,6 @@ is-core-module@^2.8.1:
|
||||
dependencies:
|
||||
has "^1.0.3"
|
||||
|
||||
is-docker@^2.0.0:
|
||||
version "2.2.1"
|
||||
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa"
|
||||
integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==
|
||||
|
||||
is-fullwidth-code-point@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d"
|
||||
@@ -402,13 +397,6 @@ is-reference@^1.2.1:
|
||||
dependencies:
|
||||
"@types/estree" "*"
|
||||
|
||||
is-wsl@^2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271"
|
||||
integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==
|
||||
dependencies:
|
||||
is-docker "^2.0.0"
|
||||
|
||||
isarray@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
|
||||
|
||||
Reference in New Issue
Block a user