Registry / devops / middleware-rename-file

middleware-rename-file

JSON →
library1.0.0jsnpmunverified

middleware-rename-file is a Node.js middleware designed for dynamically renaming Vinyl file objects by leveraging properties defined within their YAML front-matter. Currently at version 1.0.0, the package appears to be in a maintenance state, with no active feature development. It targets older Node.js environments (engines >=0.10.0) and is primarily integrated with established templating and static site generation frameworks such as Assemble, Verb, Generate, and Templates. The core functionality allows developers to specify new `basename` and `dirname` attributes directly in a file's front-matter, which the middleware then applies to the file's destination path early in the build pipeline, typically via an `onLoad` event. This declarative approach to file renaming is a key differentiator, providing a structured way to manage file output within its target ecosystems.

npm install middleware-rename-file
INSTALL
IMPORT
SIG · MIDDLEWARE-RENAME-
M
middleware-rename-file
devopsjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

renameMiddleware
const renameMiddleware = require('middleware-rename-file');
import renameMiddleware from 'middleware-rename-file';
This package is CommonJS-only. There is no native ESM support.

Demonstrates how to use the `middleware-rename-file` function by mocking a Vinyl file object and applying renaming based on front-matter properties, including an example with a filter function.

const renameMiddleware = require('middleware-rename-file'); // Mock a Vinyl-like file object with front-matter const fileWithFrontMatter = { path: 'scaffolds/layouts/base.hbs', contents: Buffer.from('---\nrename:\n basename: default.hbs\n dirname: templates\n---\n\n<!DOCTYPE html>...'), data: { // `data` property where front-matter is usually parsed rename: { basename: 'default.hbs', dirname: 'templates' } }, // Simulate Vinyl file properties basename: 'base.hbs', dirname: 'scaffolds/layouts', extname: '.hbs', stem: 'base' }; const fileWithoutFrontMatter = { path: 'src/pages/index.html', contents: Buffer.from('<html>...</html>'), data: {}, basename: 'index.html', dirname: 'src/pages', extname: '.html', stem: 'index' }; const mockApp = { emit: (event, file) => { // In a real app, this would be `app.emit('file', file)` // or similar, passing the transformed file down the pipeline. console.log(` Processed file: ${file.path}`); console.log(` New basename: ${file.basename}`); console.log(` New dirname: ${file.dirname}`); } }; // Initialize the middleware const rename = renameMiddleware(); // Apply middleware to the first file rename(fileWithFrontMatter, mockApp); // Apply middleware to the second file with a filter that prevents renaming 'index' files const renameWithFilter = renameMiddleware(file => file.stem !== 'index'); renameWithFilter(fileWithoutFrontMatter, mockApp);
Debug
Known issues
gotchaThis package is designed for CommonJS environments and does not provide native ES module support. Attempting to use `import` syntax will result in errors.
fix
Use `const renameMiddleware = require('middleware-rename-file');` for importing the module.
affects: >=1.0.0
gotchaThe package relies on a specific front-matter structure (`rename: { basename: '...', dirname: '...' }`). Incorrectly formatted or missing `rename` properties will prevent files from being renamed as expected.
fix
Ensure your file's YAML front-matter includes a top-level `rename` key with `basename` and/or `dirname` properties, for example:
```yaml
---
rename:
  basename: new-name.html
  dirname: new/path
---
```
affects: >=1.0.0
deprecatedThe package specifies Node.js engine compatibility as `>=0.10.0`, indicating it was developed for very old Node.js versions. While its simple functionality might still work, compatibility with modern Node.js versions is not explicitly guaranteed or tested.
fix
If encountering issues in modern Node.js environments, consider porting the logic or using a more actively maintained alternative. However, for its specific use-case within the Assemble/Templates ecosystem, it generally remains functional.
affects: >=1.0.0
gotchaThis middleware is specifically designed to integrate with the 'templates' ecosystem (Assemble, Verb, Generate). Its usage outside of these frameworks, particularly with generic Gulp or other build systems, may require manual integration steps for parsing front-matter and handling Vinyl file objects.
fix
When using outside of the intended ecosystem, ensure your build process correctly parses front-matter into the `file.data` property and that you are passing valid Vinyl-like file objects to the middleware.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: rename is not a function
Attempting to import the CommonJS module using `import` syntax, or trying to access a named export that does not exist.
fix
Use CommonJS `require`: `const renameMiddleware = require('middleware-rename-file');`.
File not renamed as expected
The YAML front-matter in the file is missing the `rename` key or its `basename`/`dirname` properties are malformed, or a filter function passed to the middleware is preventing the rename.
fix
Verify the front-matter structure for the `rename` key and its sub-properties. If a filter function is used, ensure it returns `true` for files that should be renamed.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
middleware-rename-file — npm install middleware-rename-file · libregistry