@unisphere/nx 3.16.0 ā 3.17.0
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/internal-dev-runner/generator.d.ts.map +1 -1
- package/dist/generators/internal-dev-runner/generator.js +2 -40
- package/dist/migrations/3-17-0/add-local-runtimes-setup.d.ts +11 -0
- package/dist/migrations/3-17-0/add-local-runtimes-setup.d.ts.map +1 -0
- package/dist/migrations/3-17-0/add-local-runtimes-setup.js +160 -0
- package/migrations.json +8 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/internal-dev-runner/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/internal-dev-runner/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKlC,wBAA8B,sBAAsB,CAAC,IAAI,EAAE,IAAI,iBAE9D"}
|
|
@@ -3,45 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = testMigrationGenerator;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
// Import the migrations to test
|
|
6
|
-
|
|
7
|
-
// import addDefinePluginToWebpack from '../../migrations/3-0-0/add-define-plugin-to-webpack';
|
|
8
|
-
// import upgradeCliToV2 from '../../migrations/3-0-0/upgrade-cli-to-v2';
|
|
9
|
-
// import preCleanupEmptyDirectories from '../../migrations/3-0-0/pre-cleanup-empty-directories';
|
|
10
|
-
// import reorganizePackagesByDistributionChannel from '../../migrations/3-0-0/reorganize-packages-by-distribution-channel';
|
|
11
|
-
// import reorganizeApplicationsByDistributionChannel from '../../migrations/3-0-0/reorganize-applications-by-distribution-channel';
|
|
12
|
-
// import upgradeSchemaTo2 from '../../migrations/3-0-0/upgrade-schema-to-2-0-0';
|
|
13
|
-
// import postCleanupEmptyDirectories from '../../migrations/3-0-0/post-cleanup-empty-directories';
|
|
14
|
-
// import removePrivateFromApplicationsAndRuntimes from '../../migrations/3-0-0/remove-private-from-applications-and-runtimes';
|
|
15
|
-
const fix_workspaces_pattern_1 = tslib_1.__importDefault(require("../../migrations/3-1-0/fix-workspaces-pattern"));
|
|
6
|
+
const add_local_runtimes_setup_1 = tslib_1.__importDefault(require("../../migrations/3-17-0/add-local-runtimes-setup"));
|
|
16
7
|
async function testMigrationGenerator(tree) {
|
|
17
|
-
|
|
18
|
-
// const callbacks: (() => void)[] = [];
|
|
19
|
-
// Upgrade CLI to v2 first (needed for other migrations)
|
|
20
|
-
// const upgradeCliCallback = await upgradeCliToV2(tree);
|
|
21
|
-
// if (upgradeCliCallback) {
|
|
22
|
-
// callbacks.push(upgradeCliCallback);
|
|
23
|
-
// }
|
|
24
|
-
// Pre-cleanup: Remove empty directories before reorganization
|
|
25
|
-
// await preCleanupEmptyDirectories(tree);
|
|
26
|
-
// Reorganize packages by distribution channel (also handles core->types rename and -react suffix)
|
|
27
|
-
// await reorganizePackagesByDistributionChannel(tree);
|
|
28
|
-
// // Reorganize applications by distribution channel
|
|
29
|
-
// await reorganizeApplicationsByDistributionChannel(tree);
|
|
30
|
-
// Upgrade schema to 2.0.0 and remove distributionChannel from packages
|
|
31
|
-
// await upgradeSchemaTo2(tree);
|
|
32
|
-
// Remove private field from applications, runtimes, and packages
|
|
33
|
-
// await removePrivateFromApplicationsAndRuntimes(tree);
|
|
34
|
-
await (0, fix_workspaces_pattern_1.default)(tree);
|
|
35
|
-
// Post-cleanup: Remove empty directories after reorganization
|
|
36
|
-
// const postCleanupCallback = await postCleanupEmptyDirectories(tree);
|
|
37
|
-
// if (postCleanupCallback) {
|
|
38
|
-
// callbacks.push(postCleanupCallback);
|
|
39
|
-
// }
|
|
40
|
-
// Run all callbacks at the end
|
|
41
|
-
// Note: In Nx generators, Tree changes are written when the generator completes.
|
|
42
|
-
// These callbacks run after all migrations but before the generator finishes.
|
|
43
|
-
// For file system operations (like npm install), they should work correctly.
|
|
44
|
-
// for (const callback of callbacks) {
|
|
45
|
-
// callback();
|
|
46
|
-
// }
|
|
8
|
+
await (0, add_local_runtimes_setup_1.default)(tree);
|
|
47
9
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration: Add local runtimes setup
|
|
3
|
+
*
|
|
4
|
+
* For each local application (sourceRoot containing '/local/'):
|
|
5
|
+
* 1. Creates setup-local-runtimes.ts with experience name from .unisphere
|
|
6
|
+
* 2. Imports and calls setupLocalRuntimes() in main.tsx
|
|
7
|
+
* 3. Adds LOCAL_RUNTIMES env var to webpack DefinePlugin
|
|
8
|
+
*/
|
|
9
|
+
import { Tree } from '@nx/devkit';
|
|
10
|
+
export default function update(tree: Tree): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=add-local-runtimes-setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-local-runtimes-setup.d.ts","sourceRoot":"","sources":["../../../src/migrations/3-17-0/add-local-runtimes-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAiC,MAAM,YAAY,CAAC;AA2GjE,wBAA8B,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CA4E9D"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Migration: Add local runtimes setup
|
|
4
|
+
*
|
|
5
|
+
* For each local application (sourceRoot containing '/local/'):
|
|
6
|
+
* 1. Creates setup-local-runtimes.ts with experience name from .unisphere
|
|
7
|
+
* 2. Imports and calls setupLocalRuntimes() in main.tsx
|
|
8
|
+
* 3. Adds LOCAL_RUNTIMES env var to webpack DefinePlugin
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.default = update;
|
|
12
|
+
const devkit_1 = require("@nx/devkit");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
function generateSetupLocalRuntimes(experienceName) {
|
|
15
|
+
return `export function setupLocalRuntimes() {
|
|
16
|
+
if (!process.env.LOCAL_RUNTIMES) return;
|
|
17
|
+
|
|
18
|
+
const runtimes: Record<string, { token: string; baseEnvName: string }> = {};
|
|
19
|
+
process.env.LOCAL_RUNTIMES.split(',').forEach((entry) => {
|
|
20
|
+
const [name, port] = entry.split('@');
|
|
21
|
+
if (name && port) {
|
|
22
|
+
runtimes[name] = { token: port, baseEnvName: '' };
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const overrides = {
|
|
27
|
+
baseEnvName: '',
|
|
28
|
+
mode: 'integration',
|
|
29
|
+
options: { verbose: 'inherit' },
|
|
30
|
+
baseEnvScope: { core: 'inherit', presets: 'inherit' },
|
|
31
|
+
runtimes: {
|
|
32
|
+
'${experienceName}': runtimes,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
(window as any).unisphereRuntimeOverrides = btoa(JSON.stringify(overrides));
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
function addImportToMainTsx(content) {
|
|
41
|
+
const importLine = "import { setupLocalRuntimes } from './setup-local-runtimes';";
|
|
42
|
+
const callLine = 'setupLocalRuntimes();';
|
|
43
|
+
if (content.includes('setupLocalRuntimes')) {
|
|
44
|
+
return content;
|
|
45
|
+
}
|
|
46
|
+
// Find the last import statement
|
|
47
|
+
const lines = content.split('\n');
|
|
48
|
+
let lastImportIndex = -1;
|
|
49
|
+
for (let i = 0; i < lines.length; i++) {
|
|
50
|
+
if (lines[i].startsWith('import ')) {
|
|
51
|
+
lastImportIndex = i;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (lastImportIndex === -1) {
|
|
55
|
+
// No imports found, add at the top
|
|
56
|
+
return `${importLine}\n\n${callLine}\n\n${content}`;
|
|
57
|
+
}
|
|
58
|
+
// Insert after the last import
|
|
59
|
+
lines.splice(lastImportIndex + 1, 0, importLine, '', callLine);
|
|
60
|
+
return lines.join('\n');
|
|
61
|
+
}
|
|
62
|
+
function addLocalRuntimesToDefinePlugin(content) {
|
|
63
|
+
const entry = "'process.env.LOCAL_RUNTIMES': JSON.stringify(process.env.LOCAL_RUNTIMES),";
|
|
64
|
+
if (content.includes('LOCAL_RUNTIMES')) {
|
|
65
|
+
return content;
|
|
66
|
+
}
|
|
67
|
+
// Find the DefinePlugin block and add before its closing })
|
|
68
|
+
const definePluginMatch = content.match(/new DefinePlugin\(\{/);
|
|
69
|
+
if (!definePluginMatch || definePluginMatch.index === undefined) {
|
|
70
|
+
return content;
|
|
71
|
+
}
|
|
72
|
+
// Find the closing }) of DefinePlugin
|
|
73
|
+
const startIndex = definePluginMatch.index;
|
|
74
|
+
let braceCount = 0;
|
|
75
|
+
let closingIndex = -1;
|
|
76
|
+
for (let i = startIndex; i < content.length; i++) {
|
|
77
|
+
if (content[i] === '{')
|
|
78
|
+
braceCount++;
|
|
79
|
+
if (content[i] === '}') {
|
|
80
|
+
braceCount--;
|
|
81
|
+
if (braceCount === 0) {
|
|
82
|
+
closingIndex = i;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (closingIndex === -1) {
|
|
88
|
+
return content;
|
|
89
|
+
}
|
|
90
|
+
const indent = ' ';
|
|
91
|
+
// Insert the new entry before the closing }
|
|
92
|
+
return content.substring(0, closingIndex).trimEnd() + '\n' +
|
|
93
|
+
`${indent}${entry}\n` +
|
|
94
|
+
' ' + content.substring(closingIndex);
|
|
95
|
+
}
|
|
96
|
+
async function update(tree) {
|
|
97
|
+
devkit_1.logger.info('š Adding local runtimes setup to local applications...');
|
|
98
|
+
if (!tree.exists('.unisphere')) {
|
|
99
|
+
devkit_1.logger.warn('ā ļø No .unisphere file found, skipping');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const config = (0, devkit_1.readJson)(tree, '.unisphere');
|
|
103
|
+
const experienceName = `${config.company}.${config.type}.${config.name}`;
|
|
104
|
+
const applications = config.elements?.applications;
|
|
105
|
+
if (!applications || Object.keys(applications).length === 0) {
|
|
106
|
+
devkit_1.logger.info('ā¹ļø No applications found, skipping');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
let updatedCount = 0;
|
|
110
|
+
for (const [appName, appConfig] of Object.entries(applications)) {
|
|
111
|
+
const { sourceRoot } = appConfig;
|
|
112
|
+
// Only process local applications
|
|
113
|
+
if (!sourceRoot.includes('/local/')) {
|
|
114
|
+
devkit_1.logger.info(`ā¹ļø ${appName}: Not a local application, skipping`);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const setupFilePath = (0, path_1.join)(sourceRoot, 'src', 'setup-local-runtimes.ts');
|
|
118
|
+
const mainTsxPath = (0, path_1.join)(sourceRoot, 'src', 'main.tsx');
|
|
119
|
+
const webpackPath = (0, path_1.join)(sourceRoot, 'webpack.config.js');
|
|
120
|
+
// 1. Create setup-local-runtimes.ts
|
|
121
|
+
if (tree.exists(setupFilePath)) {
|
|
122
|
+
devkit_1.logger.info(`ā¹ļø ${appName}: setup-local-runtimes.ts already exists, skipping`);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
tree.write(setupFilePath, generateSetupLocalRuntimes(experienceName));
|
|
126
|
+
devkit_1.logger.info(`ā
${appName}: Created setup-local-runtimes.ts`);
|
|
127
|
+
}
|
|
128
|
+
// 2. Modify main.tsx
|
|
129
|
+
if (!tree.exists(mainTsxPath)) {
|
|
130
|
+
devkit_1.logger.warn(`ā ļø ${appName}: No main.tsx found, skipping`);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const mainContent = tree.read(mainTsxPath, 'utf-8') || '';
|
|
134
|
+
const updatedMain = addImportToMainTsx(mainContent);
|
|
135
|
+
if (updatedMain !== mainContent) {
|
|
136
|
+
tree.write(mainTsxPath, updatedMain);
|
|
137
|
+
devkit_1.logger.info(`ā
${appName}: Added setupLocalRuntimes import to main.tsx`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
devkit_1.logger.info(`ā¹ļø ${appName}: main.tsx already has setupLocalRuntimes`);
|
|
141
|
+
}
|
|
142
|
+
// 3. Modify webpack.config.js
|
|
143
|
+
if (!tree.exists(webpackPath)) {
|
|
144
|
+
devkit_1.logger.warn(`ā ļø ${appName}: No webpack.config.js found, skipping`);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const webpackContent = tree.read(webpackPath, 'utf-8') || '';
|
|
148
|
+
const updatedWebpack = addLocalRuntimesToDefinePlugin(webpackContent);
|
|
149
|
+
if (updatedWebpack !== webpackContent) {
|
|
150
|
+
tree.write(webpackPath, updatedWebpack);
|
|
151
|
+
devkit_1.logger.info(`ā
${appName}: Added LOCAL_RUNTIMES to DefinePlugin`);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
devkit_1.logger.info(`ā¹ļø ${appName}: webpack.config.js already has LOCAL_RUNTIMES`);
|
|
155
|
+
}
|
|
156
|
+
updatedCount++;
|
|
157
|
+
}
|
|
158
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
159
|
+
devkit_1.logger.info(`\nā
Done: ${updatedCount} local application(s) updated with local runtimes setup (experience: ${experienceName})`);
|
|
160
|
+
}
|
package/migrations.json
CHANGED
|
@@ -338,6 +338,14 @@
|
|
|
338
338
|
"cli": {
|
|
339
339
|
"postUpdateMessage": "ā
Outdated rollup patch file removed"
|
|
340
340
|
}
|
|
341
|
+
},
|
|
342
|
+
"3-17-0-add-local-runtimes-setup": {
|
|
343
|
+
"version": "3.17.0",
|
|
344
|
+
"description": "Adds local runtimes setup to local applications for development overrides",
|
|
345
|
+
"factory": "./dist/migrations/3-17-0/add-local-runtimes-setup.js",
|
|
346
|
+
"cli": {
|
|
347
|
+
"postUpdateMessage": "ā
Local runtimes setup added to local applications"
|
|
348
|
+
}
|
|
341
349
|
}
|
|
342
350
|
},
|
|
343
351
|
"packageJsonUpdates": {
|