Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
express-transform-bare-module-specifiers
Advanced tools
Express middleware to transform bare module specifiers on-the-fly.
Express middleware to transform bare module specifiers on-the-fly.
Install the middleware:
npm i express-transform-bare-module-specifiers
Import (or require
) this package:
// ES Modules
import transformMiddleware from 'express-transform-bare-module-specifiers';
// CommonJS
const transformMiddleware = require('express-transform-bare-module-specifiers').default;
Configure and apply the middleware:
// Using defaults:
app.use('*', transformMiddleware());
// Using a custom rootDir and modulesUrl:
app.use('*', transformMiddleware({
rootDir: path.resolve(__dirname, '/bundles/my-bundle'),
modulesUrl: '/bundles/my-bundle/node_modules'
}))
rootDir
: the project base directory. This should contain the package.json and node_modules of the application. It defaults to process.cwd()
.modulesUrl
: is the route that you will be serving your node_modules
directory from. It defaults to /node_modules
.ES Modules are great. However, it can be difficult to incorporate existing npm packages, because you have to specify the fully-qualified path to the entrypoint of each and every npm package you wish to use. That is to say: you can't do this:
import * as noop from 'noop3';
... you instead must do this (for example):
import * as noop from '../node_modules/noop3/index.js';
You can see how this would rapidly become very hard to maintain.
This limitation is present because the ES Modules spec currently does not support so-called "bare module specifiers". That is: any module specifier which does not start with a relative or absolute path, such as /
, ./
, ../
, etc.
This middleware uses a single babel transform to convert these "bare module specifiers" in your code to fully-qualified relative paths. This means that you can just write code which references npm packages installed in your node_modules
, and this middleware will handle translating those package names to fully-qualified paths on-the-fly.
This middleware is based entirely on the implementation found in polyserve
. Except, it uses the babel-plugin-bare-import-rewrite
babel plugin instead of the one built into polymer-build.
FAQs
Express middleware to transform bare module specifiers on-the-fly.
The npm package express-transform-bare-module-specifiers receives a total of 868 weekly downloads. As such, express-transform-bare-module-specifiers popularity was classified as not popular.
We found that express-transform-bare-module-specifiers 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.