@common-stack/rollup-vite-utils 8.0.1-alpha.0 → 8.0.1-alpha.2

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.
@@ -1,140 +1,249 @@
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;// If you also need checkFileExists, import it from the same file:
2
- // import { pathsConfig, checkFileExists } from './commonPaths.mjs';
3
- // ESM-compatible require
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;// ESM-compatible require
4
2
  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)));
5
3
  /**
6
- * Reads modules from JSON config files and returns an array of module objects.
4
+ * For local modules, if the relative path ends with "lib",
5
+ * remove that segment so that the package root is used.
6
+ */
7
+ function normalizeLocalBase(modulePath) {
8
+ const parts = modulePath.split(path.sep);
9
+ if (parts[parts.length - 1] === 'lib') {
10
+ parts.pop();
11
+ }
12
+ return parts.join(path.sep);
13
+ }
14
+ /**
15
+ * For variant local modules, strip off a trailing role folder (if present)
16
+ * so that the group name equals the package base.
17
+ * E.g. "packages-modules/mail-campaign/browser" becomes "packages-modules/mail-campaign".
18
+ */
19
+ function getInternalGroupName(modName) {
20
+ const segments = modName.split(path.sep);
21
+ const variants = ['server', 'client', 'browser', 'core'];
22
+ if (segments.length && variants.includes(segments[segments.length - 1])) {
23
+ segments.pop();
24
+ }
25
+ return segments.join(path.sep);
26
+ }
27
+ /**
28
+ * Determines if a module is external by checking if its computed name starts with "node_modules".
29
+ * (This approach does not rely on any hard-coded vendor-specific package name prefixes.)
30
+ */
31
+ function isExternalModule(mod) {
32
+ return mod.name.split(path.sep)[0] === 'node_modules';
33
+ }
34
+ /**
35
+ * Transforms the collected module definitions into the desired final output format.
7
36
  *
8
- * The function separates modules into client and server arrays based on the suffix (“-server”),
9
- * then it attempts to resolve each module’s location. If the resolution fails—often due to a missing
10
- * "lib" folder on external packages—it falls back by removing any `/lib` reference from the module name.
37
+ * - External modules:
38
+ * If the module name contains "-browser", output an object with keys "browser", "client" and "core".
39
+ * The client and core are computed by replacing the "-browser" suffix with "-client" and "-core" respectively.
40
+ * • Else if the name ends with "-server", output an object with key "server".
41
+ * • Otherwise, output an object with key "independent".
11
42
  *
12
- * For local modules it always returns an object with { client, core, browser, server } keys.
13
- * For modules from node_modules, it generates paths based on naming conventions.
43
+ * - Internal (local) modules:
44
+ * If the module is flagged as independent (flat, no variant indicated), output an object with key "independent"
45
+ * that points to `<baseModule>/src`.
46
+ * • Otherwise (when flagged as variant) group them by their normalized base and output a single object containing
47
+ * four keys: client, core, browser, and server (e.g. `<groupName>/client/src`, etc.).
14
48
  */
