From 0b2f392c3f77b2e8964d8c00c5d5be60394c1bd9 Mon Sep 17 00:00:00 2001 From: Ilya Radchenko Date: Fri, 11 Oct 2019 10:55:24 -0400 Subject: [PATCH] fix: Don't error if using ember-template-styles-import (#15) * Don't error if using ember-template-styles-import Instead of erroring, leave that line unchanged for that addon to handle. * fix check --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index fb24470..e64643a 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,15 @@ const path = require('path'); const BroccoliFilter = require('broccoli-persistent-filter'); const md5Hex = require('md5-hex'); +const usingStylesImport = false; const IMPORT_PATTERN = /\{\{\s*import\s+([^\s]+)\s+from\s+['"]([^'"]+)['"]\s*\}\}/gi; +try { + usingStylesImport = !!require.resolve('ember-template-styles-import'); +} catch(e) { + // noop +} + function isValidVariableName(name) { if (!(/^[A-Za-z0-9]+$/.test(name))) { return false; @@ -51,6 +58,9 @@ class TemplateImportProcessor extends BroccoliFilter { processString(contents, relativePath) { let imports = []; let rewrittenContents = contents.replace(IMPORT_PATTERN, (_, localName, importPath) => { + if (importPath.endsWith('styles.scoped.scss') && usingStylesImport) { + return _; + } if (importPath.startsWith('.')) { importPath = path.resolve(relativePath, '..', importPath).split(path.sep).join('/'); importPath = path.relative(this.options.root, importPath).split(path.sep).join('/');