Splitting the API and the CLI
See original GitHub issueI use the jquery-like API for transforming outside of the CLI (FWIW I use it in rollup).
Currently, my hacky workaround (along with some changes in my fork: https://github.com/mikob/jscodeshift) looks like this:
await JSCodeShift('/transforms/split.ts', [`dist/tmp/${pluginName}.joined.mjs`], {
transform: './transforms/split.ts',
verbose: 2,
runInBand: true,
dry: false,
print: false,
babel: true,
extensions: 'js,mjs',
ignorePattern: [],
ignoreConfig: [],
silent: false,
parser: 'babel',
stdin: false
});
This is not ideal because I get CLI output, a pool of workers, filesystem R/W etc. I’m only interested in using the API internally. So I can do something like this:
const transformedSrc = await JSCodeShift([transformFn: (jscodeshift: JSCodeShift) => string], src: string);
Currently transforms have a function signature like this:
module.exports = function (fileInfo: FileInfo, api: JSCodeshift, options) {
With the separated API, I would expect to be able to call a transform and only pass it the 2nd argument.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11
Top Results From Across the Web
Split code for CLI and core functionality into separate ... - GitHub
Sceptre officially supports use via the CLI and as a Python module. This leads difficulty with versioning as we are versioning two APIs...
Read more >Split a Twilio CLI Command into Multiple Lines
This guide explains how to split your commands, and gives sample code for different environments. Notice: CLI command examples may need to swap...
Read more >Introducing the Split CLI - Split - Split Software
Using the Split CLI, you can go from setting up your Split account to creating and ramping your feature flags in minutes.
Read more >split - Redocly
The split command takes an API definition file and creates a multi-file structure out of it by extracting referenced parts into standalone, ...
Read more >split-shard — AWS CLI 1.27.37 Command Reference
Splits a shard into two new shards in the Kinesis data stream, ... This API is only supported for the data streams with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe I came up with what you were looking for. The default
jscodeshift
export is the object passed as theapi
argument to a transform module from theRunner
. If you don’t wan’t any of theRunner
functionality, just usejscodeshift
directly, however you’d like:Here I’ve defined my own transform function that does what the sample/reverse-identifiers.js does: reverse all identifiers in the given source.
Running this example produces the following output:
If you want to specify transform modules from files, then I recommend reusing the code in Worker.js, lines 78-81:
I’ve provided the sample here: https://github.com/igetgames/jscodeshift-demo. Let me know if you need any more information.
@igetgames yes, that’s great! Much simpler than I imagined! Thank you for the very detailed write up!