Giter VIP home page Giter VIP logo

ui5-migration's Introduction

UI5 logo

ui5-migration

Tooling to support the migration of UI5 projects by adapting code for new UI5 framework versions.

REUSE status Build Status npm version

Note: This project is currently in beta. While there are ongoing improvements and round-offs being applied, we see the early release as a great opportunity to collect feedback from the community to further advance the UI5 migration tooling.

The UI5 migration tool is node.js-based and performs source code replacements and optimizations, reducing or getting rid of deprecated API. It builds upon a powerful parsing of JavaScript sources into an AST (abstract syntax tree) in order to perform the actual code replacements. Migration typically consists of an analysis part and a code modification part.

IMPORTANT: The modified source code needs to be manually reviewed and thoroughly tested. There is no 100% guarantee that the modified code works as expected.

For more details on how-to migrate your project's codebase, please consult additional information such as the migration guide

Installation

Requirements

  • Node.js (version 14 or higher ⚠️)

The migration tool is currently available for early usage. It can be installed with npm.

npm install --global @ui5/migration

Usage

CLI

To verify that the installation worked, run:

ui5-migration --help

Execute migration for the current folder:

ui5-migration migrate

Please see command-line interface for more details.

Available migration tasks

A list of currently available migration tasks can be found here

Formatting options

A list of options to configure the formatting of migration output can be found here

Contributing

Please check our Contribution Guidelines. Your input and support is welcome!

Support

Please follow our Contribution Guidelines on how to report an issue.

ui5-migration's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar devtomtom avatar ecker avatar matz3 avatar misappi avatar randombyte avatar sebastianwolf-sap avatar stopcoder avatar thodd avatar tobiasso85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ui5-migration's Issues

Can't install ui5-migrate

I tried to npm install ui5-migration --global, but npm reports:
npm ERR! code E404
npm ERR! 404 Not Found: ui5-migration@latest

Also npm install --global @ui5/migration responds with a:
npm ERR! code E404
npm ERR! 404 Not Found: @ui5/migration@latest

Target version 1.60.0 not found for api.json

Problem

the parameter target-version is used to download the api information for resolving globals, e.g. sap.m.Label therefore the API version must match the one available on the https://sapui5.hana.ondemand.com/

ui5-migration analyze --target-version="1.60.0"
ui5-migration analyze --target-version="1.60.22"

produces different output

because

https://sapui5.hana.ondemand.com/1.60.22/ --> works
https://sapui5.hana.ondemand.com/1.60.0/ --> 404 Not Found

Proposal

throw an error and display it in the console.

1.60.0 was not officially released

E.g. could use:
https://sapui5.hana.ondemand.com/versionoverview.json

'migrate' removes line break(s) at the end of a file

While working on SAP/openui5@c782ce9 , I encountered the following issue with the ui5-migration tooling:

In files that are not touched otherwise, line feeds at the end are removed. While this doesn'T cause build or runtime issues, it creates a lot of noise in changes and the only workaround seems to be to revert those changes manually, which is cumbersome.

To reproduce, you can execute the following commands

cd openui5
git checkout 6555a38
ui5-migration migrate src/sap.ui.core/src/sap/ui/dom/jquery

'migrate' tends to add a dependency to the module itself

While working on SAP/openui5@c782ce9 , I encountered the following issue with the ui5-migration tooling:

When the source of a module contains a global reference to the export of the same module, then the 'migrate' command adds a dependency to self and tries to use the resulting import whenever the export value is references. This happens in nearly each library.js module, but also in a few others.

Before

