Skip to content
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

[REFACTOR] apply new linting rules #1665

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f15e4b3
refactor(packages/babel-preset-sui): apply new linting rules
kikoruiz Nov 21, 2023
5c321db
refactor(packages/sui-bundler): apply new linting rules
kikoruiz Nov 21, 2023
d241885
refactor(packages/sui-ci): apply new linting rules
kikoruiz Nov 21, 2023
5d739a2
refactor(packages/sui-consents): apply new linting rules
kikoruiz Nov 21, 2023
35110bd
refactor(packages/sui-critical-css-middleware): apply new linting rules
kikoruiz Nov 21, 2023
e97b076
refactor(packages/sui-critical-css): apply new linting rules
kikoruiz Nov 21, 2023
76feafe
refactor(packages/sui-dashboard): apply new linting rules
kikoruiz Nov 21, 2023
e0aaf39
refactor(packages/sui-decorators): apply new linting rules
kikoruiz Nov 21, 2023
7fcecad
refactor(packages/sui-domain): apply new linting rules
kikoruiz Nov 21, 2023
a78aaad
refactor(packages/sui-helpers): apply new linting rules
kikoruiz Nov 21, 2023
9ed2c95
refactor(packages/sui-hoc): apply new linting rules
kikoruiz Nov 21, 2023
64ecf0d
refactor(packages/sui-html-tagger): apply new linting rules
kikoruiz Nov 21, 2023
a5d8505
refactor(packages/sui-i18n): apply new linting rules
kikoruiz Nov 21, 2023
f95d40b
refactor(packages/sui-jest): apply new linting rules
kikoruiz Nov 21, 2023
b15581f
refactor(packages/sui-js-compiler): apply new linting rules
kikoruiz Nov 21, 2023
237bbf5
refactor(packages/sui-js): apply new linting rules
kikoruiz Nov 21, 2023
53b302f
refactor(packages/sui-lint): apply new linting rules
kikoruiz Nov 21, 2023
51b346b
refactor(packages/sui-mock): apply new linting rules
kikoruiz Nov 21, 2023
d58f859
refactor(packages/sui-mockmock): apply new linting rules
kikoruiz Nov 21, 2023
231374c
refactor(packages/sui-mono): apply new linting rules
kikoruiz Nov 21, 2023
032f614
refactor(packages/sui-pde): apply new linting rules
kikoruiz Nov 21, 2023
b9affc1
refactor(packages/sui-polyfills): apply new linting rules
kikoruiz Nov 21, 2023
405084e
refactor(packages/sui-precommit): apply new linting rules
kikoruiz Nov 21, 2023
44f605e
refactor(packages/sui-react-head): apply new linting rules
kikoruiz Nov 21, 2023
af61431
refactor(packages/sui-react-router): apply new linting rules
kikoruiz Nov 21, 2023
93ad8aa
refactor(packages/sui-react-web-vitals): apply new linting rules
kikoruiz Nov 21, 2023
f24b814
refactor(packages/sui-sass-loader): apply new linting rules
kikoruiz Nov 21, 2023
f06fab7
refactor(packages/sui-ssr): apply new linting rules
kikoruiz Nov 21, 2023
51631a9
refactor(packages/sui-studio-create): apply new linting rules
kikoruiz Nov 21, 2023
f3dc347
refactor(packages/sui-studio-utils): apply new linting rules
kikoruiz Nov 21, 2023
1f8f30c
refactor(packages/sui-studio): apply new linting rules
kikoruiz Nov 21, 2023
d5464be
refactor(packages/sui-svg): apply new linting rules
kikoruiz Nov 21, 2023
b2a6469
refactor(packages/sui-test-contract): apply new linting rules
kikoruiz Nov 21, 2023
8db0ed2
refactor(packages/sui-test-e2e): apply new linting rules
kikoruiz Nov 21, 2023
4a43745
refactor(packages/sui-test): apply new linting rules
kikoruiz Nov 21, 2023
bb047e5
refactor(packages/sui-widget-embedder): apply new linting rules
kikoruiz Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions packages/babel-preset-sui/src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
const {
DEFAULT_LEGACY_BROWSER_TARGETS,
DEFAULT_BROWSER_TARGETS,
DEFAULT_SERVER_TARGETS
} = require('./defaults.js')
const {DEFAULT_LEGACY_BROWSER_TARGETS, DEFAULT_BROWSER_TARGETS, DEFAULT_SERVER_TARGETS} = require('./defaults.js')

