ui5-tooling-transpile
Advanced tools
Comparing version 0.7.20 to 3.0.0
@@ -6,2 +6,24 @@ # Change Log | ||
# [3.0.0](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/ui5-tooling-transpile@0.7.20...ui5-tooling-transpile@3.0.0) (2023-07-31) | ||
### Bug Fixes | ||
* more cleanup of obsolete deps ([#779](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/779)) ([221a843](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/221a843ed1693f8db4233c5c6ea03ce368374046)) | ||
### Features | ||
* migration to UI5 Tooling V3 ([#776](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/776)) ([c03bc0e](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/c03bc0e8a8d0b55d38510164c885022e11b597e6)) | ||
* prepare versions for release for UI5 Tooling V3 ([#778](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/778)) ([5d2da55](https://github.com/ui5-community/ui5-ecosystem-showcase/commit/5d2da55e77513e026377aca799c413560c651f56)), closes [#770](https://github.com/ui5-community/ui5-ecosystem-showcase/issues/770) | ||
### BREAKING CHANGES | ||
* The support for UI5 Tooling V2 has been removed | ||
## [0.7.20](https://github.com/ui5-community/ui5-ecosystem-showcase/compare/ui5-tooling-transpile@0.7.19...ui5-tooling-transpile@0.7.20) (2023-07-17) | ||
@@ -8,0 +30,0 @@ |
/* eslint-disable jsdoc/check-param-names */ | ||
const log = require("@ui5/logger").getLogger("server:custommiddleware:ui5-tooling-transpile"); | ||
const parseurl = require("parseurl"); | ||
const { | ||
createConfiguration, | ||
createBabelConfig, | ||
normalizeLineFeeds, | ||
determineResourceFSPath, | ||
transformAsync, | ||
determineProjectBasePath, | ||
shouldHandlePath | ||
} = require("./util"); | ||
@@ -18,2 +8,3 @@ /** | ||
* @param {object} parameters Parameters | ||
* @param {module:@ui5/logger/Logger} parameters.log Logger instance | ||
* @param {object} parameters.resources Resource collections | ||
@@ -32,3 +23,13 @@ * @param {module:@ui5/fs.AbstractReader} parameters.resources.all Reader or Collection to read resources of the | ||
*/ | ||
module.exports = async function ({ resources, options, middlewareUtil }) { | ||
module.exports = async function ({ log, resources, options, middlewareUtil }) { | ||
const { | ||
createConfiguration, | ||
createBabelConfig, | ||
normalizeLineFeeds, | ||
determineResourceFSPath, | ||
transformAsync, | ||
determineProjectBasePath, | ||
shouldHandlePath | ||
} = require("./util")(log); | ||
const cwd = determineProjectBasePath(resources.rootProject) || process.cwd(); | ||
@@ -35,0 +36,0 @@ const config = createConfiguration(options?.configuration || {}, cwd); |
/* eslint-disable jsdoc/check-param-names */ | ||
const log = require("@ui5/logger").getLogger("builder:customtask:ui5-tooling-transpile"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const resourceFactory = require("@ui5/fs").resourceFactory; | ||
const { | ||
createConfiguration, | ||
createBabelConfig, | ||
normalizeLineFeeds, | ||
determineResourceFSPath, | ||
transformAsync, | ||
determineProjectBasePath | ||
} = require("./util"); | ||
@@ -19,2 +9,3 @@ /** | ||
* @param {object} parameters Parameters | ||
* @param {module:@ui5/logger/Logger} parameters.log Logger instance | ||
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files | ||
@@ -30,3 +21,12 @@ * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files | ||
*/ | ||
module.exports = async function ({ workspace /*, dependencies*/, taskUtil, options }) { | ||
module.exports = async function ({ log, workspace /*, dependencies*/, taskUtil, options }) { | ||
const { | ||
createConfiguration, | ||
createBabelConfig, | ||
normalizeLineFeeds, | ||
determineResourceFSPath, | ||
transformAsync, | ||
determineProjectBasePath | ||
} = require("./util")(log); | ||
const cwd = determineProjectBasePath(workspace) || process.cwd(); | ||
@@ -36,2 +36,4 @@ const config = createConfiguration(options?.configuration || {}, cwd); | ||
const { resourceFactory } = taskUtil; | ||
// TODO: should we accept the full glob pattern as param or just the file pattern? | ||
@@ -38,0 +40,0 @@ const allResources = await workspace.byGlob(`/**/*${config.filePattern}`); |
598
lib/util.js
@@ -1,3 +0,1 @@ | ||
const log = require("@ui5/logger").getLogger("builder:customtask:ui5-tooling-transpile"); | ||
const os = require("os"); | ||
@@ -69,333 +67,341 @@ const path = require("path"); | ||
const _this = (module.exports = { | ||
/** | ||
* Build the configuration for the task and the middleware. | ||
* | ||
* @param {object} configuration task/middleware configuration | ||
* @param {string} [cwd] the cwd to lookup the configuration (defaults to process.cwd()) | ||
* @returns {object} the translated task/middleware configuration | ||
*/ | ||
createConfiguration: function createConfiguration(configuration, cwd = process.cwd()) { | ||
// extract the configuration | ||
const config = configuration || {}; | ||
module.exports = function (log) { | ||
const _this = { | ||
/** | ||
* Build the configuration for the task and the middleware. | ||
* | ||
* @param {object} configuration task/middleware configuration | ||
* @param {string} [cwd] the cwd to lookup the configuration (defaults to process.cwd()) | ||
* @returns {object} the translated task/middleware configuration | ||
*/ | ||
createConfiguration: function createConfiguration(configuration, cwd = process.cwd()) { | ||
// extract the configuration | ||
const config = configuration || {}; | ||
// if a tsconfig.json file exists, the project is a TypeScript project | ||
const isTypeScriptProject = fs.existsSync(path.join(cwd, "tsconfig.json")); | ||
// if a tsconfig.json file exists, the project is a TypeScript project | ||
const isTypeScriptProject = fs.existsSync(path.join(cwd, "tsconfig.json")); | ||
// derive whether TypeScript should be transformed or not | ||
const transformTypeScript = config.transformTypeScript ?? config.transpileTypeScript ?? isTypeScriptProject; | ||
// derive whether TypeScript should be transformed or not | ||
const transformTypeScript = config.transformTypeScript ?? config.transpileTypeScript ?? isTypeScriptProject; | ||
// derive the includes/excludes from the configuration | ||
const includes = config.includes || config.includePatterns || []; | ||
const defaultExcludes = [".png", ".jpeg", ".jpg"]; // still needed? | ||
const excludes = defaultExcludes.concat(config.excludes || config.excludePatterns || []); | ||
// derive the includes/excludes from the configuration | ||
const includes = config.includes || config.includePatterns || []; | ||
const defaultExcludes = [".png", ".jpeg", ".jpg"]; // still needed? | ||
const excludes = defaultExcludes.concat(config.excludes || config.excludePatterns || []); | ||
// determine the file pattern from config or based on TypeScript project | ||
let filePattern = config.filePattern; // .+(ts|tsx) | ||
if (filePattern === undefined) { | ||
filePattern = transformTypeScript ? ".ts" : ".js"; | ||
} | ||
// determine the file pattern from config or based on TypeScript project | ||
let filePattern = config.filePattern; // .+(ts|tsx) | ||
if (filePattern === undefined) { | ||
filePattern = transformTypeScript ? ".ts" : ".js"; | ||
} | ||
// derive transformation parameters | ||
const transformModulesToUI5 = config.transformModulesToUI5 ?? !!transformTypeScript; | ||
const transformAsyncToPromise = config.transformAsyncToPromise ?? config.transpileAsync; | ||
// derive transformation parameters | ||
const transformModulesToUI5 = config.transformModulesToUI5 ?? !!transformTypeScript; | ||
const transformAsyncToPromise = config.transformAsyncToPromise ?? config.transpileAsync; | ||
// return the normalized configuration object | ||
const normalizedConfiguration = { | ||
debug: config.debug, | ||
babelConfig: config.babelConfig, | ||
includes, | ||
excludes, | ||
filePattern, | ||
omitTSFromBuildResult: config.omitTSFromBuildResult, | ||
generateDts: config.generateDts, | ||
transpileDependencies: config.transpileDependencies, | ||
transformAtStartup: config.transformAtStartup, | ||
transformTypeScript, | ||
transformModulesToUI5, | ||
transformAsyncToPromise, | ||
targetBrowsers: config.targetBrowsers, | ||
removeConsoleStatements: config.removeConsoleStatements | ||
}; | ||
config.debug && log.verbose(`Normalized configuration:\n${JSON.stringify(normalizedConfiguration, null, 2)}`); | ||
return normalizedConfiguration; | ||
}, | ||
// return the normalized configuration object | ||
const normalizedConfiguration = { | ||
debug: config.debug, | ||
babelConfig: config.babelConfig, | ||
includes, | ||
excludes, | ||
filePattern, | ||
omitTSFromBuildResult: config.omitTSFromBuildResult, | ||
generateDts: config.generateDts, | ||
transpileDependencies: config.transpileDependencies, | ||
transformAtStartup: config.transformAtStartup, | ||
transformTypeScript, | ||
transformModulesToUI5, | ||
transformAsyncToPromise, | ||
targetBrowsers: config.targetBrowsers, | ||
removeConsoleStatements: config.removeConsoleStatements | ||
}; | ||
config.debug && | ||
log.verbose(`Normalized configuration:\n${JSON.stringify(normalizedConfiguration, null, 2)}`); | ||
return normalizedConfiguration; | ||
}, | ||
/** | ||
* Lookup the Babel configuration from ui5.yaml, Babel configuration files in file system, | ||
* generated Babel configuration from configuration options or fallback to default | ||
* configuration. | ||
* | ||
* @param {object} cfg configuration object | ||
* @param {object} cfg.configuration task/middleware configuration | ||
* @param {boolean} cfg.isMiddleware true, if the function is called from the middleware | ||
* @param {string} [cwd] the cwd to lookup the configuration (defaults to process.cwd()) | ||
* @returns {object} the babel plugins configuration | ||
*/ | ||
createBabelConfig: async function createBabelConfig({ configuration, isMiddleware }, cwd = process.cwd()) { | ||
// Things to consider: | ||
// - middleware uses configs from app also for dependencies | ||
// - task must provide the cwd from outside | ||
/** | ||
* Lookup the Babel configuration from ui5.yaml, Babel configuration files in file system, | ||
* generated Babel configuration from configuration options or fallback to default | ||
* configuration. | ||
* | ||
* @param {object} cfg configuration object | ||
* @param {object} cfg.configuration task/middleware configuration | ||
* @param {boolean} cfg.isMiddleware true, if the function is called from the middleware | ||
* @param {string} [cwd] the cwd to lookup the configuration (defaults to process.cwd()) | ||
* @returns {object} the babel plugins configuration | ||
*/ | ||
createBabelConfig: async function createBabelConfig({ configuration, isMiddleware }, cwd = process.cwd()) { | ||
// Things to consider: | ||
// - middleware uses configs from app also for dependencies | ||
// - task must provide the cwd from outside | ||
// report usage of configuration options in case ofan external | ||
// configuration file or inline Babel config is used | ||
const warnAboutIgnoredConfig = function () { | ||
["transpileAsync", "transformModulesToUI5", "transformAsyncToPromise", "removeConsoleStatements"].forEach( | ||
(config) => { | ||
// report usage of configuration options in case ofan external | ||
// configuration file or inline Babel config is used | ||
const warnAboutIgnoredConfig = function () { | ||
[ | ||
"transpileAsync", | ||
"transformModulesToUI5", | ||
"transformAsyncToPromise", | ||
"removeConsoleStatements" | ||
].forEach((config) => { | ||
if (configuration?.[config] !== undefined) { | ||
log.warn(`Ignoring configuration option "${config}" due to external configuration!`); | ||
} | ||
}); | ||
}; | ||
// utility to add source maps support for middleware usage | ||
const enhanceForSourceMaps = function (babelConfig) { | ||
if (isMiddleware) { | ||
babelConfig.sourceMaps = "inline"; | ||
} | ||
); | ||
}; | ||
return babelConfig; | ||
}; | ||
// utility to add source maps support for middleware usage | ||
const enhanceForSourceMaps = function (babelConfig) { | ||
if (isMiddleware) { | ||
babelConfig.sourceMaps = "inline"; | ||
// the inline babel configuration in the ui5.yaml wins | ||
let babelConfig = configuration?.babelConfig; | ||
if (babelConfig) { | ||
if (configuration?.debug) { | ||
log.info(`Using inline Babel configuration from ui5.yaml...`); | ||
warnAboutIgnoredConfig(); | ||
log.verbose(`${JSON.stringify(babelConfig, null, 2)}`); | ||
} | ||
return enhanceForSourceMaps(babelConfig); | ||
} | ||
return babelConfig; | ||
}; | ||
// the inline babel configuration in the ui5.yaml wins | ||
let babelConfig = configuration?.babelConfig; | ||
if (babelConfig) { | ||
if (configuration?.debug) { | ||
log.info(`Using inline Babel configuration from ui5.yaml...`); | ||
warnAboutIgnoredConfig(); | ||
log.verbose(`${JSON.stringify(babelConfig, null, 2)}`); | ||
// lookup the babel config by file | ||
const config = await findBabelConfig(cwd); | ||
if (config) { | ||
if (configuration?.debug) { | ||
log.info(`Using Babel configuration from ${config.configFile}...`); | ||
warnAboutIgnoredConfig(); | ||
log.verbose(`${JSON.stringify(config.options, null, 2)}`); | ||
} | ||
return enhanceForSourceMaps(config.options); | ||
} | ||
return enhanceForSourceMaps(babelConfig); | ||
} | ||
// lookup the babel config by file | ||
const config = await findBabelConfig(cwd); | ||
if (config) { | ||
if (configuration?.debug) { | ||
log.info(`Using Babel configuration from ${config.configFile}...`); | ||
warnAboutIgnoredConfig(); | ||
log.verbose(`${JSON.stringify(config.options, null, 2)}`); | ||
} | ||
return enhanceForSourceMaps(config.options); | ||
} | ||
// create configuration based on ui5.yaml configuration options | ||
configuration?.debug && log.info(`Create Babel configuration based on ui5.yaml configuration options...`); | ||
// create configuration based on ui5.yaml configuration options | ||
configuration?.debug && log.info(`Create Babel configuration based on ui5.yaml configuration options...`); | ||
// create the babel configuration based on the ui5.yaml | ||
babelConfig = { ignore: ["**/*.d.ts"], plugins: [], presets: [] }; | ||
// create the babel configuration based on the ui5.yaml | ||
babelConfig = { ignore: ["**/*.d.ts"], plugins: [], presets: [] }; | ||
// order of the presets is important: last preset is applied first | ||
// which means the .babelrc config should look like that: | ||
// | ||
// "presets": [ | ||
// "@babel/preset-env", // applied 3rd | ||
// "transform-ui5", // applied 2nd | ||
// "@babel/preset-typescript" // applied 1st | ||
// ], | ||
// | ||
// so, first transpile typescript, then ES modules/classes to UI5 | ||
// and finally transpile the rest to the target browser env. | ||
// order of the presets is important: last preset is applied first | ||
// which means the .babelrc config should look like that: | ||
// | ||
// "presets": [ | ||
// "@babel/preset-env", // applied 3rd | ||
// "transform-ui5", // applied 2nd | ||
// "@babel/preset-typescript" // applied 1st | ||
// ], | ||
// | ||
// so, first transpile typescript, then ES modules/classes to UI5 | ||
// and finally transpile the rest to the target browser env. | ||
// add the env preset and configure to support the | ||
// last 2 browser versions (can be overruled via | ||
// configuration option defined in the ui5.yaml | ||
// using https://github.com/browserslist/browserslist) | ||
let browserListConfigFile; | ||
try { | ||
browserListConfigFile = browserslist.findConfig(cwd); | ||
} catch (ex) { | ||
configuration?.debug && log.info(`Unable to find browserslist configuration. Fallback to default...`); | ||
} | ||
const envPreset = ["@babel/preset-env"]; | ||
if (browserListConfigFile) { | ||
configuration?.debug && log.info(`Using external browserslist configuration...`); | ||
} else { | ||
configuration?.debug && log.info(`Using browserslist configuration from ui5.yaml...`); | ||
envPreset.push({ | ||
targets: { | ||
// future: consider to read the browserslist config from OpenUI5/SAPUI5? | ||
// env variables must not use "-" or "." and therefore we use "_" only | ||
browsers: | ||
process.env?.["ui5_tooling_transpile__targetBrowsers"] || | ||
configuration?.targetBrowsers || | ||
"defaults" | ||
} | ||
}); | ||
} | ||
babelConfig.presets.push(envPreset); | ||
// add the env preset and configure to support the | ||
// last 2 browser versions (can be overruled via | ||
// configuration option defined in the ui5.yaml | ||
// using https://github.com/browserslist/browserslist) | ||
let browserListConfigFile; | ||
try { | ||
browserListConfigFile = browserslist.findConfig(cwd); | ||
} catch (ex) { | ||
configuration?.debug && log.info(`Unable to find browserslist configuration. Fallback to default...`); | ||
} | ||
const envPreset = ["@babel/preset-env"]; | ||
if (browserListConfigFile) { | ||
configuration?.debug && log.info(`Using external browserslist configuration...`); | ||
} else { | ||
configuration?.debug && log.info(`Using browserslist configuration from ui5.yaml...`); | ||
envPreset.push({ | ||
targets: { | ||
// future: consider to read the browserslist config from OpenUI5/SAPUI5? | ||
// env variables must not use "-" or "." and therefore we use "_" only | ||
browsers: | ||
process.env?.["ui5_tooling_transpile__targetBrowsers"] || | ||
configuration?.targetBrowsers || | ||
"defaults" | ||
// add the presets to enable transformation of ES modules to | ||
// UI5 modules and ES classes to UI5 classes | ||
if (configuration?.transformModulesToUI5) { | ||
// if the configuration option transformModulesToUI5 is an object | ||
// it contains the configuration options for the plugin | ||
if (typeof configuration.transformModulesToUI5 === "object") { | ||
babelConfig.presets.push(["transform-ui5", configuration.transformModulesToUI5]); | ||
} else { | ||
babelConfig.presets.push("transform-ui5"); | ||
} | ||
}); | ||
} | ||
babelConfig.presets.push(envPreset); | ||
} | ||
// add the presets to enable transformation of ES modules to | ||
// UI5 modules and ES classes to UI5 classes | ||
if (configuration?.transformModulesToUI5) { | ||
// if the configuration option transformModulesToUI5 is an object | ||
// it contains the configuration options for the plugin | ||
if (typeof configuration.transformModulesToUI5 === "object") { | ||
babelConfig.presets.push(["transform-ui5", configuration.transformModulesToUI5]); | ||
} else { | ||
babelConfig.presets.push("transform-ui5"); | ||
// add the preset to enable the transpiling of TS to JS | ||
if (configuration?.transformTypeScript) { | ||
// if the configuration option transformTypeScript is an object | ||
// it contains the configuration options for the plugin | ||
if (typeof configuration.transformTypeScript === "object") { | ||
babelConfig.presets.push(["@babel/preset-typescript", configuration.transformTypeScript]); | ||
} else { | ||
babelConfig.presets.push("@babel/preset-typescript"); | ||
} | ||
} | ||
} | ||
// add the preset to enable the transpiling of TS to JS | ||
if (configuration?.transformTypeScript) { | ||
// if the configuration option transformTypeScript is an object | ||
// it contains the configuration options for the plugin | ||
if (typeof configuration.transformTypeScript === "object") { | ||
babelConfig.presets.push(["@babel/preset-typescript", configuration.transformTypeScript]); | ||
} else { | ||
babelConfig.presets.push("@babel/preset-typescript"); | ||
// add plugin to remove console statements | ||
if (configuration?.removeConsoleStatements) { | ||
babelConfig.plugins.push("transform-remove-console"); | ||
} | ||
} | ||
// add plugin to remove console statements | ||
if (configuration?.removeConsoleStatements) { | ||
babelConfig.plugins.push("transform-remove-console"); | ||
} | ||
// add plugin to transform async statements to promises | ||
// by default Babel uses the regenerator runtime but this | ||
// requires bigger redundant inline code and it is also | ||
// not CSP compliant => therefore the Promise is the better | ||
// solution than using the regenerator runtime (by default) | ||
if (configuration?.transformAsyncToPromise) { | ||
babelConfig.plugins.push([ | ||
"transform-async-to-promises", | ||
{ | ||
inlineHelpers: true | ||
} | ||
]); | ||
} else if (configuration?.targetBrowsers === undefined) { | ||
log.warn( | ||
"Babel uses regenerator runtime to transpile async/await for older target browsers. As this is not CSP compliant consider the usage of transformAsyncToPromise to convert async/await to Promises!" | ||
); | ||
} | ||
// add plugin to transform async statements to promises | ||
// by default Babel uses the regenerator runtime but this | ||
// requires bigger redundant inline code and it is also | ||
// not CSP compliant => therefore the Promise is the better | ||
// solution than using the regenerator runtime (by default) | ||
if (configuration?.transformAsyncToPromise) { | ||
babelConfig.plugins.push([ | ||
"transform-async-to-promises", | ||
{ | ||
inlineHelpers: true | ||
} | ||
]); | ||
} else if (configuration?.targetBrowsers === undefined) { | ||
log.warn( | ||
"Babel uses regenerator runtime to transpile async/await for older target browsers. As this is not CSP compliant consider the usage of transformAsyncToPromise to convert async/await to Promises!" | ||
); | ||
} | ||
// in the middleware case we generate the sourcemaps inline for | ||
// debugging purposes since the middleware may not know about the | ||
// sourcemaps files next to the source file | ||
if (isMiddleware) { | ||
babelConfig.sourceMaps = "inline"; | ||
} else { | ||
babelConfig.sourceMaps = true; | ||
} | ||
// in the middleware case we generate the sourcemaps inline for | ||
// debugging purposes since the middleware may not know about the | ||
// sourcemaps files next to the source file | ||
if (isMiddleware) { | ||
babelConfig.sourceMaps = "inline"; | ||
} else { | ||
babelConfig.sourceMaps = true; | ||
} | ||
configuration?.debug && log.verbose(`${JSON.stringify(babelConfig, null, 2)}`); | ||
configuration?.debug && log.verbose(`${JSON.stringify(babelConfig, null, 2)}`); | ||
return babelConfig; | ||
}, | ||
return babelConfig; | ||
}, | ||
/** | ||
* Normalizes the line feeds of the code to OS default | ||
* | ||
* @param {string} code the code | ||
* @returns {string} the normalized code | ||
*/ | ||
normalizeLineFeeds: function normalizeLineFeeds(code) { | ||
// since Babel does not care about linefeeds, see here: | ||
// https://github.com/babel/babel/issues/8921#issuecomment-492429934 | ||
// we have to search for any EOL character and replace it | ||
// with correct EOL for this OS | ||
return code.replace(/\r\n|\r|\n/g, os.EOL); | ||
}, | ||
/** | ||
* Normalizes the line feeds of the code to OS default | ||
* | ||
* @param {string} code the code | ||
* @returns {string} the normalized code | ||
*/ | ||
normalizeLineFeeds: function normalizeLineFeeds(code) { | ||
// since Babel does not care about linefeeds, see here: | ||
// https://github.com/babel/babel/issues/8921#issuecomment-492429934 | ||
// we have to search for any EOL character and replace it | ||
// with correct EOL for this OS | ||
return code.replace(/\r\n|\r|\n/g, os.EOL); | ||
}, | ||
/** | ||
* Checks whether the given path name should be handled | ||
* | ||
* @param {string} pathname the path name | ||
* @param {Array<string>} excludes exclude paths | ||
* @param {Array<string>} includes include paths | ||
* @returns true, if the path should be handled | ||
*/ | ||
shouldHandlePath: function shouldHandlePath(pathname, excludes = [], includes = []) { | ||
return ( | ||
!(excludes || []).some((pattern) => pathname.includes(pattern)) || | ||
(includes || []).some((pattern) => pathname.includes(pattern)) | ||
); | ||
}, | ||
/** | ||
* Checks whether the given path name should be handled | ||
* | ||
* @param {string} pathname the path name | ||
* @param {Array<string>} excludes exclude paths | ||
* @param {Array<string>} includes include paths | ||
* @returns true, if the path should be handled | ||
*/ | ||
shouldHandlePath: function shouldHandlePath(pathname, excludes = [], includes = []) { | ||
return ( | ||
!(excludes || []).some((pattern) => pathname.includes(pattern)) || | ||
(includes || []).some((pattern) => pathname.includes(pattern)) | ||
); | ||
}, | ||
/** | ||
* Determines the applications base path from the given resource collection. | ||
* | ||
* <b>ATTENTION: this is a hack to be compatible with UI5 tooling 2.x and 3.x</b> | ||
* | ||
* @param {module:@ui5/fs.AbstractReader} collection Reader or Collection to read resources of the root project and its dependencies | ||
* @returns {string} application base path | ||
*/ | ||
determineProjectBasePath: function (collection) { | ||
let projectBasePath; | ||
if (collection?._readers) { | ||
for (const _reader of collection._readers) { | ||
projectBasePath = _this.determineProjectBasePath(_reader); | ||
if (projectBasePath) break; | ||
/** | ||
* Determines the applications base path from the given resource collection. | ||
* | ||
* <b>ATTENTION: this is a hack to be compatible with UI5 tooling 2.x and 3.x</b> | ||
* | ||
* @param {module:@ui5/fs.AbstractReader} collection Reader or Collection to read resources of the root project and its dependencies | ||
* @returns {string} application base path | ||
*/ | ||
determineProjectBasePath: function (collection) { | ||
let projectBasePath; | ||
if (collection?._readers) { | ||
for (const _reader of collection._readers) { | ||
projectBasePath = _this.determineProjectBasePath(_reader); | ||
if (projectBasePath) break; | ||
} | ||
} | ||
} | ||
if (/^(application|library)$/.test(collection?._project?._type)) { | ||
projectBasePath = collection._project._modulePath; // UI5 tooling 3.x | ||
} else if (/^(application|library)$/.test(collection?._project?.type)) { | ||
projectBasePath = collection._project.path; // UI5 tooling 2.x | ||
} else if (typeof collection?._fsBasePath === "string") { | ||
projectBasePath = collection._fsBasePath; | ||
} | ||
return projectBasePath; | ||
}, | ||
if (/^(application|library)$/.test(collection?._project?._type)) { | ||
projectBasePath = collection._project._modulePath; // UI5 tooling 3.x | ||
} else if (/^(application|library)$/.test(collection?._project?.type)) { | ||
projectBasePath = collection._project.path; // UI5 tooling 2.x | ||
} else if (typeof collection?._fsBasePath === "string") { | ||
projectBasePath = collection._fsBasePath; | ||
} | ||
return projectBasePath; | ||
}, | ||
/** | ||
* Determine the given resources' file system path | ||
* | ||
* <b>ATTENTION: this is a hack to be compatible with UI5 tooling 2.x and 3.x</b> | ||
* | ||
* @param {module:@ui5/fs.Resource} resource the resource | ||
* @param {string} [cwd] the cwd to lookup the configuration (defaults to process.cwd()) | ||
* @returns {string} the file system path | ||
*/ | ||
determineResourceFSPath: function determineResourceFSPath(resource, cwd = process.cwd()) { | ||
let resourcePath = resource.getPath(); | ||
if (typeof resource.getSourceMetadata === "function") { | ||
// specVersion 3.0 provides source metadata and only if the | ||
// current work directory is the rootpath of the project resource | ||
// it is a root resource which should be considered to be resolved | ||
if (path.relative(cwd, resource.getProject().getRootPath()) === "") { | ||
resourcePath = resource.getSourceMetadata().fsPath || resourcePath; | ||
/** | ||
* Determine the given resources' file system path | ||
* | ||
* <b>ATTENTION: this is a hack to be compatible with UI5 tooling 2.x and 3.x</b> | ||
* | ||
* @param {module:@ui5/fs.Resource} resource the resource | ||
* @param {string} [cwd] the cwd to lookup the configuration (defaults to process.cwd()) | ||
* @returns {string} the file system path | ||
*/ | ||
determineResourceFSPath: function determineResourceFSPath(resource, cwd = process.cwd()) { | ||
let resourcePath = resource.getPath(); | ||
if (typeof resource.getSourceMetadata === "function") { | ||
// specVersion 3.0 provides source metadata and only if the | ||
// current work directory is the rootpath of the project resource | ||
// it is a root resource which should be considered to be resolved | ||
if (path.relative(cwd, resource.getProject().getRootPath()) === "") { | ||
// npm dependencies don't have sourceMetadata applied to resource! | ||
resourcePath = resource.getSourceMetadata()?.fsPath || resourcePath; | ||
} | ||
} else { | ||
// for older versions resolving the file system path is a bit more | ||
// tricky and also here we only consider the root resources rather | ||
// than the dependencies... | ||
const isRootResource = resource?._project?._isRoot; | ||
if (isRootResource) { | ||
const rootPath = resource._project.path; | ||
const pathMappings = resource._project.resources?.pathMappings; | ||
const pathMapping = Object.keys(pathMappings).find((basePath) => resourcePath.startsWith(basePath)); | ||
resourcePath = path.join( | ||
rootPath, | ||
pathMappings[pathMapping], | ||
resourcePath.substring(pathMapping.length) | ||
); | ||
} | ||
} | ||
} else { | ||
// for older versions resolving the file system path is a bit more | ||
// tricky and also here we only consider the root resources rather | ||
// than the dependencies... | ||
const isRootResource = resource?._project?._isRoot; | ||
if (isRootResource) { | ||
const rootPath = resource._project.path; | ||
const pathMappings = resource._project.resources?.pathMappings; | ||
const pathMapping = Object.keys(pathMappings).find((basePath) => resourcePath.startsWith(basePath)); | ||
resourcePath = path.join( | ||
rootPath, | ||
pathMappings[pathMapping], | ||
resourcePath.substring(pathMapping.length) | ||
); | ||
} | ||
} | ||
return resourcePath; | ||
}, | ||
return resourcePath; | ||
}, | ||
/** | ||
* Transforms code synchronously using Babel | ||
* | ||
* @param {string} code code to transform | ||
* @param {object} opts options | ||
* @returns {string} transformed code | ||
*/ | ||
transform: function transform(code, opts) { | ||
return babel.transform(code, opts); | ||
}, | ||
/** | ||
* Transforms code synchronously using Babel | ||
* | ||
* @param {string} code code to transform | ||
* @param {object} opts options | ||
* @returns {string} transformed code | ||
*/ | ||
transform: function transform(code, opts) { | ||
return babel.transform(code, opts); | ||
}, | ||
/** | ||
* Transforms code asynchronously using Babel | ||
* | ||
* @param {string} code code to transform | ||
* @param {object} opts options | ||
* @returns {string} transformed code | ||
*/ | ||
transformAsync: async function transformAsync(code, opts) { | ||
return babel.transformAsync(code, opts); | ||
} | ||
}); | ||
/** | ||
* Transforms code asynchronously using Babel | ||
* | ||
* @param {string} code code to transform | ||
* @param {object} opts options | ||
* @returns {string} transformed code | ||
*/ | ||
transformAsync: async function transformAsync(code, opts) { | ||
return babel.transformAsync(code, opts); | ||
} | ||
}; | ||
return _this; | ||
}; |
{ | ||
"name": "ui5-tooling-transpile", | ||
"version": "0.7.20", | ||
"version": "3.0.0", | ||
"description": "UI5 tooling extensions to transpile code", | ||
@@ -13,10 +13,8 @@ "author": "Jorge Martins, Peter Muessig", | ||
"dependencies": { | ||
"@babel/core": "^7.22.5", | ||
"@babel/preset-env": "^7.22.5", | ||
"@babel/core": "^7.22.9", | ||
"@babel/preset-env": "^7.22.9", | ||
"@babel/preset-typescript": "^7.22.5", | ||
"@ui5/fs": "^2.0.6", | ||
"@ui5/logger": "^2.0.1", | ||
"babel-plugin-transform-async-to-promises": "^0.8.18", | ||
"babel-plugin-transform-remove-console": "^6.9.4", | ||
"babel-preset-transform-ui5": "^7.2.1", | ||
"babel-preset-transform-ui5": "^7.2.4", | ||
"browserslist": "^4.21.9", | ||
@@ -40,6 +38,3 @@ "parseurl": "^1.3.3" | ||
}, | ||
"ui5": { | ||
"dependencies": [] | ||
}, | ||
"gitHead": "c74a5e0028b01b10477c25ef25ec040e0ddfa280" | ||
"gitHead": "c6e94b130e72603fc05d70bcaf982bd681b72604" | ||
} |
# UI5 Tooling Extension for Transpiling JS/TS | ||
> **DISCLAIMER**: This is a community project and there is no official support for this package! Also the functionality may stop working at any time in future with newer versions of the UI5 tooling! | ||
> :wave: This is a **community project** and there is no official support for this package! Feel free to use it, open issues, contribute, and help answering questions. | ||
@@ -11,2 +11,9 @@ The tooling extension provides a middleware and a task which transpiles JavaScript or TypeScript code to ES5 by using Babel. A default Babel configuration will be provided by the tooling extension unless a inline Babel configuration in the `ui5.yaml` or any Babel configuration as described at [Babel config files](https://babeljs.io/docs/en/config-files) will be provided. | ||
## Prerequisites | ||
- Requires at least [`@ui5/cli@3.0.0`](https://sap.github.io/ui5-tooling/v3/pages/CLI/) (to support [`specVersion: "3.0"`](https://sap.github.io/ui5-tooling/pages/Configuration/#specification-version-30)) | ||
> :warning: **UI5 Tooling Compatibility** | ||
> All releases of this tooling extension using the major version `3` require UI5 Tooling V3. Any previous releases below major version `3` (if available) also support older versions of the UI5 Tooling. But the usage of the latest UI5 Tooling is strongly recommended! | ||
## Install | ||
@@ -80,16 +87,5 @@ | ||
// ... | ||
}, | ||
"ui5": { | ||
"dependencies": [ | ||
// ... | ||
"ui5-tooling-transpile", | ||
// ... | ||
] | ||
} | ||
``` | ||
> :warning: As the devDependencies are not recognized by the UI5 tooling, they need to be listed in the `ui5 > dependencies` array. In addition, once using the `ui5 > dependencies` array you need to list all UI5 tooling relevant dependencies. | ||
> | ||
> :speech_balloon: For UI5 Tooling 3.0 the `ui5 > dependencies` section in the `package.json` isn't necessary anymore and can be removed. | ||
Register the task and middleware in your `$yourapp/ui5.yaml`: | ||
@@ -96,0 +92,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
78751
8
802
1
172
- Removed@ui5/fs@^2.0.6
- Removed@ui5/logger@^2.0.1
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@ui5/fs@2.0.6(transitive)
- Removed@ui5/logger@2.0.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedaproba@1.2.0(transitive)
- Removedare-we-there-yet@1.1.7(transitive)
- Removedarray-union@2.1.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbraces@3.0.3(transitive)
- Removedclone@2.1.2(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddelegates@1.0.0(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedgauge@2.7.4(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedglobby@11.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedignore@5.3.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedminimatch@3.1.2(transitive)
- Removednpmlog@4.1.2(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedpretty-hrtime@1.0.3(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedrandom-int@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedslash@3.0.0(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwide-align@1.1.5(transitive)
Updated@babel/core@^7.22.9
Updated@babel/preset-env@^7.22.9