Skip to content

Commit

Permalink
chore: convert to monorepo (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanwww authored Nov 9, 2024
1 parent 6b5b5cb commit 36f1e92
Show file tree
Hide file tree
Showing 79 changed files with 6,612 additions and 92 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"root": true,
"extends": "./configs/eslint/.eslintrc.basic.js",
"ignorePatterns": ["*.cjs", "*.js", "*.mjs", "/coverage", "/lib", "/lib-commonjs", "/packages", "/scripts"],
"parserOptions": {
"project": "./tsconfig.json"
}
}
6 changes: 6 additions & 0 deletions .github/workflows/regular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build Result
run: pnpm run build-result

- name: Lint
run: pnpm run lint

Expand All @@ -89,5 +92,8 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build Result
run: pnpm run build-result

- name: Do coverage test
run: pnpm run test-full
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# ------------------------------------------------------------------------------------------------------- Editor and IDE

.idea
.vscode

# ----------------------------------------------------------------------------------------------------------- Dependency
Expand All @@ -16,11 +17,14 @@ node_modules

/lib
/lib-commonjs
/packages/*/lib
/packages/*/lib-commonjs
/rust/target

# ----------------------------------------------------------------------------------------------------------------- Test

/coverage
/packages/*/coverage

# -------------------------------------------------------------------------------------------------------- Miscellaneous

Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pnpm run pre-commit
pnpm exec lint-staged
4 changes: 1 addition & 3 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"*.ts": [
"eslint --cache"
]
"*.ts": ["eslint --cache"]
}
31 changes: 9 additions & 22 deletions .eslintrc.js → configs/eslint/.eslintrc.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const naming = [
];

module.exports = {
root: true,
env: {
browser: true,
es2018: true,
Expand All @@ -58,31 +57,22 @@ module.exports = {
'plugin:jest/recommended',
'plugin:jest/style',
],
ignorePatterns: ['*.cjs', '*.js', '*.mjs', '/coverage', '/lib', '/lib-commonjs', '/scripts'],
plugins: ['@typescript-eslint', 'import', 'jest', 'prettier'],
parserOptions: {
project: './tsconfig.json',
},
settings: {
// Append 'ts' extensions to Airbnb 'import/extensions' setting
// Original: ['.js', '.mjs', '.jsx']
'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts'],

// Resolve type definition packages
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
// Override Airbnb's 'import/extensions'
'import/extensions': ['.js', '.jsx', '.ts', '.tsx'],

'import/internal-regex': '^src',

// Apply special parsing for TypeScript files
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'],
'@typescript-eslint/parser': ['.ts', '.tsx'],
},

// Append 'ts' extensions to Airbnb 'import/resolver' setting
// Original: ['.js', '.jsx', '.json']
// Override Airbnb's 'import/resolver'
'import/resolver': {
node: {
extensions: ['.mjs', '.js', '.jsx', '.json', '.ts', '.tsx', '.d.ts'],
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
},
},
},
Expand Down Expand Up @@ -362,11 +352,14 @@ module.exports = {
},
},
{
files: ['src/**/__tests__/*.{ts,tsx}', 'src/**/*.{spec,test}.{ts,tsx}', 'test/**/*.{ts,tsx}'],
files: ['src/**/__tests__/*.ts', 'src/**/*.{spec,test}.ts'],
rules: {
// https://eslint.org/docs/latest/rules/max-classes-per-file
'max-classes-per-file': 'off',

// https://eslint.org/docs/latest/rules/no-console
'no-console': 'off',

// https://typescript-eslint.io/rules/dot-notation
'@typescript-eslint/dot-notation': [
'error',
Expand All @@ -381,11 +374,5 @@ module.exports = {
'@typescript-eslint/unbound-method': 'off',
},
},
{
files: ['src/**/__tests__/*.{ts,tsx}', 'src/**/*.{spec,test}.{ts,tsx}'],
rules: {
'no-console': 'off',
},
},
],
};
19 changes: 10 additions & 9 deletions scripts/jest/jest.config.js → configs/jest/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const fs = require('node:fs');
const path = require('node:path');

