Skip to content

Commit

Permalink
Merge branch 'master' into typescript-support
Browse files Browse the repository at this point in the history
  • Loading branch information
kikoruiz committed Dec 18, 2023
2 parents 2d9830a + 912dd65 commit d667c96
Show file tree
Hide file tree
Showing 265 changed files with 2,164 additions and 3,494 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'weekly'
ignore:
- dependency-name: '*'
update-types: ['version-update:semver-major']
commit-message:
prefix: 'upgrade'
include: 'scope'
labels:
- 'dependencies'
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
13 changes: 13 additions & 0 deletions packages/sui-bundler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# CHANGELOG

# 9.45.0 (2023-12-13)



# 9.44.0 (2023-12-01)


### Features

* **packages/sui-bundler:** add server dev config ([593b902](https://github.com/SUI-Components/sui/commit/593b9028706b58070a2614fbcd04d28131a0d890))



# 9.43.0 (2023-10-18)


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
20 changes: 4 additions & 16 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,16 +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')])) {
log.error(
`✖ Required files are missing, create and index.html and app.js inside your src folder.`
)
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: 2 additions & 2 deletions packages/sui-bundler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@s-ui/bundler",
"version": "9.43.0",
"version": "9.45.0",
"description": "Config-free bundler for ES6 React apps.",
"bin": {
"sui-bundler": "./bin/sui-bundler.js"
Expand Down Expand Up @@ -28,7 +28,7 @@
"@s-ui/sass-loader": "1",
"@swc/core": "1.3.14",
"@swc/helpers": "0.4.12",
"address": "1.2.0",
"address": "1.2.2",
"autoprefixer": "10.4.8",
"babel-loader": "8.2.5",
"babel-preset-sui": "3",
Expand Down
8 changes: 2 additions & 6 deletions packages/sui-bundler/scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ const shouldGenerateTSConfig = () => {
}

async function main() {
console.log(
'🔍 [sui-bundler postinstall] Checking if tsconfig.json is up to date...'
)
console.log('🔍 [sui-bundler postinstall] Checking if tsconfig.json is up to date...')
if (!shouldGenerateTSConfig()) {
console.log('✅ [sui-bundler postinstall] tsconfig.json is up to date')
process.exit(0)
}
await writeFile(TS_CONFIG_PATH, tsConfigTemplate)
console.log(
'❌ [sui-bundler postinstall] tsconfig.json was not up to date, so we updated it'
)
console.log('❌ [sui-bundler postinstall] tsconfig.json was not up to date, so we updated it')
}

main()
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
4 changes: 1 addition & 3 deletions packages/sui-bundler/shared/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ module.exports = (vars = {}) => {
__DEV__: false,
__BASE_DIR__: JSON.stringify(process.env.PWD),
...vars,
...Object.fromEntries(
Object.entries(magic).map(([key, value]) => [key, JSON.stringify(value)])
)
...Object.fromEntries(Object.entries(magic).map(([key, value]) => [key, JSON.stringify(value)]))
}

return new webpack.DefinePlugin(definitions)
Expand Down
Loading

0 comments on commit d667c96

Please sign in to comment.