Comments (8)
I think this suggestion should be revisited (there are nice solutions today like cosmiconfig for dealing with format). I currently have to use a custom npm script which passes options to jscodeshift the way I want, I think a config file would be a cleaner solution. Also, libraries like react-codemod could read your configuration instead of asking you (and I still couldn't configure it to work, but that's another story).
from jscodeshift.
Throwing this up here for discussion. Happy to put together a pull request if we think this is a good idea.
from jscodeshift.
It should definitely be JSON.
I think this makes sense. I'm a little bit worried that people would put a lot of script-specific options into those config files and that they'd potentially collide. I guess that is not a big deal though. Go for it!
from jscodeshift.
I pushed a WIP commit for this here: https://github.com/wincent/jscodeshift/commit/7a8317a4dd66d201b5c97e89893b944e1a1408cb
- currently doesn't try any validation of config file contents (other than them being parseable by
JSON.parse
) - want to add more tests for the
ConfigReader
andOptionParser
modules, but... - ...Jest is acting very strangely with the mocks, and I can't get them to work properly (not mocking things I ask it to mock, mocking others I ask it not to mock etc...)
from jscodeshift.
@wincent do you have time to rebase your diff against the current version of jscodeshift past #24? I'd really love for us to add this feature. I'd like it to travel up the hierarchy until it finds a .jscodeshiftrc
file. At FB, we could add one to our JS codebases with default print settings so a developer doesn't have to worry about picking the right options.
from jscodeshift.
Yeah, I have some time, although the exact amount and distribution of it is unpredictable right now.
Traversing up sounds fine.
from jscodeshift.
Doesn't look like there has been progress on this in awhile (and I would like to see this feature for my own use), so I started working on a new branch. I did run into a bit of an issue, though.
I would assume that the preference is for command line arguments to override config in .jscodeshiftrc
, right? This is problematic when trying to do this in combination with nomnom
, because of the fact that nomnom
handles setting the defaults. When merging .jscodeshiftrc
values with the parsed CLI values, those defaults are always going to take precedence.
I considered pulling the defaults out of nomnom
and handling that logic/config elsewhere, but that has the caveat that --help
will no longer show defaults.
I looked at the previous WIP that Greg proposed for ideas, but (unless I'm looking at it wrong), it doesn't look like this logic will work, because options
(coming from nomnom
's parse
) will always have the property name being passed to hasOwnProperty
.
On second thought, I guess what I was doing doesn't have too much value. I was trying to make it possible to override CLI options in addition to recast
print settings, but I can't think of a scenario where you'd ever want to set most of those CLI options as static config. Maybe for now, we just provide the ability to provide print settings in the config file, and structure the config in such a way that we can add more options in the future? Example config being:
{
"recastPrintOpts": {}
}
@cpojer Any thoughts?
from jscodeshift.
that's I'm doing inside my transformer file
import path from 'path';
const cwd = process.cwd();
const getConfig = (options: Options) => {
if (!options.config) {
return defaultConfig;
}
try {
const configPath = path.join(cwd, options.config);
const config = require(configPath); // eslint-disable-line
return config;
} catch (e) {
// eslint-disable-next-line
console.log('Config not found');
return defaultConfig;
}
};
function transform(file: FileInfo, api: API, options: Options) {
const config = getConfig(options);
}
how to use it
jscodeshift -t transform.ts --config path/to/config.js
config.js
module.exports = {
options: 'optionA',
}
from jscodeshift.
Related Issues (20)
- Error: Cannot find module 'transform.js' HOT 4
- Extra parens inserted around JSX after attributes are added HOT 6
- Help: How do I get hold of Decorator nodes?
- We need more information on issues reported HOT 2
- Parsing .d.ts files HOT 2
- can I access docs online? HOT 6
- can I run jscodeshift as a REPL? HOT 2
- It seems we can't add a comment at the bottom of the target node? HOT 2
- Help: adding a line of comment `@ts-expect-error IGNORE TEMP` above all lines in files with type errors HOT 2
- Cannot find module `lodash` HOT 1
- URL transform doesn't work with TypeScript HOT 2
- Can't see file in current working directory - "Skipping path which does not exist." HOT 2
- Ignore pattern doesn't work with relative paths starting with two dots (../) HOT 1
- Automatically publish latest dev version to npm HOT 1
- Declaration has "null" loc field when inside export HOT 1
- missing semicolon how to fix this HOT 9
- how can I add @babel/plugin-proposal-private-methods to jscodeshift ? HOT 5
- extensions cli option not respected when passing individual file paths
- cannot replace JSX nodes within render props
- Added parenthesis around await expression in if statement HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jscodeshift.