@solar-icons/codemod 2.0.0-beta.3 → 2.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.mjs +1 -1
  2. package/package.json +2 -1
package/dist/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{detectFrameworks as e}from"./detect.mjs";import{transformPackageJson as t}from"./package-json.mjs";import{collectAngularSelectorRenames as n,transformAngular as r,transformAngularTemplate as i}from"./transforms/angular.mjs";import{transformNuxt as a}from"./transforms/nuxt.mjs";import{transformReactNative as o}from"./transforms/react-native.mjs";import{transformReactPerf as s}from"./transforms/react-perf.mjs";import{transformReact as c}from"./transforms/react.mjs";import{transformSolid as l}from"./transforms/solid.mjs";import{transformSvelte as u}from"./transforms/svelte.mjs";import{transformVue as d}from"./transforms/vue.mjs";import{readFile as f,readdir as p,writeFile as m}from"node:fs/promises";import{extname as h,join as g,resolve as _}from"node:path";import{pathToFileURL as v}from"node:url";import*as y from"@clack/prompts";import{Command as b,InvalidArgumentError as x}from"commander";import S from"picocolors";const C=new Set([`.html`,`.js`,`.jsx`,`.mjs`,`.ts`,`.tsx`,`.svelte`,`.vue`]),w=new Set([`.git`,`.next`,`.nuxt`,`.svelte-kit`,`coverage`,`dist`,`node_modules`]);async function T(e){let t=await p(e,{withFileTypes:!0});return(await Promise.all(t.map(async t=>{let n=g(e,t.name);return t.isDirectory()?w.has(t.name)?[]:T(n):t.isFile()&&C.has(h(t.name))?[n]:[]}))).flat()}async function E({cwd:p,reactV1Mode:h=`static`,targetVersion:_,vueV1Mode:v=`static`,write:y=!1}){let b=await e(p),x=await T(p),S=new Map(await Promise.all(x.map(async e=>[e,await f(e,`utf8`)]))),C=new Map;for(let[e,t]of S)for(let[r,i]of n(t,e))C.set(r,i);let w=new Set(x),E=[],D=[];for(let e of x){let t=s(S.get(e),e),n=c(t.code,e,h),f=o(n.code,e),p=d(f.code,e,v),g=a(p.code,e),_=u(g.code,e),b=l(_.code,e),x=r(b.code,e,w),T=i(x.code,C);D.push(...t.diagnostics,...n.diagnostics,...f.diagnostics,...p.diagnostics,...g.diagnostics,..._.diagnostics,...b.diagnostics,...x.diagnostics,...T.diagnostics),!(!t.changed&&!n.changed&&!f.changed&&!p.changed&&!g.changed&&!_.changed&&!b.changed&&!x.changed&&!T.changed)&&(E.push(e),y&&await m(e,T.code))}let O=g(p,`package.json`),k=t(await f(O,`utf8`),_);return k.changed&&(E.push(O),y&&await m(O,k.code)),{changedFiles:E,diagnostics:D,detectedFrameworks:b}}function D(e){if(e===`static`||e===`dynamic`)return e;throw new x(`Expected either "static" or "dynamic".`)}function O(e){let t=e.file&&e.line?`${e.file}:${e.line}:${e.column??1}`:e.file,n=e.severity===`error`?S.red(`error`):S.yellow(`warning`);return`${S.dim(t??`solar-icons`)} ${n} ${S.bold(`[${e.code}]`)} ${e.message}`}function k(e,t){console.info(`${S.cyan(`Detected frameworks:`)} ${e.detectedFrameworks.join(`, `)||`none`}`),console.info(`${t?S.green(`Migrated`):S.cyan(`Would migrate`)} ${S.bold(String(e.changedFiles.length))} file(s).`);for(let t of e.diagnostics)console.warn(O(t));!t&&e.changedFiles.length>0&&console.info(S.dim(`Run again with --write to apply these changes.`))}async function A(e){let t=await y.select({message:`${e} migration strategy`,options:[{value:`static`,label:`Static (recommended)`,hint:`one style per import and the smallest bundle`},{value:`dynamic`,label:`Dynamic`,hint:`preserve runtime style switching`}]});if(!y.isCancel(t))return t}async function j(t){y.intro(S.bgCyan(S.black(` Solar Icons v2 migration `)));let n=await e(t);y.log.info(`Detected: ${n.join(`, `)||`no supported framework`}`);let r=n.includes(`react`)?await A(`React`):void 0;if(n.includes(`react`)&&!r){y.cancel(`Migration cancelled.`);return}let i=n.includes(`vue`)?await A(`Vue`):void 0;if(n.includes(`vue`)&&!i){y.cancel(`Migration cancelled.`);return}let a=await y.select({message:`Choose an action`,options:[{value:`preview`,label:`Preview changes`,hint:`does not modify files`},{value:`write`,label:`Apply changes`,hint:`writes the migration to disk`}]});if(y.isCancel(a)){y.cancel(`Migration cancelled.`);return}let o=a===`write`;if(o){let e=await y.confirm({message:`Write the migration to this project?`,initialValue:!1});if(y.isCancel(e)||!e){y.cancel(`Migration cancelled.`);return}}return{reactV1Mode:r,vueV1Mode:i,write:o}}async function M(){let e=new b().name(`solar-icons-migrate`).description(`Migrate a Solar Icons project from the pre-v2 API to v2.`).argument(`[directory]`,`project directory, defaults to the current directory`).option(`-C, --cwd <path>`,`project directory, kept for backwards compatibility`).option(`-i, --interactive`,`guide the migration with prompts`).option(`-w, --write`,`apply changes instead of previewing them`).option(`--react-v1-mode <mode>`,`React strategy: static or dynamic`,D).option(`--vue-v1-mode <mode>`,`Vue strategy: static or dynamic`,D).option(`--target-version <version>`,`Solar Icons v2 version to add to package.json`).option(`--json`,`write a machine-readable report to stdout`).showHelpAfterError().showSuggestionAfterError();e.action(async(t,n)=>{t&&n.cwd&&e.error(`Use either [directory] or --cwd, not both.`,{exitCode:2}),n.interactive&&n.json&&e.error(`--interactive cannot be combined with --json.`,{exitCode:2});let r=_(n.cwd??t??process.cwd()),i=n.interactive?await j(r):void 0;if(n.interactive&&!i)return;let a={cwd:r,reactV1Mode:i?.reactV1Mode??n.reactV1Mode,targetVersion:n.targetVersion,vueV1Mode:i?.vueV1Mode??n.vueV1Mode,write:i?.write??n.write},o=await E(a);n.json?console.info(JSON.stringify(o,null,2)):k(o,!!a.write),n.interactive&&y.outro(`Migration complete.`)}),await e.parseAsync()}process.argv[1]&&import.meta.url===v(process.argv[1]).href&&M();export{E as runMigration};
2
+ import{detectFrameworks as e}from"./detect.mjs";import{transformPackageJson as t}from"./package-json.mjs";import{collectAngularSelectorRenames as n,transformAngular as r,transformAngularTemplate as i}from"./transforms/angular.mjs";import{transformNuxt as a}from"./transforms/nuxt.mjs";import{transformReactNative as o}from"./transforms/react-native.mjs";import{transformReactPerf as s}from"./transforms/react-perf.mjs";import{transformReact as c}from"./transforms/react.mjs";import{transformSolid as l}from"./transforms/solid.mjs";import{transformSvelte as u}from"./transforms/svelte.mjs";import{transformVue as d}from"./transforms/vue.mjs";import{readFile as f,readdir as p,writeFile as m}from"node:fs/promises";import{extname as h,join as g,resolve as _}from"node:path";import{realpathSync as v}from"node:fs";import{pathToFileURL as y}from"node:url";import*as b from"@clack/prompts";import{Command as x,InvalidArgumentError as S}from"commander";import C from"picocolors";const w=new Set([`.html`,`.js`,`.jsx`,`.mjs`,`.ts`,`.tsx`,`.svelte`,`.vue`]),T=new Set([`.git`,`.next`,`.nuxt`,`.svelte-kit`,`coverage`,`dist`,`node_modules`]);async function E(e){let t=await p(e,{withFileTypes:!0});return(await Promise.all(t.map(async t=>{let n=g(e,t.name);return t.isDirectory()?T.has(t.name)?[]:E(n):t.isFile()&&w.has(h(t.name))?[n]:[]}))).flat()}async function D({cwd:p,reactV1Mode:h=`static`,targetVersion:_,vueV1Mode:v=`static`,write:y=!1}){let b=await e(p),x=await E(p),S=new Map(await Promise.all(x.map(async e=>[e,await f(e,`utf8`)]))),C=new Map;for(let[e,t]of S)for(let[r,i]of n(t,e))C.set(r,i);let w=new Set(x),T=[],D=[];for(let e of x){let t=s(S.get(e),e),n=c(t.code,e,h),f=o(n.code,e),p=d(f.code,e,v),g=a(p.code,e),_=u(g.code,e),b=l(_.code,e),x=r(b.code,e,w),E=i(x.code,C);D.push(...t.diagnostics,...n.diagnostics,...f.diagnostics,...p.diagnostics,...g.diagnostics,..._.diagnostics,...b.diagnostics,...x.diagnostics,...E.diagnostics),!(!t.changed&&!n.changed&&!f.changed&&!p.changed&&!g.changed&&!_.changed&&!b.changed&&!x.changed&&!E.changed)&&(T.push(e),y&&await m(e,E.code))}let O=g(p,`package.json`),k=t(await f(O,`utf8`),_);return k.changed&&(T.push(O),y&&await m(O,k.code)),{changedFiles:T,diagnostics:D,detectedFrameworks:b}}function O(e){if(e===`static`||e===`dynamic`)return e;throw new S(`Expected either "static" or "dynamic".`)}function k(e){let t=e.file&&e.line?`${e.file}:${e.line}:${e.column??1}`:e.file,n=e.severity===`error`?C.red(`error`):C.yellow(`warning`);return`${C.dim(t??`solar-icons`)} ${n} ${C.bold(`[${e.code}]`)} ${e.message}`}function A(e,t){console.info(`${C.cyan(`Detected frameworks:`)} ${e.detectedFrameworks.join(`, `)||`none`}`),console.info(`${t?C.green(`Migrated`):C.cyan(`Would migrate`)} ${C.bold(String(e.changedFiles.length))} file(s).`);for(let t of e.diagnostics)console.warn(k(t));!t&&e.changedFiles.length>0&&console.info(C.dim(`Run again with --write to apply these changes.`))}async function j(e){let t=await b.select({message:`${e} migration strategy`,options:[{value:`static`,label:`Static (recommended)`,hint:`one style per import and the smallest bundle`},{value:`dynamic`,label:`Dynamic`,hint:`preserve runtime style switching`}]});if(!b.isCancel(t))return t}async function M(t){b.intro(C.bgCyan(C.black(` Solar Icons v2 migration `)));let n=await e(t);b.log.info(`Detected: ${n.join(`, `)||`no supported framework`}`);let r=n.includes(`react`)?await j(`React`):void 0;if(n.includes(`react`)&&!r){b.cancel(`Migration cancelled.`);return}let i=n.includes(`vue`)?await j(`Vue`):void 0;if(n.includes(`vue`)&&!i){b.cancel(`Migration cancelled.`);return}let a=await b.select({message:`Choose an action`,options:[{value:`preview`,label:`Preview changes`,hint:`does not modify files`},{value:`write`,label:`Apply changes`,hint:`writes the migration to disk`}]});if(b.isCancel(a)){b.cancel(`Migration cancelled.`);return}let o=a===`write`;if(o){let e=await b.confirm({message:`Write the migration to this project?`,initialValue:!1});if(b.isCancel(e)||!e){b.cancel(`Migration cancelled.`);return}}return{reactV1Mode:r,vueV1Mode:i,write:o}}async function N(){let e=new x().name(`solar-icons-migrate`).description(`Migrate a Solar Icons project from the pre-v2 API to v2.`).argument(`[directory]`,`project directory, defaults to the current directory`).option(`-C, --cwd <path>`,`project directory, kept for backwards compatibility`).option(`-i, --interactive`,`guide the migration with prompts`).option(`-w, --write`,`apply changes instead of previewing them`).option(`--react-v1-mode <mode>`,`React strategy: static or dynamic`,O).option(`--vue-v1-mode <mode>`,`Vue strategy: static or dynamic`,O).option(`--target-version <version>`,`Solar Icons v2 version to add to package.json`).option(`--json`,`write a machine-readable report to stdout`).showHelpAfterError().showSuggestionAfterError();e.action(async(t,n)=>{t&&n.cwd&&e.error(`Use either [directory] or --cwd, not both.`,{exitCode:2}),n.interactive&&n.json&&e.error(`--interactive cannot be combined with --json.`,{exitCode:2});let r=_(n.cwd??t??process.cwd()),i=n.interactive?await M(r):void 0;if(n.interactive&&!i)return;let a={cwd:r,reactV1Mode:i?.reactV1Mode??n.reactV1Mode,targetVersion:n.targetVersion,vueV1Mode:i?.vueV1Mode??n.vueV1Mode,write:i?.write??n.write},o=await D(a);n.json?console.info(JSON.stringify(o,null,2)):A(o,!!a.write),n.interactive&&b.outro(`Migration complete.`)}),await e.parseAsync()}const P=process.argv[1]?v(process.argv[1]):void 0;P&&import.meta.url===y(P).href&&N();export{D as runMigration};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solar-icons/codemod",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.4",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -13,6 +13,7 @@
13
13
  },
14
14
  "type": "module",
15
15
  "bin": {
16
+ "codemod": "./dist/cli.mjs",
16
17
  "solar-icons-migrate": "./dist/cli.mjs"
17
18
  },
18
19
  "files": [