Open theblockstalk opened 5 months ago
I have found 1 solution so far which allows resolution with jest, using the following in the jest.config.ts file which you can see in in PR commit https://github.com/Tonomy-Foundation/Tonomy-ID-SDK/pull/394/commits/22e19041e002344fe31410962208dc896ed3dcbd
moduleNameMapper: {
// This is a workaround for the following packages that use conditional exports in package.json which jest does not support yet
"^uint8arrays$": "<rootDir>/node_modules/uint8arrays/esm/src/index.js",
"^@ipld/dag-pb*": "<rootDir>/node_modules/@ipld/dag-pb/src/index.js",
"^multiformats/(.*)$": "<rootDir>/node_modules/multiformats/dist/src/$1.js",
"^ipfs-unixfs$": "<rootDir>/node_modules/ipfs-unixfs/dist/src/index.js",
"^protons-runtime$": "<rootDir>/node_modules/protons-runtime/dist/src/index.js",
"^uint8-varint$": "<rootDir>/node_modules/uint8-varint/dist/src/index.js",
"^uint8arrays/(.*)$": "<rootDir>/node_modules/uint8arrays/esm/src/$1.js",
}
also tried, unsucessfully:
changing jest.config.ts:
jest-resolver.cjs
const defaultResolver = require('jest-resolve').default;
const path = require('path');
// use the import field in package.json to resolve the module manually
module.exports = (request, options) => {
// Attempt to resolve using the default resolver
try {
return defaultResolver(request, options);
} catch (e) {
// If the resolution fails, attempt to resolve using "exports"
const modulePath = path.join(options.basedir, 'node_modules', request);
const pkgPath = path.join(modulePath, 'package.json');
try {
const pkg = require(pkgPath);
if (pkg.exports && pkg.exports.import) {
return path.join(modulePath, pkg.exports.import);
}
} catch (innerError) {
// If anything goes wrong, throw the original error
throw innerError;
}
}
};
// explicitly specify the conditions to resolve the module
module.exports = (path, options) => {
// Call the defaultResolver, so we leverage its cache, error handling, etc.
return options.defaultResolver(path, {
...options,
conditions: ["default", "import"]
});
};
Good chat here with Veramo author https://discord.com/channels/878293684620234752/1200026960307437578/1249720913390469245
Upgrade to the latest version of this library Would provide additional security and functional upgrades, as well as put us in a position to start using the Veramo library. See task https://github.com/Tonomy-Foundation/Tonomy-ID-SDK/issues/337
Why have we not done this yet:
Repositories
Also need to upgrade: