Skip to content
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

[FEATURE] Add 'UI5 Workspace' Support #494

Merged
merged 26 commits into from Feb 2, 2023

Conversation

RandomByte
Copy link
Member

@RandomByte RandomByte commented Nov 4, 2022

Implementing SAP/ui5-tooling#157

CPOUI5FOUNDATION-582

@RandomByte RandomByte force-pushed the local-dependency-resolution-poc branch from 615a153 to 1504c7a Compare November 4, 2022 16:01
@RandomByte RandomByte changed the base branch from main to snapshot-poc November 4, 2022 17:55
@RandomByte RandomByte force-pushed the local-dependency-resolution-poc branch 2 times, most recently from a8d63dd to 6f14964 Compare November 9, 2022 14:41
@RandomByte RandomByte changed the base branch from snapshot-poc to main November 9, 2022 14:41
@RandomByte RandomByte changed the title [FEATURE][PoC] Enable snapshot consumption from Maven repository [FEATURE][PoC] Add 'UI5 Workspace' Support Nov 9, 2022
@RandomByte RandomByte force-pushed the local-dependency-resolution-poc branch from 6f14964 to b811811 Compare November 15, 2022 23:14
@coveralls
Copy link

coveralls commented Nov 16, 2022

Coverage Status

Coverage: 95.41% (+0.6%) from 94.86% when pulling a807d70 on local-dependency-resolution-poc into f90d17a on main.

@RandomByte RandomByte force-pushed the local-dependency-resolution-poc branch 2 times, most recently from a566ebd to 73f016f Compare November 17, 2022 00:01
@RandomByte RandomByte force-pushed the local-dependency-resolution-poc branch from 73f016f to 7847b89 Compare December 8, 2022 19:45
@RandomByte RandomByte force-pushed the local-dependency-resolution-poc branch from 7847b89 to 0ba89b7 Compare January 18, 2023 18:15
@RandomByte RandomByte force-pushed the local-dependency-resolution-poc branch 4 times, most recently from 6663b14 to a8d996f Compare January 25, 2023 15:46
@RandomByte RandomByte changed the title [FEATURE][PoC] Add 'UI5 Workspace' Support [FEATURE] Add 'UI5 Workspace' Support Jan 27, 2023
Pass it to NodePackageDependencies-Provider and ui5FrameworkHelper
…of module ID

This should make the use of workspaces easier. Framework projects are
matched based on the name in the ui5.yaml instead of the package.json
name (= module ID). This allows for example framework projects to be
contained in packages that are named differently from the local copy.
E.g. "@openui5/sap.m-prebuilt" while the local copy does not have the
"-prebuilt" suffix.

Note however, that the NodePackageDependencies-provider still matches
nodes using the module ID.

The basic reason for this difference is that framework dependencies are
typically declared using the project name, while npm dependencies are
declared using the module ID.

However, we could also enhance projectGraphBuilder in the future to
additionally check whether a project can be resolved with a workspace
once the project has been created and its name is known. This could
catch those cases where the node provider could not find a workspace
resolution for a given module ID.
This means resolution paths will always be resolved relative to the
workspace config file location instead of the process CWD.

Refactored some graph code to make creating workspaces reusable for
other graph factory functions in the future. Extended related tests.
If no project is found, return null instead of undefined
While we don't expect this to happen in released UI5 versions, it might
happen with development setups using UI5 Workspaces
@RandomByte RandomByte force-pushed the local-dependency-resolution-poc branch from feb2b82 to 8a5c1b8 Compare January 30, 2023 16:25
@RandomByte RandomByte marked this pull request as ready for review January 30, 2023 16:30
@RandomByte RandomByte requested a review from a team January 30, 2023 16:30
Copy link
Member

@flovogt flovogt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @RandomByte. Well done!

lib/graph/ProjectGraph.js Outdated Show resolved Hide resolved
lib/graph/ProjectGraph.js Show resolved Hide resolved
lib/graph/Workspace.js Show resolved Hide resolved
lib/graph/Workspace.js Show resolved Hide resolved

