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.2.0 to 2.0.0

src/index.js

12

CHANGELOG.md
# Change Log
## [2.0.0] - 2018-03-25
### Breaking Change
The "modify any block of a vue component" use case is temporarily not supported until the API is figured out.
As of 2.0.0, this module can only
- transform js files
- transform the `<script>` block of vue files
## [1.2.0] - 2018-03-18
### Added
- Ability to run on directory containing js and vue files.
- Ability to run on directory containing js and vue files ([#4](https://github.com/psalaets/vue-jscodeshift-adapter/issues/4)).

@@ -8,0 +18,0 @@ ## [1.1.1] - 2018-03-13

4

package.json
{
"name": "vue-jscodeshift-adapter",
"version": "1.2.0",
"version": "2.0.0",
"description": "Run jscodeshift on Vue single file components",
"main": "index.js",
"main": "src/index.js",
"scripts": {

@@ -7,0 +7,0 @@ "test": "jest"

@@ -17,9 +17,4 @@ # vue-jscodeshift-adapter

The two main use cases for `vue-jscodeshift-adapter` are:
### Run a codemod on some `.js` and/or `.vue` files
1. Run a codemod on some `.js` and/or `.vue` files
2. Modify one or more parts of some `.vue` files
### Use case 1: Run a codemod on some `.js` and/or `.vue` files
|When transforming|`fileInfo.source` will be|

@@ -32,4 +27,6 @@ |-----------------|-------------------------|

#### 1a. Create wrapped transform function
*If `.vue` file doesn't have a `<script>`, your `transform()` will not be called and the source file will not be changed.*
#### 1. Create wrapped transform function
`my-transform.js`:

@@ -44,3 +41,3 @@

#### 1b. Run jscodeshift
#### 2. Run jscodeshift

@@ -51,40 +48,6 @@ ```

See [jscodeshift readme](https://github.com/facebook/jscodeshift#usage-cli) for more info.
See [jscodeshift readme](https://github.com/facebook/jscodeshift#usage-cli) for more info on jscodeshift CLI.
### 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) {
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);
```
#### 2b. Run jscodeshift
```
$ jscodeshift <path> -t my-transform.js --extensions vue
```
See [jscodeshift readme](https://github.com/facebook/jscodeshift#usage-cli) for more info.
## License
MIT

@@ -1,2 +0,2 @@

const adapt = require('../../../index');
const adapt = require('../../../src/index');
const describe = require('jscodeshift-helper').describe;

@@ -3,0 +3,0 @@

@@ -1,16 +0,6 @@

const adapt = require('../../../index');
const adapt = require('../../../src/index');
module.exports = adapt((fileInfo, api, options) => {
fileInfo.template.content = `
<span>
<!-- this is new -->
asdf
</span>
`;
fileInfo.script.content = `
// this is new` + fileInfo.script.content;
fileInfo.style.content = `
/* this is new too */` + fileInfo.style.content;
return `
// this is new` + fileInfo.source;
});

@@ -36,6 +36,10 @@ const { testTransform } = require('../test-helper');

<template>
<span>
<!-- this is new -->
asdf
</span>
<div class="widget">
<template>
<div>1</div>
<div>2</div>
</template>
<script>var a = 1;</script>
<style>.widget {background-color: green;}</style>
</div>
</template>

@@ -56,3 +60,2 @@

<style>
/* this is new too */
.widget {

@@ -59,0 +62,0 @@ color: red;

@@ -1,7 +0,7 @@

const adapt = require('../../../index');
const adapt = require('../../../src/index');
module.exports = adapt((fileInfo, api, options) => {
fileInfo.script.content = `
return `
export default {};
`;
});

@@ -1,2 +0,2 @@

const adapt = require('../../../index');
const adapt = require('../../../src/index');

@@ -3,0 +3,0 @@ module.exports = adapt((fileInfo, api, options) => {

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