Skip to content

Commit c0a9b60

Browse files
committed
chore(components): update @embroider/addon-dev v8
1 parent 892400a commit c0a9b60

File tree

6 files changed

+1256
-1162
lines changed

6 files changed

+1256
-1162
lines changed

packages/components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@babel/runtime": "^7.27.1",
8181
"@ember/string": "^4.0.1",
8282
"@ember/test-helpers": "^4.0.4",
83-
"@embroider/addon-dev": "^7.1.5",
83+
"@embroider/addon-dev": "^8.2.0",
8484
"@eslint/js": "^9.23.0",
8585
"@glimmer/component": "^2.0.0",
8686
"@glint/core": "^1.5.2",
@@ -103,13 +103,13 @@
103103
"eslint-plugin-ember": "^12.5.0",
104104
"eslint-plugin-import": "^2.31.0",
105105
"eslint-plugin-n": "^17.18.0",
106+
"fs-extra": "^11.3.3",
106107
"globals": "^16.0.0",
107108
"postcss": "^8.5.3",
108109
"prettier": "^3.5.3",
109110
"prettier-plugin-ember-template-tag": "^2.0.5",
110111
"rollup": "^4.39.0",
111112
"rollup-plugin-copy": "^3.5.0",
112-
"rollup-plugin-scss": "^4.0.1",
113113
"sass": "^1.89.2",
114114
"stylelint": "^16.17.0",
115115
"stylelint-config-rational-order": "^0.1.2",

packages/components/rollup.config.mjs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
import { Addon } from '@embroider/addon-dev/rollup';
77
import { babel } from '@rollup/plugin-babel';
88
import copy from 'rollup-plugin-copy';
9-
import scss from 'rollup-plugin-scss';
109
import process from 'process';
1110
import path from 'node:path';
1211

12+
import { buildStylesPlugin } from './scripts/rollup-plugin-build-styles.mjs';
13+
1314
const addon = new Addon({
1415
srcDir: 'src',
1516
destDir: 'dist',
1617
});
1718

19+
const STYLE_ENTRIES = [
20+
'@hashicorp/design-system-components.scss',
21+
'@hashicorp/design-system-power-select-overrides.scss',
22+
];
23+
1824
const plugins = [
1925
// These are the modules that users should be able to import from your
2026
// addon. Anything not listed here may get optimized away.
21-
addon.publicEntrypoints([
22-
'**/*.{js,ts}',
23-
'index.js',
24-
'template-registry.js',
25-
'styles/@hashicorp/design-system-components.scss',
26-
]),
27+
addon.publicEntrypoints(['**/*.{js,ts}', 'index.js', 'template-registry.js']),
2728

2829
// These are the modules that should get reexported into the traditional
2930
// "app" tree. Things in here should also be in publicEntrypoints above, but
@@ -50,17 +51,6 @@ const plugins = [
5051
// package names.
5152
addon.dependencies(),
5253

53-
scss({
54-
fileName: 'styles/@hashicorp/design-system-components.css',
55-
includePaths: [
56-
'node_modules/@hashicorp/design-system-tokens/dist/products/css',
57-
],
58-
}),
59-
60-
scss({
61-
fileName: 'styles/@hashicorp/design-system-power-select-overrides.css',
62-
}),
63-
6454
// Ensure that standalone .hbs files are properly integrated as Javascript.
6555
addon.hbs(),
6656

@@ -92,6 +82,18 @@ const plugins = [
9282
{ src: 'LICENSE.md', dest: 'dist' },
9383
],
9484
}),
85+
86+
// Compile SCSS entrypoints -> CSS alongside the copied SCSS in dist/styles/**
87+
buildStylesPlugin({
88+
srcRoot: 'src/styles',
89+
distRoot: 'dist/styles',
90+
entries: STYLE_ENTRIES,
91+
includePathsByEntry: {
92+
'@hashicorp/design-system-components.scss': [
93+
'node_modules/@hashicorp/design-system-tokens/dist/products/css',
94+
],
95+
},
96+
}),
9597
];
9698

