diff --git a/sass-asset-pipeline/assets/stylesheets/webjar-import/main.scss b/sass-asset-pipeline/assets/stylesheets/webjar-import/main.scss new file mode 100644 index 00000000..081329d1 --- /dev/null +++ b/sass-asset-pipeline/assets/stylesheets/webjar-import/main.scss @@ -0,0 +1 @@ +@import "/webjars/bootstrap/5.1.3/scss/bootstrap"; diff --git a/sass-asset-pipeline/build.gradle b/sass-asset-pipeline/build.gradle index 4ec05fa0..5efd07d4 100644 --- a/sass-asset-pipeline/build.gradle +++ b/sass-asset-pipeline/build.gradle @@ -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 { diff --git a/sass-asset-pipeline/src/test/groovy/asset/pipeline/jsass/SassProcessorSpec.groovy b/sass-asset-pipeline/src/test/groovy/asset/pipeline/jsass/SassProcessorSpec.groovy index df7a769a..d15a8394 100644 --- a/sass-asset-pipeline/src/test/groovy/asset/pipeline/jsass/SassProcessorSpec.groovy +++ b/sass-asset-pipeline/src/test/groovy/asset/pipeline/jsass/SassProcessorSpec.groovy @@ -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') + } } diff --git a/sass-dart-asset-pipeline/assets/stylesheets/absolute-import/main.scss b/sass-dart-asset-pipeline/assets/stylesheets/absolute-import/main.scss new file mode 100644 index 00000000..820c24a5 --- /dev/null +++ b/sass-dart-asset-pipeline/assets/stylesheets/absolute-import/main.scss @@ -0,0 +1 @@ +@import "/bootstrap/bootstrap"; diff --git a/sass-dart-asset-pipeline/assets/stylesheets/webjar-import/main.scss b/sass-dart-asset-pipeline/assets/stylesheets/webjar-import/main.scss new file mode 100644 index 00000000..081329d1 --- /dev/null +++ b/sass-dart-asset-pipeline/assets/stylesheets/webjar-import/main.scss @@ -0,0 +1 @@ +@import "/webjars/bootstrap/5.1.3/scss/bootstrap"; diff --git a/sass-dart-asset-pipeline/build.gradle b/sass-dart-asset-pipeline/build.gradle index cbec90dc..9f0a053d 100644 --- a/sass-dart-asset-pipeline/build.gradle +++ b/sass-dart-asset-pipeline/build.gradle @@ -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 { diff --git a/sass-dart-asset-pipeline/src/main/groovy/asset/pipeline/dart/SassAssetFileLoader.groovy b/sass-dart-asset-pipeline/src/main/groovy/asset/pipeline/dart/SassAssetFileLoader.groovy index 04f7e4aa..01cdcb3e 100644 --- a/sass-dart-asset-pipeline/src/main/groovy/asset/pipeline/dart/SassAssetFileLoader.groovy +++ b/sass-dart-asset-pipeline/src/main/groovy/asset/pipeline/dart/SassAssetFileLoader.groovy @@ -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}" diff --git a/sass-dart-asset-pipeline/src/test/groovy/asset/pipeline/dart/SassProcessorSpec.groovy b/sass-dart-asset-pipeline/src/test/groovy/asset/pipeline/dart/SassProcessorSpec.groovy index 4d39f116..1da216a4 100644 --- a/sass-dart-asset-pipeline/src/test/groovy/asset/pipeline/dart/SassProcessorSpec.groovy +++ b/sass-dart-asset-pipeline/src/test/groovy/asset/pipeline/dart/SassProcessorSpec.groovy @@ -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 @@ -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') + } }