@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.
Files changed (107) hide show
  1. package/LICENSE +34 -21
  2. package/lib/config-schema.cjs +104 -103
  3. package/lib/config-schema.cjs.map +1 -1
  4. package/lib/config-schema.js +104 -103
  5. package/lib/config-schema.js.map +1 -1
  6. package/lib/index.cjs +1 -1
  7. package/lib/index.js +1 -1
  8. package/lib/preStartup/configLoader/configLoader.cjs +135 -2
  9. package/lib/preStartup/configLoader/configLoader.cjs.map +1 -1
  10. package/lib/preStartup/configLoader/configLoader.js +135 -2
  11. package/lib/preStartup/configLoader/configLoader.js.map +1 -1
  12. package/lib/preStartup/configLoader/index.cjs +1 -1
  13. package/lib/preStartup/configLoader/index.cjs.map +1 -1
  14. package/lib/preStartup/configLoader/index.js +1 -1
  15. package/lib/preStartup/configLoader/index.js.map +1 -1
  16. package/lib/rollup/modifyLibFiles/extractGraphQLQueries.cjs +6 -2
  17. package/lib/rollup/modifyLibFiles/extractGraphQLQueries.cjs.map +1 -1
  18. package/lib/rollup/modifyLibFiles/extractGraphQLQueries.js +6 -2
  19. package/lib/rollup/modifyLibFiles/extractGraphQLQueries.js.map +1 -1
  20. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.cjs +2 -3
  21. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.cjs.map +1 -1
  22. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.js +2 -3
  23. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.js.map +1 -1
  24. package/lib/rollup/modifyLibFiles/handleLoaderReturn.cjs +2 -4
  25. package/lib/rollup/modifyLibFiles/handleLoaderReturn.cjs.map +1 -1
  26. package/lib/rollup/modifyLibFiles/handleLoaderReturn.js +2 -4
  27. package/lib/rollup/modifyLibFiles/handleLoaderReturn.js.map +1 -1
  28. package/lib/rollup/rollupPluginAddJsExtension.cjs +1 -1
  29. package/lib/rollup/rollupPluginAddJsExtension.cjs.map +1 -1
  30. package/lib/rollup/rollupPluginAddJsExtension.js +1 -1
  31. package/lib/rollup/rollupPluginAddJsExtension.js.map +1 -1
  32. package/lib/rollup/rollupPluginGenerateJson.cjs +27 -0
  33. package/lib/rollup/rollupPluginGenerateJson.cjs.map +1 -1
  34. package/lib/rollup/rollupPluginGenerateJson.d.ts +10 -0
  35. package/lib/rollup/rollupPluginGenerateJson.js +27 -0
  36. package/lib/rollup/rollupPluginGenerateJson.js.map +1 -1
  37. package/lib/rollup/rollupPluginGenerateJson.test.d.ts +1 -0
  38. package/lib/rollup/rollupPluginUpdateFromConfig.cjs +1 -1
  39. package/lib/rollup/rollupPluginUpdateFromConfig.js +1 -1
  40. package/lib/tools/codegen/generateCodegenConfig.cjs +30 -0
  41. package/lib/tools/codegen/generateCodegenConfig.cjs.map +1 -1
  42. package/lib/tools/codegen/generateCodegenConfig.js +30 -0
  43. package/lib/tools/codegen/generateCodegenConfig.js.map +1 -1
  44. package/lib/tools/codegen/index.cjs.map +1 -1
  45. package/lib/tools/codegen/index.js.map +1 -1
  46. package/lib/tools/codegen/performCopyOperations.cjs +94 -17
  47. package/lib/tools/codegen/performCopyOperations.cjs.map +1 -1
  48. package/lib/tools/codegen/performCopyOperations.js +94 -17
  49. package/lib/tools/codegen/performCopyOperations.js.map +1 -1
  50. package/lib/tools/codegen/readModules.cjs +80 -59
  51. package/lib/tools/codegen/readModules.cjs.map +1 -1
  52. package/lib/tools/codegen/readModules.d.ts +0 -18
  53. package/lib/tools/codegen/readModules.js +80 -59
  54. package/lib/tools/codegen/readModules.js.map +1 -1
  55. package/lib/tools/codegen/setupCommonPackage.cjs +14 -5
  56. package/lib/tools/codegen/setupCommonPackage.cjs.map +1 -1
  57. package/lib/tools/codegen/setupCommonPackage.d.ts +1 -1
  58. package/lib/tools/codegen/setupCommonPackage.js +14 -5
  59. package/lib/tools/codegen/setupCommonPackage.js.map +1 -1
  60. package/lib/tools/codegen/templates/common/package.json.template +2 -0
  61. package/lib/tools/codegen/templates/common/scripts/fix-generated-types.js.template +58 -0
  62. package/lib/tools/codegen/templates/common/src/apollo-context.ts.bk.template +34 -0
  63. package/lib/tools/codegen/templates/common/src/apollo-context.ts.template +13 -20
  64. package/lib/tools/codegen/templates/common/src/client-context.ts.template +19 -0
  65. package/lib/tools/codegen/templates/common/src/core/disposable.ts.template +93 -0
  66. package/lib/tools/codegen/templates/common/src/core/event.test.ts +16 -0
  67. package/lib/tools/codegen/templates/common/src/core/event.ts.template +326 -0
  68. package/lib/tools/codegen/templates/common/src/core/index.ts.template +3 -0
  69. package/lib/tools/codegen/templates/common/src/core/types.ts.template +1 -0
  70. package/lib/tools/codegen/templates/common/src/generated/service-schemas.ts.template +1 -0
  71. package/lib/tools/codegen/templates/common/src/index.server.ts.template +3 -1
  72. package/lib/tools/codegen/templates/common/src/index.ts.template +1 -0
  73. package/lib/utils/index.d.ts +1 -0
  74. package/lib/utils/packageUtils.cjs +142 -2
  75. package/lib/utils/packageUtils.cjs.map +1 -1
  76. package/lib/utils/packageUtils.d.ts +65 -0
  77. package/lib/utils/packageUtils.js +142 -2
  78. package/lib/utils/packageUtils.js.map +1 -1
  79. package/lib/utils/utils.cjs +1 -1
  80. package/lib/utils/utils.js +1 -1
  81. package/lib/vite-wrappers/generators/clientLoaderGenerator.cjs +11 -3
  82. package/lib/vite-wrappers/generators/clientLoaderGenerator.cjs.map +1 -1
  83. package/lib/vite-wrappers/generators/clientLoaderGenerator.js +11 -3
  84. package/lib/vite-wrappers/generators/clientLoaderGenerator.js.map +1 -1
  85. package/lib/vite-wrappers/generators/loaderGenerator.cjs +7 -16
  86. package/lib/vite-wrappers/generators/loaderGenerator.cjs.map +1 -1
  87. package/lib/vite-wrappers/generators/loaderGenerator.d.ts +1 -0
  88. package/lib/vite-wrappers/generators/loaderGenerator.js +7 -16
  89. package/lib/vite-wrappers/generators/loaderGenerator.js.map +1 -1
  90. package/lib/vite-wrappers/generators/utils/resourceParams.cjs +48 -11
  91. package/lib/vite-wrappers/generators/utils/resourceParams.cjs.map +1 -1
  92. package/lib/vite-wrappers/generators/utils/resourceParams.d.ts +10 -4
  93. package/lib/vite-wrappers/generators/utils/resourceParams.js +48 -11
  94. package/lib/vite-wrappers/generators/utils/resourceParams.js.map +1 -1
  95. package/lib/vite-wrappers/icon-switch.cjs +4 -4
  96. package/lib/vite-wrappers/icon-switch.cjs.map +1 -1
  97. package/lib/vite-wrappers/icon-switch.js +4 -4
  98. package/lib/vite-wrappers/icon-switch.js.map +1 -1
  99. package/lib/vite-wrappers/json-wrappers.cjs +30 -2
  100. package/lib/vite-wrappers/json-wrappers.cjs.map +1 -1
  101. package/lib/vite-wrappers/json-wrappers.js +30 -2
  102. package/lib/vite-wrappers/json-wrappers.js.map +1 -1
  103. package/lib/vite-wrappers/wrapperComponent.cjs +6 -13
  104. package/lib/vite-wrappers/wrapperComponent.cjs.map +1 -1
  105. package/lib/vite-wrappers/wrapperComponent.js +6 -13
  106. package/lib/vite-wrappers/wrapperComponent.js.map +1 -1
  107. package/package.json +5 -5
@@ -0,0 +1,326 @@
1
+ /* tslint:disable */
2
+
3
+ import { Disposable } from './disposable';
4
+ import { MaybePromise } from './types';
5
+
6
+ /**
7
+ * Represents a typed event.
8
+ */
9
+ export interface Event<T> {
10
+
11
+ /**
12
+ *
13
+ * @param listener The listener function will be call when the event happens.
14
+ * @param thisArgs The 'this' which will be used when calling the event listener.
15
+ * @param disposables An array to which a {{IDisposable}} will be added.
16
+ * @return a disposable to remove the listener again.
17
+ */
18
+ (listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable;
19
+ /**
20
+ * An emitter will print a warning if more listeners are added for this event.
21
+ * The event.maxListeners allows the limit to be modified for this specific event.
22
+ * The value can be set to 0 to indicate an unlimited number of listener.
23
+ */
24
+ maxListeners: number
25
+ }
26
+
27
+ export namespace Event {
28
+ const _disposable = { dispose(): void { } };
29
+ export const None: Event<any> = Object.assign(function (): { dispose(): void } { return _disposable; }, {
30
+ get maxListeners(): number { return 0; },
31
+ set maxListeners(maxListeners: number) { }
32
+ });
33
+
34
+ /**
35
+ * Given an event and a `map` function, returns another event which maps each element
36
+ * through the mapping function.
37
+ */
38
+ export function map<I, O>(event: Event<I>, mapFunc: (i: I) => O): Event<O> {
39
+ return Object.assign((listener: (e: O) => any, thisArgs?: any, disposables?: Disposable[]) => event(i => listener.call(thisArgs, mapFunc(i)), undefined, disposables), {
40
+ maxListeners: 0,
41
+ });
42
+ }
43
+ }
44
+
45
+ type Callback = (...args: any[]) => any;
46
+ class CallbackList implements Iterable<Callback> {
47
+
48
+ private _callbacks: Function[] | undefined;
49
+ private _contexts: any[] | undefined;
50
+
51
+ get length(): number {
52
+ return this._callbacks && this._callbacks.length || 0;
53
+ }
54
+
55
+ public add(callback: Function, context: any = undefined, bucket?: Disposable[]): void {
56
+ if (!this._callbacks) {
57
+ this._callbacks = [];
58
+ this._contexts = [];
59
+ }
60
+ this._callbacks.push(callback);
61
+ this._contexts!.push(context);
62
+
63
+ if (Array.isArray(bucket)) {
64
+ bucket.push({ dispose: () => this.remove(callback, context) });
65
+ }
66
+ }
67
+
68
+ public remove(callback: Function, context: any = undefined): void {
69
+ if (!this._callbacks) {
70
+ return;
71
+ }
72
+
73
+ let foundCallbackWithDifferentContext = false;
74
+ for (let i = 0; i < this._callbacks.length; i++) {
75
+ if (this._callbacks[i] === callback) {
76
+ if (this._contexts![i] === context) {
77
+ // callback & context match => remove it
78
+ this._callbacks.splice(i, 1);
79
+ this._contexts!.splice(i, 1);
80
+ return;
81
+ } else {
82
+ foundCallbackWithDifferentContext = true;
83
+ }
84
+ }
85
+ }
86
+
87
+ if (foundCallbackWithDifferentContext) {
88
+ throw new Error('When adding a listener with a context, you should remove it with the same context');
89
+ }
90
+ }
91
+
92
+ // tslint:disable-next-line:typedef
93
+ public [Symbol.iterator]() {
94
+ if (!this._callbacks) {
95
+ return [][Symbol.iterator]();
96
+ }
97
+ const callbacks = this._callbacks.slice(0);
98
+ const contexts = this._contexts!.slice(0);
99
+
100
+ return callbacks.map((callback, i) =>
101
+ (...args: any[]) => callback.apply(contexts[i], args)
102
+ )[Symbol.iterator]();
103
+ }
104
+
105
+ public invoke(...args: any[]): any[] {
106
+ const ret: any[] = [];
107
+ for (const callback of this) {
108
+ try {
109
+ ret.push(callback(...args));
110
+ } catch (e) {
111
+ console.error(e);
112
+ }
113
+ }
114
+ return ret;
115
+ }
116
+
117
+ public isEmpty(): boolean {
118
+ return !this._callbacks || this._callbacks.length === 0;
119
+ }
120
+
121
+ public dispose(): void {
122
+ this._callbacks = undefined;
123
+ this._contexts = undefined;
124
+ }
125
+ }
126
+
127
+ export interface EmitterOptions {
128
+ onFirstListenerAdd?: Function;
129
+ onLastListenerRemove?: Function;
130
+ }
131
+
132
+ export class Emitter<T = any> {
133
+
134
+ private static LEAK_WARNING_THRESHHOLD = 175;
135
+
136
+ private static _noop = function (): void { };
137
+
138
+ private _event: Event<T>;
139
+ private _callbacks: CallbackList | undefined;
140
+ private _disposed = false;
141
+
142
+ private _leakingStacks: Map<string, number> | undefined;
143
+ private _leakWarnCountdown = 0;
144
+
145
+ constructor(
146
+ private _options?: EmitterOptions
147
+ ) { }
148
+
149
+ /**
150
+ * For the public to allow to subscribe
151
+ * to events from this Emitter
152
+ */
153
+ get event(): Event<T> {
154
+ if (!this._event) {
155
+ this._event = Object.assign((listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]) => {
156
+ if (!this._callbacks) {
157
+ this._callbacks = new CallbackList();
158
+ }
159
+ if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
160
+ this._options.onFirstListenerAdd(this);
161
+ }
162
+ this._callbacks.add(listener, thisArgs);
163
+ const removeMaxListenersCheck = this.checkMaxListeners(this._event.maxListeners);
164
+
165
+ const result: Disposable = {
166
+ dispose: () => {
167
+ if (removeMaxListenersCheck) {
168
+ removeMaxListenersCheck();
169
+ }
170
+ result.dispose = Emitter._noop;
171
+ if (!this._disposed) {
172
+ this._callbacks!.remove(listener, thisArgs);
173
+ result.dispose = Emitter._noop;
174
+ if (this._options && this._options.onLastListenerRemove && this._callbacks!.isEmpty()) {
175
+ this._options.onLastListenerRemove(this);
176
+ }
177
+ }
178
+ }
179
+ };
180
+ if (Array.isArray(disposables)) {
181
+ disposables.push(result);
182
+ }
183
+
184
+ return result;
185
+ }, {
186
+ maxListeners: Emitter.LEAK_WARNING_THRESHHOLD
187
+ }
188
+ );
189
+ }
190
+ return this._event;
191
+ }
192
+
193
+ protected checkMaxListeners(maxListeners: number): (() => void) | undefined {
194
+ if (maxListeners === 0 || !this._callbacks) {
195
+ return undefined;
196
+ }
197
+ const listenerCount = this._callbacks.length;
198
+ if (listenerCount <= maxListeners) {
199
+ return undefined;
200
+ }
201
+
202
+ const popStack = this.pushLeakingStack();
203
+
204
+ this._leakWarnCountdown -= 1;
205
+ if (this._leakWarnCountdown <= 0) {
206
+ // only warn on first exceed and then every time the limit
207
+ // is exceeded by 50% again
208
+ this._leakWarnCountdown = maxListeners * 0.5;
209
+
210
+ let topStack: string;
211
+ let topCount = 0;
212
+ this._leakingStacks!.forEach((stackCount, stack) => {
213
+ if (!topStack || topCount < stackCount) {
214
+ topStack = stack;
215
+ topCount = stackCount;
216
+ }
217
+ });
218
+
219
+ // eslint-disable-next-line max-len
220
+ console.warn(`Possible Emitter memory leak detected. ${listenerCount} listeners added. Use event.maxListeners to increase the limit (${maxListeners}). MOST frequent listener (${topCount}):`);
221
+ console.warn(topStack!);
222
+ }
223
+
224
+ return popStack;
225
+ }
226
+
227
+ protected pushLeakingStack(): () => void {
228
+ if (!this._leakingStacks) {
229
+ this._leakingStacks = new Map();
230
+ }
231
+ const stack = new Error().stack!.split('\n').slice(3).join('\n');
232
+ const count = (this._leakingStacks.get(stack) || 0);
233
+ this._leakingStacks.set(stack, count + 1);
234
+ return () => this.popLeakingStack(stack);
235
+ }
236
+
237
+ protected popLeakingStack(stack: string): void {
238
+ if (!this._leakingStacks) {
239
+ return;
240
+ }
241
+ const count = (this._leakingStacks.get(stack) || 0);
242
+ this._leakingStacks.set(stack, count - 1);
243
+ }
244
+
245
+ /**
246
+ * To be kept private to fire an event to
247
+ * subscribers
248
+ */
249
+ fire(event: T): any {
250
+ if (this._callbacks) {
251
+ this._callbacks.invoke(event);
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Process each listener one by one.
257
+ * Return `false` to stop iterating over the listeners, `true` to continue.
258
+ */
259
+ async sequence(processor: (listener: (e: T) => any) => MaybePromise<boolean>): Promise<void> {
260
+ if (this._callbacks) {
261
+ for (const listener of this._callbacks) {
262
+ if (!await processor(listener)) {
263
+ break;
264
+ }
265
+ }
266
+ }
267
+ }
268
+
269
+ dispose(): void {
270
+ if (this._leakingStacks) {
271
+ this._leakingStacks.clear();
272
+ this._leakingStacks = undefined;
273
+ }
274
+ if (this._callbacks) {
275
+ this._callbacks.dispose();
276
+ this._callbacks = undefined;
277
+ }
278
+ this._disposed = true;
279
+ }
280
+ }
281
+
282
+ export interface WaitUntilEvent {
283
+ /* eslint-disable @typescript-eslint/no-explicit-any */
284
+ /**
285
+ * Allows to pause the event loop until the provided thenable resolved.
286
+ *
287
+ * *Note:* It can only be called during event dispatch and not in an asynchronous manner
288
+ *
289
+ * @param thenable A thenable that delays execution.
290
+ */
291
+ waitUntil(thenable: Promise<any>): void;
292
+ /* eslint-enable @typescript-eslint/no-explicit-any */
293
+ }
294
+ export namespace WaitUntilEvent {
295
+ export async function fire<T extends WaitUntilEvent>(
296
+ emitter: Emitter<T>,
297
+ event: Pick<T, Exclude<keyof T, 'waitUntil'>>,
298
+ timeout: number | undefined = undefined
299
+ ): Promise<void> {
300
+ const waitables: Promise<void>[] = [];
301
+ const asyncEvent = Object.assign(event, {
302
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
303
+ waitUntil: (thenable: Promise<any>) => {
304
+ if (Object.isFrozen(waitables)) {
305
+ throw new Error('waitUntil cannot be called asynchronously.');
306
+ }
307
+ waitables.push(thenable);
308
+ }
309
+ }) as T;
310
+ try {
311
+ emitter.fire(asyncEvent);
312
+ // Asynchronous calls to `waitUntil` should fail.
313
+ Object.freeze(waitables);
314
+ } finally {
315
+ delete asyncEvent['waitUntil'];
316
+ }
317
+ if (!waitables.length) {
318
+ return;
319
+ }
320
+ if (timeout !== undefined) {
321
+ await Promise.race([Promise.all(waitables), new Promise(resolve => setTimeout(resolve, timeout))]);
322
+ } else {
323
+ await Promise.all(waitables);
324
+ }
325
+ }
326
+ }
@@ -0,0 +1,3 @@
1
+ export * from './disposable';
2
+ export * from './event';
3
+ export * from './types';
@@ -0,0 +1 @@
1
+ export type MaybePromise<T> = T | PromiseLike<T>;
@@ -0,0 +1 @@
1
+ export const DUMMY2 = 'dummy';
@@ -1,5 +1,7 @@
1
1
  export * from './generated/generated-models';
2
+ export * from './generated/service-schemas';
2
3
  export * from './configuration';
3
4
  export * from './permissions';
4
5
  export * from './apollo-context';
5
- export * from './types';
6
+ export * from './types';
7
+ export * from './core';
@@ -3,3 +3,4 @@ export * from './configuration';
3
3
  export * from './permissions';
4
4
  export * from './apollo-context';
5
5
  export * from './types';
6
+ export * from './core';
@@ -1,4 +1,5 @@
1
1
  export * from './utils';
2
+ export * from './packageUtils';
2
3
  export * from './withErrorHandleUtil';
3
4
  export * from './setupConfig';
4
5
  export * from './verifyConfig';
@@ -1,4 +1,4 @@
1
- 'use strict';/**
1
+ 'use strict';var fs=require('fs'),path=require('path');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var fs__namespace=/*#__PURE__*/_interopNamespaceDefault(fs);var path__namespace=/*#__PURE__*/_interopNamespaceDefault(path);/**
2
2
  * Extracts the base package name from a full package path
3
3
  * Examples:
4
4
  * - "@org/package/path/file.js" -> "@org/package"
@@ -15,4 +15,144 @@ const getPackageName = (importPath) => {
15
15
  const match = importPath.match(/^([^/]+)/);
16
16
  return match ? match[1] : null;
17
17
  }
18
- };exports.getPackageName=getPackageName;//# sourceMappingURL=packageUtils.cjs.map
18
+ };
19
+ /**
20
+ * Resolves a module to its package.json using Node.js resolution algorithm
21
+ * with fallbacks for exports restrictions and symlinked packages.
22
+ *
23
+ * @param moduleSpec - The module specifier (e.g., 'lodash', '@babel/core', 'package/subpath')
24
+ * @param esmRequire - The Node.js require function for module resolution
25
+ * @param options - Optional configuration for resolution behavior
26
+ * @returns Path to package.json or null if not found
27
+ */
28
+ function resolvePackageJson(moduleSpec, esmRequire, options = {}) {
29
+ const { internalPackagePrefix = 'packages-modules/', cwd = process.cwd(), repoRoot } = options;
30
+ // For internal/local packages, construct path directly
31
+ if (moduleSpec.startsWith(internalPackagePrefix)) {
32
+ const localPath = path__namespace.join(cwd, moduleSpec, 'package.json');
33
+ if (fs__namespace.existsSync(localPath)) {
34
+ return localPath;
35
+ }
36
+ // If not found at cwd and repoRoot is provided, try from repo root
37
+ if (repoRoot) {
38
+ const repoRootPath = path__namespace.join(repoRoot, moduleSpec, 'package.json');
39
+ if (fs__namespace.existsSync(repoRootPath)) {
40
+ return repoRootPath;
41
+ }
42
+ }
43
+ }
44
+ // Extract the base package name (handles scoped packages)
45
+ const packageName = getPackageName(moduleSpec);
46
+ if (!packageName) {
47
+ return null;
48
+ }
49
+ // Strategy 1: Direct filesystem resolution to bypass exports restrictions
50
+ const directPath = path__namespace.join(cwd, 'node_modules', packageName, 'package.json');
51
+ if (fs__namespace.existsSync(directPath)) {
52
+ return directPath;
53
+ }
54
+ // Strategy 2: Standard require.resolve with package.json
55
+ try {
56
+ return esmRequire.resolve(path__namespace.join(moduleSpec, 'package.json'));
57
+ }
58
+ catch (err) {
59
+ // Strategy 3: Parse error path to find package root
60
+ const errorPath = extractPathFromError(err);
61
+ if (errorPath) {
62
+ const packageJsonPath = findPackageJsonFromPath(errorPath);
63
+ if (packageJsonPath && fs__namespace.existsSync(packageJsonPath)) {
64
+ return packageJsonPath;
65
+ }
66
+ }
67
+ // Strategy 4: Try resolving base package without subpaths
68
+ const baseModule = removeSubpaths(moduleSpec);
69
+ if (baseModule !== moduleSpec) {
70
+ try {
71
+ return esmRequire.resolve(path__namespace.join(baseModule, 'package.json'));
72
+ }
73
+ catch {
74
+ // Final fallback failed
75
+ }
76
+ }
77
+ }
78
+ return null;
79
+ }
80
+ /**
81
+ * Extracts file path from Node.js resolution error.
82
+ *
83
+ * @param err - Error object from require.resolve
84
+ * @returns File path from error or null if not found
85
+ */
86
+ function extractPathFromError(err) {
87
+ if (err && typeof err === 'object' && 'path' in err && typeof err.path === 'string') {
88
+ return err.path;
89
+ }
90
+ return null;
91
+ }
92
+ /**
93
+ * Finds package.json by traversing up from a given path.
94
+ *
95
+ * @param filePath - Starting file path
96
+ * @returns Path to package.json or null if not found
97
+ */
98
+ function findPackageJsonFromPath(filePath) {
99
+ // Remove /lib/ segments and everything after them
100
+ const libSegment = `${path__namespace.sep}lib${path__namespace.sep}`;
101
+ const libIndex = filePath.indexOf(libSegment);
102
+ if (libIndex !== -1) {
103
+ const packageRoot = filePath.slice(0, libIndex);
104
+ return path__namespace.join(packageRoot, 'package.json');
105
+ }
106
+ // Try the directory containing the file
107
+ const dir = path__namespace.dirname(filePath);
108
+ const packageJsonPath = path__namespace.join(dir, 'package.json');
109
+ if (fs__namespace.existsSync(packageJsonPath)) {
110
+ return packageJsonPath;
111
+ }
112
+ return null;
113
+ }
114
+ /**
115
+ * Removes subpaths from module specifier (e.g., "module/lib/index" -> "module").
116
+ *
117
+ * @param moduleSpec - Module specifier with potential subpaths
118
+ * @returns Base module specifier without subpaths
119
+ */
120
+ function removeSubpaths(moduleSpec) {
121
+ if (moduleSpec.includes('/lib')) {
122
+ return moduleSpec.replace(/\/lib.*$/, '');
123
+ }
124
+ return moduleSpec;
125
+ }
126
+ /**
127
+ * Resolves multiple modules in batch and returns successful resolutions.
128
+ *
129
+ * @param moduleSpecs - Array of module specifiers to resolve
130
+ * @param esmRequire - The Node.js require function for module resolution
131
+ * @param options - Optional configuration for resolution behavior
132
+ * @returns Array of objects with moduleSpec and resolved path
133
+ */
134
+ function resolveMultiplePackages(moduleSpecs, esmRequire, options) {
135
+ return moduleSpecs.map((moduleSpec) => ({
136
+ moduleSpec,
137
+ resolvedPath: resolvePackageJson(moduleSpec, esmRequire, options),
138
+ }));
139
+ }
140
+ /**
141
+ * Checks if a module specifier represents an internal/local package.
142
+ *
143
+ * @param moduleSpec - Module specifier to check
144
+ * @param internalPrefix - Prefix for internal packages (defaults to 'packages-modules/')
145
+ * @returns True if the module is internal/local
146
+ */
147
+ function isInternalPackage(moduleSpec, internalPrefix = 'packages-modules/') {
148
+ return moduleSpec.startsWith(internalPrefix);
149
+ }
150
+ /**
151
+ * Checks if a module specifier represents a scoped package.
152
+ *
153
+ * @param moduleSpec - Module specifier to check
154
+ * @returns True if the module is scoped (starts with @)
155
+ */
156
+ function isScopedPackage(moduleSpec) {
157
+ return moduleSpec.startsWith('@');
158
+ }exports.extractPathFromError=extractPathFromError;exports.findPackageJsonFromPath=findPackageJsonFromPath;exports.getPackageName=getPackageName;exports.isInternalPackage=isInternalPackage;exports.isScopedPackage=isScopedPackage;exports.removeSubpaths=removeSubpaths;exports.resolveMultiplePackages=resolveMultiplePackages;exports.resolvePackageJson=resolvePackageJson;//# sourceMappingURL=packageUtils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageUtils.cjs","sources":["../../src/utils/packageUtils.ts"],"sourcesContent":[null],"names":[],"mappings":"aAAA;;;;;;;AAOG;AACU,MAAA,cAAc,GAAG,CAAC,UAAkB,KAAmB;AAChE,IAAA,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;AACnD,QAAA,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,G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CAAC;AAED;;;;;;;AAOG;SACa,uBAAuB,CACnC,WAAqB,EACrB,UAAuB,EACvB,OAAkD,EAAA;IAElD,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,MAAM;QACpC,UAAU;QACV,YAAY,EAAE,kBAAkB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC;AACpE,KAAA,CAAC,CAAC,CAAC;AACR,CAAC;AAED;;;;;;AAMG;SACa,iBAAiB,CAAC,UAAkB,EAAE,iBAAyB,mBAAmB,EAAA;AAC9F,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AACjD,CAAC;AAED;;;;;AAKG;AACG,SAAU,eAAe,CAAC,UAAkB,EAAA;AAC9C,IAAA,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACtC"}
@@ -7,3 +7,68 @@
7
7
  * - "package" -> "package"
8
8
  */
9
9
  export declare const getPackageName: (importPath: string) => string | null;
10
+ /**
11
+ * Resolves a module to its package.json using Node.js resolution algorithm
12
+ * with fallbacks for exports restrictions and symlinked packages.
13
+ *
14
+ * @param moduleSpec - The module specifier (e.g., 'lodash', '@babel/core', 'package/subpath')
15
+ * @param esmRequire - The Node.js require function for module resolution
16
+ * @param options - Optional configuration for resolution behavior
17
+ * @returns Path to package.json or null if not found
18
+ */
19
+ export declare function resolvePackageJson(moduleSpec: string, esmRequire: NodeRequire, options?: {
20
+ /** Custom base path for internal packages (defaults to 'packages-modules/') */
21
+ internalPackagePrefix?: string;
22
+ /** Custom working directory (defaults to process.cwd()) */
23
+ cwd?: string;
24
+ /** Custom repo root for internal packages */
25
+ repoRoot?: string;
26
+ }): string | null;
27
+ /**
28
+ * Extracts file path from Node.js resolution error.
29
+ *
30
+ * @param err - Error object from require.resolve
31
+ * @returns File path from error or null if not found
32
+ */
33
+ export declare function extractPathFromError(err: unknown): string | null;
34
+ /**
35
+ * Finds package.json by traversing up from a given path.
36
+ *
37
+ * @param filePath - Starting file path
38
+ * @returns Path to package.json or null if not found
39
+ */
40
+ export declare function findPackageJsonFromPath(filePath: string): string | null;
41
+ /**
42
+ * Removes subpaths from module specifier (e.g., "module/lib/index" -> "module").
43
+ *
44
+ * @param moduleSpec - Module specifier with potential subpaths
45
+ * @returns Base module specifier without subpaths
46
+ */
47
+ export declare function removeSubpaths(moduleSpec: string): string;
48
+ /**
49
+ * Resolves multiple modules in batch and returns successful resolutions.
50
+ *
51
+ * @param moduleSpecs - Array of module specifiers to resolve
52
+ * @param esmRequire - The Node.js require function for module resolution
53
+ * @param options - Optional configuration for resolution behavior
54
+ * @returns Array of objects with moduleSpec and resolved path
55
+ */
56
+ export declare function resolveMultiplePackages(moduleSpecs: string[], esmRequire: NodeRequire, options?: Parameters<typeof resolvePackageJson>[2]): Array<{
57
+ moduleSpec: string;
58
+ resolvedPath: string | null;
59
+ }>;
60
+ /**
61
+ * Checks if a module specifier represents an internal/local package.
62
+ *
63
+ * @param moduleSpec - Module specifier to check
64
+ * @param internalPrefix - Prefix for internal packages (defaults to 'packages-modules/')
65
+ * @returns True if the module is internal/local
66
+ */
67
+ export declare function isInternalPackage(moduleSpec: string, internalPrefix?: string): boolean;
68
+ /**
69
+ * Checks if a module specifier represents a scoped package.
70
+ *
71
+ * @param moduleSpec - Module specifier to check
72
+ * @returns True if the module is scoped (starts with @)
73
+ */
74
+ export declare function isScopedPackage(moduleSpec: string): boolean;