From 2d46e9fff8d3003ab1a14bd530fefcec9bdcccc9 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 16:51:31 -0500 Subject: [PATCH 01/13] Add GitHub Actions. --- .github/workflows/ci.yml | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a671b62 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + - uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - run: npm run lint -- --fix + - run: npm run tsc + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: 🤖 linting with autofix + branch: ${{ github.head_ref }} + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + - uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - run: npm run build + - run: npm test From 6ef545adaabe9fa571c841651f4652e56721ad2e Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 16:55:30 -0500 Subject: [PATCH 02/13] Rename command to tsc. --- .github/workflows/ci.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a671b62..10733d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,5 +38,5 @@ jobs: restore-keys: | ${{ runner.os }}-node- - run: npm ci - - run: npm run build + - run: npm run tsc - run: npm test diff --git a/package.json b/package.json index dfef21f..92510ff 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "bracketSpacing": true }, "scripts": { - "build": "tsc", + "tsc": "tsc", "lint": "eslint .", "test": "jest" }, From fe59b378968a445a81a8950db33b9361e72871e4 Mon Sep 17 00:00:00 2001 From: iheanyi Date: Thu, 28 Jul 2022 21:56:08 +0000 Subject: [PATCH 03/13] =?UTF-8?q?=F0=9F=A4=96=20linting=20with=20autofix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jest.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 5b0fa89..e678d63 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -14,7 +14,7 @@ export default { // cacheDirectory: "/private/var/folders/39/wx5hr2ps64d83gpwscpz2jg80000gn/T/jest_dx", // Automatically clear mock calls, instances, contexts and results before every test - clearMocks: true, + clearMocks: true // Indicates whether the coverage information should be collected while executing the test // collectCoverage: false, @@ -192,4 +192,4 @@ export default { // Whether to use watchman for file crawling // watchman: true, -}; +} From e58ef14d1e2f8add32fe0d0fd6e54ac0e4936387 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 16:56:57 -0500 Subject: [PATCH 04/13] Force build. From 4aba736e554f182a61710c83db2423415d472026 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 17:03:35 -0500 Subject: [PATCH 05/13] Add first tests. --- __tests__/text.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 __tests__/text.test.ts diff --git a/__tests__/text.test.ts b/__tests__/text.test.ts new file mode 100644 index 0000000..e0179ad --- /dev/null +++ b/__tests__/text.test.ts @@ -0,0 +1,17 @@ +import { utf8Encode } from '../src/text' + +describe('text', () => { + describe('utf8Encode', () => { + test('encodes "a" properly', () => { + expect(utf8Encode('a')).toEqual('a') + }) + + test('encodes "\\a" properly', () => { + expect(utf8Encode('\\a')).toEqual('\\a') + }) + + test('encodes blank string properly', () => { + expect(utf8Encode('')).toEqual('') + }) + }) +}) From eca39bc5e49baf3d53047d1e9c5806c70c8a725f Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 17:03:45 -0500 Subject: [PATCH 06/13] Get tests actually running. --- jest.config.ts | 3 ++ package-lock.json | 119 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + tsconfig.json | 3 +- 4 files changed, 125 insertions(+), 1 deletion(-) diff --git a/jest.config.ts b/jest.config.ts index e678d63..9d7e197 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -13,6 +13,9 @@ export default { // The directory where Jest should store its cached dependency information // cacheDirectory: "/private/var/folders/39/wx5hr2ps64d83gpwscpz2jg80000gn/T/jest_dx", + preset: 'ts-jest', + testEnvironment: 'node', + // Automatically clear mock calls, instances, contexts and results before every test clearMocks: true diff --git a/package-lock.json b/package-lock.json index 6388f85..ec841e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "eslint-plugin-prettier": "^4.2.1", "jest": "^28.1.3", "prettier": "^2.7.1", + "ts-jest": "^28.0.7", "ts-node": "^10.9.1", "typescript": "^4.7.4" } @@ -1721,6 +1722,18 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -3583,6 +3596,12 @@ "node": ">=8" } }, + "node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -4418,6 +4437,64 @@ "node": ">=8.0" } }, + "node_modules/ts-jest": { + "version": "28.0.7", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-28.0.7.tgz", + "integrity": "sha512-wWXCSmTwBVmdvWrOpYhal79bDpioDy4rTT+0vyUnE3ZzM7LOAAGG9NXwzkEL/a516rQEgnMmS/WKP9jBPCVJyA==", + "dev": true, + "dependencies": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^28.0.0", + "json5": "^2.2.1", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "7.x", + "yargs-parser": "^21.0.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/types": "^28.0.0", + "babel-jest": "^28.0.0", + "jest": "^28.0.0", + "typescript": ">=4.3" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", @@ -6013,6 +6090,15 @@ "update-browserslist-db": "^1.0.5" } }, + "bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "requires": { + "fast-json-stable-stringify": "2.x" + } + }, "bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -7413,6 +7499,12 @@ "p-locate": "^4.1.0" } }, + "lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -8007,6 +8099,33 @@ "is-number": "^7.0.0" } }, + "ts-jest": { + "version": "28.0.7", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-28.0.7.tgz", + "integrity": "sha512-wWXCSmTwBVmdvWrOpYhal79bDpioDy4rTT+0vyUnE3ZzM7LOAAGG9NXwzkEL/a516rQEgnMmS/WKP9jBPCVJyA==", + "dev": true, + "requires": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^28.0.0", + "json5": "^2.2.1", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "7.x", + "yargs-parser": "^21.0.1" + }, + "dependencies": { + "semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", diff --git a/package.json b/package.json index 92510ff..c0fc54c 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "eslint-plugin-prettier": "^4.2.1", "jest": "^28.1.3", "prettier": "^2.7.1", + "ts-jest": "^28.0.7", "ts-node": "^10.9.1", "typescript": "^4.7.4" } diff --git a/tsconfig.json b/tsconfig.json index 81e6824..2953a59 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "outDir": "dist", "removeComments": true, "allowJs": true, - "moduleResolution": "node" + "moduleResolution": "node", + "esModuleInterop": true } } From 52175a3d1f421c45030417654261a502f1762b2c Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 17:08:27 -0500 Subject: [PATCH 07/13] Fix up execution. --- jest.config.ts | 4 ++++ tsconfig.json | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jest.config.ts b/jest.config.ts index 9d7e197..e16e17c 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -3,6 +3,9 @@ * https://jestjs.io/docs/configuration */ +import { pathsToModuleNameMapper } from 'ts-jest' +import { compilerOptions } from './tsconfig.json' + export default { // All imported modules in your tests should be mocked automatically // automock: false, @@ -16,6 +19,7 @@ export default { preset: 'ts-jest', testEnvironment: 'node', + moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/' }), // Automatically clear mock calls, instances, contexts and results before every test clearMocks: true diff --git a/tsconfig.json b/tsconfig.json index 2953a59..a584576 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,8 @@ "removeComments": true, "allowJs": true, "moduleResolution": "node", - "esModuleInterop": true + "paths": {}, + "esModuleInterop": true, + "resolveJsonModule": true } } From b3ee825782451bad0ce9f634fea9d3c20d184632 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 17:19:34 -0500 Subject: [PATCH 08/13] Add Node Engine. --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index c0fc54c..05b941a 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "A JavaScript client for communicating with PlanetScale Edge API.", "main": "dist/index.js", "types": "dist/index.d.js", + "engines": { + "node": ">=16" + }, "prettier": { "semi": false, "trailingComma": "none", From 17981f77a5d9b71e59bc956700da2da8a5e61d56 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 17:21:22 -0500 Subject: [PATCH 09/13] Use v3 where possible. --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10733d7..a9b4f78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,9 +10,9 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - - uses: actions/cache@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + - uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} @@ -29,9 +29,9 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - - uses: actions/cache@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + - uses: actionsth:/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} From f92ea1a8cc410ccacd5aad17e2b5697d3cbd34db Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Thu, 28 Jul 2022 17:23:06 -0500 Subject: [PATCH 10/13] Fix typo. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9b4f78..002b56c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 - - uses: actionsth:/cache@v3 + - uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} From 05fcad49e68a98bc01f4b6b8e9c4fcc2346c457a Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Fri, 29 Jul 2022 11:50:29 -0500 Subject: [PATCH 11/13] Go back to using npm run build. --- .github/workflows/ci.yml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 002b56c..9beada9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: ${{ runner.os }}-node- - run: npm ci - run: npm run lint -- --fix - - run: npm run tsc + - run: npm run build - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: @@ -38,5 +38,5 @@ jobs: restore-keys: | ${{ runner.os }}-node- - run: npm ci - - run: npm run tsc + - run: npm run build - run: npm test diff --git a/package.json b/package.json index 05b941a..a6c7320 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "bracketSpacing": true }, "scripts": { - "tsc": "tsc", + "build": "tsc", "lint": "eslint .", "test": "jest" }, From 176b251139b1f4c838aa3f955e2ef6fa58077736 Mon Sep 17 00:00:00 2001 From: David Graham Date: Fri, 29 Jul 2022 11:07:24 -0600 Subject: [PATCH 12/13] Define compiler entry point --- package.json | 3 +++ tsconfig.json | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a1d53f9..d44cf38 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "A JavaScript client for communicating with PlanetScale Edge API.", "main": "dist/index.js", "types": "dist/index.d.js", + "files": [ + "dist" + ], "engines": { "node": ">=16" }, diff --git a/tsconfig.json b/tsconfig.json index a5e95a0..45122a2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,5 +11,6 @@ "paths": {}, "esModuleInterop": true, "resolveJsonModule": true - } + }, + "files": ["src/index.ts"] } From 18187a3f1946f19ab8a9a2c56c4149333ec5a98d Mon Sep 17 00:00:00 2001 From: David Graham Date: Fri, 29 Jul 2022 11:20:33 -0600 Subject: [PATCH 13/13] Move eslint configuration into package manifest --- .eslintrc.js | 16 ---------------- package.json | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 32be0e6..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - rules: { - 'prettier/prettier': ['error', {}, { usePrettierrc: true }], - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/ban-ts-comment': 'off' - }, - root: true, - env: { - browser: true, - node: true - } -} diff --git a/package.json b/package.json index d44cf38..14b3c22 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "clean": "rm -rf dist/", "prebuild": "npm run clean", "build": "tsc", - "lint": "eslint .", + "lint": "eslint src/ __tests__/", "test": "jest" }, "repository": { @@ -59,5 +59,20 @@ "ts-jest": "^28.0.7", "ts-node": "^10.9.1", "typescript": "^4.7.4" + }, + "eslintConfig": { + "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"], + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], + "rules": { + "prettier/prettier": ["error", {}, { "usePrettierrc": true }], + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/ban-ts-comment": "off" + }, + "root": true, + "env": { + "browser": true, + "node": true + } } }