Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a4692d40
Unverified
Commit
a4692d40
authored
Nov 12, 2021
by
Tim Neutkens
Committed by
GitHub
Nov 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for jsxImportSource in tsconfig/jsconfig (#31358)
parent
06f3d398
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
97 additions
and
7 deletions
+97
-7
options.js
packages/next/build/swc/options.js
+4
-0
webpack-config.ts
packages/next/build/webpack-config.ts
+5
-5
next-swc-loader.js
packages/next/build/webpack/loaders/next-swc-loader.js
+8
-2
theme-ui.test.ts
test/development/basic/theme-ui.test.ts
+35
-0
jsconfig.json
test/development/basic/theme-ui/jsconfig.json
+5
-0
_app.js
test/development/basic/theme-ui/pages/_app.js
+13
-0
index.js
test/development/basic/theme-ui/pages/index.js
+14
-0
theme.js
test/development/basic/theme-ui/theme.js
+13
-0
No files found.
packages/next/build/swc/options.js
View file @
a4692d40
...
@@ -9,6 +9,7 @@ function getBaseSWCOptions({
...
@@ -9,6 +9,7 @@ function getBaseSWCOptions({
styledComponents
,
styledComponents
,
paths
,
paths
,
baseUrl
,
baseUrl
,
importSource
,
})
{
})
{
const
isTSFile
=
filename
.
endsWith
(
'.ts'
)
const
isTSFile
=
filename
.
endsWith
(
'.ts'
)
const
isTypeScript
=
isTSFile
||
filename
.
endsWith
(
'.tsx'
)
const
isTypeScript
=
isTSFile
||
filename
.
endsWith
(
'.tsx'
)
...
@@ -30,6 +31,7 @@ function getBaseSWCOptions({
...
@@ -30,6 +31,7 @@ function getBaseSWCOptions({
transform
:
{
transform
:
{
react
:
{
react
:
{
importSource
:
importSource
||
'react'
,
runtime
:
'automatic'
,
runtime
:
'automatic'
,
pragma
:
'React.createElement'
,
pragma
:
'React.createElement'
,
pragmaFrag
:
'React.Fragment'
,
pragmaFrag
:
'React.Fragment'
,
...
@@ -107,6 +109,7 @@ export function getLoaderSWCOptions({
...
@@ -107,6 +109,7 @@ export function getLoaderSWCOptions({
isPageFile
,
isPageFile
,
hasReactRefresh
,
hasReactRefresh
,
styledComponents
,
styledComponents
,
importSource
,
})
{
})
{
let
baseOptions
=
getBaseSWCOptions
({
let
baseOptions
=
getBaseSWCOptions
({
filename
,
filename
,
...
@@ -114,6 +117,7 @@ export function getLoaderSWCOptions({
...
@@ -114,6 +117,7 @@ export function getLoaderSWCOptions({
globalWindow
:
!
isServer
,
globalWindow
:
!
isServer
,
hasReactRefresh
,
hasReactRefresh
,
styledComponents
,
styledComponents
,
importSource
,
})
})
const
isNextDist
=
nextDistPath
.
test
(
filename
)
const
isNextDist
=
nextDistPath
.
test
(
filename
)
...
...
packages/next/build/webpack-config.ts
View file @
a4692d40
...
@@ -321,6 +321,10 @@ export default async function getBaseWebpackConfig(
...
@@ -321,6 +321,10 @@ export default async function getBaseWebpackConfig(
runWebpackSpan
:
Span
runWebpackSpan
:
Span
}
}
):
Promise
<
webpack
.
Configuration
>
{
):
Promise
<
webpack
.
Configuration
>
{
const
{
useTypeScript
,
jsConfig
,
resolvedBaseUrl
}
=
await
loadJsConfig
(
dir
,
config
)
const
supportedBrowsers
=
await
getSupportedBrowsers
(
dir
,
dev
)
const
supportedBrowsers
=
await
getSupportedBrowsers
(
dir
,
dev
)
const
hasRewrites
=
const
hasRewrites
=
rewrites
.
beforeFiles
.
length
>
0
||
rewrites
.
beforeFiles
.
length
>
0
||
...
@@ -438,6 +442,7 @@ export default async function getBaseWebpackConfig(
...
@@ -438,6 +442,7 @@ export default async function getBaseWebpackConfig(
pagesDir
,
pagesDir
,
hasReactRefresh
:
!
isMiddleware
&&
hasReactRefresh
,
hasReactRefresh
:
!
isMiddleware
&&
hasReactRefresh
,
styledComponents
:
config
.
experimental
.
styledComponents
,
styledComponents
:
config
.
experimental
.
styledComponents
,
importSource
:
jsConfig
?.
compilerOptions
?.
jsxImportSource
,
},
},
}
}
:
{
:
{
...
@@ -521,11 +526,6 @@ export default async function getBaseWebpackConfig(
...
@@ -521,11 +526,6 @@ export default async function getBaseWebpackConfig(
}
as
ClientEntries
)
}
as
ClientEntries
)
:
undefined
:
undefined
const
{
useTypeScript
,
jsConfig
,
resolvedBaseUrl
}
=
await
loadJsConfig
(
dir
,
config
)
function
getReactProfilingInProduction
()
{
function
getReactProfilingInProduction
()
{
if
(
reactProductionProfiling
)
{
if
(
reactProductionProfiling
)
{
return
{
return
{
...
...
packages/next/build/webpack/loaders/next-swc-loader.js
View file @
a4692d40
...
@@ -35,8 +35,13 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
...
@@ -35,8 +35,13 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
let
loaderOptions
=
this
.
getOptions
()
||
{}
let
loaderOptions
=
this
.
getOptions
()
||
{}
const
{
isServer
,
pagesDir
,
hasReactRefresh
,
styledComponents
}
=
const
{
loaderOptions
isServer
,
pagesDir
,
hasReactRefresh
,
styledComponents
,
importSource
,
}
=
loaderOptions
const
isPageFile
=
filename
.
startsWith
(
pagesDir
)
const
isPageFile
=
filename
.
startsWith
(
pagesDir
)
const
swcOptions
=
getLoaderSWCOptions
({
const
swcOptions
=
getLoaderSWCOptions
({
...
@@ -47,6 +52,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
...
@@ -47,6 +52,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
development
:
this
.
mode
===
'development'
,
development
:
this
.
mode
===
'development'
,
hasReactRefresh
,
hasReactRefresh
,
styledComponents
,
styledComponents
,
importSource
,
})
})
const
programmaticOptions
=
{
const
programmaticOptions
=
{
...
...
test/development/basic/theme-ui.test.ts
0 → 100644
View file @
a4692d40
import
{
join
}
from
'path'
import
webdriver
from
'next-webdriver'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
describe
(
'theme-ui SWC option'
,
()
=>
{
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
{
'jsconfig.json'
:
new
FileRef
(
join
(
__dirname
,
'theme-ui/jsconfig.json'
)),
pages
:
new
FileRef
(
join
(
__dirname
,
'theme-ui/pages'
)),
'theme.js'
:
new
FileRef
(
join
(
__dirname
,
'theme-ui/theme.js'
)),
},
dependencies
:
{
'theme-ui'
:
'0.12.0'
,
},
})
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should have theme provided styling'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
next
.
appPort
,
'/'
)
const
color
=
await
browser
.
elementByCss
(
'#hello'
).
getComputedCss
(
'color'
)
expect
(
color
).
toBe
(
'rgb(51, 51, 238)'
)
}
finally
{
if
(
browser
)
{
await
browser
.
close
()
}
}
})
})
test/development/basic/theme-ui/jsconfig.json
0 → 100644
View file @
a4692d40
{
"compilerOptions"
:
{
"jsxImportSource"
:
"theme-ui"
}
}
test/development/basic/theme-ui/pages/_app.js
0 → 100644
View file @
a4692d40
// basic usage
import
{
ThemeProvider
}
from
'theme-ui'
import
theme
from
'../theme'
function
MyApp
({
Component
,
pageProps
})
{
return
(
<
ThemeProvider
theme
=
{
theme
}
>
<
Component
{...
pageProps
}
/
>
<
/ThemeProvider
>
)
}
export
default
MyApp
test/development/basic/theme-ui/pages/index.js
0 → 100644
View file @
a4692d40
export
default
function
Home
()
{
return
(
<
div
id
=
"hello"
sx
=
{{
fontWeight
:
'bold'
,
fontSize
:
4
,
// picks up value from `theme.fontSizes[4]`
color
:
'primary'
,
// picks up value from `theme.colors.primary`
}}
>
Hello
<
/div
>
)
}
test/development/basic/theme-ui/theme.js
0 → 100644
View file @
a4692d40
// example theme.js
export
default
{
fonts
:
{
body
:
'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif'
,
heading
:
'"Avenir Next", sans-serif'
,
monospace
:
'Menlo, monospace'
,
},
colors
:
{
text
:
'#000'
,
background
:
'#fff'
,
primary
:
'#33e'
,
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment