Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@codeshift/initializer

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codeshift/initializer - npm Package Compare versions

Comparing version
0.1.8
to
0.1.9
+13
template/jest.config.js
module.exports = {
transform: {
'^.+\\.ts$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js'],
testRegex: '^.+\\.spec\\.(tsx|ts|js)$',
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json',
},
},
testPathIgnorePatterns: ['/node_modules/'],
};

Sorry, the diff of this file is not supported yet

import { applyTransform } from '@codeshift/test-utils';
import * as transformer from './transform';
describe('<% packageName %><% seperator %><% transform %> transform', () => {
it('should transform correctly', () => {
const result = applyTransform(
transformer,
`
import foo from '<% packageName %>';
console.log(foo);
`,
{ parser: 'tsx' },
);
expect(result).toMatchInlineSnapshot();
});
});
import { API, FileInfo, Options } from 'jscodeshift';
export default function transformer(
file: FileInfo,
{ jscodeshift: j }: API,
options: Options,
) {
const source = j(file.source);
/**
* Early exit condition
* -----
* It is often good practice to exit early and return the original source file
* if it does not contain code relevant to the codemod.
* See this page for more information:
* https://codeshiftcommunity.github.io/CodeshiftCommunity/docs/your-first-codemod#output
*/
if (/* Some condition here */ true) {
return file.source;
}
/**
* Codemod logic goes here 👇
* -----
* This is where the core logic for your codemod will go,
* consider grouping specific actions into 'motions' and running them in sequence
*
* See this page for more information:
* https://codeshiftcommunity.github.io/CodeshiftCommunity/docs/authoring#motions
*/
source.findVariableDeclarators('foo').renameTo('bar');
/**
* Return your modified AST here 👇
* -----
* This is where your modified AST will be transformed back into a string
* and written back to the file.
*/
return source.toSource(options.printOptions);
}
+7
-0
# @codeshift/initializer
## 0.1.9
### Patch Changes
- 427405c: Fixed a bug where npmignore in the template directory was being ignored my npm (hehe). This has now been moved into a static string as part of the main pacakge
- 49b7bcb: Usage path module over string concatinations for better cross OS support
## 0.1.8

@@ -4,0 +11,0 @@

+16
-10

@@ -10,2 +10,3 @@ 'use strict';

var package_json = require('@codeshift/utils/package.json');
var package_json$1 = require('@codeshift/test-utils/package.json');

@@ -53,7 +54,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }

'@codeshift/utils': "^".concat(package_json.version),
'@codeshift/test-utils': '*',
'@codeshift/test-utils': "^".concat(package_json$1.version),
'@types/node': '^16.11.0',
'@types/jest': '^26.0.15',
jest: '^26.6.0',
jscodeshift: '^0.12.0',
jscodeshift: '^0.13.1',
prettier: '^1.16.4',

@@ -66,2 +67,6 @@ 'ts-jest': '^26.4.4',

function getNpmIgnore() {
return "src/\n**/__test__\n**/*.spec.(ts|js)\n.vscode\njest.config.js\n";
}
function getConfig(packageName, transform, preset) {

@@ -102,5 +107,5 @@ return "module.exports = {\n maintainers: [],\n target: [],\n description: 'Codemods for ".concat(packageName, "',\n transforms: {").concat(transform ? "'".concat(transform, "': require.resolve('./").concat(transform, "/transform'),") : '', "},\n presets: {").concat(preset ? "'".concat(preset, "': require.resolve('./").concat(preset, "/transform'),") : '', "},\n};\n");

var isReduced = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var basePath = "".concat(targetPath, "/").concat(packageName.replace('/', '__'));
var configPath = "".concat(basePath).concat(!isReduced ? '/src' : '', "/codeshift.config.js");
fs__default['default'].copySync("".concat(__dirname, "/../template").concat(isReduced ? '/src' : ''), basePath, {
var basePath = path__default['default'].join(targetPath, packageName.replace('/', '__'));
var configPath = path__default['default'].join(basePath, !isReduced ? 'src' : '', 'codeshift.config.js');
fs__default['default'].copySync(path__default['default'].join(__dirname, '..', 'template', isReduced ? 'src' : ''), basePath, {
filter: src => !src.includes('src/codemod')

@@ -111,2 +116,3 @@ });

fs__default['default'].writeFileSync(path__default['default'].join(basePath, 'package.json'), getPackageJson(packageName));
fs__default['default'].writeFileSync(path__default['default'].join(basePath, '.npmignore'), getNpmIgnore());
}

@@ -126,5 +132,5 @@

var basePath = "".concat(targetPath, "/").concat(packageName.replace('/', '__'));
var transformPath = "".concat(basePath).concat(!isReduced ? '/src' : '', "/").concat(id);
var configPath = "".concat(basePath).concat(!isReduced ? '/src' : '', "/codeshift.config.js");
var basePath = path__default['default'].join(targetPath, packageName.replace('/', '__'));
var transformPath = path__default['default'].join(basePath, !isReduced ? 'src' : '', id);
var configPath = path__default['default'].join(basePath, !isReduced ? 'src' : '', 'codeshift.config.js');

@@ -135,4 +141,4 @@ if (fs__default['default'].existsSync(transformPath)) {

fs__default['default'].copySync("".concat(__dirname, "/../template").concat(isReduced ? '/src' : ''), basePath);
fs__default['default'].renameSync("".concat(basePath).concat(!isReduced ? '/src' : '', "/codemod"), transformPath);
fs__default['default'].copySync(path__default['default'].join(__dirname, '..', 'template', isReduced ? 'src' : ''), basePath);
fs__default['default'].renameSync(path__default['default'].join(basePath, !isReduced ? 'src' : '', 'codemod'), transformPath);
var testFilePath = path__default['default'].join(transformPath, 'transform.spec.ts');

@@ -139,0 +145,0 @@ var testFile = fs__default['default'].readFileSync(testFilePath, 'utf8').replace('<% packageName %>', packageName).replace('<% seperator %>', type === 'version' ? '@' : '#').replace('<% transform %>', id || '');

@@ -10,2 +10,3 @@ 'use strict';

var package_json = require('@codeshift/utils/package.json');
var package_json$1 = require('@codeshift/test-utils/package.json');

@@ -53,7 +54,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }

'@codeshift/utils': "^".concat(package_json.version),
'@codeshift/test-utils': '*',
'@codeshift/test-utils': "^".concat(package_json$1.version),
'@types/node': '^16.11.0',
'@types/jest': '^26.0.15',
jest: '^26.6.0',
jscodeshift: '^0.12.0',
jscodeshift: '^0.13.1',
prettier: '^1.16.4',

@@ -66,2 +67,6 @@ 'ts-jest': '^26.4.4',

function getNpmIgnore() {
return "src/\n**/__test__\n**/*.spec.(ts|js)\n.vscode\njest.config.js\n";
}
function getConfig(packageName, transform, preset) {

@@ -102,5 +107,5 @@ return "module.exports = {\n maintainers: [],\n target: [],\n description: 'Codemods for ".concat(packageName, "',\n transforms: {").concat(transform ? "'".concat(transform, "': require.resolve('./").concat(transform, "/transform'),") : '', "},\n presets: {").concat(preset ? "'".concat(preset, "': require.resolve('./").concat(preset, "/transform'),") : '', "},\n};\n");

var isReduced = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var basePath = "".concat(targetPath, "/").concat(packageName.replace('/', '__'));
var configPath = "".concat(basePath).concat(!isReduced ? '/src' : '', "/codeshift.config.js");
fs__default['default'].copySync("".concat(__dirname, "/../template").concat(isReduced ? '/src' : ''), basePath, {
var basePath = path__default['default'].join(targetPath, packageName.replace('/', '__'));
var configPath = path__default['default'].join(basePath, !isReduced ? 'src' : '', 'codeshift.config.js');
fs__default['default'].copySync(path__default['default'].join(__dirname, '..', 'template', isReduced ? 'src' : ''), basePath, {
filter: src => !src.includes('src/codemod')

@@ -111,2 +116,3 @@ });

fs__default['default'].writeFileSync(path__default['default'].join(basePath, 'package.json'), getPackageJson(packageName));
fs__default['default'].writeFileSync(path__default['default'].join(basePath, '.npmignore'), getNpmIgnore());
}

@@ -126,5 +132,5 @@

var basePath = "".concat(targetPath, "/").concat(packageName.replace('/', '__'));
var transformPath = "".concat(basePath).concat(!isReduced ? '/src' : '', "/").concat(id);
var configPath = "".concat(basePath).concat(!isReduced ? '/src' : '', "/codeshift.config.js");
var basePath = path__default['default'].join(targetPath, packageName.replace('/', '__'));
var transformPath = path__default['default'].join(basePath, !isReduced ? 'src' : '', id);
var configPath = path__default['default'].join(basePath, !isReduced ? 'src' : '', 'codeshift.config.js');

@@ -135,4 +141,4 @@ if (fs__default['default'].existsSync(transformPath)) {

fs__default['default'].copySync("".concat(__dirname, "/../template").concat(isReduced ? '/src' : ''), basePath);
fs__default['default'].renameSync("".concat(basePath).concat(!isReduced ? '/src' : '', "/codemod"), transformPath);
fs__default['default'].copySync(path__default['default'].join(__dirname, '..', 'template', isReduced ? 'src' : ''), basePath);
fs__default['default'].renameSync(path__default['default'].join(basePath, !isReduced ? 'src' : '', 'codemod'), transformPath);
var testFilePath = path__default['default'].join(transformPath, 'transform.spec.ts');

@@ -139,0 +145,0 @@ var testFile = fs__default['default'].readFileSync(testFilePath, 'utf8').replace('<% packageName %>', packageName).replace('<% seperator %>', type === 'version' ? '@' : '#').replace('<% transform %>', id || '');

{
"name": "@codeshift/initializer",
"version": "0.1.8",
"version": "0.1.9",
"main": "dist/codeshift-initializer.cjs.js",

@@ -9,2 +9,3 @@ "types": "dist/codeshift-initializer.cjs.d.ts",

"dependencies": {
"@codeshift/test-utils": "*",
"@codeshift/utils": "*",

@@ -11,0 +12,0 @@ "fs-extra": "^9.1.0",

@@ -6,2 +6,3 @@ import fs from 'fs-extra';

import { version as utilVersion } from '@codeshift/utils/package.json';
import { version as testUtilVersion } from '@codeshift/test-utils/package.json';

@@ -22,7 +23,7 @@ export function getPackageJson(packageName: string, version: string = '0.0.0') {

'@codeshift/utils': `^${utilVersion}`,
'@codeshift/test-utils': '*',
'@codeshift/test-utils': `^${testUtilVersion}`,
'@types/node': '^16.11.0',
'@types/jest': '^26.0.15',
jest: '^26.6.0',
jscodeshift: '^0.12.0',
jscodeshift: '^0.13.1',
prettier: '^1.16.4',

@@ -38,2 +39,11 @@ 'ts-jest': '^26.4.4',

function getNpmIgnore() {
return `src/
**/__test__
**/*.spec.(ts|js)
.vscode
jest.config.js
`;
}
function getConfig(packageName: string, transform?: string, preset?: string) {

@@ -108,10 +118,16 @@ return `module.exports = {

) {
const basePath = `${targetPath}/${packageName.replace('/', '__')}`;
const configPath = `${basePath}${
!isReduced ? '/src' : ''
}/codeshift.config.js`;
const basePath = path.join(targetPath, packageName.replace('/', '__'));
const configPath = path.join(
basePath,
!isReduced ? 'src' : '',
'codeshift.config.js',
);
fs.copySync(`${__dirname}/../template${isReduced ? '/src' : ''}`, basePath, {
filter: src => !src.includes('src/codemod'),
});
fs.copySync(
path.join(__dirname, '..', 'template', isReduced ? 'src' : ''),
basePath,
{
filter: src => !src.includes('src/codemod'),
},
);

@@ -123,2 +139,4 @@ if (!isReduced) {

);
fs.writeFileSync(path.join(basePath, '.npmignore'), getNpmIgnore());
}

@@ -142,7 +160,9 @@

const basePath = `${targetPath}/${packageName.replace('/', '__')}`;
const transformPath = `${basePath}${!isReduced ? '/src' : ''}/${id}`;
const configPath = `${basePath}${
!isReduced ? '/src' : ''
}/codeshift.config.js`;
const basePath = path.join(targetPath, packageName.replace('/', '__'));
const transformPath = path.join(basePath, !isReduced ? 'src' : '', id);
const configPath = path.join(
basePath,
!isReduced ? 'src' : '',
'codeshift.config.js',
);

@@ -153,5 +173,8 @@ if (fs.existsSync(transformPath)) {

fs.copySync(`${__dirname}/../template${isReduced ? '/src' : ''}`, basePath);
fs.copySync(
path.join(__dirname, '..', 'template', isReduced ? 'src' : ''),
basePath,
);
fs.renameSync(
`${basePath}${!isReduced ? '/src' : ''}/codemod`,
path.join(basePath, !isReduced ? 'src' : '', 'codemod'),
transformPath,

@@ -158,0 +181,0 @@ );