mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
feat(babel6): Detect when packages don't have a default export
This commit is contained in:
parent
7f50074c0d
commit
ff7f909317
5 changed files with 55 additions and 30 deletions
|
@ -19,37 +19,62 @@ module.exports = (grunt) ->
|
|||
".cjsx": true
|
||||
}
|
||||
|
||||
esSet = {}
|
||||
for f in fileset.src
|
||||
if esExtensions[path.extname(f)]
|
||||
esSet[path.basename(f, path.extname(f))] = true
|
||||
blacklist = ["events", "main", "package", "task"]
|
||||
delete esSet[item] for item in blacklist
|
||||
|
||||
errors = []
|
||||
|
||||
esExport = {}
|
||||
esNoExport = {}
|
||||
esExportDefault = {}
|
||||
|
||||
for f in fileset.src
|
||||
continue if not esExtensions[path.extname(f)]
|
||||
fname = path.basename(f, path.extname(f))
|
||||
|
||||
content = fs.readFileSync(f, encoding:'utf8')
|
||||
if /module.exports\s?=\s?.+/gmi.test(content)
|
||||
errors.push("#{f}: Don't use module.exports in ES6")
|
||||
|
||||
if /^export/gmi.test(content)
|
||||
if /^export\ default/gmi.test(content)
|
||||
esExportDefault[fname] = true
|
||||
else
|
||||
esExport[fname] = true
|
||||
else
|
||||
esNoExport[fname] = true
|
||||
|
||||
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
|
||||
if esExtensions[path.extname(f)]
|
||||
content = fs.readFileSync(f, encoding:'utf8')
|
||||
if /module.exports\s?=\s?.+/.test(content)
|
||||
errors.push("#{f}: Don't use module.exports in ES6")
|
||||
else
|
||||
content = fs.readFileSync(f, encoding:'utf8')
|
||||
if extensionRegex.test(content)
|
||||
errors.push("#{f}: Remove require extension!")
|
||||
continue if esExtensions[path.extname(f)]
|
||||
content = fs.readFileSync(f, encoding:'utf8')
|
||||
if extensionRegex.test(content)
|
||||
errors.push("#{f}: Remove require extension!")
|
||||
|
||||
requireRe = /require[\s()]['"](.*)['"]/gmi
|
||||
while result = requireRe.exec(content)
|
||||
i = 1
|
||||
while i < result.length
|
||||
requirePath = result[i]
|
||||
i += 1
|
||||
baseRequirePath = path.basename(requirePath)
|
||||
if esSet[baseRequirePath]
|
||||
testForPath = new RegExp("require\\(['\"].*#{baseRequirePath}['\"]\\)\\.","gm")
|
||||
if not testForPath.test(content)
|
||||
errors.push("#{f}: ES6 add `default` to require #{requirePath}")
|
||||
requireRe = /require[ (]['"]([\w_./-]*?)['"]/gmi
|
||||
while result = requireRe.exec(content)
|
||||
i = 1
|
||||
while i < result.length
|
||||
requirePath = result[i]
|
||||
i += 1
|
||||
baseRequirePath = path.basename(requirePath)
|
||||
|
||||
plainRequireRe = new RegExp("require[ (]['\"].*#{baseRequirePath}['\"]\\)?$","gm")
|
||||
defaultRequireRe = new RegExp("require\\(['\"].*#{baseRequirePath}['\"]\\)\\.default","gm")
|
||||
|
||||
if esExport[baseRequirePath]
|
||||
if not plainRequireRe.test(content)
|
||||
errors.push("#{f}: ES6 no `default` exported #{requirePath}")
|
||||
|
||||
if esNoExport[baseRequirePath]
|
||||
errors.push("#{f}: nothing exported from #{requirePath}")
|
||||
|
||||
if esExportDefault[baseRequirePath]
|
||||
if not defaultRequireRe.test(content)
|
||||
errors.push("#{f}: ES6 add `default` to require #{requirePath}")
|
||||
|
||||
if errors.length > 0
|
||||
grunt.log.error(err) for err in errors
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
ExtensionRegistry = require('../src/extension-registry').default
|
||||
ExtensionRegistry = require('../src/extension-registry')
|
||||
|
||||
class TestExtension
|
||||
@name: 'TestExtension'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Message = require '../models/message'
|
||||
Actions = require '../actions'
|
||||
DatabaseStore = require './database-store'
|
||||
ExtensionRegistry = require('../../extension-registry').default
|
||||
ExtensionRegistry = require('../../extension-registry')
|
||||
{Listener, Publisher} = require '../modules/reflux-coffee'
|
||||
SyncbackDraftTask = require('../tasks/syncback-draft-task').default
|
||||
CoffeeHelpers = require '../coffee-helpers'
|
||||
|
|
|
@ -27,7 +27,7 @@ SoundRegistry = require '../../sound-registry'
|
|||
{Listener, Publisher} = require '../modules/reflux-coffee'
|
||||
CoffeeHelpers = require '../coffee-helpers'
|
||||
|
||||
ExtensionRegistry = require('../../extension-registry').default
|
||||
ExtensionRegistry = require('../../extension-registry')
|
||||
{deprecate} = require '../../deprecate-utils'
|
||||
|
||||
###
|
||||
|
|
|
@ -8,7 +8,7 @@ FocusedPerspectiveStore = require './focused-perspective-store'
|
|||
FocusedContentStore = require "./focused-content-store"
|
||||
ChangeUnreadTask = require('../tasks/change-unread-task').default
|
||||
NylasAPI = require '../nylas-api'
|
||||
ExtensionRegistry = require('../../extension-registry').default
|
||||
ExtensionRegistry = require('../../extension-registry')
|
||||
{deprecate} = require '../../deprecate-utils'
|
||||
async = require 'async'
|
||||
_ = require 'underscore'
|
||||
|
|
Loading…
Reference in a new issue