Socket
Socket
Sign inDemoInstall

@tramvai/tools-migrate

Package Overview
Dependencies
Maintainers
3
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tramvai/tools-migrate - npm Package Compare versions

Comparing version 0.6.3 to 0.6.5

48

lib/api.js

@@ -19,9 +19,9 @@ "use strict";

const transform_1 = require("./transform");
transform_1.register();
const log = logger_1.logger('tramvai-migrate');
(0, transform_1.register)();
const log = (0, logger_1.logger)('tramvai-migrate');
const getTramvaiJSONPath = (cwd) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
for (const path of constants_1.TRAMVAI_JSON_PATHS) {
const resolvedPath = path_1.resolve(cwd, path);
const resolvedPath = (0, path_1.resolve)(cwd, path);
// eslint-disable-next-line no-await-in-loop
if (yield fs_extra_1.pathExists(resolvedPath)) {
if (yield (0, fs_extra_1.pathExists)(resolvedPath)) {
return resolvedPath;

@@ -33,3 +33,3 @@ }

const createJsCodeShiftApi = (parser) => {
const jscodeshift = jscodeshift_1.withParser(parser);
const jscodeshift = (0, jscodeshift_1.withParser)(parser);
return {

@@ -44,4 +44,4 @@ jscodeshift,

const createFileInfo = (cwd, filepath) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const path = path_1.resolve(cwd, filepath);
const source = yield fs_extra_1.readFile(path, 'utf-8');
const path = (0, path_1.resolve)(cwd, filepath);
const source = yield (0, fs_extra_1.readFile)(path, 'utf-8');
return {

@@ -55,6 +55,6 @@ path,

const saveFileChanges = (fileInfo, write) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
if (!equal_1.default(fileInfo.source, fileInfo.originSource)) {
if (!(0, equal_1.default)(fileInfo.source, fileInfo.originSource)) {
yield write(fileInfo);
if (fileInfo.path !== fileInfo.originPath) {
yield fs_extra_1.remove(fileInfo.originPath);
yield (0, fs_extra_1.remove)(fileInfo.originPath);
}

@@ -65,14 +65,14 @@ }

const { source, originSource } = packageJson;
return (!equal_1.default(source.dependencies, originSource.dependencies) ||
!equal_1.default(source.devDependencies, originSource.devDependencies));
return (!(0, equal_1.default)(source.dependencies, originSource.dependencies) ||
!(0, equal_1.default)(source.devDependencies, originSource.devDependencies));
};
const createApi = (cwd) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d;
const packageJSONPath = path_1.resolve(cwd, 'package.json');
const tramvaiJSONPath = yield exports.getTramvaiJSONPath(cwd);
const packageJSONSource = yield fs_extra_1.readJSON(packageJSONPath).catch(nothing_1.default);
const tramvaiJSONSource = yield fs_extra_1.readJSON(tramvaiJSONPath).catch(nothing_1.default);
const packageJSONPath = (0, path_1.resolve)(cwd, 'package.json');
const tramvaiJSONPath = yield (0, exports.getTramvaiJSONPath)(cwd);
const packageJSONSource = yield (0, fs_extra_1.readJSON)(packageJSONPath).catch(nothing_1.default);
const tramvaiJSONSource = yield (0, fs_extra_1.readJSON)(tramvaiJSONPath).catch(nothing_1.default);
const packageJSON = {
source: packageJSONSource,
originSource: clone_1.default(packageJSONSource),
originSource: (0, clone_1.default)(packageJSONSource),
path: packageJSONPath,

@@ -83,3 +83,3 @@ originPath: packageJSONPath,

source: tramvaiJSONSource,
originSource: clone_1.default(tramvaiJSONSource),
originSource: (0, clone_1.default)(tramvaiJSONSource),
path: tramvaiJSONPath,

@@ -93,3 +93,3 @@ originPath: tramvaiJSONPath,

log.debug('ignorePattern:', ignorePattern);
const files = yield fast_glob_1.default(srcGlob, {
const files = yield (0, fast_glob_1.default)(srcGlob, {
cwd,

@@ -100,4 +100,4 @@ ignore: ignorePattern,

const jsonFilesInfo = {};
const codeShiftApiTs = exports.createJsCodeShiftApi('ts');
const codeShiftApiTsx = exports.createJsCodeShiftApi('tsx');
const codeShiftApiTs = (0, exports.createJsCodeShiftApi)('ts');
const codeShiftApiTsx = (0, exports.createJsCodeShiftApi)('tsx');
const api = {

@@ -111,3 +111,3 @@ packageJSON,

const fileInfo = (_e = filesInfo[filename]) !== null && _e !== void 0 ? _e : (yield createFileInfo(cwd, filename));
const extension = path_1.extname(fileInfo.path);
const extension = (0, path_1.extname)(fileInfo.path);
const codeShiftApi = extension === '.ts' ? codeShiftApiTs : codeShiftApiTsx;

@@ -131,8 +131,8 @@ try {

yield Promise.all([
p_map_1.default(Object.values(jsonFilesInfo), (fileInfo) => saveFileChanges(fileInfo, ({ path, source }) => fs_extra_1.writeJSON(path, source, { spaces: 2 }))),
p_map_1.default(Object.values(filesInfo), (fileInfo) => saveFileChanges(fileInfo, ({ path, source }) => fs_extra_1.writeFile(path, source)), { concurrency: os_1.cpus().length }),
(0, p_map_1.default)(Object.values(jsonFilesInfo), (fileInfo) => saveFileChanges(fileInfo, ({ path, source }) => (0, fs_extra_1.writeJSON)(path, source, { spaces: 2 }))),
(0, p_map_1.default)(Object.values(filesInfo), (fileInfo) => saveFileChanges(fileInfo, ({ path, source }) => (0, fs_extra_1.writeFile)(path, source)), { concurrency: (0, os_1.cpus)().length }),
]);
if (hasDepsChanges(packageJSON)) {
log.warn('Dependency has changed - run packages install');
const packageManager = package_manager_wrapper_1.resolvePackageManager({ rootDir: cwd });
const packageManager = (0, package_manager_wrapper_1.resolvePackageManager)({ rootDir: cwd });
yield packageManager.install();

@@ -139,0 +139,0 @@ }

@@ -16,10 +16,10 @@ "use strict";

};
const ciInfo = env_ci_1.default();
const ciInfo = (0, env_ci_1.default)();
const cwd = process.env.INIT_CWD || process.cwd();
const log = logger_1.logger('tramvai-migrate');
const log = (0, logger_1.logger)('tramvai-migrate');
logger_1.logger.enable('tramvai-migrate');
// eslint-disable-next-line max-statements
(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const { name: cwdPackageName } = yield fs_extra_1.readJSON(path_1.resolve(cwd, 'package.json')).catch(() => ({}));
const tramvaiJSONPath = yield api_1.getTramvaiJSONPath(cwd);
const { name: cwdPackageName } = yield (0, fs_extra_1.readJSON)((0, path_1.resolve)(cwd, 'package.json')).catch(() => ({}));
const tramvaiJSONPath = yield (0, api_1.getTramvaiJSONPath)(cwd);
// ignore the migration check in the tramvai repository,

@@ -36,3 +36,3 @@ // or is absent `tramvai.json`,

log.info('Checking migrations');
const files = yield fast_glob_1.default([
const files = yield (0, fast_glob_1.default)([
`${constants_1.TRAMVAI_BASE_PATH}*/__migrations__/*.js`,

@@ -50,5 +50,5 @@ `${constants_1.TRAMVAI_TINKOFF_BASE_PATH}*/__migrations__/*.js`,

log.debug('Migrations found');
const appliedFilename = path_1.resolve(cwd, constants_1.APPLIED_FILENAME);
yield fs_extra_1.ensureFile(appliedFilename);
let appliedInfo = yield fs_extra_1.readJSON(appliedFilename).catch(() => ({}));
const appliedFilename = (0, path_1.resolve)(cwd, constants_1.APPLIED_FILENAME);
yield (0, fs_extra_1.ensureFile)(appliedFilename);
let appliedInfo = yield (0, fs_extra_1.readJSON)(appliedFilename).catch(() => ({}));
let api;

@@ -64,3 +64,3 @@ let save;

];
const appliedMigrations = pathOr_1.default(migrationPath, [], appliedInfo);
const appliedMigrations = (0, pathOr_1.default)(migrationPath, [], appliedInfo);
if (!appliedMigrations.includes(fileInfo.name)) {

@@ -70,5 +70,5 @@ log.info(`Running migration '${fileInfo.name}' from module '${packageName}'`);

// eslint-disable-next-line no-await-in-loop
({ api, save } = yield api_1.createApi(cwd));
({ api, save } = yield (0, api_1.createApi)(cwd));
}
const migration = require(path_1.resolve(cwd, fileInfo.path));
const migration = require((0, path_1.resolve)(cwd, fileInfo.path));
try {

@@ -78,3 +78,3 @@ // eslint-disable-next-line no-await-in-loop

appliedMigrations.push(fileInfo.name);
appliedInfo = pathSet_1.default(migrationPath, appliedMigrations, appliedInfo);
appliedInfo = (0, pathSet_1.default)(migrationPath, appliedMigrations, appliedInfo);
}

@@ -88,3 +88,3 @@ catch (error) {

yield (save === null || save === void 0 ? void 0 : save());
yield fs_extra_1.writeJSON(appliedFilename, appliedInfo);
yield (0, fs_extra_1.writeJSON)(appliedFilename, appliedInfo);
log.info('Migrations successfully completed');

@@ -91,0 +91,0 @@ }))();

@@ -5,2 +5,3 @@ "use strict";

const tslib_1 = require("tslib");
/* eslint-disable jest/no-conditional-expect */
const api_1 = require("./api");

@@ -15,3 +16,3 @@ const constants_1 = require("./constants");

}, transformTests = {}, }) => {
const jsCodeShiftApi = api_1.createJsCodeShiftApi('tsx');
const jsCodeShiftApi = (0, api_1.createJsCodeShiftApi)('tsx');
let resolveWaitTransformers;

@@ -23,3 +24,3 @@ const waitForTransformers = new Promise((resolve) => {

for (const testName in transformTests) {
it(testName, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
it(`${testName}`, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
var _a, _b;

@@ -65,2 +66,3 @@ const { transformer, pathTransformer } = yield waitForTransformers;

exports.createApi = createApi;
/* eslint-enable jest/no-conditional-expect */
//# sourceMappingURL=testUtils.js.map

@@ -110,3 +110,3 @@ "use strict";

const val = imp.node.source.value;
return jscodeshift_5.importDeclaration(imp.value.specifiers, jscodeshift_5.literal(`${val}`.replace(regexp, `${to}$1`)));
return (0, jscodeshift_5.importDeclaration)(imp.value.specifiers, (0, jscodeshift_5.literal)(`${val}`.replace(regexp, `${to}$1`)));
});

@@ -130,10 +130,10 @@ return true;

shouldRename = specifier.imported.name === specifier.local.name;
return Object.assign(Object.assign({}, specifier), { imported: jscodeshift_2.identifier(to) });
return Object.assign(Object.assign({}, specifier), { imported: (0, jscodeshift_2.identifier)(to) });
}
return specifier;
});
return jscodeshift_5.importDeclaration(specifiers, imp.value.source);
return (0, jscodeshift_5.importDeclaration)(specifiers, imp.value.source);
});
if (shouldRename) {
this.find(jscodeshift_1.Identifier, { name: from }).replaceWith(jscodeshift_2.identifier(to));
this.find(jscodeshift_1.Identifier, { name: from }).replaceWith((0, jscodeshift_2.identifier)(to));
}

@@ -159,3 +159,3 @@ return true;

const val = exp.value.arguments[0].value;
return jscodeshift_4.callExpression(exp.value.callee, [jscodeshift_3.stringLiteral(`${val}`.replace(regexp, to))]);
return (0, jscodeshift_4.callExpression)(exp.value.callee, [(0, jscodeshift_3.stringLiteral)(`${val}`.replace(regexp, to))]);
});

@@ -162,0 +162,0 @@ return true;

@@ -7,3 +7,3 @@ "use strict";

const register = () => {
jscodeshift_1.registerMethods({
(0, jscodeshift_1.registerMethods)({
addImport: import_1.addImport,

@@ -10,0 +10,0 @@ removeImport: import_1.removeImport,

{
"name": "@tramvai/tools-migrate",
"version": "0.6.3",
"version": "0.6.5",
"description": "",

@@ -15,3 +15,3 @@ "main": "lib/index.js",

"dependencies": {
"@tinkoff/logger": "0.10.51",
"@tinkoff/logger": "0.10.53",
"@tinkoff/package-manager-wrapper": "0.1.3",

@@ -25,3 +25,3 @@ "@tinkoff/utils": "^2.1.2",

"recast": "^0.17.2",
"tslib": "^2.0.3"
"tslib": "^2.4.0"
},

@@ -28,0 +28,0 @@ "devDependencies": {

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

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