mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-27 09:36:28 +08:00
feat(babel6): Add babel presets and lint for require.default
This commit is contained in:
parent
e2f9104766
commit
427a23bbe6
5 changed files with 73 additions and 38 deletions
|
@ -197,6 +197,29 @@ module.exports = (grunt) ->
|
|||
csonConfig.glob_to_multiple.src.push("#{directory}/**/*.cson")
|
||||
pegConfig.glob_to_multiple.src.push("#{directory}/**/*.pegjs")
|
||||
|
||||
COFFEE_SRC = [
|
||||
'internal_packages/**/*.cjsx'
|
||||
'internal_packages/**/*.coffee'
|
||||
'dot-nylas/**/*.coffee'
|
||||
'src/**/*.coffee'
|
||||
'src/**/*.cjsx'
|
||||
'spec/**/*.cjsx'
|
||||
'spec/**/*.coffee'
|
||||
]
|
||||
ES_SRC = [
|
||||
'internal_packages/**/*.jsx'
|
||||
'internal_packages/**/*.es6'
|
||||
'internal_packages/**/*.es'
|
||||
'dot-nylas/**/*.es6'
|
||||
'dot-nylas/**/*.es'
|
||||
'src/**/*.es6'
|
||||
'src/**/*.es'
|
||||
'src/**/*.jsx'
|
||||
'spec/**/*.es6'
|
||||
'spec/**/*.es'
|
||||
'spec/**/*.jsx'
|
||||
]
|
||||
|
||||
grunt.initConfig
|
||||
pkg: grunt.file.readJSON('package.json')
|
||||
|
||||
|
@ -219,26 +242,12 @@ module.exports = (grunt) ->
|
|||
peg: pegConfig
|
||||
|
||||
nylaslint:
|
||||
src: [
|
||||
'internal_packages/**/*.cjsx'
|
||||
'internal_packages/**/*.coffee'
|
||||
'dot-nylas/**/*.coffee'
|
||||
'src/**/*.coffee'
|
||||
'src/**/*.cjsx'
|
||||
'spec/**/*.cjsx'
|
||||
'spec/**/*.coffee'
|
||||
]
|
||||
src: COFFEE_SRC.concat(ES_SRC)
|
||||
|
||||
coffeelint:
|
||||
options:
|
||||
configFile: 'build/config/coffeelint.json'
|
||||
src: [
|
||||
'internal_packages/**/*.cjsx'
|
||||
'internal_packages/**/*.coffee'
|
||||
'dot-nylas/**/*.coffee'
|
||||
'src/**/*.coffee'
|
||||
'src/**/*.cjsx'
|
||||
]
|
||||
src: COFFEE_SRC
|
||||
build: [
|
||||
'build/tasks/**/*.coffee'
|
||||
'build/Gruntfile.coffee'
|
||||
|
@ -258,16 +267,7 @@ module.exports = (grunt) ->
|
|||
options:
|
||||
ignore: false
|
||||
configFile: 'build/config/eslint.json'
|
||||
target: [
|
||||
'internal_packages/**/*.jsx'
|
||||
'internal_packages/**/*.es6'
|
||||
'internal_packages/**/*.es'
|
||||
'dot-nylas/**/*.es6'
|
||||
'dot-nylas/**/*.es'
|
||||
'src/**/*.es6'
|
||||
'src/**/*.es'
|
||||
'src/**/*.jsx'
|
||||
]
|
||||
target: ES_SRC
|
||||
|
||||
csslint:
|
||||
options:
|
||||
|
|
|
@ -2,20 +2,51 @@ path = require 'path'
|
|||
fs = require 'fs-plus'
|
||||
|
||||
module.exports = (grunt) ->
|
||||
{spawn} = require('./task-helpers')(grunt)
|
||||
|
||||
grunt.registerMultiTask 'nylaslint', 'Check requires for file extensions compiled away', ->
|
||||
done = @async()
|
||||
regex = /require ['"].*\.(coffee|cjsx|jsx)['"]/i
|
||||
extensionRegex = /require ['"].*\.(coffee|cjsx|jsx|es6|es)['"]/i
|
||||
|
||||
for fileset in @files
|
||||
grunt.log.writeln('Nylinting ' + fileset.src.length + ' files.')
|
||||
|
||||
esExtensions = {
|
||||
".es6": true
|
||||
".es": true
|
||||
".jsx": true
|
||||
}
|
||||
coffeeExtensions = {
|
||||
".coffee": true
|
||||
".cjsx": true
|
||||
}
|
||||
|
||||
esSet = {}
|
||||
for f in fileset.src
|
||||
if esExtensions[path.extname(f)]
|
||||
esSet[path.basename(f, path.extname(f))] = true
|
||||
|
||||
errors = []
|
||||
|
||||
# file.src is the list of all matching file names.
|
||||
for f in fileset.src
|
||||
continue if esExtensions[path.extname(f)]
|
||||
content = fs.readFileSync(f, encoding:'utf8')
|
||||
if regex.test(content)
|
||||
done(new Error("#{f} contains a bad require including an coffee / cjsx / jsx extension. Remove the extension!"))
|
||||
return
|
||||
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}")
|
||||
|
||||
if errors.length > 0
|
||||
grunt.log.error(err) for err in errors
|
||||
done(new Error("Please fix the 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`"))
|
||||
|
||||
done(null)
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
"dependencies": {
|
||||
"async": "^0.9",
|
||||
"babel-core": "6.8.x",
|
||||
"babel-preset-es2015": "6.6.x",
|
||||
"babel-preset-react": "6.5.x",
|
||||
"babel-preset-stage-0": "6.5.x",
|
||||
"bluebird": "^2.9",
|
||||
"chrono-node": "^1.1.2",
|
||||
"classnames": "1.2.1",
|
||||
|
|
2
src/pro
2
src/pro
|
@ -1 +1 @@
|
|||
Subproject commit 62e283d93275f62a38a8e97d017000925d363031
|
||||
Subproject commit c4244e4845241558ba17a9419551a44de37b2fa8
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"breakConfig": true,
|
||||
"sourceMap": "inline",
|
||||
"blacklist": ["es6.forOf", "useStrict"],
|
||||
"optional": ["asyncToGenerator"],
|
||||
"stage": 0
|
||||
"presets": [
|
||||
"es2015",
|
||||
"react",
|
||||
"stage-0"
|
||||
],
|
||||
"sourceMaps": "inline"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue