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 - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

.travis.yml

5

CHANGELOG.md
# Change Log
## [1.2.0] - 2018-03-18
### Added
- Ability to run on directory containing js and vue files.
## [1.1.1] - 2018-03-13

@@ -4,0 +9,0 @@ ### Fixed

4

index.js

@@ -12,2 +12,6 @@ const compiler = require('vue-template-compiler');

return function newTransform(fileInfo, api, options) {
if (!fileInfo.path.endsWith('.vue')) {
return transform(fileInfo, api, options);
}
const sfcDescriptor = compiler.parseComponent(fileInfo.source);

@@ -14,0 +18,0 @@ const $ = cheerio.load(fileInfo.source);

2

package.json
{
"name": "vue-jscodeshift-adapter",
"version": "1.1.1",
"version": "1.2.0",
"description": "Run jscodeshift on Vue single file components",

@@ -5,0 +5,0 @@ "main": "index.js",

# vue-jscodeshift-adapter
[![Build Status](https://travis-ci.org/psalaets/vue-jscodeshift-adapter.svg?branch=master)](https://travis-ci.org/psalaets/vue-jscodeshift-adapter)
Run [jscodeshift](https://github.com/facebook/jscodeshift) on Vue single file components

@@ -15,13 +17,18 @@

### 1. Create a wrapped transform function
The two main use cases for `vue-jscodeshift-adapter` are:
This module wraps the `transform()` function, enabling it to run on Vue single file components (sfc).
1. Run a codemod on some `.js` and/or `.vue` files
2. Modify one or more parts of some `.vue` files
The two main use cases are:
### Use case 1: Run a codemod on some `.js` and/or `.vue` files
- a. Modify one or more parts of an sfc
- b. Run a codemod on just the `<script>` part of an sfc
|When transforming|`fileInfo.source` will be|
|-----------------|-------------------------|
|`.js` file | the contents of the file|
|`.vue` file | the contents of `<script>`|
#### a. Modify a sfc's script, template or style
The source file will be updated appropriately based on the return value of your `transform()`.
#### 1a. Create wrapped transform function
`my-transform.js`:

@@ -31,3 +38,26 @@

const adapt = require('vue-jscodeshift-adapter');
const someCodemod = require('some-codemod');
module.exports = adapt(someCodemod);
```
#### 1b. Run jscodeshift
```
$ jscodeshift <path> -t my-transform.js --extensions vue,js
```
See [jscodeshift readme](https://github.com/facebook/jscodeshift#usage-cli) for more info.
### Use case 2: Modify one or more parts of some `.vue` files
Modify a sfc's script, template or style.
#### 2a. Create wrapped transform function
`my-transform.js`:
```js
const adapt = require('vue-jscodeshift-adapter');
function myTransform(fileInfo, api, options) {

@@ -48,21 +78,5 @@ const script = fileInfo.script.content;

#### b. Run an existing codemod on sfc
#### 2b. Run jscodeshift
After wrapping, you can run [jscodeshift-compatible codemods](https://www.npmjs.com/search?q=codemod%20jscodeshift&page=1&ranking=optimal) 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`:
```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

@@ -69,0 +83,0 @@ ```

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