@repokit/core 1.7.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
+ import { TSCompiler } from "./TSCompiler.mjs";
2
+
1
3
  //#region externals/CommandParser.d.ts
2
- declare class CommandParser {
3
- private static compiler?;
4
+ declare class CommandParser extends TSCompiler {
4
5
  static parse(): Promise<void>;
5
6
  private static parseCommand;
6
7
  private static parsePaths;
@@ -1,25 +1,20 @@
1
- import { TSCompiler } from "./TSCompiler.mjs";
2
1
  import { RepoKitCommand } from "./RepoKitCommand.mjs";
3
- import { ConcurrencyPool } from "./ConcurrencyPool.mjs";
4
- import { parseArgs } from "node:util";
5
- import { join } from "node:path";
6
- import { stat } from "node:fs/promises";
2
+ import { TSCompiler } from "./TSCompiler.mjs";
7
3
  import { existsSync } from "node:fs";
4
+ import { stat } from "node:fs/promises";
5
+ import { join } from "node:path";
6
+ import { parseArgs } from "node:util";
8
7
  //#region externals/CommandParser.ts
9
- var CommandParser = class {
10
- static compiler;
8
+ var CommandParser = class extends TSCompiler {
11
9
  static async parse() {
12
10
  const { paths, root } = this.parsePaths();
13
11
  if (!root || !existsSync(root) || !(await stat(root)).isDirectory()) return console.log(JSON.stringify([]));
14
- this.compiler = new TSCompiler(root, "parse_commands");
15
- const pool = new ConcurrencyPool();
16
- const pathList = paths.split(",").filter(Boolean);
17
- const commands = await Promise.all(pathList.map((path) => pool.enqueue(() => this.parseCommand(root, path))));
12
+ const commands = paths.split(",").filter(Boolean).map((path) => this.parseCommand(join(root, path)));
18
13
  console.log(JSON.stringify(commands.flat()));
19
14
  }
20
- static async parseCommand(root, path) {
15
+ static parseCommand(path) {
21
16
  const commands = [];
22
- const declaredExports = await this.compiler?.compile?.(join(root, path));
17
+ const declaredExports = super.compile(path);
23
18
  for (const key in declaredExports) if (declaredExports[key] instanceof RepoKitCommand) commands.push({
24
19
  ...declaredExports[key],
25
20
  location: path
@@ -2,7 +2,7 @@ import { TSCompiler } from "./TSCompiler.mjs";
2
2
 
3
3
  //#region externals/ConfigurationParser.d.ts
4
4
  declare class ConfigurationParser extends TSCompiler {
5
- static parse(): Promise<void>;
5
+ static parse(): void;
6
6
  private static parseRoot;
7
7
  }
8
8
  //#endregion
@@ -1,15 +1,14 @@
1
1
  import { TSCompiler } from "./TSCompiler.mjs";
2
2
  import { RepoKitConfig } from "./RepoKitConfig.mjs";
3
- import { parseArgs } from "node:util";
4
- import { join } from "node:path";
5
3
  import { existsSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { parseArgs } from "node:util";
6
6
  //#region externals/ConfigurationParser.ts
7
7
  var ConfigurationParser = class extends TSCompiler {
8
- static async parse() {
9
- const root = this.parseRoot();
10
- const path = join(root, "repokit.ts");
8
+ static parse() {
9
+ const path = join(this.parseRoot(), "repokit.ts");
11
10
  if (!existsSync(path)) return;
12
- const config = await new TSCompiler(root, "parse_configuration").compile(path);
11
+ const config = super.compile(path);
13
12
  for (const key in config) if (config[key] instanceof RepoKitConfig) return console.log(JSON.stringify(config[key].toScoped(path)));
14
13
  }
15
14
  static parseRoot() {
@@ -1,10 +1,8 @@
1
1
  //#region externals/TSCompiler.d.ts
2
2
  declare class TSCompiler {
3
- readonly root: string;
4
- readonly command: string;
5
- private static readonly TMP_FILE_NAME;
6
- constructor(root: string, command: string);
7
- compile(path: string): Promise<any>;
3
+ private static readonly compilerOptions;
4
+ static compile<T extends Record<string, unknown>>(path: string): T;
5
+ private static import;
8
6
  }
9
7
  //#endregion
10
8
  export { TSCompiler };
@@ -1,20 +1,28 @@
1
- import { basename, resolve } from "node:path";
2
- import { readFile, rm, writeFile } from "node:fs/promises";
3
- import { transform } from "@swc/core";
1
+ import { __require } from "./_virtual/_rolldown/runtime.mjs";
2
+ import { register } from "ts-node";
4
3
  //#region externals/TSCompiler.ts
5
- var TSCompiler = class TSCompiler {
6
- static TMP_FILE_NAME = ".repokit_tmp.js";
7
- constructor(root, command) {
8
- this.root = root;
9
- this.command = command;
4
+ var TSCompiler = class {
5
+ static compilerOptions = {
6
+ swc: true,
7
+ typeCheck: false,
8
+ transpileOnly: true,
9
+ compilerOptions: {
10
+ noEmit: true,
11
+ module: "commonjs",
12
+ isolatedModules: false
13
+ },
14
+ moduleTypes: { "**": "cjs" }
15
+ };
16
+ static compile(path) {
17
+ const compiler = register(this.compilerOptions);
18
+ compiler.enabled(true);
19
+ const result = this.import(path);
20
+ compiler.enabled(false);
21
+ return result;
10
22
  }
11
- async compile(path) {
12
- const result = await transform((await readFile(path)).toString(), { module: { type: "es6" } });
13
- const target = `${resolve(path, "../")}/${basename(path)}${TSCompiler.TMP_FILE_NAME}`;
14
- await writeFile(target, result.code);
15
- const config = await import(target);
16
- await rm(target, { force: true });
17
- return config;
23
+ static import(filePath) {
24
+ const _module = __require(filePath);
25
+ return _module?.__esModule ? _module : { default: _module };
18
26
  }
19
27
  };
20
28
  //#endregion
@@ -0,0 +1,5 @@
1
+ import { createRequire } from "node:module";
2
+ //#region \0rolldown/runtime.js
3
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
4
+ //#endregion
5
+ export { __require };
@@ -1,7 +1,5 @@
1
1
  import { ConfigurationParser } from "../ConfigurationParser.mjs";
2
2
  //#region externals/commands/parse_configuration.ts
3
- (async () => {
4
- await ConfigurationParser.parse();
5
- })();
3
+ ConfigurationParser.parse();
6
4
  //#endregion
7
5
  export {};
@@ -1,34 +1,26 @@
1
- import { parseArgs } from "node:util";
2
- import { join } from "node:path";
3
- import { stat } from "node:fs/promises";
4
1
  import { existsSync } from "node:fs";
5
-
6
- import type { ILocatedCommand } from "./types";
7
- import { TSCompiler } from "./TSCompiler";
2
+ import { stat } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { parseArgs } from "node:util";
8
5
  import { RepoKitCommand } from "./RepoKitCommand";
9
- import { ConcurrencyPool } from "./ConcurrencyPool";
6
+ import { TSCompiler } from "./TSCompiler";
7
+ import type { ILocatedCommand } from "./types";
10
8
  /* oxlint-disable typescript-eslint(no-misused-spread) */
11
9
 
12
- export class CommandParser {
13
- private static compiler?: TSCompiler;
14
-
10
+ export class CommandParser extends TSCompiler {
15
11
  public static async parse() {
16
12
  const { paths, root } = this.parsePaths();
17
13
  if (!root || !existsSync(root) || !(await stat(root)).isDirectory()) {
18
14
  return console.log(JSON.stringify([]));
19
15
  }
20
- this.compiler = new TSCompiler(root, "parse_commands");
21
- const pool = new ConcurrencyPool<ILocatedCommand[]>();
22
16
  const pathList = paths.split(",").filter(Boolean);
23
- const commands = await Promise.all(
24
- pathList.map(path => pool.enqueue(() => this.parseCommand(root, path))),
25
- );
17
+ const commands = pathList.map(path => this.parseCommand(join(root, path)));
26
18
  console.log(JSON.stringify(commands.flat()));
27
19
  }
28
20
 
29
- private static async parseCommand(root: string, path: string) {
21
+ private static parseCommand(path: string) {
30
22
  const commands: ILocatedCommand[] = [];
31
- const declaredExports = await this.compiler?.compile?.(join(root, path));
23
+ const declaredExports = super.compile(path);
32
24
  for (const key in declaredExports) {
33
25
  if (declaredExports[key] instanceof RepoKitCommand) {
34
26
  commands.push({ ...declaredExports[key], location: path });
@@ -1,11 +1,10 @@
1
1
  import { AutoIncrementingID } from "@figliolia/event-emitter";
2
-
3
2
  import type { AsyncTask } from "./types";
4
3
 
5
4
  export class ConcurrencyPool<T> {
6
5
  private readonly IDs = new AutoIncrementingID();
7
6
  private readonly activeTasks = new Map<string, Promise<T>>();
8
- constructor(public readonly maxConcurrency: number = 10) {}
7
+ constructor(public readonly maxConcurrency = 10) {}
9
8
 
10
9
  public async enqueue(task: AsyncTask<T>) {
11
10
  if (this.activeTasks.size === this.maxConcurrency) {
@@ -1,19 +1,17 @@
1
- import { parseArgs } from "node:util";
2
- import { join } from "node:path";
3
1
  import { existsSync } from "node:fs";
4
-
5
- import { TSCompiler } from "./TSCompiler";
2
+ import { join } from "node:path";
3
+ import { parseArgs } from "node:util";
6
4
  import { RepoKitConfig } from "./RepoKitConfig";
5
+ import { TSCompiler } from "./TSCompiler";
7
6
 
8
7
  export class ConfigurationParser extends TSCompiler {
9
- public static async parse() {
8
+ public static parse() {
10
9
  const root = this.parseRoot();
11
10
  const path = join(root, "repokit.ts");
12
11
  if (!existsSync(path)) {
13
12
  return;
14
13
  }
15
- const compiler = new TSCompiler(root, "parse_configuration");
16
- const config = await compiler.compile(path);
14
+ const config = super.compile(path);
17
15
  for (const key in config) {
18
16
  if (config[key] instanceof RepoKitConfig) {
19
17
  return console.log(JSON.stringify(config[key].toScoped(path)));
@@ -1,5 +1,5 @@
1
- import type { ICommand, IRepoKitConfig } from "./types";
2
1
  import { RepoKitCommand } from "./RepoKitCommand";
2
+ import type { ICommand, IRepoKitConfig } from "./types";
3
3
  /* eslint-disable typescript-eslint(no-misused-spread */
4
4
 
5
5
  export class RepoKitConfig implements Required<IRepoKitConfig> {
@@ -1,26 +1,31 @@
1
- import { basename, resolve } from "node:path";
2
- import { readFile, rm, writeFile } from "node:fs/promises";
3
-
4
- import { transform } from "@swc/core";
1
+ import type { RegisterOptions } from "ts-node";
2
+ import { register } from "ts-node";
5
3
 
6
4
  export class TSCompiler {
7
- private static readonly TMP_FILE_NAME = ".repokit_tmp.js";
8
- constructor(
9
- public readonly root: string,
10
- public readonly command: string,
11
- ) {}
5
+ private static readonly compilerOptions: RegisterOptions = {
6
+ swc: true,
7
+ typeCheck: false,
8
+ transpileOnly: true,
9
+ compilerOptions: {
10
+ noEmit: true,
11
+ module: "commonjs",
12
+ isolatedModules: false,
13
+ },
14
+ moduleTypes: {
15
+ "**": "cjs",
16
+ },
17
+ };
18
+
19
+ public static compile<T extends Record<string, unknown>>(path: string) {
20
+ const compiler = register(this.compilerOptions);
21
+ compiler.enabled(true);
22
+ const result = this.import(path) as T;
23
+ compiler.enabled(false);
24
+ return result;
25
+ }
12
26
 
13
- public async compile(path: string) {
14
- const source = (await readFile(path)).toString();
15
- const result = await transform(source, {
16
- module: {
17
- type: "es6",
18
- },
19
- });
20
- const target = `${resolve(path, "../")}/${basename(path)}${TSCompiler.TMP_FILE_NAME}`;
21
- await writeFile(target, result.code);
22
- const config = await import(target);
23
- await rm(target, { force: true });
24
- return config;
27
+ private static import(filePath: string) {
28
+ const _module = require(filePath);
29
+ return _module?.__esModule ? _module : { default: _module };
25
30
  }
26
31
  }
@@ -1,5 +1,5 @@
1
1
  import { ConfigurationParser } from "../ConfigurationParser";
2
2
 
3
- void (async () => {
4
- await ConfigurationParser.parse();
3
+ (() => {
4
+ ConfigurationParser.parse();
5
5
  })();
@@ -1,3 +1,3 @@
1
- export * from "./RepoKitConfig";
2
1
  export * from "./RepoKitCommand";
2
+ export * from "./RepoKitConfig";
3
3
  export * from "./types";
@@ -1,4 +1,3 @@
1
-
2
1
  CWD=$(pwd)
3
2
 
4
3
  REPLACEMENT="/node_modules"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repokit/core",
3
- "version": "1.7.1",
3
+ "version": "1.9.0",
4
4
  "description": "A knowledgebase for your repository - wrapped in a CLI",
5
5
  "keywords": [
6
6
  "cli",
@@ -47,14 +47,22 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@figliolia/event-emitter": "^1.2.0",
50
- "@swc/core": "^1.15.18"
50
+ "@swc/core": "^1.15.18",
51
+ "ts-node": "^10.9.2"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@figliolia/child-process": "^1.0.4",
54
55
  "@types/node": "^25.3.0",
55
- "oxfmt": "^0.36.0",
56
+ "@typescript-eslint/eslint-plugin": "^8.57.1",
57
+ "@typescript-eslint/parser": "^8.57.1",
58
+ "eslint": "^10.0.3",
59
+ "eslint-import-resolver-typescript": "^4.4.4",
60
+ "eslint-plugin-import": "^2.32.0",
61
+ "eslint-plugin-simple-import-sort": "^12.1.1",
62
+ "eslint-plugin-unused-imports": "^4.4.1",
63
+ "oxfmt": "^0.41.0",
56
64
  "oxlint": "^1.42.0",
57
- "oxlint-tsgolint": "^0.16.0",
65
+ "oxlint-tsgolint": "^0.17.0",
58
66
  "tsdown": "^0.21.0",
59
67
  "tsx": "^4.21.0",
60
68
  "typescript": "^5.9.3"