@esmx/import 3.0.0-rc.31 → 3.0.0-rc.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/error.d.ts CHANGED
@@ -8,9 +8,7 @@ export declare class ModuleLoadingError extends Error {
8
8
  }
9
9
  export declare class CircularDependencyError extends ModuleLoadingError {
10
10
  constructor(message: string, moduleIds: string[], targetModule: string);
11
- toString(): string;
12
11
  }
13
12
  export declare class FileReadError extends ModuleLoadingError {
14
13
  constructor(message: string, moduleIds: string[], targetModule: string, originalError?: Error);
15
- toString(): string;
16
14
  }
package/dist/error.mjs CHANGED
@@ -19,14 +19,14 @@ const getRelativeFromCwd = (filePath) => {
19
19
  };
20
20
  export const formatCircularDependency = (moduleIds, targetModule) => {
21
21
  const fullChain = [...moduleIds, targetModule];
22
- return `${colorize(colorize("Circular dependency:", Colors.BOLD), Colors.RED)}
22
+ return `${colorize(colorize("Module dependency chain (circular reference found):", Colors.BOLD), Colors.RED)}
23
23
  ${fullChain.map((module, index) => {
24
24
  const isLastModule = index === fullChain.length - 1;
25
25
  const prefix = index === 0 ? "\u250C\u2500 " : index === fullChain.length - 1 ? "\u2514\u2500 " : "\u251C\u2500 ";
26
26
  const displayPath = getRelativeFromCwd(module);
27
27
  const isCircularModule = fullChain.filter((m) => m === module).length > 1;
28
28
  const coloredFile = isCircularModule ? colorize(colorize(displayPath, Colors.BOLD), Colors.RED) : colorize(displayPath, Colors.CYAN);
29
- const suffix = isLastModule ? ` ${colorize("\u2190 circular", Colors.YELLOW)}` : "";
29
+ const suffix = isLastModule ? ` ${colorize("\u{1F504} Creates circular reference", Colors.YELLOW)}` : "";
30
30
  return `${colorize(prefix, Colors.GRAY)}${coloredFile}${suffix}`;
31
31
  }).join("\n")}`;
32
32
  };
@@ -37,21 +37,21 @@ export const formatModuleChain = (moduleIds, targetModule, originalError) => {
37
37
  result = `${colorize("Failed to load:", Colors.CYAN)} ${colorize(displayPath, Colors.RED)}`;
38
38
  } else {
39
39
  const chain = [...moduleIds, targetModule];
40
- result = `${colorize(colorize("Import chain:", Colors.BOLD), Colors.CYAN)}
40
+ result = `${colorize(colorize("Module loading path:", Colors.BOLD), Colors.CYAN)}
41
41
  ${chain.map((module, index) => {
42
42
  const indent = " ".repeat(index);
43
43
  const connector = index === 0 ? "" : "\u2514\u2500 ";
44
44
  const displayPath = getRelativeFromCwd(module);
45
45
  const isFailedFile = index === chain.length - 1;
46
46
  const coloredFile = isFailedFile ? colorize(colorize(displayPath, Colors.BOLD), Colors.RED) : colorize(displayPath, Colors.CYAN);
47
- const status = isFailedFile ? ` ${colorize(colorize("\u2717 FAILED", Colors.BOLD), Colors.RED)}` : "";
47
+ const status = isFailedFile ? ` ${colorize(colorize("\u274C Loading failed", Colors.BOLD), Colors.RED)}` : "";
48
48
  return `${colorize(indent + connector, Colors.GRAY)}${coloredFile}${status}`;
49
49
  }).join("\n")}`;
50
50
  }
