Skip to content

Commit

Permalink
feat: Add prettier for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavithra K committed Mar 2, 2017
1 parent 4020043 commit 9828582
Show file tree
Hide file tree
Showing 5 changed files with 4,764 additions and 90 deletions.
4 changes: 3 additions & 1 deletion bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ if(argv.init) {
if (!filePaths.length) {
throw new Error('Please specify a path to your webpack config');
}
const outputConfigName = filePaths[1] || `${filePaths[0]}v2.js`;
const inputConfigPath = path.resolve(process.cwd(), filePaths[0]);
const outputConfigPath = path.resolve(process.cwd(), outputConfigName);

require('../lib/migrate.js')(inputConfigPath, inputConfigPath);
require('../lib/migrate.js')(inputConfigPath, outputConfigPath);
} else {
processOptions(yargs,argv);
}
169 changes: 83 additions & 86 deletions lib/transformations/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,102 +1,99 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`transform should respect recast options 1`] = `
"
module.exports = {
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
rules: [{
test: /.js$/,
use: \\"babel\\",
include: path.join(__dirname, 'src')
}]
},
resolve: {
modules: ['node_modules', path.resolve('/src')],
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
}),
new webpack.optimize.LoaderOptionsPlugin({
\\"debug\\": true,
\\"minimize\\": true,
})
],
debug: true
"module.exports = {
devtool: 'eval',
entry: ['./src/index'],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
rules: [
{
test: /.js$/,
use: 'babel',
include: path.join(__dirname, 'src')
}
]
},
resolve: {
modules: ['node_modules', path.resolve('/src')]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
}),
new webpack.optimize.LoaderOptionsPlugin({
debug: true,
minimize: true
})
],
debug: true
};
"
`;

exports[`transform should transform only using specified transformations 1`] = `
"
module.exports = {
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
rules: [{
test: /.js$/,
use: ['babel'],
include: path.join(__dirname, 'src')
}]
},
resolve: {
root: path.resolve('/src'),
modules: ['node_modules']
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
],
debug: true
"module.exports = {
devtool: 'eval',
entry: ['./src/index'],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
rules: [
{
test: /.js$/,
use: ['babel'],
include: path.join(__dirname, 'src')
}
]
},
resolve: {
root: path.resolve('/src'),
modules: ['node_modules']
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
],
debug: true
};
"
`;

exports[`transform should transform using all transformations 1`] = `
"
module.exports = {
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
rules: [{
test: /.js$/,
use: 'babel',
include: path.join(__dirname, 'src')
}]
},
resolve: {
modules: ['node_modules', path.resolve('/src')]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
}),
new webpack.optimize.LoaderOptionsPlugin({
'debug': true,
'minimize': true
})
],
debug: true
"module.exports = {
devtool: 'eval',
entry: ['./src/index'],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
rules: [
{
test: /.js$/,
use: 'babel',
include: path.join(__dirname, 'src')
}
]
},
resolve: {
modules: ['node_modules', path.resolve('/src')]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
}),
new webpack.optimize.LoaderOptionsPlugin({
debug: true,
minimize: true
})
],
debug: true
};
"
`;
4 changes: 2 additions & 2 deletions lib/transformations/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const jscodeshift = require('jscodeshift');

const prettier = require('prettier');
const loadersTransform = require('./loaders/loaders');
const resolveTransform = require('./resolve/resolve');
const removeJsonLoaderTransform = require('./removeJsonLoader/removeJsonLoader');
Expand Down Expand Up @@ -38,7 +38,7 @@ function transform(source, transforms, options) {
}, options);
transforms = transforms || Object.keys(transformations).map(k => transformations[k]);
transforms.forEach(f => f(jscodeshift, ast));
return ast.toSource(recastOptions);
return prettier.format(ast.toSource(recastOptions), {singleQuote: true, tabWidth: 2});
}

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"jscodeshift": "^0.3.30",
"loader-utils": "^0.2.16",
"lodash": "^4.17.4",
"recast": "git://github.com/kalcifer/recast.git#bug/allowbreak",
"prettier": "^0.20.0",
"recast": "^0.11.22",
"rx": "^4.1.0",
"supports-color": "^3.1.2",
"webpack": "^2.2.0-rc.0",
Expand Down
Loading

0 comments on commit 9828582

Please sign in to comment.