9799
if (!process.env.development) {
@@ -103,6 +105,6 @@ export default {
103105
// This provides defaults that work well alongside `publicEntrypoints` below.
104106
// You can augment this if you need to.
105107
output: addon.output(),
106-
plugins: plugins,
108+
plugins,
107109
external: ['ember-modifier', 'prismjs'],
108110
};
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { join, dirname, resolve } from 'node:path';
2+
import fs from 'fs-extra';
3+
import * as sass from 'sass';
4+
5+
/**
6+
* Compile a single SCSS entry into CSS (+ .map) under distRoot, preserving the same relative path.
7+
* Example:
8+
* srcRoot: src/styles
9+
* distRoot: dist/styles
10+
* relScss: @hashicorp/design-system-components.scss
11+
* -> writes:
12+
* dist/styles/@hashicorp/design-system-components.css
13+
* dist/styles/@hashicorp/design-system-components.css.map
14+
*/
15+
function compileOne({ srcRoot, distRoot, relScss, includePaths = [] }) {
16+
const inFile = join(srcRoot, relScss);
17+
18+
const outCss = join(distRoot, relScss).replace(/\.scss$/, '.css');
19+
const outMap = `${outCss}.map`;
20+
21+
const result = sass.compile(inFile, {
22+
style: 'expanded',
23+
sourceMap: true,
24+
sourceMapIncludeSources: true,
25+
// allow @use/@import to resolve from your styles root, includePaths, and node_modules
26+
loadPaths: [srcRoot, ...includePaths, 'node_modules'],
27+
});
28+
29+
fs.ensureDirSync(dirname(outCss));
30+
fs.writeFileSync(outCss, result.css);
31+
32+
if (result.sourceMap) {
33+
fs.writeFileSync(outMap, JSON.stringify(result.sourceMap));
34+
}
35+
}
36+
37+
export function buildStylesPlugin(options = {}) {
38+
const {
39+
srcRoot = 'src/styles',
40+
distRoot = 'dist/styles',
41+
entries = [],
42+
includePathsByEntry = {},
43+
} = options;
44+
45+
// Force a build at least once, then only when styles change.
46+
let needsBuild = true;
47+
48+
const absSrcRoot = resolve(srcRoot);
49+
50+
function isInStylesTree(id) {
51+
// Rollup provides absolute paths for watched files most of the time.
52+
// In case it doesn't, fall back to simple substring check too.
53+
const abs = resolve(id);
54+
return (
55+
abs.startsWith(absSrcRoot) ||
56+
id.includes('/src/styles/') ||
57+
id.includes('\\src\\styles\\')
58+
);
59+
}
60+
61+
async function copyStylesTree() {
62+
// Mirror srcRoot into distRoot
63+
await fs.ensureDir(dirname(distRoot));
64+
await fs.remove(distRoot);
65+
await fs.copy(srcRoot, distRoot);
66+
}
67+
68+
async function buildAll() {
69+
// 1) Copy the whole styles tree late, so Embroider can't clean it away.
70+
await copyStylesTree();
71+
72+
// 2) Compile entrypoints into CSS next to the copied SCSS.
73+
for (const relScss of entries) {
74+
compileOne({
75+
srcRoot,
76+
distRoot,
77+
relScss,
78+
includePaths: includePathsByEntry[relScss] ?? [],
79+
});
80+
}
81+
}
82+
83+
return {
84+
name: 'build-styles-sidecar',
85+
86+
buildStart() {
87+
// Ensure watch mode re-runs when anything under styles changes.
88+
// (Rollup will re-run the build when watched files change.)
89+
this.addWatchFile(absSrcRoot);
90+
},
91+
92+
watchChange(id) {
93+
if (isInStylesTree(id)) {
94+
needsBuild = true;
95+
}
96+
},
97+
98+
async writeBundle() {
99+
if (!needsBuild) return;
100+
101+
await buildAll();
102+
needsBuild = false;
103+
},
104+
};
105+
}

0 commit comments

Comments
 (0)