Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to resolve absolute paths in sass-dart-asset-pipeline #299

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}
}