@unisphere/nx 2.2.2 → 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.
Files changed (130) hide show
  1. package/dist/generators/add-application/add-application.d.ts.map +1 -1
  2. package/dist/generators/add-application/add-application.js +76 -59
  3. package/dist/generators/add-application/schema.d.ts +3 -1
  4. package/dist/generators/add-application/schema.json +4 -8
  5. package/dist/generators/add-application/templates/default/.env-template +6 -0
  6. package/dist/generators/add-application/templates/default/.eslintrc.json +1 -1
  7. package/dist/generators/add-application/templates/default/jest.config.ts +3 -3
  8. package/dist/generators/add-application/templates/default/project.json.template +2 -2
  9. package/dist/generators/add-application/templates/default/readme.md.template +11 -0
  10. package/dist/generators/add-application/templates/default/src/app/app.tsx.template +77 -77
  11. package/dist/generators/add-application/templates/default/tsconfig.json +1 -1
  12. package/dist/generators/add-application/templates/default/webpack.config.js.template +6 -1
  13. package/dist/generators/add-package/README.md +2 -2
  14. package/dist/generators/add-package/add-package.d.ts.map +1 -1
  15. package/dist/generators/add-package/add-package.js +11 -23
  16. package/dist/generators/add-package/schema.d.ts +1 -1
  17. package/dist/generators/add-package/schema.json +27 -19
  18. package/dist/generators/add-package/templates/new-package/.eslintrc.json +1 -1
  19. package/dist/generators/add-package/templates/new-package/package.json.template +0 -1
  20. package/dist/generators/add-package/templates/new-package/project.json.template +4 -4
  21. package/dist/generators/add-package/templates/new-package/rollup.config.js +1 -1
  22. package/dist/generators/add-package/templates/new-package/tsconfig.json +1 -1
  23. package/dist/generators/add-package/templates/new-package/tsconfig.lib.json.template +1 -1
  24. package/dist/generators/add-package/templates/new-package/tsconfig.spec.json +1 -1
  25. package/dist/generators/add-runtime/add-runtime.d.ts.map +1 -1
  26. package/dist/generators/add-runtime/add-runtime.js +62 -9
  27. package/dist/generators/add-runtime/schema.d.ts +1 -0
  28. package/dist/generators/add-runtime/schema.json +1 -9
  29. package/dist/generators/add-runtime/templates/new-runtime/src/lib/create-factory.tsx.template +4 -4
  30. package/dist/generators/add-runtime/templates/new-runtime/src/lib/runtime.tsx.template +26 -2
  31. package/dist/generators/add-visual/add-visual.d.ts +1 -1
  32. package/dist/generators/add-visual/add-visual.d.ts.map +1 -1
  33. package/dist/generators/add-visual/add-visual.js +108 -15
  34. package/dist/generators/add-visual/schema.d.ts +3 -3
  35. package/dist/generators/add-visual/schema.json +2 -24
  36. package/dist/generators/dependency-config.d.ts.map +1 -1
  37. package/dist/generators/dependency-config.js +1 -0
  38. package/dist/generators/internal-dev-runner/generator.d.ts +3 -0
  39. package/dist/generators/internal-dev-runner/generator.d.ts.map +1 -0
  40. package/dist/generators/internal-dev-runner/generator.js +45 -0
  41. package/dist/generators/internal-dev-runner/schema.json +9 -0
  42. package/dist/generators/remove/remove.d.ts +19 -0
  43. package/dist/generators/remove/remove.d.ts.map +1 -0
  44. package/dist/generators/remove/remove.js +270 -0
  45. package/dist/generators/remove/schema.d.ts +4 -0
  46. package/dist/generators/remove/schema.json +38 -0
  47. package/dist/generators/rename-package/rename-package.d.ts +3 -0
  48. package/dist/generators/rename-package/rename-package.d.ts.map +1 -1
  49. package/dist/generators/rename-package/rename-package.js +139 -20
  50. package/dist/generators/utils.d.ts +30 -1
  51. package/dist/generators/utils.d.ts.map +1 -1
  52. package/dist/generators/utils.js +258 -7
  53. package/dist/migrations/1-22-0/patches/@changesets+cli+2.29.7.patch +36 -4
  54. package/dist/migrations/3-0-0/add-define-plugin-to-webpack.d.ts +3 -0
  55. package/dist/migrations/3-0-0/add-define-plugin-to-webpack.d.ts.map +1 -0
  56. package/dist/migrations/3-0-0/add-define-plugin-to-webpack.js +233 -0
  57. package/dist/migrations/3-0-0/add-env-to-application-gitignore.d.ts +3 -0
  58. package/dist/migrations/3-0-0/add-env-to-application-gitignore.d.ts.map +1 -0
  59. package/dist/migrations/3-0-0/add-env-to-application-gitignore.js +117 -0
  60. package/dist/migrations/3-0-0/fix-vite-config-cache-paths.d.ts +10 -0
  61. package/dist/migrations/3-0-0/fix-vite-config-cache-paths.d.ts.map +1 -0
  62. package/dist/migrations/3-0-0/fix-vite-config-cache-paths.js +66 -0
  63. package/dist/migrations/3-0-0/patches/@changesets+cli+2.29.7.patch +88 -0
  64. package/dist/migrations/3-0-0/post-cleanup-empty-directories.d.ts +12 -0
  65. package/dist/migrations/3-0-0/post-cleanup-empty-directories.d.ts.map +1 -0
  66. package/dist/migrations/3-0-0/post-cleanup-empty-directories.js +62 -0
  67. package/dist/migrations/3-0-0/pre-cleanup-empty-directories.d.ts +14 -0
  68. package/dist/migrations/3-0-0/pre-cleanup-empty-directories.d.ts.map +1 -0
  69. package/dist/migrations/3-0-0/pre-cleanup-empty-directories.js +105 -0
  70. package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.d.ts +3 -0
  71. package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.d.ts.map +1 -0
  72. package/dist/migrations/3-0-0/remove-kaltura-tools-to-pre-install.js +21 -0
  73. package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.d.ts +9 -0
  74. package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.d.ts.map +1 -0
  75. package/dist/migrations/3-0-0/remove-private-from-applications-and-runtimes.js +88 -0
  76. package/dist/migrations/3-0-0/remove-publish-config-from-packages.d.ts +9 -0
  77. package/dist/migrations/3-0-0/remove-publish-config-from-packages.d.ts.map +1 -0
  78. package/dist/migrations/3-0-0/remove-publish-config-from-packages.js +45 -0
  79. package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.d.ts +15 -0
  80. package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.d.ts.map +1 -0
  81. package/dist/migrations/3-0-0/reorganize-applications-by-distribution-channel.js +563 -0
  82. package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.d.ts +23 -0
  83. package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.d.ts.map +1 -0
  84. package/dist/migrations/3-0-0/reorganize-packages-by-distribution-channel.js +645 -0
  85. package/dist/migrations/3-0-0/replace-github-workflow.d.ts +3 -0
  86. package/dist/migrations/3-0-0/replace-github-workflow.d.ts.map +1 -0
  87. package/dist/migrations/3-0-0/replace-github-workflow.js +48 -0
  88. package/dist/migrations/3-0-0/sync-package-lock.d.ts +10 -0
  89. package/dist/migrations/3-0-0/sync-package-lock.d.ts.map +1 -0
  90. package/dist/migrations/3-0-0/sync-package-lock.js +26 -0
  91. package/dist/migrations/3-0-0/templates/_publish-artifacts.template +363 -0
  92. package/dist/migrations/3-0-0/templates/cicd.template +89 -0
  93. package/dist/migrations/3-0-0/update-changeset-patch.d.ts +3 -0
  94. package/dist/migrations/3-0-0/update-changeset-patch.d.ts.map +1 -0
  95. package/dist/migrations/3-0-0/update-changeset-patch.js +31 -0
  96. package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.d.ts +21 -0
  97. package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.d.ts.map +1 -0
  98. package/dist/migrations/3-0-0/upgrade-schema-to-2-0-0.js +105 -0
  99. package/dist/migrations/utils/has-react-dependency.d.ts +14 -0
  100. package/dist/migrations/utils/has-react-dependency.d.ts.map +1 -0
  101. package/dist/migrations/utils/has-react-dependency.js +72 -0
  102. package/dist/shared.d.ts +6 -0
  103. package/dist/shared.d.ts.map +1 -0
  104. package/dist/shared.js +9 -0
  105. package/generators.json +12 -1
  106. package/migrations.json +117 -0
  107. package/package.json +3 -2
  108. package/dist/generators/add-application/templates/local-dev-playground/.babelrc +0 -11
  109. package/dist/generators/add-application/templates/local-dev-playground/.eslintrc.json +0 -22
  110. package/dist/generators/add-application/templates/local-dev-playground/jest.config.ts +0 -11
  111. package/dist/generators/add-application/templates/local-dev-playground/package.json +0 -6
  112. package/dist/generators/add-application/templates/local-dev-playground/project.json +0 -9
  113. package/dist/generators/add-application/templates/local-dev-playground/src/app/app.tsx.template +0 -212
  114. package/dist/generators/add-application/templates/local-dev-playground/src/app/components/header.tsx.template +0 -123
  115. package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings-buttons.tsx +0 -57
  116. package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings-form.tsx +0 -108
  117. package/dist/generators/add-application/templates/local-dev-playground/src/app/components/settings.tsx +0 -74
  118. package/dist/generators/add-application/templates/local-dev-playground/src/app/configuration-provider.tsx +0 -163
  119. package/dist/generators/add-application/templates/local-dev-playground/src/app/definitions.ts +0 -25
  120. package/dist/generators/add-application/templates/local-dev-playground/src/app/utils/merge-deep.ts +0 -31
  121. package/dist/generators/add-application/templates/local-dev-playground/src/favicon.ico +0 -0
  122. package/dist/generators/add-application/templates/local-dev-playground/src/index.html +0 -17
  123. package/dist/generators/add-application/templates/local-dev-playground/src/main.tsx +0 -13
  124. package/dist/generators/add-application/templates/local-dev-playground/src/styles.css +0 -0
  125. package/dist/generators/add-application/templates/local-dev-playground/tsconfig.app.json +0 -24
  126. package/dist/generators/add-application/templates/local-dev-playground/tsconfig.json +0 -20
  127. package/dist/generators/add-application/templates/local-dev-playground/tsconfig.spec.json +0 -25
  128. package/dist/generators/add-application/templates/local-dev-playground/webpack.config.js +0 -33
  129. /package/dist/generators/add-runtime/templates/{core-templates → types-templates}/__runtimeName__-runtime/index.ts.template +0 -0
  130. /package/dist/generators/add-runtime/templates/{core-templates → types-templates}/__runtimeName__-runtime/runtime-types.ts.template +0 -0
