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 plugin-css, plugin-sass #150

Merged
merged 1 commit into from
Nov 6, 2023
Merged

Fix plugin-css, plugin-sass #150

merged 1 commit into from
Nov 6, 2023

Conversation

drwpow
Copy link
Collaborator

@drwpow drwpow commented Nov 6, 2023

Changes

Fixes accidental regression in transform() APIs and plugin-sass ↔ plugin-css interop (mentioned in #145).

How to Review

  • Tests should pass.

Copy link

changeset-bot bot commented Nov 6, 2023

🦋 Changeset detected

Latest commit: cbda777

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@cobalt-ui/plugin-css Patch
@cobalt-ui/plugin-sass Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

cloudflare-workers-and-pages bot commented Nov 6, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: cbda777
Status:🚫  Deploy failed.

View logs

@@ -96,6 +96,27 @@ describe('@cobalt-ui/plugin-css', () => {
expect(fs.readFileSync(new URL('./actual.css', cwd), 'utf8')).toMatchFileSnapshot(fileURLToPath(new URL('./want.css', cwd)));
});

test('transform', async () => {
Copy link
Collaborator Author

@drwpow drwpow Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin-css’ transform() API was missing a test; now it should catch regressions a little better.

@drwpow
Copy link
Collaborator Author

drwpow commented Nov 6, 2023

🤔 Cloudflare failure seems to be a flake failure on their end (Unknown internal error). Seems unrelated to this PR.

@drwpow drwpow merged commit 8c6893d into main Nov 6, 2023
5 of 6 checks passed
@drwpow drwpow deleted the fix/plugin-css branch November 6, 2023 19:05
@github-actions github-actions bot mentioned this pull request Nov 6, 2023
options?: {
prefix?: string;
suffix?: string;
// note: the following properties are optional to preserve backwards-compat without a breaking change
Copy link

@radum radum Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean they will be removed with the const token = options?.tokens?.find((t) => t.id === refID); find and warn bellow once there is a breaking change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’re following semver in this package, so there shouldn’t be any breaking changes until 2.0.0.

This was just an unintentional internal change that accidentally led to a breaking change. It was triggered by mismatching versions of plugin-css (+/- 1.6.0) and plugin-sass (+/- 1.3.2). This change just allows for (hopefully) graceful fallback between the two plugins. The optional chaining method just allows an older version of the plugin to omit that data, and it will, still render a result.

Copy link
Collaborator Author

@drwpow drwpow Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hidden cross-dependencies like this are an antipattern in general, and something I should clean up better. Just at the moment, it felt like saving work / reducing bugs to have plugin-sass rely on plugin-css, but over time they’ve become too tightly-coupled and I think there needs to be a common core they share that allows for safer version drift between the two (irrelevant for consumers; this is just an implementation detail I’m musing on).

const variableId = refID + normalizedSuffix;

return `var(${generateName(variableId, token)})`;
return `var(${options?.generateName?.(variableId, token) ?? defaultNameGenerator(variableId, options?.prefix)})`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this mean varRef is a part of the plugin's public API? Because otherwise this is unnecessary. Both parts of this logic...

  • Was a custom name generator passed? If not use the default one
  • Was a prefix passed? If so, pass it to the default generator

...are already accounted for in the generateName argument (see line 76) by way of currying.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this mean varRef is a part of the plugin's public API?

Maybe not “public”, but used in the Sass plugin. And so mismatched versions would throw an error due to the changed signature. It’s a TODO item for cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants