-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(@npcs/get-changed-packages,@npcs/cli,@npcs/rollup-config,@npcs/…
…template,npcs): add commit lint
- Loading branch information
Showing
18 changed files
with
301 additions
and
24 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
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,4 +1,14 @@ | ||
const scopes = import("@npcs/get-changed-packages/esm/pnpm.js").then((x) => | ||
x.getChangedPackages() | ||
); | ||
|
||
/** @type {import('cz-git').UserConfig} */ | ||
module.exports = { | ||
extends: ["@commitlint/config-conventional"], | ||
prompt: { | ||
scopes, | ||
enableMultipleScopes: true, | ||
defaultScope: scopes, | ||
allowEmptyScopes: false, | ||
}, | ||
}; |
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 |
---|---|---|
|
@@ -3,12 +3,13 @@ | |
"private": true, | ||
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a", | ||
"scripts": { | ||
"prepare": "husky && turbo prisma-generate", | ||
"prepare": "husky && turbo prisma-generate & turbo compile", | ||
"commit": "git-cz" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^19.3.0", | ||
"@commitlint/config-conventional": "^19.2.2", | ||
"@npcs/get-changed-packages": "workspace:^", | ||
"cz-git": "^1.9.4", | ||
"husky": "^9.1.1", | ||
"lerna": "^8.1.7", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ packages: | |
- "./configs/*" | ||
- "./libs/*" | ||
- "./dbs/*" | ||
- "./tools/*" |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@npcs/eslint-config"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
# [0.4.0](https://github.com/xiaosen7/npcs/compare/v0.3.1...v0.4.0) (2024-07-26) | ||
|
||
**Note:** Version bump only for package @npcs/cli | ||
|
||
|
||
|
||
|
||
|
||
## [0.3.1](https://github.com/xiaosen7/npcs/compare/v0.3.0...v0.3.1) (2024-07-26) | ||
|
||
**Note:** Version bump only for package @npcs/cli | ||
|
||
|
||
|
||
|
||
|
||
# [0.3.0](https://github.com/xiaosen7/next.js-practical-cases/compare/v0.2.0...v0.3.0) (2024-07-26) | ||
|
||
**Note:** Version bump only for package @npcs/cli | ||
|
||
|
||
|
||
|
||
|
||
# [0.2.0](https://github.com/xiaosen7/next.js-practical-cases/compare/v0.1.0...v0.2.0) (2024-07-26) | ||
|
||
**Note:** Version bump only for package @npcs/cli | ||
|
||
|
||
|
||
|
||
|
||
# [0.1.0](https://github.com/xiaosen7/next.js-practical-cases/compare/v0.0.1...v0.1.0) (2024-07-26) | ||
|
||
**Note:** Version bump only for package @npcs/cli |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @npcs/get-changed-packages | ||
|
||
Get the changed packages from the last commit inside a workspace. |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@npcs/get-changed-packages", | ||
"version": "0.4.0", | ||
"description": "Get the changed packages from the last commit inside a workspace.", | ||
"repository": { | ||
"url": "https://github.com/xiaosen7/npcs" | ||
}, | ||
"type": "module", | ||
"scripts": { | ||
"check-types": "tsc --noEmit", | ||
"lint": "eslint .", | ||
"compile:watch": "rollup -c --watch", | ||
"compile": "rollup -c", | ||
"test": "vitest --run", | ||
"test:watch": "vitest watch", | ||
"test:changed": "vitest run --changed" | ||
}, | ||
"dependencies": { | ||
"@pnpm/filter-workspace-packages": "^10.0.1", | ||
"@pnpm/find-workspace-dir": "^7.0.1", | ||
"@pnpm/workspace.find-packages": "^4.0.1", | ||
"rollup": "^4.18.1" | ||
}, | ||
"devDependencies": { | ||
"@npcs/eslint-config": "workspace:*", | ||
"@npcs/rollup-config": "workspace:*", | ||
"@npcs/tailwind-config": "workspace:*", | ||
"@npcs/typescript-config": "workspace:*", | ||
"@npcs/vitest-config": "workspace:^", | ||
"@types/node": "^20.14.10", | ||
"eslint": "^8.57.0", | ||
"typescript": "5.5.3", | ||
"vitest": "^1.6.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable import/no-anonymous-default-export */ | ||
|
||
import config from "@npcs/rollup-config"; | ||
|
||
/** @type {import('rollup').RollupOptions} */ | ||
export default { | ||
...config, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { findWorkspacePackages } from "@pnpm/workspace.find-packages"; | ||
import { filterChangedPkgs, getUnCommitFiles } from "./shared"; | ||
|
||
export const getChangedPackages = async () => { | ||
const pkgs = await getPnpmWorkspacePkgs(process.cwd()); | ||
const unCommitFiles = getUnCommitFiles(); | ||
|
||
return filterChangedPkgs(pkgs, unCommitFiles); | ||
}; | ||
|
||
async function getPnpmWorkspacePkgs(cwd: string) { | ||
return (await findWorkspacePackages(cwd)) | ||
.filter((x) => !!x.manifest.name) | ||
.map(({ rootDir: path, manifest: { name } }) => ({ | ||
path, | ||
name: name!, | ||
})); | ||
} | ||
|
||
export default getChangedPackages; |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { execSync } from "child_process"; | ||
import { join } from "path"; | ||
|
||
export interface IPkg { | ||
name: string; | ||
path: string; | ||
} | ||
export function filterChangedPkgs(pkgs: IPkg[], unCommitFiles: string[]) { | ||
const sortedPkgs = pkgs.slice().sort((a, b) => comparePath(a.path, b.path)); | ||
const changedPkgs: string[] = []; | ||
|
||
for (const file of unCommitFiles) { | ||
for (let pi = 0; pi < sortedPkgs.length; pi++) { | ||
const { name, path } = sortedPkgs[pi]; | ||
if (file.startsWith(path)) { | ||
sortedPkgs.splice(pi, 1); | ||
changedPkgs.push(name); | ||
break; | ||
} | ||
} | ||
|
||
if (sortedPkgs.length === 0) { | ||
return changedPkgs; | ||
} | ||
} | ||
|
||
return changedPkgs; | ||
} | ||
|
||
export function comparePath(a: string, b: string) { | ||
return b.length - a.length; | ||
} | ||
|
||
export function getUnCommitFiles() { | ||
const gitRoot = execSync("git rev-parse --show-toplevel").toString().trim(); | ||
const statusString = execSync("git status -s").toString().trim(); | ||
return statusString | ||
.split(/\n\r?/g) | ||
.filter(Boolean) | ||
.map((x) => x.split(/\s+/)[1]) | ||
.map((x) => join(gitRoot, x)); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { comparePath, filterChangedPkgs, IPkg } from "@/shared"; | ||
import { name } from "../package.json"; | ||
|
||
describe(name, () => { | ||
test(comparePath.name, () => { | ||
expect(["a/b", "a/b/c"].sort(comparePath)).toEqual(["a/b/c", "a/b"]); | ||
}); | ||
|
||
describe(filterChangedPkgs.name, () => { | ||
const doTest = ( | ||
pkgs: IPkg[], | ||
unCommitFiles: string[], | ||
expectedResult: string[], | ||
) => { | ||
expect(filterChangedPkgs(pkgs, unCommitFiles)).toEqual(expectedResult); | ||
}; | ||
|
||
test("should filter pkgs", () => { | ||
const pkgs = [ | ||
{ | ||
name: "web", | ||
path: "/web", | ||
}, | ||
{ | ||
name: "api", | ||
path: "/api", | ||
}, | ||
]; | ||
|
||
const unCommitFiles = ["/web/src/index.ts", "/api/src/index.ts"]; | ||
doTest(pkgs, unCommitFiles, ["web", "api"]); | ||
}); | ||
|
||
test("should not include root", () => { | ||
const pkgs = [ | ||
{ | ||
name: "root", | ||
path: "/", | ||
}, | ||
{ | ||
name: "web", | ||
path: "/web", | ||
}, | ||
]; | ||
|
||
const unCommitFiles = ["/web/src/index.ts"]; | ||
doTest(pkgs, unCommitFiles, ["web"]); | ||
}); | ||
|
||
test("should include root", () => { | ||
const pkgs = [ | ||
{ | ||
name: "root", | ||
path: "/", | ||
}, | ||
{ | ||
name: "web", | ||
path: "/web", | ||
}, | ||
]; | ||
|
||
const unCommitFiles = ["/index.ts"]; | ||
doTest(pkgs, unCommitFiles, ["root"]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.