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

Use dart based sass in Portal and Stories #1080

Merged
merged 1 commit into from
Oct 29, 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
2 changes: 1 addition & 1 deletion .ncurc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"reject": ["node-sass"]
"reject": []
}
2 changes: 1 addition & 1 deletion packages/dnb-design-system-portal/.ncurc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"reject": ["eslint", "node-sass", "ora"]
"reject": ["eslint", "ora"]
}
1 change: 1 addition & 0 deletions packages/dnb-design-system-portal/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const plugins = [
process.env.NODE_ENV === 'production'
? require('@dnb/eufemia/scripts/prepub/config/postcssConfig')({
IE11: true,
sass: require('sass'),
})
: [],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-design-system-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"jest-raw-loader": "1.0.1",
"keycode": "2.2.0",
"lint-staged": "11.1.2",
"node-sass": "5.0.0",
"nodemon": "2.0.13",
"ora": "5.4.1",
"path-browserify": "1.0.1",
Expand All @@ -126,6 +125,7 @@
"react-fake-props": "1.0.3",
"react-live": "2.4.0",
"react-markdown": "7.0.1",
"sass": "1.43.4",
"start-server-and-test": "1.14.0",
"stylelint": "13.13.1",
"stylelint-config-prettier": "8.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ order: 8

## Dependencies

## sass
## node-sass vs sass

- Eufemia uses `node-sass` instead of `sass` (dart based) because we render sass during jest tests with `sass.renderSync` – even that should work with `sass` as well, it can't find the file it says.
- We use several places a module called `node-sass-once-importer`, that is compatible only with `node-sass`.
- We use `sass-loader` v10 because `TypeError: this.getOptions is not a function`.
- We use `node-sass` v5, else we get this error message during portal run:
The Portal (documentations) uses dart based `sass`, while the bundle and build process of the package `@dnb/eufemia` uses `node-sass` – because:

- we render sass styles during jest tests with `sass.renderSync` – even that should work with `sass` as well, it can't find the [file it says](https://github.com/sass/dart-sass/issues/710).
- several places a module called `node-sass-once-importer` is used, that is compatible only with `node-sass`.
- it uses `sass-loader` v10 because `TypeError: this.getOptions is not a function`.
- it uses `node-sass` v5, else we get this error message during portal run:

```
ERROR in polyfill
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-eufemia-sandbox/.ncurc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"reject": ["node-sass", "sass-loader"]
"reject": ["sass-loader"]
}
2 changes: 1 addition & 1 deletion packages/dnb-eufemia-sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@storybook/react": "6.3.8",
"@storybook/theming": "6.3.8",
"css-loader": "5.2.7",
"node-sass": "5.0.0",
"raw-loader": "4.0.2",
"sass": "1.43.4",
"sass-loader": "10.2.0",
"style-loader": "2.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/dnb-eufemia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
"rollup-plugin-node-globals": "1.4.0",
"rollup-plugin-size-snapshot": "0.12.0",
"rollup-plugin-terser": "7.0.2",
"sass": "1.43.4",
"sass-variable-parser": "1.2.2",
"semantic-release": "17.4.7",
"simple-commit-message": "4.1.3",
Expand Down
13 changes: 8 additions & 5 deletions packages/dnb-eufemia/scripts/prepub/config/postcssConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/

const fs = require('fs')
const sass = require('node-sass')
const sassBin = require('sass')
const os = require('os')
const path = require('path')

module.exports = ({ IE11 = false, ...options } = {}) => {
module.exports = ({ IE11 = false, sass = sassBin, ...options } = {}) => {
return [
// preset-env processes the most of our old legacy browsers
require('postcss-preset-env')({
Expand All @@ -19,7 +20,9 @@ module.exports = ({ IE11 = false, ...options } = {}) => {
),
importFrom: [
extractCSSProperties(
require.resolve('@dnb/eufemia/src/style/index.scss')
require.resolve('@dnb/eufemia/src/style/index.scss'),
null,
sass
),
],
...options,
Expand Down Expand Up @@ -56,13 +59,13 @@ module.exports = ({ IE11 = false, ...options } = {}) => {
].filter((i) => i)
}

function extractCSSProperties(file, opts = {}) {
function extractCSSProperties(file, opts = {}, sass = sassBin) {
try {
const sassResult = sass.renderSync({
file,
...opts,
})
const tmpDir = String(require('os').tmpdir)
const tmpDir = String(os.tmpdir)
const tmpFile = path.resolve(
tmpDir,
path.basename(file.replace('.scss', '.css'))
Expand Down
3 changes: 2 additions & 1 deletion packages/dnb-eufemia/scripts/prepub/tasks/makeLibStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import gulp from 'gulp'
import sass from 'node-sass'
import clone from 'gulp-clone'
import rename from 'gulp-rename'
import transform from 'gulp-transform'
Expand Down Expand Up @@ -67,7 +68,7 @@ export const runFactory = (
.pipe(
transform(
'utf8',
transformPostcss(postcssConfig({ IE11: true }))
transformPostcss(postcssConfig({ IE11: true, sass }))
)
)
.pipe(cloneSink)
Expand Down
3 changes: 2 additions & 1 deletion packages/dnb-eufemia/scripts/prepub/tasks/makeMainStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import gulp from 'gulp'
import sass from 'node-sass'
import onceImporter from 'node-sass-once-importer'
import clone from 'gulp-clone'
import rename from 'gulp-rename'
Expand Down Expand Up @@ -83,7 +84,7 @@ export const runFactory = (
.pipe(
transform(
'utf8',
transformPostcss(postcssConfig({ IE11: true }))
transformPostcss(postcssConfig({ IE11: true, sass }))
)
)
.pipe(cloneSink)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3477,7 +3477,7 @@ legend.dnb-form-label {
box-shadow: 0 0 0 0.125rem var(--color-emerald-green); } }
.dnb-date-picker__day, .dnb-date-picker__labels__day {
display: flex;
flex-basis: 14.28571%;
flex-basis: calc(1 / 7 * 100%);
justify-content: center; }
.dnb-date-picker__day {
position: relative;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
&__day,
&__labels__day {
display: flex;
flex-basis: percentage(1 / 7);
flex-basis: calc(1 / 7 * 100%);
justify-content: center;
}

Expand Down Expand Up @@ -470,7 +470,9 @@

&__day,
&__labels__day {
flex-basis: percentage(1 / 7) - 0.8;
// math.div works only in dart sass
// flex-basis: math.div(1, 7) * 100% - 0.8;
flex-basis: 13.48571%;
}

&__day {
Expand Down
54 changes: 33 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,7 @@ __metadata:
rollup-plugin-node-globals: 1.4.0
rollup-plugin-size-snapshot: 0.12.0
rollup-plugin-terser: 7.0.2
sass: 1.43.4
sass-variable-parser: 1.2.2
semantic-release: 17.4.7
simple-commit-message: 4.1.3
Expand Down Expand Up @@ -9516,6 +9517,25 @@ __metadata:
languageName: node
linkType: hard

"chokidar@npm:>=3.0.0 <4.0.0, chokidar@npm:^3.2.2, chokidar@npm:^3.4.0, chokidar@npm:^3.4.1, chokidar@npm:^3.4.2, chokidar@npm:^3.5.2":
version: 3.5.2
resolution: "chokidar@npm:3.5.2"
dependencies:
anymatch: ~3.1.2
braces: ~3.0.2
fsevents: ~2.3.2
glob-parent: ~5.1.2
is-binary-path: ~2.1.0
is-glob: ~4.0.1
normalize-path: ~3.0.0
readdirp: ~3.6.0
dependenciesMeta:
fsevents:
optional: true
checksum: d1fda32fcd67d9f6170a8468ad2630a3c6194949c9db3f6a91b16478c328b2800f433fb5d2592511b6cb145a47c013ea1cce60b432b1a001ae3ee978a8bffc2d
languageName: node
linkType: hard

"chokidar@npm:^2.0.0, chokidar@npm:^2.0.4, chokidar@npm:^2.1.8":
version: 2.1.8
resolution: "chokidar@npm:2.1.8"
Expand All @@ -9539,25 +9559,6 @@ __metadata:
languageName: node
linkType: hard

"chokidar@npm:^3.2.2, chokidar@npm:^3.4.0, chokidar@npm:^3.4.1, chokidar@npm:^3.4.2, chokidar@npm:^3.5.2":
version: 3.5.2
resolution: "chokidar@npm:3.5.2"
dependencies:
anymatch: ~3.1.2
braces: ~3.0.2
fsevents: ~2.3.2
glob-parent: ~5.1.2
is-binary-path: ~2.1.0
is-glob: ~4.0.1
normalize-path: ~3.0.0
readdirp: ~3.6.0
dependenciesMeta:
fsevents:
optional: true
checksum: d1fda32fcd67d9f6170a8468ad2630a3c6194949c9db3f6a91b16478c328b2800f433fb5d2592511b6cb145a47c013ea1cce60b432b1a001ae3ee978a8bffc2d
languageName: node
linkType: hard

"chownr@npm:*, chownr@npm:^2.0.0":
version: 2.0.0
resolution: "chownr@npm:2.0.0"
Expand Down Expand Up @@ -12069,7 +12070,6 @@ __metadata:
jest-raw-loader: 1.0.1
keycode: 2.2.0
lint-staged: 11.1.2
node-sass: 5.0.0
nodemon: 2.0.13
ora: 5.4.1
path-browserify: 1.0.1
Expand All @@ -12088,6 +12088,7 @@ __metadata:
react-live: 2.4.0
react-markdown: 7.0.1
react-router-dom: 5.3.0
sass: 1.43.4
smoothscroll-polyfill: 0.4.4
start-server-and-test: 1.14.0
stylelint: 13.13.1
Expand All @@ -12114,11 +12115,11 @@ __metadata:
"@storybook/react": 6.3.8
"@storybook/theming": 6.3.8
css-loader: 5.2.7
node-sass: 5.0.0
prop-types: 15.7.2
raw-loader: 4.0.2
react: 17.0.2
react-dom: 17.0.2
sass: 1.43.4
sass-loader: 10.2.0
style-loader: 2.0.0
languageName: unknown
Expand Down Expand Up @@ -28715,6 +28716,17 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard

"sass@npm:1.43.4":
version: 1.43.4
resolution: "sass@npm:1.43.4"
dependencies:
chokidar: ">=3.0.0 <4.0.0"
bin:
sass: sass.js
checksum: 9af80105dabd32752c60b4557115832982cf1019c02c952db6a26c61a3e18dc95044c896685e6e9a6d6dd6643fc411ecf2ea4a8a431a8a08a7510a45d5a492ae
languageName: node
linkType: hard

"sax@npm:>=0.6.0, sax@npm:^1.2.4, sax@npm:~1.2.4":
version: 1.2.4
resolution: "sax@npm:1.2.4"
Expand Down