Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add internal to methods #35

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For everything about Nalanda's documentation, head over to the `documentation` d

1. ensure you are in `dev` branch and do `git pull origin dev`

1. Run `pnpm -r --filter scripts set-version x.y.z` to bump the version.
1. Run `pnpm -r --filter misc set-version x.y.z` to bump the version.

1. Go to github and create a new release with the tag that was created in the previous step.

Expand Down
6 changes: 3 additions & 3 deletions config/eslint-config-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"eslint": "^8.50.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"tsconfig": "workspace:*",
"typescript": "^5.2.2"
"tsconfig": "workspace:*"
},
"devDependencies": {
"npm-run-all": "^4.1.5",
"tsup": "^7.2.0"
"tsup": "^7.2.0",
"typescript": "^5.2.2"
}
}
3 changes: 2 additions & 1 deletion config/tsconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"devDependencies": {
"npm-run-all": "^4.1.5",
"tsup": "^7.2.0"
"tsup": "^7.2.0",
"typescript": "^5.2.2"
}
}
3 changes: 2 additions & 1 deletion config/tsup-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"access": "public"
},
"devDependencies": {
"tsup": "^7.2.0"
"tsup": "^7.2.0",
"typescript": "^5.2.2"
}
}
12 changes: 3 additions & 9 deletions config/tsup-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"extends": "tsconfig/library.json",
"include": [
"."
],
"include": ["."],
"compilerOptions": {
"checkJs": true
},
"exclude": [
"dist",
"build",
"node_modules"
]
}
"exclude": ["dist", "build", "node_modules"]
}
35 changes: 35 additions & 0 deletions k.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fs = require('fs');
const path = require('path');

const IMPORT_STATEMENT =
"import { expect, jest, test } from '@jest/globals';\n";

function addImportStatementToTestFiles(dir) {
// Read all items in the directory.
const items = fs.readdirSync(dir);

for (const item of items) {
const fullPath = path.join(dir, item);

const stats = fs.statSync(fullPath);

if (stats.isDirectory()) {
// If the item is a directory, recurse into it.
addImportStatementToTestFiles(fullPath);
} else if (stats.isFile() && item.endsWith('.test.ts')) {
// If the item is a .test.ts file, add the import statement.
const fileContent = fs.readFileSync(fullPath, 'utf-8');

if (!fileContent.startsWith(IMPORT_STATEMENT)) {
const updatedContent = IMPORT_STATEMENT + fileContent;
fs.writeFileSync(fullPath, updatedContent, 'utf-8');
console.log(`Updated file: ${fullPath}`);
}
}
}
}

const directoryToStart = './'; // You can modify this path to be the directory you want to start from.
addImportStatementToTestFiles(directoryToStart);

console.log('Processing completed.');
24 changes: 24 additions & 0 deletions misc/__test__/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, test } from '@jest/globals';
import { createKey } from '@nalanda/core';

