mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-21 22:54:11 +08:00
feat(babel6): Use absolute paths for linter and dont call default on coffee
This commit is contained in:
parent
2d55322705
commit
e355971dd2
1 changed files with 23 additions and 12 deletions
|
@ -27,7 +27,7 @@ module.exports = (grunt) ->
|
|||
|
||||
for f in fileset.src
|
||||
continue if not esExtensions[path.extname(f)]
|
||||
fname = path.basename(f, path.extname(f))
|
||||
lookupPath = "#{path.dirname(f)}/#{path.basename(f, path.extname(f))}"
|
||||
|
||||
content = fs.readFileSync(f, encoding:'utf8')
|
||||
if /module.exports\s?=\s?.+/gmi.test(content)
|
||||
|
@ -35,17 +35,17 @@ module.exports = (grunt) ->
|
|||
|
||||
if /^export/gmi.test(content)
|
||||
if /^export\ default/gmi.test(content)
|
||||
esExportDefault[fname] = true
|
||||
esExportDefault[lookupPath] = true
|
||||
else
|
||||
esExport[fname] = true
|
||||
esExport[lookupPath] = true
|
||||
else
|
||||
esNoExport[fname] = true
|
||||
esNoExport[lookupPath] = true
|
||||
|
||||
blacklist = ["events", "main", "package", "task"]
|
||||
for item in blacklist
|
||||
delete esExportDefault[item]
|
||||
delete esExport[item]
|
||||
delete esNoExport[item]
|
||||
# blacklist = ["events", "main", "package", "task"]
|
||||
# for item in blacklist
|
||||
# delete esExportDefault[item]
|
||||
# delete esExport[item]
|
||||
# delete esNoExport[item]
|
||||
|
||||
# file.src is the list of all matching file names.
|
||||
for f in fileset.src
|
||||
|
@ -60,22 +60,33 @@ module.exports = (grunt) ->
|
|||
while i < result.length
|
||||
requirePath = result[i]
|
||||
i += 1
|
||||
|
||||
if requirePath[0] is "."
|
||||
lookupPath = path.normalize(path.join(path.dirname(f), requirePath))
|
||||
else
|
||||
lookupPath = requirePath
|
||||
|
||||
baseRequirePath = path.basename(requirePath)
|
||||
|
||||
plainRequireRe = new RegExp("require[ (]['\"].*#{baseRequirePath}['\"]\\)?$","gm")
|
||||
defaultRequireRe = new RegExp("require\\(['\"].*#{baseRequirePath}['\"]\\)\\.default","gm")
|
||||
|
||||
if esExport[baseRequirePath]
|
||||
if esExport[lookupPath]
|
||||
if not plainRequireRe.test(content)
|
||||
errors.push("#{f}: ES6 no `default` exported #{requirePath}")
|
||||
|
||||
if esNoExport[baseRequirePath]
|
||||
else if esNoExport[lookupPath]
|
||||
errors.push("#{f}: nothing exported from #{requirePath}")
|
||||
|
||||
if esExportDefault[baseRequirePath]
|
||||
else if esExportDefault[lookupPath]
|
||||
if not defaultRequireRe.test(content)
|
||||
errors.push("#{f}: ES6 add `default` to require #{requirePath}")
|
||||
|
||||
else
|
||||
# must be a coffeescript or core file
|
||||
if defaultRequireRe.test(content)
|
||||
errors.push("#{f}: don't ask for `default` from #{requirePath}")
|
||||
|
||||
if errors.length > 0
|
||||
grunt.log.error(err) for err in errors
|
||||
done(new Error("Please fix the #{errors.length} linter errors! Since we compile files in production to plain `.js` files it's very important you do NOT include the file extension when `require`ing a file. Also, as of Babel 6, `require` no longer returns whatever the `default` value is. If you are `require`ing an es6 file from a coffeescript file, you must explicitly request the `default` property. For example: do `require('./my-es6-file').default`"))
|
||||
|
|
Loading…
Reference in a new issue