-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support user .babelrc #347
Changes from 29 commits
6a09a3c
f0a5d22
0cd4bfa
3aaf007
951762a
fe59ec1
99cc9a6
728376a
1a20d71
fde2c16
0b51740
8ed645f
851331f
fb67e16
1f1497c
b1ff996
2bcb1f8
631ea4f
2a0b9cd
428543e
81cf6b5
1c653e2
f1b01ed
d0c0c18
001e202
877853a
fbffeac
406c0e1
8ef59f8
f6ad967
e04c035
7b69ecf
18fbc8f
9c8ab1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"no-var": 0 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var babelPresetLatest = require('babel-preset-latest'); | ||
var babelTransformRuntime = require('babel-plugin-transform-runtime'); | ||
var babelTransformModules = require('babel-plugin-transform-es2015-modules-commonjs'); | ||
|
||
module.exports = function(context, opts) { | ||
opts = opts || {}; | ||
return { | ||
// modules are handled by webpack, don't transform them | ||
presets: [[babelPresetLatest, { modules: false }]], | ||
|
||
// provide the ability to opt into babel-plugin-transform-runtime inclusion | ||
plugins: [opts.includeRuntime === true && babelTransformRuntime].filter(Boolean), | ||
|
||
env: { | ||
test: { | ||
plugins: [ | ||
[babelTransformModules, { loose: true }], | ||
], | ||
}, | ||
}, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "babel-preset-kyt-core", | ||
"version": "0.1.0-alpha.1", | ||
"description": "an opinionated babel preset, best used with kyt", | ||
"main": "lib/index.js", | ||
"author": "NYTimes", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"babel-plugin-transform-es2015-modules-commonjs": "6.16.0", | ||
"babel-plugin-transform-runtime": "6.15.0", | ||
"babel-preset-latest": "6.16.0" | ||
}, | ||
"keywords": ["babel", "babel-preset", "kyt"], | ||
"files": ["lib"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"no-var": 0 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var babelPresetReact = require('babel-preset-react'); | ||
var reactRemovePropTypes = require('babel-plugin-transform-react-remove-prop-types'); | ||
var reactTransformConstant = require('babel-plugin-transform-react-constant-elements'); | ||
var reactTransformInline = require('babel-plugin-transform-react-inline-elements'); | ||
var reactTransformJsxSource = require('babel-plugin-transform-react-jsx-source'); | ||
var babelPresetKytCore = require('babel-preset-kyt-core'); | ||
|
||
module.exports = function(context, opts) { | ||
opts = opts || {}; | ||
return { | ||
presets: [ | ||
babelPresetReact, | ||
// pass options through to core preset | ||
[babelPresetKytCore, opts.coreOptions || {}], | ||
], | ||
env: { | ||
development: { | ||
plugins: [ | ||
reactTransformJsxSource, | ||
], | ||
}, | ||
production: { | ||
plugins: [ | ||
reactRemovePropTypes, | ||
reactTransformConstant, | ||
reactTransformInline, | ||
], | ||
}, | ||
}, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "babel-preset-kyt-react", | ||
"version": "0.1.0-alpha.1", | ||
"description": "an opinionated babel preset for react apps, best used with kyt", | ||
"main": "lib/index.js", | ||
"author": "NYTimes", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"babel-plugin-transform-react-constant-elements": "6.9.1", | ||
"babel-plugin-transform-react-inline-elements": "^6.8.0", | ||
"babel-plugin-transform-react-jsx-source": "6.9.0", | ||
"babel-plugin-transform-react-remove-prop-types": "0.2.10", | ||
"babel-preset-kyt-core": "0.1.0-alpha.1", | ||
"babel-preset-react": "6.16.0" | ||
}, | ||
"keywords": [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do this for our other packages? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably! |
||
"babel", | ||
"babel-preset", | ||
"kyt", | ||
"react" | ||
], | ||
"files": [ | ||
"lib" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ module.exports = (flags, args) => { | |
userKytConfigPath, | ||
userNodeModulesPath, | ||
userPackageJSONPath, | ||
userBabelrcPath, | ||
} = require('kyt-utils/paths')(); // eslint-disable-line | ||
|
||
const date = Date.now(); | ||
|
@@ -282,6 +283,17 @@ module.exports = (flags, args) => { | |
logger.task('Created .editorconfig file'); | ||
}; | ||
|
||
const createBabelrc = () => { | ||
// back up existing .babelrc, if it exists | ||
if (shell.test('-f', userBabelrcPath)) { | ||
const mvTo = path.join(userRootPath, `.babelrc-${date}.bak`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe append a time stamp so there's no collisions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry missed the |
||
shell.mv(userBabelrcPath, mvTo); | ||
logger.info(`Backed up current .babelrc to ${mvTo}`); | ||
} | ||
shell.cp(`${tmpDir}/.babelrc`, userBabelrcPath); | ||
logger.task('Created .babelrc'); | ||
}; | ||
|
||
// Copies the starter kyt kyt.config.js | ||
// to the user's base directory. | ||
const createKytConfig = () => { | ||
|
@@ -389,11 +401,16 @@ module.exports = (flags, args) => { | |
logger.log(error); | ||
bailProcess(); | ||
} | ||
if (!args.repository) { | ||
// temporary - get the right version of the starter-kyts | ||
shell.exec('cd .kyt-tmp && git checkout babelrc'); | ||
} | ||
// eslint-disable-next-line global-require,import/no-dynamic-require | ||
tempPackageJSON = require(`${tmpDir}/package.json`); | ||
updateUserPackageJSON(false); | ||
installUserDependencies(); | ||
createESLintFile(); | ||
createBabelrc(); | ||
createStylelintFile(); | ||
createEditorconfigLink(); | ||
createKytConfig(); | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
coverage | ||
**/node_modules |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also curious of the argument for using < ES2015 in the presets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this is naive but I figured there's nothing about these presets that really requires them to be used inside kyt, so might as well make them es5 compatible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW these
.eslintrc.json
s aren't even honored right now since the root package'slint
ignores them (to work around needing to get the eslint config cascade working)