const repository = path.join(__dirname, '../..');
const nodeModules = path.resolve(repository, 'node_modules');
const repo = path.join(__dirname, '../..');

/** @returns {import('@jest/types').Config.InitialOptions} */
function getConfig() {
const testSetup = path.resolve(repository, 'src/test.setup.ts');
const hasTestSetup = fs.existsSync(testSetup);
const packageJson = process.env.npm_package_json;
const packageDir = packageJson ? path.dirname(packageJson) : process.cwd();

const packageOwnTestSetup = path.resolve(packageDir, 'src/test.setup.ts');
const hasPackageOwnTestSetup = fs.existsSync(packageOwnTestSetup);

return {
rootDir: repository,
rootDir: packageDir,
roots: ['<rootDir>/src'],
cacheDirectory: path.resolve(nodeModules, '.cache/jest'),
cacheDirectory: path.resolve(repo, 'node_modules', '.cache/jest'),

setupFilesAfterEnv: hasTestSetup ? [testSetup] : [],
setupFilesAfterEnv: hasPackageOwnTestSetup ? [packageOwnTestSetup] : [],

collectCoverageFrom: [
'src/**/*.ts',
Expand All @@ -32,8 +34,7 @@ function getConfig() {
{
jsc: {
transform: {
react: { runtime: 'automatic' },
useDefineForClassFields: true,
useDefineForClassFields: false,
},
},
isModule: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"strict": true,
"stripInternal": true,
"target": "ES2018",
"useDefineForClassFields": false,
"verbatimModuleSyntax": true
}
}
7 changes: 7 additions & 0 deletions configs/tsconfigs/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "CommonJS",
"verbatimModuleSyntax": false
}
}
8 changes: 8 additions & 0 deletions configs/tsconfigs/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"removeComments": false
}
}
39 changes: 27 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,33 @@
},
"packageManager": "[email protected]+sha512.8e4c3550fb500e808dbc30bb0ce4dd1eb614e30b1c55245f211591ec2cdf9c611cabd34e1364b42f564bd54b3945ed0f49d61d1bbf2ec9bd74b866fcdc723276",
"scripts": {
"build": "concurrently -n cjs,esm,types \"pnpm run build:cjs\" \"pnpm run build:esm\" \"pnpm run build:types\"",
"build:cjs": "tsc --project tsconfigs/tsconfig.cjs.json",
"build:esm": "tsc --project tsconfigs/tsconfig.esm.json",
"build:types": "tsc --project tsconfigs/tsconfig.types.json",
"clean": "rimraf --glob coverage lib lib-commonjs tsconfigs/*.tsbuildinfo",
"format": "prettier --write \"**/*.{cjs,js,mjs,json,ts,yaml,yml}\"",
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"pre-commit": "lint-staged",
"build": "pnpm run build:root && pnpm run build:workspaces",
"build:workspaces": "pnpm run --recursive --stream build",
"build:root": "concurrently -n cjs,esm,types \"pnpm run build:root:cjs\" \"pnpm run build:root:esm\" \"pnpm run build:root:types\"",
"build:root:cjs": "tsc --project tsconfigs/tsconfig.cjs.json",
"build:root:esm": "tsc --project tsconfigs/tsconfig.esm.json",
"build:root:types": "tsc --project tsconfigs/tsconfig.types.json",
"build-result": "pnpm run --filter @result/result build",
"clean": "pnpm run clean:root && pnpm run clean:workspaces",
"clean:workspaces": "pnpm run --recursive --no-sort clean",
"clean:root": "rimraf --glob coverage lib lib-commonjs tsconfigs/*.tsbuildinfo",
"format": "pnpm run format:root && pnpm run format:workspaces",
"format:workspaces": "pnpm run --recursive --no-sort --stream format",
"format:root": "prettier --write \"**/*.{cjs,js,mjs,json,ts,yaml,yml}\"",
"lint": "pnpm run lint:root && pnpm run lint:workspaces",
"lint:workspaces": "pnpm run --recursive --no-sort --stream lint",
"lint:root": "eslint .",
"lint-fix": "pnpm run lint-fix:root && pnpm run lint-fix:workspaces",
"lint-fix:workspaces": "pnpm run --recursive --no-sort --stream lint-fix",
"lint-fix:root": "eslint . --fix",
"prepare": "husky",
"test": "node scripts/unit-test.js",
"test-full": "node scripts/unit-test.js",
"typecheck": "tsc --project tsconfig.json --noEmit --incremental false"
"test": "node scripts/unit-test.mjs --watch",
"test-full": "pnpm run test-full:root && pnpm run test-full:workspaces",
"test-full:workspaces": "pnpm run --recursive --no-sort --stream test-full",
"test-full:root": "node scripts/unit-test.mjs --coverage",
"typecheck": "pnpm run typecheck:root && pnpm run typecheck:workspaces",
"typecheck:workspaces": "pnpm run --recursive --no-sort --stream typecheck",
"typecheck:root": "tsc --project tsconfig.json --noEmit --incremental false"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand All @@ -61,6 +75,7 @@
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"chalk": "^5.3.0",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/json-serializr/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"root": true,
"extends": "../../configs/eslint/.eslintrc.basic.js",
"ignorePatterns": ["*.cjs", "*.js", "*.mjs", "/coverage", "/lib", "/lib-commonjs"],
"parserOptions": {
"project": "./tsconfig.json"
}
}
3 changes: 3 additions & 0 deletions packages/json-serializr/.lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*.ts": ["eslint --cache"]
}
8 changes: 8 additions & 0 deletions packages/json-serializr/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Compilation