51
51
  if (originalError) {
52
52
  result += `
53
53
 
54
- ${colorize("Cause:", Colors.YELLOW)} ${originalError.message}`;
54
+ ${colorize("Error details:", Colors.YELLOW)} ${originalError.message}`;
55
55
  }
56
56
  return result;
57
57
  };
@@ -62,27 +62,43 @@ export class ModuleLoadingError extends Error {
62
62
  this.targetModule = targetModule;
63
63
  this.originalError = originalError;
64
64
  this.name = "ModuleLoadingError";
65
+ Object.defineProperty(this, "moduleIds", {
66
+ value: moduleIds,
67
+ writable: false,
68
+ enumerable: false,
69
+ configurable: true
70
+ });
71
+ Object.defineProperty(this, "targetModule", {
72
+ value: targetModule,
73
+ writable: false,
74
+ enumerable: false,
75
+ configurable: true
76
+ });
77
+ if (originalError) {
78
+ Object.defineProperty(this, "originalError", {
79
+ value: originalError,
80
+ writable: false,
81
+ enumerable: false,
82
+ configurable: true
83
+ });
84
+ }
65
85
  }
66
86
  }
67
87
  export class CircularDependencyError extends ModuleLoadingError {
68
88
  constructor(message, moduleIds, targetModule) {
69
89
  super(message, moduleIds, targetModule);
70
90
  this.name = "CircularDependencyError";
71
- }
72
- toString() {
73
- return `${this.name}: ${this.message}
91
+ this.stack = `${this.name}: ${message}
74
92
 
75
- ${formatCircularDependency(this.moduleIds, this.targetModule)}`;
93
+ ${formatCircularDependency(moduleIds, targetModule)}`;
76
94
  }
77
95
  }
78
96
  export class FileReadError extends ModuleLoadingError {
79
97
  constructor(message, moduleIds, targetModule, originalError) {
80
98
  super(message, moduleIds, targetModule, originalError);
81
99
  this.name = "FileReadError";
82
- }
83
- toString() {
84
- return `${this.name}: ${this.message}
100
+ this.stack = `${this.name}: ${message}
85
101
 
86
- ${formatModuleChain(this.moduleIds, this.targetModule, this.originalError)}`;
102
+ ${formatModuleChain(moduleIds, targetModule, originalError)}`;
87
103
  }
88
104
  }
@@ -31,6 +31,13 @@ describe("Module Loading Errors", () => {
31
31
  );
32
32
  expect(error.name).toBe("CircularDependencyError");
33
33
  expect(error.message).toBe("Test circular dependency");
34
+ expect(error.stack).toContain("Test circular dependency");
35
+ expect(error.stack).toContain(
36
+ "Module dependency chain (circular reference found):"
37
+ );
38
+ expect(error.stack).toContain("\u250C\u2500");
39
+ expect(error.stack).toContain("\u2514\u2500");
40
+ expect(error.stack).toContain("\u{1F504} Creates circular reference");
34
41
  expect(error.moduleIds).toEqual(moduleIds);
35
42
  expect(error.targetModule).toBe(targetModule);
36
43
  expect(error instanceof ModuleLoadingError).toBe(true);
@@ -44,14 +51,8 @@ describe("Module Loading Errors", () => {
44
51
  targetModule
45
52
  );
46
53
  const formatted = error.toString();
47
- const relativeA = path.relative(process.cwd(), "/src/A.js");
48
- const relativeB = path.relative(process.cwd(), "/src/B.js");
49
54
  expect(formatted).toContain("CircularDependencyError");
50
55
  expect(formatted).toContain("Circular dependency detected");
51
- expect(formatted).toContain(`\u250C\u2500 ${relativeA}`);
52
- expect(formatted).toContain(`\u251C\u2500 ${relativeB}`);
53
- expect(formatted).toContain(`\u2514\u2500 ${relativeA}`);
54
- expect(formatted).toContain("circular");
55
56
  });
56
57
  });
57
58
  describe("FileReadError", () => {
@@ -69,6 +70,14 @@ describe("Module Loading Errors", () => {
69
70
  );
70
71
  expect(error.name).toBe("FileReadError");
71
72
  expect(error.message).toBe("Failed to read module");
73
+ expect(error.stack).toContain("Failed to read module");
74
+ expect(error.stack).toContain("Module loading path:");
75
+ expect(error.stack).toContain("main.js");
76
+ expect(error.stack).toContain("App.js");
77
+ expect(error.stack).toContain("missing.js");
78
+ expect(error.stack).toContain("\u274C Loading failed");
79
+ expect(error.stack).toContain("Error details:");
80
+ expect(error.stack).toContain("ENOENT");
72
81
  expect(error.moduleIds).toEqual(moduleIds);
73
82
  expect(error.targetModule).toBe(targetModule);
74
83
  expect(error.originalError).toBe(originalError);
@@ -89,13 +98,6 @@ describe("Module Loading Errors", () => {
89
98
  const formatted = error.toString();
90
99
  expect(formatted).toContain("FileReadError");
91
100
  expect(formatted).toContain("Failed to read module");
92
- expect(formatted).toContain("Import chain:");
93
- expect(formatted).toContain("main.js");
94
- expect(formatted).toContain("App.js");
95
- expect(formatted).toContain("missing.js");
96
- expect(formatted).toContain("\u2717 FAILED");
97
- expect(formatted).toContain("Cause:");
98
- expect(formatted).toContain("ENOENT");
99
101
  });
100
102
  });
101
103
  describe("Formatting Functions", () => {
@@ -106,12 +108,14 @@ describe("Module Loading Errors", () => {
106
108
  const relativeA = path.relative(process.cwd(), "/src/A.js");
107
109
  const relativeB = path.relative(process.cwd(), "/src/B.js");
108
110
  const relativeC = path.relative(process.cwd(), "/src/C.js");
109
- expect(formatted).toContain("Circular dependency:");
111
+ expect(formatted).toContain(
112
+ "Module dependency chain (circular reference found):"
113
+ );
110
114
  expect(formatted).toContain(`\u250C\u2500 ${relativeA}`);
111
115
  expect(formatted).toContain(`\u251C\u2500 ${relativeB}`);
112
116
  expect(formatted).toContain(`\u251C\u2500 ${relativeC}`);
113
117
  expect(formatted).toContain(`\u2514\u2500 ${relativeA}`);
114
- expect(formatted).toContain("circular");
118
+ expect(formatted).toContain("\u{1F504} Creates circular reference");
115
119
  });
116
120
  it("should format module chain correctly", () => {
117
121
  const moduleIds = ["/src/main.js", "/src/app.js"];
@@ -122,12 +126,12 @@ describe("Module Loading Errors", () => {
122
126
  targetModule,
123
127
  originalError
124
128
  );
125
- expect(formatted).toContain("Import chain:");
129
+ expect(formatted).toContain("Module loading path:");
126
130
  expect(formatted).toContain("main.js");
127
131
  expect(formatted).toContain("app.js");
128
132
  expect(formatted).toContain("missing.js");
129
- expect(formatted).toContain("\u2717 FAILED");
130
- expect(formatted).toContain("Cause:");
133
+ expect(formatted).toContain("\u274C Loading failed");
134
+ expect(formatted).toContain("Error details:");
131
135
  expect(formatted).toContain("File not found");
132
136
  });
133
137
  it("should handle empty moduleIds in formatModuleChain", () => {
@@ -155,7 +159,9 @@ describe("Module Loading Errors", () => {
155
159
  expect(formatted).toContain(` \u2514\u2500 ${relativeB}`);
156
160
  expect(formatted).toContain(` \u2514\u2500 ${relativeC}`);
157
161
  expect(formatted).toContain(` \u2514\u2500 ${relativeD}`);
158
- expect(formatted).toContain(` \u2514\u2500 ${relativeE} \u2717 FAILED`);
162
+ expect(formatted).toContain(
163
+ ` \u2514\u2500 ${relativeE} \u274C Loading failed`
164
+ );
159
165
  });
160
166
  });
161
167
  });
package/package.json CHANGED
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@biomejs/biome": "1.9.4",
36
- "@esmx/lint": "3.0.0-rc.31",
36
+ "@esmx/lint": "3.0.0-rc.33",
37
37
  "@types/node": "^24.0.0",
38
38
  "@vitest/coverage-v8": "3.2.4",
39
39
  "stylelint": "16.21.0",
@@ -41,7 +41,7 @@
41
41
  "unbuild": "3.5.0",
42
42
  "vitest": "3.2.4"
43
43
  },
44
- "version": "3.0.0-rc.31",
44
+ "version": "3.0.0-rc.33",
45
45
  "type": "module",
46
46
  "private": false,
47
47
  "exports": {
@@ -60,5 +60,5 @@
60
60
  "template",
61
61
  "public"
62
62
  ],
63
- "gitHead": "d472904500f5d697cd61b99b012570f6b063c580"
63
+ "gitHead": "b38d6e27a1e1df3e4a11474e91e5838ddf26a3c4"
64
64
  }
package/src/error.test.ts CHANGED
@@ -36,7 +36,16 @@ describe('Module Loading Errors', () => {
36
36
  );
37
37
 
38
38
  expect(error.name).toBe('CircularDependencyError');
39
+ // Message is now clean and simple
39
40
  expect(error.message).toBe('Test circular dependency');
41
+ // Formatted content is in stack property
42
+ expect(error.stack).toContain('Test circular dependency');
43
+ expect(error.stack).toContain(
44
+ 'Module dependency chain (circular reference found):'
45
+ );
46
+ expect(error.stack).toContain('┌─');
47
+ expect(error.stack).toContain('└─');
48
+ expect(error.stack).toContain('🔄 Creates circular reference');
40
49
  expect(error.moduleIds).toEqual(moduleIds);
41
50
  expect(error.targetModule).toBe(targetModule);
42
51
  expect(error instanceof ModuleLoadingError).toBe(true);
@@ -54,16 +63,9 @@ describe('Module Loading Errors', () => {
54
63
 
55
64
  const formatted = error.toString();
56
65
 
57
- // Calculate expected relative paths
58
- const relativeA = path.relative(process.cwd(), '/src/A.js');
59
- const relativeB = path.relative(process.cwd(), '/src/B.js');
60
-
61
66
  expect(formatted).toContain('CircularDependencyError');
62
67
  expect(formatted).toContain('Circular dependency detected');
63
- expect(formatted).toContain(`┌─ ${relativeA}`);
64
- expect(formatted).toContain(`├─ ${relativeB}`);
65
- expect(formatted).toContain(`└─ ${relativeA}`);
66
- expect(formatted).toContain('circular');
68
+ // toString() now uses default Error behavior, so it only shows name and message
67
69
  });
68
70
  });
69
71
 
@@ -83,7 +85,17 @@ describe('Module Loading Errors', () => {
83
85
  );
84
86
 
85
87
  expect(error.name).toBe('FileReadError');
88
+ // Message is now clean and simple
86
89
  expect(error.message).toBe('Failed to read module');
90
+ // Formatted content is in stack property
91
+ expect(error.stack).toContain('Failed to read module');
92
+ expect(error.stack).toContain('Module loading path:');
93
+ expect(error.stack).toContain('main.js');
94
+ expect(error.stack).toContain('App.js');
95
+ expect(error.stack).toContain('missing.js');
96
+ expect(error.stack).toContain('❌ Loading failed');
97
+ expect(error.stack).toContain('Error details:');
98
+ expect(error.stack).toContain('ENOENT');
87
99
  expect(error.moduleIds).toEqual(moduleIds);
88
100
  expect(error.targetModule).toBe(targetModule);
89
101
  expect(error.originalError).toBe(originalError);
@@ -108,13 +120,7 @@ describe('Module Loading Errors', () => {
108
120
 
109
121
  expect(formatted).toContain('FileReadError');
110
122
  expect(formatted).toContain('Failed to read module');
111
- expect(formatted).toContain('Import chain:');
112
- expect(formatted).toContain('main.js');
113
- expect(formatted).toContain('App.js');
114
- expect(formatted).toContain('missing.js');
115
- expect(formatted).toContain('✗ FAILED');
116
- expect(formatted).toContain('Cause:');
117
- expect(formatted).toContain('ENOENT');
123
+ // toString() now uses default Error behavior, so it only shows name and message
118
124
  });
119
125
  });
120
126
 
@@ -130,12 +136,14 @@ describe('Module Loading Errors', () => {
130
136
  const relativeB = path.relative(process.cwd(), '/src/B.js');
131
137
  const relativeC = path.relative(process.cwd(), '/src/C.js');
132
138
 
133
- expect(formatted).toContain('Circular dependency:');
139
+ expect(formatted).toContain(
140
+ 'Module dependency chain (circular reference found):'
141
+ );
134
142
  expect(formatted).toContain(`┌─ ${relativeA}`);
135
143
  expect(formatted).toContain(`├─ ${relativeB}`);
136
144
  expect(formatted).toContain(`├─ ${relativeC}`);
137
145
  expect(formatted).toContain(`└─ ${relativeA}`);
138
- expect(formatted).toContain('circular');
146
+ expect(formatted).toContain('🔄 Creates circular reference');
139
147
  });
140
148
 
141
149
  it('should format module chain correctly', () => {
@@ -149,12 +157,12 @@ describe('Module Loading Errors', () => {
149
157
  originalError
150
158
  );
151
159
 
152
- expect(formatted).toContain('Import chain:');
160
+ expect(formatted).toContain('Module loading path:');
153
161
  expect(formatted).toContain('main.js');
154
162
  expect(formatted).toContain('app.js');
155
163
  expect(formatted).toContain('missing.js');
156
- expect(formatted).toContain(' FAILED');
157
- expect(formatted).toContain('Cause:');
164
+ expect(formatted).toContain(' Loading failed');
165
+ expect(formatted).toContain('Error details:');
158
166
  expect(formatted).toContain('File not found');
159
167
  });
160
168
 
@@ -190,7 +198,9 @@ describe('Module Loading Errors', () => {
190
198
  expect(formatted).toContain(` └─ ${relativeB}`);
191
199
  expect(formatted).toContain(` └─ ${relativeC}`);
192
200
  expect(formatted).toContain(` └─ ${relativeD}`);
193
- expect(formatted).toContain(` └─ ${relativeE} ✗ FAILED`);
201
+ expect(formatted).toContain(
202
+ ` └─ ${relativeE} ❌ Loading failed`
203
+ );
194
204
  });
195
205
  });
196
206
  });
package/src/error.ts CHANGED
@@ -38,7 +38,7 @@ export const formatCircularDependency = (
38
38
  ): string => {
39
39
  const fullChain = [...moduleIds, targetModule];
40
40
 
41
- return `${colorize(colorize('Circular dependency:', Colors.BOLD), Colors.RED)}\n${fullChain
41
+ return `${colorize(colorize('Module dependency chain (circular reference found):', Colors.BOLD), Colors.RED)}\n${fullChain
42
42
  .map((module, index) => {
43
43
  const isLastModule = index === fullChain.length - 1;
44
44
  const prefix =
@@ -59,7 +59,7 @@ export const formatCircularDependency = (
59
59
  : colorize(displayPath, Colors.CYAN);
60
60
 
61
61
  const suffix = isLastModule
62
- ? ` ${colorize(' circular', Colors.YELLOW)}`
62
+ ? ` ${colorize('🔄 Creates circular reference', Colors.YELLOW)}`
63
63
  : '';
64
64
 
65
65
  return `${colorize(prefix, Colors.GRAY)}${coloredFile}${suffix}`;
@@ -80,7 +80,7 @@ export const formatModuleChain = (
80
80
  result = `${colorize('Failed to load:', Colors.CYAN)} ${colorize(displayPath, Colors.RED)}`;
81
81
  } else {
82
82
  const chain = [...moduleIds, targetModule];
83
- result = `${colorize(colorize('Import chain:', Colors.BOLD), Colors.CYAN)}\n${chain
83
+ result = `${colorize(colorize('Module loading path:', Colors.BOLD), Colors.CYAN)}\n${chain
84
84
  .map((module, index) => {
85
85
  const indent = ' '.repeat(index);
86
86
  const connector = index === 0 ? '' : '└─ ';
@@ -92,7 +92,7 @@ export const formatModuleChain = (
92
92
  : colorize(displayPath, Colors.CYAN);
93
93
 
94
94
  const status = isFailedFile
95
- ? ` ${colorize(colorize(' FAILED', Colors.BOLD), Colors.RED)}`
95
+ ? ` ${colorize(colorize(' Loading failed', Colors.BOLD), Colors.RED)}`
96
96
  : '';
97
97
 
98
98
  return `${colorize(indent + connector, Colors.GRAY)}${coloredFile}${status}`;
@@ -101,7 +101,7 @@ export const formatModuleChain = (
101
101
  }
102
102
 
103
103
  if (originalError) {
104
- result += `\n\n${colorize('Cause:', Colors.YELLOW)} ${originalError.message}`;
104
+ result += `\n\n${colorize('Error details:', Colors.YELLOW)} ${originalError.message}`;
105
105
  }
106
106
 
107
107
  return result;
@@ -117,6 +117,30 @@ export class ModuleLoadingError extends Error {
117
117
  ) {
118
118
  super(message);
119
119
  this.name = 'ModuleLoadingError';
120
+
121
+ // Hide auxiliary properties from enumeration to avoid cluttering error display
122
+ Object.defineProperty(this, 'moduleIds', {
123
+ value: moduleIds,
124
+ writable: false,
125
+ enumerable: false,
126
+ configurable: true
127
+ });
128
+
129
+ Object.defineProperty(this, 'targetModule', {
130
+ value: targetModule,
131
+ writable: false,
132
+ enumerable: false,
133
+ configurable: true
134
+ });
135
+
136
+ if (originalError) {
137
+ Object.defineProperty(this, 'originalError', {
138
+ value: originalError,
139
+ writable: false,
140
+ enumerable: false,
141
+ configurable: true
142
+ });
143
+ }
120
144
  }
121
145
  }
122
146
 
@@ -125,10 +149,9 @@ export class CircularDependencyError extends ModuleLoadingError {
125
149
  constructor(message: string, moduleIds: string[], targetModule: string) {
126
150
  super(message, moduleIds, targetModule);
127
151
  this.name = 'CircularDependencyError';
128
- }
129
152
 
130
- toString(): string {
131
- return `${this.name}: ${this.message}\n\n${formatCircularDependency(this.moduleIds, this.targetModule)}`;
153
+ // Custom stack for clean error display
154
+ this.stack = `${this.name}: ${message}\n\n${formatCircularDependency(moduleIds, targetModule)}`;
132
155
  }
133
156
  }
134
157
 
@@ -142,9 +165,8 @@ export class FileReadError extends ModuleLoadingError {
142
165
  ) {
143
166
  super(message, moduleIds, targetModule, originalError);
144
167
  this.name = 'FileReadError';
145
- }
146
168
 
147
- toString(): string {
148
- return `${this.name}: ${this.message}\n\n${formatModuleChain(this.moduleIds, this.targetModule, this.originalError)}`;
169
+ // Custom stack for clean error display
170
+ this.stack = `${this.name}: ${message}\n\n${formatModuleChain(moduleIds, targetModule, originalError)}`;
149
171
  }
150
172
  }