Skip to content

Commit 3ab94c7

Browse files
authored
Merge pull request #2 from IKatsuba/add-deno-support
Add deno support
2 parents 8362966 + 872af6d commit 3ab94c7

File tree

13 files changed

+421
-227
lines changed

13 files changed

+421
-227
lines changed

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ jobs:
2121
with:
2222
deno-version: v2.1.1
2323
- run: deno fmt --check
24-
- run: deno task test
24+
- run: deno lint
25+
- run: deno test

deno.json

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
{
22
"tasks": {
3-
"e2e": {
4-
"command": "deno test packages/cli-e2e/**/*.spec.ts --allow-all"
5-
},
6-
"test": {
7-
"command": "deno test packages/cli/**/*.spec.ts --allow-all"
8-
},
9-
"compile": {
10-
"command": "deno compile --allow-sys --allow-write --allow-read --allow-env --allow-run --output ./dist/cli packages/cli/mod.ts"
11-
},
12-
"install": {
13-
"command": "deno install --allow-sys --allow-write --allow-read --allow-env --allow-run -g -N -R -f -n runx jsr:@runx/cli"
14-
}
3+
"e2e": "deno test packages/cli-e2e/**/*.spec.ts --allow-all",
4+
"compile": "deno compile --allow-sys --allow-write --allow-read --allow-env --allow-run --output ./dist/cli packages/cli/mod.ts",
5+
"runx": "deno run --allow-sys --allow-write --allow-read --allow-env --allow-run packages/cli/mod.ts",
6+
"install": "deno install --allow-sys --allow-write --allow-read --allow-env --allow-run -g -N -R -f -n runx jsr:@runx/cli"
157
},
168
"workspace": [
179
"./packages/*"
1810
],
1911
"fmt": {
2012
"singleQuote": true
2113
},
14+
"test": {
15+
"include": [
16+
"packages/cli/**/*.spec.ts"
17+
]
18+
},
2219
"imports": {}
2320
}

packages/cli-e2e/deno.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"version": "0.0.0"
2+
"name": "@runx/e2e",
3+
"version": "0.0.0",
4+
"exports": {}
35
}

packages/cli/commands/list.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Command } from '@cliffy/command';
2+
import {
3+
getWorkspacePatterns,
4+
getWorkspaceProjects,
5+
readRootConfig,
6+
} from '../lib/workspace.ts';
7+
import { logger } from '../lib/logger.ts';
8+
9+
export const listCommand = new Command()
10+
.description('List all packages')
11+
.option('--json', 'Output in JSON format')
12+
.action(async ({ json }) => {
13+
const rootPackageJson = await readRootConfig();
14+
const workspacePatterns = getWorkspacePatterns(rootPackageJson);
15+
16+
// Find all packages using optimized search
17+
const packageFiles = await getWorkspaceProjects(
18+
workspacePatterns,
19+
);
20+
21+
if (json) {
22+
logger.raw(
23+
JSON.stringify(
24+
packageFiles.map((packageFile) => packageFile.name),
25+
null,
26+
2,
27+
),
28+
);
29+
} else {
30+
for (const packageFile of packageFiles) {
31+
logger.info(packageFile.name);
32+
}
33+
}
34+
});

packages/cli/deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@runx/cli",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"exports": "./mod.ts",
55
"license": "MIT",
66
"imports": {

packages/cli/lib/cache.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { crypto } from '@std/crypto';
22
import { logger } from './logger.ts';
33
import { dirname, join } from '@std/path';
44
import { copy, ensureDir, exists, expandGlob } from '@std/fs';
5-
import type { Graph, PackageJson } from './graph.ts';
5+
import type { Graph, Project } from './graph.ts';
6+
import { parseGitignore } from './gitignore.ts';
67

78
interface TaskCache {
89
hash: string;
@@ -19,7 +20,7 @@ interface HashCache {
1920
taskName: string;
2021
dependencies: {
2122
files: string[];
22-
packageJson: PackageJson;
23+
project: Project;
2324
};
2425
localDependencyHashes: string[];
2526
};
@@ -230,10 +231,10 @@ export async function calculateTaskHash(
230231
taskName: string,
231232
dependencies: {
232233
files: string[];
233-
packageJson: PackageJson;
234+
project: Project;
234235
},
235236
graph?: Graph,
236-
packageMap?: Map<string, { packageJson: PackageJson; cwd: string }>,
237+
packageMap?: Map<string, Project>,
237238
affectedPackages?: Set<string>,
238239
): Promise<string> {
239240
if (!globalCacheManager) {
@@ -298,15 +299,13 @@ export async function calculateTaskHash(
298299
if (await exists(gitignorePath)) {
299300
const gitignore = await Deno.readTextFile(gitignorePath);
300301
exclude.push(
301-
...gitignore.split('\n').map((file) => file.trim()).filter(
302-
Boolean,
303-
),
302+
...parseGitignore(gitignore),
304303
);
305304
}
306305

307306
const depFiles = await Array.fromAsync(
308307
expandGlob('**/*', {
309-
root: depInfo.cwd,
308+
root: depInfo.path,
310309
exclude,
311310
}),
312311
).then((files) =>
@@ -319,7 +318,7 @@ export async function calculateTaskHash(
319318
taskName,
320319
{
321320
files: depFiles,
322-
packageJson: depInfo.packageJson,
321+
project: depInfo,
323322
},
324323
graph,
325324
packageMap,
@@ -372,3 +371,5 @@ export async function hashify(input: string): Promise<string> {
372371

373372
return hash;
374373
}
374+
375+
export const cacheManager = await initCacheManager(Deno.cwd());

packages/cli/lib/git.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import $ from '@david/dax';
22
import { join } from '@std/path';
33
import { logger } from './logger.ts';
4+
import type { Project } from './graph.ts';
5+
46
export async function getChangedFiles(baseBranch = 'main'): Promise<string[]> {
57
try {
68
// Get the merge base commit
@@ -39,20 +41,20 @@ export async function getChangedFiles(baseBranch = 'main'): Promise<string[]> {
3941

4042
export function getAffectedPackages(
4143
changedFiles: string[],
42-
packages: { packageJson: { name: string }; cwd: string }[],
44+
packages: Project[],
4345
): Set<string> {
4446
const affectedPackages = new Set<string>();
4547

4648
for (const pkg of packages) {
47-
const packagePath = pkg.cwd;
49+
const packagePath = pkg.path;
4850

4951
// Check if any changed file is within this package's directory
5052
const isAffected = changedFiles.some((file) =>
5153
join(Deno.cwd(), file).startsWith(packagePath)
5254
);
5355

5456
if (isAffected) {
55-
affectedPackages.add(pkg.packageJson.name);
57+
affectedPackages.add(pkg.name);
5658
}
5759
}
5860

packages/cli/lib/gitignore.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export function parseGitignore(gitignore: string) {
2+
const values = gitignore.split('\n').map((file) => file.trim()).filter(
3+
(file) => {
4+
if (!file) {
5+
return false;
6+
}
7+
8+
if (file.startsWith('#')) {
9+
return false;
10+
}
11+
12+
return true;
13+
},
14+
);
15+
16+
// format to glob patterns
17+
return values.map((value) => {
18+
if (value.endsWith('/')) {
19+
value = `${value}**`;
20+
}
21+
22+
if (value.startsWith('/')) {
23+
value = `**${value}`;
24+
}
25+
26+
return value;
27+
});
28+
}

0 commit comments

Comments
 (0)