UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 3.03 kB
{"version":3,"file":"imports.cjs","names":["Effect","listFiles","readText"],"sources":["../../../../../src/services/scaffold/upgrade-audit/checks/imports.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { Finding, type ImportRewrite } from \"../domain\";\nimport { listFiles, readText } from \"../fs\";\n\nexport const IMPORT_REWRITES: ReadonlyArray<readonly [string, string]> = [\n ['from \"@/auth\"', 'from \"@/app\"'],\n [\"from '@/auth'\", \"from '@/app'\"],\n ['from \"@/lib/auth-utils\"', 'from \"@/lib/auth\"'],\n [\"from '@/lib/auth-utils'\", \"from '@/lib/auth'\"],\n ['from \"@/lib/use-api-client\"', 'from \"@/app\"'],\n [\"from '@/lib/use-api-client'\", \"from '@/app'\"],\n ['from \"@/lib/api-client\"', 'from \"@/app\"'],\n [\"from '@/lib/api-client'\", \"from '@/app'\"],\n ['from \"everything-dev/dist/', 'from \"everything-dev/'],\n [\"from 'everything-dev/dist/\", \"from 'everything-dev/\"],\n];\n\nexport const scanImports = (projectDir: string): Effect.Effect<readonly ImportRewrite[], Error> =>\n Effect.gen(function* () {\n const files = (yield* listFiles(projectDir, [\n \"ui/src/**/*.{ts,tsx}\",\n \"api/src/**/*.ts\",\n \"plugins/*/src/**/*.{ts,tsx}\",\n ])).filter((file) => !file.endsWith(\".gen.ts\") && !file.endsWith(\".test.ts\"));\n\n const sources = new Map<string, string>();\n for (const file of files) {\n sources.set(file, yield* readText(projectDir, file));\n }\n\n return IMPORT_REWRITES.map(([from, to]) => {\n const matched: string[] = [];\n for (const [file, source] of sources) {\n if (source.includes(from)) matched.push(file);\n }\n return { from, to, files: matched };\n });\n });\n\nexport const checkImports = (projectDir: string): Effect.Effect<Finding[], Error> =>\n Effect.gen(function* () {\n const rewrites = yield* scanImports(projectDir);\n return rewrites.flatMap((rewrite) =>\n rewrite.files.length === 0\n ? []\n : [\n new Finding({\n check: \"imports\",\n path: rewrite.files.join(\", \"),\n severity: \"warn\",\n message: `legacy import \"${rewrite.from}\" — rewrite to \"${rewrite.to}\"`,\n }),\n ],\n );\n });\n"],"mappings":";;;;AAIA,MAAa,kBAA4D;CACvE,CAAC,mBAAiB,gBAAc;CAChC,CAAC,iBAAiB,cAAc;CAChC,CAAC,6BAA2B,qBAAmB;CAC/C,CAAC,2BAA2B,mBAAmB;CAC/C,CAAC,iCAA+B,gBAAc;CAC9C,CAAC,+BAA+B,cAAc;CAC9C,CAAC,6BAA2B,gBAAc;CAC1C,CAAC,2BAA2B,cAAc;CAC1C,CAAC,+BAA8B,wBAAuB;CACtD,CAAC,8BAA8B,uBAAuB;AACxD;AAEA,MAAa,eAAe,eAC1BA,cAAO,IAAI,aAAa;CACtB,MAAM,SAAS,OAAOC,qBAAU,YAAY;EAC1C;EACA;EACA;CACF,CAAC,EAAC,CAAE,QAAQ,SAAS,CAAC,KAAK,SAAS,SAAS,KAAK,CAAC,KAAK,SAAS,UAAU,CAAC;CAE5E,MAAM,0BAAU,IAAI,IAAoB;CACxC,KAAK,MAAM,QAAQ,OACjB,QAAQ,IAAI,MAAM,OAAOC,oBAAS,YAAY,IAAI,CAAC;CAGrD,OAAO,gBAAgB,KAAK,CAAC,MAAM,QAAQ;EACzC,MAAM,UAAoB,CAAC;EAC3B,KAAK,MAAM,CAAC,MAAM,WAAW,SAC3B,IAAI,OAAO,SAAS,IAAI,GAAG,QAAQ,KAAK,IAAI;EAE9C,OAAO;GAAE;GAAM;GAAI,OAAO;EAAQ;CACpC,CAAC;AACH,CAAC"}