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

#10 Updating code to version 2.0.0. #11

Merged
merged 1 commit into from
Aug 19, 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
3 changes: 2 additions & 1 deletion .c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"src/**/*.ts"
],
"exclude": [
"src/__test__/**/*.*",
"src/**/__test__/**/*.*",
"**/*.d.ts",
"**/*.types.ts",
"src/index.ts"
],
"reporter": [
Expand Down
46 changes: 32 additions & 14 deletions .eslintrc.library.cjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
// ESLint config for formatting the <project name>/src/**/*.ts files.
module.exports = {
root: true,
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
// See https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21
"plugin:type-only-import/recommended",
"plugin:jsdoc/recommended-typescript-error",
"plugin:prettier/recommended",
"plugin:sonarjs/recommended"
],
plugins: ["prettier"],
plugins: [
"type-only-import",
"jsdoc",
"prettier"
],
parser: "@typescript-eslint/parser",
env: {
node: true,
es2020: true
},
parserOptions: {
project: "./tsconfig.json",
sourceType: "module",
ecmaVersion: 2020,
ecmaVersion: "latest",
tsconfigRootDir: __dirname,
},
rules: {
Expand All @@ -31,13 +33,29 @@ module.exports = {
"no-useless-return": "error",
"no-console": "error",
"sonarjs/no-nested-template-literals": "off", // Nested template literals are OK really
},
settings: {
"import/resolver": {
node: {
paths: ["src"],
extensions: [".ts"] // Add .tsx, .js, .jsx if needed
"jsdoc/require-file-overview": "error",
"jsdoc/require-jsdoc": [
"error",
{
"publicOnly": true,
"require": {
"ArrowFunctionExpression": true,
"ClassDeclaration": true,
"ClassExpression": true,
"FunctionDeclaration": true,
"FunctionExpression": true,
"MethodDefinition": true
},
"exemptEmptyConstructors": true,
"exemptEmptyFunctions": false,
"enableFixer": false,
"contexts": [
"TSInterfaceDeclaration",
"TSTypeAliasDeclaration",
"TSMethodSignature",
"TSPropertySignature"
]
}
}
]
}
};
17 changes: 17 additions & 0 deletions .eslintrc.out-ts.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ESLint config for formatting the resulting .d.ts files (<project name>/dist-ts/**/*.d.ts) that end up in NPM package for typing information.
const { extends: extendsArray, plugins, rules } = require("./.eslintrc.cjs");
module.exports = {
root: true,
extends: extendsArray.filter((ext) => ext.startsWith("plugin:jsdoc/") || ext.startsWith("plugin:prettier/")),
plugins: plugins.filter((plugin) => plugin === "jsdoc" || plugin === "prettier"),
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.out.json",
sourceType: "module",
ecmaVersion: "latest",
tsconfigRootDir: __dirname,
},
rules: Object.fromEntries(Object.entries(rules).filter(([ruleKey]) => ruleKey.startsWith("jsdoc/") || ruleKey.startsWith("prettier/"))),
// So we won't get errors on comments disable e.g. @typescript-eslint/xyz rules.
noInlineConfig: true,
};
19 changes: 19 additions & 0 deletions .eslintrc.out.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ESLint config for formatting the resulting .[m]js files (<project name>/dist-(cjs|mjs)/**/*.[m]js) that end up in NPM package.
module.exports = {
root: true,
extends: [
"plugin:path-import-extension/recommended",
"plugin:prettier/recommended",
],
plugins: [
"path-import-extension",
"prettier"
],
parser: "@babel/eslint-parser",
parserOptions: {
requireConfigFile: false
},
rules: {
"prettier/prettier": "error",
}
};
27 changes: 0 additions & 27 deletions .eslintrc.output.cjs

This file was deleted.

34 changes: 16 additions & 18 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ on:
default: |
tyras_post_run ()
{
echo 'No post-run.'
cd "$1"
cp ../LICENSE ./LICENSE.txt
# Note - yarn doesn't have functionality to install package without saving it to package.json (!)
# So we use global install instead.
yarn global add "@jsdevtools/npm-publish@$(cat ../versions/npm-publish)"
npm-publish --dry-run --access public
}
secrets:
npm-publish-token:
Expand All @@ -30,7 +35,8 @@ jobs:
build_and_test:
strategy:
matrix:
dir: [ server ]
dir:
- server
runs-on: ubuntu-latest
name: Build and test ${{ matrix.dir }}
steps:
Expand Down Expand Up @@ -63,31 +69,23 @@ jobs:

./scripts/test.sh '${{ matrix.dir }}' coverage

- id: lint
name: Lint ${{ matrix.dir }}
shell: bash
run: |
set -e

./scripts/lint.sh '${{ matrix.dir }}'

# Run build *after* tests - since tests no longer require transpiled JS to run
# We still want to run build to catch any TS error possibly lurking somewhere.
# Because we test first and build then, we can do compilation without __tests__ directory.
# We re-add it to src folder in order to include it in published NPM package (if CD pipeline).
# Remember to also remove 'type' property from package.json, as it is no longer needed at this point.
- id: compile
name: Compile ${{ matrix.dir }}
shell: bash
run: |
set -e

# We can't redirect immediately back to same file, because processes are async, and we will end up with empty package.json
cat '${{ matrix.dir }}/package.json' | jq -M 'del(.type)' > '${{ matrix.dir }}/package.json.new'
mv '${{ matrix.dir }}/package.json.new' '${{ matrix.dir }}/package.json'
./scripts/build.sh '${{ matrix.dir }}' ci
ls -al '${{ matrix.dir }}/dist-cjs' || echo 'No dist folder - TS-only package!'
ls -al '${{ matrix.dir }}/dist-mjs' || echo 'No dist folder - TS-only package!'

- id: lint
name: Lint ${{ matrix.dir }}
shell: bash
run: |
set -e

./scripts/lint.sh '${{ matrix.dir }}'

- id: coverage
name: Upload coverage for '${{ matrix.dir }}'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ build
dist*
coverage
.yarn
yarn-*.log
*/.eslintrc*.cjs
*/tsconfig*.json
9 changes: 9 additions & 0 deletions scripts/generate-stub-package-json.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

const fs = require("fs");
const { version } = JSON.parse(fs.readFileSync("package.json"));
fs.writeFileSync(
"dist-cjs/package.json",
// Just version is enough
JSON.stringify({ version })
);
6 changes: 4 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
yarn install "$@"

cp .eslintrc.library.cjs "${TYRAS_LIB_DIR}/.eslintrc.cjs"
cp .eslintrc.output.cjs "${TYRAS_LIB_DIR}"
cp .eslintrc.out.cjs "${TYRAS_LIB_DIR}"
cp .eslintrc.out-ts.cjs "${TYRAS_LIB_DIR}"
cp tsconfig.library.json "${TYRAS_LIB_DIR}/tsconfig.json"
cp tsconfig.build.json "${TYRAS_LIB_DIR}"
cp tsconfig.build.json "${TYRAS_LIB_DIR}"
cp tsconfig.out.json "${TYRAS_LIB_DIR}"
26 changes: 26 additions & 0 deletions scripts/remove-empty-js-files.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node

const fs = require("fs");
const glob = require("glob");

glob
// Find all CommonJS files
.sync("dist-cjs/**/*.js")
// Read their contents while remembering the file path
.map((file) => ({ file, contents: fs.readFileSync(file, "utf8") }))
// Check whether the contents match what is emitted by a file without anything runtime-living to export
.filter(({ contents }) => contents === '"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\n')
// Delete the files
.map(({ file }) => fs.unlinkSync(file))
;

glob
// Find all ESM files
.sync("dist-esm/**/*.js")
// Read their contents while remembering the file path
.map((file) => ({ file, contents: fs.readFileSync(file, "utf8") }))
// Check whether the contents match what is emitted by a file without anything runtime-living to export
.filter(({ contents }) => contents === 'export {};\n')
// Delete the files
.map(({ file }) => fs.unlinkSync(file))
;
84 changes: 51 additions & 33 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ty-ras/server-express",
"version": "0.10.0",
"version": "2.0.0",
"author": {
"name": "Stanislav Muhametsin",
"email": "[email protected]",
Expand All @@ -13,59 +13,77 @@
},
"files": [
"./src",
"./dist-mjs",
"./dist-ts",
"./dist-esm",
"./dist-cjs",
"README.md",
"LICENSE.txt"
],
"type": "module",
"main": "./dist-cjs/index.js",
"module": "./dist-mjs/index.mjs",
"types": "./src/index.ts",
"module": "./dist-esm/index.js",
"types": "./dist-ts/index.d.ts",
"exports": {
".": {
"types": "./src/index.ts",
"import": "./dist-mjs/index.mjs",
"types": "./dist-ts/index.d.ts",
"import": "./dist-esm/index.js",
"require": "./dist-cjs/index.js"
}
},
"dependencies": {
"@ty-ras/server": "0.10.1",
"@ty-ras/endpoint-prefix": "0.10.1"
"@ty-ras/server": "^2.0.0"
},
"peerDependencies": {
"express": "^4.18.1"
"express": "^4.18.2",
"http2-express-bridge": "^1.0.7"
},
"devDependencies": {
"@babel/core": "7.19.3",
"@babel/eslint-parser": "7.19.1",
"@types/express": "4.17.14",
"@types/node": "18.7.18",
"@typescript-eslint/eslint-plugin": "5.38.0",
"@typescript-eslint/parser": "5.38.0",
"@ty-ras/server-test-support": "0.10.5",
"ava": "4.3.3",
"@ava/get-port": "2.0.0",
"c8": "7.12.0",
"eslint": "8.23.1",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-sonarjs": "0.15.0",
"express": "4.18.1",
"prettier": "2.7.1",
"raw-body": "2.5.1",
"@babel/core": "7.22.10",
"@babel/eslint-parser": "7.22.10",
"@ty-ras/server-test-support": "2.0.0",
"@typescript-eslint/eslint-plugin": "6.3.0",
"@typescript-eslint/parser": "6.3.0",
"@types/express": "4.17.17",
"@types/node": "18.16.3",
"@types/node-forge": "1.3.4",
"ava": "5.3.1",
"c8": "8.0.1",
"eslint": "8.47.0",
"eslint-plugin-jsdoc": "46.4.6",
"eslint-plugin-path-import-extension": "0.9.0",
"eslint-plugin-type-only-import": "0.9.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-sonarjs": "0.20.0",
"express": "4.18.2",
"madge": "6.1.0",
"node-forge": "1.3.1",
"prettier": "3.0.1",
"ts-node": "10.9.1",
"typescript": "4.8.3"
"typescript": "5.1.6"
},
"scripts": {
"build:run": "yarn run lint && yarn run tsc",
"build:ci": "yarn run clear-build-artifacts && yarn run tsc --outDir ./dist-mjs && yarn run rename-js-to-mjs && yarn run tsc --module CommonJS --outDir ./dist-cjs && yarn run format-output-files",
"clear-build-artifacts": "rm -rf dist dist-cjs dist-mjs build",
"format-output-files": "eslint --no-eslintrc --config '.eslintrc.output.cjs' --fix 'dist-cjs/*js' 'dist-mjs/*js'",
"lint": "eslint ./src --ext .ts,.tsx",
"rename-js-to-mjs": "find dist-mjs -name '*.js' -type f -exec sh -c 'for f in \"$@\"; do mv -- \"$f\" \"${f%.js}.mjs\"; done' -- {} +",
"build:ci": "yarn run clear-build-artifacts && yarn run compile-d-ts-files && yarn run tsc --outDir ./dist-esm && yarn run tsc --module CommonJS --outDir ./dist-cjs && yarn run remove-empty-js-files && yarn run generate-stub-package-json-for-cjs && yarn run format-output-files",
"clear-build-artifacts": "rm -rf dist dist-ts dist-cjs dist-esm build",
"compile-d-ts-files": "yarn run tsc --removeComments false --emitDeclarationOnly --declaration --declarationDir ./dist-ts && yarn run tsc:plain --project tsconfig.out.json",
"format-output-files": "yarn run format-output-files-ts && yarn run format-output-files-js",
"format-output-files-ts": "eslint --no-eslintrc --config '.eslintrc.out-ts.cjs' --fix --fix-type layout './dist-ts/**/*.ts'",
"format-output-files-js": "eslint --no-eslintrc --config '.eslintrc.out.cjs' --fix 'dist-cjs/**/*js' 'dist-esm/**/*js'",
"generate-stub-package-json-for-cjs": "../scripts/generate-stub-package-json.cjs",
"lint": "yarn run lint:eslint && yarn run lint:circular",
"lint:circular": "madge --circular --no-color --no-spinner --extensions ts --warning ./src",
"lint:eslint": "eslint ./src --ext .ts,.tsx",
"remove-empty-js-files": "../scripts/remove-empty-js-files.cjs",
"tsc": "tsc --project tsconfig.build.json",
"test:coverage": "c8 ava",
"test:run": "ava"
"tsc:plain": "tsc",
"test:coverage": "c8 --temp-directory /tmp ava",
"test:run": "c8 --temp-directory /tmp --reporter text ava"
},
"resolutions": {
"detective-typescript": "11.1.0",
"dependency-tree": "10.0.9",
"precinct": "11.0.5"
}
}
Loading