-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat!: simplify UnoCSS integration #270
Merged
Nemikolh
merged 5 commits into
stackblitz:main
from
AriPerkkio:feat/internal-uno-config
Aug 27, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
98b1cad
feat!: simplify UnoCSS integration
AriPerkkio 8f7eafb
Merge branch 'main' into feat/internal-uno-config
AriPerkkio f63f768
fix: tests to use new config
AriPerkkio 6af1bc9
fix: code review
AriPerkkio 7c2d629
Merge branch 'main' into feat/internal-uno-config
Nemikolh 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 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 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 |
---|---|---|
@@ -1,45 +1,5 @@ | ||
import { unoCSSConfig } from '@tutorialkit/astro'; | ||
import { globSync, convertPathToPattern } from 'fast-glob'; | ||
import fs from 'node:fs/promises'; | ||
import { basename, dirname, join } from 'node:path'; | ||
import { defineConfig, presetIcons, presetUno, transformerDirectives } from 'unocss'; | ||
|
||
const iconPaths = globSync('./icons/languages/*.svg'); | ||
|
||
const customIconCollection = iconPaths.reduce( | ||
(acc, iconPath) => { | ||
const collectionName = basename(dirname(iconPath)); | ||
const [iconName] = basename(iconPath).split('.'); | ||
|
||
acc[collectionName] ??= {}; | ||
acc[collectionName][iconName] = async () => fs.readFile(iconPath, 'utf8'); | ||
|
||
return acc; | ||
}, | ||
{} as Record<string, Record<string, () => Promise<string>>>, | ||
); | ||
import { defineConfig } from '@tutorialkit/theme'; | ||
|
||
export default defineConfig({ | ||
...unoCSSConfig, | ||
content: { | ||
inline: globSync([ | ||
`${convertPathToPattern(join(require.resolve('@tutorialkit/components-react'), '..'))}/**/*.js`, | ||
`${convertPathToPattern(join(require.resolve('@tutorialkit/astro'), '..'))}/default/**/*.astro`, | ||
]).map((filePath) => { | ||
return () => fs.readFile(filePath, { encoding: 'utf8' }); | ||
}), | ||
}, | ||
transformers: [transformerDirectives()], | ||
presets: [ | ||
presetUno({ | ||
dark: { | ||
dark: '[data-theme="dark"]', | ||
}, | ||
}), | ||
presetIcons({ | ||
collections: { | ||
...customIconCollection, | ||
}, | ||
}), | ||
], | ||
// add your UnoCSS config here: https://unocss.dev/guide/config-file | ||
}); |
This file contains 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 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 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 |
---|---|---|
@@ -1,20 +1,5 @@ | ||
import { theme, rules, shortcuts } from '@tutorialkit/theme'; | ||
import { convertPathToPattern, globSync } from 'fast-glob'; | ||
import fs from 'node:fs/promises'; | ||
import { join } from 'path'; | ||
import { defineConfig, presetIcons, presetUno, transformerDirectives } from 'unocss'; | ||
import { defineConfig } from '@tutorialkit/theme'; | ||
|
||
export default defineConfig({ | ||
theme, | ||
rules, | ||
shortcuts, | ||
content: { | ||
inline: globSync( | ||
`${convertPathToPattern(join(require.resolve('@tutorialkit/components-react'), '..'))}/**/*.js`, | ||
).map((filePath) => { | ||
return () => fs.readFile(filePath, { encoding: 'utf8' }); | ||
}), | ||
}, | ||
transformers: [transformerDirectives()], | ||
presets: [presetUno(), presetIcons()], | ||
// add your UnoCSS config here: https://unocss.dev/guide/config-file | ||
}); |
This file contains 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 |
---|---|---|
@@ -1,47 +1,5 @@ | ||
import fs from 'node:fs/promises'; | ||
import { basename, dirname, join } from 'node:path'; | ||
import { globSync, convertPathToPattern } from 'fast-glob'; | ||
import { defineConfig, presetIcons, presetUno, transformerDirectives } from 'unocss'; | ||
import { rules, shortcuts, theme } from '@tutorialkit/theme'; | ||
|
||
const iconPaths = globSync('./icons/languages/*.svg'); | ||
|
||
const customIconCollection = iconPaths.reduce( | ||
(acc, iconPath) => { | ||
const collectionName = basename(dirname(iconPath)); | ||
const [iconName] = basename(iconPath).split('.'); | ||
|
||
acc[collectionName] ??= {}; | ||
acc[collectionName][iconName] = async () => fs.readFile(iconPath, 'utf8'); | ||
|
||
return acc; | ||
}, | ||
{} as Record<string, Record<string, () => Promise<string>>>, | ||
); | ||
import { defineConfig } from '@tutorialkit/theme'; | ||
|
||
export default defineConfig({ | ||
rules, | ||
shortcuts, | ||
theme, | ||
content: { | ||
inline: globSync([ | ||
`${convertPathToPattern(join(require.resolve('@tutorialkit/components-react'), '..')).replace('\\@', '/@')}/**/*.js`, | ||
`${convertPathToPattern(join(require.resolve('@tutorialkit/astro'), '..')).replace('\\@', '/@')}/default/**/*.astro`, | ||
]).map((filePath) => { | ||
return () => fs.readFile(filePath, { encoding: 'utf8' }); | ||
}), | ||
}, | ||
transformers: [transformerDirectives()], | ||
presets: [ | ||
presetUno({ | ||
dark: { | ||
dark: '[data-theme="dark"]', | ||
}, | ||
}), | ||
presetIcons({ | ||
collections: { | ||
...customIconCollection, | ||
}, | ||
}), | ||
], | ||
// add your UnoCSS config here: https://unocss.dev/guide/config-file | ||
}); |
This file contains 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 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 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 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 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
2 changes: 1 addition & 1 deletion
2
packages/components/react/src/core/CodeMirrorEditor/cm-theme.ts
This file contains 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 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 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 |
---|---|---|
@@ -1,45 +1,5 @@ | ||
import { unoCSSConfig } from '@tutorialkit/astro'; | ||
import { globSync, convertPathToPattern } from 'fast-glob'; | ||
import fs from 'node:fs/promises'; | ||
import { basename, dirname, join } from 'node:path'; | ||
import { defineConfig, presetIcons, presetUno, transformerDirectives } from 'unocss'; | ||
|
||
const iconPaths = globSync('./icons/languages/*.svg'); | ||
|
||
const customIconCollection = iconPaths.reduce( | ||
(acc, iconPath) => { | ||
const collectionName = basename(dirname(iconPath)); | ||
const [iconName] = basename(iconPath).split('.'); | ||
|
||
acc[collectionName] ??= {}; | ||
acc[collectionName][iconName] = async () => fs.readFile(iconPath, 'utf8'); | ||
|
||
return acc; | ||
}, | ||
{} as Record<string, Record<string, () => Promise<string>>>, | ||
); | ||
import { defineConfig } from '@tutorialkit/theme'; | ||
|
||
export default defineConfig({ | ||
...unoCSSConfig, | ||
content: { | ||
inline: globSync([ | ||
`${convertPathToPattern(join(require.resolve('@tutorialkit/components-react'), '..')).replace('\\@', '/@')}/**/*.js`, | ||
`${convertPathToPattern(join(require.resolve('@tutorialkit/astro'), '..')).replace('\\@', '/@')}/default/**/*.astro`, | ||
]).map((filePath) => { | ||
return () => fs.readFile(filePath, { encoding: 'utf8' }); | ||
}), | ||
}, | ||
transformers: [transformerDirectives()], | ||
presets: [ | ||
presetUno({ | ||
dark: { | ||
dark: '[data-theme="dark"]', | ||
}, | ||
}), | ||
presetIcons({ | ||
collections: { | ||
...customIconCollection, | ||
}, | ||
}), | ||
], | ||
// add your UnoCSS config here: https://unocss.dev/guide/config-file | ||
}); |
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.
Oh I'm curious: why is the root needed? Is it because
@unocss/reset
is not a dependency of@tutorialkit/astro
?What about we add it as a dependency?
Or we could also keep the
true
value.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.
It is a dependency of
@tutorialkit/astro
.When
injectReset: true
is used I'm seeing following error: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.
Oh that is strange, could that be a bug in the unocss astro integration?
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.
This is also mentioned on UnoCSS:
Now that we don't require end-users (or template) to add
@unocss/reset
as their dependency, it's likely causing a hoisting issue here, like mentioned on the issue. Usingrequire.resolve
solves this.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.
Gotcha, thanks for the clarification!