npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fabiomcosta/mvjs

v1.16.1

Published

Easily move files and directories around your JavaScript project.

Downloads

38

Readme

mvjs · GitHub license npm version

Easily move files and directories around your JavaScript project.

The problem

Moving JavaScript modules inside a project is generally a tedious task. After you move it using mv, you have to update their references on the other modules inside your project.

mvjs moves the module and also updates all its references on the other modules making the task of moving modules much simpler, similarly to using mv.

It does this by running a codemod on all JavaScript modules inside the project (with the help of jscodeshift) and smartly updating import declarations and require calls.

For non-js module files, a regular expression runs on their content, replacing any string that looks like a path and matches any of the moved files will be properly replaced. This gives extra piece of mind when moving .scss and other file extensions that can potentially import one of the moved files.

Features

  • Supports and updates import _ from '...', import('...') and require('...')
  • Updates files using JavaScript, TypeScript or Flow
  • Does its best to also update non-js files
  • Moves files or directories
  • Same api and simplicity of the mv command
  • Shows easy to understand errors when unexpected things happen
  • Uses DEBUG environment variable to show extra dbug information. Ex: DEBUB=* mvjs ./a.js ./b.js

Install

npm install -g @fabiomcosta/mvjs

This makes mvjs available globally.

CLI Usage

$ mvjs --help
mvjs - moves a JavaScript module and updates all import references in the project.

Options:
  --version         Show version number                                                                        [boolean]
  --parser          jscodeshift's parser option.
                    See https://github.com/facebook/jscodeshift#parser                        [string] [default: "flow"]
  --ignore-pattern  Pattern of files that won't have their file references updated                              [string]
  --help            Show help                                                                                  [boolean]

Examples:
  cli.js ./a.js ./b.js                                          Moves "a.js" to "b.js" and updates the other modules
                                                                importing "a.js" to now import "b.js".
  cli.js --recast.quote='double' ./a.js ./b.js                  Recast options can be changed by using
                                                                --recast.optionName notation.
                                                                In this example the codemoded files are going to have
                                                                double quotes for all strings.
                                                                See https://github.com/benjamn/recast/blob/master/lib/op
                                                                tions.ts
  cli.js --ignore-pattern='*.d.ts'                              Ignore patterns with the familiar gitignore syntax
  --ignore-pattern='*.js.flow' ./a.js ./b.js                    defined at https://git-scm.com/docs/gitignore
                                                                Multiple patterns can be ignored by providing multiple
                                                                options.

Example

Consider the following folder structure for a project:

root/
│   package.json
└── src/
    ├── common/
    │   └── config.js
    └── client/
        │   paths-client.js
        └── files-client.js

And the following file content for ./src/client/paths-client.js:

import files from './files-client';
// or const files = require('./files-client');

Let's move the ./src/client/files-client.js module inside the ./src/common/ folder:

mvjs ./src/client/files-client.js ./src/common/files.js

This will make sure that all files that had a reference to this module are also going to be properly updated, which means that paths-client.js will be updated to:

import files from '../common/files';
// or const files = require('../common/files');

API Usage

move (and ONLY move) modules:

import {move} from '@fabiomcosta/mvjs';

(async () => {
  await move({
    sourcePaths: ['./foo.js', './bar.mjs'],
    targePath: './baz'
  });
})();

codemod the import statements from the current project modules:

import {transform} from '@fabiomcosta/mvjs';

(async () => {
  await transform({
    sourcePaths: ['./foo.js', './bar.mjs'],
    targePath: './baz',
    parser: 'flow', // optional
    recastOptions: {quotes: 'single'} // optional
  });
})();

TODO

  • [x] move .jsx, .mjs, .es, .es6
  • [x] move multiple sources to a directory
  • [x] move a directory to another directory
  • [x] move any file extension (keep updating the references only from .js, .jsx, .mjs, .es, .es6 files)
  • [x] Update references on other types of files, like CSS, SASS, LESS etc.
  • [ ] Optionaly rename imported default
  • [ ] Add option to allow other function calls to be replaced