Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
b931cbec
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b931cbec
编写于
5月 13, 2020
作者:
J
Joe Haddad
提交者:
GitHub
5月 13, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify CSS Errors (#12852)
上级
b41f9baa
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
103 addition
and
8 deletion
+103
-8
packages/next/build/webpack/plugins/wellknown-errors-plugin/parseCss.ts
...build/webpack/plugins/wellknown-errors-plugin/parseCss.ts
+38
-0
packages/next/build/webpack/plugins/wellknown-errors-plugin/webpackModuleError.ts
...ack/plugins/wellknown-errors-plugin/webpackModuleError.ts
+15
-5
test/acceptance/ReactRefreshLogBox.test.js
test/acceptance/ReactRefreshLogBox.test.js
+47
-0
test/integration/css-features/test/index.test.js
test/integration/css-features/test/index.test.js
+3
-3
未找到文件。
packages/next/build/webpack/plugins/wellknown-errors-plugin/parseCss.ts
0 → 100644
浏览文件 @
b931cbec
import
Chalk
from
'
next/dist/compiled/chalk
'
import
{
SimpleWebpackError
}
from
'
./simpleWebpackError
'
const
chalk
=
new
Chalk
.
constructor
({
enabled
:
true
})
const
regexCssError
=
/^
(?:
CssSyntaxError|SyntaxError
)\n\n\((\d
+
)
:
(\d
*
)\)
(
.*
)
$/
s
export
function
getCssError
(
fileName
:
string
,
err
:
Error
):
SimpleWebpackError
|
false
{
if
(
!
(
(
err
.
name
===
'
CssSyntaxError
'
||
err
.
name
===
'
SyntaxError
'
)
&&
(
err
as
any
).
stack
===
false
&&
!
(
err
instanceof
SyntaxError
)
)
)
{
return
false
}
// https://github.com/postcss/postcss-loader/blob/d6931da177ac79707bd758436e476036a55e4f59/src/Error.js
const
res
=
regexCssError
.
exec
(
err
.
message
)
if
(
res
)
{
const
[,
_lineNumer
,
_column
,
reason
]
=
res
const
lineNumber
=
Math
.
max
(
1
,
parseInt
(
_lineNumer
,
10
))
const
column
=
Math
.
max
(
1
,
parseInt
(
_column
,
10
))
return
new
SimpleWebpackError
(
`
${
chalk
.
cyan
(
fileName
)}
:
${
chalk
.
yellow
(
lineNumber
.
toString
()
)}
:
${
chalk
.
yellow
(
column
.
toString
())}
`
,
chalk
.
red
.
bold
(
'
Syntax error
'
).
concat
(
`:
${
reason
}
`
)
)
}
return
false
}
packages/next/build/webpack/plugins/wellknown-errors-plugin/webpackModuleError.ts
浏览文件 @
b931cbec
...
...
@@ -2,19 +2,23 @@ import * as path from 'path'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import
{
compilation
}
from
'
webpack
'
import
{
getBabelError
}
from
'
./parseBabel
'
import
{
getCssError
}
from
'
./parseCss
'
import
{
SimpleWebpackError
}
from
'
./simpleWebpackError
'
function
getFilename
(
compilation
:
compilation
.
Compilation
,
m
:
any
):
string
{
let
ctx
:
string
|
null
=
compilation
.
compiler
?.
context
??
compilation
.
context
??
null
if
(
ctx
!==
null
&&
typeof
m
.
resource
===
'
string
'
)
{
const
res
=
path
.
relative
(
ctx
,
m
.
resource
).
replace
(
/
\\
/g
,
path
.
posix
.
sep
)
return
res
.
startsWith
(
'
.
'
)
?
res
:
`.
${
path
.
posix
.
sep
}${
res
}
`
}
const
requestShortener
=
compilation
.
requestShortener
if
(
typeof
m
?.
readableIdentifier
===
'
function
'
)
{
return
m
.
readableIdentifier
(
requestShortener
)
}
if
(
typeof
m
.
resource
===
'
string
'
)
{
const
res
=
path
.
relative
(
compilation
.
context
,
m
.
resource
)
return
res
.
startsWith
(
'
.
'
)
?
res
:
`.
${
path
.
sep
}${
res
}
`
}
return
m
.
request
??
'
<unknown>
'
return
m
.
request
??
m
.
userRequest
??
'
<unknown>
'
}
export
function
getModuleBuildError
(
...
...
@@ -34,10 +38,16 @@ export function getModuleBuildError(
const
err
:
Error
=
input
.
error
const
sourceFilename
=
getFilename
(
compilation
,
input
.
module
)
const
babel
=
getBabelError
(
sourceFilename
,
err
)
if
(
babel
!==
false
)
{
return
babel
}
const
css
=
getCssError
(
sourceFilename
,
err
)
if
(
css
!==
false
)
{
return
css
}
return
false
}
test/acceptance/ReactRefreshLogBox.test.js
浏览文件 @
b931cbec
...
...
@@ -713,3 +713,50 @@ test('conversion to class component (1)', async () => {
await
cleanup
()
})
test
(
'
css syntax errors
'
,
async
()
=>
{
const
[
session
,
cleanup
]
=
await
sandbox
()
await
session
.
write
(
'
index.module.css
'
,
`.button {}`
)
await
session
.
patch
(
'
index.js
'
,
`
import './index.module.css';
export default () => {
return (
<div>
<p>lol</p>
</div>
)
}
`
)
expect
(
await
session
.
hasRedbox
()).
toBe
(
false
)
// Syntax error
await
session
.
patch
(
'
index.module.css
'
,
`.button {`
)
expect
(
await
session
.
hasRedbox
(
true
)).
toBe
(
true
)
const
source
=
await
session
.
getRedboxSource
()
expect
(
source
).
toMatchInlineSnapshot
(
`
"./index.module.css:1:1
Syntax error: Unclosed block
> 1 | .button {
| ^"
`
)
// Not local error
await
session
.
patch
(
'
index.module.css
'
,
`button {}`
)
expect
(
await
session
.
hasRedbox
(
true
)).
toBe
(
true
)
const
source2
=
await
session
.
getRedboxSource
()
expect
(
source2
).
toMatchInlineSnapshot
(
`
"./index.module.css:1:1
Syntax error: Selector \\"button\\" is not pure (pure selectors must contain at least one local class or id)
> 1 | button {}
| ^"
`
)
await
cleanup
()
})
test/integration/css-features/test/index.test.js
浏览文件 @
b931cbec
...
...
@@ -150,7 +150,7 @@ describe('Custom Properties: Fail for :root {} in CSS Modules', () => {
expect
(
code
).
not
.
toBe
(
0
)
expect
(
stderr
).
toContain
(
'
Failed to compile
'
)
expect
(
stderr
).
toContain
(
'
pages/styles.module.css
'
)
expect
(
stderr
).
toContain
(
'
CssSyntax error:
Selector ":root" is not pure
'
)
expect
(
stderr
).
toContain
(
'
Selector ":root" is not pure
'
)
})
})
...
...
@@ -168,7 +168,7 @@ describe('Custom Properties: Fail for global element in CSS Modules', () => {
expect
(
code
).
not
.
toBe
(
0
)
expect
(
stderr
).
toContain
(
'
Failed to compile
'
)
expect
(
stderr
).
toContain
(
'
pages/styles.module.css
'
)
expect
(
stderr
).
toContain
(
'
CssSyntax error:
Selector "h1" is not pure
'
)
expect
(
stderr
).
toContain
(
'
Selector "h1" is not pure
'
)
})
})
...
...
@@ -218,6 +218,6 @@ describe('CSS Modules: Importing Invalid Global CSS', () => {
expect
(
code
).
not
.
toBe
(
0
)
expect
(
stderr
).
toContain
(
'
Failed to compile
'
)
expect
(
stderr
).
toContain
(
'
pages/styles.module.css
'
)
expect
(
stderr
).
toContain
(
'
CssSyntax error:
Selector "a" is not pure
'
)
expect
(
stderr
).
toContain
(
'
Selector "a" is not pure
'
)
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录