-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add preferPackFiles * fix: fix the preferPackFiles * feat: add npmPkg meta and add cjsImportEsm * fix: fix tip and missing export * chore: delete dead code * refactor: refactor the code * fix: fix getSourceFiles * chore: change npmPkg config field * chore: change examples * refactor: refactor the code * chore: delete the unless code * chore: recover the .npmrc * chore: detail adjustment * chore: detail adjustment
- Loading branch information
Showing
11 changed files
with
127 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ npm run test | |
``` | ||
|
||
`examples/diy` 整合了目前已有的绝大部分 rules | ||
|
||
```sh | ||
cd examples/diy | ||
npm run test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
export const PRESET_NAME = "npm-pkg"; | ||
export const DEFAULT_SOURCE_IGNORES = [ | ||
"**/.*", | ||
"**/.*/**", | ||
"**/node_modules/**", | ||
"**/dist/**", | ||
"**/build/**", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,99 @@ | ||
import { globSync } from "glob"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
import lodash from "lodash"; | ||
import sourceParser from "./features/scanningParser"; | ||
import { DEFAULT_SOURCE_IGNORES } from "./constants"; | ||
import { SourceFile } from "./types"; | ||
|
||
export function getPkgNameFromPath(p: string) { | ||
return p.match(/^(?:@[a-z\d][\w-.]*\/)?[a-z\d][\w-.]*/i)?.[0]; | ||
} | ||
|
||
//----------------------------- Source --------------------------------- | ||
export function getSourceDirs(files: string[]) { | ||
const configDirs = lodash.uniq([...files.map((c) => path.dirname(c))]); | ||
|
||
return configDirs; | ||
} | ||
|
||
export function getSourceFiles(compileFiles: string[], cwd: string) { | ||
let files: string[] = []; | ||
|
||
if (compileFiles.length) { | ||
compileFiles.forEach((e) => { | ||
globSync(e, { | ||
cwd, | ||
ignore: DEFAULT_SOURCE_IGNORES, | ||
nodir: true, | ||
}).forEach((file) => { | ||
files.push(file); | ||
}); | ||
}); | ||
} else { | ||
files = globSync("**/*.{ts,js}", { | ||
cwd, | ||
ignore: DEFAULT_SOURCE_IGNORES, | ||
nodir: true, | ||
}); | ||
} | ||
|
||
const sourceDirs = getSourceDirs(files); | ||
|
||
let allFiles: string[] = sourceDirs.reduce<string[]>( | ||
(ret: string[], dir: string) => | ||
ret.concat( | ||
globSync(`${dir}/**/*.{ts,js}`, { | ||
cwd, | ||
ignore: DEFAULT_SOURCE_IGNORES, | ||
nodir: true, | ||
}) | ||
), | ||
[] | ||
); | ||
|
||
allFiles = [...new Set(allFiles)]; | ||
|
||
return allFiles; | ||
} | ||
|
||
export async function getFilesWithImports( | ||
compileFiles: string[], | ||
AbsDir: string | ||
) { | ||
const files: string[] = getSourceFiles(compileFiles, AbsDir); | ||
|
||
let sourceFiles: SourceFile[]; | ||
|
||
sourceFiles = await Promise.all( | ||
files.map(async (file) => { | ||
return { | ||
path: file, | ||
imports: (await sourceParser(path.join(AbsDir, file))).imports, | ||
content: fs.readFileSync(path.join(AbsDir, file), "utf-8"), | ||
}; | ||
}) | ||
); | ||
|
||
return sourceFiles; | ||
} | ||
|
||
//----------------------------- MonoRepo --------------------------------- | ||
export function getMonorepoSonPackages(workSpaces: string[], cwd: string) { | ||
const packAgeJsonFiles: string[] = []; | ||
workSpaces.forEach((workSpace) => { | ||
packAgeJsonFiles.push( | ||
...globSync(workSpace + "/**/*.json", { | ||
cwd, | ||
ignore: DEFAULT_SOURCE_IGNORES, | ||
nodir: true, | ||
}).filter((jsonFile) => { | ||
return jsonFile.endsWith("package.json"); | ||
}) | ||
); | ||
}); | ||
|
||
const packages = getSourceDirs(packAgeJsonFiles); | ||
|
||
return packages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
import { type IDoctorSourceParseResult } from "../features/scanningParser"; | ||
|
||
export type Awaitable<T> = T | Promise<T>; | ||
|
||
export interface SourceFile { | ||
path?: string; | ||
imports?: IDoctorSourceParseResult["imports"]; | ||
contents?: string; | ||
} |