Skip to content

Commit

Permalink
Convert build tools to use dart-sass (#1617)
Browse files Browse the repository at this point in the history
* Installing dart-sass

* Moving css compiling to separate file

* Removing node version

* Create polite-mayflies-refuse.md

* Don't compile support files

* Fix test to not check support

* Create olive-ants-kick.md
  • Loading branch information
jonrohan committed Sep 24, 2021
1 parent 122eb0e commit e47324f
Show file tree
Hide file tree
Showing 13 changed files with 491 additions and 1,090 deletions.
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

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

0 comments on commit e47324f

Please sign in to comment.