Skip to content

Commit

Permalink
Workspace management (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored Jan 27, 2024
1 parent 9edaa28 commit ff0a502
Show file tree
Hide file tree
Showing 37 changed files with 3,665 additions and 3,015 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- run: npm install -g pnpm
name: Install PNPM
- uses: pnpm/action-setup@v2
name: Install pnpm

- run: pnpm install
name: Install dependencies
Expand Down
3 changes: 0 additions & 3 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ printWidth: 120
quoteProps: "consistent"
endOfLine: lf
arrowParens: always
plugins:
- "./node_modules/@cadl-lang/prettier-plugin-cadl"
overrides: [{ "files": "*.cadl", "options": { "parser": "cadl" } }]
6 changes: 2 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"search.exclude": {
"**/node_modules": true,
"dist": true
},
"files.eol": "\n",
"prettier.prettierPath": "./node_modules/prettier",
"prettier.prettierPath": "./node_modules/prettier/index.cjs",
"typescript.tsdk": "node_modules/typescript/lib",
"jest.jestCommandLine": "jest",
"jest.autoRun": "off"
}
9 changes: 0 additions & 9 deletions jest.config.js

This file was deleted.

26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"name": "@kronos/monorepo",
"private": true,
"version": "0.1.0",
"packageManager": "[email protected]",
"description": "Monorepo for kronos",
"type": "module",
"workspaces": [
"packages/*"
],
"scripts": {
"test": "jest",
"test": "vitest run",
"test:watch": "vitest -w",
"preinstall": "npx only-allow pnpm",
"watch": "tsc --build ./tsconfig.ws.json --watch",
"build": "pnpm -r run build",
Expand Down Expand Up @@ -36,19 +38,19 @@
},
"homepage": "https://github.com/timotheeguerin/kronos#readme",
"devDependencies": {
"@cadl-lang/prettier-plugin-cadl": "^0.5.15",
"cspell": "^6.8.1",
"eslint": "^8.23.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-unicorn": "^43.0.2",
"jest": "^29.3.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"syncpack": "^8.2.4",
"ts-jest": "^29.0.0",
"typescript": "^4.9.3"
"cspell": "^8.3.2",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-unicorn": "^50.0.1",
"prettier": "^3.2.4",
"rimraf": "^5.0.5",
"syncpack": "^12.3.0",
"typescript": "^5.3.3"
},
"syncpack": {
"workspace": false
},
"dependencies": {
"vitest": "^1.2.2"
}
}
70 changes: 0 additions & 70 deletions packages/eslint-config-konos/index.js

This file was deleted.

29 changes: 0 additions & 29 deletions packages/eslint-config-konos/package.json

This file was deleted.

This file was deleted.

14 changes: 9 additions & 5 deletions packages/kronos/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require("@cadl-lang/eslint-config-cadl/patch/modern-module-resolution");

module.exports = {
plugins: [],
extends: ["@cadl-lang/eslint-config-cadl"],
parserOptions: { tsconfigRootDir: __dirname },
root: true,
env: { browser: true, es2020: true },
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
rules: {
"no-console": "warn",
"@typescript-eslint/no-explicit-any": "off",
},
};
2 changes: 0 additions & 2 deletions packages/kronos/jest.config.js

This file was deleted.

25 changes: 13 additions & 12 deletions packages/kronos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"clean": "rimraf dist/ .temp/",
"lint": "eslint . --ext .ts --max-warnings=0",
"lint:fix": "eslint . --fix --ext .ts",
"test": "jest",
"test:watch": "jest --watch"
"test": "vitest run",
"test:watch": "vitest -w"
},
"engines": {
"node": ">=16.0.0"
Expand All @@ -31,27 +31,28 @@
},
"homepage": "https://github.com/timotheeguerin/kronos#readme",
"dependencies": {
"ajv": "8.11.0",
"js-yaml": "^4.1.0",
"micromatch": "^4.0.5",
"picocolors": "^1.0.0",
"prettier": "^2.7.1",
"prettier": "^3.2.4",
"source-map-support": "^0.5.21",
"vitest": "^1.2.2",
"yargs": "^17.5.1"
},
"devDependencies": {
"@cadl-lang/eslint-config-cadl": "^0.4.1",
"@jest/globals": "^29.3.1",
"@types/cross-spawn": "^6.0.2",
"@types/js-yaml": "^4.0.5",
"@types/node": "^18.7.16",
"@types/micromatch": "^4.0.6",
"@types/node-fetch": "^2.6.2",
"@types/node": "^18.7.16",
"@types/xml2js": "^0.4.11",
"@types/yargs": "^17.0.12",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"cross-spawn": "^7.0.3",
"eslint": "^8.23.1",
"jest": "^29.3.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.0",
"typescript": "^4.9.3"
"eslint": "^8.56.0",
"globby": "^13.1.2",
"rimraf": "^5.0.5",
"typescript": "^5.3.3"
}
}
3 changes: 2 additions & 1 deletion packages/kronos/src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "source-map-support/register.js";
import yargs from "yargs";
import { addChangeset } from "./commands/add-changeset.js";

