Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sourcemaps for JS files that are modified by ember-scoped-css #24

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ember-scoped-css/src/addon-hbs-rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export default function rollupCssColocation() {
return rewriteHbs(hbs, classes, tags, postfix);
});

return rewrittenHbsJs;
return {
code: rewrittenHbsJs,
// this rollup plugin changes only the template string, so the code structure is the same
map: null,
};
}
}
},
Expand Down
14 changes: 12 additions & 2 deletions ember-scoped-css/src/addon-js-unplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ export default createUnplugin(() => {
css = result.css;
code = recast.print(result.ast).code;
this.getModuleInfo(jsPath).meta.gjsCss = result.css;

// TODO: generate changed source map. Implementation depends on implemented rollup plugin for style tag
}
}

if (!css) {
return code;
return {
code,
map: null,
};
}

// add css import for js and gjs files
Expand All @@ -44,12 +49,17 @@ export default createUnplugin(() => {
// rewrite hbs in js in case it is gjs file (for gjs files hbs is already in js file)
// for js components "@embroider/addon-dev/template-colocation-plugin", will add hbs to js later. So there is hbs plugin to rewrite hbs

return replaceHbsInJs(code, (hbs) => {
const rewrittenCode = replaceHbsInJs(code, (hbs) => {
const { classes, tags } = getClassesTagsFromCss(css);
const postfix = getPostfix(cssPath);
const rewritten = rewriteHbs(hbs, classes, tags, postfix);
return rewritten;
});

return {
code: rewrittenCode,
map: null,
};
},
};
});