Skip to content

Commit 0df2f9b

Browse files
authored
chore: separate yarn workspaces (redhat-developer#2790)
* separate yarn workspaces Signed-off-by: Paul Schultz <pschultz@pobox.com> add @rjsf/utils to resolutions to fix export-dynamic issues with rbac Signed-off-by: Kashish Mittal <kmittal@redhat.com> fix build:dockerfile Signed-off-by: Paul Schultz <pschultz@pobox.com> * update dockerfile Signed-off-by: Paul Schultz <pschultz@pobox.com> * update the copy plugins scipt Signed-off-by: Paul Schultz <pschultz@pobox.com> * update gh actions Signed-off-by: Paul Schultz <pschultz@pobox.com> --------- Signed-off-by: Paul Schultz <pschultz@pobox.com>
1 parent fd9589c commit 0df2f9b

174 files changed

Lines changed: 44175 additions & 13213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
5454
with:
5555
node-version: ${{ matrix.node-version }}
56-
registry-url: 'https://registry.npmjs.org'
56+
registry-url: "https://registry.npmjs.org"
5757

5858
- name: Setup local Turbo cache
5959
uses: dtinth/setup-github-actions-caching-for-turbo@cc723b4600e40a6b8815b65701d8614b91e2669e # v1
@@ -96,7 +96,7 @@ jobs:
9696
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
9797
with:
9898
node-version: ${{ matrix.node-version }}
99-
registry-url: 'https://registry.npmjs.org'
99+
registry-url: "https://registry.npmjs.org"
100100

101101
- name: Setup local Turbo cache
102102
uses: dtinth/setup-github-actions-caching-for-turbo@cc723b4600e40a6b8815b65701d8614b91e2669e # v1
@@ -127,5 +127,8 @@ jobs:
127127
- name: Run tests
128128
run: yarn run test --continue --affected
129129

130-
- name: Verify wrappers
131-
run: yarn workspace dynamic-plugins-utils run test:wrappers
130+
- name: Install dynamic plugin dependencies
131+
run: cd ./dynamic-plugins && yarn install && cd ..
132+
133+
- name: Verify dynamic plugin wrappers
134+
run: cd ./dynamic-plugins && yarn test && cd ..

.rhdh/docker/Dockerfile

Lines changed: 42 additions & 104 deletions
Large diffs are not rendered by default.

docker/Dockerfile

Lines changed: 38 additions & 98 deletions
Large diffs are not rendered by default.

dynamic-plugins/.gitkeep

Whitespace-only changes.

dynamic-plugins/.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch

Lines changed: 133 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 104 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,115 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const process = require('process');
1+
const fs = require("fs").promises; // Use the promises API
2+
const path = require("path");
3+
const process = require("process");
44

5-
process.chdir(path.join(__dirname, '..'));
6-
7-
if (!process.argv[2]) {
8-
console.log('Usage: node copy-plugins.js <destination directory>');
9-
process.exit(1);
5+
// Helper function to check if a directory exists
6+
async function directoryExists(dirPath) {
7+
try {
8+
const stats = await fs.stat(dirPath);
9+
return stats.isDirectory();
10+
} catch (error) {
11+
if (error.code === "ENOENT") {
12+
return false;
13+
}
14+
throw error; // Re-throw unexpected errors
15+
}
1016
}
1117

12-
const destination = process.argv[2];
13-
fs.mkdirSync(destination, { recursive: true });
18+
async function main() {
19+
process.chdir(path.join(__dirname, ".."));
1420

15-
const wrappersDir = path.join('.', 'wrappers');
21+
if (!process.argv[2]) {
22+
console.log("Usage: node copy-plugins.js <destination directory>");
23+
process.exit(1);
24+
}
1625

17-
const wrappers = fs
18-
.readdirSync(wrappersDir, {
19-
withFileTypes: true,
20-
})
21-
.filter(dirent => dirent.isDirectory())
22-
.map(dirent => path.join(wrappersDir, dirent.name));
26+
const destination = process.argv[2];
27+
// Ensure destination exists using async mkdir
28+
await fs.mkdir(destination, { recursive: true });
29+
console.log(`Ensured destination directory exists: ${destination}`);
2330

24-
for (const directory of wrappers) {
25-
const distDynamicDir = path.join(directory, 'dist-dynamic');
31+
const wrappersDir = path.join(".", "wrappers");
2632

27-
const packageToCopy = fs.existsSync(distDynamicDir)
28-
? distDynamicDir
29-
: directory;
33+
// Read directories asynchronously
34+
const dirents = await fs.readdir(wrappersDir, { withFileTypes: true });
3035

31-
const pkgJsonPath = path.join(packageToCopy, 'package.json');
32-
if (!fs.existsSync(pkgJsonPath)) {
33-
console.error(`No 'package.json' in '${directory}': skipping`);
34-
continue;
35-
}
36-
const pkgJson = require(fs.realpathSync(pkgJsonPath));
37-
if (!pkgJson?.name) {
38-
console.error(
39-
`Package '${directory}' is missing 'package.json' or 'name' attribute.`,
40-
);
41-
continue;
42-
}
43-
const copyName = pkgJson.name.replace(/^@/, '').replace(/\//, '-');
36+
const wrapperDirs = dirents
37+
.filter((dirent) => dirent.isDirectory())
38+
.map((dirent) => path.join(wrappersDir, dirent.name));
39+
40+
// Create an array of promises, one for each directory processing task
41+
const copyPromises = wrapperDirs.map(async (directory) => {
42+
try {
43+
const distDynamicDir = path.join(directory, "dist-dynamic");
44+
let packageToCopy = directory; // Default source
45+
46+
// Check asynchronously if dist-dynamic exists and is a directory
47+
if (await directoryExists(distDynamicDir)) {
48+
packageToCopy = distDynamicDir;
49+
}
50+
51+
const pkgJsonPath = path.join(packageToCopy, "package.json");
52+
let pkgJson;
53+
try {
54+
// Read and parse package.json asynchronously
55+
const pkgJsonContent = await fs.readFile(pkgJsonPath, "utf-8");
56+
pkgJson = JSON.parse(pkgJsonContent);
57+
} catch (error) {
58+
if (error.code === "ENOENT") {
59+
console.error(
60+
`Skipping '${directory}': No 'package.json' found in '${packageToCopy}'`,
61+
);
62+
return; // Skip this directory successfully (promise resolves)
63+
}
64+
// Re-throw other read/parse errors
65+
throw new Error(
66+
`Error reading package.json from ${pkgJsonPath}: ${error.message}`,
67+
);
68+
}
4469

45-
console.log(`Copying ${packageToCopy} to ${destination}`);
46-
const destinationDir = path.join(destination, copyName);
47-
fs.rmSync(destinationDir, { recursive: true, force: true });
48-
fs.cpSync(fs.realpathSync(packageToCopy), destinationDir, {
49-
recursive: true,
70+
if (!pkgJson?.name) {
71+
console.error(
72+
`Skipping '${directory}': Invalid 'package.json' in '${packageToCopy}' (missing 'name' attribute).`,
73+
);
74+
return; // Skip this directory successfully (promise resolves)
75+
}
76+
77+
const copyName = pkgJson.name.replace(/^@/, "").replace(/\//, "-");
78+
const destinationDir = path.join(destination, copyName);
79+
// Get the real path of the source directory asynchronously
80+
const sourceRealPath = await fs.realpath(packageToCopy);
81+
82+
console.log(
83+
`Processing ${pkgJson.name}: Copying ${sourceRealPath} to ${destinationDir}`,
84+
);
85+
86+
// Remove destination directory asynchronously
87+
await fs.rm(destinationDir, { recursive: true, force: true });
88+
89+
// Copy directory asynchronously
90+
await fs.cp(sourceRealPath, destinationDir, { recursive: true });
91+
92+
console.log(`Finished copying ${pkgJson.name} to ${destinationDir}`);
93+
} catch (error) {
94+
// Log the error and re-throw to make Promise.all fail
95+
console.error(`Error processing directory '${directory}':`, error);
96+
throw error;
97+
}
5098
});
99+
100+
// Wait for all copy operations to complete
101+
try {
102+
await Promise.all(copyPromises);
103+
console.log("\nAll plugins copied successfully.");
104+
} catch (error) {
105+
// Error is already logged in the individual promise catch block
106+
console.error("\nOne or more plugins failed to copy. See errors above.");
107+
process.exit(1); // Exit with error status
108+
}
51109
}
110+
111+
// Run the main async function and catch any top-level errors
112+
main().catch((err) => {
113+
console.error("Script execution failed:", err);
114+
process.exit(1);
115+
});

dynamic-plugins/_utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"copy-dynamic-plugins": "node ./copy-plugins.js",
1111
"lint": "backstage-cli package lint",
12-
"test:wrappers": "backstage-cli package test --passWithNoTests --coverage"
12+
"test": "backstage-cli package test --passWithNoTests --coverage"
1313
},
1414
"devDependencies": {
1515
"@backstage/cli": "0.30.0",

dynamic-plugins/package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "dynamic-plugins-root",
3+
"version": "1.7.0",
4+
"private": true,
5+
"engines": {
6+
"node": "22"
7+
},
8+
"scripts": {
9+
"build": "turbo run build",
10+
"tsc": "turbo run tsc",
11+
"export-dynamic": "turbo run export-dynamic",
12+
"export-dynamic:clean": "turbo run export-dynamic:clean",
13+
"copy-dynamic-plugins": "turbo copy-dynamic-plugins --",
14+
"clean": "turbo run clean",
15+
"test": "turbo run test",
16+
"lint:check": "turbo run lint:check",
17+
"lint:fix": "turbo run lint:fix"
18+
},
19+
"workspaces": {
20+
"packages": [
21+
"_utils",
22+
"wrappers/*"
23+
]
24+
},
25+
"devDependencies": {
26+
"turbo": "2.5.0"
27+
},
28+
"resolutions": {
29+
"@types/react": "18.3.20",
30+
"@types/react-dom": "18.3.6",
31+
"@rjsf/utils": "=5.24.0",
32+
"@aws-sdk/util-utf8-browser": "npm:@smithy/util-utf8@~2",
33+
"@kubernetes/client-node@npm:0.20.0/jsonpath-plus": "^10.3.0",
34+
"@backstage/plugin-auth-node@^0.6.0": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
35+
"@backstage/plugin-auth-node@0.6.0": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
36+
"@backstage/plugin-auth-node@^0.5.6": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
37+
"@backstage/plugin-auth-node@^0.5.1": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
38+
"@backstage/plugin-auth-node@^0.4.17": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
39+
"@backstage/plugin-auth-node@^0.4.13": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
40+
"@backstage/plugin-auth-node@^0.5.2": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
41+
"@backstage/plugin-auth-node@^0.4.16": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch"
42+
},
43+
"packageManager": "yarn@3.8.7"
44+
}

dynamic-plugins/turbo.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"tasks": {
4+
"export-dynamic": {
5+
"dependsOn": ["tsc"]
6+
},
7+
"export-dynamic:clean": {
8+
"cache": false,
9+
"dependsOn": ["tsc"]
10+
},
11+
"start": {
12+
"cache": false,
13+
"persistent": true
14+
},
15+
"build": {
16+
"outputs": ["dist/**"],
17+
"dependsOn": ["tsc", "^build"]
18+
},
19+
"clean": {
20+
"cache": false
21+
},
22+
"test": {
23+
"outputs": ["coverage/**"]
24+
},
25+
"lint:check": {},
26+
"lint:fix": {
27+
"cache": false
28+
},
29+
"tsc": {
30+
"dependsOn": ["^tsc"]
31+
},
32+
"copy-dynamic-plugins": {}
33+
}
34+
}

dynamic-plugins/wrappers/backstage-community-plugin-3scale-backend-dynamic/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"include": ["src", "dev", "migrations"],
44
"exclude": ["node_modules"],
55
"compilerOptions": {
6-
"outDir": "../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-3scale-backend-dynamic",
6+
"outDir": "../../dist-types/wrappers/backstage-community-plugin-3scale-backend-dynamic",
77
"rootDir": "."
88
}
99
}

0 commit comments

Comments
 (0)