jscodeshift
Advanced tools
Comparing version 0.6.4 to 0.7.0
#!/usr/bin/env node | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -11,0 +9,0 @@ |
@@ -7,2 +7,10 @@ # Changelog | ||
## [0.7.0] 2019-12-11 | ||
### Changed | ||
- Moved from BSD to MIT license | ||
### Fixed | ||
- No longer throw an error when calling jscodeshift on a non-existent path (#334, @threepointone) | ||
- Preserve the original file extension in remote files (#317, @samselikoff) | ||
## [0.6.4] 2019-04-30 | ||
@@ -9,0 +17,0 @@ ### Changed |
@@ -45,4 +45,4 @@ # Contributing to jscodeshift | ||
## License | ||
By contributing to jscodeshift, you agree that your contributions will be licensed | ||
under its BSD license. | ||
### License | ||
jscodeshift is [MIT licensed](./LICENSE). |
@@ -1,8 +0,6 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -9,0 +7,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -144,3 +142,3 @@ | ||
process.stderr.write('Skipping path ' + file + ' which does not exist. \n'); | ||
resolve(); | ||
resolve([]); | ||
return; | ||
@@ -188,3 +186,4 @@ } | ||
.on('end', () => { | ||
temp.open('jscodeshift', (err, info) => { | ||
const ext = path.extname(transformFile); | ||
temp.open({ prefix: 'jscodeshift', suffix: ext }, (err, info) => { | ||
if (err) return reject(err); | ||
@@ -191,0 +190,0 @@ fs.write(info.fd, contents, function (err) { |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
/** | ||
* Copyright (c) 2016-present, Facebook, Inc. | ||
* All rights reserved. | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -17,3 +15,3 @@ | ||
function runInlineTest(module, options, input, expectedOutput) { | ||
function applyTransform(module, options, input, testOptions = {}) { | ||
// Handle ES6 modules using default export for the transform | ||
@@ -25,4 +23,4 @@ const transform = module.default ? module.default : module; | ||
let jscodeshift = require('./core'); | ||
if (module.parser) { | ||
jscodeshift = jscodeshift.withParser(module.parser); | ||
if (testOptions.parser || module.parser) { | ||
jscodeshift = jscodeshift.withParser(testOptions.parser || module.parser); | ||
} | ||
@@ -38,6 +36,31 @@ | ||
); | ||
expect((output || '').trim()).toEqual(expectedOutput.trim()); | ||
return (output || '').trim(); | ||
} | ||
exports.applyTransform = applyTransform; | ||
function runSnapshotTest(module, options, input) { | ||
const output = applyTransform(module, options, input); | ||
expect(output).toMatchSnapshot(); | ||
return output; | ||
} | ||
exports.runSnapshotTest = runSnapshotTest; | ||
function runInlineTest(module, options, input, expectedOutput, testOptions) { | ||
const output = applyTransform(module, options, input, testOptions); | ||
expect(output).toEqual(expectedOutput.trim()); | ||
return output; | ||
} | ||
exports.runInlineTest = runInlineTest; | ||
function extensionForParser(parser) { | ||
switch (parser) { | ||
case 'ts': | ||
case 'tsx': | ||
return parser; | ||
default: | ||
return 'js' | ||
} | ||
} | ||
/** | ||
@@ -62,3 +85,3 @@ * Utility function to run a jscodeshift script within a unit test. This makes | ||
*/ | ||
function runTest(dirName, transformName, options, testFilePrefix) { | ||
function runTest(dirName, transformName, options, testFilePrefix, testOptions = {}) { | ||
if (!testFilePrefix) { | ||
@@ -68,7 +91,8 @@ testFilePrefix = transformName; | ||
const extension = extensionForParser(testOptions.parser) | ||
const fixtureDir = path.join(dirName, '..', '__testfixtures__'); | ||
const inputPath = path.join(fixtureDir, testFilePrefix + '.input.js'); | ||
const inputPath = path.join(fixtureDir, testFilePrefix + `.input.${extension}`); | ||
const source = fs.readFileSync(inputPath, 'utf8'); | ||
const expectedOutput = fs.readFileSync( | ||
path.join(fixtureDir, testFilePrefix + '.output.js'), | ||
path.join(fixtureDir, testFilePrefix + `.output.${extension}`), | ||
'utf8' | ||
@@ -81,3 +105,3 @@ ); | ||
source | ||
}, expectedOutput); | ||
}, expectedOutput, testOptions); | ||
} | ||
@@ -90,3 +114,3 @@ exports.runTest = runTest; | ||
*/ | ||
function defineTest(dirName, transformName, options, testFilePrefix) { | ||
function defineTest(dirName, transformName, options, testFilePrefix, testOptions) { | ||
const testName = testFilePrefix | ||
@@ -97,3 +121,3 @@ ? `transforms correctly using "${testFilePrefix}" data` | ||
it(testName, () => { | ||
runTest(dirName, transformName, options, testFilePrefix); | ||
runTest(dirName, transformName, options, testFilePrefix, testOptions); | ||
}); | ||
@@ -112,1 +136,10 @@ }); | ||
exports.defineInlineTest = defineInlineTest; | ||
function defineSnapshotTest(module, options, input, testName) { | ||
it(testName || 'transforms correctly', () => { | ||
runSnapshotTest(module, options, { | ||
source: input | ||
}); | ||
}); | ||
} | ||
exports.defineSnapshotTest = defineSnapshotTest; |
@@ -1,8 +0,6 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -9,0 +7,0 @@ |
@@ -1,8 +0,6 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -9,0 +7,0 @@ |
@@ -1,8 +0,6 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -9,0 +7,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
12
index.js
@@ -1,11 +0,9 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
module.exports = require('./src/core'); |
{ | ||
"name": "jscodeshift", | ||
"version": "0.6.4", | ||
"version": "0.7.0", | ||
"description": "A toolkit for JavaScript codemods", | ||
@@ -25,3 +25,2 @@ "repository": { | ||
"author": "Felix Kling", | ||
"license": "BSD-3-Clause", | ||
"dependencies": { | ||
@@ -43,3 +42,3 @@ "@babel/core": "^7.1.6", | ||
"node-dir": "^0.1.17", | ||
"recast": "^0.16.1", | ||
"recast": "^0.18.1", | ||
"temp": "^0.8.1", | ||
@@ -46,0 +45,0 @@ "write-file-atomic": "^2.3.0" |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -366,2 +366,3 @@ # jscodeshift [![Build Status](https://travis-ci.org/facebook/jscodeshift.svg?branch=master)](https://travis-ci.org/facebook/jscodeshift) | ||
This results in a directory structure like this: | ||
``` | ||
@@ -374,5 +375,10 @@ /MyTransform.js | ||
To define a test, use `defineTest` or `defineInlineTest` from the `testUtils` module. A simple example is bundled in the [sample directory](sample). | ||
A simple example of unit tests is bundled in the [sample directory](sample). | ||
The `testUtils` module exposes a number of useful helpers for unit testing. | ||
#### `defineTest` | ||
Defines a Jest/Jasmine test for a jscodeshift transform which depends on fixtures | ||
```js | ||
@@ -384,3 +390,5 @@ jest.autoMockOff(); | ||
An alternate fixture filename can be provided as the fourth argument to `defineTest`. This also means that multiple test fixtures can be provided: | ||
An alternate fixture filename can be provided as the fourth argument to `defineTest`. | ||
This also means that multiple test fixtures can be provided: | ||
```js | ||
@@ -390,10 +398,45 @@ defineTest(__dirname, 'MyTransform', null, 'FirstFixture'); | ||
``` | ||
This will run two tests: One for `__testfixtures__/FirstFixture.input.js` and one for `__testfixtures__/SecondFixture.input.js` | ||
This will run two tests: | ||
- `__testfixtures__/FirstFixture.input.js` | ||
- `__testfixtures__/SecondFixture.input.js` | ||
#### `defineInlineTest` | ||
Defines a Jest/Jasmine test suite for a jscodeshift transform which accepts inline values | ||
This is a more flexible alternative to `defineTest`, as this allows to also provide options to your transform | ||
```js | ||
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest; | ||
const transform = require('../myTransform'); | ||
defineInlineTest(transform, {}, 'input', 'expected output', 'test name (optional)'); | ||
const transformOptions = {}; | ||
defineInlineTest(transform, transformOptions, 'input', 'expected output', 'test name (optional)'); | ||
``` | ||
#### `defineSnapshotTest` | ||
Similar to `defineInlineTest` but instead of requiring an output value, it uses Jest's `toMatchSnapshot()` | ||
```js | ||
const defineSnapshotTest = require('jscodeshift/dist/testUtils').defineSnapshotTest; | ||
const transform = require('../myTransform'); | ||
const transformOptions = {}; | ||
defineSnapshotTest(transform, transformOptions, 'input', 'test name (optional)'); | ||
``` | ||
For more information on snapshots, check out [Jest's docs](https://jestjs.io/docs/en/snapshot-testing) | ||
#### `applyTransform` | ||
Executes your transform using the options and the input given and returns the result. | ||
This function is used internally by the other helpers, but it can prove useful in other cases. | ||
```js | ||
const applyTransform = require('jscodeshift/dist/testUtils').applyTransform; | ||
const transform = require('../myTransform'); | ||
const transformOptions = {}; | ||
const output = applyTransform(transform, transformOptions, 'input'); | ||
``` | ||
### Example Codemods | ||
@@ -409,6 +452,2 @@ | ||
### Support | ||
* Discord - [Reactiflux](http://www.reactiflux.com/) | ||
[npm]: https://www.npmjs.com/ | ||
@@ -415,0 +454,0 @@ [Mozilla Parser API]: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API |
@@ -1,8 +0,6 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -9,0 +7,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -144,3 +142,3 @@ | ||
process.stderr.write('Skipping path ' + file + ' which does not exist. \n'); | ||
resolve(); | ||
resolve([]); | ||
return; | ||
@@ -188,3 +186,4 @@ } | ||
.on('end', () => { | ||
temp.open('jscodeshift', (err, info) => { | ||
const ext = path.extname(transformFile); | ||
temp.open({ prefix: 'jscodeshift', suffix: ext }, (err, info) => { | ||
if (err) return reject(err); | ||
@@ -191,0 +190,0 @@ fs.write(info.fd, contents, function (err) { |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
/** | ||
* Copyright (c) 2016-present, Facebook, Inc. | ||
* All rights reserved. | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -17,3 +15,3 @@ | ||
function runInlineTest(module, options, input, expectedOutput) { | ||
function applyTransform(module, options, input, testOptions = {}) { | ||
// Handle ES6 modules using default export for the transform | ||
@@ -25,4 +23,4 @@ const transform = module.default ? module.default : module; | ||
let jscodeshift = require('./core'); | ||
if (module.parser) { | ||
jscodeshift = jscodeshift.withParser(module.parser); | ||
if (testOptions.parser || module.parser) { | ||
jscodeshift = jscodeshift.withParser(testOptions.parser || module.parser); | ||
} | ||
@@ -38,6 +36,31 @@ | ||
); | ||
expect((output || '').trim()).toEqual(expectedOutput.trim()); | ||
return (output || '').trim(); | ||
} | ||
exports.applyTransform = applyTransform; | ||
function runSnapshotTest(module, options, input) { | ||
const output = applyTransform(module, options, input); | ||
expect(output).toMatchSnapshot(); | ||
return output; | ||
} | ||
exports.runSnapshotTest = runSnapshotTest; | ||
function runInlineTest(module, options, input, expectedOutput, testOptions) { | ||
const output = applyTransform(module, options, input, testOptions); | ||
expect(output).toEqual(expectedOutput.trim()); | ||
return output; | ||
} | ||
exports.runInlineTest = runInlineTest; | ||
function extensionForParser(parser) { | ||
switch (parser) { | ||
case 'ts': | ||
case 'tsx': | ||
return parser; | ||
default: | ||
return 'js' | ||
} | ||
} | ||
/** | ||
@@ -62,3 +85,3 @@ * Utility function to run a jscodeshift script within a unit test. This makes | ||
*/ | ||
function runTest(dirName, transformName, options, testFilePrefix) { | ||
function runTest(dirName, transformName, options, testFilePrefix, testOptions = {}) { | ||
if (!testFilePrefix) { | ||
@@ -68,7 +91,8 @@ testFilePrefix = transformName; | ||
const extension = extensionForParser(testOptions.parser) | ||
const fixtureDir = path.join(dirName, '..', '__testfixtures__'); | ||
const inputPath = path.join(fixtureDir, testFilePrefix + '.input.js'); | ||
const inputPath = path.join(fixtureDir, testFilePrefix + `.input.${extension}`); | ||
const source = fs.readFileSync(inputPath, 'utf8'); | ||
const expectedOutput = fs.readFileSync( | ||
path.join(fixtureDir, testFilePrefix + '.output.js'), | ||
path.join(fixtureDir, testFilePrefix + `.output.${extension}`), | ||
'utf8' | ||
@@ -81,3 +105,3 @@ ); | ||
source | ||
}, expectedOutput); | ||
}, expectedOutput, testOptions); | ||
} | ||
@@ -90,3 +114,3 @@ exports.runTest = runTest; | ||
*/ | ||
function defineTest(dirName, transformName, options, testFilePrefix) { | ||
function defineTest(dirName, transformName, options, testFilePrefix, testOptions) { | ||
const testName = testFilePrefix | ||
@@ -97,3 +121,3 @@ ? `transforms correctly using "${testFilePrefix}" data` | ||
it(testName, () => { | ||
runTest(dirName, transformName, options, testFilePrefix); | ||
runTest(dirName, transformName, options, testFilePrefix, testOptions); | ||
}); | ||
@@ -112,1 +136,10 @@ }); | ||
exports.defineInlineTest = defineInlineTest; | ||
function defineSnapshotTest(module, options, input, testName) { | ||
it(testName || 'transforms correctly', () => { | ||
runSnapshotTest(module, options, { | ||
source: input | ||
}); | ||
}); | ||
} | ||
exports.defineSnapshotTest = defineSnapshotTest; |
@@ -1,8 +0,6 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -9,0 +7,0 @@ |
@@ -1,8 +0,6 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -9,0 +7,0 @@ |
@@ -1,8 +0,6 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -9,0 +7,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
@@ -1,9 +0,7 @@ | ||
/* | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
@@ -10,0 +8,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
453
1337955
95
5458
7
+ Addedast-types@0.13.3(transitive)
+ Addedrecast@0.18.10(transitive)
- Removedast-types@0.11.7(transitive)
- Removedrecast@0.16.2(transitive)
Updatedrecast@^0.18.1