Skip to content

Commit

Permalink
fix: Don't error if using ember-template-styles-import (#15)
Browse files Browse the repository at this point in the history
* Don't error if using ember-template-styles-import

Instead of erroring, leave that line unchanged for that addon to handle.

* fix check
  • Loading branch information
knownasilya authored Oct 11, 2019
1 parent eea632e commit 0b2f392
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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('/');
Expand Down

0 comments on commit 0b2f392

Please sign in to comment.