-
Notifications
You must be signed in to change notification settings - Fork 50
chore(components): update @embroider/addon-dev v8
#3474
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/components/scripts/rollup-plugin-build-styles.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { join, dirname, resolve } from 'node:path'; | ||
| import fs from 'fs-extra'; | ||
| import * as sass from 'sass'; | ||
|
|
||
| /** | ||
| * Compile a single SCSS entry into CSS (+ .map) under distRoot, preserving the same relative path. | ||
| * Example: | ||
| * srcRoot: src/styles | ||
| * distRoot: dist/styles | ||
| * relScss: @hashicorp/design-system-components.scss | ||
| * -> writes: | ||
| * dist/styles/@hashicorp/design-system-components.css | ||
| * dist/styles/@hashicorp/design-system-components.css.map | ||
| */ | ||
| function compileOne({ srcRoot, distRoot, relScss, includePaths = [] }) { | ||
| const inFile = join(srcRoot, relScss); | ||
|
|
||
| const outCss = join(distRoot, relScss).replace(/\.scss$/, '.css'); | ||
| const outMap = `${outCss}.map`; | ||
|
|
||
| const result = sass.compile(inFile, { | ||
| style: 'expanded', | ||
| sourceMap: true, | ||
| sourceMapIncludeSources: true, | ||
| // allow @use/@import to resolve from your styles root, includePaths, and node_modules | ||
| loadPaths: [srcRoot, ...includePaths, 'node_modules'], | ||
| }); | ||
|
|
||
| fs.ensureDirSync(dirname(outCss)); | ||
| fs.writeFileSync(outCss, result.css); | ||
|
|
||
| if (result.sourceMap) { | ||
| fs.writeFileSync(outMap, JSON.stringify(result.sourceMap)); | ||
| } | ||
| } | ||
|
|
||
| export function buildStylesPlugin(options = {}) { | ||
| const { | ||
| srcRoot = 'src/styles', | ||
| distRoot = 'dist/styles', | ||
| entries = [], | ||
| includePathsByEntry = {}, | ||
| } = options; | ||
|
|
||
| // Force a build at least once, then only when styles change. | ||
| let needsBuild = true; | ||
|
|
||
| const absSrcRoot = resolve(srcRoot); | ||
|
|
||
| function isInStylesTree(id) { | ||
| // Rollup provides absolute paths for watched files most of the time. | ||
| // In case it doesn't, fall back to simple substring check too. | ||
| const abs = resolve(id); | ||
| return ( | ||
| abs.startsWith(absSrcRoot) || | ||
| id.includes('/src/styles/') || | ||
| id.includes('\\src\\styles\\') | ||
| ); | ||
| } | ||
|
|
||
| async function copyStylesTree() { | ||
| // Mirror srcRoot into distRoot | ||
| await fs.ensureDir(dirname(distRoot)); | ||
| await fs.remove(distRoot); | ||
| await fs.copy(srcRoot, distRoot); | ||
| } | ||
|
|
||
| async function buildAll() { | ||
| // 1) Copy the whole styles tree late, so Embroider can't clean it away. | ||
| await copyStylesTree(); | ||
|
|
||
| // 2) Compile entrypoints into CSS next to the copied SCSS. | ||
| for (const relScss of entries) { | ||
| compileOne({ | ||
| srcRoot, | ||
| distRoot, | ||
| relScss, | ||
| includePaths: includePathsByEntry[relScss] ?? [], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| name: 'build-styles-sidecar', | ||
|
|
||
| buildStart() { | ||
| // Ensure watch mode re-runs when anything under styles changes. | ||
| // (Rollup will re-run the build when watched files change.) | ||
| this.addWatchFile(absSrcRoot); | ||
| }, | ||
|
|
||
| watchChange(id) { | ||
| if (isInStylesTree(id)) { | ||
| needsBuild = true; | ||
| } | ||
| }, | ||
|
|
||
| async writeBundle() { | ||
| if (!needsBuild) return; | ||
|
|
||
| await buildAll(); | ||
| needsBuild = false; | ||
| }, | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[blocker] we're moving away from this plugin, see https://github.com/hashicorp/design-system/pull/3237/files#diff-30635ef46c2e2d021e9e18afbf2cab0bfd4b5c3d8201db8c1321306396d28955
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have put comprehensive explanation why it's needed I will let you decide which way you prefer it unblocks upgrade to for addon-dev and should go in soon to unblock
gtsmigration workUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, please open also a PR on the main feature branch #3237 for Project Solar ("IBM carbonization" of HDS) so that your update works also on that branch, which represents a large (months) chunk of work; otherwise how would we "merge" the two approaches?
/cc @alex-ju @hashicorp/hds-engineering