@@ -0,0 +1,645 @@
1
+ "use strict";
2
+ /**
3
+ * Migration: Reorganize Packages by Distribution Channel
4
+ *
5
+ * This migration reorganizes packages based on their `distributionChannel` property in `.unisphere`:
6
+ *
7
+ * Directory structure:
8
+ * - none -> packages/local/
9
+ * - github -> packages/kaltura-corp/
10
+ * - npm -> packages/unisphere/
11
+ * - kaltura-ai -> packages/kaltura-ai/
12
+ *
13
+ * Package scope changes:
14
+ * - none -> @local/{pkg}
15
+ * - github -> @kaltura-corp/unisphere-{pkg} (replaces @kaltura/unisphere-{pkg})
16
+ * - npm -> @unisphere/{pkg} (unchanged)
17
+ * - kaltura-ai -> @kaltura-ai/{pkg}
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.default = update;
21
+ const devkit_1 = require("@nx/devkit");
22
+ const generators_1 = require("@nx/workspace/generators");
23
+ const child_process_1 = require("child_process");
24
+ const fs_1 = require("fs");
25
+ const path_1 = require("path");
26
+ const has_react_dependency_1 = require("../utils/has-react-dependency");
27
+ /**
28
+ * Reset Nx cache to ensure fresh project graph
29
+ * This is important before moving projects, as Nx caches project locations
30
+ */
31
+ function resetNxCache() {
32
+ try {
33
+ devkit_1.logger.info('Resetting Nx cache to ensure fresh project graph...');
34
+ (0, child_process_1.execSync)('npx nx reset', {
35
+ stdio: 'pipe',
36
+ });
37
+ devkit_1.logger.info('Nx cache reset successfully');
38
+ }
39
+ catch (error) {
40
+ // Log but don't fail - cache reset is best effort
41
+ devkit_1.logger.warn('Could not reset Nx cache (continuing anyway): ' + error);
42
+ }
43
+ }
44
+ /**
45
+ * Check if a package name needs the "-react" suffix and return the new name.
46
+ * Following the convention in validateReactNaming() from dependency-config.ts.
47
+ */
48
+ function applyReactSuffixIfNeeded(name, hasReact) {
49
+ if (hasReact && !name.endsWith('-react')) {
50
+ return `${name}-react`;
51
+ }
52
+ return name;
53
+ }
54
+ /**
55
+ * Infer distribution channel from the current sourceRoot path.
56
+ * This is needed when distributionChannel is not explicitly set in .unisphere config,
57
+ * but the package is already in a subdirectory from a previous migration or manual move.
58
+ */
59
+ function inferDistributionChannelFromPath(sourceRoot) {
60
+ if (sourceRoot.includes('/local/') || sourceRoot.includes('/packages/local/')) {
61
+ return 'none';
62
+ }
63
+ if (sourceRoot.includes('/kaltura-corp/') || sourceRoot.includes('/packages/kaltura-corp/')) {
64
+ return 'github';
65
+ }
66
+ if (sourceRoot.includes('/unisphere/') || sourceRoot.includes('/packages/unisphere/')) {
67
+ return 'npm';
68
+ }
69
+ if (sourceRoot.includes('/kaltura-ai/') || sourceRoot.includes('/packages/kaltura-ai/')) {
70
+ return 'kaltura-ai';
71
+ }
72
+ return null;
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 'github':
82
+ return 'kaltura-corp';
83
+ case 'npm':
84
+ return 'unisphere';
85
+ case 'kaltura-ai':
86
+ return 'kaltura-ai';
87
+ default:
88
+ return 'local';
89
+ }
90
+ }
91
+ /**
92
+ * Calculate the new package.json name based on distribution channel
93
+ */
94
+ function calculateNewPackageJsonName(currentPackageJsonName, distributionChannel) {
95
+ // Extract the base package name (after the scope and any prefixes)
96
+ let baseName;
97
+ if (currentPackageJsonName.startsWith('@kaltura/unisphere-')) {
98
+ baseName = currentPackageJsonName.replace('@kaltura/unisphere-', '');
99
+ }
100
+ else if (currentPackageJsonName.startsWith('@unisphere/')) {
101
+ baseName = currentPackageJsonName.replace('@unisphere/', '');
102
+ }
103
+ else if (currentPackageJsonName.startsWith('@kaltura-corp/unisphere-')) {
104
+ baseName = currentPackageJsonName.replace('@kaltura-corp/unisphere-', '');
105
+ }
106
+ else if (currentPackageJsonName.startsWith('@unisphere-corp/')) {
107
+ baseName = currentPackageJsonName.replace('@unisphere-corp/', '');
108
+ }
109
+ else if (currentPackageJsonName.startsWith('@local/')) {
110
+ baseName = currentPackageJsonName.replace('@local/', '');
111
+ }
112
+ else if (currentPackageJsonName.startsWith('@kaltura-ai/')) {
113
+ baseName = currentPackageJsonName.replace('@kaltura-ai/', '');
114
+ }
115
+ else {
116
+ // No scope, use as-is
117
+ baseName = currentPackageJsonName;
118
+ }
119
+ switch (distributionChannel) {
120
+ case 'npm':
121
+ return `@unisphere/${baseName}`;
122
+ case 'github':
123
+ return `@kaltura-corp/unisphere-${baseName}`;
124
+ case 'kaltura-ai':
125
+ return `@kaltura-ai/${baseName}`;
126
+ case 'none':
127
+ default:
128
+ return `@local/${baseName}`;
129
+ }
130
+ }
131
+ /**
132
+ * Check if a package has already been migrated to the new subdirectory structure.
133
+ * Checks both regular name and name with "-react" suffix since we don't know
134
+ * at this point if the package has React dependencies.
135
+ */
136
+ function isAlreadyMigrated(tree, name, distributionChannel) {
137
+ const subdirectory = getSubdirectory(distributionChannel);
138
+ // Handle core -> types rename
139
+ const targetName = name === 'core' ? 'types' : name;
140
+ // Check regular path
141
+ const newPath = `unisphere/packages/${subdirectory}/${targetName}/package.json`;
142
+ if (tree.exists(newPath)) {
143
+ return true;
144
+ }
145
+ // Also check with -react suffix (for packages with React dependencies)
146
+ const newPathWithReact = `unisphere/packages/${subdirectory}/${targetName}-react/package.json`;
147
+ return tree.exists(newPathWithReact);
148
+ }
149
+ /**
150
+ * Get the actual Nx project name from project.json
151
+ */
152
+ function getProjectNameFromProjectJson(tree, projectPath) {
153
+ const projectJsonPath = `${projectPath}/project.json`;
154
+ if (!tree.exists(projectJsonPath)) {
155
+ return null;
156
+ }
157
+ try {
158
+ const projectJson = (0, devkit_1.readJson)(tree, projectJsonPath);
159
+ return projectJson.name || null;
160
+ }
161
+ catch {
162
+ return null;
163
+ }
164
+ }
165
+ /**
166
+ * Discover all packages in the workspace
167
+ */
168
+ async function discoverPackages(tree) {
169
+ if (!tree.exists('.unisphere')) {
170
+ devkit_1.logger.warn('No .unisphere file found, skipping migration');
171
+ return [];
172
+ }
173
+ const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
174
+ const packages = [];
175
+ const packagesConfig = unisphereConfig.elements?.packages || {};
176
+ for (const [name, config] of Object.entries(packagesConfig)) {
177
+ const normalizedName = (0, devkit_1.names)(name).fileName;
178
+ // Get sourceRoot from .unisphere config, or fall back to default path
179
+ const sourceRoot = config.sourceRoot;
180
+ const currentPath = sourceRoot || `unisphere/packages/${normalizedName}`;
181
+ // Determine distribution channel:
182
+ // 1. First check if explicitly set in config
183
+ // 2. If not, try to infer from current sourceRoot path (for already-migrated packages)
184
+ // 3. Default to 'none' if neither works
185
+ let distributionChannel;
186
+ const configDistributionChannel = config.distributionChannel;
187
+ if (configDistributionChannel) {
188
+ distributionChannel = configDistributionChannel;
189
+ }
190
+ else {
191
+ const inferredChannel = inferDistributionChannelFromPath(currentPath);
192
+ if (inferredChannel) {
193
+ distributionChannel = inferredChannel;
194
+ devkit_1.logger.info(` Inferred distributionChannel '${distributionChannel}' from path for ${name}`);
195
+ }
196
+ else {
197
+ distributionChannel = 'none';
198
+ }
199
+ }
200
+ // Calculate target path to check if package is already at the target location
201
+ const subdirectory = getSubdirectory(distributionChannel);
202
+ // Handle core -> types rename when calculating target path
203
+ const targetName = normalizedName === 'core' ? 'types' : normalizedName;
204
+ const targetPath = `unisphere/packages/${subdirectory}/${targetName}`;
205
+ // Check if package is already at the target location (sourceRoot == targetPath)
206
+ // Also check with -react suffix since we don't know React dependency status yet
207
+ if (currentPath === targetPath || currentPath === `${targetPath}-react`) {
208
+ devkit_1.logger.info(` Package ${name} is already at target location (${currentPath}), skipping`);
209
+ continue;
210
+ }
211
+ // Check if already migrated to new location (package.json exists at new location)
212
+ if (isAlreadyMigrated(tree, normalizedName, distributionChannel)) {
213
+ devkit_1.logger.info(` Package ${name} already migrated to new location, skipping`);
214
+ continue;
215
+ }
216
+ // Check if target path already exists with actual content (package.json)
217
+ // If target exists but is empty (no package.json), clean it up and proceed
218
+ // Also check with potential -react suffix
219
+ let skipPackage = false;
220
+ for (const pathToCheck of [targetPath, `${targetPath}-react`]) {
221
+ if (tree.exists(pathToCheck)) {
222
+ if (tree.exists(`${pathToCheck}/package.json`)) {
223
+ devkit_1.logger.info(` Package ${name} target path already exists with package.json (${pathToCheck}), skipping`);
224
+ skipPackage = true;
225
+ break;
226
+ }
227
+ else {
228
+ // Empty directory - clean it up so migration can proceed
229
+ devkit_1.logger.info(` Package ${name} target path exists but is empty, cleaning up: ${pathToCheck}`);
230
+ tree.delete(pathToCheck);
231
+ }
232
+ }
233
+ }
234
+ if (skipPackage) {
235
+ continue;
236
+ }
237
+ const packageJsonPath = `${currentPath}/package.json`;
238
+ if (!tree.exists(packageJsonPath)) {
239
+ devkit_1.logger.warn(`Package ${name} not found at ${currentPath}, skipping`);
240
+ continue;
241
+ }
242
+ // Read actual project name from project.json instead of assuming it
243
+ const actualProjectName = getProjectNameFromProjectJson(tree, currentPath);
244
+ if (!actualProjectName) {
245
+ devkit_1.logger.warn(`Package ${name} has no project.json or missing name at ${currentPath}, skipping`);
246
+ continue;
247
+ }
248
+ const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
249
+ // Check if package has React dependencies (including transitive through workspace packages)
250
+ const hasReact = await (0, has_react_dependency_1.hasReactDependency)(actualProjectName);
251
+ devkit_1.logger.info(` Found package: ${normalizedName} (Nx project: ${actualProjectName}, channel: ${distributionChannel})${hasReact ? ' [React]' : ''}`);
252
+ packages.push({
253
+ name: normalizedName,
254
+ distributionChannel: distributionChannel,
255
+ currentPath,
256
+ currentPackageJsonName: packageJson.name,
257
+ currentNxProjectName: actualProjectName,
258
+ hasReactDependency: hasReact,
259
+ });
260
+ }
261
+ return packages;
262
+ }
263
+ /**
264
+ * Calculate migration target for a package
265
+ * Handles:
266
+ * - Moving to subdirectory based on distribution channel
267
+ * - Renaming "core" to "types"
268
+ * - Adding "-react" suffix for packages with React dependencies (except core/types)
269
+ */
270
+ function calculateMigrationTarget(pkg) {
271
+ const subdirectory = getSubdirectory(pkg.distributionChannel);
272
+ // Check if this is the core/types package (special case - no React suffix)
273
+ const isCoreOrTypes = pkg.name === 'core' || pkg.name === 'types';
274
+ // Step 1: Apply special case renames (core -> types)
275
+ let newName = pkg.name === 'core' ? 'types' : pkg.name;
276
+ // Step 2: Apply "-react" suffix if package has React dependencies
277
+ // Skip for core/types packages - they don't get the React suffix
278
+ // Following the convention in validateReactNaming() from dependency-config.ts
279
+ if (!isCoreOrTypes) {
280
+ newName = applyReactSuffixIfNeeded(newName, pkg.hasReactDependency);
281
+ }
282
+ const isRename = newName !== pkg.name;
283
+ const newPath = `unisphere/packages/${subdirectory}/${newName}`;
284
+ // Calculate new package.json name
285
+ let newPackageJsonName = calculateNewPackageJsonName(pkg.currentPackageJsonName, pkg.distributionChannel);
286
+ // Handle core->types rename in package.json name
287
+ if (pkg.name === 'core') {
288
+ newPackageJsonName = newPackageJsonName
289
+ .replace(/-core$/, '-types')
290
+ .replace(/\/core$/, '/types');
291
+ }
292
+ // Handle React suffix in package.json name (skip for core/types)
293
+ if (!isCoreOrTypes && pkg.hasReactDependency && !newPackageJsonName.endsWith('-react')) {
294
+ newPackageJsonName = `${newPackageJsonName}-react`;
295
+ }
296
+ // Update Nx project name if renamed
297
+ const newNxProjectName = isRename
298
+ ? `unisphere-package-${newName}`
299
+ : pkg.currentNxProjectName;
300
+ return {
301
+ package: pkg,
302
+ newPath,
303
+ newPackageJsonName,
304
+ newNxProjectName,
305
+ newName,
306
+ subdirectory,
307
+ };
308
+ }
309
+ /**
310
+ * Validate migration preconditions
311
+ */
312
+ function validateMigrationPreconditions(tree, targets) {
313
+ // Check destination directories don't conflict
314
+ const destinations = new Set();
315
+ for (const target of targets) {
316
+ if (destinations.has(target.newPath)) {
317
+ throw new Error(`Duplicate destination path: ${target.newPath}`);
318
+ }
319
+ destinations.add(target.newPath);
320
+ // Check destination doesn't already exist
321
+ if (tree.exists(target.newPath)) {
322
+ throw new Error(`Destination already exists: ${target.newPath}`);
323
+ }
324
+ }
325
+ // Check all source packages exist
326
+ for (const target of targets) {
327
+ if (!tree.exists(target.package.currentPath)) {
328
+ throw new Error(`Source package not found: ${target.package.currentPath}`);
329
+ }
330
+ }
331
+ }
332
+ /**
333
+ * Update .unisphere configuration sourceRoot
334
+ * Also handles renaming the package key if oldName !== newName (e.g., core -> types, admin -> admin-react)
335
+ * Note: distributionChannel removal is handled by the separate upgrade-schema-to-2-0-0 migration
336
+ */
337
+ function updateUnisphereSourceRoot(tree, oldName, newName, newPath) {
338
+ const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
339
+ if (unisphereConfig.elements?.packages?.[oldName]) {
340
+ const packageConfig = unisphereConfig.elements.packages[oldName];
341
+ packageConfig.sourceRoot = newPath;
342
+ // If renaming (e.g., core -> types, admin -> admin-react), update the key in packages object
343
+ if (oldName !== newName) {
344
+ // Preserve package order by rebuilding the packages object
345
+ const newPackages = {};
346
+ for (const key of Object.keys(unisphereConfig.elements.packages)) {
347
+ if (key === oldName) {
348
+ newPackages[newName] = packageConfig;
349
+ }
350
+ else {
351
+ newPackages[key] = unisphereConfig.elements.packages[key];
352
+ }
353
+ }
354
+ unisphereConfig.elements.packages = newPackages;
355
+ devkit_1.logger.info(` Renamed package key in .unisphere: ${oldName} -> ${newName}`);
356
+ }
357
+ (0, devkit_1.writeJson)(tree, '.unisphere', unisphereConfig);
358
+ }
359
+ }
360
+ /**
361
+ * Update package-lock.json paths
362
+ */
363
+ function updatePackageLockPaths(tree, oldPath, newPath) {
364
+ if (!tree.exists('package-lock.json')) {
365
+ return;
366
+ }
367
+ const packageLock = (0, devkit_1.readJson)(tree, 'package-lock.json');
368
+ let updated = false;
369
+ if (packageLock.packages) {
370
+ const newPackages = {};
371
+ for (const [key, value] of Object.entries(packageLock.packages)) {
372
+ if (key === oldPath) {
373
+ newPackages[newPath] = value;
374
+ updated = true;
375
+ }
376
+ else if (key.startsWith(oldPath + '/')) {
377
+ // Handle nested node_modules paths if any
378
+ newPackages[key.replace(oldPath, newPath)] = value;
379
+ updated = true;
380
+ }
381
+ else {
382
+ newPackages[key] = value;
383
+ }
384
+ }
385
+ if (updated) {
386
+ packageLock.packages = newPackages;
387
+ }
388
+ }
389
+ // Update resolved paths if they exist
390
+ if (packageLock.packages) {
391
+ for (const value of Object.values(packageLock.packages)) {
392
+ if (value && typeof value === 'object' && 'resolved' in value) {
393
+ const pkg = value;
394
+ if (pkg.resolved === oldPath) {
395
+ pkg.resolved = newPath;
396
+ updated = true;
397
+ }
398
+ }
399
+ }
400
+ }
401
+ if (updated) {
402
+ (0, devkit_1.writeJson)(tree, 'package-lock.json', packageLock);
403
+ devkit_1.logger.info(` Updated package-lock.json paths`);
404
+ }
405
+ }
406
+ /**
407
+ * Fix .eslintrc.json extends path after moving to subdirectory
408
+ * Path changes from ../../../.eslintrc.json to ../../../../.eslintrc.json
409
+ */
410
+ function fixEslintConfigPath(tree, packagePath) {
411
+ const eslintConfigPath = `${packagePath}/.eslintrc.json`;
412
+ if (!tree.exists(eslintConfigPath)) {
413
+ return;
414
+ }
415
+ const eslintConfig = (0, devkit_1.readJson)(tree, eslintConfigPath);
416
+ if (eslintConfig.extends && Array.isArray(eslintConfig.extends)) {
417
+ const updatedExtends = eslintConfig.extends.map((ext) => {
418
+ // Update the relative path to root .eslintrc.json
419
+ if (ext === '../../../.eslintrc.json') {
420
+ return '../../../../.eslintrc.json';
421
+ }
422
+ return ext;
423
+ });
424
+ eslintConfig.extends = updatedExtends;
425
+ (0, devkit_1.writeJson)(tree, eslintConfigPath, eslintConfig);
426
+ devkit_1.logger.info(` Fixed .eslintrc.json extends path`);
427
+ }
428
+ }
429
+ /**
430
+ * Verify package.json name is correct
431
+ */
432
+ function verifyPackageJsonName(tree, packagePath, expectedName) {
433
+ const packageJsonPath = `${packagePath}/package.json`;
434
+ if (!tree.exists(packageJsonPath)) {
435
+ devkit_1.logger.warn(` package.json not found at ${packageJsonPath}`);
436
+ return;
437
+ }
438
+ const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
439
+ if (packageJson.name !== expectedName) {
440
+ packageJson.name = expectedName;
441
+ (0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
442
+ devkit_1.logger.info(` Updated package.json name to "${expectedName}"`);
443
+ }
444
+ }
445
+ /**
446
+ * Update tsconfig.base.json paths for the package.
447
+ * This ensures paths are updated even if moveGenerator fails to do so
448
+ * (e.g., due to stale project graph cache).
449
+ */
450
+ function updateTsConfigBasePaths(tree, oldPath, newPath, oldImportPath, newImportPath) {
451
+ if (!tree.exists('tsconfig.base.json')) {
452
+ return;
453
+ }
454
+ const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
455
+ if (!tsconfigBase.compilerOptions?.paths) {
456
+ return;
457
+ }
458
+ let updated = false;
459
+ const newPaths = {};
460
+ for (const [key, paths] of Object.entries(tsconfigBase.compilerOptions.paths)) {
461
+ // Check if we need to rename the key (import path changed)
462
+ let newKey = key;
463
+ if (key === oldImportPath || key === `${oldImportPath}/*`) {
464
+ newKey = key === oldImportPath ? newImportPath : `${newImportPath}/*`;
465
+ updated = true;
466
+ }
467
+ // Update the path values
468
+ if (Array.isArray(paths)) {
469
+ const updatedPaths = paths.map((p) => {
470
+ if (p.startsWith(oldPath + '/') || p === oldPath) {
471
+ updated = true;
472
+ return p.replace(oldPath, newPath);
473
+ }
474
+ return p;
475
+ });
476
+ newPaths[newKey] = updatedPaths;
477
+ }
478
+ else {
479
+ newPaths[newKey] = paths;
480
+ }
481
+ }
482
+ if (updated) {
483
+ tsconfigBase.compilerOptions.paths = newPaths;
484
+ (0, devkit_1.writeJson)(tree, 'tsconfig.base.json', tsconfigBase);
485
+ devkit_1.logger.info(` Updated tsconfig.base.json paths`);
486
+ }
487
+ }
488
+ /**
489
+ * Migrate a single package
490
+ */
491
+ async function migratePackage(tree, target) {
492
+ const { package: pkg, newPath, newPackageJsonName, newNxProjectName, newName } = target;
493
+ const isRename = pkg.name !== newName;
494
+ if (isRename) {
495
+ const renameReason = pkg.hasReactDependency && !pkg.name.endsWith('-react')
496
+ ? ' (adding -react suffix for React dependency)'
497
+ : pkg.name === 'core' ? ' (core -> types rename)' : '';
498
+ devkit_1.logger.info(`Moving and renaming ${pkg.name} -> ${newName} to ${target.subdirectory}/${renameReason}`);
499
+ }
500
+ else {
501
+ devkit_1.logger.info(`Moving ${pkg.name} to ${target.subdirectory}/`);
502
+ }
503
+ devkit_1.logger.info(` From: ${pkg.currentPath}`);
504
+ devkit_1.logger.info(` To: ${newPath}`);
505
+ devkit_1.logger.info(` Nx project name: ${pkg.currentNxProjectName} -> ${newNxProjectName}`);
506
+ devkit_1.logger.info(` Package.json name: ${pkg.currentPackageJsonName} -> ${newPackageJsonName}`);
507
+ // Verify source exists before attempting move (safety check)
508
+ const sourcePackageJson = `${pkg.currentPath}/package.json`;
509
+ if (!tree.exists(sourcePackageJson)) {
510
+ devkit_1.logger.warn(` Source package.json not found at ${sourcePackageJson}, skipping`);
511
+ return;
512
+ }
513
+ // Step 0: Clean node_modules from destination on disk if present.
514
+ // npm install may create node_modules/ at the target path (e.g. for workspace
515
+ // dependency resolution). tree.delete() only records a virtual deletion and
516
+ // doesn't remove on-disk children, so moveGenerator's checkDestination
517
+ // (which uses tree.children() -> readdirSync) would see node_modules and
518
+ // throw "Path is not empty". We must remove it from the real filesystem.
519
+ const destNodeModules = (0, path_1.join)(newPath, 'node_modules');
520
+ if ((0, fs_1.existsSync)(destNodeModules)) {
521
+ devkit_1.logger.info(` Removing leftover node_modules at destination: ${destNodeModules}`);
522
+ (0, fs_1.rmSync)(destNodeModules, { recursive: true, force: true });
523
+ }
524
+ // Step 1: Use Nx moveGenerator for the heavy lifting
525
+ try {
526
+ await (0, generators_1.moveGenerator)(tree, {
527
+ projectName: pkg.currentNxProjectName,
528
+ destination: newPath,
529
+ newProjectName: newNxProjectName,
530
+ importPath: newPackageJsonName,
531
+ updateImportPath: true,
532
+ skipFormat: true,
533
+ });
534
+ devkit_1.logger.info(` Nx moved project successfully`);
535
+ // Reset Nx cache after move to ensure fresh project graph for next operations
536
+ // This is important because moveGenerator uses the project graph, and it can become stale
537
+ resetNxCache();
538
+ }
539
+ catch (error) {
540
+ devkit_1.logger.error(` Failed to move project with Nx: ${error}`);
541
+ devkit_1.logger.error(` Source path: ${pkg.currentPath}`);
542
+ devkit_1.logger.error(` Destination path: ${newPath}`);
543
+ devkit_1.logger.error(` Project name: ${pkg.currentNxProjectName}`);
544
+ throw error;
545
+ }
546
+ // Step 2: Update .unisphere configuration (handles rename if needed)
547
+ updateUnisphereSourceRoot(tree, pkg.name, newName, newPath);
548
+ devkit_1.logger.info(` Updated .unisphere sourceRoot`);
549
+ // Step 3: Update package-lock.json
550
+ updatePackageLockPaths(tree, pkg.currentPath, newPath);
551
+ // Step 4: Verify package.json name
552
+ verifyPackageJsonName(tree, newPath, newPackageJsonName);
553
+ // Step 5: Fix .eslintrc.json extends path
554
+ fixEslintConfigPath(tree, newPath);
555
+ // Step 6: Update tsconfig.base.json paths
556
+ // This ensures paths are updated even if moveGenerator didn't do it
557
+ // (can happen due to stale project graph cache issues)
558
+ updateTsConfigBasePaths(tree, pkg.currentPath, newPath, pkg.currentPackageJsonName, newPackageJsonName);
559
+ // Step 7: Update vite.config.ts cache directories if renamed
560
+ if (isRename) {
561
+ const viteConfigPath = `${newPath}/vite.config.ts`;
562
+ if (tree.exists(viteConfigPath)) {
563
+ let viteContent = tree.read(viteConfigPath, 'utf-8');
564
+ if (viteContent) {
565
+ const oldPattern = `package-${pkg.name}`;
566
+ const newPattern = `package-${newName}`;
567
+ if (viteContent.includes(oldPattern)) {
568
+ viteContent = viteContent.replace(new RegExp(oldPattern, 'g'), newPattern);
569
+ tree.write(viteConfigPath, viteContent);
570
+ devkit_1.logger.info(` Updated vite.config.ts cache directories`);
571
+ }
572
+ }
573
+ }
574
+ }
575
+ }
576
+ /**
577
+ * Main migration function
578
+ */
579
+ async function update(tree) {
580
+ devkit_1.logger.info('');
581
+ devkit_1.logger.info('========================================');
582
+ devkit_1.logger.info('Reorganizing packages by distribution channel');
583
+ devkit_1.logger.info('========================================');
584
+ devkit_1.logger.info('');
585
+ // Phase 0: Reset Nx cache to ensure fresh project graph
586
+ resetNxCache();
587
+ devkit_1.logger.info('');
588
+ // Phase 1: Discover packages
589
+ const packages = await discoverPackages(tree);
590
+ if (packages.length === 0) {
591
+ devkit_1.logger.info('No packages found to migrate');
592
+ return;
593
+ }
594
+ devkit_1.logger.info(`Found ${packages.length} package(s) to reorganize`);
595
+ // Phase 2: Calculate migration targets
596
+ const targets = packages.map(calculateMigrationTarget);
597
+ // Group by subdirectory for logging
598
+ const byChannel = {
599
+ 'local': targets.filter((t) => t.subdirectory === 'local'),
600
+ 'kaltura-corp': targets.filter((t) => t.subdirectory === 'kaltura-corp'),
601
+ 'unisphere': targets.filter((t) => t.subdirectory === 'unisphere'),
602
+ 'kaltura-ai': targets.filter((t) => t.subdirectory === 'kaltura-ai'),
603
+ };
604
+ devkit_1.logger.info('');
605
+ devkit_1.logger.info('Migration plan:');
606
+ devkit_1.logger.info(` - local/ (none): ${byChannel['local'].length} package(s)`);
607
+ devkit_1.logger.info(` - kaltura-corp/ (github): ${byChannel['kaltura-corp'].length} package(s)`);
608
+ devkit_1.logger.info(` - unisphere/ (npm): ${byChannel['unisphere'].length} package(s)`);
609
+ devkit_1.logger.info(` - kaltura-ai/ (kaltura-ai): ${byChannel['kaltura-ai'].length} package(s)`);
610
+ devkit_1.logger.info('');
611
+ // Phase 3: Validate preconditions
612
+ try {
613
+ validateMigrationPreconditions(tree, targets);
614
+ }
615
+ catch (error) {
616
+ devkit_1.logger.error(`Migration precondition failed: ${error}`);
617
+ throw error;
618
+ }
619
+ // Phase 4: Execute migrations SEQUENTIALLY
620
+ let migrated = 0;
621
+ for (const target of targets) {
622
+ try {
623
+ await migratePackage(tree, target);
624
+ migrated++;
625
+ devkit_1.logger.info(` [${migrated}/${targets.length}] Migrated ${target.package.name}`);
626
+ devkit_1.logger.info('');
627
+ }
628
+ catch (error) {
629
+ devkit_1.logger.error(`Failed to migrate ${target.package.name}: ${error}`);
630
+ throw error;
631
+ }
632
+ }
633
+ // Format all files at the end
634
+ await (0, devkit_1.formatFiles)(tree);
635
+ devkit_1.logger.info('');
636
+ devkit_1.logger.info('========================================');
637
+ devkit_1.logger.info(`Successfully reorganized ${migrated} package(s)`);
638
+ devkit_1.logger.info('========================================');
639
+ devkit_1.logger.info('');
640
+ devkit_1.logger.info('Next steps:');
641
+ devkit_1.logger.info(' 1. Run: npm install');
642
+ devkit_1.logger.info(' 2. Run: npm run build');
643
+ devkit_1.logger.info(' 3. Verify all imports are updated');
644
+ devkit_1.logger.info('');
645
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
3
+ //# sourceMappingURL=replace-github-workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replace-github-workflow.d.ts","sourceRoot":"","sources":["../../../src/migrations/3-0-0/replace-github-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAU,MAAM,YAAY,CAAC;AAI1C,wBAA8B,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CA+C9D"}