Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/ui5-tooling-transpile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ npm install ui5-tooling-transpile --save-dev
- generateBabelConfig: `boolean|string` (*experimental feature*)
this option allows to generate the babel config file for the current project when the babel config file doesn't exist - this option is useful when you are using babel generation within a different tooling (like a native babel execution inside e.g. jest) to use the same configuration like when running the task or middleware; if the value is a string the tooling extension will assume to generate a file with the provided name

- aliasPatterns: `Map<string,string` (*experimental feature*)
allows to define alias patterns to convert a request urls into target urls, e.g. converting `/__alias/ui5.ecosystem.demo.tslib.util/capitalize.js` into `/resources/ui5/ecosystem/demo/tslib/util/capitalize.js`. This can be done by providing the following mapping: `^/__alias/([^.]+)\\.([^.]+)\\.([^.]+)\\.([^.]+)\\.([^.]+)/(.*)$": "/resources/$1/$2/$3/$4/$5/$6"` as an entry of this configuration option.

The following configuration options will only be taken into account if no inline babel configuration is maintained in the `ui5.yaml` as `babelConfig` or no external babel configuration exists in any configuration file as described in [Babels configuration section](https://babeljs.io/docs/configuration):

- targetBrowsers: `String` (default: [`"defaults"`](https://browsersl.ist/#q=defaults))
Expand Down
15 changes: 14 additions & 1 deletion packages/ui5-tooling-transpile/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,22 @@ module.exports = async function ({ log, resources, options, middlewareUtil }) {
return async (req, res, next) => {
const pathname = req.url?.match("^[^?]*")[0];
if (pathname.endsWith(".js") && shouldHandlePath(pathname, config.excludes, config.includes)) {
const pathWithFilePattern = pathname.replace(".js", config.filePattern);
let pathWithFilePattern = pathname.replace(".js", config.filePattern);
config.debug && log.verbose(`Lookup resource ${pathWithFilePattern}`);

// allow alias patterns to be used in the path which can be rewritten using the
// configuration option "aliasPatterns" (key: alias pattern, value: replacement)
if (config.aliasPatterns || options?.configuration?.aliasPatterns) {
Object.entries(config.aliasPatterns).forEach(([aliasPattern, replacement]) => {
const re = new RegExp(aliasPattern, "g");
if (re.test(pathWithFilePattern)) {
config.debug &&
log.verbose(` --> Replacing alias pattern ${aliasPattern} with ${replacement}`);
pathWithFilePattern = pathWithFilePattern.replace(re, replacement);
}
});
}

const matchedResources = await reader.byGlob(pathWithFilePattern);
config.debug && log.verbose(` --> Found ${matchedResources?.length || 0} match(es)!`);

Expand Down
1 change: 1 addition & 0 deletions packages/ui5-tooling-transpile/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ module.exports = function (log) {
includes,
excludes,
filePattern,
aliasPatterns: config.aliasPatterns,
omitTSFromBuildResult: config.omitTSFromBuildResult,
omitSourceMaps: config.omitSourceMaps,
generateTsInterfaces,
Expand Down
5 changes: 5 additions & 0 deletions showcases/ui5-tsapp/ui5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ customConfiguration:
config-ui5-tooling-transpile: &cfgTranspile
debug: true
filePattern: .+(ts|tsx)
aliasPatterns:
"^/__alias/([^.]+)\\.([^.]+)/(.*)$": "/resources/$1/$2/$3"
"^/__alias/([^.]+)\\.([^.]+)\\.([^.]+)/(.*)$": "/resources/$1/$2/$3/$4"
"^/__alias/([^.]+)\\.([^.]+)\\.([^.]+)\\.([^.]+)/(.*)$": "/resources/$1/$2/$3/$4/$5"
"^/__alias/([^.]+)\\.([^.]+)\\.([^.]+)\\.([^.]+)\\.([^.]+)/(.*)$": "/resources/$1/$2/$3/$4/$5/$6"
generateDts: true
omitTSFromBuildResult: true
config-ui5-tooling-modules: &cfgModules
Expand Down
Loading