New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@korautils/alias-fixer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@korautils/alias-fixer - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

2

dist/index.js

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

import u from"fs";import i from"path";import w from"figlet";import*as j from"jsonc-parser";var b=t=>{console.log("-------------------------------------------------------"),console.log(t),console.log("-------------------------------------------------------"),console.log("Finding tsconfig file..."),console.log("-------------------------------------------------------");let s=$();if(!W(s)){console.log("ERROR: No se encontr\xF3 el archivo tsconfig.json o no se encontr\xF3 una configuraci\xF3n v\xE1lida"),console.log("Se finaliza la operaci\xF3n.");return}let n=i.resolve(process.cwd(),P("--dir","./")),r=P("--types","ts,tsx,jsx,js").split(","),e=h(s,"exclude",["node_modules"]);console.log("dir:",n),console.log("types:",r),console.log("exclude:",e);let o=R(n,r,e);S(o,s)};function S(t,s){let n=s.compilerOptions?.paths||{},r=i.resolve(process.cwd(),s.compilerOptions?.baseUrl||"./"),e=[];for(let o in n)if(Object.prototype.hasOwnProperty.call(n,o)){let f=n[o];e.push({alias:o.replace(/\/\*{1,2}(\*)?$/,""),folders:f.map(p=>i.join(process.cwd(),p.replace(/\/\*{1,2}(\*)?$/,"")))})}t.forEach(o=>{let f=u.readFileSync(o,"utf-8"),p=f.replace(/(import\s+.*?['"])(\.{1,2}\/.*?)(['"])/g,(c,l,g,F)=>{let y=i.resolve(i.dirname(o),g),O=I(g),v=i.dirname(o);for(let a=0;a<O;a++)v=i.dirname(v);if(!v.startsWith(r)||e.every(a=>!a.folders.some(m=>y.startsWith(m))))return c;let d=null;return e.forEach(a=>{a.folders.forEach(m=>{if(y.startsWith(m)){let T=i.relative(m,y),x=i.join(a.alias,T);(!d||x.length>d.relativeImportPath.length)&&(d={alias:a.alias,relativeImportPath:x})}})}),d?`${l}${h(d,"relativeImportPath")}${F}`:c});f!==p&&(console.log("Updated import in:",o),u.writeFileSync(o,p,"utf-8"))})}function I(t){let s=/\.\.\//g,n=t.match(s);return n?n.length:0}function R(t,s,n=[]){let r=[];function e(o){let f=u.readdirSync(o,{withFileTypes:!0}),p=n.map(c=>{let l=i.join(o,c.trim());return u.existsSync(l)?l:c.trim()});for(let c of f){let l=i.join(o,c.name);if(!p.some(g=>l.includes(g))){if(c.isDirectory())e(l);else if(c.isFile()){let g=i.extname(c.name).slice(1);s.includes(g)&&r.push(l)}}}}return e(t),r}function P(t,s="./"){let n=process.argv.slice(2),r=`${t}=`,e=n.find(o=>o.startsWith(r));return e?e.slice(r.length):s}var W=t=>{let s=h(t,"compilerOptions.baseUrl"),n=h(t,"compilerOptions.paths");return!(!t||!s||!n||Object.keys(n).filter(e=>e.startsWith("@/")).length==0)},$=()=>{let t=i.resolve(process.cwd(),"tsconfig.json");if(!u.existsSync(t))return;let s=u.readFileSync(t,"utf-8");return j.parse(s)};w("fix-imports",(t,s)=>{if(t){console.log("Algo sali\xF3 mal...",t);return}b(s)});function h(t,s,n){if(!t||typeof s!="string")return n;let r=s.split("."),e=t;for(let o of r)if(e&&typeof e=="object"&&o in e)e=e[o];else return n;return e}
import u from"fs";import i from"path";import w from"figlet";import*as j from"jsonc-parser";var b=t=>{console.log("-----------------------------------------------"),console.log(t),console.log("-----------------------------------------------"),console.log("*********** @korautils/alias-fixer ************"),console.log("-----------------------------------------------"),console.log("\u{1F50D} Finding tsconfig file...");let s=W();if(!R(s)){console.log("ERROR: No se encontr\xF3 el archivo tsconfig.json o no se encontr\xF3 una configuraci\xF3n v\xE1lida"),console.log("Se finaliza la operaci\xF3n.");return}let o=i.resolve(process.cwd(),x("--dir","./")),r=x("--types","ts,tsx,jsx,js").split(","),e=h(s,"exclude",["node_modules"]);console.log("\u{1F5C2}\uFE0F dir:",o),console.log("\u26AA\uFE0F types:",r),console.log("\u{1F6AB} exclude:",e);let n=I(o,r,e);k(n,s),console.log("-----------------------------------------------"),console.log("\u2705 Process completed successfully."),console.log("-----------------------------------------------")};function k(t,s){let o=s.compilerOptions?.paths||{},r=i.resolve(process.cwd(),s.compilerOptions?.baseUrl||"./"),e=[];for(let n in o)if(Object.prototype.hasOwnProperty.call(o,n)){let f=o[n];e.push({alias:n.replace(/\/\*{1,2}(\*)?$/,""),folders:f.map(p=>i.join(process.cwd(),p.replace(/\/\*{1,2}(\*)?$/,"")))})}t.forEach(n=>{let f=u.readFileSync(n,"utf-8"),p=f.replace(/(import\s+.*?['"])(\.{1,2}\/.*?)(['"])/g,(c,l,g,F)=>{let y=i.resolve(i.dirname(n),g),O=S(g),v=i.dirname(n);for(let a=0;a<O;a++)v=i.dirname(v);if(!v.startsWith(r)||e.every(a=>!a.folders.some(m=>y.startsWith(m))))return c;let d=null;return e.forEach(a=>{a.folders.forEach(m=>{if(y.startsWith(m)){let T=i.relative(m,y),P=i.join(a.alias,T);(!d||P.length>d.relativeImportPath.length)&&(d={alias:a.alias,relativeImportPath:P})}})}),d?`${l}${h(d,"relativeImportPath")}${F}`:c});f!==p&&(console.log("Updated import in:",n),u.writeFileSync(n,p,"utf-8"))})}function S(t){let s=/\.\.\//g,o=t.match(s);return o?o.length:0}function I(t,s,o=[]){let r=[];function e(n){let f=u.readdirSync(n,{withFileTypes:!0}),p=o.map(c=>{let l=i.join(n,c.trim());return u.existsSync(l)?l:c.trim()});for(let c of f){let l=i.join(n,c.name);if(!p.some(g=>l.includes(g))){if(c.isDirectory())e(l);else if(c.isFile()){let g=i.extname(c.name).slice(1);s.includes(g)&&r.push(l)}}}}return e(t),r}function x(t,s="./"){let o=process.argv.slice(2),r=`${t}=`,e=o.find(n=>n.startsWith(r));return e?e.slice(r.length):s}var R=t=>{let s=h(t,"compilerOptions.baseUrl"),o=h(t,"compilerOptions.paths");return!(!t||!s||!o||Object.keys(o).filter(e=>e.startsWith("@/")).length==0)},W=()=>{let t=i.resolve(process.cwd(),"tsconfig.json");if(!u.existsSync(t))return;let s=u.readFileSync(t,"utf-8");return j.parse(s)};w("kora-utils",(t,s)=>{if(t){console.log("Algo sali\xF3 mal...",t);return}b(s)});function h(t,s,o){if(!t||typeof s!="string")return o;let r=s.split("."),e=t;for(let n of r)if(e&&typeof e=="object"&&n in e)e=e[n];else return o;return e}
//# sourceMappingURL=index.js.map
{
"name": "@korautils/alias-fixer",
"version": "1.0.7",
"version": "1.0.8",
"description": "A development utility to automatically fix relative imports by replacing them with path aliases defined in your tsconfig.json. Ideal for streamlining large codebases with consistent import paths.",

@@ -5,0 +5,0 @@ "type": "module",

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