Skip to content

Commit

Permalink
Issue bertramdev#287: Fix path issues with nested imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Long committed Nov 25, 2021
1 parent 6530a12 commit 641f10f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
39 changes: 24 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ ext {
group = 'com.bertramlabs.plugins'

repositories {
jcenter()
mavenCentral()
}

java {
withJavadocJar()
withSourcesJar()
}

//if (isReleaseVersion) {
// apply plugin: "io.github.gradle-nexus.publish-plugin"
// nexusPublishing {
Expand All @@ -45,20 +49,25 @@ repositories {
// }
// }
//} else {
publishing {
repositories {
maven {
url = project.hasProperty('labsNexusUrl') ? labsNexusUrl : "https://nexus.bertramlabs.com/content/repositories/snapshots"
if(project.hasProperty('labsNexusUser')) {
credentials {
username = labsNexusUser
password = labsNexusPassword
}
}
}
}
}
//}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
url = project.hasProperty('labsNexusUrl') ? labsNexusUrl : "https://nexus.bertramlabs.com/content/repositories/snapshots"
if(project.hasProperty('labsNexusUser')) {
credentials {
username = labsNexusUser
password = labsNexusPassword
}
}
}
}
}

subprojects { project ->
if (project.name != 'asset-pipeline-classpath-test' && project.name != 'asset-pipeline-docs' && project.name != 'asset-pipeline-site') {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=3.3.6.TRITON.1
version=3.3.6.TRITON.2
org.gradle.warning.mode=none
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,53 @@ class SassAssetFileLoader {

AssetFile baseFile

Map<String, String> importMap = [:]

SassAssetFileLoader(AssetFile assetFile) {
this.baseFile = assetFile
}

/**
* Java callback function for the dart-sass Importer API
* https://sass-lang.com/documentation/js-api/interfaces/LegacySharedOptions#importer
*
* @param url the import it appears in the source file
* @prev either 'stdin' for the first level imports or the original url from the parent for nested
* @param assetFilePath the original assetFile.path that started the import chain
* @return https://sass-lang.com/documentation/js-api/modules#LegacyImporterResult
*/
@V8Function
@SuppressWarnings('unused')
Map resolveImport(String url, String prev, String assetFilePath) {
println "Import - Url=$url, Prev=$prev, AssetFilePath=$assetFilePath"
log.debug("resolving import for url [{}], prev [{}], asset file path [{}]", url, prev, assetFilePath)
println " > Importing [${url}], prev [$prev], asset file [${assetFilePath}]"

Path filePath = Paths.get(assetFilePath)
// The initial import has a path of stdin, but we need to convert that to the proper base path
// Otherwise, if we have a parent, append that to form the correct URL as the importer syntax doesn't send what's expected
if (prev == 'stdin') {
prev = assetFilePath
}
else if (filePath.parent) {
prev = "${filePath.parent.toString()}/${prev}"
else {
// Resolve the real base path for this import
String priorParent = importMap.find { it.value == prev }?.key
if (priorParent) {
Path priorParentPath = Paths.get(priorParent)
if (priorParentPath.parent) {
prev = "${priorParentPath.parent.toString()}/${prev}"
}
}
}

importMap[prev] = url

AssetFile imported = getAssetFromScssImport(prev, url)
[contents: imported.inputStream.text]
return [contents: imported.inputStream.text]
}

/**
* Find the real file name to be resolved to a AssetFile instance
* This method tries to resolve path/to/imported.scss and path/to/_imported.scss
*
* @param url
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package asset.pipeline.dart
import asset.pipeline.AbstractProcessor
import asset.pipeline.AssetCompiler
import asset.pipeline.AssetFile
import asset.pipeline.fs.FileSystemAssetResolver
import com.caoccao.javet.enums.JSRuntimeType
import com.caoccao.javet.interception.logging.JavetStandardConsoleInterceptor
import com.caoccao.javet.interop.V8Runtime
Expand Down Expand Up @@ -55,7 +54,9 @@ class SassProcessor extends AbstractProcessor {
* @return the compiled output
*/
String process(String input, AssetFile assetFile) {
log.debug "Compiling $assetFile.path"
println "Compiling $assetFile.path"

String output = null

IJavetEngine<V8Runtime> javetEngine = javetEnginePool.getEngine()
Expand All @@ -77,13 +78,14 @@ class SassProcessor extends AbstractProcessor {
v8ValueObject.close()
}

// Setup the options passed to the SASS compiler
// https://sass-lang.com/documentation/js-api/interfaces/LegacyStringOptions
v8Runtime.getGlobalObject().setProperty("compileOptions", [
assetFilePath: assetFile.path,
data: input,
// includePaths: [((assetFile.sourceResolver as FileSystemAssetResolver).scanDirectories.first())]
])

// Execute the sass compiler
// Compile and retrieve the CSS output
v8Runtime.getExecutor(sassCompiler).executeVoid()
output = v8Runtime.getGlobalObject().get("css") as String

Expand Down

0 comments on commit 641f10f

Please sign in to comment.