-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Using async functions in replacer #205
Comments
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 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 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. |
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. |
How If you provide more details I’ll suggest you best way to implement what you want. Take a look at |
Hey @coderaiser sorry for taking a while to reply.
and the file it requires has the following:
Im converting this so we end up with:
To do this I need to know the file path for I was hoping to this asynchronously as there could be lots of files to resolve. Thanks for creating this library! |
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:
If you will have any questions related rules, I’ll be glad to help :). |
Here is how it can look like https://putout.cloudcmd.io/#/gist/9c145612c7f7f7fb6b8906c766346957/2a84c80ceec6e56e7d853d7ceb3e4ce5396443b6 The idea is: you traversing filesystem tree, received from |
Hey, I'm working on a custom plugin to transform some legacy code using a replacer.
The replacer looks something like the example below:
I'd like to use an async function to resolve some file paths dynamically base on the value of
__a
Is this possible?
Thanks!
The text was updated successfully, but these errors were encountered: