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

Convert build tools to use dart-sass #1617

Merged
merged 11 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-ants-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/css": major
---

Removing `<kbd>` import from markdown package. Going forward you'll need to include `@primer/css/base/kbd.scss` directly.
5 changes: 5 additions & 0 deletions .changeset/polite-mayflies-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/css": minor
---

Convert postcss build tool, from node-sass to dart-sass.
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

1 change: 1 addition & 0 deletions __tests__/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('./dist/ folder', () => {

it('contains source maps', () => {
for (const file of distCSS) {
if (file.includes('support')) { continue }
expect(distMap).toContain(`${file}.map`)
}
})
Expand Down
7 changes: 7 additions & 0 deletions docs/content/support/v18-migration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ See [color utility classes](/utilities/colors) for a list of all the functional
| `.text-inherit` | `.color-fg-inherit` |

A few more selectors and variables were removed. Please refer to [deprecations.json](https://github.com/primer/css/blob/main/src/deprecations.json) for a complete list.

Note: The `<kbd>` styles also got removed from the markdown bundle. In case you import the `markdown` bundle **without** the `base` bundle, make sure to import the `<kbd>` styles as well:

```diff
@import "@primer/css/markdown/index.scss";
+ @import "@primer/css/base/kbd.scss";
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@changesets/changelog-github": "0.4.1",
"@changesets/cli": "2.17.0",
"@github/prettier-config": "0.0.4",
"@koddsson/postcss-sass": "5.0.0",
"autoprefixer": "10.3.4",
"cssstats": "4.0.2",
"eslint": "7.32.0",
Expand All @@ -56,7 +57,6 @@
"postcss-calc": "8.0.0",
"postcss-import": "14.0.2",
"postcss-load-config": "3.1.0",
"postcss-node-sass": "3.1.1",
"postcss-scss": "4.0.0",
"postcss-simple-vars": "6.0.3",
"prettier": "2.4.1",
Expand Down
16 changes: 0 additions & 16 deletions postcss.config.cjs

This file was deleted.

27 changes: 27 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import autoprefixer from 'autoprefixer'
import sass from '@koddsson/postcss-sass'
import scss from 'postcss-scss'
import scssImport from 'postcss-import'
import {fileURLToPath} from 'url'
import {join, dirname} from 'path'

const __dirname = dirname(fileURLToPath(import.meta.url))

const plugins = [
scssImport,
sass({
includePaths: [join(__dirname, 'node_modules')],
outputStyle: process.env.CSS_MINIFY === '0' ? 'expanded' : 'compressed'
}),
autoprefixer,
];

export default {
map: {
sourcesContent: false,
annotation: true
},
syntax: scss,
parser: scss,
plugins: plugins
}
8 changes: 3 additions & 5 deletions script/dist.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node
import {globby} from 'globby'
import compiler from './primer-css-compiler.js'
import cssstats from 'cssstats'
import postcss from 'postcss'
import loadConfig from 'postcss-load-config'
import {dirname, join} from 'path'

import analyzeVariables from './analyze-variables.js'
Expand All @@ -27,8 +26,6 @@ const bundleNames = {
async function dist() {
try {
const bundles = {}
const {plugins, options} = await loadConfig()
const processor = postcss(plugins)

await remove(outDir)
await mkdirp(statsDir)
Expand All @@ -53,7 +50,8 @@ async function dist() {

const scss = await readFile(from, encoding)
meta.imports = getExternalImports(scss, path).map(getPathName)
const result = await processor.process(scss, Object.assign({from, to}, options))
const result = await compiler(scss, {from, to})

await Promise.all([
writeFile(to, result.css, encoding),
writeFile(meta.stats, JSON.stringify(cssstats(result.css)), encoding),
Expand Down
12 changes: 12 additions & 0 deletions script/primer-css-compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import postcss from 'postcss'
import postCssConfig from '../postcss.config.js'

export default async function compiler(css, options) {
const { plugins, ...config } = postCssConfig

const result = await postcss(plugins).process(css, {
...config,
...options
})
return result
}
2 changes: 0 additions & 2 deletions src/markdown/markdown-body.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
line-height: $body-line-height;
word-wrap: break-word;

@import "../base/kbd.scss"; // adds support for keyboard shortcuts
Copy link
Contributor

Choose a reason for hiding this comment

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

Is importing a file like that not possible in dart-sass? If so, we might need to just duplicate those styles?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello inspect the styles on me

yes, I meant to say. dart-sass didn't like this. but checking the .markdown-body kbd and the normal kbd that's included in base both apply in dotcom. So I'm unsure if this more specific import is needed?

If it is, we can try putting .markdown-body kbd, kbd {} in the base/kbd.scss file.


// Clearfix on the markdown body
&::before {
display: table;
Expand Down
Loading