Skip to content

Commit

Permalink
WIP: emborider approach may need to change entirely to be more like g…
Browse files Browse the repository at this point in the history
…limmer-scoped-css
  • Loading branch information
NullVoxPopuli committed May 21, 2024
1 parent 548b5ca commit 09ee2c7
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 84 deletions.
24 changes: 22 additions & 2 deletions ember-scoped-css/src/build/ember-classic-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,33 @@ import {
} from '../lib/path/utils.js';
import rewriteCss from '../lib/rewriteCss.js';
import rewriteHbs from '../lib/rewriteHbs.js';
import { createPlugin } from './template-plugin.js';

const p = new Preprocessor();
const COMPONENT_EXTENSIONS = ['hbs', 'js', 'ts', 'gjs', 'gts'];
const TEMPLATE_EXTENSIONS = ['hbs', 'gjs', 'gts'];

export function installScopedCSS(registry, options) {
registry.add('htmlbars-ast-plugin', buildASTPlugin(options));
}

export function buildASTPlugin(options) {
let plugin = createPlugin(options);

return {
name: 'ember-scoped-css::template-plugin',
plugin,
baseDir: function () {
return __dirname;
},
parallelBabel: {
requireFile: __filename,
buildUsing: 'buildASTPlugin',
params: {},
},
};
}

class ScopedFilter extends Filter {
constructor(componentsNode, options = {}) {
super(componentsNode, options);
Expand Down Expand Up @@ -235,8 +257,6 @@ export default class ScopedCssPreprocessor {
...(this.userOptions.additionalRoots || []).map(
(root) => `${this.appName}/${root}`,
),
'app/components/',
...(this.userOptions.additionalRoots || []).map((root) => `app/${root}`),
];
let include = roots
.map((root) => {
Expand Down
7 changes: 5 additions & 2 deletions ember-scoped-css/src/lib/path/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ export function isRelevantFile(fileName, additionalRoots) {

// These are already the bundled files.
if (fileName.includes('/node_modules/.embroider/rewritten-app/assets/')) {
return false;

// not supported, never will be
if (
fileName.endsWith(
Expand Down Expand Up @@ -265,6 +267,7 @@ export function appPath(sourcePath) {
}

const CACHE = new Set();
const cwd = process.cwd();

/**
* For a given source path, if we have seen a
Expand All @@ -273,7 +276,7 @@ const CACHE = new Set();
*/
function hasSeen(sourcePath) {
for (let entry of CACHE) {
if (sourcePath.startsWith(entry)) {
if (sourcePath.startsWith(entry) && cwd !== entry) {
return entry;
}
}
Expand All @@ -294,7 +297,7 @@ export function findWorkspacePath(sourcePath) {
}

const packageJsonPath = findUp.sync('package.json', {
cwd: path.dirname(sourcePath),
cwd: sourcePath,
});

const workspacePath = path.dirname(packageJsonPath);
Expand Down
Loading

0 comments on commit 09ee2c7

Please sign in to comment.