/lib
/lib-commonjs

# Test

/coverage
1 change: 1 addition & 0 deletions packages/json-serializr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @result/json-serializr
68 changes: 68 additions & 0 deletions packages/json-serializr/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "@result/json-serializr",
"version": "0.6.0-alpha.0",
"description": "A json (de)serialization implementation using serializr for @result/result",
"exports": {
".": {
"types": "./lib/index.d.ts",
"node": "./lib-commonjs/index.js",
"import": "./lib/index.js",
"default": "./lib-commonjs/index.js"
},
"./cjs": "./lib-commonjs/index.js"
},
"main": "lib-commonjs/index.js",
"module": "lib/index.js",
"types": "lib/index.d.ts",
"homepage": "https://github.com/yifanwww/rustlike-result#readme",
"license": "MIT",
"author": "yifanwww <[email protected]> (https://github.com/yifanwww)",
"bugs": {
"url": "https://github.com/yifanwww/rustlike-result/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/yifanwww/rustlike-result.git",
"directory": "packages/json-serializr"
},
"packageManager": "[email protected]+sha512.8e4c3550fb500e808dbc30bb0ce4dd1eb614e30b1c55245f211591ec2cdf9c611cabd34e1364b42f564bd54b3945ed0f49d61d1bbf2ec9bd74b866fcdc723276",
"scripts": {
"build": "concurrently -n cjs,esm,types \"pnpm run build:cjs\" \"pnpm run build:esm\" \"pnpm run build:types\"",
"build:cjs": "tsc --project tsconfigs/tsconfig.cjs.json",
"build:esm": "tsc --project tsconfigs/tsconfig.esm.json",
"build:types": "tsc --project tsconfigs/tsconfig.types.json",
"clean": "rimraf --glob coverage lib lib-commonjs tsconfigs/*.tsbuildinfo",
"format": "prettier --write \"**/*.{cjs,js,mjs,json,ts,yaml,yml}\"",
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"test": "node ../../scripts/unit-test.mjs --watch",
"test-full": "node ../../scripts/unit-test.mjs --coverage",
"typecheck": "tsc --project tsconfig.json --noEmit --incremental false"
},
"dependencies": {
"@result/result": "workspace:0.6.0-alpha.0",
"serializr": "^3.0.2"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@swc/jest": "^0.2.36",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "3.2.5",
"rimraf": "^5.0.6",
"typescript": "5.4.5"
},
"files": [
"CHANGELOG.md",
"lib",
"lib-commonjs"
]
}
Loading

0 comments on commit 36f1e92

Please sign in to comment.