Skip to content

Commit e47324f

Browse files
authored
Convert build tools to use dart-sass (#1617)
* 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
1 parent 122eb0e commit e47324f

13 files changed

+491
-1090
lines changed

.changeset/olive-ants-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": major
3+
---
4+
5+
Removing `<kbd>` import from markdown package. Going forward you'll need to include `@primer/css/base/kbd.scss` directly.

.changeset/polite-mayflies-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": minor
3+
---
4+
5+
Convert postcss build tool, from node-sass to dart-sass.

.node-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

__tests__/build.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('./dist/ folder', () => {
2222

2323
it('contains source maps', () => {
2424
for (const file of distCSS) {
25+
if (file.includes('support')) { continue }
2526
expect(distMap).toContain(`${file}.map`)
2627
}
2728
})

docs/content/support/v18-migration.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ See [color utility classes](/utilities/colors) for a list of all the functional
7878
| `.text-inherit` | `.color-fg-inherit` |
7979

8080
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.
81+
82+
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:
83+
84+
```diff
85+
@import "@primer/css/markdown/index.scss";
86+
+ @import "@primer/css/base/kbd.scss";
87+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@changesets/changelog-github": "0.4.1",
4141
"@changesets/cli": "2.17.0",
4242
"@github/prettier-config": "0.0.4",
43+
"@koddsson/postcss-sass": "5.0.0",
4344
"autoprefixer": "10.3.4",
4445
"cssstats": "4.0.2",
4546
"eslint": "7.32.0",
@@ -56,7 +57,6 @@
5657
"postcss-calc": "8.0.0",
5758
"postcss-import": "14.0.2",
5859
"postcss-load-config": "3.1.0",
59-
"postcss-node-sass": "3.1.1",
6060
"postcss-scss": "4.0.0",
6161
"postcss-simple-vars": "6.0.3",
6262
"prettier": "2.4.1",

postcss.config.cjs

Lines changed: 0 additions & 16 deletions
This file was deleted.

postcss.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import autoprefixer from 'autoprefixer'
2+
import sass from '@koddsson/postcss-sass'
3+
import scss from 'postcss-scss'
4+
import scssImport from 'postcss-import'
5+
import {fileURLToPath} from 'url'
6+
import {join, dirname} from 'path'
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url))
9+
10+
const plugins = [
11+
scssImport,
12+
sass({
13+
includePaths: [join(__dirname, 'node_modules')],
14+
outputStyle: process.env.CSS_MINIFY === '0' ? 'expanded' : 'compressed'
15+
}),
16+
autoprefixer,
17+
];
18+
19+
export default {
20+
map: {
21+
sourcesContent: false,
22+
annotation: true
23+
},
24+
syntax: scss,
25+
parser: scss,
26+
plugins: plugins
27+
}

script/dist.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env node
22
import {globby} from 'globby'
3+
import compiler from './primer-css-compiler.js'
34
import cssstats from 'cssstats'
4-
import postcss from 'postcss'
5-
import loadConfig from 'postcss-load-config'
65
import {dirname, join} from 'path'
76

87
import analyzeVariables from './analyze-variables.js'
@@ -27,8 +26,6 @@ const bundleNames = {
2726
async function dist() {
2827
try {
2928
const bundles = {}
30-
const {plugins, options} = await loadConfig()
31-
const processor = postcss(plugins)
3229

3330
await remove(outDir)
3431
await mkdirp(statsDir)
@@ -53,7 +50,8 @@ async function dist() {
5350

5451
const scss = await readFile(from, encoding)
5552
meta.imports = getExternalImports(scss, path).map(getPathName)
56-
const result = await processor.process(scss, Object.assign({from, to}, options))
53+
const result = await compiler(scss, {from, to})
54+
5755
await Promise.all([
5856
writeFile(to, result.css, encoding),
5957
writeFile(meta.stats, JSON.stringify(cssstats(result.css)), encoding),

script/primer-css-compiler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import postcss from 'postcss'
2+
import postCssConfig from '../postcss.config.js'
3+
4+
export default async function compiler(css, options) {
5+
const { plugins, ...config } = postCssConfig
6+
7+
const result = await postcss(plugins).process(css, {
8+
...config,
9+
...options
10+
})
11+
return result
12+
}

src/markdown/markdown-body.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
line-height: $body-line-height;
1111
word-wrap: break-word;
1212

13-
@import "../base/kbd.scss"; // adds support for keyboard shortcuts
14-
1513
// Clearfix on the markdown body
1614
&::before {
1715
display: table;

0 commit comments

Comments
 (0)