-
Notifications
You must be signed in to change notification settings - Fork 73
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
Replace node-sass
with sass-embedded
#1001
Conversation
9456f45
to
7dcbe48
Compare
7072912
to
7f81d1b
Compare
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.
initial review, still need to look at variable from scss when my brain isnt completely fried
@@ -16,7 +16,7 @@ | |||
position: absolute; | |||
left: 0; | |||
top: 50%; | |||
margin-top: -($ouiRangeThumbHeight / 2); | |||
margin-top: calc(-1 * $ouiRangeThumbHeight / 2); |
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.
Does this need to be -1 * x
? What about $ouiRangeThumbHeight / -2
?
$arrowPlusSize: (calc($arrowSize/2) + 1px) * -1; /* 1 */ | ||
$arrowMinusSize: (calc($arrowSize/2) - 1px) * -1; /* 1 */ |
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.
I feel like these equations could be optimized but that could be done in a followup
7f81d1b
to
a6e4271
Compare
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.
A couple questions, but looks good to me. The important part is that it works! 😁
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.
const idKey = '!!variables-from-scss!!'; | ||
const keyLength = idKey.length; | ||
|
||
const forbiddenKeyNames = [...Object.getOwnPropertyNames(Object.prototype), 'prototype']; |
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.
We can write them in uppercase to note that these variables are constant and should not be changed:
const IMPORT_PREFIX = '!!variables-from-scss!!';
const FORBIDDEN_KEYS = [...Object.getOwnPropertyNames(Object.prototype), 'prototype'];
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.
I reserve uppercased names for constants that get exported; here they are just local variables. Do you have a strong feeling for this? or do you think they should be exported?
const { variables } = compileWithVariablesSync(importTarget); | ||
|
||
// If no default specifier is used, reduce the variables to only those needed | ||
const importedVariables = assignments.length === 0 ? usedVariableNames.reduce((acc, name) => { | ||
if (!forbiddenKeyNames.includes(name)) acc[name] = variables[name]; | ||
return acc; | ||
}, {}) : variables; |
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.
We can put the logic in a separate function to improve readability:
const filterImportedVariables = (allVariables, usedVariableNames) => {
return usedVariableNames.reduce((acc, name) => {
if (!FORBIDDEN_KEYS.includes(name)) {
acc[name] = allVariables[name];
}
return acc;
}, {});
};
const importTarget = join(dirname(state.file.opts.filename), path.node.source.value.substring(IMPORT_PREFIX.length));
const { variables: allVariables } = compileWithVariablesSync(importTarget);
const importedVariables = assignments.length === 0 ? filterImportedVariables(allVariables, usedVariableNames) : allVariables;
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.
I have a feeling that these are called synchronously and recursively and was very worried about stack overflows; hence I inlined everything without looking at the depth.
const varListMarker = ':֍෴֍߷'; | ||
const arrayMarker = '෴'; | ||
const objectMarker = '߷'; | ||
const forbiddenKeyNames = [...Object.getOwnPropertyNames(Object.prototype), 'prototype']; |
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.
We can write them in uppercase to note that these variables are constant and should not be changed:
const VAR_LIST_MARKER = ':֍෴֍߷';
const ARRAY_MARKER = '෴';
const OBJECT_MARKER = '߷';
const FORBIDDEN_KEY_NAMES = [...Object.getOwnPropertyNames(Object.prototype), 'prototype'];
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.
Since they are local variables and not exported, I didn't; do you have a strong feeling towards this?
PS, for the same reason, i didn't deepFreeze
the forbidden key names.
// originalKey is only used for displaying errors | ||
const _set = (o, path, value, originalKey) => { | ||
// To improve performance, since this is a private method, it is not validating `path` | ||
const [key, type, ...rest] = path; | ||
if (forbiddenKeyNames.includes(key)) return; | ||
if (rest.length === 0) { | ||
if (type) { | ||
throw new Error(`Unexpected type ${type} for ${key} was found on ${originalKey}`); | ||
} | ||
// For bwc, 0px -> 0 | ||
o[key] = isFinite(value) ? parseFloat(value) : (value === '0px' ? 0 : value); | ||
} else { | ||
switch (type) { | ||
case arrayMarker: | ||
if (key in o) { | ||
if (!Array.isArray(o[key])) | ||
throw new Error(`${key} of ${originalKey} was found to be ${Object.prototype.toString.call(o[key])}`); | ||
} else { | ||
o[key] = []; | ||
// Inserting to the beginning to make sure the inner references appear before the outer ones. | ||
foundArrays.unshift({ node: o, key }); | ||
} | ||
_set(o[key], rest, value); | ||
break; | ||
|
||
case objectMarker: | ||
if (key in o) { | ||
if (Object.prototype.toString.call(o[key]) !== '[object Object]') | ||
throw new Error(`${key} of ${originalKey} was found to be ${Object.prototype.toString.call(o[key])}`); | ||
} else { | ||
o[key] = {}; | ||
knownKeys.add(key); | ||
} | ||
_set(o[key], rest, value); | ||
break; | ||
|
||
default: | ||
throw new Error(`Unknown type [${type}] in ${originalKey}`); | ||
} | ||
} | ||
}; |
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.
We can move this function somewhere else to avoid overloading this part of the code
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.
We should; let's hold of though until OUI 2 when we remove all of those backward compatibility stuff or else we will have to pass foundArrays
and knownKeys
around.
This will follow the |
compileScssFiles(path.join('src', 'theme_*.scss'), 'dist', ouiPackageName) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(2); | ||
}); |
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.
Thinking about it again, this function shouldn't ever throw an error, I think. Everything that might is wrapped in a try-catch
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.
There is a re-throw in compileScssFiles
.
Also: * Implement sass variable extraction * Implement sass variable importing in typescript * Add guards to post-install cleanup * Make sources compatible with dart sass by wrapping divisions in `calc()` and adding units were necessary * Fold in `@elastic/charts/dist/theme.scss` to modify it for dart-sass compatibility * Break out compiling `charts` Signed-off-by: Miki <[email protected]>
a6e4271
to
b7b5dc6
Compare
Also: * Implement sass variable extraction * Implement sass variable importing in typescript * Add guards to post-install cleanup * Make sources compatible with dart sass by wrapping divisions in `calc()` and adding units were necessary * Fold in `@elastic/charts/dist/theme.scss` to modify it for dart-sass compatibility * Break out compiling `charts` Signed-off-by: Miki <[email protected]> (cherry picked from commit db94845) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Also: * Implement sass variable extraction * Implement sass variable importing in typescript * Add guards to post-install cleanup * Make sources compatible with dart sass by wrapping divisions in `calc()` and adding units were necessary * Fold in `@elastic/charts/dist/theme.scss` to modify it for dart-sass compatibility * Break out compiling `charts` (cherry picked from commit db94845) Signed-off-by: Miki <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Also: * Implement sass variable extraction * Implement sass variable importing in typescript * Add guards to post-install cleanup * Make sources compatible with dart sass by wrapping divisions in `calc()` and adding units were necessary * Fold in `@elastic/charts/dist/theme.scss` to modify it for dart-sass compatibility * Break out compiling `charts` Signed-off-by: Miki <[email protected]> Signed-off-by: ShatilKhan <[email protected]>
Also: * Implement sass variable extraction * Implement sass variable importing in typescript * Add guards to post-install cleanup * Make sources compatible with dart sass by wrapping divisions in `calc()` and adding units were necessary * Fold in `@elastic/charts/dist/theme.scss` to modify it for dart-sass compatibility * Break out compiling `charts` Signed-off-by: Miki <[email protected]> Signed-off-by: ShatilKhan <[email protected]>
Description
Replace
node-sass
withsass-embedded
Also:
calc()
and adding units were necessary@elastic/charts/dist/theme.scss
to modify it for dart-sass compatibilitycharts
closes #966
Check List
yarn lint
yarn test-unit
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.