-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjest-resolver.js
More file actions
41 lines (35 loc) · 1.34 KB
/
jest-resolver.js
File metadata and controls
41 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Custom Jest resolver to handle node: protocol imports and workspace packages
const path = require('path');
const fs = require('fs');
module.exports = (request, options) => {
// Strip 'node:' prefix from built-in module imports
if (request.startsWith('node:')) {
request = request.replace(/^node:/, '');
}
// Handle @pie-element workspace packages for Jest mocking
if (request.startsWith('@pie-element/')) {
const packageName = request.replace('@pie-element/', '');
const parts = packageName.split('/');
const mainPackage = parts[0];
// Check if it's a subpath like "rubric/configure/lib"
if (parts.length > 1) {
const subpath = parts.slice(1).join('/');
const libPath = path.join(options.rootDir, 'packages', mainPackage, subpath, 'index.js');
if (fs.existsSync(libPath)) {
return libPath;
}
}
// Try main package lib/index.js
const libPath = path.join(options.rootDir, 'packages', mainPackage, 'lib', 'index.js');
if (fs.existsSync(libPath)) {
return libPath;
}
// Fallback to src/index.js if lib doesn't exist
const srcPath = path.join(options.rootDir, 'packages', mainPackage, 'src', 'index.js');
if (fs.existsSync(srcPath)) {
return srcPath;
}
}
// Use the default Jest resolver
return options.defaultResolver(request, options);
};