@lynxwall/cucumber-tsflow 7.3.0 → 7.3.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.
@@ -79,21 +79,57 @@ export async function resolveWithExtensions(specifier, parentURL, extensions = C
79
79
  return null;
80
80
  }
81
81
 
82
- // TSConfig path mapping resolver
82
+ const pathResolutionCache = new Map();
83
+
83
84
  export function resolveTsconfigPaths(specifier) {
85
+ // Fast path: skip what we know won't match
86
+ if (
87
+ specifier.startsWith('.') ||
88
+ specifier.startsWith('/') ||
89
+ specifier.startsWith('file:') ||
90
+ specifier.startsWith('node:')
91
+ ) {
92
+ return null;
93
+ }
94
+
95
+ // Check cache
96
+ if (pathResolutionCache.has(specifier)) {
97
+ return pathResolutionCache.get(specifier);
98
+ }
99
+
84
100
  const matchPath = initializeTsconfigPaths();
101
+ if (!matchPath) {
102
+ pathResolutionCache.set(specifier, null);
103
+ return null;
104
+ }
85
105
 
86
- if (matchPath && !specifier.startsWith('.') && !specifier.startsWith('/') && !specifier.startsWith('file:')) {
87
- const mapped = matchPath(specifier);
106
+ // Try direct match first
107
+ const mapped = matchPath(specifier);
108
+ if (mapped) {
109
+ const result = {
110
+ url: pathToFileURL(mapped).href,
111
+ shortCircuit: true
112
+ };
113
+ pathResolutionCache.set(specifier, result);
114
+ return result;
115
+ }
88
116
 
89
- if (mapped) {
90
- return {
91
- url: pathToFileURL(mapped).href,
92
- shortCircuit: true
93
- };
117
+ // Try with extensions if no extension present
118
+ if (!path.extname(specifier)) {
119
+ for (const ext of ['.ts', '.js', '.mjs', '.vue']) {
120
+ const mappedWithExt = matchPath(specifier + ext);
121
+ if (mappedWithExt) {
122
+ const result = {
123
+ url: pathToFileURL(mappedWithExt).href,
124
+ shortCircuit: true
125
+ };
126
+ pathResolutionCache.set(specifier, result);
127
+ return result;
128
+ }
94
129
  }
95
130
  }
96
131
 
132
+ pathResolutionCache.set(specifier, null);
97
133
  return null;
98
134
  }
99
135
 
@@ -118,6 +154,45 @@ export function shouldEnableVueStyle() {
118
154
  );
119
155
  }
120
156
 
157
+ async function transformImports(code, parentURL) {
158
+ // Match various import patterns
159
+ const importRegex =
160
+ /(?:import|export)\s+(?:(?:\{[^}]*\}|\*\s+as\s+\w+|\w+|type\s+\{[^}]*\}|type\s+\w+)\s+from\s+)?['"]([^'"]+)['"]/g;
161
+
162
+ const matches = [...code.matchAll(importRegex)];
163
+ let transformed = code;
164
+
165
+ for (const match of matches) {
166
+ const specifier = match[1];
167
+
168
+ // Skip if it's already a relative path or absolute URL
169
+ if (specifier.startsWith('.') || specifier.startsWith('/') || specifier.startsWith('file:')) {
170
+ continue;
171
+ }
172
+
173
+ // Try to resolve with tsconfig paths
174
+ const resolved = resolveTsconfigPaths(specifier);
175
+ if (resolved) {
176
+ // Convert the resolved path to a relative import from the parent file
177
+ const parentDir = path.dirname(fileURLToPath(parentURL));
178
+ const resolvedPath = fileURLToPath(resolved.url);
179
+ let relativePath = path.relative(parentDir, resolvedPath).replace(/\\/g, '/');
180
+
181
+ // Ensure it starts with ./ or ../
182
+ if (!relativePath.startsWith('.')) {
183
+ relativePath = './' + relativePath;
184
+ }
185
+
186
+ // Replace the specifier in the import statement
187
+ const originalImport = match[0];
188
+ const newImport = originalImport.replace(specifier, relativePath);
189
+ transformed = transformed.replace(originalImport, newImport);
190
+ }
191
+ }
192
+
193
+ return transformed;
194
+ }
195
+
121
196
  export async function loadVue(url, context, nextLoad) {
122
197
  const { source } = await nextLoad(url, { ...context, format: 'module' });
123
198
  const code = source.toString();
@@ -127,13 +202,52 @@ export async function loadVue(url, context, nextLoad) {
127
202
  enableStyle: shouldEnableVueStyle()
128
203
  });
