Skip to content
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

Feature: Jscodeshift Transformations for --migrate #40

Merged
merged 43 commits into from
Feb 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d8b57af
fix: Support for more complex query strings in loaders syntax
okonet Jan 26, 2017
465b915
style: Re-format source code for loaders transformation
okonet Jan 26, 2017
7da4804
style: Don't run eslint on fixtures code
okonet Jan 26, 2017
0278297
WIP: Added tests for removeJsonLoader
okonet Jan 26, 2017
cdd2cad
Do not pre-process test fixtures with eslint --fix since it makes our…
okonet Jan 27, 2017
97866e1
Use spaces instead of tabs for indentation in fixtures to get reliabl…
okonet Jan 27, 2017
dcdcd91
Introduce removeJsonLoaderTransform that remove json-loader from load…
okonet Jan 27, 2017
02c1425
style: Re-format code of resolve transformation
okonet Jan 27, 2017
eaab59a
Introduce uglifyJsPluginTransform
okonet Jan 27, 2017
c15acac
Add .editorconfig to fixtures directories
okonet Jan 27, 2017
4fa696d
Add OccurrenceOrderPlugin transformation
okonet Jan 27, 2017
1cbd96a
fixup! Introduce uglifyJsPluginTransform
okonet Feb 1, 2017
97e547a
Made OccurrenceOrderPlugin in to a more generic removeDeprecatedPlugi…
okonet Feb 1, 2017
6242628
Renamed safeTraverse to utils to allow multiple jscodeshift-helpers t…
okonet Feb 1, 2017
0f24d8d
Share memberExpressionToPathString when working with plugins
okonet Feb 1, 2017
c731d18
Introduce findPluginsByName function
okonet Feb 1, 2017
a8d8c31
WIP on LoaderOptionsPlugin
okonet Feb 1, 2017
d6a7364
WIP on LoaderOptionsPlugin
okonet Feb 3, 2017
e198fa1
WIP Extract Plugin
Feb 7, 2017
7ffb1e8
Gets basic case of extract text plugin working
Feb 11, 2017
8c2c9ad
Fixed ExtractTextPlugin tests by properly formatting both input and o…
okonet Feb 13, 2017
0dabfc3
Added tests for utils
okonet Feb 14, 2017
2bbfc4c
Fixed createOrUpdatePluginByName implementation
okonet Feb 15, 2017
333ff91
Always use Literals for keys for now
okonet Feb 15, 2017
734b3be
Fixed LoaderOptionsPlugin
okonet Feb 15, 2017
73ef8ce
Return the full AST for compatibility
okonet Feb 15, 2017
6d21726
Implemented BannerPlugin transformation.
okonet Feb 15, 2017
e8deaed
Use shorthand object syntax
okonet Feb 15, 2017
8f5a9d7
Added JSDoc for findPluginsByName util function
okonet Feb 15, 2017
5bcc5ec
Export all available transforms
okonet Feb 15, 2017
4601054
fixup! Implemented BannerPlugin transformation.
okonet Feb 15, 2017
83c65db
Simplified directory structure and colocate tests with source files.
okonet Feb 15, 2017
c12df12
Switch to snapshot testing and removed output fixtures
okonet Feb 15, 2017
45ccf97
All transformations return AST to allow chaining
okonet Feb 15, 2017
99624b5
Split separate test cases into separate files
okonet Feb 15, 2017
6f04f3d
Added tests and fixed some edge cases in BannerPlugin
okonet Feb 15, 2017
4223c3a
Introduce and export `transform` function
okonet Feb 15, 2017
067f71a
Adds new utils and tests
Feb 19, 2017
99e99cd
Refactors loaders transforms
Feb 19, 2017
3e064b4
Adds more refactoring
Feb 19, 2017
d758330
Trims the input test
Feb 19, 2017
d66f4e1
Fixes eslint and parse bug
Feb 19, 2017
e0539a1
Adds to the contributor docs about transforms
Feb 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch to snapshot testing and removed output fixtures
  • Loading branch information
