-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📁 types(patch): improve typings (@roots/bud-react) (#2442)
Improve typings and exports organization for @roots/bud-react. ## Type of change **PATCH: backwards compatible change**
- Loading branch information
1 parent
0c92177
commit 4c845ed
Showing
17 changed files
with
351 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
// Copyright © Roots Software Foundation LLC | ||
// Licensed under the MIT license. | ||
import type {Bud} from '@roots/bud-framework' | ||
|
||
import {Extension} from '@roots/bud-framework/extension' | ||
import { | ||
bind, | ||
development, | ||
label, | ||
} from '@roots/bud-framework/extension/decorators' | ||
|
||
/** | ||
* Adds TypeScript react-refresh transform | ||
* | ||
* @see https://bud.js.org | ||
* @see https://github.com/roots/bud | ||
* | ||
* @packageDocumentation | ||
* Register `react-refresh-typescript` transform with TSC compiler | ||
*/ | ||
@label(`@roots/bud-react/babel-refresh`) | ||
@development | ||
export default class BudBabelRefresh extends Extension { | ||
/** | ||
* {@link Extension.register} | ||
*/ | ||
@bind | ||
public override async register(bud: Bud) { | ||
this.logger.log(`Registering react-refresh-babel transformer`) | ||
|
||
import BudBabelRefresh from './extension.js' | ||
export default BudBabelRefresh | ||
bud.babel.setPlugin( | ||
`react-refresh/babel`, | ||
await this.resolve(`react-refresh/babel`, import.meta.url), | ||
) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,93 @@ | ||
import BudReact from './extension.js' | ||
export default BudReact | ||
import type {Bud} from '@roots/bud-framework' | ||
|
||
import {Extension} from '@roots/bud-framework/extension' | ||
import { | ||
bind, | ||
dependsOn, | ||
expose, | ||
label, | ||
} from '@roots/bud-framework/extension/decorators' | ||
import merge from '@roots/bud-support/lodash/merge' | ||
|
||
import type BudReactRefresh from '../react-refresh/index.js' | ||
|
||
/** | ||
* React configuration | ||
*/ | ||
@label(`@roots/bud-react`) | ||
@dependsOn([`@roots/bud-react/react-refresh`]) | ||
@expose(`react`) | ||
export default class BudReact extends Extension { | ||
/** | ||
* {@link Extension.configAfter} | ||
* | ||
*/ | ||
@bind | ||
public override async boot(bud: Bud) { | ||
if ( | ||
![this.useSWC, this.useTypeScript, this.useBabel].some( | ||
t => t === true, | ||
) | ||
) { | ||
this.logger.warn(`No supported compiler found.`) | ||
} | ||
|
||
if (this.useSWC) { | ||
bud.swc.setJsc( | ||
merge(bud.swc.jsc, {transform: {react: {runtime: `automatic`}}}), | ||
) | ||
} | ||
|
||
if (this.useBabel) { | ||
const babelPluginUrl = await this.resolve(`@babel/preset-react`, import.meta.url).catch(bud.catch) | ||
this.app.babel.setPreset( | ||
`@babel/preset-react`, | ||
babelPluginUrl, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Accessor for `@roots/bud-react/react-refresh` | ||
* | ||
* @readonly | ||
*/ | ||
public get refresh(): BudReactRefresh { | ||
return this.app.extensions.get(`@roots/bud-react/react-refresh`) | ||
} | ||
|
||
/** | ||
* Use babel | ||
* | ||
* @readonly | ||
*/ | ||
public get useBabel(): boolean { | ||
if (this.useTypeScript) return false | ||
if (this.useSWC) return false | ||
return this.app.extensions.has(`@roots/bud-babel`) | ||
} | ||
|
||
/** | ||
* Use SWC | ||
* | ||
* @readonly | ||
*/ | ||
public get useSWC(): boolean { | ||
return this.app.extensions.has(`@roots/bud-swc`) | ||
} | ||
|
||
/** | ||
* Use TypeScript | ||
* | ||
* @readonly | ||
*/ | ||
public get useTypeScript(): boolean { | ||
if (this.useSWC) return false | ||
|
||
if (this.app.extensions.has(`@roots/bud-typescript`)) { | ||
return !this.app.extensions.get(`@roots/bud-typescript`).get(`babel`) | ||
} | ||
|
||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.