
Product
Rubygems Ecosystem Support Now Generally Available
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.
esm-directory-import
Advanced tools
Import the files in a directory recursively using dynamic import(import.meta.url)
Using the
import.meta.url
file URL to recursively and dynamicallyimport()
each of the files inside the directory of the specified URL. Thedefault
export for each file (module) is collected into a dictionary that sets the export into a directory delimited structure.
- directory1
- index.js (file that calls `importDir(import.meta.url)`
- file1.js
- directory2
- file2.mjs
- file3.cjs
{
file1: (default export of file1.js),
directory2: {
file2: (default export of file2.mjs),
file3: (default export of file3.cjs),
}
}
import importDir from 'import-dir';
export const defaults = await importDir(import.meta.url);
// or
export const defaults = await importDir(import.meta.url, { exclude: ['directory2/file2.mjs'] });
The default export function of esm-directory-import
accepts 2 arguments, the first is a file URL, typically the value of import.meta.url
from the ESM that invokes the function. The second argument is a dictionary of options outlined here:
exclude: string[] = []
An array of string file paths relative to the initial file URL that
should be excluded from the returned object.glob: (pattern: string, options: GlobOptions) => Promise<string[]> = glob
A function that accepts a glob pattern as the first argument and an object that specifies { cwd: dirname(fileUrlToPath(import.meta.url)) }
.extensions: string[] = ['.mjs', '.cjs', '.js']
An array of string file extensions that will
be used in the glob pattern used for determining the files that should be imported.template: (exts: string[]) => string = (exts) => '**/*{${exts.join(',')}}'
A function that takes a list of file extensions that should be looked for and returns a glob file matching pattern.collector: (mod: Module) => any = (mod) => mod.default
A function that accepts the result of await import(file)
as an argument and returns the value that should be stored as the value of the file in the object structure.FAQs
Import the files in a directory recursively using dynamic import(import.meta.url)
The npm package esm-directory-import receives a total of 1 weekly downloads. As such, esm-directory-import popularity was classified as not popular.
We found that esm-directory-import demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.
Research
The Socket Research Team investigates a malicious npm package that appears to be an Advcash integration but triggers a reverse shell during payment success, targeting servers handling transactions.
Security Fundamentals
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.