forked from opensearch-project/oui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
node-sass
with sass-embedded
Also: * Implement sass variable extraction * Implement sass variable importing in typescript * Add guards to post-install cleanup Signed-off-by: Miki <miki@amazon.com>
- Loading branch information
Showing
83 changed files
with
508 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const fs = require('fs'); | ||
const { join, dirname, parse } = require('path'); | ||
const { compileWithVariablesSync } = require('../../lib/compile-scss-with-variables'); | ||
|
||
const idKey = '!!variables-from-scss!!'; | ||
const keyLength = idKey.length; | ||
|
||
const forbiddenKeyNames = [...Object.getOwnPropertyNames(Object.prototype), 'prototype']; | ||
|
||
module.exports = (babel) => ({ | ||
visitor: { | ||
ImportDeclaration(path, state) { | ||
if (path.node.source.value.startsWith(idKey)) { | ||
const deconstructedAssignments = []; | ||
const usedVariableNames = []; | ||
const assignments = []; | ||
for (const specifier of path.node.specifiers) { | ||
if (specifier.type === 'ImportDefaultSpecifier') { | ||
assignments.push(specifier.local.name); | ||
} else if (specifier.type === 'ImportSpecifier') { | ||
usedVariableNames.push(specifier.imported.name); | ||
deconstructedAssignments.push(specifier.imported.name === specifier.local.name ? specifier.local.name : `${specifier.imported.name}: ${specifier.local.name}`); | ||
} | ||
} | ||
|
||
const importTarget = join(dirname(state.file.opts.filename), path.node.source.value.substring(keyLength)); | ||
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; | ||
|
||
if (deconstructedAssignments.length > 0) assignments.push(`{ ${deconstructedAssignments.join(', ')} }`); | ||
path.replaceWith(babel.template.statement.ast(`const ${assignments.join(', ')} = ${JSON.stringify(importedVariables)};`)); | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
|
||
const { execSync } = require('child_process'); | ||
const chalk = require('chalk'); | ||
const path = require('path'); | ||
const dtsGenerator = require('dts-generator').default; | ||
|
||
function compileChartsBundle() { | ||
console.log('Building chart theme module...'); | ||
execSync( | ||
'webpack src/themes/charts/themes.ts -o dist/oui_charts_theme.js --output-library-target="commonjs" --config=src/webpack.config.js', | ||
{ | ||
stdio: 'inherit', | ||
} | ||
); | ||
dtsGenerator({ | ||
prefix: '', | ||
out: 'dist/oui_charts_theme.d.ts', | ||
baseDir: path.resolve(__dirname, '..', 'src/themes/charts/'), | ||
files: ['themes.ts'], | ||
resolveModuleId() { | ||
return '@opensearch-project/oui/dist/oui_charts_theme'; | ||
}, | ||
resolveModuleImport(params) { | ||
if (params.importedModuleId === '../../components/common') { | ||
return '@opensearch-project/oui/src/components/common'; | ||
} | ||
return null; | ||
} | ||
}); | ||
|
||
/* OUI -> EUI Aliases */ | ||
execSync( | ||
'webpack src/themes/charts/themes.ts -o dist/eui_charts_theme.js --output-library-target="commonjs" --config=src/webpack.config.js', | ||
{ | ||
stdio: 'inherit', | ||
} | ||
); | ||
dtsGenerator({ | ||
prefix: '', | ||
out: 'dist/eui_charts_theme.d.ts', | ||
baseDir: path.resolve(__dirname, '..', 'src/themes/charts/'), | ||
files: ['themes.ts'], | ||
resolveModuleId() { | ||
return '@elastic/eui/dist/eui_charts_theme'; | ||
}, | ||
resolveModuleImport(params) { | ||
if (params.importedModuleId === '../../components/common') { | ||
return '@elastic/eui/src/components/common'; | ||
} | ||
return null; | ||
} | ||
}); | ||
/* End of Aliases */ | ||
|
||
console.log(chalk.green('✔ Finished chart theme module')); | ||
} | ||
|
||
compileChartsBundle(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.