From 120305904f3cfd4df28087afb5b7c130931e7b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20=C3=85str=C3=B6m?= Date: Thu, 10 Aug 2023 09:36:34 +0200 Subject: [PATCH] chore: clean warnings in build (#1327) * chore: clean warnings in build * chore: fix test * chore: revert semver things --- .../src/components/listbox/ListBox.jsx | 6 ++--- .../listbox/components/ListBoxDisclaimer.jsx | 6 ++--- .../listbox/components/ListBoxError.jsx | 4 ++-- .../listbox/components/ScreenReaders.jsx | 20 +++++++++++----- apis/nucleus/src/sn/__tests__/type.test.js | 23 ++++++++++--------- apis/nucleus/src/sn/type.js | 2 +- commands/build/lib/build.js | 1 + commands/build/lib/resolveNative.js | 1 + commands/build/lib/watch.js | 1 + commands/cli/lib/index.js | 1 + commands/create/lib/create.js | 1 + .../sn/picasso/common/src/pic-selections.js | 2 +- commands/sense/lib/build.js | 1 + commands/serve/lib/fixtures.js | 1 + commands/serve/lib/placeholder.js | 1 + commands/serve/lib/webpack.serve.js | 2 +- .../web/components/Visualize/Visualize.jsx | 14 +++++------ rollup.config.js | 10 +++++++- 18 files changed, 61 insertions(+), 36 deletions(-) diff --git a/apis/nucleus/src/components/listbox/ListBox.jsx b/apis/nucleus/src/components/listbox/ListBox.jsx index 96bf26a9a..89f6d4f73 100644 --- a/apis/nucleus/src/components/listbox/ListBox.jsx +++ b/apis/nucleus/src/components/listbox/ListBox.jsx @@ -57,7 +57,7 @@ export default function ListBox({ showSearch, isModal, }) { - const { translator } = useContext(InstanceContext); + const { translator: translatorDynamic } = useContext(InstanceContext); const [initScrollPosIsSet, setInitScrollPosIsSet] = useState(false); const isSingleSelect = !!(layout && layout.qListObject.qDimensionInfo.qIsOneAndOnlyOne); const { checkboxes = checkboxOption, histogram } = layout ?? {}; @@ -225,7 +225,7 @@ export default function ListBox({ useEffect(() => { if (inputText) { const srText = getScreenReaderSearchText(listCount); - const srFinalText = translator.get(srText, [listCount]); + const srFinalText = translatorDynamic.get(srText, [listCount]); setScreenReaderText(srFinalText); } }, [inputText, listCount]); @@ -306,7 +306,7 @@ export default function ListBox({ constraints, frequencyMax, freqIsAllowed, - translator, + translator: translatorDynamic, showSearch, isModal, }); diff --git a/apis/nucleus/src/components/listbox/components/ListBoxDisclaimer.jsx b/apis/nucleus/src/components/listbox/components/ListBoxDisclaimer.jsx index 3e41b5634..f54d8fb36 100644 --- a/apis/nucleus/src/components/listbox/components/ListBoxDisclaimer.jsx +++ b/apis/nucleus/src/components/listbox/components/ListBoxDisclaimer.jsx @@ -18,12 +18,12 @@ const StyledText = styled(Typography, { shouldForwardProp: (p) => !['width', 'de ); export default function ListBoxDisclaimer({ width, text, dense, tooltip }) { - const { translator } = useContext(InstanceContext); + const { translator: translatorDynamic } = useContext(InstanceContext); return ( - + - {translator.get(text)} + {translatorDynamic.get(text)} ); diff --git a/apis/nucleus/src/components/listbox/components/ListBoxError.jsx b/apis/nucleus/src/components/listbox/components/ListBoxError.jsx index 869dffa49..bf68da9f3 100644 --- a/apis/nucleus/src/components/listbox/components/ListBoxError.jsx +++ b/apis/nucleus/src/components/listbox/components/ListBoxError.jsx @@ -11,6 +11,6 @@ const StyledDiv = styled('div')(() => ({ })); export default function ListBoxError({ text }) { - const { translator } = useContext(InstanceContext); - return {translator.get(text)}; + const { translator: translatorDynamic } = useContext(InstanceContext); + return {translatorDynamic.get(text)}; } diff --git a/apis/nucleus/src/components/listbox/components/ScreenReaders.jsx b/apis/nucleus/src/components/listbox/components/ScreenReaders.jsx index 5bf0c942c..80d1da750 100644 --- a/apis/nucleus/src/components/listbox/components/ScreenReaders.jsx +++ b/apis/nucleus/src/components/listbox/components/ScreenReaders.jsx @@ -12,21 +12,29 @@ const LOC_STATES = { XL: 'Object.Listbox.ExcludedLock', }; -export function getValueLabel({ translator, label, qState, isSelected, currentIndex, maxIndex, showSearch }) { +export function getValueLabel({ + translator: translatorDynamic, + label, + qState, + isSelected, + currentIndex, + maxIndex, + showSearch, +}) { const stateTranslation = LOC_STATES[qState]; - const state = translator.get(stateTranslation); + const state = translatorDynamic.get(stateTranslation); const srStringArr = []; if (isSelected) { const navTranslation = showSearch ? 'Listbox.ScreenReader.SearchThenSelectionsMenu.WithAccSelMenu' : 'Listbox.ScreenReader.SelectionMenu.WithAccSelMenu'; - const nav = translator.get(navTranslation); + const nav = translatorDynamic.get(navTranslation); srStringArr.push(nav); } const valueString = `${label} ${state}`; - const indexString = translator.get('CurrentSelections.Of', [currentIndex + 1, maxIndex + 1]); // E.g. 3 of 20 + const indexString = translatorDynamic.get('CurrentSelections.Of', [currentIndex + 1, maxIndex + 1]); // E.g. 3 of 20 srStringArr.unshift(valueString, indexString); const srString = srStringArr.join('. ').trim(); return srString; @@ -40,7 +48,7 @@ export function getValueLabel({ translator, label, qState, isSelected, currentIn * @returns {Element} An (invisible) component. */ export function ScreenReaderForSelections({ layout }) { - const { translator } = useContext(InstanceContext); + const { translator: translatorDynamic } = useContext(InstanceContext); const { qStateCounts: s = {} } = layout?.qListObject?.qDimensionInfo || {}; const count = s.qSelected + s.qSelectedExcluded + s.qLocked + s.qLockedExcluded; @@ -58,7 +66,7 @@ export function ScreenReaderForSelections({ layout }) { break; } - const text = translator.get(t, [count]); + const text = translatorDynamic.get(t, [count]); return (
diff --git a/apis/nucleus/src/sn/__tests__/type.test.js b/apis/nucleus/src/sn/__tests__/type.test.js index 30ab6f28f..35f43b8f0 100644 --- a/apis/nucleus/src/sn/__tests__/type.test.js +++ b/apis/nucleus/src/sn/__tests__/type.test.js @@ -1,25 +1,20 @@ -/* eslint import/newline-after-import: 0 */ import * as loadModule from '../load'; import create from '../type'; -const semverModule = require('semver'); + const supernovaModule = require('@nebula.js/supernova'); jest.mock('@nebula.js/supernova', () => ({ ...jest.requireActual('@nebula.js/supernova') })); -jest.mock('semver', () => ({ ...jest.requireActual('semver') })); describe('type', () => { let c; let SNFactory; let load; - let satisfies; let halo; beforeEach(() => { SNFactory = jest.fn(); load = jest.fn(); - satisfies = jest.fn(); jest.spyOn(supernovaModule, 'generator').mockImplementation(SNFactory); - jest.spyOn(semverModule, 'satisfies').mockImplementation(satisfies); jest.spyOn(loadModule, 'load').mockImplementation(load); halo = { public: { env: 'env' } }; @@ -38,10 +33,6 @@ describe('type', () => { }); describe('supportsPropertiesVersion', () => { - beforeEach(() => { - satisfies.mockReturnValue('a bool'); - }); - test('should return true when no meta is provided', () => { const cc = create({}); expect(cc.supportsPropertiesVersion('1.2.0')).toBe(true); @@ -54,7 +45,17 @@ describe('type', () => { test('should return semver satisfaction when version and semver range is provided ', () => { const cc = create({}, 'c', { meta: { deps: { properties: '^1.0.0' } } }); - expect(cc.supportsPropertiesVersion('1.2.0')).toBe('a bool'); + expect(cc.supportsPropertiesVersion('1.2.0')).toBe(true); + }); + + test('should return semver satisfaction when version and semver is not a range', () => { + const cc = create({}, 'c', { meta: { deps: { properties: '1.0.0' } } }); + expect(cc.supportsPropertiesVersion('1.2.0')).toBe(false); + }); + + test('should return semver satisfaction when version and semver is an open range', () => { + const cc = create({}, 'c', { meta: { deps: { properties: '>=1.0.0' } } }); + expect(cc.supportsPropertiesVersion('2.2.0')).toBe(true); }); }); diff --git a/apis/nucleus/src/sn/type.js b/apis/nucleus/src/sn/type.js index ccc06500e..d8e193187 100644 --- a/apis/nucleus/src/sn/type.js +++ b/apis/nucleus/src/sn/type.js @@ -1,6 +1,6 @@ import { generator as SNFactory } from '@nebula.js/supernova'; -import { satisfies } from 'semver'; import extend from 'extend'; +import satisfies from 'semver/functions/satisfies'; import { load } from './load'; /** diff --git a/commands/build/lib/build.js b/commands/build/lib/build.js index d54bb269f..feb4b66d0 100644 --- a/commands/build/lib/build.js +++ b/commands/build/lib/build.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const path = require('path'); const extend = require('extend'); const yargs = require('yargs'); diff --git a/commands/build/lib/resolveNative.js b/commands/build/lib/resolveNative.js index d2352d368..1d3d24f9a 100644 --- a/commands/build/lib/resolveNative.js +++ b/commands/build/lib/resolveNative.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const path = require('path'); const fs = require('fs'); // this plugin will check if there is a corresponding .native file for the input file and output the contents of the native file diff --git a/commands/build/lib/watch.js b/commands/build/lib/watch.js index f401353ea..49d9731e6 100644 --- a/commands/build/lib/watch.js +++ b/commands/build/lib/watch.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const path = require('path'); const readline = require('readline'); const chalk = require('chalk'); diff --git a/commands/cli/lib/index.js b/commands/cli/lib/index.js index af52bb424..d48bb2aaf 100755 --- a/commands/cli/lib/index.js +++ b/commands/cli/lib/index.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +/* eslint-disable no-console */ const yargs = require('yargs'); const importCwd = require('import-cwd'); const checkNodeVersion = require('./checkNodeVersion'); diff --git a/commands/create/lib/create.js b/commands/create/lib/create.js index e0fc31cd1..760bd4cf2 100644 --- a/commands/create/lib/create.js +++ b/commands/create/lib/create.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const path = require('path'); const fs = require('fs'); const { execSync } = require('child_process'); diff --git a/commands/create/templates/sn/picasso/common/src/pic-selections.js b/commands/create/templates/sn/picasso/common/src/pic-selections.js index cfdb28d3c..6923f79bb 100644 --- a/commands/create/templates/sn/picasso/common/src/pic-selections.js +++ b/commands/create/templates/sn/picasso/common/src/pic-selections.js @@ -1,4 +1,4 @@ -/* eslint no-param-reassign: 0 */ +/* eslint-disable no-param-reassign, no-console */ // --- enable keyboard accessibility --- // pressing enter (escape) key should confirm (cancel) selections diff --git a/commands/sense/lib/build.js b/commands/sense/lib/build.js index 1d9509987..b52a08a63 100644 --- a/commands/sense/lib/build.js +++ b/commands/sense/lib/build.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const path = require('path'); const fs = require('fs-extra'); diff --git a/commands/serve/lib/fixtures.js b/commands/serve/lib/fixtures.js index 911a701bb..0b9c5dbe4 100644 --- a/commands/serve/lib/fixtures.js +++ b/commands/serve/lib/fixtures.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /** * Manages loading and delivering fixtures. * diff --git a/commands/serve/lib/placeholder.js b/commands/serve/lib/placeholder.js index 47bee92e5..cd5354f44 100644 --- a/commands/serve/lib/placeholder.js +++ b/commands/serve/lib/placeholder.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ export default { component: { mounted() { diff --git a/commands/serve/lib/webpack.serve.js b/commands/serve/lib/webpack.serve.js index 3c475d8f1..279ed2b69 100644 --- a/commands/serve/lib/webpack.serve.js +++ b/commands/serve/lib/webpack.serve.js @@ -1,4 +1,4 @@ -/* eslint global-require: 0 */ +/* eslint-disable global-require, no-console */ const path = require('path'); const fs = require('fs'); const homedir = require('os').homedir(); diff --git a/commands/serve/web/components/Visualize/Visualize.jsx b/commands/serve/web/components/Visualize/Visualize.jsx index 08eeb5192..bcd085fd8 100644 --- a/commands/serve/web/components/Visualize/Visualize.jsx +++ b/commands/serve/web/components/Visualize/Visualize.jsx @@ -150,6 +150,13 @@ export default function Visualize() { } }, [nebbie, currentThemeName]); + const create = () => { + if (window[info?.supernova.name]) { + uid.current = String(Date.now()); + setCurrentId(uid.current); + } + }; + useEffect(() => { if (!nebbie) return; @@ -181,13 +188,6 @@ export default function Visualize() { }; }, [app]); - const create = () => { - if (window[info?.supernova.name]) { - uid.current = String(Date.now()); - setCurrentId(uid.current); - } - }; - const handleThemeChange = (t) => { setThemeChooserAnchorEl(null); storage.save('themeName', t); diff --git a/rollup.config.js b/rollup.config.js index 45fcaf672..c4251863d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,6 @@ +/* eslint-disable no-console */ const path = require('path'); +const crypto = require('crypto'); const babel = require('@rollup/plugin-babel'); const commonjs = require('@rollup/plugin-commonjs'); const json = require('@rollup/plugin-json'); @@ -6,7 +8,6 @@ const { nodeResolve } = require('@rollup/plugin-node-resolve'); const replace = require('@rollup/plugin-replace'); const terser = require('@rollup/plugin-terser'); -const crypto = require('crypto'); const localeStringValidator = require('./tools/locale-string-validator'); const cwd = process.cwd(); @@ -103,6 +104,13 @@ const config = ({ format = 'umd', debug = false, file, targetPkg }) => { }); const cfg = { + onwarn(warning, warn) { + // Supress "use client" warnings coming from MUI bundling + if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && warning.message.includes(`"use client"`)) { + return; + } + warn(warning); + }, input: path.resolve(cwd, 'src', 'index'), output: { // file: path.resolve(targetDir, getFileName(isEsm ? 'esm' : '', dev)),