sap.ui.define([
	'sap/ui/core/library', // library dependency
	'sap/ui/commons/library'], // library dependency
	function() {
	...
	return sap.ui.ux3;

After (please also note that the 'library dependency' comments are also misplaced)

sap.ui.define([
	"sap/ui/ux3/library", // library dependency
	'sap/ui/core/library',
	'sap/ui/commons/library'], // library dependency
	function(ux3Library) {
	...
	return ux3Library;
});

To reproduce, you can execute the following commands

cd openui5
git checkout 6555a38
ui5-migration migrate src/sap.ui.ux3/src/sap/ui/ux3/library.js
ui5-migration migrate src/sap.ui.core/src/sap/ui/core/support/Support.js

'migrate' command adds duplicate parameters to sap.ui.define call

While working on SAP/openui5@c782ce9 , I encountered the following issue with the ui5-migration tooling:

In sap.m.Page, the tooling added a dependency to jQuery and to a jQuery UI plugin and gave both a local parameter name of jQuery. This resulted in an eslint error

Strict mode function may not have duplicate parameter names

Resulting code after migration

sap.ui.define([
    ...
    "./PageRenderer",
    "sap/ui/thirdparty/jquery",
    "sap/ui/thirdparty/jqueryui/jquery-ui-position"
],
function(
	...
	PageRenderer,
	jQuery,
	jQuery
) {
		"use strict";

To reproduce, you can execute the following commands

cd openui5
git checkout 6555a38
ui5-migration migrate src/sap.m/src/sap/m/Page.js
eslint -q src/sap.m/src/sap/m/Page.js

Newly added single line comment breaks syntax of sap.ui.define call

While working on SAP/openui5@c782ce9 , I encountered the following issue with the ui5-migration tooling:

A missing dependency to a jQuery plugin was added with an explaining comment, but the single line comment preceded the dependency and the closing bracket and comma, which broke the syntax of the source.

Before

sap.ui.define(["./library", 'sap/ui/core/Core', "...
..., "sap/ui/events/KeyCodes"],
	function(library, Core, Item, Icon, ...

After

sap.ui.define(["./library", 'sap/ui/core/Core', ...
..., "sap/ui/core/library",
    // jQuery Plugin "addAriaLabelledBy" "sap/ui/dom/jquery/Aria"],
	function(library, Core, Item, Icon, ...

To reproduce, you can execute the following commands

cd openui5
git checkout 6555a38
ui5-migration migrate src/sap.tnt/src/sap/tnt/NavigationListItem.js

fails silent behind firewall

running migrate behind a firewall "fails" e.g. reports no changes without any indication why.

ui5-migration migrate --exclude-path test/ --logLevel trace

Switching on logLevel trace shows this
image

Expected behaviour is to fail with "Failed to load library"

'migrate', tool uses an incorrect replacement for the UriParameter

The following replacement is done by the migration tool:
„jQuery.sap.getUriParameters().get("$direct")“ by “new UriParameters(window.location.href).get("$direct")”
But in the JSDoc of the UriParameter is described under "Future Migration", one should not use the constructor

Future Migration

* * Note: To simplify a future migration from this class to the standard URLSearchParams * API, consuming code should follow some recommendations: *
    *
  • **do not use the constructor,** either use {@link #.fromURL UriParameters.fromURL} when the input is a full URL, * or use {@link #.fromQuery UriParameters.fromQuery} when the input only contains the query part of an URL * (e.g. location.search).
  • *
  • do not use the get method with the second parameter bAll; use the getAll * method instead
  • *
  • do not access the internal property mParams (you never should access internal properties of * UI5 classes or objects). With the predecessor of this API, access to mParams was often used * to check whether a parameter is defined at all. Using the new has method or checking the * result of get against null serves the same purpose.
  • *

UI5 Migrate should return != 0, if files have been modified

This tool would be great to check UI5 apps in Github actions for none recommended code pattern.
The only thing missing, is a return code that lets a ci fail e.g. -1.

image

Workaround:

name: 'migration'
description: 'see https://www.npmjs.com/package/@ui5/migration'
runs:
  using: "composite"
  steps:
      - name: Install
        run: npm install --global @ui5/migration
        shell: bash
      # see https://github.com/SAP/ui5-migration/issues/209
      - name: run-migration 
        run: | 
          ui5-migration migrate
          echo 'delta<<EOF' >> $GITHUB_ENV
          git diff --color webapp/  >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV
        shell: bash
      - name: check
        run: echo "${{ env.delta }}"  && exit ${{ env.delta && 1 || 0 }}
        shell: bash

Tooling sometimes breaks the source formatting

While working on SAP/openui5@c782ce9 , I encountered the following issue with the ui5-migration tooling:

The migration tooling sometimes breaks the source formatting, especially the indent of closing brackets. This might be a follow-up issue of #29, but I think I encountered it more often than #29.

Before

					...
					if (selectedItem == subItem) {
						popupSelectedItem = popupSubItem;
					}
				}

			}

			var newGroup = new NavigationListItem({
				expanded: true,
			...

After (note the curly braces which have moved, as has the follow-up statement)

					...
					if (selectedItem == subItem) {
						popupSelectedItem = popupSubItem;
				}

			}

			

		}

		var newGroup = new NavigationListItem({
				expanded: true,
		...

To reproduce, you can execute the following commands

cd openui5
git checkout 6555a38
ui5-migration migrate src/sap.tnt/src/sap/tnt/NavigationListItem.js

Provide option to integrate with eslint

Integration with eslint is possible by using the CLIEngine of eslint.

E.g. by providing an output json which looks like the result expected by eslint and then using the eslint formatter to format the result.

See:

Since CLIEngine is deprecated:

jQuery.sap.extend() should be replaced or not?

Hi, we use SAPUI5 version 1.60.3 for our enterprise application. While moving to AMD-like syntax, we have currently replaced shallow and deep jQuery.sap.extend() with merge(), as Object.assign() resulted in errors as it did not copy prototype properties. The recent push to ui5-migration tool suggested we do not replace it at all. Whereas the page https://openui5.hana.ondemand.com/1.60.3//#/topic/a075ed88ef324261bca41813a6ac4a1c still suggests the otherwise. Could anyone just throw some light as to what needs to be done? Thanks!

Enhancement Request: Marker Comment to prevent Migration

In some special cases, the generic rules used by the migration tooling might not be suitable and a developer might decide to revert a migration step done by the tooling.

In that case, it would be helpful for a repeated usage of the tooling, if the corresponding code location could be marked as 'don't touch'. It might however be tricky to express what shouldn'T be touched

  • what exact part of the code shouldn't be touched (e.g. only part of a line or a range starting somewhere in one line and continuing to some other line)
  • what change should not be applied? How to prevent that new migration rules are also blocked by old comments

Logging improvements for CI-integration

Dear UI5 team,

As communicated before, this is the collection of logging improvements we'd need in order to use the ui5-migration tool inside our Git pre-commit hook and, later on, also in our CI infrastructure.

The current logging done by the tool is not concise enough and does not show exactly what is wrong where in what file.
As there are different tasks that can be executed using the tool, the ideal output for us would contain some information about the issue that was found and its position in the file, as well as log-level-appropriate output.
Currently, there are only minor up to no differences between the report levels:

  • WARNING
  • INFO
  • ERROR

It could look like the ESLint output, grouped by file name:

/absolute/path/to/some/js/file.js
    1:1  warning  Replace global call of "sap.ui.thirdparty.jquery" with "jQuery" (replaceGlobals)
  500:42 warning  Add dependency for "jQuery" (amdCleanup)

✖ 2 problems (0 error, 2 warnings)

As most of the developers are already familiar with this logging format, it would be great if you could adopt it. If you don't want to change it, it would also be feasible for us if there were a concept for pluggable Reporters where we could add a custom implementation for the reporting only.

Thank you for your help with this! 🙂

Best regards,
Dominic

Gruntfile.js needs to be ignored

running with ui5-migration migrate in a ui folder containing a Gruntfile.js causes issues since that is wrapped inside sap.ui

git diff
+++ b/ui-app/Gruntfile.js
@@ -1,3 +1,5 @@
+sap.ui.define([], function() {
+	  "use strict";
 	module.exports = function(grunt) {
 	  "use strict";
 	  grunt.initConfig({
@@ -21,3 +23,4 @@
 	    "build"
 	  ]);
 	};
+});
`
``

Migrate source tags in html files

Sometimes source code is within html files (e.g. index.html).

Currently ui5-migration ignores html files completely.

An idea would be to create a js file next to it, migrate it and load the script then from the index.html.

addMissingDependencies task duplicate variable name

During a replacement with addMissingDependencies and a config which contains newVariableName and newModulePath
there can be a nameclash which produces invalid code:

config.json:

"*.control": {
	"newModulePath": "sap/ui/core/Element",
	"newVariableName": "Element",
	"replacer": "Module",
	"finder": "NewExpressionFinder",
         "newExpressionCalleeName": "ReplaceMe"
	"extender": "AddImport"
}

source:

sap.ui.define(["sap/me/Element"],
	function(Element) {
		"use strict";
                Element.foo();
                var x = new ReplaceMe();
});

current behaviour:

sap.ui.define(["sap/me/Element", "sap/ui/core/Element"],
	function(Element, Element) {
		"use strict";
                Element.foo();
                var x = Element;
});

Here the Element variable is duplicated and this is invalid code.

target behaviour:

source:

sap.ui.define(["sap/me/Element", "sap/ui/core/Element"],
	function(Element, CoreElement) {
		"use strict";
                Element.foo();
                var x = CoreElement;
});

'migrate' sometimes adds a redundant dependency

While working on SAP/openui5@c782ce9 , I encountered the following issue with the ui5-migration tooling:

Sometimes, the cleanup of global names adds a dependency again although it exists already. This seems only to happen when the existing dependency uses a relative name (./library or ./Tokenizer).

Before:

sap.ui.define([
	...
	'./Tokenizer',
	...
],
function( ...

After:

sap.ui.define([
	...
	'./Tokenizer',
	...
	"sap/m/Tokenizer",
	...
],
function( ...

To reproduce, you can execute the following commands

cd openui5
git checkout 6555a38
ui5-migration migrate src/sap.m/src/sap/m/MultiComboBox.js

Provide machine-readable output for analysis

Current output:

$ ui5-migration analyze webapp
info cli Using ignore file: .gitignore
info cli Searching in folder 'webapp'
info cli Searching for files to migrate ...
info cli Migrating: 19 files:
info cli webapp\Component.js
info cli webapp\control\ChartControl.js
info cli webapp\control\ChartControlRenderer.js
info cli webapp\controller\App.controller.js
info cli webapp\control\MyControl.js
info cli webapp\controller\Details.controller.js
info cli webapp\control\MyControlRenderer.js
info cli webapp\controller\MyLegacy.controller.js
info cli webapp\test\integration\AllJourneys.js
info cli webapp\test\testsuite.qunit.js
info cli webapp\test\integration\FilterJourney.js
info cli webapp\test\integration\arrangements\Startup.js
info cli webapp\test\unit\AllTests.js
info cli webapp\test\integration\opaTests.qunit.js
info cli webapp\test\integration\SearchJourney.js
info cli webapp\test\unit\unitTests.qunit.js
info cli webapp\test\unit\controller\App.controller.js
info cli webapp\test\integration\pages\App.js
info cli webapp\test\integration\TodoListJourney.js
info cli Files: 19
info cli Tasks: amdCleanup, addMissingDependencies, addRenderers, fixTypeDependency, replaceGlobals, variableNamePrettifier
error addRenderers webapp\control\MyControl.js:1:0 detected missing dependency to Renderer module
warning addRenderers webapp\controller\MyLegacy.controller.js:1:1 could not find sap.ui.define call
warning fixTypeDependency webapp\controller\MyLegacy.controller.js:1:1 could not find sap.ui.define call
error amdCleanup webapp\test\unit\AllTests.js:1:1 Analysis failed. Error: Cannot read property 'type' of undefined
error addMissingDependencies webapp\test\unit\AllTests.js:1:1 Analysis failed. Error: Cannot read property 'type' of undefined
error addRenderers webapp\test\unit\AllTests.js:1:1 Analysis failed. Error: Cannot read property 'type' of undefined
error fixTypeDependency webapp\test\unit\AllTests.js:1:1 Analysis failed. Error: Cannot read property 'type' of undefined
error replaceGlobals webapp\test\unit\AllTests.js:1:1 Analysis failed. Error: Cannot read property 'type' of undefined
error variableNamePrettifier webapp\test\unit\AllTests.js:1:1 Analysis failed. Error: Cannot read property 'type' of undefined
error variableNamePrettifier webapp\test\unit\AllTests.js:1:1 Analysis failed. Error: Cannot read property 'type' of undefined
info cli Finished in 1s 945966200ms

Report for cli:
info files: 19
info files modified: 0

Report for amdCleanup:
info replacementsFound: 5
info amdStructureCreated: 1

Report for addMissingDependencies:
info replacementsFound: 1

Report for fixTypeDependency:
info Found missing module: 1
info Added library dependency: sap/ui/core/library: 1

Report for replaceGlobals:
info callsToReplace: 4

Report for variableNamePrettifier:
info replacementsFound: 0

A machine-readable output should contain:

  • file name (absolute)
  • finding location (line, column)

Source without statements loses all top-level comments during 'migrate'

While working on SAP/openui5@c782ce9 , I encountered the following issue with the ui5-migration tooling:

The file src/sap.m/src/sap/m/SelectionDetailsFacade.js which contains only JSDoc comments, was converted to sap.ui.define (not necessary) and all comments went lost.

After (this is the whole file)

sap.ui.define([], function() {
"use strict";
});

To reproduce, you can execute the following commands

cd openui5
git checkout 6555a38
ui5-migration migrate src/sap.m/src/sap/m/SelectionDetailsFacade.js 

Migration breaks code when during format of whitespaces for apply-amd-syntax task

Running task apply-amd-syntax causes the code to break then there is a comment between jQuery.sap.declare and jQuery.sap.require.
The code is broken afterwards

before:

jQuery.sap.require("sap.ui.core.UIComponent");
// my comment
jQuery.sap.declare("a.b.c.Component");

after:

// my commentsap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent) {
"use strict";
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.