Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-jscodeshift-adapter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-jscodeshift-adapter

Run jscodeshift on Vue single file components

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
42K
decreased by-0.42%
Maintainers
1
Weekly downloads
 
Created
Source

vue-jscodeshift-adapter

Run jscodeshift on Vue single file components

Install

npm install vue-jscodeshift-adapter -D

Usage

The instructions below assume you're familiar with jscodeshift.

1. Create a wrapped transform function

This module wraps the transform() function, enabling it to run on Vue single file components (sfc).

The two main use cases are:

  • a. Modify one or more parts of an sfc
  • b. Run a codemod on just the <script> part of an sfc
a. Modify a sfc's script, template or style

my-transform.js:

const adapt = require('vue-jscodeshift-adapter');

function myTransform(fileInfo, api, options) {
  const script   = fileInfo.script.content;
  const template = fileInfo.template.content;
  const style    = fileInfo.style.content;

  // (transform source somehow)

  fileInfo.script.content   = newScript;
  fileInfo.template.content = newTemplate;
  fileInfo.style.content    = newStyle;
}

module.exports = adapt(myTransform);
b. Run an existing codemod on sfc

After wrapping, you can run jscodeshift-compatible codemods on your sfc because

  1. fileInfo.source will be the content of the sfc's <script>
  2. If transform() returns a string, that string becomes the content of <script>

my-transform.js:

const adapt = require('vue-jscodeshift-adapter');
const someCodemod = require('some-codemod');

module.exports = adapt(someCodemod);

2. Run jscodeshift

$ jscodeshift <path> -t my-transform.js --extensions vue

See jscodeshift readme for more info.

License

MIT

Keywords

FAQs

Package last updated on 03 Mar 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc