diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index d5ac3bf6424..45a4da2b44a 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -157,8 +157,8 @@ class K2JSCompilerArguments : CommonCompilerArguments() { @Argument(value = "-Xir-per-module", description = "Splits generated .js per-module") var irPerModule: Boolean by FreezableVar(false) - @Argument(value = "-Xir-per-module-prefix", description = "Adds a custom prefix to the splitted js files") - var irPerModulePrefix: String? by NullableStringFreezableVar(null) + @Argument(value = "-Xir-per-module-output-name", description = "Adds a custom output name to the splitted js files") + var irPerModuleOutputName: String? by NullableStringFreezableVar(null) @Argument( value = "-Xinclude", diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index 8a15a29cba7..603482633da 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -207,8 +207,7 @@ class K2JsIrCompiler : CLICompiler() { irFactory = PersistentIrFactory(), // TODO IrFactoryImpl? outputKlibPath = outputFile.path, nopack = arguments.irProduceKlibDir, - jsOutputName = moduleName - .substringAfterLast(":"), + jsOutputName = arguments.irPerModuleOutputName, ) } @@ -277,7 +276,6 @@ class K2JsIrCompiler : CLICompiler() { relativeRequirePath = true, propertyLazyInitialization = arguments.irPropertyLazyInitialization, legacyPropertyAccess = arguments.irLegacyPropertyAccess, - irPerModulePrefix = arguments.irPerModulePrefix ) val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!! diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index e101fa408ce..1a84a4949a0 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -53,7 +53,6 @@ fun compile( relativeRequirePath: Boolean = false, propertyLazyInitialization: Boolean, legacyPropertyAccess: Boolean = false, - irPerModulePrefix: String? = null, ): CompilerResult { val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) = loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, irFactory, forceAllJs) @@ -112,7 +111,6 @@ fun compile( multiModule = multiModule, relativeRequirePath = relativeRequirePath, moduleToName = moduleToName, - irPerModulePrefix = irPerModulePrefix, ) return transformer.generateModule(allModules) } else { @@ -125,7 +123,6 @@ fun compile( multiModule = multiModule, relativeRequirePath = relativeRequirePath, moduleToName = moduleToName, - irPerModulePrefix = irPerModulePrefix, ) return transformer.generateModule(allModules) } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrModuleToJsTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrModuleToJsTransformer.kt index dca47a9a37b..620c9c28df7 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrModuleToJsTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrModuleToJsTransformer.kt @@ -33,7 +33,6 @@ class IrModuleToJsTransformer( private val multiModule: Boolean = false, private val relativeRequirePath: Boolean = false, private val moduleToName: Map = emptyMap(), - private val irPerModulePrefix: String? = null, ) { private val generateRegionComments = backendContext.configuration.getBoolean(JSConfigurationKeys.GENERATE_REGION_COMMENTS) @@ -193,7 +192,7 @@ class IrModuleToJsTransformer( } private fun IrModuleFragment.externalModuleName(): String { - return (irPerModulePrefix ?: "") + (moduleToName[this] ?: sanitizeName(safeName)) + return moduleToName[this] ?: sanitizeName(safeName) } private fun generateCrossModuleImports( diff --git a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt index 39d2ce01e85..02d85149bd5 100644 --- a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt +++ b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt @@ -70,7 +70,6 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.utils.DFS import java.io.File -import java.util.* import org.jetbrains.kotlin.konan.file.File as KFile val KotlinLibrary.moduleName: String @@ -243,7 +242,8 @@ fun loadIr( JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns) } val moduleFragmentToUniqueName = mutableMapOf() - val irLinker = JsIrLinker(psi2IrContext.moduleDescriptor, messageLogger, irBuiltIns, symbolTable, functionFactory, feContext, null) + val irLinker = + JsIrLinker(psi2IrContext.moduleDescriptor, messageLogger, irBuiltIns, symbolTable, functionFactory, feContext, null) val deserializedModuleFragments = sortDependencies(allDependencies.getFullList(), depsDescriptors.descriptors).map { klib -> irLinker.deserializeIrModuleHeader(depsDescriptors.getModuleDescriptor(klib), klib).also { moduleFragment -> klib.manifestProperties.getProperty(KLIB_PROPERTY_JS_OUTPUT_NAME)?.let { @@ -319,7 +319,11 @@ private fun runAnalysisAndPreparePsi2Ir( Psi2IrConfiguration(errorIgnorancePolicy.allowErrors) ) val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory) - return psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable) to analysisResult.hasErrors + return psi2Ir.createGeneratorContext( + analysisResult.moduleDescriptor, + analysisResult.bindingContext, + symbolTable + ) to analysisResult.hasErrors } fun GeneratorContext.generateModuleFragmentWithPlugins( @@ -571,20 +575,20 @@ fun serializeModuleIntoKlib( } } - buildKotlinLibrary( - linkDependencies = dependencies, - ir = fullSerializedIr, - metadata = serializedMetadata, - dataFlowGraph = null, - manifestProperties = properties, - moduleName = moduleName, - nopack = nopack, - perFile = perFile, - output = klibPath, - versions = versions, - builtInsPlatform = BuiltInsPlatform.JS - ) - } + buildKotlinLibrary( + linkDependencies = dependencies, + ir = fullSerializedIr, + metadata = serializedMetadata, + dataFlowGraph = null, + manifestProperties = properties, + moduleName = moduleName, + nopack = nopack, + perFile = perFile, + output = klibPath, + versions = versions, + builtInsPlatform = BuiltInsPlatform.JS + ) +} const val KLIB_PROPERTY_JS_OUTPUT_NAME = "jsOutputName" @@ -617,11 +621,12 @@ private fun compareMetadataAndGoToNextICRoundIfNeeded( if (nextRoundChecker.shouldGoToNextRound()) throw IncrementalNextRoundException() } -private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfiguration, project: Project, allowErrors: Boolean) = KlibMetadataIncrementalSerializer( - languageVersionSettings = configuration.languageVersionSettings, - metadataVersion = configuration.metadataVersion, - project = project, - exportKDoc = false, - skipExpects = !configuration.expectActualLinker, - allowErrorTypes = allowErrors -) +private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfiguration, project: Project, allowErrors: Boolean) = + KlibMetadataIncrementalSerializer( + languageVersionSettings = configuration.languageVersionSettings, + metadataVersion = configuration.metadataVersion, + project = project, + exportKDoc = false, + skipExpects = !configuration.expectActualLinker, + allowErrorTypes = allowErrors + ) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/CompilerFlags.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/CompilerFlags.kt index c8132d950cf..04bc081f60d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/CompilerFlags.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/CompilerFlags.kt @@ -24,5 +24,7 @@ internal const val PRODUCE_ZIPPED_KLIB = "-Xir-produce-klib-file" internal const val MODULE_NAME = "-Xir-module-name" +internal const val PER_MODULE_OUTPUT_NAME = "-Xir-per-module-output-name" + fun KotlinJsOptions.isProduceUnzippedKlib() = PRODUCE_UNZIPPED_KLIB in freeCompilerArgs fun KotlinJsOptions.isProduceZippedKlib() = PRODUCE_ZIPPED_KLIB in freeCompilerArgs \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrSubTarget.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrSubTarget.kt index fa05b726f94..c2e1da4009d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrSubTarget.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrSubTarget.kt @@ -58,6 +58,13 @@ abstract class KotlinJsIrSubTarget( internal fun configure() { NpmResolverPlugin.apply(project) + target.compilations.all { + val npmProject = it.npmProject + it.kotlinOptions { + freeCompilerArgs += "$PER_MODULE_OUTPUT_NAME=${npmProject.name}" + } + } + configureTests() }