test('test', () => {
const dep1Key = createKey('dep1Key', []);
const dep1Slice = dep1Key.slice({
fields: {},
});

const dep2Key = createKey('dep2Key', []);
const dep2Slice = dep2Key.slice({
fields: {},
});

const key = createKey('myKey', [dep1Slice, dep2Slice]);

const field1 = key.field(1);

const mySlice = key.slice({
fields: {},
});

expect(1).toBe(1);
});
6 changes: 6 additions & 0 deletions misc/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
},
clearMocks: true,
};
25 changes: 25 additions & 0 deletions misc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "misc",
"version": "0.0.0",
"private": true,
"license": "MIT",
"publishConfig": {
"access": "public"
},
"scripts": {
"set-version": "tsx ./set-version.ts",
"test:watch": "jest --watch",
"test": "jest"
},
"devDependencies": {
"jest": "^29.7.0",
"@jest/globals": "^29.7.0",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"@nalanda/core": "workspace:*",
"tsx": "^3.13.0",
"tsconfig": "workspace:*",
"typescript": "^5.2.2",
"@types/node": "20.8.2"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions misc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["."],
"exclude": ["node_modules"]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
"build": "pnpm -r run build",
"lint": "pnpm -r run lint",
"test": "pnpm -r run test",
"test:watch": "pnpm -r run test:watch",
"build-docs": "pnpm -r --filter documentation build",
"build-packages": "pnpm -r --filter \"./packages/**\" build",
"build-packages:watch": "pnpm -r --filter \"./packages/**\" build:watch",
"publish-alpha": "pnpm -r --filter \"./packages/**\" publish --tag alpha --otp ${npm_config_otp} --access public",
"publish-latest": "pnpm -r --filter \"./packages/**\" publish --tag latest --otp ${npm_config_otp} --access public"
},
Expand Down
18 changes: 8 additions & 10 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,37 @@
"typecheck": "tsc --noEmit",
"typecheck:watch": "tsc --noEmit --watch",
"test": "jest",
"test:watch": "jest --watch",
"lint": "npm-run-all -l --aggregate-output --parallel lint:*",
"lint:eslint": "eslint .",
"lint:tsc": "tsc --noEmit",
"lint:prettier": "prettier src --check",
"format": "prettier src --write",
"build": "tsup --config tsup.config.ts",
"prepack": "pnpm run build"
"build": "tsup --config tsup.config.ts && pnpm run patch-core-types",
"build:watch": "tsup --config tsup.config.ts --watch",
"prepack": "pnpm run build",
"patch-core-types": "tsx ./src/patch/patch-types.ts",
"generate-original-types": "tsup --config tsup.config.ts --dts-only --out-dir ./src/patch/original-types && pnpm prettier ./src/patch/original-types --write"
},
"files": [
"dist",
"src"
],
"devDependencies": {
"tsx": "^3.13.0",
"tsup-config": "workspace:*",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"@types/jest": "^29.5.5",
"eslint-config-custom": "workspace:*",
"jest": "^29.7.0",
"@jest/globals": "^29.7.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"tsconfig": "workspace:*",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"wait-for-expect": "^3.0.2"
},
"prettier": {
"singleQuote": true,
"trailingComma": "all",
"quoteProps": "consistent",
"arrowParens": "always",
"printWidth": 80
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/__tests__/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {
expect,
jest,
test,
describe,
beforeEach,
afterEach,
} from '@jest/globals';
import { testCleanup } from '../helpers/test-cleanup';
import { createKey } from '../slice/key';
import { createStore } from '../store';
Expand Down
24 changes: 16 additions & 8 deletions packages/core/src/__tests__/dependency-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {
expect,
jest,
test,
describe,
beforeEach,
afterEach,
} from '@jest/globals';
import { calcReverseDependencies as _calcReverseDependencies } from '../helpers/dependency-helpers';
import { Slice } from '../slice/slice';

Expand Down Expand Up @@ -38,14 +46,14 @@ const slX = createSlice('X');
const slY = createSlice('Y');

describe('calcReverseDependencies', () => {
it('should calculate reverse dependencies for case 1', () => {
test('should calculate reverse dependencies for case 1', () => {
const slices = [setDeps(sl1, ['2', '3'])];
const result = calcReverseDependencies(slices);
expect(result['2']).toEqual(new Set(['1']));
expect(result['3']).toEqual(new Set(['1']));
});

it('should calculate reverse dependencies for case 2', () => {
test('should calculate reverse dependencies for case 2', () => {
const slices = [
setDeps(sl0, ['1']),
setDeps(sl1, ['2', '3']),
Expand All @@ -58,7 +66,7 @@ describe('calcReverseDependencies', () => {
expect(result['3']).toEqual(new Set(['0', '1', '2']));
});

it('should calculate reverse dependencies for case 3', () => {
test('should calculate reverse dependencies for case 3', () => {
const slices = [
setDeps(sl0, ['1']),
setDeps(sl1, ['2', '3']),
Expand All @@ -71,7 +79,7 @@ describe('calcReverseDependencies', () => {
expect(result['3']).toEqual(new Set(['0', '1', '2']));
});

it('should calculate reverse dependencies for case 4.a', () => {
test('should calculate reverse dependencies for case 4.a', () => {
const slices = [
setDeps(sl0, ['1']),
setDeps(sl1, ['2']),
Expand All @@ -85,7 +93,7 @@ describe('calcReverseDependencies', () => {
expect(result['4']).toEqual(new Set(['1', '0', '2', '3']));
});

it('should calculate reverse dependencies for case 4.b', () => {
test('should calculate reverse dependencies for case 4.b', () => {
const slices = [
setDeps(sl1, ['2', '3']),
setDeps(slA, ['2', '3']),
Expand All @@ -99,7 +107,7 @@ describe('calcReverseDependencies', () => {
expect(result['B']).toEqual(new Set([]));
});

it('should calculate reverse dependencies for case 5', () => {
test('should calculate reverse dependencies for case 5', () => {
const slices = [
setDeps(slD, ['A', 'B', 'C']),
setDeps(slA, ['B']),
Expand All @@ -112,7 +120,7 @@ describe('calcReverseDependencies', () => {
expect(result['C']).toEqual(new Set(['D']));
});

it('should calculate reverse dependencies for case 6', () => {
test('should calculate reverse dependencies for case 6', () => {
const slices = [
setDeps(slX, ['C', 'A', 'B']),
setDeps(slC, ['F', 'R']),
Expand All @@ -130,7 +138,7 @@ describe('calcReverseDependencies', () => {
expect(result['X']).toEqual(new Set([]));
});

it('should calculate reverse dependencies for case 7', () => {
test('should calculate reverse dependencies for case 7', () => {
const slices = [
setDeps(slE, ['F', 'G', 'H']),
setDeps(slF, ['B', 'G']),
Expand Down
Loading