Skip to content

Commit

Permalink
chore: update to yarn v3
Browse files Browse the repository at this point in the history
As [kaoto-ui](https://github.com/KaotoIO/kaoto-ui) migrated to yarn v3, it's
time for vscode to do the same.

Changes:

* Upgrade yarn to v3 - berry
* Remove installing global dependencies from CI workflows as those are deprecated
in favor of the "yarn dlx" command
* Add a local yarn plugin (.yarn/plugins/plugins-list.js) to bring the functionality
from yarn v1 "yarn list --prod --json" since the "@vscode/vsce" depends on such functionality.
more datails in [the following issue](microsoft/vscode-vsce#517)
* Update the CONTRIBUTING.md file to reflect the new API for "yarn link"
* Bump "@kie-tools-core/*" from "0.27.0" to "0.29.0" as it's required that the dependencies
match from the root package and the linked package.
* Add a resolution entry for "zundo" package to support both "[email protected]" and "kaoto-ui@main-branch"

fixes: #270
  • Loading branch information
lordrip committed Jun 12, 2023
1 parent 42dbfec commit e699b53
Show file tree
Hide file tree
Showing 10 changed files with 8,885 additions and 5,242 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ jobs:
with:
node-version: '16'
cache: 'yarn'
- name: Install prerequisites
run: |
yarn global add rimraf
yarn global add @vscode/vsce
yarn global add webpack-cli
yarn global add webpack
- name: yarn
run: yarn --network-timeout 1000000
- name: yarn build:dev
Expand Down
17 changes: 4 additions & 13 deletions .github/workflows/main-kaoto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,14 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install prerequisites
- name: Kaoto-ui build
working-directory: kaoto-ui
run: |
yarn global add rimraf
yarn global add @vscode/vsce
yarn global add webpack-cli
yarn global add webpack
- name: Kaoto-ui link and build
run: |
cd kaoto-ui
yarn
yarn link
yarn build:lib
- name: yarn
- name: yarn link kaoto-ui
working-directory: vscode-kaoto
run: |
yarn
yarn link @kaoto/kaoto-ui
run: yarn link ../kaoto-ui
- name: yarn build:dev
working-directory: vscode-kaoto
run: yarn build:dev
Expand Down
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
# dependencies
/node_modules
dist
# no longer using yarn berry
/.yarn
.pnp.js
.pnp.cjs
.pnp.loader.mjs

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# testing
/coverage
Expand Down
138 changes: 138 additions & 0 deletions .yarn/plugins/plugin-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Workaround for https://github.com/microsoft/vscode-vsce/issues/517
// taken from https://gist.githubusercontent.com/arendjr/415747652a8c79f12b005ce3cfb2f808/raw/a4a227070319e1d4c61e982b74153765d6338694/list-plugin.js

const fs = require('fs');

// Setup: Place this file in `.yarn/plugins/list-plugin.js` and the following
// to `.yarnrc.yml`:
//
// ```
// plugins:
// - path: .yarn/plugins/plugin-list.js
// ```
module.exports = {
name: 'plugin-list',
factory: (require) => {
const { BaseCommand } = require('@yarnpkg/cli');
const { Command, Option } = require('clipanion');
const { parseSyml } = require('@yarnpkg/parsers');
const { Manifest } = require('@yarnpkg/core');

class ListCommand extends BaseCommand {
static paths = [['list']];

static usage = Command.Usage({
description: 'Lists installed packages.',
});

prod = Option.Boolean('--prod', false);
json = Option.Boolean('--json', false);
manifest = new Manifest();
trees = [];

async execute() {
await this.manifest.loadFile(Manifest.fileName, {});

if (!this.prod || !this.json) {
throw new Error(
'This command can only be used with the --prod and --json ' +
'args to match the behavior required by VSCE. See: ' +
'https://github.com/microsoft/vscode-vsce/blob/main/src/npm.ts'
);
}

const packageJsonContents = fs.readFileSync('package.json', 'utf-8');
const { dependencies, resolutions } = JSON.parse(packageJsonContents);

const lockContents = fs.readFileSync('yarn.lock', 'utf-8');
const resolved = parseSyml(lockContents);

this.addDependencies(dependencies, resolved, resolutions);

const output = {
type: 'tree',
data: { type: 'list', trees: this.trees },
};

this.context.stdout.write(JSON.stringify(output));
}

addDependencies(dependencies, resolved, resolutions) {
for (const [packageName, versionSpecifier] of Object.entries(dependencies)) {
this.addDependency(packageName, versionSpecifier, resolved, resolutions);
}
}

addDependency(packageName, versionSpecifier, resolved, resolutions) {
const packageInfo = this.lookup(resolved, packageName, versionSpecifier, resolutions);
if (!packageInfo) {
throw new Error(
`Cannot resolve "${packageName}" with version range "${versionSpecifier}"`
);
}

const { version, dependencies } = packageInfo;
const name = `${packageName}@${version}`;
if (this.trees.find((tree) => tree.name === name)) {
return; // Dependency already added as part of another tree.
}

if (dependencies) {
const children = Object.entries(dependencies).map(([name, range]) => ({
name: `${name}@${range}`,
}));
this.trees.push({ name, children });

this.addDependencies(dependencies, resolved, resolutions);
} else {
this.trees.push({ name, children: [] });
}
}

/**
* @param resolved All the resolved dependencies as found in the lock file.
* @param packageName The package name to look up.
* @param versionSpecifier The package version range as declared in the package.json.
* @param resolutions The resolutions override as declared in the package.json.
*/
lookup(resolved, packageName, versionSpecifier, resolutions) {
const dependencyKey = this.getLockFileKey(packageName, versionSpecifier, resolutions);

const packageInfo = resolved[dependencyKey];
if (packageInfo) {
return packageInfo;
}

// Fall back to slower iteration-based lookup for combined keys.
for (const [key, packageInfo] of Object.entries(resolved)) {
// Resolving ranges: "@babel/runtime@npm:^7.1.2, @babel/runtime@npm:^7.12.13, @babel/runtime@npm:^7.12.5"
const versionsRange = key.split(',');

// Resolving yarn link resolutions: "@kaoto/kaoto-ui@portal:/home/rmartinez/repos/kaoto-ui::locator=vscode-kaoto%40workspace%3A."
const yarnLinkResolution = key.split('::')[0];

if (
versionsRange.some((key) => key.trim() === dependencyKey) ||
yarnLinkResolution === dependencyKey
) {
return packageInfo;
}
}
}

getLockFileKey(packageName, versionSpecifier, resolutions) {
// If the package name is in the resolutions field, use the version from there.
const resolvedVersionSpecifier = resolutions[packageName] ?? versionSpecifier;

// If the version field contains a URL, don't attempt to use the NPM registry
return resolvedVersionSpecifier.includes(':')
? `${packageName}@${resolvedVersionSpecifier}`
: `${packageName}@npm:${resolvedVersionSpecifier}`;
}
}

return {
commands: [ListCommand],
};
},
};
874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.0.cjs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
yarnPath: .yarn/releases/yarn-3.6.0.cjs

nodeLinker: node-modules

plugins:
- path: .yarn/plugins/plugin-list.js
34 changes: 20 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Everyone is welcome to contribute to Kaoto.
Everyone is welcome to contribute to Kaoto.

We have a Kanban board with good first issues in https://github.com/orgs/KaotoIO/projects/4

Expand All @@ -14,7 +14,7 @@ Always **use one of the templates available** and answer as many of the question
If you are **submitting a bug**, provide a simple step by step explanation of how to reproduce it and what is the expected outcome.

If you are **submitting a feature**, be ready to follow up and contribute with its development. Features that are proposed but don't have
funds or developers ready to implement it may be closed due to not enough interest raised. If you can't fund or implement it yourself and
funds or developers ready to implement it may be closed due to not enough interest raised. If you can't fund or implement it yourself and
you want the feature implemented, you must look for a way to find resources to implement it.

### Clarifying bugs
Expand All @@ -23,7 +23,7 @@ You can also contribute by looking for open bugs and test corner cases to add mo

### Implementing bug fixes or features

Feel free to work on any of the open issues. Add a comment to it saying that you want to work on it and deliver regular updates on the
Feel free to work on any of the open issues. Add a comment to it saying that you want to work on it and deliver regular updates on the
status of the development.

If you can no longer work on an issue, please, let us know as soon as possible so someone else can work on it.
Expand All @@ -32,14 +32,14 @@ See pull request section.

## Pull Requests

If you are reviewing pull requests, please use the [conventional comments](https://conventionalcomments.org/) standard to do so.
If you are reviewing pull requests, please use the [conventional comments](https://conventionalcomments.org/) standard to do so.
Comments that don't follow this standard may be ignored.

There are a few things to consider when sending a pull request merge:

* Small commits. We prefer small commits because they are easier to review
* All commits must pass tests: Each commit should have consistency on its own and don't break any functionality
* All jobs/checks must be green: This includes test coverage, code smells, security issues,...
* All jobs/checks must be green: This includes test coverage, code smells, security issues,...
* Be descriptive on the PR text about what the changes are. Better to have duplicated explanation than no explanation at all. Provide examples.
* Add screenshots and videos of what your PR is doing. Especially if you are adding a new feature.
* High test coverage: Your code must be covered by unit and e2e tests. If for some reason your PR can't or shouldn't, be very clear why. The tests must be included in the same PR.
Expand All @@ -48,8 +48,8 @@ There are a few things to consider when sending a pull request merge:

**All your commits should follow the [conventional commits standard](https://www.conventionalcommits.org/).**

The Conventional Commits specification is a lightweight convention on top of commit messages.
It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of.
The Conventional Commits specification is a lightweight convention on top of commit messages.
It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of.
This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.

The commit message should be structured as follows:
Expand All @@ -66,13 +66,13 @@ The commit contains the following structural elements, to communicate intent to

* fix: a commit of the type fix patches a bug in your codebase (this correlates with PATCH in Semantic Versioning).
* feat: a commit of the type feat introduces a new feature to the codebase (this correlates with MINOR in Semantic Versioning).
* BREAKING CHANGE: a commit that has a footer BREAKING CHANGE:, or appends a ! after the type/scope, introduces a breaking API change
* BREAKING CHANGE: a commit that has a footer BREAKING CHANGE:, or appends a ! after the type/scope, introduces a breaking API change
(correlating with MAJOR in Semantic Versioning). A BREAKING CHANGE can be part of commits of any type.
* types other than fix: and feat: are allowed, like build:, chore:, ci:, docs:, style:, refactor:, perf:, test:, and others.
* footers other than BREAKING CHANGE: `description` may be provided and follow a convention similar to git trailer format.

Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning
(unless they include a BREAKING CHANGE). A scope may be provided to a commit’s type, to provide additional contextual information and
Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning
(unless they include a BREAKING CHANGE). A scope may be provided to a commit’s type, to provide additional contextual information and
is contained within parenthesis, e.g., `feat(parser): add ability to parse arrays`.

## Development environment
Expand Down Expand Up @@ -101,18 +101,24 @@ If you'd like to test latest Kaoto UI and not rely on a released version, follow

* In `kaoto-ui` local clone folder:
* `yarn`
* `yarn link`
* `yarn build:lib`
* Open VS Code on `vscode-kaoto` local clone folder
* `yarn`
* `yarn link @kaoto/kaoto-ui`
* `yarn link` _\<kaoto-ui local clone folder uri>_
* i.e. `yarn link ~/repositories/kaoto-ui`
* `yarn build:dev`
* In `Run and debug` perspective, call the `Run Extension` launch configuration
* In the new VS Code opened (which has `[Extension Development host]` in window title,
* In the new VS Code opened (which has `[Extension Development host]` in window title),
* Open a folder (use the one you want)
* Create a file named with the following pattern `*.kaoto.yaml`
* Open the file


To return to the default Kaoto UI version, just write on `vscode-kaoto` local clone folder:
* `yarn unlink` _\<kaoto-ui local clone folder uri>_
* i.e. `yarn unlink ~/repositories/kaoto-ui`

More information about [linking](https://yarnpkg.com/cli/link) and [unlinking](https://yarnpkg.com/cli/unlink) local packages with [yarn](https://yarnpkg.com/)

### How to debug Kaoto UI embedded in VS Code

The command `Developer: Toggle Developer Tools` gives access to classic developer tools for web applications. See [official documentation](https://code.visualstudio.com/api/extension-guides/webview#inspecting-and-debugging-webviews) for more details.
Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
},
"dependencies": {
"@kaoto/kaoto-ui": "1.0.0",
"@kie-tools-core/backend": "^0.27.0",
"@kie-tools-core/editor": "^0.27.0",
"@kie-tools-core/i18n": "^0.27.0",
"@kie-tools-core/monaco-editor": "^0.27.0",
"@kie-tools-core/patternfly-base": "^0.27.0",
"@kie-tools-core/vscode-extension": "^0.27.0",
"@kie-tools-core/workspace": "^0.27.0",
"@kie-tools-core/backend": "^0.29.0",
"@kie-tools-core/editor": "^0.29.0",
"@kie-tools-core/i18n": "^0.29.0",
"@kie-tools-core/monaco-editor": "^0.29.0",
"@kie-tools-core/patternfly-base": "^0.29.0",
"@kie-tools-core/vscode-extension": "^0.29.0",
"@kie-tools-core/workspace": "^0.29.0",
"@patternfly/react-core": "4.276.8",
"@redhat-developer/vscode-redhat-telemetry": "^0.6.1",
"async-wait-until": "^2.0.12",
Expand Down Expand Up @@ -166,7 +166,10 @@
"webpack-merge": "^5.8.0"
},
"resolutions": {
"@types/react": "18.2.6",
"react": "18.2.0",
"react-dom": "18.2.0"
}
"react-dom": "18.2.0",
"zundo": "2.0.0-beta.19"
},
"packageManager": "[email protected]"
}
10 changes: 5 additions & 5 deletions src/webview/KaotoEditorEnvelopeApp.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { KaotoEditorFactory } from "@kaoto/kaoto-ui/dist/lib/kogito-integration";
import * as EditorEnvelope from "@kie-tools-core/editor/dist/envelope";

import { KaotoEditorFactory } from '@kaoto/kaoto-ui/dist/lib/kogito-integration';
import { Editor, EditorFactory, KogitoEditorChannelApi } from '@kie-tools-core/editor/dist/api';
import * as EditorEnvelope from '@kie-tools-core/editor/dist/envelope';
declare const acquireVsCodeApi: any;

EditorEnvelope.init({
container: document.getElementById("envelope-app")!,
container: document.getElementById('envelope-app')!,
bus: acquireVsCodeApi(),
editorFactory: new KaotoEditorFactory(),
editorFactory: new KaotoEditorFactory() as unknown as EditorFactory<Editor, KogitoEditorChannelApi>,
});
Loading

0 comments on commit e699b53

Please sign in to comment.