Skip to content

Commit 290334b

Browse files
authored
V16: Sub-dependencies from workspaces are missing in the main package.json file (#19416)
* fix: renames `./src` to `./dist-cms` in distributed package.json * build: adds missing package.json to segment package * build: adds missing package and vite.config for 'settings' * build: adds missing package.json for 'translation' * build: hoist all sub-dependencies to main package.json file * build: sync lock file with workspaces * build: join the paths (for os agnosticity)
1 parent 407e7a2 commit 290334b

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

src/Umbraco.Web.UI.Client/devops/publish/cleanse-pkg.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { readFileSync, writeFileSync } from 'fs';
1+
import { readFileSync, writeFileSync, existsSync } from 'fs';
2+
import { join } from 'path';
3+
import glob from 'tiny-glob'
24

35
console.log('[Prepublish] Cleansing package.json');
46

@@ -12,5 +14,40 @@ delete packageJson.devDependencies;
1214
packageJson.peerDependencies = { ...packageJson.dependencies };
1315
delete packageJson.dependencies;
1416

17+
// Iterate all workspaces and hoist the dependencies to the root package.json
18+
const workspaces = packageJson.workspaces || [];
19+
const workspacePromises = workspaces.map(async workspaceGlob => {
20+
// Use glob to find the workspace path
21+
const localWorkspace = workspaceGlob.replace(/\.\/src/, './dist-cms');
22+
const workspacePaths = await glob(localWorkspace, { cwd: './', absolute: true });
23+
24+
workspacePaths.forEach(workspace => {
25+
const workspacePackageFile = join(workspace, 'package.json');
26+
27+
// Ensure the workspace package.json exists
28+
if (!existsSync(workspacePackageFile)) {
29+
// If the package.json does not exist, log a warning and continue
30+
console.warn(`No package.json found in workspace: ${workspace}`);
31+
return;
32+
}
33+
34+
const workspacePackageJson = JSON.parse(readFileSync(workspacePackageFile, 'utf8'));
35+
36+
// Move dependencies from the workspace to the root package.json
37+
if (workspacePackageJson.dependencies) {
38+
Object.entries(workspacePackageJson.dependencies).forEach(([key, value]) => {
39+
console.log('Hoisting dependency:', key, 'from workspace:', workspace, 'with version:', value);
40+
packageJson.peerDependencies[key] = value;
41+
});
42+
}
43+
})
44+
});
45+
46+
// Wait for all workspace processing to complete
47+
await Promise.all(workspacePromises);
48+
49+
// Remove the workspaces field from the root package.json
50+
delete packageJson.workspaces;
51+
1552
// Write the package.json back to disk
1653
writeFileSync(packageFile, JSON.stringify(packageJson, null, 2), 'utf8');

src/Umbraco.Web.UI.Client/package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@umbraco-backoffice/segment",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "vite build"
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@umbraco-backoffice/settings",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "vite build"
7+
}
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'vite';
2+
import { rmSync } from 'fs';
3+
import { getDefaultConfig } from '../../vite-config-base';
4+
5+
const dist = '../../../dist-cms/packages/settings';
6+
7+
// delete the unbundled dist folder
8+
rmSync(dist, { recursive: true, force: true });
9+
10+
export default defineConfig({
11+
...getDefaultConfig({
12+
dist,
13+
}),
14+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@umbraco-backoffice/translation",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "vite build"
7+
}
8+
}

0 commit comments

Comments
 (0)