15
- function readModules(serverConfigPaths = []) {
16
- // Separate client and server modules while loading the JSON config files.
17
- const [clientModules, serverModules] = serverConfigPaths.reduce((acc, configFile) => {
18
- if (!fs.existsSync(configFile)) {
19
- console.error(`Config file not found: ${configFile}`);
20
- process.exit(1);
21
- }
22
- const configData = JSON.parse(fs.readFileSync(configFile, 'utf-8'));
23
- // Process regular modules.
24
- configData.modules?.forEach((mod) => {
25
- if (mod.endsWith('-server')) {
26
- acc[1].push(mod);
27
- }
28
- else {
29
- acc[0].push(mod);
49
+ function transformModules(modules) {
50
+ const finalOutput = [];
51
+ const variantGroups = new Map();
52
+ modules.forEach((mod) => {
53
+ if (isExternalModule(mod)) {
54
+ // External modules: check if the computed name indicates a browser variant.
55
+ if (mod.name.includes('-browser')) {
56
+ // Remove only the trailing "-browser" occurrence to compute client/core names.
57
+ const base = mod.name.replace(/-browser$/, '');
58
+ finalOutput.push({
59
+ client: `${base}-client/lib`,
60
+ core: `${base}-core/lib`,
61
+ browser: `${base}-browser/lib`,
62
+ });
30
63
  }
31
- });
32
- // Process external modules.
33
- configData.externalModules?.forEach((mod) => {
34
- if (mod.endsWith('-server')) {
35
- acc[1].push(mod);
64
+ else if (mod.name.endsWith('-server')) {
65
+ finalOutput.push({ server: `${mod.name}/lib` });
36
66
  }
37
67
  else {
38
- acc[0].push(mod);
68
+ finalOutput.push({ independent: `${mod.name}/lib` });
39
69
  }
40
- });
41
- // Process devModules.
42
- configData.devModules?.forEach((mod) => {
43
- if (mod.endsWith('-server')) {
44
- acc[1].push(mod);
70
+ }
71
+ else {
72
+ // Internal (local) modules.
73
+ if (mod.isIndependentLocal) {
74
+ finalOutput.push({ independent: `${mod.name}/src` });
45
75
  }
46
76
  else {
47
- acc[0].push(mod);
77
+ const groupName = getInternalGroupName(mod.name);
78
+ if (!variantGroups.has(groupName)) {
79
+ variantGroups.set(groupName, {
80
+ client: `${groupName}/client/src`,
81
+ core: `${groupName}/core/src`,
82
+ browser: `${groupName}/browser/src`,
83
+ server: `${groupName}/server/src`,
84
+ });
85
+ }
48
86
  }
49
- });
50
- return acc;
51
- }, [[], []]);
52
- // Combine modules uniquely
53
- const allModules = [...new Set([...clientModules, ...serverModules])];
54
- const processedModules = new Set();
55
- return allModules.reduce((acc, moduleName) => {
87
+ }
88
+ });
89
+ return [...finalOutput, ...Array.from(variantGroups.values())];
90
+ }
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
+ function readModules(configPaths = []) {
110
+ const rawModuleSet = new Set();
111
+ // Collect raw module names from all config files.
112
+ configPaths.forEach((configFile) => {
113
+ if (!fs.existsSync(configFile)) {
114
+ console.error(`Config file not found: ${configFile}`);
115
+ process.exit(1);
116
+ }
117
+ const configData = JSON.parse(fs.readFileSync(configFile, 'utf-8'));
118
+ (configData.modules || []).forEach((mod) => rawModuleSet.add(mod));
119
+ (configData.externalModules || []).forEach((mod) => rawModuleSet.add(mod));
120
+ (configData.devModules || []).forEach((mod) => rawModuleSet.add(mod));
121
+ });
122
+ const collectedModules = [];
123
+ // Process each unique raw module.
124
+ rawModuleSet.forEach((rawStr) => {
56
125
  try {
126
+ // Determine if the raw config string suggests a variant module.
127
+ const isVariant = rawStr.includes('-browser') || rawStr.endsWith('-server');
57
128
  let resolvedFile;
58
129
  try {
59
- // Attempt normal resolution.
60
- resolvedFile = esmRequire.resolve(moduleName);
130
+ // Primary resolution: try to resolve directly to package.json.
131
+ resolvedFile = esmRequire.resolve(path.join(rawStr, 'package.json'));
61
132
  }
62
133
  catch (err) {
63
- // Fallback resolution: if the module name includes "/lib", remove it and try again.
64
- const fallbackModule = moduleName.includes('/lib') ? moduleName.replace(/\/lib.*$/, '') : moduleName;
65
- try {
66
- resolvedFile = esmRequire.resolve(fallbackModule);
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
+ }
67
159
  }
68
- catch (err2) {
69
- console.warn(`Could not resolve module ${moduleName} even with fallback ${fallbackModule}. Skipping.`);
70
- return acc;
160
+ else {
161
+ // Fallback resolution if error object doesn't contain a path.
162
+ const fallbackModule = rawStr.includes('/lib') ? rawStr.replace(/\/lib.*$/, '') : rawStr;
163
+ try {
164
+ resolvedFile = esmRequire.resolve(path.join(fallbackModule, 'package.json'));
165
+ }
166
+ catch (err2) {
167
+ console.warn(`Could not resolve module ${rawStr} even with fallback ${fallbackModule}. Skipping.`);
168
+ return;
169
+ }
71
170
  }
72
171
  }
73
172
  const dirName = path.dirname(resolvedFile);
74
- const modulePath = path.relative(commonPaths.pathsConfig.repoRoot, dirName);
75
- // Reverse the split parts to check if "node_modules" exists.
76
- const [dir, pkg, ...rest] = modulePath.split('/').reverse();
77
- const isLocal = !rest.includes('node_modules');
78
- const baseModule = isLocal ? [...rest].reverse().join('/') : modulePath.replace('/lib', '');
79
- if (processedModules.has(baseModule)) {
80
- return acc;
81
- }
82
- processedModules.add(baseModule);
83
- // For local modules, use "src" directory; for node_modules, use "lib"
173
+ // Compute the folder path relative to the repository root.
174
+ const modulePathRaw = path.relative(commonPaths.pathsConfig.repoRoot, dirName);
175
+ const isLocal = !modulePathRaw.split(path.sep).includes('node_modules');
176
+ const baseModule = isLocal ? normalizeLocalBase(modulePathRaw) : modulePathRaw.replace(/\/lib.*/, '');
177
+ // Avoid duplicates based on the computed base.
178
+ if (collectedModules.find((m) => m.name === baseModule))
179
+ return;
84
180
  const srcOrLib = isLocal ? 'src' : 'lib';
85
- const generatePath = (type) => `${baseModule}${isLocal ? `/${type}` : ''}/${srcOrLib}`;
86
- // For local modules, always return all module keys.
87
- if (isLocal) {
88
- return [
89
- ...acc,
90
- {
91
- client: generatePath('client'),
92
- core: generatePath('core'),
93
- browser: generatePath('browser'),
94
- server: generatePath('server'),
95
- },
96
- ];
181
+ // Start a module definition.
182
+ const moduleDef = { raw: rawStr, name: baseModule };
183
+ if (!isLocal) {
184
+ // External modules.
185
+ if (rawStr.includes('-browser')) {
186
+ // For external variants, look for client and core as well.
187
+ moduleDef.browser = `${baseModule}/${srcOrLib}`;
188
+ // Replace only the trailing "-browser" for client/core.
189
+ moduleDef.client = `${baseModule.replace(/-browser$/, '-client')}/${srcOrLib}`;
190
+ moduleDef.core = `${baseModule.replace(/-browser$/, '-core')}/${srcOrLib}`;
191
+ }
192
+ else if (rawStr.endsWith('-server')) {
193
+ moduleDef.server = `${baseModule}/${srcOrLib}`;
194
+ }
195
+ else {
196
+ moduleDef.server = `${baseModule}/${srcOrLib}`;
197
+ }
198
+ }
199
+ else {
200
+ // Local (internal) modules.
201
+ if (isVariant) {
202
+ if (rawStr.includes('-browser')) {
203
+ // For variant local modules with -browser, expect subfolders for browser, client, core and server.
204
+ moduleDef.browser = `${baseModule}/browser/${srcOrLib}`;
205
+ moduleDef.client = `${baseModule}/client/${srcOrLib}`;
206
+ moduleDef.core = `${baseModule}/core/${srcOrLib}`;
207
+ moduleDef.server = `${baseModule}/server/${srcOrLib}`;
208
+ }
209
+ else if (rawStr.endsWith('-server')) {
210
+ moduleDef.server = `${baseModule}/server/${srcOrLib}`;
211
+ }
212
+ moduleDef.isVariant = true;
213
+ }
214
+ else {
215
+ // Independent local package with a flat structure.
216
+ moduleDef.server = `${baseModule}/src`;
217
+ moduleDef.isIndependentLocal = true;
218
+ }
97
219
  }
98
- // Otherwise, handle node_module naming conventions.
99
- // If the baseModule ends with "-browser".
100
- if (baseModule.endsWith('-browser')) {
101
- return [
102
- ...acc,
103
- {
104
- browser: `${baseModule}/${srcOrLib}`,
105
- client: `${baseModule.replace(/-browser$/, '-client')}/${srcOrLib}`,
106
- core: `${baseModule.replace(/-browser$/, '-core')}/${srcOrLib}`,
107
- },
108
- ];
220
+ // Optionally, if package.json exists, adjust the server path using its "main" field.
221
+ let packageJsonPath;
222
+ if (isLocal) {
223
+ packageJsonPath = path.join(commonPaths.pathsConfig.repoRoot, baseModule, 'package.json');
109
224
  }
110
- if (baseModule.endsWith('-server')) {
111
- return [
112
- ...acc,
113
- {
114
- server: `${baseModule}/${srcOrLib}`,
115
- },
116
- ];
225
+ else {
226
+ packageJsonPath = path.join('node_modules', baseModule, 'package.json');
117
227
  }
118
- if (baseModule.includes('-browser')) {
119
- return [
120
- ...acc,
121
- {
122
- browser: `${baseModule}/${srcOrLib}`,
123
- },
124
- ];
228
+ if (fs.existsSync(packageJsonPath)) {
229
+ try {
230
+ const pkgContent = fs.readFileSync(packageJsonPath, 'utf-8');
231
+ const pkg = JSON.parse(pkgContent);
232
+ if (pkg.main) {
233
+ moduleDef.server = pkg.main.replace(/\.js$/, `/${srcOrLib}`);
234
+ }
235
+ }
236
+ catch (error) {
237
+ console.error(`Error reading package.json for ${baseModule}:`, error);
238
+ }
125
239
  }
126
- // Default fallback.
127
- return [
128
- ...acc,
129
- {
130
- independent: `${baseModule}/${srcOrLib}`,
131
- },
132
- ];
240
+ collectedModules.push(moduleDef);
133
241
  }
134
242
  catch (e) {
135
- console.error(e);
136
- console.log('Error while processing module:', moduleName);
137
- return acc;
243
+ console.error('Error while processing module:', rawStr, e);
138
244
  }
139
- }, []);
245
+ });
246
+ // Transform the intermediate definitions into the final output format.
247
+ const finalOutput = transformModules(collectedModules);
248
+ return finalOutput;
140
249
  }exports.readModules=readModules;//# sourceMappingURL=readModules.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"readModules.cjs","sources":["../../../src/tools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SACd;KACJ,EAAE,EAAW,CAAC,CAAC;AACpB"}
1
+ {"version":3,"file":"readModules.cjs","sources":["../../../src/tools/codegen/readModules.ts"],"sourcesContent":[null],"names":["createRequire","pathsConfig"],"mappings":"8MAMA;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;QACnC,KAAK,CAAC,GAAG,EAAE,CAAC;KACf;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC;AAED;;;;AAIG;AACH,SAAS,oBAAoB,CAAC,OAAe,EAAA;IACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AACzD,IAAA,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE;QACrE,QAAQ,CAAC,GAAG,EAAE,CAAC;KAClB;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AAED;;;AAGG;AACH,SAAS,gBAAgB,CAAC,GAAqB,EAAA;AAC3C,IAAA,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;;;;AAcG;AACH,SAAS,gBAAgB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,wBAAA,SAAS,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAE,CAAC,CAAC;qBAChE;iBACJ;gBAAC,OAAO,KAAK,EAAE;oBACZ,OAAO,CAAC,KAAK,CAAC,CAAA,+BAAA,EAAkC,UAAU,CAAG,CAAA,CAAA,EAAE,KAAK,CAAC,CAAC;iBACzE;aACJ;AAED,YAAA,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SACpC;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;SAC9D;AACL,KAAC,CAAC,CAAC;;AAGH,IAAA,MAAM,WAAW,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;AACvD,IAAA,OAAO,WAAW,CAAC;AACvB"}
@@ -1,11 +1,33 @@
1
1
  /**
2
- * Reads modules from JSON config files and returns an array of module objects.
2
+ * Internal module definition.
3
+ * Note: The extra properties "raw", "isVariant" and "isIndependentLocal" are used only during processing.
4
+ */
5
+ export interface ModuleDefinition {
6
+ raw?: string;
7
+ name: string;
8
+ server?: string;
9
+ browser?: string;
10
+ client?: string;
11
+ core?: string;
12
+ isVariant?: boolean;
13
+ isIndependentLocal?: boolean;
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.
3
18
  *
4
- * The function separates modules into client and server arrays based on the suffix (“-server”),
5
- * then it attempts to resolve each module’s location. If the resolution fails—often due to a missing
6
- * "lib" folder on external packages—it falls back by removing any `/lib` reference from the module name.
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.
7
29
  *
8
- * For local modules it always returns an object with { client, core, browser, server } keys.
9
- * For modules from node_modules, it generates paths based on naming conventions.
30
+ * @param {string[]} configPaths - Array of configuration file paths.
31
+ * @returns {any[]} Final processed module objects.
10
32
  */
11
- export declare function readModules(serverConfigPaths?: string[]): any[];
33
+ export declare function readModules(configPaths?: string[]): any[];