@unisphere/cli 1.58.6 → 1.58.7
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/bundler/package/rollup.js +149 -12
- package/package.json +1 -1
|
@@ -7,9 +7,139 @@ const svg = require('@svgr/rollup');
|
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const path = require('path');
|
|
9
9
|
const { getEnvVariables } = require('../../src/lib/utils/unisphere/get-env-variables');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
|
|
12
|
+
function createTempBuildTsconfig({
|
|
13
|
+
projectRoot,
|
|
14
|
+
baseTsconfigPath, // can be absolute OR relative to projectRoot
|
|
15
|
+
compilerOptions = {},
|
|
16
|
+
}) {
|
|
17
|
+
if (!projectRoot) {
|
|
18
|
+
throw new Error('createTempBuildTsconfig: projectRoot is required');
|
|
19
|
+
}
|
|
20
|
+
if (!baseTsconfigPath) {
|
|
21
|
+
throw new Error('createTempBuildTsconfig: baseTsconfigPath is required');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const resolvedProjectRoot = path.resolve(projectRoot);
|
|
25
|
+
|
|
26
|
+
// ✅ resolve base tsconfig relative to projectRoot (unless already absolute)
|
|
27
|
+
const resolvedBaseTsconfig = path.isAbsolute(baseTsconfigPath)
|
|
28
|
+
? baseTsconfigPath
|
|
29
|
+
: path.resolve(resolvedProjectRoot, baseTsconfigPath);
|
|
30
|
+
|
|
31
|
+
if (!fs.existsSync(resolvedBaseTsconfig)) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`createTempBuildTsconfig: base tsconfig not found at: ${resolvedBaseTsconfig}`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'unisphere-tsc-'));
|
|
38
|
+
const tempTsconfigPath = path.join(tempDir, 'tsconfig.build.json');
|
|
39
|
+
|
|
40
|
+
// ✅ important: "extends" can be absolute; TS supports it.
|
|
41
|
+
const tsconfig = {
|
|
42
|
+
extends: resolvedBaseTsconfig,
|
|
43
|
+
compilerOptions: {
|
|
44
|
+
...compilerOptions,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
console.log(`creating temporary build file in '${tempTsconfigPath}'`)
|
|
49
|
+
fs.writeFileSync(tempTsconfigPath, JSON.stringify(tsconfig, null, 2), 'utf8');
|
|
50
|
+
|
|
51
|
+
// Optional cleanup
|
|
52
|
+
const cleanup = () => {
|
|
53
|
+
try {
|
|
54
|
+
console.log(`removing temporary folder '${tempDir}'`)
|
|
55
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
56
|
+
} catch { }
|
|
57
|
+
};
|
|
58
|
+
process.on('exit', cleanup);
|
|
59
|
+
process.on('SIGINT', cleanup);
|
|
60
|
+
process.on('SIGTERM', cleanup);
|
|
61
|
+
|
|
62
|
+
return tempTsconfigPath;
|
|
63
|
+
}
|
|
10
64
|
|
|
11
65
|
const { envVariables, isUnisphereEnvironment } = getEnvVariables();
|
|
12
66
|
|
|
67
|
+
function generateDynamicPaths(projectRoot) {
|
|
68
|
+
const paths = {};
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
// Find workspace root by following tsconfig extends chain
|
|
72
|
+
const { workspaceRoot, baseTsconfigPath } = findWorkspaceRoot(projectRoot);
|
|
73
|
+
console.log(`[unisphere] Found workspace root: ${workspaceRoot}`);
|
|
74
|
+
console.log(`[unisphere] Base tsconfig path: ${baseTsconfigPath}`);
|
|
75
|
+
|
|
76
|
+
// Read base tsconfig to get original paths
|
|
77
|
+
if (fs.existsSync(baseTsconfigPath)) {
|
|
78
|
+
const baseTsconfig = JSON.parse(fs.readFileSync(baseTsconfigPath, 'utf8'));
|
|
79
|
+
const originalPaths = baseTsconfig.compilerOptions?.paths || {};
|
|
80
|
+
|
|
81
|
+
console.log(`[unisphere] Found ${Object.keys(originalPaths).length} original paths in base tsconfig`);
|
|
82
|
+
|
|
83
|
+
// Convert each path from .ts to .d.ts in dist folder
|
|
84
|
+
Object.entries(originalPaths).forEach(([key, pathArray]) => {
|
|
85
|
+
const convertedPaths = pathArray.map(originalPath => {
|
|
86
|
+
// Convert index.ts to index.d.ts and prefix with dist
|
|
87
|
+
return originalPath.replace(/index\.ts$/, 'index.d.ts').replace(/^/, 'dist/');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
paths[key] = convertedPaths;
|
|
91
|
+
console.log(`[unisphere] Converted path mapping: ${key} -> ${convertedPaths.join(', ')}`);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.warn(`[unisphere] Failed to generate dynamic paths: ${error.message}`);
|
|
96
|
+
console.log(`[unisphere] Falling back to basic path generation`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.log(`[unisphere] Generated ${Object.keys(paths).length} path mappings`);
|
|
100
|
+
return paths;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function findWorkspaceRoot(projectRoot) {
|
|
104
|
+
let currentPath = projectRoot;
|
|
105
|
+
let tsconfigPath = path.join(currentPath, 'tsconfig.json');
|
|
106
|
+
|
|
107
|
+
console.log(`[unisphere] Starting search from: ${projectRoot}`);
|
|
108
|
+
|
|
109
|
+
while (fs.existsSync(tsconfigPath)) {
|
|
110
|
+
const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf8'));
|
|
111
|
+
const extendsPath = tsconfig.extends;
|
|
112
|
+
|
|
113
|
+
if (!extendsPath) {
|
|
114
|
+
// No extends, this might be the base
|
|
115
|
+
return { workspaceRoot: currentPath, baseTsconfigPath: tsconfigPath };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
console.log(`[unisphere] Found extends: ${extendsPath} in ${tsconfigPath}`);
|
|
119
|
+
|
|
120
|
+
// Resolve the extends path
|
|
121
|
+
const resolvedExtendsPath = path.resolve(path.dirname(tsconfigPath), extendsPath);
|
|
122
|
+
|
|
123
|
+
if (!fs.existsSync(resolvedExtendsPath)) {
|
|
124
|
+
// Can't follow the chain further
|
|
125
|
+
return { workspaceRoot: currentPath, baseTsconfigPath: tsconfigPath };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Check if this is tsconfig.base.json (likely the root)
|
|
129
|
+
if (path.basename(resolvedExtendsPath) === 'tsconfig.base.json') {
|
|
130
|
+
const workspaceRoot = path.dirname(resolvedExtendsPath);
|
|
131
|
+
return { workspaceRoot, baseTsconfigPath: resolvedExtendsPath };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Continue following the chain
|
|
135
|
+
currentPath = path.dirname(resolvedExtendsPath);
|
|
136
|
+
tsconfigPath = resolvedExtendsPath;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Fallback - couldn't find the chain
|
|
140
|
+
throw new Error('Could not find workspace root through tsconfig extends chain');
|
|
141
|
+
}
|
|
142
|
+
|
|
13
143
|
if (!isUnisphereEnvironment) {
|
|
14
144
|
console.warn(
|
|
15
145
|
'WARNING: Building or linting unisphere elements from outside the unisphere cli will not handle runtimes.'
|
|
@@ -27,10 +157,8 @@ const withUnisphere = (config) => {
|
|
|
27
157
|
|
|
28
158
|
const onwarn = config.onwarn;
|
|
29
159
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
config.onwarn = function(warning) {
|
|
33
|
-
if ( warning.code === 'THIS_IS_UNDEFINED' ) { return; }
|
|
160
|
+
config.onwarn = function (warning) {
|
|
161
|
+
if (warning.code === 'THIS_IS_UNDEFINED') { return; }
|
|
34
162
|
return onwarn?.(warning)
|
|
35
163
|
}
|
|
36
164
|
|
|
@@ -59,20 +187,21 @@ const withUnisphere = (config) => {
|
|
|
59
187
|
};
|
|
60
188
|
}
|
|
61
189
|
|
|
62
|
-
config.plugins.push(analyze({
|
|
190
|
+
config.plugins.push(analyze({
|
|
191
|
+
summaryOnly: true, // Adjusts the output to show summary information
|
|
63
192
|
limit: 20 // Limits the output to the top 10 items
|
|
64
|
-
}),
|
|
65
|
-
"process.env['NODE_ENV']": JSON.stringify(`${envVariables.UNISPHERE_ENV}`),
|
|
193
|
+
}), replace({
|
|
194
|
+
"process.env['NODE_ENV']": JSON.stringify(`${envVariables.UNISPHERE_ENV}`),
|
|
66
195
|
preventAssignment: true,
|
|
67
196
|
}),);
|
|
68
197
|
return config;
|
|
69
198
|
};
|
|
70
199
|
|
|
71
|
-
const withUnisphereInterceptors =
|
|
200
|
+
const withUnisphereInterceptors = (config) => {
|
|
72
201
|
console.log('patching rollup package config');
|
|
73
202
|
config.unisphere = {
|
|
74
203
|
interceptors: {
|
|
75
|
-
compilerOptions
|
|
204
|
+
compilerOptions: (options) => {
|
|
76
205
|
return options;
|
|
77
206
|
}
|
|
78
207
|
}
|
|
@@ -92,17 +221,25 @@ module.exports = (unisphereConfig) => {
|
|
|
92
221
|
const outputPath = path.join('..', '..', '..', 'dist', ...sourcePath);
|
|
93
222
|
|
|
94
223
|
|
|
224
|
+
const dynamicPaths = generateDynamicPaths(unisphereConfig.cwd);
|
|
225
|
+
|
|
226
|
+
const tsConfig = createTempBuildTsconfig({
|
|
227
|
+
projectRoot: unisphereConfig.cwd,
|
|
228
|
+
baseTsconfigPath: 'tsconfig.lib.json',
|
|
229
|
+
compilerOptions: {
|
|
230
|
+
paths: dynamicPaths,
|
|
231
|
+
},
|
|
232
|
+
});
|
|
95
233
|
return withUnisphere(withNx(
|
|
96
234
|
{
|
|
97
235
|
main: './src/index.ts',
|
|
98
236
|
outputPath,
|
|
99
|
-
tsConfig:
|
|
100
|
-
compiler: 'babel',
|
|
237
|
+
tsConfig: tsConfig,
|
|
101
238
|
external: ['react', 'react-dom', 'react/jsx-runtime'],
|
|
102
239
|
format: ['esm'],
|
|
103
240
|
assets: [{ input: '.', output: '.', glob: 'README.md' }],
|
|
104
241
|
},
|
|
105
|
-
|
|
242
|
+
withUnisphereInterceptors({
|
|
106
243
|
// Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
|
|
107
244
|
plugins: [
|
|
108
245
|
svg({
|