export const DEFAULT_PORT = 3000;

Expand All @@ -17,7 +18,7 @@ async function main() {
description: "Output debug log messages.",
default: false,
})

.command("add", "Add a new changeset", () => addChangeset(process.cwd()))
.parse();
}

Expand Down
10 changes: 10 additions & 0 deletions packages/kronos/src/cli/commands/add-changeset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NodeKronosHost } from "../../utils/node-host.js";
import { createPnpmWorkspaceManager } from "../../workspace-manager/pnpm.js";

export async function addChangeset(cwd: string): Promise<void> {
const host = NodeKronosHost;
const pnpm = createPnpmWorkspaceManager(host);
const packages = await pnpm.load(cwd);
// eslint-disable-next-line no-console
console.log("Packages", packages);
}
6 changes: 3 additions & 3 deletions packages/kronos/src/source-control/git.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, it } from "@jest/globals";
import { beforeEach, describe, expect, it } from "vitest";
import { join } from "node:path";
import { createTestDir, TestDir } from "../testing/index.js";
import { createTestDir, type TestDir } from "../testing/index.js";
import { execAsync } from "../utils/exec-async.js";
import { createGitSourceControl, GitRepository } from "./git.js";
import { createGitSourceControl, type GitRepository } from "./git.js";

describe("git", () => {
let cwd: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/kronos/src/source-control/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execAsync, ExecResult } from "../utils/exec-async.js";
import { execAsync, type ExecResult } from "../utils/exec-async.js";

export interface GitRepository {
/**
Expand Down
48 changes: 48 additions & 0 deletions packages/kronos/src/testing/test-host.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { GlobOptions, KronosHost } from "../utils/host.js";
import micromatch from "micromatch";
import { getDirectoryPath } from "../utils/path-utils.js";

export interface TestHost {
host: KronosHost;
addFile(path: string, content: string): void;
}

export function createTestHost(files: Record<string, string> = {}): TestHost {
const fs: Record<string, string> = files;
const host: KronosHost = {
readFile: (path: string) => {
const content = fs[path];
return Promise.resolve({ path, content });
},
writeFile: (path: string, content: string) => {
fs[path] = content;
return Promise.resolve();
},
access: (path: string) => {
return path in fs ? Promise.resolve() : Promise.reject(new Error(`VFS: File ${path} does not exist`));
},
glob: (pattern: string, options?: GlobOptions) => {
const baseDir = (options?.baseDir ?? "") + "/";
const filesInBaseDir = Object.keys(fs)
.filter((x) => x.startsWith(baseDir))
.map((x) => x.substring(baseDir.length));

const content = new Set<string>();

for (const file of filesInBaseDir) {
let current = file;
while (current !== getDirectoryPath(current)) {
content.add(current);
current = getDirectoryPath(current);
}
}
return Promise.resolve([...content].filter((x) => micromatch.isMatch(x, pattern)));
},
};
return {
host,
addFile: (path: string, content: string) => {
fs[path] = content;
},
};
}
1 change: 1 addition & 0 deletions packages/kronos/src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class KronosError extends Error {}
2 changes: 1 addition & 1 deletion packages/kronos/src/utils/exec-async.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SpawnOptions } from "child_process";
import type { SpawnOptions } from "child_process";
import crosspawn from "cross-spawn";

export interface ExecResult {
Expand Down
30 changes: 30 additions & 0 deletions packages/kronos/src/utils/fs-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { getDirectoryPath } from "./path-utils.js";
import type { KronosHost } from "./host.js";

export async function isPathAccessible(host: KronosHost, path: string): Promise<boolean> {
try {
await host.access(path);
return true;
} catch {
return false;
}
}
/**
* Look in parent directories using the given callback to test for success.
* Callback can return a string of another path that was match, true to accept the current path or false to keep traversing up.
*/
export async function lookup(
startDir: string,
callback: (currentDir: string) => string | boolean | Promise<string | boolean>,
): Promise<string | undefined> {
let last = undefined;
let current = startDir;
while (last !== current) {
if (callback(current)) {
return current;
}
last = current;
current = getDirectoryPath(startDir);
}
return undefined;
}
Loading

0 comments on commit ff0a502

Please sign in to comment.