Skip to content

Commit

Permalink
Merge pull request #42 from cardstack/support-app-builds
Browse files Browse the repository at this point in the history
Rollup plugin: support app usage
  • Loading branch information
ef4 authored Oct 25, 2024
2 parents e59096a + 1367e3e commit 8084e6a
Show file tree
Hide file tree
Showing 6 changed files with 2,032 additions and 2,149 deletions.
2 changes: 1 addition & 1 deletion failing-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@types/ember__template": "^4.0.1",
"@types/ember__test": "^4.0.1",
"@types/ember__utils": "^4.0.2",
"@types/qunit": "^2.19.4",
"@types/qunit": "2.19.10",
"@types/rsvp": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
Expand Down
25 changes: 7 additions & 18 deletions glimmer-scoped-css/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,30 @@ import { createHash } from 'crypto';
import { Plugin } from 'rollup';
import path from 'path';

export function scopedCSS(srcDir: string): Plugin {
export function scopedCSS(): Plugin {
return {
name: 'scoped-css',
resolveId(source, importer) {
if (!isScopedCSSRequest(source) || !importer) {
return null;
}
let hash = createHash('md5');
let fullSrcDir = path.resolve(srcDir);
let localPath = path.relative(fullSrcDir, importer);
hash.update(source);
let cssFileName = hash.digest('hex').slice(0, 10) + '.css';
let dir = path.dirname(localPath);
let cssAndFile = decodeScopedCSSRequest(source);
let { css } = decodeScopedCSSRequest(source);
return {
id: path.resolve(path.dirname(importer), cssFileName),
meta: {
'scoped-css': {
css: cssAndFile.css,
fileName: path.join(dir, cssFileName),
css,
},
},
external: 'relative',
};
},
generateBundle() {
for (const moduleId of this.getModuleIds()) {
let info = this.getModuleInfo(moduleId);
if (info?.meta['scoped-css']) {
this.emitFile({
type: 'asset',
fileName: info.meta['scoped-css'].fileName,
source: info.meta['scoped-css'].css,
});
}
load(id: string) {
let meta = this.getModuleInfo(id)?.meta?.['scoped-css'];
if (meta) {
return meta.css;
}
},
};
Expand Down
Loading

0 comments on commit 8084e6a

Please sign in to comment.