diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-10 18:09:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-10 18:09:11 +0300 |
commit | d2091d1e924e2887eb9db4fad761965a24d024f1 (patch) | |
tree | 482fe37d97a4169895ae3ddf6d6f42e6f632cbb9 /scripts/frontend | |
parent | 152b3268d701b54cac9b615a0e29e0e5726bfd99 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts/frontend')
-rw-r--r-- | scripts/frontend/block_dependencies.js | 8 | ||||
-rwxr-xr-x | scripts/frontend/check_page_bundle_mixins_css_for_sideeffects.js | 2 | ||||
-rw-r--r-- | scripts/frontend/extract_gettext_all.js | 39 | ||||
-rwxr-xr-x | scripts/frontend/file_test_coverage.js | 44 | ||||
-rw-r--r-- | scripts/frontend/merge_coverage_frontend.js | 13 | ||||
-rw-r--r-- | scripts/frontend/parallel_ci_sequencer.js | 24 | ||||
-rw-r--r-- | scripts/frontend/stylelint/stylelint-duplicate-selectors.js | 6 | ||||
-rw-r--r-- | scripts/frontend/stylelint/stylelint-utility-classes.js | 5 | ||||
-rw-r--r-- | scripts/frontend/stylelint/stylelint-utility-map.js | 30 | ||||
-rw-r--r-- | scripts/frontend/stylelint/stylelint-utils.js | 11 | ||||
-rwxr-xr-x | scripts/frontend/webpack_dev_server.js | 12 |
11 files changed, 110 insertions, 84 deletions
diff --git a/scripts/frontend/block_dependencies.js b/scripts/frontend/block_dependencies.js index a1ff8d5ee36..f229f317cbb 100644 --- a/scripts/frontend/block_dependencies.js +++ b/scripts/frontend/block_dependencies.js @@ -1,8 +1,8 @@ -const path = require('path'); -const packageJson = require(path.join(process.cwd(), 'package.json')); +const packageJson = require('../../package.json'); + const blockedDependencies = packageJson.blockedDependencies || {}; -const dependencies = packageJson.dependencies; -const devDependencies = packageJson.devDependencies; +const { dependencies } = packageJson; +const { devDependencies } = packageJson; const blockedDependenciesNames = Object.keys(blockedDependencies); const blockedDependenciesFound = blockedDependenciesNames.filter( (blockedDependency) => dependencies[blockedDependency] || devDependencies[blockedDependency], diff --git a/scripts/frontend/check_page_bundle_mixins_css_for_sideeffects.js b/scripts/frontend/check_page_bundle_mixins_css_for_sideeffects.js index 34e939e3ceb..22a4aac762b 100755 --- a/scripts/frontend/check_page_bundle_mixins_css_for_sideeffects.js +++ b/scripts/frontend/check_page_bundle_mixins_css_for_sideeffects.js @@ -7,9 +7,9 @@ if (process.env.RAILS_ENV !== 'production') { process.exit(0); } -const path = require('path'); const fs = require('fs'); const glob = require('glob'); +const path = require('path'); const pjs = require('postcss'); const paths = glob.sync('public/assets/page_bundles/_mixins_and_variables_and_functions*.css', { diff --git a/scripts/frontend/extract_gettext_all.js b/scripts/frontend/extract_gettext_all.js index 67163a601bc..896790a73bb 100644 --- a/scripts/frontend/extract_gettext_all.js +++ b/scripts/frontend/extract_gettext_all.js @@ -5,6 +5,7 @@ const { decorateJSParserWithVueSupport, decorateExtractorWithHelpers, } = require('gettext-extractor-vue'); +const vue2TemplateCompiler = require('vue-template-compiler'); const ensureSingleLine = require('../../app/assets/javascripts/locale/ensure_single_line.js'); const args = argumentsParser @@ -37,12 +38,12 @@ const jsParser = extractor.createJsParser([ ]); const vueParser = decorateJSParserWithVueSupport(jsParser, { - vue2TemplateCompiler: require('vue-template-compiler'), + vue2TemplateCompiler, }); function printJson() { - const messages = extractor.getMessages().reduce((result, message) => { - let text = message.text; + const messages = extractor.getMessages().reduce((acc, message) => { + let { text } = message; if (message.textPlural) { text += `\u0000${message.textPlural}`; } @@ -50,25 +51,35 @@ function printJson() { message.references.forEach((reference) => { const filename = reference.replace(/:\d+$/, ''); - if (!Array.isArray(result[filename])) { - result[filename] = []; + if (!Array.isArray(acc[filename])) { + acc[filename] = []; } - result[filename].push([text, reference]); + acc[filename].push([text, reference]); }); - return result; + return acc; }, {}); console.log(JSON.stringify(messages)); } -if (args.file) { - vueParser.parseFile(args.file).then(() => printJson()); -} else if (args.all) { - vueParser.parseFilesGlob('{ee/app,app}/assets/javascripts/**/*.{js,vue}').then(() => printJson()); -} else { - console.warn('ERROR: Please use the script correctly:'); +async function main() { + if (args.file) { + return vueParser.parseFile(args.file).then(() => printJson()); + } + + if (args.all) { + return vueParser + .parseFilesGlob('{ee/app,app}/assets/javascripts/**/*.{js,vue}') + .then(() => printJson()); + } + + throw new Error('ERROR: Please use the script correctly:'); +} + +main().catch((error) => { + console.warn(error.message); args.outputHelp(); process.exit(1); -} +}); diff --git a/scripts/frontend/file_test_coverage.js b/scripts/frontend/file_test_coverage.js index ec6ec4a1e9d..04a9035fce2 100755 --- a/scripts/frontend/file_test_coverage.js +++ b/scripts/frontend/file_test_coverage.js @@ -31,28 +31,6 @@ let numTestFiles = 0; const isVerbose = process.argv.some((arg) => arg === '-v'); -const countSourceFiles = (path) => - forEachFileIn(path, (fileName) => { - if (fileName.endsWith('.vue') || fileName.endsWith('.js')) { - if (isVerbose) { - console.log(`source file: ${fileName}`); - } - - numSourceFiles += 1; - } - }); - -const countTestFiles = (path) => - forEachFileIn(path, (fileName) => { - if (fileName.endsWith('_spec.js')) { - if (isVerbose) { - console.log(`test file: ${fileName}`); - } - - numTestFiles += 1; - } - }); - function forEachFileIn(dirPath, callback) { fs.readdir(dirPath, (err, files) => { if (err) { @@ -75,6 +53,28 @@ function forEachFileIn(dirPath, callback) { }); } +const countSourceFiles = (currentPath) => + forEachFileIn(currentPath, (fileName) => { + if (fileName.endsWith('.vue') || fileName.endsWith('.js')) { + if (isVerbose) { + console.log(`source file: ${fileName}`); + } + + numSourceFiles += 1; + } + }); + +const countTestFiles = (currentPath) => + forEachFileIn(currentPath, (fileName) => { + if (fileName.endsWith('_spec.js')) { + if (isVerbose) { + console.log(`test file: ${fileName}`); + } + + numTestFiles += 1; + } + }); + console.log(`Source directories: ${sourceDirectories.join(', ')}`); console.log(`Test directories: ${testDirectories.join(', ')}`); diff --git a/scripts/frontend/merge_coverage_frontend.js b/scripts/frontend/merge_coverage_frontend.js index 0c45a38b9b5..6b3826ddac7 100644 --- a/scripts/frontend/merge_coverage_frontend.js +++ b/scripts/frontend/merge_coverage_frontend.js @@ -1,8 +1,8 @@ -const { create } = require('istanbul-reports'); +const { sync } = require('glob'); const { createCoverageMap } = require('istanbul-lib-coverage'); const { createContext } = require('istanbul-lib-report'); +const { create } = require('istanbul-reports'); const { resolve } = require('path'); -const { sync } = require('glob'); const coverageMap = createCoverageMap(); @@ -12,7 +12,7 @@ const reportFiles = sync(`${coverageDir}/*/coverage-final.json`); // Normalize coverage report generated by jest that has additional "data" key // https://github.com/facebook/jest/issues/2418#issuecomment-423806659 const normalizeReport = (report) => { - const normalizedReport = Object.assign({}, report); + const normalizedReport = { ...report }; Object.entries(normalizedReport).forEach(([k, v]) => { if (v.data) normalizedReport[k] = v.data; }); @@ -20,11 +20,14 @@ const normalizeReport = (report) => { }; reportFiles - .map((reportFile) => require(reportFile)) + .map((reportFile) => { + // eslint-disable-next-line global-require, import/no-dynamic-require + return require(reportFile); + }) .map(normalizeReport) .forEach((report) => coverageMap.merge(report)); -const context = createContext({ coverageMap: coverageMap, dir: 'coverage-frontend' }); +const context = createContext({ coverageMap, dir: 'coverage-frontend' }); ['json', 'lcov', 'text-summary', 'clover', 'cobertura'].forEach((reporter) => { create(reporter, {}).execute(context); diff --git a/scripts/frontend/parallel_ci_sequencer.js b/scripts/frontend/parallel_ci_sequencer.js index d7a674535a6..262e9e2256e 100644 --- a/scripts/frontend/parallel_ci_sequencer.js +++ b/scripts/frontend/parallel_ci_sequencer.js @@ -1,5 +1,15 @@ const Sequencer = require('@jest/test-sequencer').default; +const sortByPath = (test1, test2) => { + if (test1.path < test2.path) { + return -1; + } + if (test1.path > test2.path) { + return 1; + } + return 0; +}; + class ParallelCISequencer extends Sequencer { constructor() { super(); @@ -8,7 +18,7 @@ class ParallelCISequencer extends Sequencer { } sort(tests) { - const sortedTests = this.sortByPath(tests); + const sortedTests = [...tests].sort(sortByPath); const testsForThisRunner = this.distributeAcrossCINodes(sortedTests); console.log(`CI_NODE_INDEX: ${this.ciNodeIndex}`); @@ -19,18 +29,6 @@ class ParallelCISequencer extends Sequencer { return testsForThisRunner; } - sortByPath(tests) { - return tests.sort((test1, test2) => { - if (test1.path < test2.path) { - return -1; - } - if (test1.path > test2.path) { - return 1; - } - return 0; - }); - } - distributeAcrossCINodes(tests) { return tests.filter((test, index) => { return index % this.ciNodeTotal === this.ciNodeIndex - 1; diff --git a/scripts/frontend/stylelint/stylelint-duplicate-selectors.js b/scripts/frontend/stylelint/stylelint-duplicate-selectors.js index 89242158157..982ddf524a3 100644 --- a/scripts/frontend/stylelint/stylelint-duplicate-selectors.js +++ b/scripts/frontend/stylelint/stylelint-duplicate-selectors.js @@ -1,5 +1,6 @@ const stylelint = require('stylelint'); const utils = require('./stylelint-utils'); + const ruleName = 'stylelint-gitlab/duplicate-selectors'; const messages = stylelint.utils.ruleMessages(ruleName, { @@ -8,12 +9,13 @@ const messages = stylelint.utils.ruleMessages(ruleName, { }, }); -module.exports = stylelint.createPlugin(ruleName, function (enabled) { +module.exports = stylelint.createPlugin(ruleName, (enabled) => { if (!enabled) { return; } - return function (root, result) { + // eslint-disable-next-line consistent-return + return (root, result) => { const selectorGroups = {}; utils.createPropertiesHashmap(root, result, ruleName, messages, selectorGroups, true); }; diff --git a/scripts/frontend/stylelint/stylelint-utility-classes.js b/scripts/frontend/stylelint/stylelint-utility-classes.js index 1b266fc31c9..420fe82d826 100644 --- a/scripts/frontend/stylelint/stylelint-utility-classes.js +++ b/scripts/frontend/stylelint/stylelint-utility-classes.js @@ -10,12 +10,13 @@ const messages = stylelint.utils.ruleMessages(ruleName, { }, }); -module.exports = stylelint.createPlugin(ruleName, function (enabled) { +module.exports = stylelint.createPlugin(ruleName, (enabled) => { if (!enabled) { return; } - return function (root, result) { + // eslint-disable-next-line consistent-return + return (root, result) => { utils.createPropertiesHashmap(root, result, ruleName, messages, utilityClasses, false); }; }); diff --git a/scripts/frontend/stylelint/stylelint-utility-map.js b/scripts/frontend/stylelint/stylelint-utility-map.js index bf8ee362740..545aade9ccc 100644 --- a/scripts/frontend/stylelint/stylelint-utility-map.js +++ b/scripts/frontend/stylelint/stylelint-utility-map.js @@ -1,10 +1,11 @@ -const sass = require('node-sass'); -const postcss = require('postcss'); const fs = require('fs'); +const sass = require('node-sass'); const path = require('path'); +const postcss = require('postcss'); const prettier = require('prettier'); const utils = require('./stylelint-utils'); + const ROOT_PATH = path.resolve(__dirname, '../../..'); const hashMapPath = path.resolve(__dirname, './utility-classes-map.js'); @@ -22,19 +23,28 @@ sass.render( includePaths: [path.resolve(ROOT_PATH, 'node_modules/bootstrap/scss')], }, (err, result) => { - if (err) console.error('Error ', err); + if (err) { + return console.error('Error ', err); + } const cssResult = result.css.toString(); // We just use postcss to create a CSS tree - postcss([]) + return postcss([]) .process(cssResult, { // This suppresses a postcss warning from: undefined, }) - .then((result) => { + .then((processedResult) => { const selectorGroups = {}; - utils.createPropertiesHashmap(result.root, result, null, null, selectorGroups, true); + utils.createPropertiesHashmap( + processedResult.root, + processedResult, + null, + null, + selectorGroups, + true, + ); const prettierOptions = prettier.resolveConfig.sync(hashMapPath); const prettyHashmap = prettier.format( @@ -42,12 +52,12 @@ sass.render( prettierOptions, ); - fs.writeFile(hashMapPath, prettyHashmap, function (err) { - if (err) { - return console.log(err); + fs.writeFile(hashMapPath, prettyHashmap, (e) => { + if (e) { + return console.log(e); } - console.log('The file was saved!'); + return console.log('The file was saved!'); }); }); }, diff --git a/scripts/frontend/stylelint/stylelint-utils.js b/scripts/frontend/stylelint/stylelint-utils.js index e7452b0cdb2..c9d9c7d9aad 100644 --- a/scripts/frontend/stylelint/stylelint-utils.js +++ b/scripts/frontend/stylelint/stylelint-utils.js @@ -1,5 +1,5 @@ -const stylelint = require('stylelint'); const md5 = require('md5'); +const stylelint = require('stylelint'); module.exports.createPropertiesHashmap = ( ruleRoot, @@ -15,7 +15,7 @@ module.exports.createPropertiesHashmap = ( if ( rule && rule.parent && - rule.parent.type != 'atrule' && + rule.parent.type !== 'atrule' && !( selector.includes('-webkit-') || selector.includes('-moz-') || @@ -25,7 +25,7 @@ module.exports.createPropertiesHashmap = ( ) ) { let cssArray = []; - rule.nodes.forEach(function (property) { + rule.nodes.forEach((property) => { const { prop, value } = property; if (property && value) { const propval = `${prop}${value}${property.important ? '!important' : ''}`; @@ -41,11 +41,11 @@ module.exports.createPropertiesHashmap = ( const selObj = selectorGroups[hashValue]; const selectorLine = `${selector} (${ - rule.source.input.file ? rule.source.input.file + ' -' : '' + rule.source.input.file ? `${rule.source.input.file} -` : '' }${rule.source.start.line}:${rule.source.start.column})`; if (selObj) { - if (selectorGroups[hashValue].selectors.indexOf(selector) == -1) { + if (selectorGroups[hashValue].selectors.indexOf(selector) === -1) { let lastSelector = selectorGroups[hashValue].selectors[selectorGroups[hashValue].selectors.length - 1]; @@ -67,6 +67,7 @@ module.exports.createPropertiesHashmap = ( } } } else if (addSelectors) { + // eslint-disable-next-line no-param-reassign selectorGroups[hashValue] = { selectors: [selectorLine], }; diff --git a/scripts/frontend/webpack_dev_server.js b/scripts/frontend/webpack_dev_server.js index fbb80c9617d..a76e6dc024a 100755 --- a/scripts/frontend/webpack_dev_server.js +++ b/scripts/frontend/webpack_dev_server.js @@ -2,8 +2,8 @@ const nodemon = require('nodemon'); const DEV_SERVER_HOST = process.env.DEV_SERVER_HOST || 'localhost'; const DEV_SERVER_PORT = process.env.DEV_SERVER_PORT || '3808'; -const STATIC_MODE = process.env.DEV_SERVER_STATIC && process.env.DEV_SERVER_STATIC != 'false'; -const DLL_MODE = process.env.WEBPACK_VENDOR_DLL && process.env.WEBPACK_VENDOR_DLL != 'false'; +const STATIC_MODE = process.env.DEV_SERVER_STATIC && process.env.DEV_SERVER_STATIC !== 'false'; +const DLL_MODE = process.env.WEBPACK_VENDOR_DLL && process.env.WEBPACK_VENDOR_DLL !== 'false'; const baseConfig = { ignoreRoot: ['.git', 'node_modules/*/'], @@ -30,7 +30,7 @@ if (STATIC_MODE) { // run webpack through webpack-dev-server, optionally compiling a DLL to reduce memory else { - let watch = ['config/webpack.config.js']; + const watch = ['config/webpack.config.js']; // if utilizing the vendor DLL, we need to restart the process when dependency changes occur if (DLL_MODE) { @@ -51,7 +51,7 @@ else { // print useful messages for nodemon events nodemon - .on('start', function () { + .on('start', () => { console.log(`Starting webpack webserver on http://${DEV_SERVER_HOST}:${DEV_SERVER_PORT}`); if (STATIC_MODE) { console.log('You are starting webpack in compile-once mode'); @@ -59,10 +59,10 @@ nodemon console.log('If you change them often, you might want to unset DEV_SERVER_STATIC'); } }) - .on('quit', function () { + .on('quit', () => { console.log('Shutting down webpack process'); process.exit(); }) - .on('restart', function (files) { + .on('restart', (files) => { console.log('Restarting webpack process due to: ', files); }); |