/**
* @param {object} options
* @param {object} options.cwd Path to use for resolving all paths of the workspace configuration from.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cwd is of type string, isn't?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

test/lib/graph/graph.js Show resolved Hide resolved
test/lib/graph/helpers/createWorkspace.js Outdated Show resolved Hide resolved
test/lib/graph/helpers/createWorkspace.js Show resolved Hide resolved
});

test.afterEach.always((t) => {
t.context.sinon.restore();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing esmock.purge(t.context.createWorkspace)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read https://github.com/iambumblehead/esmock/wiki#calling-esmock-await-import and came to think that this might not be necessary in this case.

esmock creates a new mock for every test in parallel. Cleaning up after each test to free memory (or for any other reason) seems unnecessary since ava executes this file in a separate process which it will kill after all tests are done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we had to do it when await import is used.... Interesting

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because await import requires the delayed esmock.p API which might interfere with other tests and therefore would require all tests to use .serial().

As it turns out, we don't use await import for "Workspace.js" anymore (this was used in an earlier version of this PR) and esmock is enough 👍

test/lib/graph/helpers/createWorkspace.js Show resolved Hide resolved
RandomByte and others added 4 commits February 1, 2023 14:54
Co-authored-by: Florian Vogt <florian.vogt@sap.com>
Keep modules that only contain extensions instead of discarding them.
This allows to use workspaces for resolving extensions too. Before, only
extensions in modules that also contained projects where resolved.
Copy link
Member Author

@RandomByte RandomByte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much @flovogt 😊

lib/graph/ProjectGraph.js Show resolved Hide resolved
lib/graph/Workspace.js Show resolved Hide resolved
lib/graph/Workspace.js Show resolved Hide resolved
lib/graph/Workspace.js Show resolved Hide resolved

/**
* @param {object} options
* @param {object} options.cwd Path to use for resolving all paths of the workspace configuration from.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

`Try adding it temporarily to the root project's dependencies`);
}

// TODO: If a cyclic dependency is declared, this will empty the event loop.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is obsolete. I solved this problem by taking in the _checkCycle function from the ProjectGraph. I dreamed that I forgot to remove this comment but the next morning I thought it was just a dream. Oh well...

lib/graph/helpers/ui5Framework.js Show resolved Hide resolved
/*!
* ${copyright}
*/
console.log('HelloWorld');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

metadata:
name: extension.a-ui5-yaml
task:
path: lib/extensionModule.js
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

test/lib/graph/graph.js Show resolved Hide resolved
lib/graph/Workspace.js Show resolved Hide resolved

/**
* For a given project name (e.g. the value of the <code>metadata.name</code> property in a ui5.yaml),
* returns a Module instance or undefined depending on whether the project
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* returns a Module instance or undefined depending on whether the project
* returns a module instance or <code>undefined</code> depending on whether the project

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*
* @public
* @param {string} projectName Name of the project
* @returns {Promise<@ui5/project/graph/Module|undefined>} Module instance of undefined if none is found
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @returns {Promise<@ui5/project/graph/Module|undefined>} Module instance of undefined if none is found
* @returns {Promise<@ui5/project/graph/Module|undefined>} Module instance of <code>undefined</code> if none is found

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* For a given node id (e.g. the value of the name property in a package.json),
* returns a Module instance or undefined depending on whether the module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* returns a Module instance or undefined depending on whether the module
* returns a module instance or <code>undefined</code> depending on whether the module

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*
* @public
* @param {string} nodeId Node ID of the module
* @returns {Promise<@ui5/project/graph/Module|undefined>} Module instance of undefined if none is found
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @returns {Promise<@ui5/project/graph/Module|undefined>} Module instance of undefined if none is found
* @returns {Promise<@ui5/project/graph/Module|undefined>} Module instance of <code>undefined</code> if none is found

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

test/lib/graph/graph.js Show resolved Hide resolved
});

test.afterEach.always((t) => {
t.context.sinon.restore();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we had to do it when await import is used.... Interesting

test/lib/graph/helpers/createWorkspace.js Show resolved Hide resolved
@RandomByte RandomByte merged commit b77ca2f into main Feb 2, 2023
@RandomByte RandomByte deleted the local-dependency-resolution-poc branch February 2, 2023 09:43
* @public
* @typedef {object} @ui5/project/graph/Workspace~Configuration
* @property {string} node.specVersion
* @property {object} node.metadata Version of the project
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be something like "Metadata of the configuration`, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Correction in #568

d3xter666 pushed a commit that referenced this pull request Feb 7, 2023
Co-authored-by: Florian Vogt <florian.vogt@sap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants