Skip to content

Commit 17b323a

Browse files
authored
Upgrade @embroider/addon-dev to unblock gts (#3513)
1 parent e410b2e commit 17b323a

File tree

6 files changed

+147
-100
lines changed

6 files changed

+147
-100
lines changed

packages/components/package.json

Lines changed: 1 addition & 1 deletion
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",

packages/components/rollup.config.mjs

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,57 @@
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';
11+
import * as sass from 'sass';
1212

1313
const addon = new Addon({
1414
srcDir: 'src',
1515
destDir: 'dist',
1616
});
1717

18+
// Custom SCSS compilation plugin for Rollup
19+
function addScssCompilationPlugins(options) {
20+
return options.map(({ inputFile, outputFile, loadPaths }) => ({
21+
name: `rollup custom plugin to generate ${outputFile}`,
22+
generateBundle() {
23+
try {
24+
const inputFileFullPath = `src/styles/@hashicorp/${inputFile}`;
25+
const outputFileFullPath = `styles/@hashicorp/${outputFile}`;
26+
27+
const result = sass.compile(inputFileFullPath, {
28+
sourceMap: true,
29+
loadPaths,
30+
});
31+
32+
// Emit the compiled CSS
33+
this.emitFile({
34+
type: 'asset',
35+
fileName: outputFileFullPath,
36+
source: result.css,
37+
});
38+
39+
// Emit the source map
40+
if (result.sourceMap) {
41+
this.emitFile({
42+
type: 'asset',
43+
fileName: `${outputFileFullPath}.map`,
44+
source: JSON.stringify(result.sourceMap),
45+
});
46+
}
47+
} catch (error) {
48+
this.error(
49+
`Failed to compile SCSS file "${inputFile}": ${error.message}`
50+
);
51+
}
52+
},
53+
}));
54+
}
55+
1856
const plugins = [
1957
// These are the modules that users should be able to import from your
2058
// 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-
]),
59+
addon.publicEntrypoints(['**/*.{js,ts}', 'index.js', 'template-registry.js']),
2760

2861
// These are the modules that should get reexported into the traditional
2962
// "app" tree. Things in here should also be in publicEntrypoints above, but
@@ -50,16 +83,22 @@ const plugins = [
5083
// package names.
5184
addon.dependencies(),
5285

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-
}),
86+
// We use a custom plugin for the Sass/SCSS compilation
87+
// so we can have multiple input and multiple outputs
88+
...addScssCompilationPlugins(
89+
// files that will be compiled
90+
[
91+
{
92+
inputFile: 'design-system-components.scss',
93+
outputFile: 'design-system-components.css',
94+
loadPaths: ['node_modules/@hashicorp/design-system-tokens/dist'],
95+
},
96+
{
97+
inputFile: 'design-system-power-select-overrides.scss',
98+
outputFile: 'design-system-power-select-overrides.css',
99+
},
100+
]
101+
),
63102

64103
// Ensure that standalone .hbs files are properly integrated as Javascript.
65104
addon.hbs(),
@@ -85,12 +124,20 @@ const plugins = [
85124
// to leave alone and keep in the published output.
86125
addon.keepAssets(['**/*.css', '**/*.scss']),
87126

88-
// Copy readme and license files into published package
89127
copy({
90128
targets: [
129+
// Copy readme and license files into published package
91130
{ src: 'README.md', dest: 'dist' },
92131
{ src: 'LICENSE.md', dest: 'dist' },
132+
// Copy sass mixins for consumers to use directly
133+
{ src: 'src/styles/mixins', dest: 'dist/styles' },
134+
// Copy sass components for consumers to use directly
135+
{ src: 'src/styles/components', dest: 'dist/styles' },
93136
],
137+
hook: 'writeBundle',
138+
copySync: true,
139+
copyOnce: true,
140+
// verbose: true,
94141
}),
95142
];
96143

packages/components/src/styles/@hashicorp/design-system-components.scss

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* SPDX-License-Identifier: MPL-2.0
44
*/
55

6-
// these files come from the 'design-system-tokens' package
7-
@use "tokens";
8-
@use "helpers/color";
9-
@use "helpers/elevation";
10-
@use "helpers/focus-ring";
11-
@use "helpers/typography";
6+
// these files come from `packages/tokens/dist/`
7+
@use "products/css/tokens";
8+
@use "products/css/helpers/color";
9+
@use "products/css/helpers/elevation";
10+
@use "products/css/helpers/focus-ring";
11+
@use "products/css/helpers/typography";
1212

1313
// Vendor styles
1414
@use "./design-system-ember-a11y-refocus";

0 commit comments

Comments
 (0)