129
204
 
205
+ // Transform imports to resolve path aliases
206
+ const transformed = await transformImports(compiled.code, url);
207
+
130
208
  return {
131
209
  format: 'module',
132
- source: compiled.code,
210
+ source: transformed,
211
+ shortCircuit: true
212
+ };
213
+ }
214
+
215
+ // Common load handlers
216
+ export async function loadJson(url, context, nextLoad) {
217
+ const result = await nextLoad(url, {
218
+ ...context,
219
+ format: 'json',
220
+ importAttributes: { type: 'json' }
221
+ });
222
+
223
+ return {
224
+ ...result,
225
+ format: 'json',
133
226
  shortCircuit: true
134
227
  };
135
228
  }
136
229
 
230
+ // loader-utils.mjs - Add a simple common file handler
231
+ export function handleCommonFileTypes(url, context, nextLoad, loaderName) {
232
+ // Handle assets
233
+ const ext = path.extname(url).toLowerCase();
234
+ if (ASSET_EXTENSIONS.includes(ext)) {
235
+ return loadAsset(url);
236
+ }
237
+
238
+ // Handle JSON
239
+ if (url.endsWith('.json')) {
240
+ try {
241
+ return loadJson(url, context, nextLoad);
242
+ } catch (error) {
243
+ console.error(`>>> ${loaderName}: Failed to compile ${url}:`, error);
244
+ throw new Error(`Failed to compile ${url}: ${error.message}`);
245
+ }
246
+ }
247
+
248
+ return null; // Not a common file type
249
+ }
250
+
137
251
  /**
138
252
  * Resolves module specifiers with support for TypeScript paths, extensions, and more
139
253
  * @param {string} specifier - The module specifier to resolve
@@ -243,11 +357,9 @@ export function createEsbuildLoader(options = {}) {
243
357
  },
244
358
 
245
359
  load: async (url, context, nextLoad) => {
246
- // Handle asset files
247
- const ext = path.extname(url).toLowerCase();
248
- if (ASSET_EXTENSIONS.includes(ext)) {
249
- return loadAsset(url);
250
- }
360
+ // Check common file types first
361
+ const commonResult = await handleCommonFileTypes(url, context, nextLoad);
362
+ if (commonResult) return commonResult;
251
363
 
252
364
  // Handle Vue files if enabled
253
365
  if (handleVue && url.endsWith('.vue')) {
@@ -37,8 +37,7 @@
37
37
  * preprocessor packages to be installed. Missing preprocessors will be skipped
38
38
  * with a warning rather than failing the compilation.
39
39
  */
40
- import path from 'path';
41
- import { ASSET_EXTENSIONS, resolveSpecifier, loadAsset, loadVue } from './loader-utils.mjs';
40
+ import { resolveSpecifier, loadVue, handleCommonFileTypes } from './loader-utils.mjs';
42
41
 
43
42
  // Cache for the TypeScript loader
44
43
  let tsLoader;
@@ -65,11 +64,9 @@ async function getTsLoader() {
65
64
  }
66
65
 
67
66
  export async function load(url, context, nextLoad) {
68
- // Handle asset files that Vue compiler turns into imports
69
- const ext = path.extname(url).toLowerCase();
70
- if (ASSET_EXTENSIONS.includes(ext)) {
71
- return loadAsset(url);
72
- }
67
+ // Check common file types first
68
+ const commonResult = await handleCommonFileTypes(url, context, nextLoad);
69
+ if (commonResult) return commonResult;
73
70
 
74
71
  // Only process .vue files directly
75
72
  if (url.endsWith('.vue')) {
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "7.3.0";
1
+ export declare const version = "7.3.2";
package/lib/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // Generated by genversion.
5
- exports.version = '7.3.0';
5
+ exports.version = '7.3.2';
6
6
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AACd,QAAA,OAAO,GAAG,OAAO,CAAA","sourcesContent":["// Generated by genversion.\nexport const version = '7.3.0'\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AACd,QAAA,OAAO,GAAG,OAAO,CAAA","sourcesContent":["// Generated by genversion.\nexport const version = '7.3.2'\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lynxwall/cucumber-tsflow",
3
3
  "description": "Provides 'specflow' like bindings for CucumberJS 11.2.0 in TypeScript 5.8+.",
4
- "version": "7.3.0",
4
+ "version": "7.3.2",
5
5
  "author": "Lonnie Wall <lynxdev@lynxwall.com>",
6
6
  "license": "MIT",
7
7
  "keywords": [