From 886e67f46472bce3837895cc3cb51ec7cca6d857 Mon Sep 17 00:00:00 2001 From: Moritz Kobel Date: Tue, 8 Mar 2022 00:36:13 +0100 Subject: [PATCH 1/2] Allow to resolve absolute paths in sass-dart-asset-pipeline This enables the same behaviour as in sass-asset-pipeline. Added webjar test cases in bot sass asset-pipelines. fixes #297 --- .../stylesheets/webjar-import/main.scss | 1 + sass-asset-pipeline/build.gradle | 2 ++ .../pipeline/jsass/SassProcessorSpec.groovy | 13 ++++++++++ .../stylesheets/absolute-import/main.scss | 1 + .../stylesheets/webjar-import/main.scss | 1 + sass-dart-asset-pipeline/build.gradle | 3 +++ .../pipeline/dart/SassAssetFileLoader.groovy | 4 +-- .../pipeline/dart/SassProcessorSpec.groovy | 26 +++++++++++++++++++ 8 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 sass-asset-pipeline/assets/stylesheets/webjar-import/main.scss create mode 100644 sass-dart-asset-pipeline/assets/stylesheets/absolute-import/main.scss create mode 100644 sass-dart-asset-pipeline/assets/stylesheets/webjar-import/main.scss 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..72ba07e3 100644 --- a/sass-asset-pipeline/build.gradle +++ b/sass-asset-pipeline/build.gradle @@ -50,6 +50,8 @@ dependencies { testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4' testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.21' + + compile '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..86e29800 100644 --- a/sass-dart-asset-pipeline/build.gradle +++ b/sass-dart-asset-pipeline/build.gradle @@ -57,6 +57,9 @@ dependencies { testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4' testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.21' + + compile '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') + } } From 58ea69264f0c4a2108c5e8d9551778baa227a1a2 Mon Sep 17 00:00:00 2001 From: Moritz Kobel Date: Tue, 8 Mar 2022 09:09:54 +0100 Subject: [PATCH 2/2] fix: Allow to resolve absolute paths in sass-dart-asset-pipeline reconfigure bootstrap webjar as testRuntimeOnly depenendecy --- sass-asset-pipeline/build.gradle | 3 +-- sass-dart-asset-pipeline/build.gradle | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sass-asset-pipeline/build.gradle b/sass-asset-pipeline/build.gradle index 72ba07e3..5efd07d4 100644 --- a/sass-asset-pipeline/build.gradle +++ b/sass-asset-pipeline/build.gradle @@ -50,8 +50,7 @@ dependencies { testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4' testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.21' - - compile 'org.webjars:bootstrap:5.1.3' + testRuntimeOnly 'org.webjars:bootstrap:5.1.3' } publishing { diff --git a/sass-dart-asset-pipeline/build.gradle b/sass-dart-asset-pipeline/build.gradle index 86e29800..9f0a053d 100644 --- a/sass-dart-asset-pipeline/build.gradle +++ b/sass-dart-asset-pipeline/build.gradle @@ -57,8 +57,7 @@ dependencies { testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4' testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.21' - - compile 'org.webjars:bootstrap:5.1.3' + testRuntimeOnly 'org.webjars:bootstrap:5.1.3' }