babel-plugin-transform-modules-ui5
babel-plugin-transform-modules-ui5 copied to clipboard
Ignore certain files from applying sap.ui.define
Hello,
I have a question regarding the process which converts all typescript files into UI5-Like JS files. It seems to me that basically every TypeScript files receives the sap.ui.define addition when needed / possible. Now I have a Service-Worker in our UI5 App which definitely doesn't need the sap.ui.define addition. Is there any way right not to let the transformation to UI5 modules know, to ignore certain files whilst still transpiling TS to JS?
If not, would that be something that could be implemented? I would look myself into this if no other option is available today.
Kind regards
HI @DaniloMurer
Maybe I am wrong, but typescript to js compilation is due to the preset @babel/preset-typescript in your .babelrc file (if you dont have an explicit one yet, would suggest to do so), and the preset/plugin transform-ui5 only kicks in at a later stage, once the code is already JS. Within transform-ui5 it is then decided for which files to add the define syntax, and which ones to convert to UI5 style "extend" syntax.
For the latter feaute (which is not what you are interested it) in class plugin/src/classes/visitor/enter() the method shouldConvertClass() is called to take a decision on whether to do the conversion or not. Relatively simple.
For the import module format, seem in index.js in method exit() first all imports are parsed, and finally the wrap method actually put the wrapping code around. This would skip Proj.ts file from processing, no matter in which folder:
exit(path, { file, /* << new parameter for getting file ifo */ opts }) { console.log("> " + file.opts.filename ); if (file.opts.filename.endsWith("Proj.ts")) { return; } path.traverse({ ImportDeclaration: _visitor2.ModuleTransformVisitor.ImportDeclaration }, this); (0, _wrapper.wrap)(this, path.node, opts); }
As far as I can see there is at the moment no way to control (via parameters) which files are processed. It think it would make sense to make 2 "subsections" in the configuration: One for module processing, and one for class conversion. That would make clear whether the setting applies to one or the other. Within each of these two sections I could imagine an includeFiles and excludeFiles array, with entries in gitignore-like pattern format. E.g.
.babelerc excerpt:
`
"transform-ui5", { "namespacePrefix": "com.whatever", "autoConvertControllerClass": true,
"moduleImportConversion": {
"includeFiles": [
"webapp/controller/**",
"webapp/model/**",
"webapp/Component.js"
],
"excludeFiles": [
"webapp/model/MyFile.js"
]
}
}
`
default for includefiles could be **/*.js|ts
Oliver