diff --git a/.gitignore b/.gitignore index 994fe9f..bfdd50d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,8 +23,7 @@ Cargo.lock node_modules !/fixtures/modules/node_modules -/npm/*/* -!/npm/sovra/scripts -!/npm/sovra/package.json +/npm/* +!/npm/sovra /napi/*.node diff --git a/README.md b/README.md deleted file mode 100644 index edd4e59..0000000 --- a/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# Sovra - -Fast test decider for JavaScript projects, written in Rust on top of Oxc. - -## Usage - -### `getAffected(testFiles: string[], changedFiles: string[], resolverOptions: OxcResolverOptions)` - -Returns a subset of `testFiles` that have `changedFiles` in their import graph. This is useful in order to determine which tests to run in a large repo. - -#### Arguments - -| Name | Description | -| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -| `testFiles` | List of files to check if they were affected by changes | -| `changedFiles` | List of changed files | -| `resolverOptions` | Configuration on how to resolve imports, see [oxc-resolver](https://github.com/oxc-project/oxc-resolver?tab=readme-ov-file#options) | - -#### Example - -```ts -import { getAffected } from "sovra"; -import { execSync } from "node:child_process"; -import { glob } from "glob"; - -const testFiles = glob.sync("src/**/*.spec.{ts,tsx}"); -const changedFiles = execSync("git diff --name-only main", { encoding: "utf8" }) - .trim() - .split("\n"); -const resolverOptions = { - tsconfig: { - configFile: "tsconfig.json", - }, -}; - -const affected = getAffected(testFiles, changedFiles, resolverOptions); - -if (affected.errors) { - console.error(...affected.errors); -} else { - console.log(affected.files); -} -``` - -## Test - -```bash -cargo test -``` - -## Limitations - -Imports using variables or expressions are not supported as they can only be determined during runtime: - -```ts -requre(process.env.SOME_VAR + ".js"); // ❌ -import(`./file.${platform}.mjs`); // ❌ -``` - -## License - -MIT © Joel Arvidsson 2024 diff --git a/README.md b/README.md new file mode 120000 index 0000000..6e35af4 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +npm/sovra/README.md \ No newline at end of file diff --git a/npm/sovra/README.md b/npm/sovra/README.md new file mode 100644 index 0000000..edd4e59 --- /dev/null +++ b/npm/sovra/README.md @@ -0,0 +1,62 @@ +# Sovra + +Fast test decider for JavaScript projects, written in Rust on top of Oxc. + +## Usage + +### `getAffected(testFiles: string[], changedFiles: string[], resolverOptions: OxcResolverOptions)` + +Returns a subset of `testFiles` that have `changedFiles` in their import graph. This is useful in order to determine which tests to run in a large repo. + +#### Arguments + +| Name | Description | +| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------- | +| `testFiles` | List of files to check if they were affected by changes | +| `changedFiles` | List of changed files | +| `resolverOptions` | Configuration on how to resolve imports, see [oxc-resolver](https://github.com/oxc-project/oxc-resolver?tab=readme-ov-file#options) | + +#### Example + +```ts +import { getAffected } from "sovra"; +import { execSync } from "node:child_process"; +import { glob } from "glob"; + +const testFiles = glob.sync("src/**/*.spec.{ts,tsx}"); +const changedFiles = execSync("git diff --name-only main", { encoding: "utf8" }) + .trim() + .split("\n"); +const resolverOptions = { + tsconfig: { + configFile: "tsconfig.json", + }, +}; + +const affected = getAffected(testFiles, changedFiles, resolverOptions); + +if (affected.errors) { + console.error(...affected.errors); +} else { + console.log(affected.files); +} +``` + +## Test + +```bash +cargo test +``` + +## Limitations + +Imports using variables or expressions are not supported as they can only be determined during runtime: + +```ts +requre(process.env.SOME_VAR + ".js"); // ❌ +import(`./file.${platform}.mjs`); // ❌ +``` + +## License + +MIT © Joel Arvidsson 2024