Skip to content

Commit

Permalink
Allow to resolve absolute paths in sass-dart-asset-pipeline (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkobel committed Jun 10, 2022
1 parent b02d327 commit 0d230a2
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "/webjars/bootstrap/5.1.3/scss/bootstrap";
1 change: 1 addition & 0 deletions sass-asset-pipeline/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4'

testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.21'
testRuntimeOnly 'org.webjars:bootstrap:5.1.3'
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,17 @@ class SassProcessorSpec extends Specification {
then:
output.contains('Twitter')
}

void "should compile webjar imports"() {
given:
AssetPipelineConfigHolder.resolvers = []
AssetPipelineConfigHolder.registerResolver(new FileSystemAssetResolver('test','assets'))
AssetPipelineConfigHolder.registerResolver(new ClasspathAssetResolver('classpath','META-INF/resources'))
def assetFile = AssetHelper.fileForFullName('webjar-import/main.scss')
def processor = new SassProcessor()
when:
def output = processor.process(assetFile.inputStream.text,assetFile)
then:
output.contains('Twitter')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "/bootstrap/bootstrap";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "/webjars/bootstrap/5.1.3/scss/bootstrap";
2 changes: 2 additions & 0 deletions sass-dart-asset-pipeline/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ dependencies {
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4'

testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.21'
testRuntimeOnly 'org.webjars:bootstrap:5.1.3'

}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class SassAssetFileLoader {
prev = baseFile.path
}
else {
// Resolve the real base path for this import
// Resolve the real base path for this import if it's not an absolute path
String priorParent = importMap[prev]
if (priorParent) {
if (priorParent && !prev.startsWith('/')) {
Path priorParentPath = Paths.get(priorParent)
if (priorParentPath.parent) {
prev = "${priorParentPath.parent.toString()}/${prev}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package asset.pipeline.dart

import asset.pipeline.AssetHelper
import asset.pipeline.AssetPipelineConfigHolder
import asset.pipeline.fs.ClasspathAssetResolver
import asset.pipeline.fs.FileSystemAssetResolver
import spock.lang.Specification

Expand Down Expand Up @@ -104,4 +105,29 @@ class SassProcessorSpec extends Specification {
then:
output.contains('Twitter')
}

void "should compile absolute imports"() {
given:
AssetPipelineConfigHolder.resolvers = []
AssetPipelineConfigHolder.registerResolver(new FileSystemAssetResolver('test','assets'))
def assetFile = AssetHelper.fileForFullName('absolute-import/main.scss')
def processor = new SassProcessor()
when:
def output = processor.process(assetFile.inputStream.text,assetFile)
then:
output.contains('Twitter')
}

void "should compile webjar imports"() {
given:
AssetPipelineConfigHolder.resolvers = []
AssetPipelineConfigHolder.registerResolver(new FileSystemAssetResolver('test','assets'))
AssetPipelineConfigHolder.registerResolver(new ClasspathAssetResolver('classpath','META-INF/resources'))
def assetFile = AssetHelper.fileForFullName('webjar-import/main.scss')
def processor = new SassProcessor()
when:
def output = processor.process(assetFile.inputStream.text,assetFile)
then:
output.contains('Twitter')
}
}

0 comments on commit 0d230a2

Please sign in to comment.