Comments (6)
Replacer is sync only because 🐊Putout can also be used as plugin for ESLint which works on IDE. Could you please provide more details, I don’t think that it will be a problem if you use sync
versions resolve files paths. Also please tell me how do you want to run transformations, are you going to use 🐊Putout CLI for this purpose?
Also keep in mind that is better when your plugins is "clean" in this case is much simpler to write plugins using 🐊Putout Editor and also test them.
If you need to dial with FileSystem and you want test + write fast drafts in editor - use Scanner + Replacer. Take a look to nodejs/mjs-file
for example.
Also take a look on RedPut to generate tests for your code mods and RedLint to run filesystem-based rules easily.
If you have any questions - ask, I’ll try to help.
from putout.
Hey @coderaiser thanks for the reply. I am using the module itself in JS, as an example it looks like:
// index.js
import putout from 'putout';
import * as convert from './plugins/convert.js'
// example of some code that would be loaded
let currentCode = `app.definitions[ 'app.view.context.entity.FilterMenu' ] = {
extend : 'app.view.filter.FilterMenu',
className : 'selectButton hasForm filter nonLinkList needsEntities',
attributes : {
'data-integration' : 'entity-filter'
},
intialize() {
console.log('initialize');
},
loadData : function() {
console.log('loadData');
}
}`;
const code = putout(currentCode, {
plugins: [
['modernise', convert],
],
});
I have a large legacy codebase that I want to convert from our custom module implementation to standard ES modules and classes.
So far I've found using the custom plugin has worked pretty well for this, but perhaps this is not the best way to implement it. If there is a more appropriate way I can look in to that, but using some async functions would be useful.
For now I have gotten around it by using some sync functions as you mentioned.
from putout.
How convert
looks like right now? I don’t quit understand why you need async functions? What is final result of transformation?
If you provide more details I’ll suggest you best way to implement what you want.
Take a look at @putout/operator-match-files
, here is usage example and way to run it programmatically. This is for cases when you need to dial with File System, and still have simple, easy testable code (with autogenerated tests).
from putout.
Hey @coderaiser sorry for taking a while to reply.
The code im converting has a custom loader that I'm trying to convert to standard module imports so for example one file might contain
requires: [
'app.view.List'
]
and the file it requires has the following:
app.definitions[ 'app.view.List' ] = {
....
}
Im converting this so we end up with:
import AppViewList from 'FILE PATH HERE'
To do this I need to know the file path for app.view.List
.
I was hoping to this asynchronously as there could be lots of files to resolve.
For now Im using child.execSync
and a grep command which is reasonably fast but it would be useful if I could do this when the plugin runs async. My alternative is to generate a lookup of all the paths in advanced and use in my custom plugin, either way I am unblocked for now so I will close the issue.
Thanks for creating this library!
from putout.
So it something like this:
// App.js
requires: [
'app.view.List'
];
// AppViewList.js
app.definitions[ 'app.view.List' ] = {
}
And you want:
// App.js
import AppViewList from './AppViewList.js';
// AppViewList.js
export default () = {
}
The idea is good, but we blocked by eslint/eslint#15394, (and this is really hard to support all IDE’s without ESLint, it should be made beforehand) when unblocked we can implement this, but there’s a couple things to remember anyways:
- Scanner was done to dial with file system API in a simplest possible way;
- If you dial with filesystem in another way, it will be hard to test things, you need lots of mocking, and it will not work in 🐊Putout Editor, so it’s preferred to write plugins as clean functions. You can write code in any way you like, of course, but this is preferred way that helps you to not shoot in your feet.
If you will have any questions related rules, I’ll be glad to help :).
from putout.
Here is how it can look like https://putout.cloudcmd.io/#/gist/9c145612c7f7f7fb6b8906c766346957/2a84c80ceec6e56e7d853d7ceb3e4ce5396443b6
The idea is: you traversing filesystem tree, received from redlint
, and run regular 🐊Putout rule that does transformation you need. It is easy to test and develop, since there is no writing to file system, and when you are ready and tests passes you run on real file system.
from putout.
Related Issues (20)
- convert-commonjs-to-esm/exports not working HOT 8
- Double quotes to single quotes conversion creates syntax error HOT 3
- question: how can i disable all plugins that are not in the rulesdir? HOT 3
- [printer] [bug] HOT 2
- Question: Reverse mode HOT 4
- Wrong transform with @putout/plugin-for-of HOT 15
- Incorrect order of initialization of variables HOT 4
- Incorrect removing of an expression HOT 2
- ignore test files HOT 5
- path is missing for ruler toggler HOT 2
- babel config is not loaded. HOT 13
- how to run just specific rules HOT 1
- putout ignores camelCased paths HOT 1
- Mistaken removal of semi from unnamed prop types in FC HOT 12
- @putout/printer: Removed useful comma in TS HOT 6
- 🐊 name.startsWith is not a function HOT 13
- How to use indetifier name as a string? HOT 4
- It it possible to use Putout as Eslint backend? HOT 1
- remove-unused-expressions: "use client" false warning HOT 2
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 putout.