Skip to content

Commit 07f28e6

Browse files
committed
feat(compas): reimplement zakmes, add package manager support
- Mainly moved tui + cache + watcher to development only code. - Manage all the state in a single `state` class. - Add all integrations as singular things. Every integration can react to cache changes, config changes, file changes or keypress inputs. File changes are debounced automatically and need to be registered by the integration. - Support running in multiple root directories. There are some optimizations to be made, but implementing a reactive and cache enabled integration should be pretty straight-forward.
1 parent 3773403 commit 07f28e6

34 files changed

+2201
-1834
lines changed

docs/docs/workspaces.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ you are currently working on.
3838

3939
## Limitations
4040

41-
- Compas only supports a single package manager (npm, yarn or pnpm) in a
42-
workspace.
4341
- Compas assumes that nested projects are also setup correctly in your package
4442
manager and only runs installation (e.g `npm install`) in the root project.
45-
For sibling projects, Compas runs the package manager in all individual
46-
projects, but it is still limited to a single package manager.
43+
For sibling projects, Compas runs the inferred package manager in each
44+
project.
4745
- Compas stores its cache in the project that you started Compas in and removes
4846
the cache from referenced projects. This way Compas has a single source of
4947
truth. So the most efficient way of developing is to always start Compas from

gen/compas.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function applyCompasStructure(generator) {
4040

4141
projects: T.array()
4242
.values(T.string())
43-
.optional()
43+
.default(`[]`)
4444
.docs(
4545
"Relative paths to projects. Each project is expected to provide their own configuration.",
4646
),
@@ -51,7 +51,7 @@ export function applyCompasStructure(generator) {
5151
shortcut: T.string(),
5252
command: T.array().values(T.string()).min(1),
5353
})
54-
.optional()
54+
.default(`[]`)
5555
.docs("Available actions for this project."),
5656
};
5757

@@ -68,8 +68,35 @@ export function applyCompasStructure(generator) {
6868
.loose(),
6969

7070
T.object("cache").keys({
71-
version: T.string(),
72-
config: T.reference("compas", "resolvedConfig").optional(),
71+
version: T.string().docs("Compas version, used for cache invalidations."),
72+
73+
config: T.reference("compas", "resolvedConfig")
74+
.optional()
75+
.docs(
76+
"The resolved config. Managed by {@link ConfigLoaderIntegration}.",
77+
),
78+
79+
rootDirectories: T.array()
80+
.values(T.string())
81+
.optional()
82+
.min(1)
83+
.docs(
84+
"Resolved project root directories. Managed by {@link RootDirectoriesIntegration}.",
85+
),
86+
87+
cachesCleaned: T.bool()
88+
.optional()
89+
.docs(
90+
"Did clean caches from project directories. Managed by {@link CacheCleanupIntegration}.",
91+
),
92+
93+
packageManagerInstallCommand: T.generic()
94+
.keys(T.string())
95+
.values(T.array().values(T.string()))
96+
.optional()
97+
.docs(
98+
"The inferred package install command per rootDirectory. Managed by {@link PackageManagerIntegration}.",
99+
),
73100
}),
74101
);
75102
}

packages/compas/src/cli/bin.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
#!/usr/bin/env node
22

33
import { existsSync } from "node:fs";
4-
import { isNil } from "@compas/stdlib";
5-
import { configLoadEnvironment } from "../config.js";
4+
import { newLogger } from "@compas/stdlib";
5+
import { configLoadEnvironment } from "../shared/config.js";
6+
import {
7+
debugDisable,
8+
debugEnable,
9+
debugPrint,
10+
logger,
11+
loggerEnable,
12+
} from "../shared/output.js";
613

714
// Just execute some temporary command matching
815
const args = process.argv.slice(2);
916
const debug = args.includes("--debug");
1017

1118
if (debug) {
1219
args.splice(args.indexOf("--debug"), 1);
20+
await debugEnable();
21+
} else {
22+
debugDisable();
1323
}
1424

25+
debugPrint({
26+
argv: process.argv,
27+
args,
28+
});
29+
1530
if (args.length === 0) {
1631
if (!existsSync("./package.json")) {
1732
// eslint-disable-next-line no-console
1833
console.log(`Please run 'npx compas@latest init' to install Compas.`);
1934
} else {
20-
// TODO: check if we are in a project or someone forgot to run 'compas init'.
35+
// TODO: check if we are in a project with Compas installed or if we should nudge the user to run Compas init. We probably want to do this differently in the different modes.
2136

22-
// TODO: debug
37+
const env = await configLoadEnvironment(false);
2338

24-
const env = await configLoadEnvironment("", !isNil(process.env.NODE_ENV));
39+
debugPrint(env);
2540

2641
if (env.isCI) {
2742
const { ciMode } = await import("../main/ci/index.js");
@@ -34,15 +49,26 @@ if (args.length === 0) {
3449
await developmentMode(env);
3550
}
3651
}
37-
} else if (args.length === 1) {
38-
if (args[0] === "init") {
39-
const { initCompas } = await import("../main/init/compas.js");
40-
await initCompas();
41-
}
4252
} else {
43-
// eslint-disable-next-line no-console
44-
console.log(`Unsupported command. Available commands:
53+
const command = args.join(" ");
54+
const env = await configLoadEnvironment(true);
55+
56+
loggerEnable(
57+
newLogger({
58+
ctx: {
59+
type: env.appName,
60+
},
61+
}),
62+
);
63+
64+
if (command === "init") {
65+
const { initCompas } = await import("../main/init/compas.js");
66+
await initCompas(env);
67+
} else {
68+
// eslint-disable-next-line no-console
69+
logger.info(`Unsupported command. Available commands:
4570
4671
- compas
4772
- compas init`);
73+
}
4874
}

packages/compas/src/config.js

Lines changed: 0 additions & 207 deletions
This file was deleted.

0 commit comments

Comments
 (0)