const getTargets = ({targets = {}, isModern, isServer}) => {
const {server, browser} = targets
if (isModern && isServer) return server ?? DEFAULT_SERVER_TARGETS

return (
browser ??
(isModern ? DEFAULT_BROWSER_TARGETS : DEFAULT_LEGACY_BROWSER_TARGETS)
)
return browser ?? (isModern ? DEFAULT_BROWSER_TARGETS : DEFAULT_LEGACY_BROWSER_TARGETS)
}

const plugins = (api, {useESModules = true} = {}) => [
Expand Down Expand Up @@ -47,10 +40,7 @@ const presets = (api, opts = {}) => {
useBuiltIns: false
}
],
[
require('@babel/preset-react').default,
{runtime: 'automatic', useBuiltIns: true}
]
[require('@babel/preset-react').default, {runtime: 'automatic', useBuiltIns: true}]
]
}

Expand Down
38 changes: 8 additions & 30 deletions packages/sui-bundler/bin/sui-bundler-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ program
})
.parse(process.argv)

const {
clean = false,
context,
saveStats,
linkPackage: packagesToLink = []
} = program.opts()
const {clean = false, context, saveStats, linkPackage: packagesToLink = []} = program.opts()

config.context = context || config.context

Expand Down Expand Up @@ -106,10 +101,7 @@ compiler.run(async (error, stats) => {
const resolvePublicFile = file => path.resolve(process.cwd(), 'public', file)

if (offlinePageExists) {
fs.copyFileSync(
path.resolve(offlinePath),
resolvePublicFile('offline.html')
)
fs.copyFileSync(path.resolve(offlinePath), resolvePublicFile('offline.html'))
}

if (offlinePageExists || staticsCacheOnly) {
Expand All @@ -126,41 +118,27 @@ compiler.run(async (error, stats) => {

const importScripts = offlineConfig.importScripts || []

const stringImportScripts = importScripts
.map(url => `importScripts("${url}")`)
.join('\n')
const stringImportScripts = importScripts.map(url => `importScripts("${url}")`).join('\n')

Boolean(importScripts.length) &&
console.log('\nExternal Scripts Added to the SW:\n', stringImportScripts)
Boolean(importScripts.length) && console.log('\nExternal Scripts Added to the SW:\n', stringImportScripts)

// read the service worker template
const swTemplate = fs.readFileSync(
path.resolve(__dirname, '..', 'service-worker.js'),
'utf-8'
)
const swTemplate = fs.readFileSync(path.resolve(__dirname, '..', 'service-worker.js'), 'utf-8')

// replace all the variables from the template with the actual values
const swCode = swTemplate
.replace('// IMPORT_SCRIPTS_HERE', stringImportScripts)
.replace("require('static-manifest')", JSON.stringify(manifestStatics))
.replace(
"require('static-cache-name')",
JSON.stringify(Date.now().toString())
)
.replace(
"require('static-statics-cache-only')",
JSON.stringify(staticsCacheOnly)
)
.replace("require('static-cache-name')", JSON.stringify(Date.now().toString()))
.replace("require('static-statics-cache-only')", JSON.stringify(staticsCacheOnly))

const swFilePath = resolvePublicFile('service-worker.js')

await writeFile(swFilePath, swCode)
console.log('\nService worker generated succesfully!\n')
}

log.success(
`Your app is compiled in ${process.env.NODE_ENV} mode in /public. It's ready to roll!`
)
log.success(`Your app is compiled in ${process.env.NODE_ENV} mode in /public. It's ready to roll!`)

compiler.close(closeErr => {
const exitCode = closeErr ? 1 : 0
Expand Down
27 changes: 5 additions & 22 deletions packages/sui-bundler/bin/sui-bundler-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ const DEFAULT_WATCH = !CI
if (!module.parent) {
program
.option('-c, --context [folder]', 'Context folder (cwd by default)')
.option(
'-L, --link-all [monorepo]',
'Link all packages inside of monorepo multipackage'
)
.option('-L, --link-all [monorepo]', 'Link all packages inside of monorepo multipackage')
.option(
'-l, --link-package [package]',
'Replace each occurrence of this package with an absolute path to this folder',
Expand All @@ -41,11 +38,7 @@ if (!module.parent) {
},
[]
)
.option(
'-w, --watch',
'Watch files and restart the server on change',
DEFAULT_WATCH
)
.option('-w, --watch', 'Watch files and restart the server on change', DEFAULT_WATCH)
.on('--help', () => {
console.log(' Examples:')
console.log('')
Expand All @@ -61,21 +54,11 @@ if (!module.parent) {
webpackConfig.context = context || webpackConfig.context
}

const start = async ({
config = webpackConfig,
packagesToLink = program.opts().linkPackage || []
} = {}) => {
const start = async ({config = webpackConfig, packagesToLink = program.opts().linkPackage || []} = {}) => {
clearConsole()
// Warn and crash if required files are missing
if (
!checkRequiredFiles([
path.join(config.context, 'index.html'),
path.join(config.context, 'app.js')
])
) {
log.error(
`✖ Required files are missing, create and index.html and app.js inside your src folder.`
)
if (!checkRequiredFiles([path.join(config.context, 'index.html'), path.join(config.context, 'app.js')])) {
log.error(`✖ Required files are missing, create and index.html and app.js inside your src folder.`)
process.exit(1)
}

Expand Down
16 changes: 3 additions & 13 deletions packages/sui-bundler/bin/sui-bundler-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ program
.option('-o, --output [output]', 'Bundle folder path')
.option('-u, --umd [libraryName]', 'Whether to output library as umb')
.option('-r, --root', 'Create build in root dir instead of version subdir')
.option(
'-p, --path [path]',
'Absolute public path where files will be located.'
)
.option('-p, --path [path]', 'Absolute public path where files will be located.')
.on('--help', () =>
console.log(`Examples:
$ sui-bundler lib src/index.js -o umd/my-lib -p http://my-cdn.com/my-lib -C'
Expand Down Expand Up @@ -48,12 +45,7 @@ if (!publicPath) {
process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const version = getPackageJson(process.cwd()).version
const outputFolder = path.join(
process.cwd(),
output,
path.sep,
root ? '' : version
)
const outputFolder = path.join(process.cwd(), output, path.sep, root ? '' : version)
const webpackConfig = {...config, entry: path.resolve(process.cwd(), entry)}
webpackConfig.output.publicPath = publicPath + (root ? '' : version + '/')
webpackConfig.output.path = outputFolder
Expand Down Expand Up @@ -94,7 +86,5 @@ webpack(webpackConfig).run((error, stats) => {
}

console.log(`Webpack stats: ${stats}`)
log.success(
`Your library is compiled in production mode in: \n${outputFolder}`
)
log.success(`Your library is compiled in production mode in: \n${outputFolder}`)
})
5 changes: 1 addition & 4 deletions packages/sui-bundler/bin/sui-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ program
.command('dev', 'open a server dev to start the development')
.command('build', 'Compile all assets and create a public folder')
.command('lib', 'Compile a library to a bundle with chunks.')
.command(
'analyzer',
'Compile all assets and create a HTML inspector for your bundle'
)
.command('analyzer', 'Compile all assets and create a HTML inspector for your bundle')

program.parse(process.argv)
10 changes: 4 additions & 6 deletions packages/sui-bundler/example/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {render} from 'react-dom'
import Hello from './hello.js'

// eslint-next-disable-line
import(/* webpackChunkName: "my-chunk-name" */ './foo.js').then(
({default: foo}) => {
console.log('loaded async chunk')
foo()
}
)
import(/* webpackChunkName: "my-chunk-name" */ './foo.js').then(({default: foo}) => {
console.log('loaded async chunk')
foo()
})

render(<Hello />, document.getElementById('root'))
8 changes: 2 additions & 6 deletions packages/sui-bundler/factories/createCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ module.exports = (config, urls) => {

// Log the correct message of compilation depending if we have warnings
if (isSuccessful) {
stats.hasWarnings()
? log.warn('⚠ Compiled with warnings')
: log.success('✔ Compiled successfully')
stats.hasWarnings() ? log.warn('⚠ Compiled with warnings') : log.success('✔ Compiled successfully')
}

// Even with warnings, we show instructions to access localhost if we have a compilation
Expand All @@ -52,9 +50,7 @@ module.exports = (config, urls) => {

// With warnings, even after showing the instructions we must list the warnings we have
if (stats.hasWarnings()) {
const messages = formatWebpackMessages(
stats.toJson('errors-warnings', true)
)
const messages = formatWebpackMessages(stats.toJson('errors-warnings', true))
log.warn(messages.warnings.join('\n\n'))
}
})
Expand Down
4 changes: 1 addition & 3 deletions packages/sui-bundler/loaders/ExternalsManifestLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ async function externalsManifestLoader(source) {

try {
const manifest = await getRemoteManifest(
typeof manifestURL === 'string'
? manifestURL
: manifestURL[process.env.NODE_ENV]
typeof manifestURL === 'string' ? manifestURL : manifestURL[process.env.NODE_ENV]
)
const entries = Object.entries(manifest)
const nextSource = entries.reduce((acc, entry) => {
Expand Down
10 changes: 2 additions & 8 deletions packages/sui-bundler/loaders/linkLoaderConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@ const diccFromAbsolutePaths = (paths, init = {}) =>
log.success(`✔ ${pkg.name} from path "${packagePath}"`)
return acc
} catch (e) {
log.warn(
`⚠ Package from path "${packagePath}" can't be linked.\n Path is wrong or package.json is missing.`
)
log.warn(`⚠ Package from path "${packagePath}" can't be linked.\n Path is wrong or package.json is missing.`)
return acc
}
}, init)

const absolutePathForMonoRepo = base => {
if (!base) return []
return fg
.sync([
`${path.resolve(base)}/**/package.json`,
'!**/node_modules/**',
'!**/lib/**'
])
.sync([`${path.resolve(base)}/**/package.json`, '!**/node_modules/**', '!**/lib/**'])
.map(p => path.dirname(p))
}

Expand Down
5 changes: 1 addition & 4 deletions packages/sui-bundler/loaders/sassLinkImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ const createSassLinkImporter = entryPoints => url => {
const [org, name] = url.split(/\//)
const pkg = [org.replace('~', ''), name].join('/')

const absoluteUrl = url.replace(
new RegExp(`~?${pkg}(\\/lib)?`, 'g'),
entryPoints[pkg]
)
const absoluteUrl = url.replace(new RegExp(`~?${pkg}(\\/lib)?`, 'g'), entryPoints[pkg])
return {file: absoluteUrl}
}
return null
Expand Down
4 changes: 1 addition & 3 deletions packages/sui-bundler/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ const copyResponse = async function (response) {
statusText: clonedResponse.statusText
}

const body = canConstructResponseFromBodyStream()
? clonedResponse.body
: await clonedResponse.blob()
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob()

return new Response(body, responseInit)
}
Expand Down
10 changes: 2 additions & 8 deletions packages/sui-bundler/shared/config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/* Extract sui-bundler from package.json -> "config": {"sui-bundler": { ... }} */
const {
config: packageJsonConfig = {}
} = require(`${process.cwd()}/package.json`)
const {config: packageJsonConfig = {}} = require(`${process.cwd()}/package.json`)

const {'sui-bundler': config = {}} = packageJsonConfig
const {
extractComments = false,
sourcemaps,
supportLegacyBrowsers = true
} = config
const {extractComments = false, sourcemaps, supportLegacyBrowsers = true} = config

exports.config = config
exports.supportLegacyBrowsers = supportLegacyBrowsers
Expand Down
7 changes: 2 additions & 5 deletions packages/sui-bundler/shared/inline-chunk-html-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class InlineChunkHtmlPlugin {
if (tag.tagName !== 'script' || !(tag.attributes && tag.attributes.src)) {
return tag
}
const scriptName = publicPath
? tag.attributes.src.replace(publicPath, '')
: tag.attributes.src
const scriptName = publicPath ? tag.attributes.src.replace(publicPath, '') : tag.attributes.src
if (!this.tests.some(test => scriptName.match(test))) {
return tag
}
Expand All @@ -39,8 +37,7 @@ class InlineChunkHtmlPlugin {
}

compiler.hooks.compilation.tap('InlineChunkHtmlPlugin', compilation => {
const tagFunction = tag =>
this.getInlinedTag(publicPath, compilation.assets, tag)
const tagFunction = tag => this.getInlinedTag(publicPath, compilation.assets, tag)

const hooks = this.htmlWebpackPlugin.getHooks(compilation)
hooks.alterAssetTagGroups.tap('InlineChunkHtmlPlugin', assets => {
Expand Down
4 changes: 1 addition & 3 deletions packages/sui-bundler/shared/minify-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ const terserMinifier = ({extractComments, sourceMap}) =>
})

module.exports = ({extractComments, sourceMap}) =>
supportLegacyBrowsers
? terserMinifier({extractComments, sourceMap})
: esbuildMinifier({sourceMap})
supportLegacyBrowsers ? terserMinifier({extractComments, sourceMap}) : esbuildMinifier({sourceMap})
10 changes: 2 additions & 8 deletions packages/sui-bundler/shared/module-rules-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const EXCLUDED_FOLDERS_REGEXP = new RegExp(
`node_modules(?!${path.sep}@s-ui(${path.sep}studio)(${path.sep}workbench)?${path.sep}src)`
)

module.exports = ({
isServer = false,
isDevelopment = false,
supportLegacyBrowsers = true
} = {}) => ({
module.exports = ({isServer = false, isDevelopment = false, supportLegacyBrowsers = true} = {}) => ({
test: /\.jsx?$/,
exclude: EXCLUDED_FOLDERS_REGEXP,
use: [
Expand All @@ -20,9 +16,7 @@ module.exports = ({
cacheCompression: false,
babelrc: false,
compact: true,
plugins: [
isDevelopment && require.resolve('react-refresh/babel')
].filter(Boolean),
plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
presets: [
[
require.resolve('babel-preset-sui'),
Expand Down
Loading
Loading