Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
jest-haste-map
Advanced tools
`jest-haste-map` is a module used by Jest, a popular JavaScript testing framework, to create a fast lookup of files in a project. It helps Jest efficiently locate and track changes in files during testing, making it particularly useful for large projects
The jest-haste-map npm package is a utility for building a Haste map, which is a mapping from module names to file paths. It is used by Jest to quickly resolve module dependencies for tests by keeping an in-memory map of all available modules. It can handle duplicate module names and provides a way to query the map for a specific module.
Building a Haste Map
This code sample demonstrates how to create a new HasteMap instance with a configuration object, build the map, and then use it to get the module name for a specific file.
const HasteMap = require('jest-haste-map');
const config = {
// These options are required:
roots: ['/path/to/project'],
extensions: ['js', 'json'],
platforms: ['ios', 'android'],
// You can provide additional options:
computeSha1: true,
// other options...
};
const hasteMap = new HasteMap(config);
hasteMap.build().then(map => {
console.log(map.hasteFS.getModuleName('/path/to/project/file.js'));
});
Querying the Haste Map
This code sample shows how to query the built Haste map for the path of a module given its name, platform, and whether it supports the native platform.
hasteMap.build().then(map => {
const modulePath = map.moduleMap.getModule('moduleName', 'platform', 'supportsNativePlatform');
console.log(modulePath);
});
Metro is a JavaScript bundler for React Native applications. It includes a Haste map implementation similar to jest-haste-map, but it is tailored specifically for React Native and includes additional features for bundling and transforming code.
Webpack is a powerful module bundler for JavaScript applications. While it does not use a Haste map, it provides a similar functionality through its own resolution mechanism, which can handle complex dependency graphs and offers a wide range of plugins for different tasks.
Browserify is a tool for bundling JavaScript files for usage in the browser. Like webpack, it does not use a Haste map, but it allows developers to require modules in the browser by bundling up all dependencies. It's simpler than webpack and may be more suitable for smaller projects.
jest-haste-map
is a module used by Jest, a popular JavaScript testing framework, to create a fast lookup of files in a project. It helps Jest efficiently locate and track changes in files during testing, making it particularly useful for large projects with many files.
with npm :
npm install jest-haste-map --save-dev
with yarn :
yarn add jest-haste-map --dev
jest-haste-map
is compatible with both ES modules
and CommonJS
const map = new HasteMap.default({
// options
});
import HasteMap from 'jest-haste-map';
import os from 'os';
import {dirname} from 'path';
import {fileURLToPath} from 'url';
const root = dirname(fileURLToPath(import.meta.url));
const map = new HasteMap.default({
id: 'myproject', //Used for caching.
extensions: ['js'], // Tells jest-haste-map to only crawl .js files.
maxWorkers: os.availableParallelism(), //Parallelizes across all available CPUs.
platforms: [], // This is only used for React Native, you can leave it empty.
roots: [root], // Can be used to only search a subset of files within `rootDir`
retainAllFiles: true,
rootDir: root, //The project root.
});
const {hasteFS} = await map.build();
const files = hasteFS.getAllFiles();
console.log(files);
Option | Type | Required | Default Value |
---|---|---|---|
cacheDirectory | string | No | os.tmpdir() |
computeDependencies | boolean | No | true |
computeSha1 | boolean | No | false |
console | Console | No | - |
dependencyExtractor | string | null | No | null |
enableSymlinks | boolean | No | false |
extensions | Array<string> | Yes | - |
forceNodeFilesystemAPI | boolean | Yes | - |
hasteImplModulePath | string | Yes | - |
hasteMapModulePath | string | Yes | - |
id | string | Yes | - |
ignorePattern | HasteRegExp | No | - |
maxWorkers | number | Yes | - |
mocksPattern | string | No | - |
platforms | Array<string> | Yes | - |
resetCache | boolean | No | - |
retainAllFiles | boolean | Yes | - |
rootDir | string | Yes | - |
roots | Array<string> | Yes | - |
skipPackageJson | boolean | Yes | - |
throwOnModuleCollision | boolean | Yes | - |
useWatchman | boolean | No | true |
For more, you can check github
FAQs
Unknown package
The npm package jest-haste-map receives a total of 29,430,113 weekly downloads. As such, jest-haste-map popularity was classified as popular.
We found that jest-haste-map demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.