@unisphere/nx 2.2.1 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/add-application/add-application.d.ts.map +1 -1
- package/dist/generators/add-application/add-application.js +77 -55
- package/dist/generators/add-application/schema.d.ts +3 -1
- package/dist/generators/add-application/schema.json +4 -8
- package/dist/generators/add-application/templates/default/.env-template +6 -0
- package/dist/generators/add-application/templates/default/.eslintrc.json +1 -1
- package/dist/generators/add-application/templates/default/jest.config.ts +3 -3
- package/dist/generators/add-application/templates/default/project.json.template +2 -2
- package/dist/generators/add-application/templates/default/readme.md.template +11 -0
- package/dist/generators/add-application/templates/default/src/app/app.tsx.template +77 -77
- package/dist/generators/add-application/templates/default/tsconfig.json +1 -1
- package/dist/generators/add-application/templates/default/webpack.config.js.template +6 -1
- package/dist/generators/add-package/README.md +2 -2
- package/dist/generators/add-package/add-package.d.ts.map +1 -1
- package/dist/generators/add-package/add-package.js +11 -23
- package/dist/generators/add-package/schema.d.ts +1 -1
- package/dist/generators/add-package/schema.json +27 -19
- package/dist/generators/add-package/templates/new-package/.eslintrc.json +1 -1
- package/dist/generators/add-package/templates/new-package/package.json.template +0 -1
- package/dist/generators/add-package/templates/new-package/project.json.template +4 -4
- package/dist/generators/add-package/templates/new-package/rollup.config.js +1 -1
- package/dist/generators/add-package/templates/new-package/tsconfig.json +1 -1
- package/dist/generators/add-package/templates/new-package/tsconfig.lib.json.template +1 -1
- package/dist/generators/add-package/templates/new-package/tsconfig.spec.json +1 -1
- package/dist/generators/add-runtime/add-runtime.d.ts.map +1 -1
- package/dist/generators/add-runtime/add-runtime.js +62 -9
- package/dist/generators/add-runtime/schema.d.ts +1 -0
- package/dist/generators/add-runtime/schema.json +1 -9
- package/dist/generators/add-runtime/templates/new-runtime/src/lib/create-factory.tsx.template +4 -4
- package/dist/generators/add-runtime/templates/new-runtime/src/lib/runtime.tsx.template +26 -2
- package/dist/generators/add-visual/add-visual.d.ts +1 -1
- package/dist/generators/add-visual/add-visual.d.ts.map +1 -1
- package/dist/generators/add-visual/add-visual.js +108 -15
- package/dist/generators/add-visual/schema.d.ts +3 -3
- package/dist/generators/add-visual/schema.json +2 -24
- package/dist/generators/dependency-config.d.ts.map +1 -1
- package/dist/generators/dependency-config.js +1 -0
- package/dist/generators/internal-dev-runner/generator.d.ts +3 -0
- package/dist/generators/internal-dev-runner/generator.d.ts.map +1 -0
- package/dist/generators/internal-dev-runner/generator.js +45 -0
- package/dist/generators/internal-dev-runner/schema.json +9 -0
- package/dist/generators/remove/remove.d.ts +19 -0
- package/dist/generators/remove/remove.d.ts.map +1 -0
- package/dist/generators/remove/remove.js +270 -0
- package/dist/generators/remove/schema.d.ts +4 -0
- package/dist/generators/remove/schema.json +38 -0
- package/dist/generators/rename-package/rename-package.d.ts +3 -0
- package/dist/generators/rename-package/rename-package.d.ts.map +1 -1
- package/dist/generators/rename-package/rename-package.js +139 -20
- package/dist/generators/utils.d.ts +30 -1
- package/dist/generators/utils.d.ts.map +1 -1
- package/dist/generators/utils.js +258 -7
- package/dist/migrations/1-22-0/patches/@changesets+cli+2.29.7.patch +36 -4
- package/dist/migrations/1-22-2/templates/_publish-artifacts.template +5 -5
- package/dist/migrations/1-24-2/templates/_publish-artifacts.template +5 -5
- package/dist/migrations/2-1-0/replace-readme-md.d.ts.map +1 -1
- package/dist/migrations/2-1-0/replace-readme-md.js +2 -3
- package/dist/migrations/2-2-0/templates/_publish-artifacts.template +5 -5
- package/dist/migrations/3-0-0/add-define-plugin-to-webpack.d.ts +3 -0
- package/dist/migrations/3-0-0/add-define-plugin-to-webpack.d.ts.map +1 -0
- package/dist/migrations/3-0-0/add-define-plugin-to-webpack.js +233 -0
- package/dist/migrations/3-0-0/add-env-to-application-gitignore.d.ts +3 -0
- package/dist/migrations/3-0-0/add-env-to-application-gitignore.d.ts.map +1 -0
- package/dist/migrations/3-0-0/add-env-to-application-gitignore.js +117 -0
- package/dist/migrations/3-0-0/fix-vite-config-cache-paths.d.ts +10 -0
- package/dist/migrations/3-0-0/fix-vite-config-cache-paths.d.ts.map +1 -0
- package/dist/migrations/3-0-0/fix-vite-config-cache-paths.js +66 -0
- package/dist/migrations/3-0-0/patches/@changesets+cli+2.29.7.patch +88 -0
- package/dist/migrations/3-0-0/post-cleanup-empty-directories.d.ts +12 -0
- package/dist/migrations/3-0-0/post-cleanup-empty-directories.d.ts.map +1 -0
- package/dist/migrations/3-0-0/post-cleanup-empty-directories.js +62 -0
- package/dist/migrations/3-0-0/pre-cleanup-empty-directories.d.ts +14 -0
- package/dist/migrations/3-0-0/pre-cleanup-empty-directories.d.ts.map +1 -0
- package/dist/migrations/3-0-0/pre-cleanup-empty-directories.js +105 -0
- package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.d.ts +3 -0
- package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.d.ts.map +1 -0
- package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.js +21 -0
- package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.d.ts +9 -0
- package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.d.ts.map +1 -0
- package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.js +88 -0
- package/dist/migrations/3-0-0/remove-publish-config-from-packages.d.ts +9 -0
- package/dist/migrations/3-0-0/remove-publish-config-from-packages.d.ts.map +1 -0
- package/dist/migrations/3-0-0/remove-publish-config-from-packages.js +45 -0
- package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.d.ts +15 -0
- package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.d.ts.map +1 -0
- package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.js +563 -0
- package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.d.ts +23 -0
- package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.d.ts.map +1 -0
- package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.js +645 -0
- package/dist/migrations/3-0-0/replace-github-workflow.d.ts +3 -0
- package/dist/migrations/3-0-0/replace-github-workflow.d.ts.map +1 -0
- package/dist/migrations/3-0-0/replace-github-workflow.js +48 -0
- package/dist/migrations/3-0-0/sync-package-lock.d.ts +10 -0
- package/dist/migrations/3-0-0/sync-package-lock.d.ts.map +1 -0
- package/dist/migrations/3-0-0/sync-package-lock.js +26 -0
- package/dist/migrations/3-0-0/templates/_publish-artifacts.template +363 -0
- package/dist/migrations/3-0-0/templates/cicd.template +89 -0
- package/dist/migrations/3-0-0/update-changeset-patch.d.ts +3 -0
- package/dist/migrations/3-0-0/update-changeset-patch.d.ts.map +1 -0
- package/dist/migrations/3-0-0/update-changeset-patch.js +31 -0
- package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.d.ts +21 -0
- package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.d.ts.map +1 -0
- package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.js +105 -0
- package/dist/migrations/utils/has-react-dependency.d.ts +14 -0
- package/dist/migrations/utils/has-react-dependency.d.ts.map +1 -0
- package/dist/migrations/utils/has-react-dependency.js +72 -0
- package/dist/shared.d.ts +6 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +9 -0
- package/generators.json +12 -1
- package/migrations.json +117 -0
- package/package.json +3 -2
- package/dist/generators/add-application/templates/local-dev-playground/.babelrc +0 -11
- package/dist/generators/add-application/templates/local-dev-playground/.eslintrc.json +0 -22
- package/dist/generators/add-application/templates/local-dev-playground/jest.config.ts +0 -11
- package/dist/generators/add-application/templates/local-dev-playground/package.json +0 -6
- package/dist/generators/add-application/templates/local-dev-playground/project.json +0 -9
- package/dist/generators/add-application/templates/local-dev-playground/src/app/app.tsx.template +0 -212
- package/dist/generators/add-application/templates/local-dev-playground/src/app/components/header.tsx.template +0 -123
- package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings-buttons.tsx +0 -57
- package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings-form.tsx +0 -108
- package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings.tsx +0 -74
- package/dist/generators/add-application/templates/local-dev-playground/src/app/configuration-provider.tsx +0 -163
- package/dist/generators/add-application/templates/local-dev-playground/src/app/definitions.ts +0 -25
- package/dist/generators/add-application/templates/local-dev-playground/src/app/utils/merge-deep.ts +0 -31
- package/dist/generators/add-application/templates/local-dev-playground/src/favicon.ico +0 -0
- package/dist/generators/add-application/templates/local-dev-playground/src/index.html +0 -17
- package/dist/generators/add-application/templates/local-dev-playground/src/main.tsx +0 -13
- package/dist/generators/add-application/templates/local-dev-playground/src/styles.css +0 -0
- package/dist/generators/add-application/templates/local-dev-playground/tsconfig.app.json +0 -24
- package/dist/generators/add-application/templates/local-dev-playground/tsconfig.json +0 -20
- package/dist/generators/add-application/templates/local-dev-playground/tsconfig.spec.json +0 -25
- package/dist/generators/add-application/templates/local-dev-playground/webpack.config.js +0 -33
- /package/dist/generators/add-runtime/templates/{core-templates → types-templates}/__runtimeName__-runtime/index.ts.template +0 -0
- /package/dist/generators/add-runtime/templates/{core-templates → types-templates}/__runtimeName__-runtime/runtime-types.ts.template +0 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Migration: Reorganize Applications by Distribution Channel
|
|
4
|
+
*
|
|
5
|
+
* This migration reorganizes applications based on their `distributionChannel` property in `.unisphere`:
|
|
6
|
+
*
|
|
7
|
+
* Directory structure:
|
|
8
|
+
* - none (local-dev-playground) -> applications/local/
|
|
9
|
+
* - unisphere (server) -> applications/server/
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.default = update;
|
|
13
|
+
const devkit_1 = require("@nx/devkit");
|
|
14
|
+
const child_process_1 = require("child_process");
|
|
15
|
+
/**
|
|
16
|
+
* Manually move all files from source to destination directory.
|
|
17
|
+
* This avoids using moveGenerator which relies on the Nx project graph cache.
|
|
18
|
+
* The project graph is read from disk, but during migrations the Tree (virtual FS)
|
|
19
|
+
* may have changes that aren't flushed to disk yet, causing stale data issues.
|
|
20
|
+
* Using manual move with Tree APIs ensures we always work with the correct state.
|
|
21
|
+
*/
|
|
22
|
+
function moveProjectFiles(tree, sourcePath, destPath) {
|
|
23
|
+
const filesToMove = [];
|
|
24
|
+
// Collect all files to move
|
|
25
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, sourcePath, (filePath) => {
|
|
26
|
+
const relativePath = filePath.substring(sourcePath.length);
|
|
27
|
+
const newPath = `${destPath}${relativePath}`;
|
|
28
|
+
filesToMove.push({ source: filePath, dest: newPath });
|
|
29
|
+
});
|
|
30
|
+
// Move files (create at dest, delete at source)
|
|
31
|
+
for (const { source, dest } of filesToMove) {
|
|
32
|
+
const content = tree.read(source);
|
|
33
|
+
if (content !== null) {
|
|
34
|
+
tree.write(dest, content);
|
|
35
|
+
tree.delete(source);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
devkit_1.logger.info(` Moved ${filesToMove.length} files from ${sourcePath} to ${destPath}`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Update project.json after moving to new location
|
|
42
|
+
*/
|
|
43
|
+
function updateProjectJsonAfterMove(tree, newPath, newProjectName) {
|
|
44
|
+
const projectJsonPath = `${newPath}/project.json`;
|
|
45
|
+
if (!tree.exists(projectJsonPath)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const projectJson = (0, devkit_1.readJson)(tree, projectJsonPath);
|
|
49
|
+
// Update name if different
|
|
50
|
+
if (projectJson.name !== newProjectName) {
|
|
51
|
+
projectJson.name = newProjectName;
|
|
52
|
+
}
|
|
53
|
+
// Update sourceRoot to match new location
|
|
54
|
+
projectJson.sourceRoot = `${newPath}/src`;
|
|
55
|
+
(0, devkit_1.writeJson)(tree, projectJsonPath, projectJson);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Reset Nx cache to ensure fresh project graph
|
|
59
|
+
* This is important before moving projects, as Nx caches project locations
|
|
60
|
+
*/
|
|
61
|
+
function resetNxCache() {
|
|
62
|
+
try {
|
|
63
|
+
devkit_1.logger.info('Resetting Nx cache to ensure fresh project graph...');
|
|
64
|
+
(0, child_process_1.execSync)('npx nx reset', {
|
|
65
|
+
stdio: 'pipe',
|
|
66
|
+
});
|
|
67
|
+
devkit_1.logger.info('Nx cache reset successfully');
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// Log but don't fail - cache reset is best effort
|
|
71
|
+
devkit_1.logger.warn('Could not reset Nx cache (continuing anyway): ' + error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the subdirectory based on distribution channel
|
|
76
|
+
*/
|
|
77
|
+
function getSubdirectory(distributionChannel) {
|
|
78
|
+
switch (distributionChannel) {
|
|
79
|
+
case 'none':
|
|
80
|
+
return 'local';
|
|
81
|
+
case 'unisphere':
|
|
82
|
+
return 'server';
|
|
83
|
+
default:
|
|
84
|
+
// Default to local for unknown channels
|
|
85
|
+
return 'local';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the actual Nx project name from project.json
|
|
90
|
+
*/
|
|
91
|
+
function getProjectNameFromProjectJson(tree, projectPath) {
|
|
92
|
+
const projectJsonPath = `${projectPath}/project.json`;
|
|
93
|
+
if (!tree.exists(projectJsonPath)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const projectJson = (0, devkit_1.readJson)(tree, projectJsonPath);
|
|
98
|
+
return projectJson.name || null;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if an application has already been migrated to the new subdirectory structure
|
|
106
|
+
*/
|
|
107
|
+
function isAlreadyMigrated(tree, name, distributionChannel) {
|
|
108
|
+
const subdirectory = getSubdirectory(distributionChannel);
|
|
109
|
+
const newPath = `unisphere/applications/${subdirectory}/${name}`;
|
|
110
|
+
// Check if the new path exists and has a project.json
|
|
111
|
+
return tree.exists(`${newPath}/project.json`);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Discover all applications in the workspace
|
|
115
|
+
*/
|
|
116
|
+
function discoverApplications(tree) {
|
|
117
|
+
if (!tree.exists('.unisphere')) {
|
|
118
|
+
devkit_1.logger.warn('No .unisphere file found, skipping migration');
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
|
|
122
|
+
const applications = [];
|
|
123
|
+
const applicationsConfig = unisphereConfig.elements?.applications || {};
|
|
124
|
+
for (const [name, config] of Object.entries(applicationsConfig)) {
|
|
125
|
+
const normalizedName = (0, devkit_1.names)(name).fileName;
|
|
126
|
+
const distributionChannel = config.distributionChannel || 'none';
|
|
127
|
+
// Get sourceRoot from .unisphere config, or fall back to default path
|
|
128
|
+
const sourceRoot = config.sourceRoot;
|
|
129
|
+
const currentPath = sourceRoot || `unisphere/applications/${normalizedName}`;
|
|
130
|
+
// Calculate target path
|
|
131
|
+
const subdirectory = getSubdirectory(distributionChannel);
|
|
132
|
+
const targetPath = `unisphere/applications/${subdirectory}/${normalizedName}`;
|
|
133
|
+
// Check if application is already at the target location (sourceRoot == targetPath)
|
|
134
|
+
if (currentPath === targetPath) {
|
|
135
|
+
devkit_1.logger.info(` Application ${name} is already at target location (${targetPath}), skipping`);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
// Check if already migrated to new location (project.json exists at new location)
|
|
139
|
+
if (isAlreadyMigrated(tree, normalizedName, distributionChannel)) {
|
|
140
|
+
devkit_1.logger.info(` Application ${name} already migrated to new location, skipping`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
// Check if target path already exists with actual content (project.json)
|
|
144
|
+
// If target exists but is empty (no project.json), clean it up and proceed
|
|
145
|
+
if (tree.exists(targetPath)) {
|
|
146
|
+
if (tree.exists(`${targetPath}/project.json`)) {
|
|
147
|
+
devkit_1.logger.info(` Application ${name} target path already exists with project.json (${targetPath}), skipping`);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// Empty directory - clean it up so migration can proceed
|
|
152
|
+
devkit_1.logger.info(` Application ${name} target path exists but is empty, cleaning up: ${targetPath}`);
|
|
153
|
+
tree.delete(targetPath);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (!tree.exists(currentPath)) {
|
|
157
|
+
devkit_1.logger.warn(`Application ${name} not found at ${currentPath}, skipping`);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
// Read actual project name from project.json instead of assuming it
|
|
161
|
+
const actualProjectName = getProjectNameFromProjectJson(tree, currentPath);
|
|
162
|
+
if (!actualProjectName) {
|
|
163
|
+
devkit_1.logger.warn(`Application ${name} has no project.json or missing name at ${currentPath}, skipping`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
devkit_1.logger.info(` Found application: ${normalizedName} (Nx project: ${actualProjectName})`);
|
|
167
|
+
applications.push({
|
|
168
|
+
name: normalizedName,
|
|
169
|
+
distributionChannel: distributionChannel,
|
|
170
|
+
currentPath,
|
|
171
|
+
currentNxProjectName: actualProjectName,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return applications;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Calculate migration target for an application
|
|
178
|
+
*/
|
|
179
|
+
function calculateMigrationTarget(app) {
|
|
180
|
+
const subdirectory = getSubdirectory(app.distributionChannel);
|
|
181
|
+
const newPath = `unisphere/applications/${subdirectory}/${app.name}`;
|
|
182
|
+
return {
|
|
183
|
+
application: app,
|
|
184
|
+
newPath,
|
|
185
|
+
newNxProjectName: app.currentNxProjectName,
|
|
186
|
+
subdirectory,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Validate migration preconditions
|
|
191
|
+
*/
|
|
192
|
+
function validateMigrationPreconditions(tree, targets) {
|
|
193
|
+
// Check destination directories don't conflict
|
|
194
|
+
const destinations = new Set();
|
|
195
|
+
for (const target of targets) {
|
|
196
|
+
if (destinations.has(target.newPath)) {
|
|
197
|
+
throw new Error(`Duplicate destination path: ${target.newPath}`);
|
|
198
|
+
}
|
|
199
|
+
destinations.add(target.newPath);
|
|
200
|
+
// Check destination doesn't already exist
|
|
201
|
+
if (tree.exists(target.newPath)) {
|
|
202
|
+
throw new Error(`Destination already exists: ${target.newPath}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Check all source applications exist
|
|
206
|
+
for (const target of targets) {
|
|
207
|
+
if (!tree.exists(target.application.currentPath)) {
|
|
208
|
+
throw new Error(`Source application not found: ${target.application.currentPath}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Update .unisphere configuration sourceRoot
|
|
214
|
+
*/
|
|
215
|
+
function updateUnisphereSourceRoot(tree, name, newPath) {
|
|
216
|
+
const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
|
|
217
|
+
if (unisphereConfig.elements?.applications?.[name]) {
|
|
218
|
+
const applicationConfig = unisphereConfig.elements.applications[name];
|
|
219
|
+
applicationConfig.sourceRoot = newPath;
|
|
220
|
+
(0, devkit_1.writeJson)(tree, '.unisphere', unisphereConfig);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Update package-lock.json paths
|
|
225
|
+
*/
|
|
226
|
+
function updatePackageLockPaths(tree, oldPath, newPath) {
|
|
227
|
+
if (!tree.exists('package-lock.json')) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const packageLock = (0, devkit_1.readJson)(tree, 'package-lock.json');
|
|
231
|
+
let updated = false;
|
|
232
|
+
if (packageLock.packages) {
|
|
233
|
+
const newPackages = {};
|
|
234
|
+
for (const [key, value] of Object.entries(packageLock.packages)) {
|
|
235
|
+
if (key === oldPath) {
|
|
236
|
+
newPackages[newPath] = value;
|
|
237
|
+
updated = true;
|
|
238
|
+
}
|
|
239
|
+
else if (key.startsWith(oldPath + '/')) {
|
|
240
|
+
// Handle nested node_modules paths if any
|
|
241
|
+
newPackages[key.replace(oldPath, newPath)] = value;
|
|
242
|
+
updated = true;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
newPackages[key] = value;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (updated) {
|
|
249
|
+
packageLock.packages = newPackages;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Update resolved paths if they exist
|
|
253
|
+
if (packageLock.packages) {
|
|
254
|
+
for (const value of Object.values(packageLock.packages)) {
|
|
255
|
+
if (value && typeof value === 'object' && 'resolved' in value) {
|
|
256
|
+
const pkg = value;
|
|
257
|
+
if (pkg.resolved === oldPath) {
|
|
258
|
+
pkg.resolved = newPath;
|
|
259
|
+
updated = true;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (updated) {
|
|
265
|
+
(0, devkit_1.writeJson)(tree, 'package-lock.json', packageLock);
|
|
266
|
+
devkit_1.logger.info(` Updated package-lock.json paths`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Fix .eslintrc.json extends path after moving to subdirectory
|
|
271
|
+
* Path changes from ../../../.eslintrc.json to ../../../../.eslintrc.json
|
|
272
|
+
*/
|
|
273
|
+
function fixEslintConfigPath(tree, applicationPath) {
|
|
274
|
+
const eslintConfigPath = `${applicationPath}/.eslintrc.json`;
|
|
275
|
+
if (!tree.exists(eslintConfigPath)) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const eslintConfig = (0, devkit_1.readJson)(tree, eslintConfigPath);
|
|
279
|
+
if (eslintConfig.extends && Array.isArray(eslintConfig.extends)) {
|
|
280
|
+
const updatedExtends = eslintConfig.extends.map((ext) => {
|
|
281
|
+
// Update the relative path to root .eslintrc.json
|
|
282
|
+
if (ext === '../../../.eslintrc.json') {
|
|
283
|
+
return '../../../../.eslintrc.json';
|
|
284
|
+
}
|
|
285
|
+
return ext;
|
|
286
|
+
});
|
|
287
|
+
eslintConfig.extends = updatedExtends;
|
|
288
|
+
(0, devkit_1.writeJson)(tree, eslintConfigPath, eslintConfig);
|
|
289
|
+
devkit_1.logger.info(` Fixed .eslintrc.json extends path`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Fix tsconfig.json extends path after moving to subdirectory
|
|
294
|
+
* Path changes from ../../../tsconfig.base.json to ../../../../tsconfig.base.json
|
|
295
|
+
*/
|
|
296
|
+
function fixTsconfigJsonPath(tree, applicationPath) {
|
|
297
|
+
const tsconfigPath = `${applicationPath}/tsconfig.json`;
|
|
298
|
+
if (!tree.exists(tsconfigPath)) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const tsconfig = (0, devkit_1.readJson)(tree, tsconfigPath);
|
|
302
|
+
if (tsconfig.extends === '../../../tsconfig.base.json') {
|
|
303
|
+
tsconfig.extends = '../../../../tsconfig.base.json';
|
|
304
|
+
(0, devkit_1.writeJson)(tree, tsconfigPath, tsconfig);
|
|
305
|
+
devkit_1.logger.info(` Fixed tsconfig.json extends path`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Fix jest.config.ts paths after moving to subdirectory
|
|
310
|
+
* - preset path changes from ../../../jest.preset.js to ../../../../jest.preset.js
|
|
311
|
+
* - coverageDirectory path needs extra level
|
|
312
|
+
*/
|
|
313
|
+
function fixJestConfigPath(tree, applicationPath, newPath) {
|
|
314
|
+
const jestConfigPath = `${applicationPath}/jest.config.ts`;
|
|
315
|
+
if (!tree.exists(jestConfigPath)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
let content = tree.read(jestConfigPath, 'utf-8');
|
|
319
|
+
if (!content) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
let updated = false;
|
|
323
|
+
// Fix preset path
|
|
324
|
+
if (content.includes("preset: '../../../jest.preset.js'")) {
|
|
325
|
+
content = content.replace("preset: '../../../jest.preset.js'", "preset: '../../../../jest.preset.js'");
|
|
326
|
+
updated = true;
|
|
327
|
+
}
|
|
328
|
+
// Fix coverageDirectory path - update to use the new path
|
|
329
|
+
const coverageDirRegex = /coverageDirectory:\s*['"]\.\.\/\.\.\/\.\.\/coverage\/[^'"]+['"]/;
|
|
330
|
+
if (coverageDirRegex.test(content)) {
|
|
331
|
+
content = content.replace(coverageDirRegex, `coverageDirectory: '../../../../coverage/${newPath}'`);
|
|
332
|
+
updated = true;
|
|
333
|
+
}
|
|
334
|
+
if (updated) {
|
|
335
|
+
tree.write(jestConfigPath, content);
|
|
336
|
+
devkit_1.logger.info(` Fixed jest.config.ts paths`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Fix project.json $schema path after moving to subdirectory
|
|
341
|
+
* Path changes from ../../../node_modules/... to ../../../../node_modules/...
|
|
342
|
+
*/
|
|
343
|
+
function fixProjectJsonPath(tree, applicationPath, newPath) {
|
|
344
|
+
const projectJsonPath = `${applicationPath}/project.json`;
|
|
345
|
+
if (!tree.exists(projectJsonPath)) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const projectJson = (0, devkit_1.readJson)(tree, projectJsonPath);
|
|
349
|
+
let updated = false;
|
|
350
|
+
// Fix $schema path
|
|
351
|
+
if (projectJson['$schema'] === '../../../node_modules/nx/schemas/project-schema.json') {
|
|
352
|
+
projectJson['$schema'] = '../../../../node_modules/nx/schemas/project-schema.json';
|
|
353
|
+
updated = true;
|
|
354
|
+
}
|
|
355
|
+
// Update sourceRoot to use the new path
|
|
356
|
+
if (projectJson.sourceRoot && !projectJson.sourceRoot.includes(newPath)) {
|
|
357
|
+
projectJson.sourceRoot = `${newPath}/src`;
|
|
358
|
+
updated = true;
|
|
359
|
+
}
|
|
360
|
+
if (updated) {
|
|
361
|
+
(0, devkit_1.writeJson)(tree, projectJsonPath, projectJson);
|
|
362
|
+
devkit_1.logger.info(` Fixed project.json paths`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Fix webpack.config.js output path after moving to subdirectory
|
|
367
|
+
* Path changes from ../../../dist/unisphere/applications/... to ../../../../dist/...
|
|
368
|
+
*/
|
|
369
|
+
function fixWebpackConfigPath(tree, applicationPath, newPath) {
|
|
370
|
+
const webpackConfigPath = `${applicationPath}/webpack.config.js`;
|
|
371
|
+
if (!tree.exists(webpackConfigPath)) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
let content = tree.read(webpackConfigPath, 'utf-8');
|
|
375
|
+
if (!content) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
let updated = false;
|
|
379
|
+
// Fix output path - look for various patterns
|
|
380
|
+
const outputPathRegex = /path:\s*join\(__dirname,\s*['"]\.\.\/\.\.\/\.\.\/dist\/unisphere\/applications\/[^'"]+['"]\)/;
|
|
381
|
+
if (outputPathRegex.test(content)) {
|
|
382
|
+
content = content.replace(outputPathRegex, `path: join(__dirname, '../../../../dist/${newPath}')`);
|
|
383
|
+
updated = true;
|
|
384
|
+
}
|
|
385
|
+
if (updated) {
|
|
386
|
+
tree.write(webpackConfigPath, content);
|
|
387
|
+
devkit_1.logger.info(` Fixed webpack.config.js output path`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Update tsconfig.base.json paths for the application
|
|
392
|
+
*/
|
|
393
|
+
function updateTsConfigBasePaths(tree, oldPath, newPath) {
|
|
394
|
+
if (!tree.exists('tsconfig.base.json')) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
398
|
+
if (!tsconfigBase.compilerOptions?.paths) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
let updated = false;
|
|
402
|
+
for (const [key, paths] of Object.entries(tsconfigBase.compilerOptions.paths)) {
|
|
403
|
+
if (Array.isArray(paths)) {
|
|
404
|
+
const newPaths = paths.map((p) => {
|
|
405
|
+
if (p.startsWith(oldPath + '/') || p === oldPath) {
|
|
406
|
+
updated = true;
|
|
407
|
+
return p.replace(oldPath, newPath);
|
|
408
|
+
}
|
|
409
|
+
return p;
|
|
410
|
+
});
|
|
411
|
+
tsconfigBase.compilerOptions.paths[key] = newPaths;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (updated) {
|
|
415
|
+
(0, devkit_1.writeJson)(tree, 'tsconfig.base.json', tsconfigBase);
|
|
416
|
+
devkit_1.logger.info(` Updated tsconfig.base.json paths`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Update root package.json scripts that reference the application
|
|
421
|
+
*/
|
|
422
|
+
function updateRootPackageJsonScripts(tree, oldPath, newPath) {
|
|
423
|
+
if (!tree.exists('package.json')) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
427
|
+
if (!packageJson.scripts) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
let updated = false;
|
|
431
|
+
for (const [scriptName, scriptValue] of Object.entries(packageJson.scripts)) {
|
|
432
|
+
if (typeof scriptValue === 'string' && scriptValue.includes(oldPath)) {
|
|
433
|
+
packageJson.scripts[scriptName] = scriptValue.replace(new RegExp(oldPath.replace(/[/\\]/g, '[\\\\/]'), 'g'), newPath);
|
|
434
|
+
updated = true;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (updated) {
|
|
438
|
+
(0, devkit_1.writeJson)(tree, 'package.json', packageJson);
|
|
439
|
+
devkit_1.logger.info(` Updated root package.json scripts`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Migrate a single application
|
|
444
|
+
*/
|
|
445
|
+
async function migrateApplication(tree, target) {
|
|
446
|
+
const { application: app, newPath, newNxProjectName } = target;
|
|
447
|
+
devkit_1.logger.info(`Moving ${app.name} to ${target.subdirectory}/`);
|
|
448
|
+
devkit_1.logger.info(` From: ${app.currentPath}`);
|
|
449
|
+
devkit_1.logger.info(` To: ${newPath}`);
|
|
450
|
+
devkit_1.logger.info(` Nx project: ${app.currentNxProjectName}`);
|
|
451
|
+
// Verify source exists before attempting move (safety check)
|
|
452
|
+
const sourceProjectJson = `${app.currentPath}/project.json`;
|
|
453
|
+
if (!tree.exists(sourceProjectJson)) {
|
|
454
|
+
devkit_1.logger.warn(` Source project.json not found at ${sourceProjectJson}, skipping`);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
// Step 1: Manually move files using Tree APIs
|
|
458
|
+
// We avoid moveGenerator because it relies on the Nx project graph cache,
|
|
459
|
+
// which reads from disk. During migrations, the packages migration may have
|
|
460
|
+
// already moved packages in the Tree but those changes aren't flushed to disk
|
|
461
|
+
// yet, causing moveGenerator to use stale project locations.
|
|
462
|
+
// Since applications don't need import path updates (they're entry points),
|
|
463
|
+
// manual move is safe and reliable.
|
|
464
|
+
try {
|
|
465
|
+
moveProjectFiles(tree, app.currentPath, newPath);
|
|
466
|
+
updateProjectJsonAfterMove(tree, newPath, newNxProjectName);
|
|
467
|
+
devkit_1.logger.info(` Project moved successfully`);
|
|
468
|
+
// Reset Nx cache after move to ensure fresh project graph for next operations
|
|
469
|
+
resetNxCache();
|
|
470
|
+
}
|
|
471
|
+
catch (error) {
|
|
472
|
+
devkit_1.logger.error(` Failed to move project: ${error}`);
|
|
473
|
+
devkit_1.logger.error(` Source path: ${app.currentPath}`);
|
|
474
|
+
devkit_1.logger.error(` Destination path: ${newPath}`);
|
|
475
|
+
devkit_1.logger.error(` Project name: ${app.currentNxProjectName}`);
|
|
476
|
+
throw error;
|
|
477
|
+
}
|
|
478
|
+
// Step 2: Update .unisphere configuration
|
|
479
|
+
updateUnisphereSourceRoot(tree, app.name, newPath);
|
|
480
|
+
devkit_1.logger.info(` Updated .unisphere sourceRoot`);
|
|
481
|
+
// Step 3: Update package-lock.json
|
|
482
|
+
updatePackageLockPaths(tree, app.currentPath, newPath);
|
|
483
|
+
// Step 4: Fix .eslintrc.json extends path
|
|
484
|
+
fixEslintConfigPath(tree, newPath);
|
|
485
|
+
// Step 5: Fix tsconfig.json extends path
|
|
486
|
+
fixTsconfigJsonPath(tree, newPath);
|
|
487
|
+
// Step 6: Fix jest.config.ts paths
|
|
488
|
+
fixJestConfigPath(tree, newPath, newPath);
|
|
489
|
+
// Step 7: Fix project.json paths
|
|
490
|
+
fixProjectJsonPath(tree, newPath, newPath);
|
|
491
|
+
// Step 8: Fix webpack.config.js output path
|
|
492
|
+
fixWebpackConfigPath(tree, newPath, newPath);
|
|
493
|
+
// Step 9: Update tsconfig.base.json paths
|
|
494
|
+
updateTsConfigBasePaths(tree, app.currentPath, newPath);
|
|
495
|
+
// Step 10: Update root package.json scripts
|
|
496
|
+
updateRootPackageJsonScripts(tree, app.currentPath, newPath);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Main migration function
|
|
500
|
+
*/
|
|
501
|
+
async function update(tree) {
|
|
502
|
+
devkit_1.logger.info('');
|
|
503
|
+
devkit_1.logger.info('========================================');
|
|
504
|
+
devkit_1.logger.info('Reorganizing applications by distribution channel');
|
|
505
|
+
devkit_1.logger.info('========================================');
|
|
506
|
+
devkit_1.logger.info('');
|
|
507
|
+
// Phase 0: Reset Nx cache to ensure fresh project graph
|
|
508
|
+
resetNxCache();
|
|
509
|
+
devkit_1.logger.info('');
|
|
510
|
+
// Phase 1: Discover applications
|
|
511
|
+
const applications = discoverApplications(tree);
|
|
512
|
+
if (applications.length === 0) {
|
|
513
|
+
devkit_1.logger.info('No applications found to migrate');
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
devkit_1.logger.info(`Found ${applications.length} application(s) to reorganize`);
|
|
517
|
+
// Phase 2: Calculate migration targets
|
|
518
|
+
const targets = applications.map(calculateMigrationTarget);
|
|
519
|
+
// Group by subdirectory for logging
|
|
520
|
+
const byChannel = {
|
|
521
|
+
local: targets.filter((t) => t.subdirectory === 'local'),
|
|
522
|
+
server: targets.filter((t) => t.subdirectory === 'server'),
|
|
523
|
+
};
|
|
524
|
+
devkit_1.logger.info('');
|
|
525
|
+
devkit_1.logger.info('Migration plan:');
|
|
526
|
+
devkit_1.logger.info(` - local/ (distributionChannel: none): ${byChannel['local'].length} application(s)`);
|
|
527
|
+
devkit_1.logger.info(` - server/ (distributionChannel: unisphere): ${byChannel['server'].length} application(s)`);
|
|
528
|
+
devkit_1.logger.info('');
|
|
529
|
+
// Phase 3: Validate preconditions
|
|
530
|
+
try {
|
|
531
|
+
validateMigrationPreconditions(tree, targets);
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
devkit_1.logger.error(`Migration precondition failed: ${error}`);
|
|
535
|
+
throw error;
|
|
536
|
+
}
|
|
537
|
+
// Phase 4: Execute migrations SEQUENTIALLY
|
|
538
|
+
let migrated = 0;
|
|
539
|
+
for (const target of targets) {
|
|
540
|
+
try {
|
|
541
|
+
await migrateApplication(tree, target);
|
|
542
|
+
migrated++;
|
|
543
|
+
devkit_1.logger.info(` [${migrated}/${targets.length}] Migrated ${target.application.name}`);
|
|
544
|
+
devkit_1.logger.info('');
|
|
545
|
+
}
|
|
546
|
+
catch (error) {
|
|
547
|
+
devkit_1.logger.error(`Failed to migrate ${target.application.name}: ${error}`);
|
|
548
|
+
throw error;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
// Format all files at the end
|
|
552
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
553
|
+
devkit_1.logger.info('');
|
|
554
|
+
devkit_1.logger.info('========================================');
|
|
555
|
+
devkit_1.logger.info(`Successfully reorganized ${migrated} application(s)`);
|
|
556
|
+
devkit_1.logger.info('========================================');
|
|
557
|
+
devkit_1.logger.info('');
|
|
558
|
+
devkit_1.logger.info('Next steps:');
|
|
559
|
+
devkit_1.logger.info(' 1. Run: npm install');
|
|
560
|
+
devkit_1.logger.info(' 2. Run: npm run build');
|
|
561
|
+
devkit_1.logger.info(' 3. Verify all imports are updated');
|
|
562
|
+
devkit_1.logger.info('');
|
|
563
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration: Reorganize Packages by Distribution Channel
|
|
3
|
+
*
|
|
4
|
+
* This migration reorganizes packages based on their `distributionChannel` property in `.unisphere`:
|
|
5
|
+
*
|
|
6
|
+
* Directory structure:
|
|
7
|
+
* - none -> packages/local/
|
|
8
|
+
* - github -> packages/kaltura-corp/
|
|
9
|
+
* - npm -> packages/unisphere/
|
|
10
|
+
* - kaltura-ai -> packages/kaltura-ai/
|
|
11
|
+
*
|
|
12
|
+
* Package scope changes:
|
|
13
|
+
* - none -> @local/{pkg}
|
|
14
|
+
* - github -> @kaltura-corp/unisphere-{pkg} (replaces @kaltura/unisphere-{pkg})
|
|
15
|
+
* - npm -> @unisphere/{pkg} (unchanged)
|
|
16
|
+
* - kaltura-ai -> @kaltura-ai/{pkg}
|
|
17
|
+
*/
|
|
18
|
+
import { Tree } from '@nx/devkit';
|
|
19
|
+
/**
|
|
20
|
+
* Main migration function
|
|
21
|
+
*/
|
|
22
|
+
export default function update(tree: Tree): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=reorganize-packages-by-distribution-channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reorganize-packages-by-distribution-channel.d.ts","sourceRoot":"","sources":["../../../src/migrations/3-0-0/reorganize-packages-by-distribution-channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,IAAI,EAML,MAAM,YAAY,CAAC;AA8qBpB;;GAEG;AACH,wBAA8B,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CA6E9D"}
|