@common-stack/rollup-vite-utils 8.0.2-alpha.1 → 8.2.1-alpha.1
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/LICENSE +34 -21
- package/lib/config-schema.cjs +104 -103
- package/lib/config-schema.cjs.map +1 -1
- package/lib/config-schema.js +104 -103
- package/lib/config-schema.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.js +1 -1
- package/lib/preStartup/configLoader/configLoader.cjs +135 -2
- package/lib/preStartup/configLoader/configLoader.cjs.map +1 -1
- package/lib/preStartup/configLoader/configLoader.js +135 -2
- package/lib/preStartup/configLoader/configLoader.js.map +1 -1
- package/lib/preStartup/configLoader/index.cjs +1 -1
- package/lib/preStartup/configLoader/index.cjs.map +1 -1
- package/lib/preStartup/configLoader/index.js +1 -1
- package/lib/preStartup/configLoader/index.js.map +1 -1
- package/lib/rollup/modifyLibFiles/extractGraphQLQueries.cjs +6 -2
- package/lib/rollup/modifyLibFiles/extractGraphQLQueries.cjs.map +1 -1
- package/lib/rollup/modifyLibFiles/extractGraphQLQueries.js +6 -2
- package/lib/rollup/modifyLibFiles/extractGraphQLQueries.js.map +1 -1
- package/lib/rollup/modifyLibFiles/handleComponentOrDialog.cjs +2 -3
- package/lib/rollup/modifyLibFiles/handleComponentOrDialog.cjs.map +1 -1
- package/lib/rollup/modifyLibFiles/handleComponentOrDialog.js +2 -3
- package/lib/rollup/modifyLibFiles/handleComponentOrDialog.js.map +1 -1
- package/lib/rollup/modifyLibFiles/handleLoaderReturn.cjs +2 -4
- package/lib/rollup/modifyLibFiles/handleLoaderReturn.cjs.map +1 -1
- package/lib/rollup/modifyLibFiles/handleLoaderReturn.js +2 -4
- package/lib/rollup/modifyLibFiles/handleLoaderReturn.js.map +1 -1
- package/lib/rollup/rollupPluginAddJsExtension.cjs +1 -1
- package/lib/rollup/rollupPluginAddJsExtension.cjs.map +1 -1
- package/lib/rollup/rollupPluginAddJsExtension.js +1 -1
- package/lib/rollup/rollupPluginAddJsExtension.js.map +1 -1
- package/lib/rollup/rollupPluginGenerateJson.cjs +27 -0
- package/lib/rollup/rollupPluginGenerateJson.cjs.map +1 -1
- package/lib/rollup/rollupPluginGenerateJson.d.ts +10 -0
- package/lib/rollup/rollupPluginGenerateJson.js +27 -0
- package/lib/rollup/rollupPluginGenerateJson.js.map +1 -1
- package/lib/rollup/rollupPluginGenerateJson.test.d.ts +1 -0
- package/lib/rollup/rollupPluginUpdateFromConfig.cjs +1 -1
- package/lib/rollup/rollupPluginUpdateFromConfig.js +1 -1
- package/lib/tools/codegen/generateCodegenConfig.cjs +30 -0
- package/lib/tools/codegen/generateCodegenConfig.cjs.map +1 -1
- package/lib/tools/codegen/generateCodegenConfig.js +30 -0
- package/lib/tools/codegen/generateCodegenConfig.js.map +1 -1
- package/lib/tools/codegen/index.cjs.map +1 -1
- package/lib/tools/codegen/index.js.map +1 -1
- package/lib/tools/codegen/performCopyOperations.cjs +94 -17
- package/lib/tools/codegen/performCopyOperations.cjs.map +1 -1
- package/lib/tools/codegen/performCopyOperations.js +94 -17
- package/lib/tools/codegen/performCopyOperations.js.map +1 -1
- package/lib/tools/codegen/readModules.cjs +80 -59
- package/lib/tools/codegen/readModules.cjs.map +1 -1
- package/lib/tools/codegen/readModules.d.ts +0 -18
- package/lib/tools/codegen/readModules.js +80 -59
- package/lib/tools/codegen/readModules.js.map +1 -1
- package/lib/tools/codegen/setupCommonPackage.cjs +14 -5
- package/lib/tools/codegen/setupCommonPackage.cjs.map +1 -1
- package/lib/tools/codegen/setupCommonPackage.d.ts +1 -1
- package/lib/tools/codegen/setupCommonPackage.js +14 -5
- package/lib/tools/codegen/setupCommonPackage.js.map +1 -1
- package/lib/tools/codegen/templates/common/package.json.template +2 -0
- package/lib/tools/codegen/templates/common/scripts/fix-generated-types.js.template +58 -0
- package/lib/tools/codegen/templates/common/src/apollo-context.ts.bk.template +34 -0
- package/lib/tools/codegen/templates/common/src/apollo-context.ts.template +13 -20
- package/lib/tools/codegen/templates/common/src/client-context.ts.template +19 -0
- package/lib/tools/codegen/templates/common/src/core/disposable.ts.template +93 -0
- package/lib/tools/codegen/templates/common/src/core/event.test.ts +16 -0
- package/lib/tools/codegen/templates/common/src/core/event.ts.template +326 -0
- package/lib/tools/codegen/templates/common/src/core/index.ts.template +3 -0
- package/lib/tools/codegen/templates/common/src/core/types.ts.template +1 -0
- package/lib/tools/codegen/templates/common/src/generated/service-schemas.ts.template +1 -0
- package/lib/tools/codegen/templates/common/src/index.server.ts.template +3 -1
- package/lib/tools/codegen/templates/common/src/index.ts.template +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/packageUtils.cjs +142 -2
- package/lib/utils/packageUtils.cjs.map +1 -1
- package/lib/utils/packageUtils.d.ts +65 -0
- package/lib/utils/packageUtils.js +142 -2
- package/lib/utils/packageUtils.js.map +1 -1
- package/lib/utils/utils.cjs +1 -1
- package/lib/utils/utils.js +1 -1
- package/lib/vite-wrappers/generators/clientLoaderGenerator.cjs +11 -3
- package/lib/vite-wrappers/generators/clientLoaderGenerator.cjs.map +1 -1
- package/lib/vite-wrappers/generators/clientLoaderGenerator.js +11 -3
- package/lib/vite-wrappers/generators/clientLoaderGenerator.js.map +1 -1
- package/lib/vite-wrappers/generators/loaderGenerator.cjs +7 -16
- package/lib/vite-wrappers/generators/loaderGenerator.cjs.map +1 -1
- package/lib/vite-wrappers/generators/loaderGenerator.d.ts +1 -0
- package/lib/vite-wrappers/generators/loaderGenerator.js +7 -16
- package/lib/vite-wrappers/generators/loaderGenerator.js.map +1 -1
- package/lib/vite-wrappers/generators/utils/resourceParams.cjs +48 -11
- package/lib/vite-wrappers/generators/utils/resourceParams.cjs.map +1 -1
- package/lib/vite-wrappers/generators/utils/resourceParams.d.ts +10 -4
- package/lib/vite-wrappers/generators/utils/resourceParams.js +48 -11
- package/lib/vite-wrappers/generators/utils/resourceParams.js.map +1 -1
- package/lib/vite-wrappers/icon-switch.cjs +4 -4
- package/lib/vite-wrappers/icon-switch.cjs.map +1 -1
- package/lib/vite-wrappers/icon-switch.js +4 -4
- package/lib/vite-wrappers/icon-switch.js.map +1 -1
- package/lib/vite-wrappers/json-wrappers.cjs +30 -2
- package/lib/vite-wrappers/json-wrappers.cjs.map +1 -1
- package/lib/vite-wrappers/json-wrappers.js +30 -2
- package/lib/vite-wrappers/json-wrappers.js.map +1 -1
- package/lib/vite-wrappers/wrapperComponent.cjs +6 -13
- package/lib/vite-wrappers/wrapperComponent.cjs.map +1 -1
- package/lib/vite-wrappers/wrapperComponent.js +6 -13
- package/lib/vite-wrappers/wrapperComponent.js.map +1 -1
- package/package.json +5 -5
|
@@ -27,6 +27,29 @@ import {execSync}from'child_process';import fs__default from'fs';import path__de
|
|
|
27
27
|
*/
|
|
28
28
|
function performCopyOperations(modules, cdecodePaths = {}, options) {
|
|
29
29
|
let { repoRoot, commonPackagePath } = cdecodePaths;
|
|
30
|
+
// Use the provided commandRunner or default to execSync.
|
|
31
|
+
const commandRunner = options?.commandRunner || ((cmd) => execSync(cmd));
|
|
32
|
+
// Track which files have been added to index.ts files
|
|
33
|
+
const indexExports = new Map();
|
|
34
|
+
// When adding to an index.ts file, check if the export already exists
|
|
35
|
+
function addToIndex(indexPath, exportName) {
|
|
36
|
+
// Initialize tracking for this index file if needed
|
|
37
|
+
if (!indexExports.has(indexPath)) {
|
|
38
|
+
indexExports.set(indexPath, new Set());
|
|
39
|
+
// Create the index file if it doesn't exist
|
|
40
|
+
if (!fs__default.existsSync(indexPath)) {
|
|
41
|
+
commandRunner(`touch ${indexPath}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Check if this export already exists in the index
|
|
45
|
+
const exportsForIndex = indexExports.get(indexPath);
|
|
46
|
+
if (!exportsForIndex.has(exportName)) {
|
|
47
|
+
// Add to tracking
|
|
48
|
+
exportsForIndex.add(exportName);
|
|
49
|
+
// Add to index file
|
|
50
|
+
commandRunner(`echo "${exportName}" >> ${indexPath}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
30
53
|
if (!repoRoot) {
|
|
31
54
|
repoRoot = pathsConfig.repoRoot;
|
|
32
55
|
}
|
|
@@ -34,8 +57,6 @@ function performCopyOperations(modules, cdecodePaths = {}, options) {
|
|
|
34
57
|
// For example, "packages/common"
|
|
35
58
|
commonPackagePath = path__default.join(pathsConfig.repoRoot, 'packages/common');
|
|
36
59
|
}
|
|
37
|
-
// Use the provided commandRunner or default to execSync.
|
|
38
|
-
const commandRunner = options?.commandRunner || ((cmd) => execSync(cmd));
|
|
39
60
|
// Track which resource folders are processed.
|
|
40
61
|
const processedFolders = {};
|
|
41
62
|
// Object to collect enum contributions.
|
|
@@ -121,7 +142,7 @@ function performCopyOperations(modules, cdecodePaths = {}, options) {
|
|
|
121
142
|
// Prepend a comment to indicate the package origin.
|
|
122
143
|
commandRunner(`(echo "// from package: ${pkgName}" && cat ${destFile}) > ${destFile}.tmp && mv ${destFile}.tmp ${destFile}`);
|
|
123
144
|
// Append an export statement to the folder's index.
|
|
124
|
-
|
|
145
|
+
addToIndex(path__default.join(destFolder, 'index.ts'), `export * from './${destFileName.replace('.ts', '')}';`);
|
|
125
146
|
// Replace any import from "common" (or from "common/lib/generated/generated-model" or "common/lib/generated/generated-model.js")
|
|
126
147
|
// with the relative path using a single regex.
|
|
127
148
|
try {
|
|
@@ -140,15 +161,33 @@ function performCopyOperations(modules, cdecodePaths = {}, options) {
|
|
|
140
161
|
const serviceBaseName = destFileName.replace('.ts', '');
|
|
141
162
|
const propertyName = serviceBaseName.charAt(0).toLowerCase() + serviceBaseName.slice(1);
|
|
142
163
|
const augmentationContent = `\n/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
declare module '../apollo-context' {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
`;
|
|
164
|
+
* This file augments the ServerContext interface from the central apollo-context.
|
|
165
|
+
* Through declaration merging, the ${propertyName} will be added to the ServerContext.
|
|
166
|
+
*/
|
|
167
|
+
declare module '../apollo-context' {
|
|
168
|
+
export interface ServerContext {
|
|
169
|
+
${propertyName}: I${serviceBaseName};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
`;
|
|
173
|
+
// Append the augmentation content directly to the service file.
|
|
174
|
+
fs__default.appendFileSync(destFile, augmentationContent, 'utf8');
|
|
175
|
+
}
|
|
176
|
+
// If this is a service file, instead of creating a separate augmentation file,
|
|
177
|
+
// append the augmentation boilerplate directly to the service file.
|
|
178
|
+
if (folderType === 'clients') {
|
|
179
|
+
const serviceBaseName = destFileName.replace('.ts', '');
|
|
180
|
+
const propertyName = serviceBaseName.charAt(0).toLowerCase() + serviceBaseName.slice(1);
|
|
181
|
+
const augmentationContent = `\n/**
|
|
182
|
+
* This file augments the ClientContext interface from the central apollo-context.
|
|
183
|
+
* Through declaration merging, the ${propertyName} will be added to the ServerContext.
|
|
184
|
+
*/
|
|
185
|
+
declare module '../client-context' {
|
|
186
|
+
export interface ClientContext {
|
|
187
|
+
${propertyName}: I${serviceBaseName};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
152
191
|
// Append the augmentation content directly to the service file.
|
|
153
192
|
fs__default.appendFileSync(destFile, augmentationContent, 'utf8');
|
|
154
193
|
}
|
|
@@ -185,7 +224,7 @@ declare module '../apollo-context' {
|
|
|
185
224
|
// Close the enum declaration.
|
|
186
225
|
commandRunner(`echo "}" >> ${aggregatedFile}`);
|
|
187
226
|
// Append an export statement to the enums index.
|
|
188
|
-
|
|
227
|
+
addToIndex(path__default.join(enumDestFolder, 'index.ts'), `export * from './${enumName}';`);
|
|
189
228
|
}
|
|
190
229
|
}
|
|
191
230
|
else {
|
|
@@ -216,7 +255,7 @@ declare module '../apollo-context' {
|
|
|
216
255
|
// Close the object literal.
|
|
217
256
|
commandRunner(`echo "};" >> ${aggregatedFile}`);
|
|
218
257
|
// Append an export statement to the constants index.
|
|
219
|
-
|
|
258
|
+
addToIndex(path__default.join(constantsDestFolder, 'index.ts'), `export * from './${constName}';`);
|
|
220
259
|
}
|
|
221
260
|
}
|
|
222
261
|
else {
|
|
@@ -231,14 +270,52 @@ declare module '../apollo-context' {
|
|
|
231
270
|
if (processedFolders[folderKey]) {
|
|
232
271
|
// For services/repositories use index.server.ts; others use index.ts.
|
|
233
272
|
const globalIndexFileName = folderKey === 'services' || folderKey === 'repositories' ? 'index.server.ts' : 'index.ts';
|
|
234
|
-
|
|
273
|
+
addToIndex(path__default.join(commonPackagePath, 'src', globalIndexFileName), `export * from './${folderKey}';`);
|
|
235
274
|
}
|
|
236
275
|
}
|
|
237
276
|
// Now, handle constants specially.
|
|
238
277
|
if (processedFolders.constants) {
|
|
239
278
|
// Global client index should export from constants/index
|
|
240
|
-
commandRunner(
|
|
279
|
+
// commandRunner(
|
|
280
|
+
// `echo "export * from './constants/index';" >> ${path.join(commonPackagePath, 'src', 'index.ts')}`,
|
|
281
|
+
// );
|
|
282
|
+
addToIndex(path__default.join(commonPackagePath, 'src', 'index.ts'), `export * from './constants';`);
|
|
241
283
|
// Global server index should export from constants/index.server
|
|
242
|
-
commandRunner(
|
|
284
|
+
// commandRunner(
|
|
285
|
+
// `echo "export * from './constants/index.server';" >> ${path.join(commonPackagePath, 'src', 'index.server.ts')}`,
|
|
286
|
+
// );
|
|
287
|
+
addToIndex(path__default.join(commonPackagePath, 'src', 'index.server.ts'), `export * from './constants';`);
|
|
288
|
+
}
|
|
289
|
+
console.log('.....processedFolders', JSON.stringify(processedFolders, null, 2));
|
|
290
|
+
if (processedFolders.enums) {
|
|
291
|
+
// commandRunner(`echo "export * from './enums';" >> ${path.join(commonPackagePath, 'src', 'index.ts')}`);
|
|
292
|
+
commandRunner(`echo "export * from './enums';" >> ${path__default.join(commonPackagePath, 'src', 'index.server.ts')}`);
|
|
293
|
+
}
|
|
294
|
+
if (processedFolders.modules) {
|
|
295
|
+
// commandRunner(`echo "export * from './modules';" >> ${path.join(commonPackagePath, 'src', 'index.ts')}`);
|
|
296
|
+
commandRunner(`echo "export * from './modules';" >> ${path__default.join(commonPackagePath, 'src', 'index.server.ts')}`);
|
|
297
|
+
}
|
|
298
|
+
const filePath = path__default.join(commonPackagePath, 'src', 'apollo-context.ts');
|
|
299
|
+
// Check if the file exists
|
|
300
|
+
if (fs__default.existsSync(filePath)) {
|
|
301
|
+
// Read the file content
|
|
302
|
+
let fileContent = fs__default.readFileSync(filePath, 'utf-8');
|
|
303
|
+
// Regex to match 'accessRoleService: any;' in 'ServerContext' interface
|
|
304
|
+
const accessRoleRegex = /\s*accessRoleService\s*:\s*any\s*;\s*/;
|
|
305
|
+
// Check if 'accessRoleService' exists in 'ServerContext'
|
|
306
|
+
if (accessRoleRegex.test(fileContent)) {
|
|
307
|
+
console.log("'accessRoleService' found in the 'ServerContext' interface.");
|
|
308
|
+
// Remove 'accessRoleService: any;' from the 'ServerContext' interface
|
|
309
|
+
fileContent = fileContent.replace(accessRoleRegex, '');
|
|
310
|
+
// Save the updated file content
|
|
311
|
+
fs__default.writeFileSync(filePath, fileContent, 'utf-8');
|
|
312
|
+
console.log("Updated 'ServerContext' by removing 'accessRoleService: any;'");
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
console.log("'accessRoleService' not found in the 'ServerContext' interface.");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
console.error(`File ${filePath} does not exist.`);
|
|
243
320
|
}
|
|
244
321
|
}export{performCopyOperations};//# sourceMappingURL=performCopyOperations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performCopyOperations.js","sources":["../../../src/tools/codegen/performCopyOperations.ts"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"performCopyOperations.js","sources":["../../../src/tools/codegen/performCopyOperations.ts"],"sourcesContent":[null],"names":["fs","path"],"mappings":"4LAAA;AACA;AACA;AACA;AACA;AAYA;;;;;;;;;;;;;;;;;;;;;AAqBG;AACG,SAAU,qB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AC;;YAG3E,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;;YAGvDA,WAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AACjD,YAAA,OAAO,CAAC,GAAG,CAAC,+DAA+D,CAAC,CAAC;SAChF;aAAM;AACH,YAAA,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;SAClF;KACJ;SAAM;AACH,QAAA,OAAO,CAAC,KAAK,CAAC,QAAQ,QAAQ,CAAA,gBAAA,CAAkB,CAAC,CAAC;KACrD;AACL"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
'use strict';var fs=require('fs'),path=require('path'),module$1=require('module'),commonPaths=require('./commonPaths.cjs');var_documentCurrentScript=typeofdocument!=='undefined'?document.currentScript:null
|
|
1
|
+
'use strict';var fs=require('fs'),path=require('path'),module$1=require('module'),packageUtils=require('../../utils/packageUtils.cjs'),commonPaths=require('./commonPaths.cjs');var_documentCurrentScript=typeofdocument!=='undefined'?document.currentScript:null;/* eslint-disable no-lonely-if */
|
|
2
|
+
/* eslint-disable no-use-before-define */
|
|
3
|
+
// ESM-compatible require
|
|
2
4
|
const esmRequire = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('tools/codegen/readModules.cjs', document.baseURI).href)));
|
|
3
5
|
/**
|
|
4
6
|
* For local modules, if the relative path ends with "lib",
|
|
@@ -88,24 +90,6 @@ function transformModules(modules) {
|
|
|
88
90
|
});
|
|
89
91
|
return [...finalOutput, ...Array.from(variantGroups.values())];
|
|
90
92
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Reads modules from one or more JSON config files (e.g., cdecode-config.json) and returns an array,
|
|
93
|
-
* transformed into the final desired output format of module objects.
|
|
94
|
-
*
|
|
95
|
-
* The processing steps are:
|
|
96
|
-
* 1. Load module names (from keys such as modules, externalModules, devModules) from each config.
|
|
97
|
-
* 2. Deduplicate the raw module names.
|
|
98
|
-
* 3. For each raw module string, attempt to resolve it using esmRequire.resolve (with fallback).
|
|
99
|
-
* 4. Compute the module's base folder relative to the repository root.
|
|
100
|
-
* 5. Determine if the module is local (i.e. does not live in node_modules).
|
|
101
|
-
* 6. For local modules, decide whether it is "variant" (if the raw config string indicates "-browser" or "-server")
|
|
102
|
-
* or independent (if not).
|
|
103
|
-
* 7. Optionally, if a package.json exists, adjust the server path using its "main" field.
|
|
104
|
-
* 8. Finally, transform the processed definitions into the desired output format.
|
|
105
|
-
*
|
|
106
|
-
* @param {string[]} configPaths - Array of configuration file paths.
|
|
107
|
-
* @returns {any[]} Final processed module objects.
|
|
108
|
-
*/
|
|
109
93
|
function readModules(configPaths = []) {
|
|
110
94
|
const rawModuleSet = new Set();
|
|
111
95
|
// Collect raw module names from all config files.
|
|
@@ -125,53 +109,54 @@ function readModules(configPaths = []) {
|
|
|
125
109
|
try {
|
|
126
110
|
// Determine if the raw config string suggests a variant module.
|
|
127
111
|
const isVariant = rawStr.includes('-browser') || rawStr.endsWith('-server');
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// If resolution fails, try to use error file details.
|
|
135
|
-
if (err && typeof err === 'object' && 'path' in err && typeof err.path === 'string') {
|
|
136
|
-
let filePath = err.path;
|
|
137
|
-
// Check if the file path includes a "/lib/" segment.
|
|
138
|
-
const libSegment = `${path.sep}lib${path.sep}`;
|
|
139
|
-
const libIndex = filePath.indexOf(libSegment);
|
|
140
|
-
if (libIndex !== -1) {
|
|
141
|
-
// Remove the lib folder and what follows, then append package.json.
|
|
142
|
-
filePath = filePath.slice(0, libIndex);
|
|
143
|
-
filePath = path.join(filePath, 'package.json');
|
|
144
|
-
}
|
|
145
|
-
if (fs.existsSync(filePath)) {
|
|
146
|
-
resolvedFile = filePath;
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
// Fallback: if the error-derived path fails, remove "/lib" from the raw string.
|
|
150
|
-
const fallbackModule = rawStr.includes('/lib') ? rawStr.replace(/\/lib.*$/, '') : rawStr;
|
|
151
|
-
try {
|
|
152
|
-
resolvedFile = esmRequire.resolve(path.join(fallbackModule, 'package.json'));
|
|
153
|
-
}
|
|
154
|
-
catch (err2) {
|
|
155
|
-
console.warn(`Could not resolve module ${rawStr} even with fallback ${fallbackModule}. Skipping.`);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
112
|
+
// For internal/local packages, construct path directly
|
|
113
|
+
let resolvedFile = null;
|
|
114
|
+
if (rawStr.startsWith('packages-modules/')) {
|
|
115
|
+
const localPath = path.join(process.cwd(), rawStr, 'package.json');
|
|
116
|
+
if (fs.existsSync(localPath)) {
|
|
117
|
+
resolvedFile = localPath;
|
|
159
118
|
}
|
|
160
119
|
else {
|
|
161
|
-
//
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
resolvedFile =
|
|
120
|
+
// If not found at cwd, try from repo root
|
|
121
|
+
const repoRootPath = path.join(commonPaths.pathsConfig.repoRoot, rawStr, 'package.json');
|
|
122
|
+
if (fs.existsSync(repoRootPath)) {
|
|
123
|
+
resolvedFile = repoRootPath;
|
|
165
124
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
resolvedFile = packageUtils.resolvePackageJson(rawStr, esmRequire, {
|
|
129
|
+
repoRoot: commonPaths.pathsConfig.repoRoot,
|
|
130
|
+
});
|
|
131
|
+
if (!resolvedFile) {
|
|
132
|
+
// For subpaths like '@pkg/name/subpath', try resolving the base package
|
|
133
|
+
const basePackageName = rawStr
|
|
134
|
+
.split('/')
|
|
135
|
+
.slice(0, rawStr.startsWith('@') ? 2 : 1)
|
|
136
|
+
.join('/');
|
|
137
|
+
if (basePackageName !== rawStr) {
|
|
138
|
+
resolvedFile = packageUtils.resolvePackageJson(basePackageName, esmRequire, {
|
|
139
|
+
repoRoot: commonPaths.pathsConfig.repoRoot,
|
|
140
|
+
});
|
|
169
141
|
}
|
|
170
142
|
}
|
|
171
143
|
}
|
|
144
|
+
if (!resolvedFile) {
|
|
145
|
+
console.warn(`Could not resolve module ${rawStr}. Skipping.`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
172
148
|
const dirName = path.dirname(resolvedFile);
|
|
149
|
+
// Follow symlinks to get the real path for linked packages
|
|
150
|
+
let realDirPath;
|
|
151
|
+
try {
|
|
152
|
+
realDirPath = fs.realpathSync(dirName);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
// If realpath fails, fall back to the original path
|
|
156
|
+
realDirPath = dirName;
|
|
157
|
+
}
|
|
173
158
|
// Compute the folder path relative to the repository root.
|
|
174
|
-
const modulePathRaw = path.relative(commonPaths.pathsConfig.repoRoot,
|
|
159
|
+
const modulePathRaw = path.relative(commonPaths.pathsConfig.repoRoot, realDirPath);
|
|
175
160
|
const isLocal = !modulePathRaw.split(path.sep).includes('node_modules');
|
|
176
161
|
const baseModule = isLocal ? normalizeLocalBase(modulePathRaw) : modulePathRaw.replace(/\/lib.*/, '');
|
|
177
162
|
// Avoid duplicates based on the computed base.
|
|
@@ -245,5 +230,41 @@ function readModules(configPaths = []) {
|
|
|
245
230
|
});
|
|
246
231
|
// Transform the intermediate definitions into the final output format.
|
|
247
232
|
const finalOutput = transformModules(collectedModules);
|
|
248
|
-
|
|
233
|
+
// Before returning the final output, deduplicate the modules
|
|
234
|
+
const uniqueModules = deduplicateModules(finalOutput);
|
|
235
|
+
return uniqueModules;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Deduplicates modules to prevent processing the same package multiple times.
|
|
239
|
+
* Checks all paths (server, client, browser, core, independent) for duplicates.
|
|
240
|
+
*/
|
|
241
|
+
function deduplicateModules(modules) {
|
|
242
|
+
// Track all paths we've seen
|
|
243
|
+
const seenPaths = new Set();
|
|
244
|
+
const result = [];
|
|
245
|
+
for (const mod of modules) {
|
|
246
|
+
let newPaths = false;
|
|
247
|
+
// Create a copy of the module to potentially modify
|
|
248
|
+
const newMod = { ...mod };
|
|
249
|
+
// Check each path type
|
|
250
|
+
for (const pathType of ['server', 'client', 'browser', 'core', 'independent']) {
|
|
251
|
+
if (mod[pathType]) {
|
|
252
|
+
if (seenPaths.has(mod[pathType])) {
|
|
253
|
+
// This path is a duplicate, remove it from our new module
|
|
254
|
+
delete newMod[pathType];
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// New path, add to seen set
|
|
258
|
+
seenPaths.add(mod[pathType]);
|
|
259
|
+
newPaths = true;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Only add the module if it has at least one new path
|
|
264
|
+
// and we've removed any duplicate paths
|
|
265
|
+
if (newPaths) {
|
|
266
|
+
result.push(newMod);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return result;
|
|
249
270
|
}exports.readModules=readModules;//# sourceMappingURL=readModules.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readModules.cjs","sources":["../../../src/tools/codegen/readModules.ts"],"sourcesContent":[null],"names":["createRequire","pathsConfig"],"mappings":"
|
|
1
|
+
{"version":3,"file":"readModules.cjs","sources":["../../../src/tools/codegen/readModules.ts"],"sourcesContent":[null],"names":["createRequire","pathsConfig","resolvePackageJson"],"mappings":"mQAAA;AACA;AAQA;AACA,MAAM,UAAU,GAAGA,sBAAa,CAAC,+QAAe,CAAC,CAAC;AAkBlD;;;AAGG;AACH,SAAS,kBAAkB,CAAC,UAAkB,EAAA;IAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK,EAAE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EAAE,CAAC;AAEzB,IAAA,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;QAGvB,IAAI,QAAQ,GAAG,KAAK,CAAC;;AAGrB,QAAA,MAAM,MAAM,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;;AAG1B,QAAA,KAAK,MAAM,QAAQ,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE;AAC3E,YAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE;gBACf,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE;;AAE9B,oBAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;iBAE3B;qBAAM;;oBAEH,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;oBAC7B,QAAQ,GAAG,IAAI,CAAC;iBACnB;aACJ;SACJ;;;QAID,IAAI,QAAQ,EAAE;AACV,YAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACvB;KACJ;AAED,IAAA,OAAO,MAAM,CAAC;AAClB"}
|
|
@@ -12,22 +12,4 @@ export interface ModuleDefinition {
|
|
|
12
12
|
isVariant?: boolean;
|
|
13
13
|
isIndependentLocal?: boolean;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Reads modules from one or more JSON config files (e.g., cdecode-config.json) and returns an array,
|
|
17
|
-
* transformed into the final desired output format of module objects.
|
|
18
|
-
*
|
|
19
|
-
* The processing steps are:
|
|
20
|
-
* 1. Load module names (from keys such as modules, externalModules, devModules) from each config.
|
|
21
|
-
* 2. Deduplicate the raw module names.
|
|
22
|
-
* 3. For each raw module string, attempt to resolve it using esmRequire.resolve (with fallback).
|
|
23
|
-
* 4. Compute the module's base folder relative to the repository root.
|
|
24
|
-
* 5. Determine if the module is local (i.e. does not live in node_modules).
|
|
25
|
-
* 6. For local modules, decide whether it is "variant" (if the raw config string indicates "-browser" or "-server")
|
|
26
|
-
* or independent (if not).
|
|
27
|
-
* 7. Optionally, if a package.json exists, adjust the server path using its "main" field.
|
|
28
|
-
* 8. Finally, transform the processed definitions into the desired output format.
|
|
29
|
-
*
|
|
30
|
-
* @param {string[]} configPaths - Array of configuration file paths.
|
|
31
|
-
* @returns {any[]} Final processed module objects.
|
|
32
|
-
*/
|
|
33
15
|
export declare function readModules(configPaths?: string[]): any[];
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import fs__default from'fs';import path__default from'path';import {createRequire}from'module';import {pathsConfig}from'./commonPaths.js'
|
|
1
|
+
import fs__default from'fs';import path__default from'path';import {createRequire}from'module';import {resolvePackageJson}from'../../utils/packageUtils.js';import {pathsConfig}from'./commonPaths.js';/* eslint-disable no-lonely-if */
|
|
2
|
+
/* eslint-disable no-use-before-define */
|
|
3
|
+
// ESM-compatible require
|
|
2
4
|
const esmRequire = createRequire(import.meta.url);
|
|
3
5
|
/**
|
|
4
6
|
* For local modules, if the relative path ends with "lib",
|
|
@@ -88,24 +90,6 @@ function transformModules(modules) {
|
|
|
88
90
|
});
|
|
89
91
|
return [...finalOutput, ...Array.from(variantGroups.values())];
|
|
90
92
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Reads modules from one or more JSON config files (e.g., cdecode-config.json) and returns an array,
|
|
93
|
-
* transformed into the final desired output format of module objects.
|
|
94
|
-
*
|
|
95
|
-
* The processing steps are:
|
|
96
|
-
* 1. Load module names (from keys such as modules, externalModules, devModules) from each config.
|
|
97
|
-
* 2. Deduplicate the raw module names.
|
|
98
|
-
* 3. For each raw module string, attempt to resolve it using esmRequire.resolve (with fallback).
|
|
99
|
-
* 4. Compute the module's base folder relative to the repository root.
|
|
100
|
-
* 5. Determine if the module is local (i.e. does not live in node_modules).
|
|
101
|
-
* 6. For local modules, decide whether it is "variant" (if the raw config string indicates "-browser" or "-server")
|
|
102
|
-
* or independent (if not).
|
|
103
|
-
* 7. Optionally, if a package.json exists, adjust the server path using its "main" field.
|
|
104
|
-
* 8. Finally, transform the processed definitions into the desired output format.
|
|
105
|
-
*
|
|
106
|
-
* @param {string[]} configPaths - Array of configuration file paths.
|
|
107
|
-
* @returns {any[]} Final processed module objects.
|
|
108
|
-
*/
|
|
109
93
|
function readModules(configPaths = []) {
|
|
110
94
|
const rawModuleSet = new Set();
|
|
111
95
|
// Collect raw module names from all config files.
|
|
@@ -125,53 +109,54 @@ function readModules(configPaths = []) {
|
|
|
125
109
|
try {
|
|
126
110
|
// Determine if the raw config string suggests a variant module.
|
|
127
111
|
const isVariant = rawStr.includes('-browser') || rawStr.endsWith('-server');
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// If resolution fails, try to use error file details.
|
|
135
|
-
if (err && typeof err === 'object' && 'path' in err && typeof err.path === 'string') {
|
|
136
|
-
let filePath = err.path;
|
|
137
|
-
// Check if the file path includes a "/lib/" segment.
|
|
138
|
-
const libSegment = `${path__default.sep}lib${path__default.sep}`;
|
|
139
|
-
const libIndex = filePath.indexOf(libSegment);
|
|
140
|
-
if (libIndex !== -1) {
|
|
141
|
-
// Remove the lib folder and what follows, then append package.json.
|
|
142
|
-
filePath = filePath.slice(0, libIndex);
|
|
143
|
-
filePath = path__default.join(filePath, 'package.json');
|
|
144
|
-
}
|
|
145
|
-
if (fs__default.existsSync(filePath)) {
|
|
146
|
-
resolvedFile = filePath;
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
// Fallback: if the error-derived path fails, remove "/lib" from the raw string.
|
|
150
|
-
const fallbackModule = rawStr.includes('/lib') ? rawStr.replace(/\/lib.*$/, '') : rawStr;
|
|
151
|
-
try {
|
|
152
|
-
resolvedFile = esmRequire.resolve(path__default.join(fallbackModule, 'package.json'));
|
|
153
|
-
}
|
|
154
|
-
catch (err2) {
|
|
155
|
-
console.warn(`Could not resolve module ${rawStr} even with fallback ${fallbackModule}. Skipping.`);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
112
|
+
// For internal/local packages, construct path directly
|
|
113
|
+
let resolvedFile = null;
|
|
114
|
+
if (rawStr.startsWith('packages-modules/')) {
|
|
115
|
+
const localPath = path__default.join(process.cwd(), rawStr, 'package.json');
|
|
116
|
+
if (fs__default.existsSync(localPath)) {
|
|
117
|
+
resolvedFile = localPath;
|
|
159
118
|
}
|
|
160
119
|
else {
|
|
161
|
-
//
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
resolvedFile =
|
|
120
|
+
// If not found at cwd, try from repo root
|
|
121
|
+
const repoRootPath = path__default.join(pathsConfig.repoRoot, rawStr, 'package.json');
|
|
122
|
+
if (fs__default.existsSync(repoRootPath)) {
|
|
123
|
+
resolvedFile = repoRootPath;
|
|
165
124
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
resolvedFile = resolvePackageJson(rawStr, esmRequire, {
|
|
129
|
+
repoRoot: pathsConfig.repoRoot,
|
|
130
|
+
});
|
|
131
|
+
if (!resolvedFile) {
|
|
132
|
+
// For subpaths like '@pkg/name/subpath', try resolving the base package
|
|
133
|
+
const basePackageName = rawStr
|
|
134
|
+
.split('/')
|
|
135
|
+
.slice(0, rawStr.startsWith('@') ? 2 : 1)
|
|
136
|
+
.join('/');
|
|
137
|
+
if (basePackageName !== rawStr) {
|
|
138
|
+
resolvedFile = resolvePackageJson(basePackageName, esmRequire, {
|
|
139
|
+
repoRoot: pathsConfig.repoRoot,
|
|
140
|
+
});
|
|
169
141
|
}
|
|
170
142
|
}
|
|
171
143
|
}
|
|
144
|
+
if (!resolvedFile) {
|
|
145
|
+
console.warn(`Could not resolve module ${rawStr}. Skipping.`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
172
148
|
const dirName = path__default.dirname(resolvedFile);
|
|
149
|
+
// Follow symlinks to get the real path for linked packages
|
|
150
|
+
let realDirPath;
|
|
151
|
+
try {
|
|
152
|
+
realDirPath = fs__default.realpathSync(dirName);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
// If realpath fails, fall back to the original path
|
|
156
|
+
realDirPath = dirName;
|
|
157
|
+
}
|
|
173
158
|
// Compute the folder path relative to the repository root.
|
|
174
|
-
const modulePathRaw = path__default.relative(pathsConfig.repoRoot,
|
|
159
|
+
const modulePathRaw = path__default.relative(pathsConfig.repoRoot, realDirPath);
|
|
175
160
|
const isLocal = !modulePathRaw.split(path__default.sep).includes('node_modules');
|
|
176
161
|
const baseModule = isLocal ? normalizeLocalBase(modulePathRaw) : modulePathRaw.replace(/\/lib.*/, '');
|
|
177
162
|
// Avoid duplicates based on the computed base.
|
|
@@ -245,5 +230,41 @@ function readModules(configPaths = []) {
|
|
|
245
230
|
});
|
|
246
231
|
// Transform the intermediate definitions into the final output format.
|
|
247
232
|
const finalOutput = transformModules(collectedModules);
|
|
248
|
-
|
|
233
|
+
// Before returning the final output, deduplicate the modules
|
|
234
|
+
const uniqueModules = deduplicateModules(finalOutput);
|
|
235
|
+
return uniqueModules;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Deduplicates modules to prevent processing the same package multiple times.
|
|
239
|
+
* Checks all paths (server, client, browser, core, independent) for duplicates.
|
|
240
|
+
*/
|
|
241
|
+
function deduplicateModules(modules) {
|
|
242
|
+
// Track all paths we've seen
|
|
243
|
+
const seenPaths = new Set();
|
|
244
|
+
const result = [];
|
|
245
|
+
for (const mod of modules) {
|
|
246
|
+
let newPaths = false;
|
|
247
|
+
// Create a copy of the module to potentially modify
|
|
248
|
+
const newMod = { ...mod };
|
|
249
|
+
// Check each path type
|
|
250
|
+
for (const pathType of ['server', 'client', 'browser', 'core', 'independent']) {
|
|
251
|
+
if (mod[pathType]) {
|
|
252
|
+
if (seenPaths.has(mod[pathType])) {
|
|
253
|
+
// This path is a duplicate, remove it from our new module
|
|
254
|
+
delete newMod[pathType];
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// New path, add to seen set
|
|
258
|
+
seenPaths.add(mod[pathType]);
|
|
259
|
+
newPaths = true;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Only add the module if it has at least one new path
|
|
264
|
+
// and we've removed any duplicate paths
|
|
265
|
+
if (newPaths) {
|
|
266
|
+
result.push(newMod);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return result;
|
|
249
270
|
}export{readModules};//# sourceMappingURL=readModules.js.map
|