okonet authored and Pavithra K committed Feb 19, 2017
commit c12df128c66947524cf59017a7b2bbc5b0e23f28
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module.exports = {
exports[`bannerPlugin transforms correctly 1`] = `
"module.exports = {
plugins: [
new webpack.BannerPlugin({
raw: true,
entryOnly: true,
'banner': 'Banner'
\'banner\': \'Banner\'
})
]
}
"
`;
11 changes: 2 additions & 9 deletions lib/transformations/defineTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ function runTest(dirName, transformName, options, testFilePrefix) {
const fixtureDir = path.join(dirName, '__testfixtures__');
const inputPath = path.join(fixtureDir, testFilePrefix + '.input.js');
const source = fs.readFileSync(inputPath, 'utf8');
const expectedOutput = fs.readFileSync(
path.join(fixtureDir, testFilePrefix + '.output.js'),
'utf8'
);
// Assumes transform and test are on the same level
const module = require(path.join(dirName, transformName + '.js'));
// Handle ES6 modules using default export for the transform
Expand All @@ -61,11 +57,8 @@ function runTest(dirName, transformName, options, testFilePrefix) {
jscodeshift = jscodeshift.withParser(module.parser);
}
const ast = jscodeshift(source);
const output = transform(
jscodeshift,
ast
);
expect((output || '').trim()).toEqual(expectedOutput.trim());
const output = transform(jscodeshift, ast);
expect(output).toMatchSnapshot();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
exports[`extractTextPlugin transforms correctly 1`] = `
"let ExtractTextPlugin = require(\'extract-text-webpack-plugin\');

let extractCSS = new ExtractTextPlugin(\'stylesheets/[name].css\');
let extractLESS = new ExtractTextPlugin(\'stylesheets/[name].less\');

module.export = {
module: {
rules: [
{
test: /\\.css$/,
use: ExtractTextPlugin.extract({
fallback: \'style-loader\',
use: \'css-loader\'
})
}
]
},
plugins: [
new ExtractTextPlugin(\"styles.css\"),
]
}
"
`;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports[`loaderOptionsPlugin transforms correctly 1`] = `
"module.exports = {
debug: true,
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.LoaderOptionsPlugin({
foo: \'bar\',
\'debug\': true,
\'minimize\': true
})
]
}
"
`;

This file was deleted.

80 changes: 80 additions & 0 deletions lib/transformations/loaders/__snapshots__/loaders.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
exports[`loaders transforms correctly 1`] = `
"export default [{
module: {
rules: [{
test: /\\.js$/,
use: \'babel-loader\'
}]
}
}, {
module: {
rules: [{
test: /\\.css$/,
use: [{
loader: \'style-loader\'
}, {
loader: \'css-loader\',

options: {
modules: true,
importLoaders: 1,
string: \'test123\'
}
}]
}]
}
}, {
module: {
rules: [{
test: /\\.css$/,
use: [{
loader: \'style-loader\'
}, {
loader: \'css-loader\',
options: {
modules: true
}
}]
}]
}
}, {
module: {
rules:[{
test: /\\.js$/,
use: \'eslint-loader\',
enforce: \'pre\'
}]
}
}, {
module: {
rules:[{
test: /\\.js$/,
use: \'my-post-loader\',
enforce: \'post\'
}]
}
}, {
module: {
rules: [{
test: /\\.js$/,
use: \'babel-loader\'
}, {
test: /\\.js$/,
use: \'eslint-loader\',
enforce: \'pre\'
}]
}
}, {
module: {
rules: [{
test: /\\.js$/,
use: \'babel-loader\'
}, {
test: /\\.js$/,
use: \'my-post-loader\',
enforce: \'post\'
}]
}
}];
"
`;
76 changes: 0 additions & 76 deletions lib/transformations/loaders/__testfixtures__/loaders.output.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Works for OccurrenceOrderPlugin
exports[`removeDeprecatedPlugins transforms correctly 1`] = `
"// Works for OccurrenceOrderPlugin
module.exports = {}

// Works for DedupePlugin
module.exports = {}

// Doesn't remove unmatched plugins
// Doesn\'t remove unmatched plugins
module.exports = {
plugins: [new webpack.optimize.UglifyJsPlugin()]
}
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
exports[`removeJsonLoader transforms correctly 1`] = `
"export default [{
module: {
rules: [{
test: /\\.yml/,
use: [\'another-loader\', \'yml-loader\']
}]
}
}, {
module: {
rules: [{
test: /\\.yml/,
use: \'yml-loader\'
}]
}
}, {
module: {
rules: []
}
}, {
module: {
rules: [{
test: /\\.yml/,
use: [\'another-loader\', \'yml-loader\']
}, {
test: /\\.yml/,
use: \'yml-loader\'
}]
}
}];

"
`;

This file was deleted.

22 changes: 22 additions & 0 deletions lib/transformations/resolve/__snapshots__/resolve.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
exports[`resolve transforms correctly 1`] = `
"import path from \'path\';

export default [{
resolve: {
modules: [path.resolve(\'/src\')]
}
}, {
resolve: {
modules: [path.resolve(\'/src\')]
}
}, {
resolve: {
modules: [path.resolve(\'/src\'), \'node_modules\']
}
}, {
resolve: {
modules: [\'node_modules\', path.resolve(\'/src\')]
}
}];
"
`;
19 changes: 0 additions & 19 deletions lib/transformations/resolve/__testfixtures__/resolve.output.js

This file was deleted.

Loading