Skip to content

Commit

Permalink
chore(*): remove built-in tsyringe symbols and rule caches
Browse files Browse the repository at this point in the history
  • Loading branch information
almostSouji committed Dec 25, 2023
1 parent bc536e4 commit 3ed27be
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 51 deletions.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build:clean": "del-cli dist",
"build:check": "tsc --noEmit",
Expand All @@ -20,15 +23,14 @@
"dev": "node --enable-source-maps dist/index.js",
"test": "yarn build && node --enable-source-maps --test",
"test:only": "yarn test --test-only",
"prepare": "is-ci || husky install"
"prepare": "is-ci || husky install",
"prepublish": "tsc"
},
"dependencies": {
"chevrotain": "^11.0.3",
"octokit": "^3.1.2",
"re2": "^1.20.9",
"readdirp": "^3.6.0",
"reflect-metadata": "^0.2.1",
"tsyringe": "^4.8.0",
"yaml": "^2.3.4"
},
"devDependencies": {
Expand All @@ -47,5 +49,8 @@
"rimraf": "^5.0.5",
"typescript": "^5.3.3"
},
"engines": {
"node": ">=21.0.0"
},
"packageManager": "[email protected]"
}
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { evaluateOmega } from "./omega.js";
export * from "./rules.js";
export * from "./types/omega.js";
export { kRules } from "./utils/symbols.js";
export * from "./utils/validator.js";
28 changes: 3 additions & 25 deletions src/rules.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
import { readFile } from "node:fs/promises";
import { Octokit } from "octokit";
import readdirp from "readdirp";
import { container } from "tsyringe";
import { parse } from "yaml";
import type { Rule } from "./types/omega.js";
import { kRules } from "./utils/symbols.js";

/**
* Create a rule cache
*
* @returns A reference to the rule cache
*/
export function createRuleCache() {
const rules = new Map<string, Rule>();
container.register(kRules, { useValue: rules });
return rules;
}

/**
* Get the registered rule cache
*
* @returns A reference to the rule cache
*/
export function getRuleChache() {
return container.resolve<Map<string, Rule>>(kRules);
}
import type { Rule, RuleCache } from "./types/omega.js";

/**
* Load rules from a defined directory and all sub directories into the provided cache
Expand All @@ -33,7 +11,7 @@ export function getRuleChache() {
* @param cache - The rule cache to load rules into
* @returns A reference to the rule cache
*/
export async function loadRulesInto(path: string, cache: Map<string, Rule>) {
export async function loadRulesInto(path: string, cache: RuleCache) {
const ruleDir = readdirp(path, {
fileFilter: "*.yml",
});
Expand Down Expand Up @@ -100,7 +78,7 @@ export async function loadRuleRepositoryInto(
owner: string,
repository: string,
path: string,
cache: Map<string, Rule>,
cache: RuleCache,
) {
const result = await fetchRepositoryContents(owner, repository, path, []);

Expand Down
1 change: 0 additions & 1 deletion src/tests/rules.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable id-length */
import "reflect-metadata";
import assert from "node:assert";
import { fileURLToPath, URL } from "node:url";
import { describe, it } from "node:test";
Expand Down
1 change: 0 additions & 1 deletion src/tests/validator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "reflect-metadata";
import assert from "node:assert";
import { fileURLToPath, URL } from "node:url";
import { describe, it } from "node:test";
Expand Down
2 changes: 2 additions & 0 deletions src/types/omega.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type Rule = {
title: string;
};

export type RuleCache = Map<string, Rule>;

export type OmegaResult = {
matches: boolean;
rule: Rule;
Expand Down
1 change: 0 additions & 1 deletion src/utils/symbols.ts

This file was deleted.

20 changes: 1 addition & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6631,9 +6631,7 @@ __metadata:
prettier: "npm:^3.1.1"
re2: "npm:^1.20.9"
readdirp: "npm:^3.6.0"
reflect-metadata: "npm:^0.2.1"
rimraf: "npm:^5.0.5"
tsyringe: "npm:^4.8.0"
typescript: "npm:^5.3.3"
yaml: "npm:^2.3.4"
languageName: unknown
Expand Down Expand Up @@ -7185,13 +7183,6 @@ __metadata:
languageName: node
linkType: hard

"reflect-metadata@npm:^0.2.1":
version: 0.2.1
resolution: "reflect-metadata@npm:0.2.1"
checksum: 6ca3c674bb43cf8ec3a3f5f38c8730a6116335f8e562fcdcdf3a492af168c5a7f0e8f17476a5710c3fe6bf9b5d22e8a463f14c0e26e326339cab65e099900ef7
languageName: node
linkType: hard

"reflect.getprototypeof@npm:^1.0.4":
version: 1.0.4
resolution: "reflect.getprototypeof@npm:1.0.4"
Expand Down Expand Up @@ -8209,7 +8200,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^1.8.1, tslib@npm:^1.9.3":
"tslib@npm:^1.8.1":
version: 1.14.1
resolution: "tslib@npm:1.14.1"
checksum: 69ae09c49eea644bc5ebe1bca4fa4cc2c82b7b3e02f43b84bd891504edf66dbc6b2ec0eef31a957042de2269139e4acff911e6d186a258fb14069cd7f6febce2
Expand Down Expand Up @@ -8250,15 +8241,6 @@ __metadata:
languageName: node
linkType: hard

"tsyringe@npm:^4.8.0":
version: 4.8.0
resolution: "tsyringe@npm:4.8.0"
dependencies:
tslib: "npm:^1.9.3"
checksum: e13810e8ff39c4093acd0649bc5db3c164825827631e1522cd9d5ca8694a018447fa1c24f059ea54e93b1020767b1131b9dc9ce598dabfc9aa41c11544bbfe19
languageName: node
linkType: hard

"type-check@npm:^0.4.0, type-check@npm:~0.4.0":
version: 0.4.0
resolution: "type-check@npm:0.4.0"
Expand Down

0 comments on commit 3ed27be

Please sign in to comment.