From 0f5e33e08af4d07ea4059d73c016efb3a088c5d0 Mon Sep 17 00:00:00 2001 From: midudev Date: Wed, 8 Sep 2021 15:36:51 +0200 Subject: [PATCH 01/90] feat(packages/sui-bundler): Use latest webpack-dev-server --- packages/sui-bundler/bin/sui-bundler-dev.js | 13 +++-- .../factories/createDevServerConfig.js | 47 ++++++------------- packages/sui-bundler/package.json | 12 ++--- 3 files changed, 31 insertions(+), 41 deletions(-) diff --git a/packages/sui-bundler/bin/sui-bundler-dev.js b/packages/sui-bundler/bin/sui-bundler-dev.js index e9c24ddd5..b499f98ba 100755 --- a/packages/sui-bundler/bin/sui-bundler-dev.js +++ b/packages/sui-bundler/bin/sui-bundler-dev.js @@ -85,13 +85,20 @@ const start = async ({ }) const compiler = createCompiler(nextConfig, urls) const serverConfig = createDevServerConfig(nextConfig, urls.lanUrlForConfig) - const devServer = new WebpackDevServer(compiler, serverConfig) + const devServer = new WebpackDevServer( + { + ...serverConfig, + port, + host: HOST + }, + compiler + ) log.processing('❯ Starting the development server...\n') - devServer.listen(port, HOST, err => { + devServer.startCallback(err => { if (err) return log.error(err) ;['SIGINT', 'SIGTERM'].forEach(sig => { process.on(sig, () => { - devServer.close() + devServer.stop() process.exit() }) }) diff --git a/packages/sui-bundler/factories/createDevServerConfig.js b/packages/sui-bundler/factories/createDevServerConfig.js index 753a7e680..e1bd71fa0 100644 --- a/packages/sui-bundler/factories/createDevServerConfig.js +++ b/packages/sui-bundler/factories/createDevServerConfig.js @@ -5,47 +5,30 @@ const ignoredFiles = require('react-dev-utils/ignoredFiles') const protocol = process.env.HTTPS === 'true' ? 'https' : 'http' const host = process.env.HOST || '0.0.0.0' -module.exports = (config, allowedHost) => ({ - // Enable gzip compression of generated files. - compress: true, - // Silence WebpackDevServer's own logs since they're generally not useful. - // It will still show compile warnings and errors with this setting. - clientLogLevel: 'none', - // Tell the server where to serve content from. This is only necessary if you want to serve static files from this folder as normally they come from memory - contentBase: 'public', - // By default files from `contentBase` will not trigger a page reload. - watchContentBase: true, - // Enable hot reloading server. - hot: true, - // Use 'ws' instead of 'sockjs-node' on server since we're using native - // websockets in `webpackHotDevClient`. - transportMode: 'ws', - // Prevent a WS client from getting injected as we're already including - // `webpackHotDevClient`. - injectClient: false, - // Tell the server at what URL to serve devServer.contentBase static content. - publicPath: config.output.publicPath, - // WebpackDevServer is noisy by default so we emit custom message instead - // by listening to the compiler events with `compiler.hooks[...].tap` calls above. - quiet: true, - // Reportedly, this avoids CPU overload on some systems. - watchOptions: { - ignored: ignoredFiles(config.context) +module.exports = config => ({ + allowedHosts: 'all', + client: { + logging: 'none' + }, + static: { + directory: 'public', + watch: { + ignored: ignoredFiles(config.context) + } }, + hot: true, https: protocol === 'https', host, - overlay: false, historyApiFallback: { disableDotRule: true }, - public: allowedHost, - before(app) { + onBeforeSetupMiddleware(devServer) { // This lets us open files from the runtime error overlay. - app.use(errorOverlayMiddleware()) + devServer.app.use(errorOverlayMiddleware()) }, - after(app) { + onAfterSetupMiddleware(devServer) { // This service worker file is effectively a 'no-op' that will reset any // previous service worker registered for the same host:port combination. - app.use(noopServiceWorkerMiddleware(config.output.publicPath)) + devServer.app.use(noopServiceWorkerMiddleware(config.output.publicPath)) } }) diff --git a/packages/sui-bundler/package.json b/packages/sui-bundler/package.json index 7526793b3..3402635f3 100644 --- a/packages/sui-bundler/package.json +++ b/packages/sui-bundler/package.json @@ -1,6 +1,6 @@ { "name": "@s-ui/bundler", - "version": "7.30.0", + "version": "7.30.2-beta.1", "description": "Config-free bundler for ES6 React apps.", "bin": { "sui-bundler": "./bin/sui-bundler.js" @@ -21,7 +21,7 @@ }, "homepage": "https://github.com/SUI-Components/sui/tree/master/packages/sui-bundler#readme", "dependencies": { - "@babel/core": "7.15.0", + "@babel/core": "7.15.5", "@s-ui/helpers": "1", "autoprefixer": "9.8.6", "babel-loader": "8.2.2", @@ -29,7 +29,7 @@ "commander": "6.2.1", "css-loader": "4.3.0", "css-minimizer-webpack-plugin": "1.1.5", - "esbuild-loader": "2.15.0", + "esbuild-loader": "2.15.1", "fast-glob": "3.2.7", "html-webpack-plugin": "4.5.0", "mini-css-extract-plugin": "1.6.0", @@ -38,15 +38,15 @@ "postcss-loader": "4.1.0", "react-dev-utils": "11.0.4", "rimraf": "3.0.2", - "sass": "1.37.5", + "sass": "1.39.0", "sass-loader": "10.1.0", "super-sass-loader": "0.1", "speed-measure-webpack-plugin": "1.5.0", "style-loader": "2.0.0", "terser-webpack-plugin": "4.2.2", "webpack": "4.46.0", - "webpack-dev-server": "3.11.2", - "webpack-manifest-plugin": "3.1.1", + "webpack-dev-server": "4.1.1", + "webpack-manifest-plugin": "4.0.2", "webpack-node-externals": "3.0.0" } } From 78b60112c6ae9b07aa44339c99a57808482042d6 Mon Sep 17 00:00:00 2001 From: Joan Manrubia Date: Tue, 5 Oct 2021 11:47:56 +0200 Subject: [PATCH 02/90] feat(packages/sui-studio) allow to pass custom context on generate --- .../sui-studio/bin/sui-studio-generate.js | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/packages/sui-studio/bin/sui-studio-generate.js b/packages/sui-studio/bin/sui-studio-generate.js index d6c943396..fa48b0306 100755 --- a/packages/sui-studio/bin/sui-studio-generate.js +++ b/packages/sui-studio/bin/sui-studio-generate.js @@ -12,7 +12,7 @@ const {showError} = require('@s-ui/helpers/cli') const {writeFile} = require('@s-ui/helpers/file') program - .option('-C, --context', 'add context for this component') + .option('-C, --context [customContextPath]', 'add context for this component') .option('-P, --prefix ', 'add prefix for this component') .option('-S, --scope ', 'add scope for this component') .on('--help', () => { @@ -73,6 +73,20 @@ const packageName = `${packageScope}${prefix}-${packageCategory}${toKebabCase( const packageInfo = require(path.join(process.cwd(), 'package.json')) const {repository = {}, homepage} = packageInfo +const defaultContext = `module.exports = { + default: { + i18n: { + t(s) { + return s + .split('') + .reverse() + .join('') + } + } + } +} +` + // Check if the component already exist before continuing if (fs.existsSync(COMPONENT_PATH)) { showError(`[${packageName}] This component already exist in the path: @@ -212,22 +226,14 @@ export default () => <${componentInPascal} /> ), context && - writeFile( - COMPONENT_CONTEXT_FILE, - `module.exports = { - default: { - i18n: { - t(s) { - return s - .split('') - .reverse() - .join('') - } - } - } -} -` - ), + (function() { + const isBooleanContext = typeof context === 'boolean' + if (isBooleanContext) + return writeFile(COMPONENT_CONTEXT_FILE, defaultContext) + + const contextBuffer = fs.readFileSync(`${BASE_DIR}${context}`) + writeFile(COMPONENT_CONTEXT_FILE, contextBuffer.toString()) + })(), writeFile( COMPONENT_TEST_FILE, `/* @@ -243,6 +249,8 @@ import chai, {expect} from 'chai' import chaiDOM from 'chai-dom' import Component from '../src/index' +${context && "import '@s-ui/studio/src/patcher-mocha'"} + chai.use(chaiDOM) describe('${componentInPascal}', () => { From 2f929e34b159d0af27fb6da68d1016cd1ecf3daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Dur=C3=A1n?= Date: Wed, 6 Oct 2021 10:23:34 +0200 Subject: [PATCH 03/90] feat(packages/sui-lint): Migrate to programmatic Node --- packages/sui-lint/bin/sui-lint-js.js | 59 +++++++++----- packages/sui-lint/bin/sui-lint-sass.js | 57 ++++++++------ packages/sui-lint/bin/sui-lint.js | 4 +- packages/sui-lint/package.json | 19 +++-- packages/sui-lint/src/helpers.js | 102 ++++++++++--------------- 5 files changed, 123 insertions(+), 118 deletions(-) diff --git a/packages/sui-lint/bin/sui-lint-js.js b/packages/sui-lint/bin/sui-lint-js.js index cf7229c88..5d55a2d67 100755 --- a/packages/sui-lint/bin/sui-lint-js.js +++ b/packages/sui-lint/bin/sui-lint-js.js @@ -1,31 +1,52 @@ #!/usr/bin/env node /* eslint-disable no-console */ const { - executeLintingCommand, - getArrayArgs, getFilesToLint, getGitIgnoredFiles, isOptionSet, stageFilesIfRequired } = require('../src/helpers') -const BIN_PATH = require.resolve('eslint/bin/eslint') -const CONFIG_PATH = require.resolve('../eslintrc.js') +const {ESLint} = require('eslint') +const config = require('../eslintrc.js') + const EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'] const IGNORE_PATTERNS = ['lib', 'dist', 'public', 'node_modules'] -const patterns = IGNORE_PATTERNS.concat(getGitIgnoredFiles()) - -getFilesToLint(EXTENSIONS).then( - files => - (files.length && - executeLintingCommand(BIN_PATH, [ - `-c ${CONFIG_PATH}`, - ...getArrayArgs('--ext', EXTENSIONS), - ...getArrayArgs('--ignore-pattern', patterns), - ...files - ]).then( - () => isOptionSet('--fix') && stageFilesIfRequired(EXTENSIONS) - )) || - console.log('[sui-lint js] No javascript files to lint.') -) +const baseConfig = { + ...config, + ignorePatterns: IGNORE_PATTERNS.concat(getGitIgnoredFiles()) +} +const formatterName = process.env.CI ? 'stylish' : 'codeframe' + +;(async function main() { + const files = await getFilesToLint(EXTENSIONS) + if (!files.length) { + console.log('[sui-lint js] No JavaScript files to lint') + return + } + console.log(`[sui-lint js] Linting JavaScript files...`) + + const fix = isOptionSet('fix') + const eslint = new ESLint({ + baseConfig, + fix, + extensions: EXTENSIONS, + useEslintrc: false + }) + + const results = await eslint.lintFiles(files) + + if (fix) { + await ESLint.outputFixes(results) + stageFilesIfRequired(EXTENSIONS) + } + + const formatter = await eslint.loadFormatter(formatterName) + const resultText = formatter.format(results) + + console.log(resultText) +})().catch(error => { + process.exitCode = 1 + console.error('[sui-lint js]', error) +}) diff --git a/packages/sui-lint/bin/sui-lint-sass.js b/packages/sui-lint/bin/sui-lint-sass.js index 05ed920ec..22eda9dcd 100755 --- a/packages/sui-lint/bin/sui-lint-sass.js +++ b/packages/sui-lint/bin/sui-lint-sass.js @@ -1,38 +1,47 @@ #!/usr/bin/env node /* eslint-disable no-console */ const program = require('commander') +const stylelint = require('stylelint') +const config = require('../stylelint.config.js') +const {getGitIgnoredFiles, getFilesToLint} = require('../src/helpers') -const { - executeLintingCommand, - getGitIgnoredFiles, - getFilesToLint -} = require('../src/helpers') -const BIN_PATH = require.resolve('stylelint/bin/stylelint') -const CONFIG_PATH = require.resolve('../stylelint.config.js') const EXTENSIONS = ['scss'] const IGNORE_PATTERNS = ['**/node_modules/**', '**/lib/**', '**/dist/**'] -const patterns = IGNORE_PATTERNS.concat(getGitIgnoredFiles()) - program .option('--add-fixes') .option('--staged') .option('--fix', 'fix automatically problems with sass files') - .option('--pattern ', 'root path to locate the sass files') + .option( + '--pattern ', + 'root path to locate the sass files', + '**/*.scss' + ) .parse(process.argv) -getFilesToLint(EXTENSIONS, program.pattern || '**/src/**/*.scss').then( - files => - (files.length && - executeLintingCommand(BIN_PATH, [ - files - .reduce((acc, file) => (acc += file + "' '"), " '") - .replace(/'$/, ''), - - '--config', - CONFIG_PATH, - '--ignore-pattern', - `'${patterns.join(', ')}'` - ])) || +getFilesToLint(EXTENSIONS, program.pattern).then(files => { + if (!files.length) { console.log('[sui-lint sass] No sass files to lint.') -) + return + } + + console.log(`[sui-lint scss] Linting SCSS files...`) + + return stylelint + .lint({ + files, + formatter: 'string', + syntax: 'scss', + config: { + ...config, + ignoreFiles: IGNORE_PATTERNS.concat(getGitIgnoredFiles()) + } + }) + .then(data => { + console.log(data.output) + }) + .catch(error => { + process.exitCode = 1 + console.error('[sui-lint scss]', error) + }) +}) diff --git a/packages/sui-lint/bin/sui-lint.js b/packages/sui-lint/bin/sui-lint.js index 46f3111bc..8b89307ae 100755 --- a/packages/sui-lint/bin/sui-lint.js +++ b/packages/sui-lint/bin/sui-lint.js @@ -1,8 +1,6 @@ #!/usr/bin/env node const program = require('commander') - -const pkg = require('../package.json') -const version = pkg.version +const {version} = require('../package.json') program.version(version, ' --version') diff --git a/packages/sui-lint/package.json b/packages/sui-lint/package.json index c9d3d61d6..270bd09f4 100644 --- a/packages/sui-lint/package.json +++ b/packages/sui-lint/package.json @@ -1,6 +1,6 @@ { "name": "@s-ui/lint", - "version": "3.35.0", + "version": "3.36.0-beta.11", "description": "Linting CLI for sui packages", "main": "./bin/sui-lint.js", "bin": { @@ -9,8 +9,8 @@ "scripts": { "lint": "sui-lint js", "postinstall": "node ./scripts/add-package-json-fields.js", - "eslint:print-rules": "./node_modules/.bin/eslint --config=./eslintrc.js --print-config .", - "eslint:prettier-check": "./node_modules/.bin/eslint --config=./eslintrc.js --print-config . | ./node_modules/.bin/eslint-config-prettier-check" + "eslint:print-rules": "eslint --config=./eslintrc.js --print-config eslintrc.js", + "eslint:prettier-check": "eslint --config=./eslintrc.js --print-config eslintrc.js | eslint-config-prettier-check" }, "keywords": [], "author": "", @@ -26,22 +26,21 @@ "eslint-config-standard": "14.1.1", "eslint-config-standard-react": "9.2.0", "eslint-plugin-chai-friendly": "0.6.0", - "eslint-plugin-cypress": "2.11.2", - "eslint-plugin-import": "2.22.1", - "eslint-plugin-no-only-tests": "2.4.0", + "eslint-plugin-cypress": "2.12.1", + "eslint-plugin-import": "2.24.2", + "eslint-plugin-no-only-tests": "2.6.0", "eslint-plugin-node": "11.1.0", "eslint-plugin-prettier": "3.1.4", - "eslint-plugin-promise": "4.2.1", - "eslint-plugin-react": "7.21.5", + "eslint-plugin-promise": "5.1.0", + "eslint-plugin-react": "7.26.1", "eslint-plugin-react-hooks": "4.2.0", "eslint-plugin-standard": "4.0.2", "prettier": "1.19.1", - "simple-git": "1.126.0", "stylelint": "13.13.1", "stylelint-config-prettier": "8.0.2", "stylelint-config-recommended-scss": "4.2.0", "stylelint-prettier": "1.2.0", - "stylelint-scss": "3.19.0", + "stylelint-scss": "3.21.0", "ts-standard": "10.0.0" } } diff --git a/packages/sui-lint/src/helpers.js b/packages/sui-lint/src/helpers.js index a77b6e529..9cfe5d4db 100644 --- a/packages/sui-lint/src/helpers.js +++ b/packages/sui-lint/src/helpers.js @@ -1,7 +1,9 @@ /* eslint-disable no-console */ const {existsSync, readFileSync} = require('fs') const {extname} = require('path') -const git = require('simple-git') +const {getSpawnPromise} = require('@s-ui/helpers/cli') +const {promisify} = require('util') +const exec = promisify(require('child_process').exec) const GIT_IGNORE_PATH = `${process.cwd()}/.gitignore` const OPTIONS = { @@ -9,31 +11,6 @@ const OPTIONS = { addFixes: '--add-fixes', pattern: '--pattern' } -const optionFlags = Object.values(OPTIONS) - -/** - * Get args removing given args - * @param {Array} args process.argv - * @returns {Array} - */ -const filterOptionFlags = args => args.filter(arg => !optionFlags.includes(arg)) - -/** - * Execute bin as lint command. If -c is defined, process will be exited. - * @param {String} binPath Absolute path of binary - * @param {Array} args Arguments to pass to child process - * @return {ChildProcess} - */ -function executeLintingCommand(binPath, args) { - const {showError, getSpawnPromise} = require('@s-ui/helpers/cli') - const [, , ...processArgs] = filterOptionFlags(process.argv) - - if (processArgs.find(arg => arg === '-c')) { - console.log('[sui-lint] Dont use your own config file. Remove `-c` flag') - process.exit(1) - } - return getSpawnPromise(binPath, args.concat(processArgs)).catch(showError) -} /** * Get lines of a text file as an array of strings @@ -43,7 +20,6 @@ function executeLintingCommand(binPath, args) { const getFileLinesAsArray = path => existsSync(path) ? readFileSync(path, 'utf8') - .toString() .split('\n') .filter(Boolean) : [] @@ -56,45 +32,50 @@ const getGitIgnoredFiles = () => getFileLinesAsArray(GIT_IGNORE_PATH).filter(line => !line.startsWith('#')) /** - * Get multiple value arg - * @param {String} arg Ex: '--my-option' - * @param {Array} values - * @returns {Array} ['--ignore-pattern', 'folder/', ...] + * Get from git status name of staged files + * @param {string[]} extensions Extensions list. Example: ['js', 'sass', 'css'] + * @returns {Promise} Array of file paths */ -const getArrayArgs = (arg, values) => - values.filter(Boolean).map(pattern => `${arg} "${pattern}"`) +const getGitDiffFiles = async ({extensions, range = null, staged = true}) => { + const command = [ + 'git diff --name-only --diff-filter=d', + range && `${range}`, + staged && '--cached' + ] + .filter(Boolean) + .join(' ') + + return exec(command).then(({stdout: summary = ''}) => + getFilesFromDiff({summary, extensions}) + ) +} /** - * Get from git status name of staged files - * @param {Array} extensions Extensions list: ['js', 'sass', 'css'] - * @returns {Promise} Array of file paths + * Filter files from git diff status stdout + * @param {string[]} extensions Extensions list. Example: ['js', 'sass', 'css'] + * @param {string} summary stdout from git diff + * @returns {string[]} Array of file paths */ -const getGitStatusFiles = async extensions => - new Promise((resolve, reject) => { - git().diff( - ['--cached', '--name-only', '--diff-filter=d'], // Delete files as excluded - (err, summary) => { - err && reject(err) - const files = summary - ? summary - .split('\n') - .filter(file => extensions.includes(extname(file).substr(1))) - : [] - resolve(files) - } - ) - }) +const getFilesFromDiff = ({extensions, summary}) => + summary + .split('\n') + .filter(file => extensions.includes(extname(file).substring(1))) /** * Get files to lint according to command options - * @param {Array} extensions Extensions list: ['js', 'sass', 'css'] - * @param {String} defaultFiles Defaults to './' - * @returns {Promise} Array of file patterns + * @param {string[]} extensions Extensions list: ['js', 'sass', 'css'] + * @param {string} defaultFiles Defaults to './' + * @returns {Promise} Array of file patterns */ -const getFilesToLint = async (extensions, defaultFiles = './') => - process.argv.includes(OPTIONS.staged) - ? getGitStatusFiles(extensions) +const getFilesToLint = async (extensions, defaultFiles = './') => { + const {TRAVIS_COMMIT_RANGE: range} = process.env + const staged = process.argv.includes(OPTIONS.staged) + const getFromDiff = range || staged + + return getFromDiff + ? getGitDiffFiles({extensions, range, staged}) : [defaultFiles] +} /** * If --staged option is on, it will staged made changes @@ -104,8 +85,7 @@ const getFilesToLint = async (extensions, defaultFiles = './') => const stageFilesIfRequired = async extensions => { const {argv} = process if (argv.includes(OPTIONS.staged) && argv.includes(OPTIONS.addFixes)) { - const {getSpawnPromise} = require('@s-ui/helpers/cli') - const files = await getGitStatusFiles(extensions) + const files = await getGitStagedFiles(extensions) return getSpawnPromise('git', ['add', ...files]) } } @@ -114,11 +94,9 @@ const stageFilesIfRequired = async extensions => { * Get if current process has option set * @param {String} option */ -const isOptionSet = option => process.argv.includes(option) +const isOptionSet = option => process.argv.includes(`--${option}`) -exports.executeLintingCommand = executeLintingCommand exports.getFileLinesAsArray = getFileLinesAsArray -exports.getArrayArgs = getArrayArgs exports.getFilesToLint = getFilesToLint exports.getGitIgnoredFiles = getGitIgnoredFiles exports.stageFilesIfRequired = stageFilesIfRequired From 0f8850a59f8edf38fe9fb48316ebadaad34f94f8 Mon Sep 17 00:00:00 2001 From: Joan Manrubia Date: Fri, 15 Oct 2021 12:57:43 +0200 Subject: [PATCH 04/90] feat(packages/sui-studio) trim empty lines for a generated testTemplate --- .../sui-studio/bin/sui-studio-generate.js | 101 +++++++++--------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/packages/sui-studio/bin/sui-studio-generate.js b/packages/sui-studio/bin/sui-studio-generate.js index fa48b0306..7b29f2f91 100755 --- a/packages/sui-studio/bin/sui-studio-generate.js +++ b/packages/sui-studio/bin/sui-studio-generate.js @@ -73,6 +73,57 @@ const packageName = `${packageScope}${prefix}-${packageCategory}${toKebabCase( const packageInfo = require(path.join(process.cwd(), 'package.json')) const {repository = {}, homepage} = packageInfo +const trimLines = str => str.replace(/(\r\n|\r|\n){2,}/g, '$1\n') + +const testTemplate = `/* + * Remember: YOUR COMPONENT IS DEFINED GLOBALLY + * */ + +/* eslint react/jsx-no-undef:0 */ +/* eslint no-undef:0 */ + +import ReactDOM from 'react-dom' + +import chai, {expect} from 'chai' +import chaiDOM from 'chai-dom' +${context ? '' : "import Component from '../src/index'"} + +${context ? "import '@s-ui/studio/src/patcher-mocha'" : ''} + +chai.use(chaiDOM) + +describe${context ? '.context.default' : ''}('${componentInPascal}', ${ + context ? 'Component' : '()' +} => { + const setup = setupEnvironment(Component) + + it('should render without crashing', () => { + // Given + const props = {} + + // When + const component = + + // Then + const div = document.createElement('div') + ReactDOM.render(component, div) + ReactDOM.unmountComponentAtNode(div) + }) + + it('should NOT render null', () => { + // Given + const props = {} + + // When + const {container} = setup(props) + + // Then + expect(container.innerHTML).to.be.a('string') + expect(container.innerHTML).to.not.have.lengthOf(0) + }) +}) +` + const defaultContext = `module.exports = { default: { i18n: { @@ -234,55 +285,7 @@ export default () => <${componentInPascal} /> const contextBuffer = fs.readFileSync(`${BASE_DIR}${context}`) writeFile(COMPONENT_CONTEXT_FILE, contextBuffer.toString()) })(), - writeFile( - COMPONENT_TEST_FILE, - `/* - * Remember: YOUR COMPONENT IS DEFINED GLOBALLY - * */ - -/* eslint react/jsx-no-undef:0 */ -/* eslint no-undef:0 */ - -import ReactDOM from 'react-dom' - -import chai, {expect} from 'chai' -import chaiDOM from 'chai-dom' -import Component from '../src/index' - -${context && "import '@s-ui/studio/src/patcher-mocha'"} - -chai.use(chaiDOM) - -describe('${componentInPascal}', () => { - const setup = setupEnvironment(Component) - - it('should render without crashing', () => { - // Given - const props = {} - - // When - const component = - - // Then - const div = document.createElement('div') - ReactDOM.render(component, div) - ReactDOM.unmountComponentAtNode(div) - }) - - it('should NOT render null', () => { - // Given - const props = {} - - // When - const {container} = setup(props) - - // Then - expect(container.innerHTML).to.be.a('string') - expect(container.innerHTML).to.not.have.lengthOf(0) - }) -}) -` - ) + writeFile(COMPONENT_TEST_FILE, trimLines(testTemplate)) ]).then(() => { console.log(colors.gray(`[${packageName}]: Installing the dependencies`)) const install = spawn('npm', ['install'], {cwd: COMPONENT_PATH}) From 8f9102d75f2708fb51fcff53bb320797d82a464a Mon Sep 17 00:00:00 2001 From: Joan Manrubia Date: Fri, 15 Oct 2021 13:06:00 +0200 Subject: [PATCH 05/90] docs(packages/sui-studio) add an example of usage of context parameter --- packages/sui-studio/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/sui-studio/README.md b/packages/sui-studio/README.md index 2ab267c26..3438ac108 100644 --- a/packages/sui-studio/README.md +++ b/packages/sui-studio/README.md @@ -32,6 +32,20 @@ Once you're in a new project, execute `sui-studio start` to start the developmen $ npx sui-studio generate house window ``` +#### Context + +Use `-C` parameter to generate the component with a default context + +```sh +$ npx sui-studio generate house window -C +``` + +Use `-C path` parameter to generate the component with a given default context + +```sh +$ npx sui-studio generate house window -C ./myCustomContext.js +``` + ### To develop the new component, #### 1) Launch the development environment From 5692a020a88551c604e72559a6be040b3aa6cd06 Mon Sep 17 00:00:00 2001 From: Joan Manrubia Date: Fri, 15 Oct 2021 13:38:24 +0200 Subject: [PATCH 06/90] docs(packages/sui-studio) be more explicit for context flag usage --- packages/sui-studio/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sui-studio/README.md b/packages/sui-studio/README.md index 3438ac108..c8781a45e 100644 --- a/packages/sui-studio/README.md +++ b/packages/sui-studio/README.md @@ -34,13 +34,13 @@ $ npx sui-studio generate house window #### Context -Use `-C` parameter to generate the component with a default context +Use `-C` or `--context` parameter to generate the component with a default context ```sh $ npx sui-studio generate house window -C ``` -Use `-C path` parameter to generate the component with a given default context +Use `-C path` or `--context path` parameter to generate the component with a given default context ```sh $ npx sui-studio generate house window -C ./myCustomContext.js From 29f686e40edbbbfb680f2d0180e357b238ed2f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Dur=C3=A1n?= Date: Mon, 18 Oct 2021 12:42:12 +0200 Subject: [PATCH 07/90] feat(packages/sui-js-compiler): Remove promise.all for now --- packages/sui-js-compiler/index.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/sui-js-compiler/index.js b/packages/sui-js-compiler/index.js index b28c48986..2ba6a42df 100755 --- a/packages/sui-js-compiler/index.js +++ b/packages/sui-js-compiler/index.js @@ -1,23 +1,20 @@ #!/usr/bin/env node const {transformFile} = require('@swc/core') -const defaultConfig = require('./swc-config.js') const fg = require('fast-glob') const fs = require('fs-extra') +const defaultConfig = require('./swc-config.js') ;(async () => { console.time('[sui-js-compiler]') const files = await fg('./src/**/*.{js,jsx}') - await Promise.all( - files.map(async file => { - const output = await transformFile(file, defaultConfig) - const {code} = output - const outputPath = file.replace('./src', './lib') - return fs.outputFile(outputPath, code) - }) - ) + files.forEach(async file => { + const {code} = await transformFile(file, defaultConfig) + const outputPath = file.replace('./src', './lib') + fs.outputFile(outputPath, code) + }) console.timeEnd('[sui-js-compiler]') })() From 0ff23531366e67dbaf64b243204a90ee193dcc04 Mon Sep 17 00:00:00 2001 From: sui-bot Date: Mon, 18 Oct 2021 10:57:04 +0000 Subject: [PATCH 08/90] release(packages/sui-js-compiler): v1.2.0 [skip ci] --- packages/sui-js-compiler/CHANGELOG.md | 9 +++++++++ packages/sui-js-compiler/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/sui-js-compiler/CHANGELOG.md b/packages/sui-js-compiler/CHANGELOG.md index a7278ad05..ad9bb7e2c 100644 --- a/packages/sui-js-compiler/CHANGELOG.md +++ b/packages/sui-js-compiler/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +# 1.2.0 (2021-10-18) + + +### Features + +* **packages/sui-js-compiler:** Remove promise.all for now ([29f686e](https://github.com/SUI-Components/sui/commit/29f686e40edbbbfb680f2d0180e357b238ed2f8b)) + + + # 1.1.0 (2021-10-05) diff --git a/packages/sui-js-compiler/package.json b/packages/sui-js-compiler/package.json index dc74807f8..b15033ae7 100644 --- a/packages/sui-js-compiler/package.json +++ b/packages/sui-js-compiler/package.json @@ -1,6 +1,6 @@ { "name": "@s-ui/js-compiler", - "version": "1.1.0", + "version": "1.2.0", "description": "JavaScript Compiler", "main": "index.js", "bin": { From e2f1ea4f837d5491f3b7647e065a30c60def8ca4 Mon Sep 17 00:00:00 2001 From: Nacho Torrella Date: Tue, 19 Oct 2021 11:21:23 +0200 Subject: [PATCH 09/90] feat(packages/sui-ssr): http cookie --- packages/sui-ssr/server/ssr/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/sui-ssr/server/ssr/index.js b/packages/sui-ssr/server/ssr/index.js index 4c52bfa07..0a0a7ac5b 100644 --- a/packages/sui-ssr/server/ssr/index.js +++ b/packages/sui-ssr/server/ssr/index.js @@ -168,7 +168,13 @@ export default async (req, res, next) => { const {__HTTP__} = initialProps if (__HTTP__) { - const {redirectTo, redirectStatusCode} = __HTTP__ + const {redirectTo, redirectStatusCode, httpCookie} = __HTTP__ + + if (httpCookie) { + const [[field, value]] = Object.entries(httpCookie) + res.cookie(field, value, {httpOnly: true}) + } + if (redirectTo) { const isValidRedirectStatusCode = redirectStatusCodes.includes( redirectStatusCode From b77f93aa8fc2cac6156aa5e81d955dc89a1a3898 Mon Sep 17 00:00:00 2001 From: Nacho Torrella Date: Tue, 19 Oct 2021 11:58:46 +0200 Subject: [PATCH 10/90] feat(packages/sui-react-initial-props): update readme according ton new htppCookie sui-ssr feature --- packages/sui-react-initial-props/README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/sui-react-initial-props/README.md b/packages/sui-react-initial-props/README.md index 8013fc1ad..ad6e7f9da 100644 --- a/packages/sui-react-initial-props/README.md +++ b/packages/sui-react-initial-props/README.md @@ -76,7 +76,13 @@ Page.getInitialProps = ({ context, routeInfo }) => Promise.resolve({ initialContent: 'This is the initial content', // Optional __HTTP__ object to perform 301 Redirects - __HTTP__: {redirectTo: 'https://<301 Redirect Route>'} + __HTTP__: { + redirectTo: 'https://<301 Redirect Route>', + // Optional object to set an Http-Cookie before redirection + httpCookie: { + AdNotAvailable: true + } + } }) /** * Determine if Page should be kept while navigating on client between routes for the same page. @@ -154,7 +160,7 @@ The response is a promise resolved with two parameters. In addition, you can def Field | Type | Description --- | --- | --- initialProps | `object` | Result of executing the `getInitialProps` of the pageComponent. -initialprops.__HTTP__ | `object` | An optional object containing a `redirectTo` key where an url might be included to allow 3XX server side redirects using [sui-ssr](https://github.com/SUI-Components/sui/tree/master/packages/sui-ssr). By default, redirect status code is 301, but you may set a valid `redirectStatusCode` option set in the file `@s-ui/ssr/status-codes`. +initialprops.__HTTP__ | `object` | An optional object containing a `redirectTo` key where an url might be included to allow 3XX server side redirects using [sui-ssr]. By default, redirect status code is 301, but you may set a valid `redirectStatusCode` option set in the file `@s-ui/ssr/status-codes` and an optional `httpCookie` key where you will define an object with the key/value of the `Http-Cookie` to be set from server. (see https://github.com/SUI-Components/sui/tree/master/packages/sui-ssr) reactString | `string` | String with the renderized app ready to be sent. #### loadPage(contextFactory, importPage) From 0478b5da8f2f459cf818ca0b7783753c05238170 Mon Sep 17 00:00:00 2001 From: Nacho Torrella Date: Tue, 19 Oct 2021 11:59:23 +0200 Subject: [PATCH 11/90] feat(packages/sui-ssr): update readme according ton new htppCookie sui-ssr feature --- packages/sui-ssr/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/sui-ssr/README.md b/packages/sui-ssr/README.md index 739a36471..d7f50ca71 100644 --- a/packages/sui-ssr/README.md +++ b/packages/sui-ssr/README.md @@ -371,6 +371,11 @@ SOME_OTHER_ENV_VAR: https://pre.somedomain.com/contact SUI-SSR allows any kind of redirects (3XX) in server side rendering when combined with SUI-REACT-INITIAL-PROPS. Check out its [documentation](https://github.com/SUI-Components/sui/tree/master/packages/sui-react-initial-props#response-2) to get detailed information and an implementation example. +## Server Side Htpp-Cookie + +SUI-SSR allows to set an Http-Cookie in server side rendering when combined with SUI-REACT-INITIAL-PROPS. +Check out its [documentation](https://github.com/SUI-Components/sui/tree/master/packages/sui-react-initial-props#response-2) to get detailed information and an implementation example. + ## Third Parties It is very likely that for performance reasons you will want to put the third party scripts directly into the index.html of your page. From 473b4aeb6a1a42c1d57d76671833ff0f0504a365 Mon Sep 17 00:00:00 2001 From: sui-bot Date: Tue, 19 Oct 2021 10:49:28 +0000 Subject: [PATCH 12/90] release(packages/sui-react-initial-props): v2.19.0 [skip ci] --- packages/sui-react-initial-props/CHANGELOG.md | 9 +++++++++ packages/sui-react-initial-props/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/sui-react-initial-props/CHANGELOG.md b/packages/sui-react-initial-props/CHANGELOG.md index 0ca66b591..05d365b1e 100644 --- a/packages/sui-react-initial-props/CHANGELOG.md +++ b/packages/sui-react-initial-props/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +# 2.19.0 (2021-10-19) + + +### Features + +* **packages/sui-react-initial-props:** update readme according ton new htppCookie sui-ssr feature ([b77f93a](https://github.com/SUI-Components/sui/commit/b77f93aa8fc2cac6156aa5e81d955dc89a1a3898)) + + + # 2.18.0 (2021-10-06) diff --git a/packages/sui-react-initial-props/package.json b/packages/sui-react-initial-props/package.json index 424f53960..983a0124f 100644 --- a/packages/sui-react-initial-props/package.json +++ b/packages/sui-react-initial-props/package.json @@ -1,6 +1,6 @@ { "name": "@s-ui/react-initial-props", - "version": "2.18.0", + "version": "2.19.0", "main": "lib/index.js", "types": "lib/index.d.ts", "description": "Provide a way to get initial props for async pages", From fe1576e2975fbf5df05cadffe2cd5c34780668eb Mon Sep 17 00:00:00 2001 From: sui-bot Date: Tue, 19 Oct 2021 10:49:33 +0000 Subject: [PATCH 13/90] release(packages/sui-ssr): v7.39.0 [skip ci] --- packages/sui-ssr/CHANGELOG.md | 10 ++++++++++ packages/sui-ssr/package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/sui-ssr/CHANGELOG.md b/packages/sui-ssr/CHANGELOG.md index 5283b033c..782858bd8 100644 --- a/packages/sui-ssr/CHANGELOG.md +++ b/packages/sui-ssr/CHANGELOG.md @@ -1,5 +1,15 @@ # CHANGELOG +# 7.39.0 (2021-10-19) + + +### Features + +* **packages/sui-ssr:** http cookie ([e2f1ea4](https://github.com/SUI-Components/sui/commit/e2f1ea4f837d5491f3b7647e065a30c60def8ca4)) +* **packages/sui-ssr:** update readme according ton new htppCookie sui-ssr feature ([0478b5d](https://github.com/SUI-Components/sui/commit/0478b5da8f2f459cf818ca0b7783753c05238170)) + + + # 7.38.0 (2021-08-17) diff --git a/packages/sui-ssr/package.json b/packages/sui-ssr/package.json index 0483a552c..8c06f1075 100644 --- a/packages/sui-ssr/package.json +++ b/packages/sui-ssr/package.json @@ -1,6 +1,6 @@ { "name": "@s-ui/ssr", - "version": "7.38.0", + "version": "7.39.0", "description": "> Plug SSR to you SUI SPA.", "main": "index.js", "bin": { From 3ceb2852691568285b70938e5d2235e7f8dd1292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Dur=C3=A1n?= Date: Tue, 19 Oct 2021 17:05:07 +0200 Subject: [PATCH 14/90] fix(packages/sui-studio): Add Babel package on index.html for dev mode --- packages/sui-studio/src/components/preview/index.js | 1 + packages/sui-studio/workbench/src/index.html | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/sui-studio/src/components/preview/index.js b/packages/sui-studio/src/components/preview/index.js index b35f96b92..15cf29264 100644 --- a/packages/sui-studio/src/components/preview/index.js +++ b/packages/sui-studio/src/components/preview/index.js @@ -20,6 +20,7 @@ const getCompiledCode = ({code, scope}) => { previousCode = code return code } catch (e) { + console.error(e) return previousCode } } diff --git a/packages/sui-studio/workbench/src/index.html b/packages/sui-studio/workbench/src/index.html index f785debef..ec612f023 100644 --- a/packages/sui-studio/workbench/src/index.html +++ b/packages/sui-studio/workbench/src/index.html @@ -3,6 +3,7 @@ SUI Studio +