From bb538e79982cf3a87de09a91168889318cbd2a64 Mon Sep 17 00:00:00 2001 From: Adam Sparks Date: Sat, 16 Jul 2022 04:11:02 -0500 Subject: [PATCH 1/2] integrate eslint --- .eslintrc.yml | 25 +++ .husky/pre-commit | 6 - package.json | 21 +- packages/resolver-svimg/package.json | 1 + pnpm-lock.yaml | 320 +++++++++++++++++++++++---- 5 files changed, 314 insertions(+), 59 deletions(-) create mode 100644 .eslintrc.yml delete mode 100755 .husky/pre-commit create mode 100644 packages/resolver-svimg/package.json diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 00000000..fea37197 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,25 @@ +env: + browser: true + es2021: true +extends: + - eslint:recommended + - plugin:@typescript-eslint/recommended +parser: '@typescript-eslint/parser' +parserOptions: + ecmaVersion: latest + sourceType: module +plugins: + - '@typescript-eslint' +rules: + indent: + - error + - 2 + linebreak-style: + - error + - unix + quotes: + - error + - backtick + semi: + - error + - always diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100755 index d09c1811..00000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -pnpm run lint:fix:prettier -# pnpm run lint -# pnpm test diff --git a/package.json b/package.json index 6156fec1..f1db1d01 100644 --- a/package.json +++ b/package.json @@ -12,17 +12,17 @@ "build": "pnpm -r --filter !playground build", "build:types": "pnpm -r --filter !playground exec -- tsup --dts-only", "dev": "pnpm -r --parallel --filter !playground dev", - "lint": "prettier --check --plugin-search-dir=. .", - "lint:fix": "pnpm lint:fix:prettier", - "lint:fix:prettier": "prettier --write --plugin-search-dir=. .", + "lint": "prettier --check --plugin-search-dir=. . && eslint packages/**/src", + "lint:fix": "pnpm lint:fix:prettier && pnpm lint:fix:eslint", + "lint:fix:prettier": "pretty-quick --staged", + "lint:fix:eslint": "eslint packages/**/src --fix && eslint playground/**/src --fix", "play": "cd playground && pnpm dev", "play:build": "pnpm build && cd playground && pnpm build", "prepublish:ci": "pnpm -r update", "publish:ci": "esmo scripts/publish.ts", "release": "esmo scripts/release.ts && git push --follow-tags", "test": "ava", - "dev:test": "ava --watch --verbose", - "prepare": "husky install" + "dev:test": "ava --watch --verbose" }, "repository": { "type": "git", @@ -45,14 +45,18 @@ "@ava/typescript": "^3.0.1", "@nrwl/workspace": "^14.3.6", "@types/node": "^16.11.42", + "@typescript-eslint/eslint-plugin": "^5.30.6", + "@typescript-eslint/parser": "^5.30.6", "ava": "^4.3.0", "bumpp": "^7.2.0", + "eslint": "7.32.0", "esno": "^0.12.1", "export-size": "^0.5.2", - "husky": "^7.0.4", + "husky": "^8.0.1", "kleur": "^4.1.5", "npkill": "^0.8.3", "prettier": "2.7.1", + "pretty-quick": "^3.1.3", "ts-node": "^10.8.1", "tsconfig-paths": "^3.14.1", "tsup": "^6.1.2", @@ -64,5 +68,10 @@ "graphql": "^16.0.1" } } + }, + "husky": { + "hooks": { + "pre-commit": "lint:fix" + } } } diff --git a/packages/resolver-svimg/package.json b/packages/resolver-svimg/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/packages/resolver-svimg/package.json @@ -0,0 +1 @@ +{} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf51c8a6..5b475ab9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: 5.4 +lockfileVersion: 5.3 importers: @@ -11,15 +11,19 @@ importers: '@flatbread/transformer-markdown': workspace:* '@nrwl/workspace': ^14.3.6 '@types/node': ^16.11.42 + '@typescript-eslint/eslint-plugin': ^5.30.6 + '@typescript-eslint/parser': ^5.30.6 ava: ^4.3.0 bumpp: ^7.2.0 + eslint: 7.32.0 esno: ^0.12.1 export-size: ^0.5.2 flatbread: workspace:* - husky: ^7.0.4 + husky: ^8.0.1 kleur: ^4.1.5 npkill: ^0.8.3 prettier: 2.7.1 + pretty-quick: ^3.1.3 ts-node: ^10.8.1 tsconfig-paths: ^3.14.1 tsup: ^6.1.2 @@ -32,19 +36,23 @@ importers: flatbread: link:packages/flatbread devDependencies: '@ava/typescript': 3.0.1 - '@nrwl/workspace': 14.3.6_2272ehng6hskpfcmxgjtyxgnqm + '@nrwl/workspace': 14.3.6_2c8239371ba80b743941bea5cc4eab07 '@types/node': 16.11.42 + '@typescript-eslint/eslint-plugin': 5.30.6_7b4477901712ff0cc0851bd2d74e4145 + '@typescript-eslint/parser': 5.30.6_eslint@7.32.0+typescript@4.7.4 ava: 4.3.0_@ava+typescript@3.0.1 bumpp: 7.2.0 + eslint: 7.32.0 esno: 0.12.1 export-size: 0.5.2 - husky: 7.0.4 + husky: 8.0.1 kleur: 4.1.5 npkill: 0.8.3 prettier: 2.7.1 - ts-node: 10.8.1_572ewalfkz76l4wczrwi7uyo64 + pretty-quick: 3.1.3_prettier@2.7.1 + ts-node: 10.8.1_eff44b0165567fe5f2c2cc6c8fd30ef7 tsconfig-paths: 3.14.1 - tsup: 6.1.2_mu66ohdiwyrigyorzidgf4bsdu + tsup: 6.1.2_ts-node@10.8.1+typescript@4.7.4 typescript: 4.7.4 packages/config: @@ -149,6 +157,9 @@ importers: typescript: 4.7.4 vfile: 5.3.4 + packages/resolver-svimg: + specifiers: {} + packages/source-filesystem: specifiers: '@flatbread/core': workspace:* @@ -863,7 +874,7 @@ packages: dependencies: '@jest/types': 27.5.1 '@types/node': 16.11.42 - chalk: 4.1.0 + chalk: 4.1.2 jest-message-util: 27.5.1 jest-util: 27.5.1 slash: 3.0.0 @@ -915,10 +926,10 @@ packages: '@jest/transform': 27.5.1 '@jest/types': 27.5.1 '@types/node': 16.11.42 - chalk: 4.1.0 + chalk: 4.1.2 collect-v8-coverage: 1.0.1 exit: 0.1.2 - glob: 7.1.4 + glob: 7.2.3 graceful-fs: 4.2.10 istanbul-lib-coverage: 3.2.0 istanbul-lib-instrument: 5.2.0 @@ -976,7 +987,7 @@ packages: '@babel/core': 7.18.6 '@jest/types': 27.5.1 babel-plugin-istanbul: 6.1.1 - chalk: 4.1.0 + chalk: 4.1.2 convert-source-map: 1.8.0 fast-json-stable-stringify: 2.1.0 graceful-fs: 4.2.10 @@ -1000,7 +1011,7 @@ packages: '@types/istanbul-reports': 3.0.1 '@types/node': 16.11.42 '@types/yargs': 16.0.4 - chalk: 4.1.0 + chalk: 4.1.2 dev: true /@josephg/resolvable/1.0.1: @@ -1130,7 +1141,7 @@ packages: tslib: 2.4.0 dev: true - /@nrwl/jest/14.3.6_jxopofg2vqpv3bqu6dfbj6thra: + /@nrwl/jest/14.3.6_4ddcf714daac1f5d8614f0ca14fa6788: resolution: {integrity: sha512-206afRAbxtcpy1y0lPKDQWHlUjyqcSWijxQsAe2clz7Qv/TC7bbBo0fdDkSKQX9fsk4rOo5TmBOl+wD8grvGWA==} dependencies: '@jest/reporters': 27.5.1 @@ -1156,7 +1167,7 @@ packages: - utf-8-validate dev: true - /@nrwl/linter/14.3.6_mu66ohdiwyrigyorzidgf4bsdu: + /@nrwl/linter/14.3.6_ea09189d6d1865b7a025d84985c38794: resolution: {integrity: sha512-Iv3D2+gukgaiSLlWKQnAZOAfFh/zlLk9Nmn47jalqbluYCjm5awk4cK9Hkr2dd8QwjOg1uJprc0qxppNYAJoMA==} peerDependencies: eslint: ^8.0.0 @@ -1165,8 +1176,9 @@ packages: optional: true dependencies: '@nrwl/devkit': 14.3.6_nx@14.3.6 - '@nrwl/jest': 14.3.6_jxopofg2vqpv3bqu6dfbj6thra + '@nrwl/jest': 14.3.6_4ddcf714daac1f5d8614f0ca14fa6788 '@phenomnomnominal/tsquery': 4.1.1_typescript@4.7.4 + eslint: 7.32.0 nx: 14.3.6 tmp: 0.2.1 tslib: 2.4.0 @@ -1192,7 +1204,7 @@ packages: - '@swc/core' dev: true - /@nrwl/workspace/14.3.6_2272ehng6hskpfcmxgjtyxgnqm: + /@nrwl/workspace/14.3.6_2c8239371ba80b743941bea5cc4eab07: resolution: {integrity: sha512-uuJ6rFj55FLydJrYYi8ME5pJviXLS0VC/t3Jk2D9+4wEyRMwdWS/6jUnCLnRgLHtEm1SARSzy/KYGz4UtbKncQ==} peerDependencies: prettier: ^2.6.2 @@ -1201,8 +1213,8 @@ packages: optional: true dependencies: '@nrwl/devkit': 14.3.6_nx@14.3.6 - '@nrwl/jest': 14.3.6_jxopofg2vqpv3bqu6dfbj6thra - '@nrwl/linter': 14.3.6_mu66ohdiwyrigyorzidgf4bsdu + '@nrwl/jest': 14.3.6_4ddcf714daac1f5d8614f0ca14fa6788 + '@nrwl/linter': 14.3.6_ea09189d6d1865b7a025d84985c38794 '@parcel/watcher': 2.0.4 chalk: 4.1.0 chokidar: 3.5.3 @@ -1615,6 +1627,10 @@ packages: /@types/mime/1.3.2: resolution: {integrity: sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==} + /@types/minimatch/3.0.5: + resolution: {integrity: sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==} + dev: true + /@types/mri/1.1.1: resolution: {integrity: sha512-nJOuiTlsvmClSr3+a/trTSx4DTuY/VURsWGKSf/eeavh0LRMqdsK60ti0TlwM5iHiGOK3/Ibkxsbr7i9rzGreA==} dev: true @@ -1732,6 +1748,33 @@ packages: - supports-color dev: true + /@typescript-eslint/eslint-plugin/5.30.6_7b4477901712ff0cc0851bd2d74e4145: + resolution: {integrity: sha512-J4zYMIhgrx4MgnZrSDD7sEnQp7FmhKNOaqaOpaoQ/SfdMfRB/0yvK74hTnvH+VQxndZynqs5/Hn4t+2/j9bADg==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + '@typescript-eslint/parser': ^5.0.0 + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/parser': 5.30.6_eslint@7.32.0+typescript@4.7.4 + '@typescript-eslint/scope-manager': 5.30.6 + '@typescript-eslint/type-utils': 5.30.6_eslint@7.32.0+typescript@4.7.4 + '@typescript-eslint/utils': 5.30.6_eslint@7.32.0+typescript@4.7.4 + debug: 4.3.4 + eslint: 7.32.0 + functional-red-black-tree: 1.0.1 + ignore: 5.2.0 + regexpp: 3.2.0 + semver: 7.3.7 + tsutils: 3.21.0_typescript@4.7.4 + typescript: 4.7.4 + transitivePeerDependencies: + - supports-color + dev: true + /@typescript-eslint/experimental-utils/4.33.0_hxadhbs2xogijvk7vq4t2azzbu: resolution: {integrity: sha512-zeQjOoES5JFjTnAhI5QY7ZviczMzDptls15GFsI6jyUOq0kOf9+WonkhtlIhh0RgHRnqj5gdNxW5j1EvAyYg6Q==} engines: {node: ^10.12.0 || >=12.0.0} @@ -1770,6 +1813,26 @@ packages: - supports-color dev: true + /@typescript-eslint/parser/5.30.6_eslint@7.32.0+typescript@4.7.4: + resolution: {integrity: sha512-gfF9lZjT0p2ZSdxO70Xbw8w9sPPJGfAdjK7WikEjB3fcUI/yr9maUVEdqigBjKincUYNKOmf7QBMiTf719kbrA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/scope-manager': 5.30.6 + '@typescript-eslint/types': 5.30.6 + '@typescript-eslint/typescript-estree': 5.30.6_typescript@4.7.4 + debug: 4.3.4 + eslint: 7.32.0 + typescript: 4.7.4 + transitivePeerDependencies: + - supports-color + dev: true + /@typescript-eslint/scope-manager/4.33.0: resolution: {integrity: sha512-5IfJHpgTsTZuONKbODctL4kKuQje/bzBRkwHE8UOZ4f89Zeddg+EGZs8PD8NcN4LdM3ygHWYB3ukPAYjvl/qbQ==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} @@ -1778,11 +1841,43 @@ packages: '@typescript-eslint/visitor-keys': 4.33.0 dev: true + /@typescript-eslint/scope-manager/5.30.6: + resolution: {integrity: sha512-Hkq5PhLgtVoW1obkqYH0i4iELctEKixkhWLPTYs55doGUKCASvkjOXOd/pisVeLdO24ZX9D6yymJ/twqpJiG3g==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + '@typescript-eslint/types': 5.30.6 + '@typescript-eslint/visitor-keys': 5.30.6 + dev: true + + /@typescript-eslint/type-utils/5.30.6_eslint@7.32.0+typescript@4.7.4: + resolution: {integrity: sha512-GFVVzs2j0QPpM+NTDMXtNmJKlF842lkZKDSanIxf+ArJsGeZUIaeT4jGg+gAgHt7AcQSFwW7htzF/rbAh2jaVA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: '*' + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/utils': 5.30.6_eslint@7.32.0+typescript@4.7.4 + debug: 4.3.4 + eslint: 7.32.0 + tsutils: 3.21.0_typescript@4.7.4 + typescript: 4.7.4 + transitivePeerDependencies: + - supports-color + dev: true + /@typescript-eslint/types/4.33.0: resolution: {integrity: sha512-zKp7CjQzLQImXEpLt2BUw1tvOMPfNoTAfb8l51evhYbOEEzdWyQNmHWWGPR6hwKJDAi+1VXSBmnhL9kyVTTOuQ==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} dev: true + /@typescript-eslint/types/5.30.6: + resolution: {integrity: sha512-HdnP8HioL1F7CwVmT4RaaMX57RrfqsOMclZc08wGMiDYJBsLGBM7JwXM4cZJmbWLzIR/pXg1kkrBBVpxTOwfUg==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + /@typescript-eslint/typescript-estree/4.33.0_typescript@4.7.4: resolution: {integrity: sha512-rkWRY1MPFzjwnEVHsxGemDzqqddw2QbTJlICPD9p9I9LfsO8fdmfQPOX3uKfUaGRDFJbfrtm/sXhVXN4E+bzCA==} engines: {node: ^10.12.0 || >=12.0.0} @@ -1804,6 +1899,45 @@ packages: - supports-color dev: true + /@typescript-eslint/typescript-estree/5.30.6_typescript@4.7.4: + resolution: {integrity: sha512-Z7TgPoeYUm06smfEfYF0RBkpF8csMyVnqQbLYiGgmUSTaSXTP57bt8f0UFXstbGxKIreTwQCujtaH0LY9w9B+A==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/types': 5.30.6 + '@typescript-eslint/visitor-keys': 5.30.6 + debug: 4.3.4 + globby: 11.1.0 + is-glob: 4.0.3 + semver: 7.3.7 + tsutils: 3.21.0_typescript@4.7.4 + typescript: 4.7.4 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/utils/5.30.6_eslint@7.32.0+typescript@4.7.4: + resolution: {integrity: sha512-xFBLc/esUbLOJLk9jKv0E9gD/OH966M40aY9jJ8GiqpSkP2xOV908cokJqqhVd85WoIvHVHYXxSFE4cCSDzVvA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + dependencies: + '@types/json-schema': 7.0.11 + '@typescript-eslint/scope-manager': 5.30.6 + '@typescript-eslint/types': 5.30.6 + '@typescript-eslint/typescript-estree': 5.30.6_typescript@4.7.4 + eslint: 7.32.0 + eslint-scope: 5.1.1 + eslint-utils: 3.0.0_eslint@7.32.0 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + /@typescript-eslint/visitor-keys/4.33.0: resolution: {integrity: sha512-uqi/2aSz9g2ftcHWf8uLPJA70rUv6yuMW5Bohw+bwcuzaxQIHaKFZCKGoGXIrc9vkTJ3+0txM73K0Hq3d5wgIg==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} @@ -1812,6 +1946,14 @@ packages: eslint-visitor-keys: 2.1.0 dev: true + /@typescript-eslint/visitor-keys/5.30.6: + resolution: {integrity: sha512-41OiCjdL2mCaSDi2SvYbzFLlqqlm5v1ZW9Ym55wXKL/Rx6OOB1IbuFGo71Fj6Xy90gJDFTlgOS+vbmtGHPTQQA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + '@typescript-eslint/types': 5.30.6 + eslint-visitor-keys: 3.3.0 + dev: true + /@vercel/nft/0.20.1: resolution: {integrity: sha512-hSLcr64KHOkcNiTAlv154K4p4faEFBwYIi2eIgu1QCDhB1qyQYvFuEhtw3eaapNjA4/7x/2jcclfCAjILua/ag==} hasBin: true @@ -2144,6 +2286,11 @@ packages: engines: {node: '>=6'} dev: true + /array-differ/3.0.0: + resolution: {integrity: sha512-THtfYS6KtME/yIAhKjZ2ul7XI96lQGHRputJQHO80LAWQnuGP4iCIN8vdMRboGbIEYBwU33q8Tch1os2+X0kMg==} + engines: {node: '>=8'} + dev: true + /array-find-index/1.0.2: resolution: {integrity: sha512-M1HQyIXcBGtVywBt8WVdim+lrNaK7VHp99Qt5pSNziXznKHViIBbXWtfRTpEFpF/c4FdfxNAsCCwPp5phBYJtw==} engines: {node: '>=0.10.0'} @@ -2163,6 +2310,11 @@ packages: engines: {node: '>=8.0.0'} dev: true + /arrify/2.0.1: + resolution: {integrity: sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug==} + engines: {node: '>=8'} + dev: true + /arrify/3.0.0: resolution: {integrity: sha512-tLkvA81vQG/XqE2mjDkGQHoOINtMHtysSnemrmoGe6PydDPMRbVugqyk4A6V/WDWEfm3l+0d8anA9r8cv/5Jaw==} engines: {node: '>=12'} @@ -2275,7 +2427,7 @@ packages: '@types/babel__core': 7.1.19 babel-plugin-istanbul: 6.1.1 babel-preset-jest: 27.5.1_@babel+core@7.18.6 - chalk: 4.1.0 + chalk: 4.1.2 graceful-fs: 4.2.10 slash: 3.0.0 transitivePeerDependencies: @@ -2558,6 +2710,14 @@ packages: supports-color: 5.5.0 dev: true + /chalk/3.0.0: + resolution: {integrity: sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==} + engines: {node: '>=8'} + dependencies: + ansi-styles: 4.3.0 + supports-color: 7.2.0 + dev: true + /chalk/4.1.0: resolution: {integrity: sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==} engines: {node: '>=10'} @@ -3648,6 +3808,11 @@ packages: engines: {node: '>=10'} dev: true + /eslint-visitor-keys/3.3.0: + resolution: {integrity: sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + /eslint/7.32.0: resolution: {integrity: sha512-VHZ8gX+EDfz+97jGcgyGCyRia/dPOd6Xh9yPv8Bl1+SoaIwD+a/vlrOmGRUyOYu7MwUhc7CxqeaDZU13S4+EpA==} engines: {node: ^10.12.0 || >=12.0.0} @@ -3768,6 +3933,21 @@ packages: engines: {node: '>= 0.6'} dev: false + /execa/4.1.0: + resolution: {integrity: sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA==} + engines: {node: '>=10'} + dependencies: + cross-spawn: 7.0.3 + get-stream: 5.2.0 + human-signals: 1.1.1 + is-stream: 2.0.1 + merge-stream: 2.0.0 + npm-run-path: 4.0.1 + onetime: 5.1.2 + signal-exit: 3.0.7 + strip-final-newline: 2.0.0 + dev: true + /execa/5.1.1: resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} engines: {node: '>=10'} @@ -4154,6 +4334,13 @@ packages: engines: {node: '>=8.0.0'} dev: true + /get-stream/5.2.0: + resolution: {integrity: sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==} + engines: {node: '>=8'} + dependencies: + pump: 3.0.0 + dev: true + /get-stream/6.0.1: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} @@ -4183,7 +4370,7 @@ packages: fs.realpath: 1.0.0 inflight: 1.0.6 inherits: 2.0.4 - minimatch: 3.0.5 + minimatch: 3.1.2 once: 1.4.0 path-is-absolute: 1.0.1 dev: true @@ -4522,14 +4709,19 @@ packages: - supports-color dev: true + /human-signals/1.1.1: + resolution: {integrity: sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==} + engines: {node: '>=8.12.0'} + dev: true + /human-signals/2.1.0: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} engines: {node: '>=10.17.0'} dev: true - /husky/7.0.4: - resolution: {integrity: sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==} - engines: {node: '>=12'} + /husky/8.0.1: + resolution: {integrity: sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw==} + engines: {node: '>=14'} hasBin: true dev: true @@ -4805,9 +4997,9 @@ packages: hasBin: true dependencies: async: 3.2.4 - chalk: 4.1.0 + chalk: 4.1.2 filelist: 1.0.4 - minimatch: 3.0.5 + minimatch: 3.1.2 dev: true /jest-circus/27.5.1: @@ -4818,7 +5010,7 @@ packages: '@jest/test-result': 27.5.1 '@jest/types': 27.5.1 '@types/node': 16.11.42 - chalk: 4.1.0 + chalk: 4.1.2 co: 4.6.0 dedent: 0.7.0 expect: 27.5.1 @@ -4850,10 +5042,10 @@ packages: '@jest/test-sequencer': 27.5.1 '@jest/types': 27.5.1 babel-jest: 27.5.1_@babel+core@7.18.6 - chalk: 4.1.0 + chalk: 4.1.2 ci-info: 3.3.2 deepmerge: 4.2.2 - glob: 7.1.4 + glob: 7.2.3 graceful-fs: 4.2.10 jest-circus: 27.5.1 jest-environment-jsdom: 27.5.1 @@ -4870,7 +5062,7 @@ packages: pretty-format: 27.5.1 slash: 3.0.0 strip-json-comments: 3.1.1 - ts-node: 10.8.1_572ewalfkz76l4wczrwi7uyo64 + ts-node: 10.8.1_eff44b0165567fe5f2c2cc6c8fd30ef7 transitivePeerDependencies: - bufferutil - canvas @@ -4882,7 +5074,7 @@ packages: resolution: {integrity: sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: - chalk: 4.1.0 + chalk: 4.1.2 diff-sequences: 27.5.1 jest-get-type: 27.5.1 pretty-format: 27.5.1 @@ -4900,7 +5092,7 @@ packages: engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: '@jest/types': 27.5.1 - chalk: 4.1.0 + chalk: 4.1.2 jest-get-type: 27.5.1 jest-util: 27.5.1 pretty-format: 27.5.1 @@ -4970,7 +5162,7 @@ packages: '@jest/test-result': 27.5.1 '@jest/types': 27.5.1 '@types/node': 16.11.42 - chalk: 4.1.0 + chalk: 4.1.2 co: 4.6.0 expect: 27.5.1 is-generator-fn: 2.1.0 @@ -4998,7 +5190,7 @@ packages: resolution: {integrity: sha512-z2uTx/T6LBaCoNWNFWwChLBKYxTMcGBRjAt+2SbP929/Fflb9aa5LGma654Rz8z9HLxsrUaYzxE9T/EFIL/PAw==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: - chalk: 4.1.0 + chalk: 4.1.2 jest-diff: 27.5.1 jest-get-type: 27.5.1 pretty-format: 27.5.1 @@ -5011,7 +5203,7 @@ packages: '@babel/code-frame': 7.18.6 '@jest/types': 27.5.1 '@types/stack-utils': 2.0.1 - chalk: 4.1.0 + chalk: 4.1.2 graceful-fs: 4.2.10 micromatch: 4.0.5 pretty-format: 27.5.1 @@ -5049,7 +5241,7 @@ packages: engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: '@jest/types': 27.5.1 - chalk: 4.1.0 + chalk: 4.1.2 graceful-fs: 4.2.10 jest-haste-map: 27.5.1 jest-pnp-resolver: 1.2.2_jest-resolve@27.5.1 @@ -5070,7 +5262,7 @@ packages: '@jest/transform': 27.5.1 '@jest/types': 27.5.1 '@types/node': 16.11.42 - chalk: 4.1.0 + chalk: 4.1.2 emittery: 0.8.1 graceful-fs: 4.2.10 jest-docblock: 27.5.1 @@ -5103,11 +5295,11 @@ packages: '@jest/test-result': 27.5.1 '@jest/transform': 27.5.1 '@jest/types': 27.5.1 - chalk: 4.1.0 + chalk: 4.1.2 cjs-module-lexer: 1.2.2 collect-v8-coverage: 1.0.1 execa: 5.1.1 - glob: 7.1.4 + glob: 7.2.3 graceful-fs: 4.2.10 jest-haste-map: 27.5.1 jest-message-util: 27.5.1 @@ -5144,7 +5336,7 @@ packages: '@types/babel__traverse': 7.17.1 '@types/prettier': 2.6.3 babel-preset-current-node-syntax: 1.0.1_@babel+core@7.18.6 - chalk: 4.1.0 + chalk: 4.1.2 expect: 27.5.1 graceful-fs: 4.2.10 jest-diff: 27.5.1 @@ -5155,7 +5347,7 @@ packages: jest-util: 27.5.1 natural-compare: 1.4.0 pretty-format: 27.5.1 - semver: 7.3.4 + semver: 7.3.7 transitivePeerDependencies: - supports-color dev: true @@ -5166,7 +5358,7 @@ packages: dependencies: '@jest/types': 27.5.1 '@types/node': 16.11.42 - chalk: 4.1.0 + chalk: 4.1.2 ci-info: 3.3.2 graceful-fs: 4.2.10 picomatch: 2.3.1 @@ -5178,7 +5370,7 @@ packages: dependencies: '@jest/types': 27.5.1 camelcase: 6.3.0 - chalk: 4.1.0 + chalk: 4.1.2 jest-get-type: 27.5.1 leven: 3.1.0 pretty-format: 27.5.1 @@ -6041,6 +6233,17 @@ packages: /ms/2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + /multimatch/4.0.0: + resolution: {integrity: sha512-lDmx79y1z6i7RNx0ZGCPq1bzJ6ZoDDKbvh7jxr9SJcWLkShMzXrHbYVpTdnhNM5MXpDUxCQ4DgqVttVXlBgiBQ==} + engines: {node: '>=8'} + dependencies: + '@types/minimatch': 3.0.5 + array-differ: 3.0.0 + array-union: 2.1.0 + arrify: 2.0.1 + minimatch: 3.1.2 + dev: true + /mz/2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} dependencies: @@ -6492,7 +6695,7 @@ packages: optional: true dependencies: lilconfig: 2.0.5 - ts-node: 10.8.1_572ewalfkz76l4wczrwi7uyo64 + ts-node: 10.8.1_eff44b0165567fe5f2c2cc6c8fd30ef7 yaml: 1.10.2 dev: true @@ -6574,6 +6777,22 @@ packages: parse-ms: 2.1.0 dev: true + /pretty-quick/3.1.3_prettier@2.7.1: + resolution: {integrity: sha512-kOCi2FJabvuh1as9enxYmrnBC6tVMoVOenMaBqRfsvBHB0cbpYHjdQEpSglpASDFEXVwplpcGR4CLEaisYAFcA==} + engines: {node: '>=10.13'} + hasBin: true + peerDependencies: + prettier: '>=2.0.0' + dependencies: + chalk: 3.0.0 + execa: 4.1.0 + find-up: 4.1.0 + ignore: 5.2.0 + mri: 1.2.0 + multimatch: 4.0.0 + prettier: 2.7.1 + dev: true + /progress/2.0.3: resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==} engines: {node: '>=0.4.0'} @@ -6603,6 +6822,13 @@ packages: resolution: {integrity: sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==} dev: true + /pump/3.0.0: + resolution: {integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==} + dependencies: + end-of-stream: 1.4.4 + once: 1.4.0 + dev: true + /punycode/2.1.1: resolution: {integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==} engines: {node: '>=6'} @@ -6917,7 +7143,7 @@ packages: resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} hasBin: true dependencies: - glob: 7.1.4 + glob: 7.2.3 dev: true /rollup-pluginutils/2.8.2: @@ -7556,8 +7782,8 @@ packages: engines: {node: '>=8'} dependencies: '@istanbuljs/schema': 0.1.3 - glob: 7.1.4 - minimatch: 3.0.5 + glob: 7.2.3 + minimatch: 3.1.2 dev: true /text-table/0.2.0: @@ -7686,7 +7912,7 @@ packages: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} dev: true - /ts-node/10.8.1_572ewalfkz76l4wczrwi7uyo64: + /ts-node/10.8.1_eff44b0165567fe5f2c2cc6c8fd30ef7: resolution: {integrity: sha512-Wwsnao4DQoJsN034wePSg5nZiw4YKXf56mPIAeD6wVmiv+RytNSWqc2f3fKvcUoV+Yn2+yocD71VOfQHbmVX4g==} hasBin: true peerDependencies: @@ -7737,7 +7963,7 @@ packages: /tslib/2.4.0: resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} - /tsup/6.1.2_mu66ohdiwyrigyorzidgf4bsdu: + /tsup/6.1.2_ts-node@10.8.1+typescript@4.7.4: resolution: {integrity: sha512-Hw4hKDHaAQkm2eVavlArEOrAPA93bziRDamdfwaNs0vXQdUUFfItvUWY0L/F6oQQMVh6GvjQq1+HpDXw8UKtPA==} engines: {node: '>=14'} hasBin: true From 0231520f1b6d44d551e6848e66ad77a9896a9769 Mon Sep 17 00:00:00 2001 From: Adam Sparks Date: Sat, 16 Jul 2022 04:25:14 -0500 Subject: [PATCH 2/2] apply fixes --- package.json | 2 +- packages/config/src/index.ts | 14 +-- packages/core/src/cache/index.ts | 2 +- packages/core/src/generators/arguments.ts | 20 ++-- packages/core/src/generators/schema.ts | 26 ++--- packages/core/src/resolvers/arguments.ts | 4 +- packages/core/src/utils/deepEntries.ts | 4 +- packages/core/src/utils/reduceBooleans.ts | 6 +- packages/core/src/utils/sift.ts | 94 +++++++++---------- packages/core/src/utils/tests/sift.test.ts | 32 +++---- packages/core/src/utils/tests/typeOf.test.ts | 20 ++-- packages/core/src/utils/typeOf.ts | 14 +-- packages/flatbread/src/cli/index.ts | 50 +++++----- packages/flatbread/src/cli/initConfig.ts | 6 +- packages/flatbread/src/cli/runner.ts | 26 ++--- packages/flatbread/src/graphql/server.ts | 2 +- packages/flatbread/src/utils/getSchema.ts | 8 +- packages/source-filesystem/src/index.ts | 11 +-- .../src/utils/gatherFileNodes.ts | 6 +- .../src/utils/tests/gatherFileNodes.test.ts | 52 +++++----- .../src/utils/tests/mocks.ts | 20 ++-- .../src/graphql/schema-helpers.ts | 36 +++---- packages/transformer-markdown/src/index.ts | 2 +- .../src/processors/excerpt.ts | 2 +- .../src/processors/markdown.ts | 4 +- .../src/processors/toHTML.ts | 2 +- packages/transformer-yaml/src/index.ts | 4 +- 27 files changed, 235 insertions(+), 234 deletions(-) diff --git a/package.json b/package.json index f1db1d01..a52f689c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "lint": "prettier --check --plugin-search-dir=. . && eslint packages/**/src", "lint:fix": "pnpm lint:fix:prettier && pnpm lint:fix:eslint", "lint:fix:prettier": "pretty-quick --staged", - "lint:fix:eslint": "eslint packages/**/src --fix && eslint playground/**/src --fix", + "lint:fix:eslint": "eslint packages/**/src --fix && eslint playground/src --fix", "play": "cd playground && pnpm dev", "play:build": "pnpm build && cd playground && pnpm build", "prepublish:ci": "pnpm -r update", diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index bd4e45f2..44801762 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -22,7 +22,7 @@ export const defineConfig = (config: FlatbreadConfig): FlatbreadConfig => export async function loadConfig({ cwd = process.cwd() } = {}): Promise< ConfigResult > { - const configFilePath = path.join(cwd, 'flatbread.config.js'); + const configFilePath = path.join(cwd, `flatbread.config.js`); const configModule = validateConfigHasExports( await import(url.pathToFileURL(configFilePath).href) @@ -46,13 +46,13 @@ export function validateConfigHasExports< >(config: unknown | any): C { const type = typeof config; - if (type === 'undefined') { + if (type === `undefined`) { throw new Error( - 'Your flatbread config is missing default exports. Make sure to include "export default config;"' + `Your flatbread config is missing default exports. Make sure to include "export default config;"` ); } - if (config.default && typeof config.default !== 'object') { + if (config.default && typeof config.default !== `object`) { throw new Error( `Unexpected default export type "${typeof config.default}" in your flatbread config, make sure your default export is an object.` ); @@ -71,15 +71,15 @@ export function validateConfigHasExports< export function validateConfigStructure( config: C ): FlatbreadConfig { - if (typeof config.source !== 'object') { + if (typeof config.source !== `object`) { throw new Error( - 'Your Flatbread config is missing a valid "source" property. Make sure to include an Flatbread-compatible source plugin, such as @flatbread/source-filesystem' + `Your Flatbread config is missing a valid "source" property. Make sure to include an Flatbread-compatible source plugin, such as @flatbread/source-filesystem` ); } if (!Array.isArray(config.content)) { throw new Error( - 'Your Flatbread config is missing a valid "content" property. Make sure to include an Flatbread-compatible source plugin, such as @flatbread/source-filesystem' + `Your Flatbread config is missing a valid "content" property. Make sure to include an Flatbread-compatible source plugin, such as @flatbread/source-filesystem` ); } diff --git a/packages/core/src/cache/index.ts b/packages/core/src/cache/index.ts index 40038795..a42de129 100644 --- a/packages/core/src/cache/index.ts +++ b/packages/core/src/cache/index.ts @@ -24,5 +24,5 @@ export function createCacheKey( // This should include serialized node contents to ensure that we don't hit old cache entries const key = `${nodeType}:${uid}:${attribute}`; - return crypto.createHash('md5').update(key).digest('hex'); + return crypto.createHash(`md5`).update(key).digest(`hex`); } diff --git a/packages/core/src/generators/arguments.ts b/packages/core/src/generators/arguments.ts index 7eed6d69..7504f56e 100644 --- a/packages/core/src/generators/arguments.ts +++ b/packages/core/src/generators/arguments.ts @@ -6,7 +6,7 @@ export const generateArgsForAllItemQuery = (pluralType: string) => ({ ...skip(), ...limit(pluralType), - ...order(pluralType, 'ASC'), + ...order(pluralType, `ASC`), ...sortBy(pluralType), ...filter(pluralType), }); @@ -18,11 +18,11 @@ export const generateArgsForAllItemQuery = (pluralType: string) => ({ */ export const generateArgsForManyItemQuery = (pluralType: string) => ({ ids: { - type: '[String]', + type: `[String]`, }, ...skip(), ...limit(pluralType), - ...order(pluralType, 'ASC'), + ...order(pluralType, `ASC`), ...sortBy(pluralType), }); @@ -32,7 +32,7 @@ export const generateArgsForManyItemQuery = (pluralType: string) => ({ */ export const generateArgsForSingleItemQuery = () => ({ id: { - type: 'String', + type: `String`, }, }); @@ -41,8 +41,8 @@ export const generateArgsForSingleItemQuery = () => ({ */ export const skip = () => ({ skip: { - description: 'Skip the first `n` results', - type: 'Int', + description: `Skip the first \`n\` results`, + type: `Int`, }, }); @@ -54,7 +54,7 @@ export const skip = () => ({ export const limit = (pluralType: string) => ({ limit: { description: `The maximum number of ${pluralType} to return`, - type: 'Int', + type: `Int`, }, }); @@ -66,7 +66,7 @@ export const limit = (pluralType: string) => ({ */ export const order = ( pluralType: string, - defaultValue: 'ASC' | 'DESC' = 'ASC' + defaultValue: `ASC` | `DESC` = `ASC` ) => ({ order: { description: `Which order to return ${pluralType} in`, @@ -83,7 +83,7 @@ export const order = ( export const sortBy = (pluralType: string) => ({ sortBy: { description: `The field to sort ${pluralType} by`, - type: 'String', + type: `String`, }, }); @@ -95,6 +95,6 @@ export const sortBy = (pluralType: string) => ({ export const filter = (pluralType: string) => ({ filter: { description: `Filter ${pluralType} by a JSON object`, - type: 'JSON', + type: `JSON`, }, }); diff --git a/packages/core/src/generators/schema.ts b/packages/core/src/generators/schema.ts index 41769b71..aee44596 100644 --- a/packages/core/src/generators/schema.ts +++ b/packages/core/src/generators/schema.ts @@ -24,7 +24,7 @@ interface RootQueries { const generateSchema = async (configResult: ConfigResult) => { const { config } = configResult; if (!config) { - throw new Error('Config is not defined'); + throw new Error(`Config is not defined`); } // Invoke the content source resolver to retrieve the content nodes @@ -61,7 +61,7 @@ const generateSchema = async (configResult: ConfigResult) => { /** * @todo potentially able to remove this **/ - let queries: RootQueries = { + const queries: RootQueries = { maybeReturnsSingleItem: [], maybeReturnsList: [], }; @@ -69,7 +69,7 @@ const generateSchema = async (configResult: ConfigResult) => { // Main builder loop - iterate through each content type and generate query resolvers + relationships for it for (const [type, schema] of Object.entries(schemaArray)) { const pluralType = plur(type, 2); - const pluralTypeQueryName = 'all' + pluralType; + const pluralTypeQueryName = `all` + pluralType; // /// Global meta fields @@ -77,8 +77,8 @@ const generateSchema = async (configResult: ConfigResult) => { schema.addFields({ _collection: { - type: 'String', - description: 'The collection name', + type: `String`, + description: `The collection name`, resolve: () => type, }, }); @@ -88,7 +88,7 @@ const generateSchema = async (configResult: ConfigResult) => { // schema.addResolver({ - name: 'findById', + name: `findById`, type: () => schema, description: `Find one ${type} by its ID`, args: generateArgsForSingleItemQuery(), @@ -99,7 +99,7 @@ const generateSchema = async (configResult: ConfigResult) => { }); schema.addResolver({ - name: 'findMany', + name: `findMany`, type: () => [schema], description: `Find many ${pluralType} by their IDs`, args: generateArgsForManyItemQuery(pluralType), @@ -114,7 +114,7 @@ const generateSchema = async (configResult: ConfigResult) => { }); schema.addResolver({ - name: 'all', + name: `all`, args: generateArgsForAllItemQuery(pluralType), type: () => [schema], description: `Return a set of ${pluralType}`, @@ -128,11 +128,11 @@ const generateSchema = async (configResult: ConfigResult) => { /** * Add find by ID to each content type */ - [type]: schema.getResolver('findById'), + [type]: schema.getResolver(`findById`), /** * Add find 'many' to each content type */ - [pluralTypeQueryName]: schema.getResolver('all'), + [pluralTypeQueryName]: schema.getResolver(`all`), }); /** @@ -163,7 +163,7 @@ const generateSchema = async (configResult: ConfigResult) => { String(refType), 2 )} that are referenced by this ${collection}`, - resolver: () => refTypeTC.getResolver('findMany'), + resolver: () => refTypeTC.getResolver(`findMany`), prepareArgs: { ids: (source) => source[refField], }, @@ -173,7 +173,7 @@ const generateSchema = async (configResult: ConfigResult) => { // If the reference field has a single node typeTC.addRelation(refField, { description: `The ${refType} referenced by this ${collection}`, - resolver: () => refTypeTC.getResolver('findById'), + resolver: () => refTypeTC.getResolver(`findById`), prepareArgs: { id: (source) => source[refField], }, @@ -195,7 +195,7 @@ const generateSchema = async (configResult: ConfigResult) => { */ const fetchPreknownSchemaFragments = ( config: FlatbreadConfig -): Record | {} => { +): Record => { if (config.transformer && config.transformer.preknownSchemaFragments) { return config.transformer.preknownSchemaFragments(); } diff --git a/packages/core/src/resolvers/arguments.ts b/packages/core/src/resolvers/arguments.ts index 6b88e9af..eadb7fcb 100644 --- a/packages/core/src/resolvers/arguments.ts +++ b/packages/core/src/resolvers/arguments.ts @@ -31,7 +31,7 @@ const resolveQueryArgs = async ( resolveSortBy(sortBy, nodes); } - if (order === 'DESC') { + if (order === `DESC`) { nodes.reverse(); } @@ -54,7 +54,7 @@ export const resolveFilter = async ( ) => { // construct custom resolver of nodes to build temp list const filterSetManifest = generateFilterSetManifest(filter); - console.log('filter manifest', filterSetManifest); + console.log(`filter manifest`, filterSetManifest); for (const filter of filterSetManifest) { for (const field of filter.path) { diff --git a/packages/core/src/utils/deepEntries.ts b/packages/core/src/utils/deepEntries.ts index 3d24e5e9..863460f3 100644 --- a/packages/core/src/utils/deepEntries.ts +++ b/packages/core/src/utils/deepEntries.ts @@ -13,8 +13,8 @@ const deepEntries = ( path: string[] = [], stack: any[] = [] ): [string[], any] => { - if (typeOf(obj) === 'object') { - for (let [key, value] of Object.entries(obj)) { + if (typeOf(obj) === `object`) { + for (const [key, value] of Object.entries(obj)) { stack = deepEntries(value, [...path, key], stack); } } else { diff --git a/packages/core/src/utils/reduceBooleans.ts b/packages/core/src/utils/reduceBooleans.ts index 4ffb46ef..366cbe1b 100644 --- a/packages/core/src/utils/reduceBooleans.ts +++ b/packages/core/src/utils/reduceBooleans.ts @@ -7,11 +7,11 @@ */ const reduceBooleans = ( array: Required, - unionType: Required<'and' | 'or'> + unionType: Required<`and` | `or`> ): boolean => { - if (unionType === 'and') { + if (unionType === `and`) { return array.reduce((acc, curr) => acc && curr, true); - } else if (unionType === 'or') { + } else if (unionType === `or`) { return array.reduce((acc, curr) => acc || curr, false); } throw new Error( diff --git a/packages/core/src/utils/sift.ts b/packages/core/src/utils/sift.ts index 9ccf118d..37275869 100644 --- a/packages/core/src/utils/sift.ts +++ b/packages/core/src/utils/sift.ts @@ -26,9 +26,9 @@ const createFilterFunction = ( // Filter args transformed to logical expressions. filterSetManifest ??= generateFilterSetManifest(filterArgs); - let evaluatedFilterSet: boolean[] = []; + const evaluatedFilterSet: boolean[] = []; - for (let { path, comparator } of filterSetManifest) { + for (const { path, comparator } of filterSetManifest) { // Retrieve the value of interest from the node. const needle = get(node, path, undefined); // Compare the value of interest to the target value, and store the result of the evaluated expression. @@ -36,7 +36,7 @@ const createFilterFunction = ( } // Combine the filter set results with the union operation. - return reduceBooleans(evaluatedFilterSet, 'and'); + return reduceBooleans(evaluatedFilterSet, `and`); }; }; export default createFilterFunction; @@ -52,36 +52,36 @@ function generateComparisonFunction( ): CompareValueAgainstConstant { const { operation, value } = comparator; switch (operation) { - case 'eq': - return (a: any) => a === value; - case 'ne': - return (a: any) => a !== value; - case 'lt': - return (a: any) => a < value; - case 'lte': - return (a: any) => a <= value; - case 'gt': - return (a: any) => a > value; - case 'gte': - return (a: any) => a >= value; - case 'in': - return (a: any) => value.includes(a); - case 'nin': - return (a: any) => !value.includes(a); - case 'includes': - return (a: any) => a.includes(value); - case 'excludes': - return (a: any) => !a.includes(value); - case 'regex': - return (a: any) => value.test(a); - case 'wildcard': - return (a: any) => isWildcardMatch(a, value); - case 'exists': - return (a: any) => (value ? a != undefined : a == undefined); - case 'strictlyExists': - return (a: any) => (value ? a !== undefined : a === undefined); - default: - throw new Error(`Unsupported operation: ${operation}`); + case `eq`: + return (a: any) => a === value; + case `ne`: + return (a: any) => a !== value; + case `lt`: + return (a: any) => a < value; + case `lte`: + return (a: any) => a <= value; + case `gt`: + return (a: any) => a > value; + case `gte`: + return (a: any) => a >= value; + case `in`: + return (a: any) => value.includes(a); + case `nin`: + return (a: any) => !value.includes(a); + case `includes`: + return (a: any) => a.includes(value); + case `excludes`: + return (a: any) => !a.includes(value); + case `regex`: + return (a: any) => value.test(a); + case `wildcard`: + return (a: any) => isWildcardMatch(a, value); + case `exists`: + return (a: any) => (value ? a != undefined : a == undefined); + case `strictlyExists`: + return (a: any) => (value ? a !== undefined : a === undefined); + default: + throw new Error(`Unsupported operation: ${operation}`); } } @@ -149,20 +149,20 @@ type Comparator = { * ``` */ type ComparatorOperation = - | 'eq' - | 'ne' - | 'lt' - | 'lte' - | 'gt' - | 'gte' - | 'in' - | 'nin' - | 'includes' - | 'excludes' - | 'regex' - | 'wildcard' - | 'exists' - | 'strictlyExists'; + | `eq` + | `ne` + | `lt` + | `lte` + | `gt` + | `gte` + | `in` + | `nin` + | `includes` + | `excludes` + | `regex` + | `wildcard` + | `exists` + | `strictlyExists`; /** * Compare a value to a constant target value. diff --git a/packages/core/src/utils/tests/sift.test.ts b/packages/core/src/utils/tests/sift.test.ts index f73c5724..52519951 100644 --- a/packages/core/src/utils/tests/sift.test.ts +++ b/packages/core/src/utils/tests/sift.test.ts @@ -2,31 +2,31 @@ import test from 'ava'; import sift from '../sift.js'; const nodes = [ - { id: 1, name: 'foo', child: { id: 2, name: 'bar', age: 44 } }, - { id: 3, name: 'baz', child: { id: 4, name: 'qux', age: 9 } }, - { id: 5, name: 'quux', child: { id: 6, name: 'quuz', age: 18 } }, + { id: 1, name: `foo`, child: { id: 2, name: `bar`, age: 44 } }, + { id: 3, name: `baz`, child: { id: 4, name: `qux`, age: 9 } }, + { id: 5, name: `quux`, child: { id: 6, name: `quuz`, age: 18 } }, ]; -test('Sifting an empty array returns an empty array', (t) => { +test(`Sifting an empty array returns an empty array`, (t) => { t.deepEqual([].filter(sift({ id: { eq: 1 } })), []); }); -test('Sifting with empty filter args returns the unfiltered nodes', (t) => { +test(`Sifting with empty filter args returns the unfiltered nodes`, (t) => { t.deepEqual(nodes.filter(sift({})), nodes); }); -test('Sift for nodes with name equal to "foo"', (t) => { - t.deepEqual(nodes.filter(sift({ name: { eq: 'foo' } })), [nodes[0]]); +test(`Sift for nodes with name equal to "foo"`, (t) => { + t.deepEqual(nodes.filter(sift({ name: { eq: `foo` } })), [nodes[0]]); }); -test('Sift for nodes with nested object "child" having age greater than or equal to 18', (t) => { +test(`Sift for nodes with nested object "child" having age greater than or equal to 18`, (t) => { t.deepEqual(nodes.filter(sift({ child: { age: { gte: 18 } } })), [ nodes[0], nodes[2], ]); }); -test('Union sift for nodes with id greater than 1 and nested object "child" having age greater than or equal to 18', (t) => { +test(`Union sift for nodes with id greater than 1 and nested object "child" having age greater than or equal to 18`, (t) => { t.deepEqual( nodes.filter( sift({ @@ -45,26 +45,26 @@ test('Union sift for nodes with id greater than 1 and nested object "child" havi }); const nodes2 = [ - { id: 1, title: 'My pretzel collection', postMeta: { rating: 97 } }, - { id: 2, title: 'Debugging the simulation', postMeta: { rating: 20 } }, + { id: 1, title: `My pretzel collection`, postMeta: { rating: 97 } }, + { id: 2, title: `Debugging the simulation`, postMeta: { rating: 20 } }, { id: 3, - title: 'Liquid Proust is a great tea vendor btw', + title: `Liquid Proust is a great tea vendor btw`, postMeta: { rating: 99 }, }, - { id: 4, title: 'Sitting in a chair', postMeta: { rating: 74 } }, + { id: 4, title: `Sitting in a chair`, postMeta: { rating: 74 } }, ]; -test('Sift by regex where title contains "pretzel"', (t) => { +test(`Sift by regex where title contains "pretzel"`, (t) => { t.deepEqual(nodes2.filter(sift({ title: { regex: /pretzel/i } })), [ nodes2[0], ]); }); -test('Union sift for nodes with wildcard title matching "*tion", rating greater than 80', (t) => { +test(`Union sift for nodes with wildcard title matching "*tion", rating greater than 80`, (t) => { t.deepEqual( nodes2.filter( - sift({ title: { wildcard: '*tion' }, postMeta: { rating: { gt: 80 } } }) + sift({ title: { wildcard: `*tion` }, postMeta: { rating: { gt: 80 } } }) ), [nodes2[0]] ); diff --git a/packages/core/src/utils/tests/typeOf.test.ts b/packages/core/src/utils/tests/typeOf.test.ts index 5af6060b..281475b6 100644 --- a/packages/core/src/utils/tests/typeOf.test.ts +++ b/packages/core/src/utils/tests/typeOf.test.ts @@ -1,20 +1,20 @@ import test from 'ava'; import typeOf from '../typeOf.js'; -test('Nullish types return specific type', (t) => { - t.is(typeOf(null), 'null'); - t.is(typeOf({}), 'object'); - t.is(typeOf(), 'undefined'); - t.is(typeOf(''), 'string'); +test(`Nullish types return specific type`, (t) => { + t.is(typeOf(null), `null`); + t.is(typeOf({}), `object`); + t.is(typeOf(), `undefined`); + t.is(typeOf(``), `string`); }); -test('Function is not an object', (t) => { +test(`Function is not an object`, (t) => { t.not( - typeOf(() => console.log("I'm a function!")), - 'object' + typeOf(() => console.log(`I'm a function!`)), + `object` ); }); -test('Date is not an object', (t) => { - t.not(typeOf(new Date()), 'object'); +test(`Date is not an object`, (t) => { + t.not(typeOf(new Date()), `object`); }); diff --git a/packages/core/src/utils/typeOf.ts b/packages/core/src/utils/typeOf.ts index 401d6a8d..c0fa43f7 100644 --- a/packages/core/src/utils/typeOf.ts +++ b/packages/core/src/utils/typeOf.ts @@ -6,12 +6,12 @@ */ export default function typeOf(obj?: T) { if (obj == null) { - return (obj + '').toLowerCase(); + return (obj + ``).toLowerCase(); } // implicit toString() conversion - var deepType = Object.prototype.toString.call(obj).slice(8, -1).toLowerCase(); - if (deepType === 'generatorfunction') { - return 'function'; + const deepType = Object.prototype.toString.call(obj).slice(8, -1).toLowerCase(); + if (deepType === `generatorfunction`) { + return `function`; } // Prevent overspecificity (for example, [object HTMLDivElement], etc). @@ -22,7 +22,7 @@ export default function typeOf(obj?: T) { /^(array|bigint|date|error|function|generator|regexp|symbol)$/ ) ? deepType - : typeof obj === 'object' || typeof obj === 'function' - ? 'object' - : typeof obj; + : typeof obj === `object` || typeof obj === `function` + ? `object` + : typeof obj; } diff --git a/packages/flatbread/src/cli/index.ts b/packages/flatbread/src/cli/index.ts index d6cf585a..e4a14776 100644 --- a/packages/flatbread/src/cli/index.ts +++ b/packages/flatbread/src/cli/index.ts @@ -6,7 +6,7 @@ import { networkInterfaces, release } from 'os'; import orchestrateProcesses from './runner'; import initConfig from './initConfig'; -const GRAPHQL_ENDPOINT = '/graphql'; +const GRAPHQL_ENDPOINT = `/graphql`; /** * Launch the GraphQL explorer in a browser. @@ -17,37 +17,37 @@ const GRAPHQL_ENDPOINT = '/graphql'; * @param {boolean} https whether the server is running on https */ async function launch(port: number, https: boolean): Promise { - const { exec } = await import('child_process'); - let cmd = 'open'; - if (process.platform == 'win32') { - cmd = 'start'; - } else if (process.platform == 'linux') { + const { exec } = await import(`child_process`); + let cmd = `open`; + if (process.platform == `win32`) { + cmd = `start`; + } else if (process.platform == `linux`) { if (/microsoft/i.test(release())) { - cmd = 'cmd.exe /c start'; + cmd = `cmd.exe /c start`; } else { - cmd = 'xdg-open'; + cmd = `xdg-open`; } } exec( - `${cmd} ${https ? 'https' : 'http'}://localhost:${port + GRAPHQL_ENDPOINT}` + `${cmd} ${https ? `https` : `http`}://localhost:${port + GRAPHQL_ENDPOINT}` ); } -const prog = sade('flatbread').version(version); +const prog = sade(`flatbread`).version(version); prog - .command('start [corunner]', 'Start flatbread with a GraphQL server') - .option('--, _', 'Pass options to the corunning script') - .option('-p, --port', 'Port to run the GraphQL server', 5057) - .option('-H, --https', 'Use self-signed HTTPS certificate', false) - .option('-o, --open', 'Open the explorer in a browser tab', false) + .command(`start [corunner]`, `Start flatbread with a GraphQL server`) + .option(`--, _`, `Pass options to the corunning script`) + .option(`-p, --port`, `Port to run the GraphQL server`, 5057) + .option(`-H, --https`, `Use self-signed HTTPS certificate`, false) + .option(`-o, --open`, `Open the explorer in a browser tab`, false) .option( - '-X, --exec', - 'The runner to execute the corunning script with. Defaults to your package manager (i.e. npm, pnpm, yarn)' + `-X, --exec`, + `The runner to execute the corunning script with. Defaults to your package manager (i.e. npm, pnpm, yarn)` ) .action(async (corunner, { _, port, https, open, exec }) => { // Combine the corunning script & the options passed to it - const secondaryScript = `${corunner} ${_.join(' ')}`; + const secondaryScript = `${corunner} ${_.join(` `)}`; // Yeet it into the all seeing eye of the universe orchestrateProcesses({ corunner: secondaryScript, @@ -59,7 +59,7 @@ prog }); prog - .command('init', 'Generate a flatbread.config.js file skeleton') + .command(`init`, `Generate a flatbread.config.js file skeleton`) .action(initConfig); prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` }); @@ -84,28 +84,28 @@ function welcome({ console.log( colors.bold( - gradient.fruit('\n Flatbread 🥯') + gradient.vice(` v${version}\n`) + gradient.fruit(`\n Flatbread 🥯`) + gradient.vice(` v${version}\n`) ) ); - const protocol = https ? 'https:' : 'http:'; + const protocol = https ? `https:` : `http:`; Object.values(networkInterfaces()).forEach((interfaces) => { if (!interfaces) return; interfaces.forEach((details) => { - if (details.family !== 'IPv4') return; + if (details.family !== `IPv4`) return; if (details.internal) { console.log( - ` ${colors.gray('graphql:')} ${protocol}//${colors.bold( + ` ${colors.gray(`graphql:`)} ${protocol}//${colors.bold( `localhost:${port + GRAPHQL_ENDPOINT}` )}` ); } else { - if (details.mac === '00:00:00:00:00:00') return; + if (details.mac === `00:00:00:00:00:00`) return; } }); }); - console.log('\n'); + console.log(`\n`); } diff --git a/packages/flatbread/src/cli/initConfig.ts b/packages/flatbread/src/cli/initConfig.ts index 8d4bbfce..42aa2c09 100644 --- a/packages/flatbread/src/cli/initConfig.ts +++ b/packages/flatbread/src/cli/initConfig.ts @@ -6,7 +6,7 @@ import { resolve } from 'path'; * Initialize the Flatbread config file */ const initConfig = () => { - const configFileName = 'flatbread.config.js'; + const configFileName = `flatbread.config.js`; const configPath = resolve(process.cwd(), configFileName); if (fs.existsSync(configPath)) { console.log(colors.red(`${configFileName} already exists`)); @@ -53,8 +53,8 @@ export default defineConfig({ ) ); console.log( - colors.bold("Don't forget to replace your dev/build scripts with:"), - colors.dim('\n\n"flatbread start -- "\n') + colors.bold(`Don't forget to replace your dev/build scripts with:`), + colors.dim(`\n\n"flatbread start -- "\n`) ); } }; diff --git a/packages/flatbread/src/cli/runner.ts b/packages/flatbread/src/cli/runner.ts index 5a9aafce..6f256dd2 100644 --- a/packages/flatbread/src/cli/runner.ts +++ b/packages/flatbread/src/cli/runner.ts @@ -26,7 +26,7 @@ export default function orchestrateProcesses({ packageManager = null, }: OrchestraOptions) { const pkgManager = packageManager || detectPkgManager(process.cwd()); - let serverModulePath = 'node_modules/flatbread/dist/graphql/server.js'; + const serverModulePath = `node_modules/flatbread/dist/graphql/server.js`; process.cwd(); const gql = fork(resolve(process.cwd(), serverModulePath), [], { @@ -34,21 +34,21 @@ export default function orchestrateProcesses({ FLATBREAD_PORT: String(flatbreadPort), }, }); - let runningScripts = [gql]; + const runningScripts = [gql]; - gql.on('message', (msg) => { - if (msg === 'flatbread-gql-ready') { + gql.on(`message`, (msg) => { + if (msg === `flatbread-gql-ready`) { // Start the target process (e.g. the dev server or the build script) - const targetProcess = spawn(pkgManager ?? 'npm run', [corunner], { + const targetProcess = spawn(pkgManager ?? `npm run`, [corunner], { shell: true, - stdio: 'inherit', + stdio: `inherit`, }); // targetProcess.stdout.pipe(process.stdout); runningScripts.push(targetProcess); // Exit the parent process when the target process exits - for (let script of runningScripts) { - script.on('close', function (code) { + for (const script of runningScripts) { + script.on(`close`, function (code) { process.exit(); }); } @@ -56,9 +56,9 @@ export default function orchestrateProcesses({ }); // End any remaining child processes when the parent process exits - process.on('exit', function () { + process.on(`exit`, function () { console.log( - colors.bold().green('\nFlatbread is done for now. Bye bye! 🥪') + colors.bold().green(`\nFlatbread is done for now. Bye bye! 🥪`) ); runningScripts.forEach(function (child) { child.kill(); @@ -71,9 +71,9 @@ export default function orchestrateProcesses({ * with that respective package manager. */ const lockToRunner: Record = { - 'pnpm-lock.yaml': 'pnpm', - 'yarn.lock': 'yarn', - 'package-lock.json': 'npm run', + 'pnpm-lock.yaml': `pnpm`, + 'yarn.lock': `yarn`, + 'package-lock.json': `npm run`, }; /** diff --git a/packages/flatbread/src/graphql/server.ts b/packages/flatbread/src/graphql/server.ts index e8fe3aae..299a2531 100644 --- a/packages/flatbread/src/graphql/server.ts +++ b/packages/flatbread/src/graphql/server.ts @@ -43,5 +43,5 @@ function communicateReadiness() { * This allows the parent process to wait for the server to be ready before continuing, like when you want the GraphQL server to be ready before starting the build process. * @see https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback */ - process.send && process.send('flatbread-gql-ready'); + process.send && process.send(`flatbread-gql-ready`); } diff --git a/packages/flatbread/src/utils/getSchema.ts b/packages/flatbread/src/utils/getSchema.ts index e91f9f99..ac70b5df 100644 --- a/packages/flatbread/src/utils/getSchema.ts +++ b/packages/flatbread/src/utils/getSchema.ts @@ -8,17 +8,17 @@ import type { ConfigResult, FlatbreadConfig } from '../'; * @returns user config promise */ export async function getConfig(): Promise> { - const { loadConfig } = await import('@flatbread/config'); + const { loadConfig } = await import(`@flatbread/config`); try { return await loadConfig(); } catch (err) { // Provide a helpful error message if the config file is not found console.error( - colors.red('\nFlatbread could not find a valid') + - colors.bold(' flatbread.config.js') + + colors.red(`\nFlatbread could not find a valid`) + + colors.bold(` flatbread.config.js`) + colors.red( - ' file. Make sure you have one with the correct schema in your project root to use this!\n' + ` file. Make sure you have one with the correct schema in your project root to use this!\n` ) ); console.error(err); diff --git a/packages/source-filesystem/src/index.ts b/packages/source-filesystem/src/index.ts index 87a73d76..88cf9342 100644 --- a/packages/source-filesystem/src/index.ts +++ b/packages/source-filesystem/src/index.ts @@ -39,13 +39,10 @@ async function getAllNodes( ): Promise> { const nodeEntries = await Promise.all( allContentTypes.map( - async (contentType): Promise> => - new Promise(async (res) => - res([ - contentType.collection, - await getNodesFromDirectory(contentType.path, config), - ]) - ) + async (contentType): Promise> => [ + contentType.collection, + await getNodesFromDirectory(contentType.path, config), + ] ) ); diff --git a/packages/source-filesystem/src/utils/gatherFileNodes.ts b/packages/source-filesystem/src/utils/gatherFileNodes.ts index 8f880636..4f7387d7 100644 --- a/packages/source-filesystem/src/utils/gatherFileNodes.ts +++ b/packages/source-filesystem/src/utils/gatherFileNodes.ts @@ -47,8 +47,8 @@ export default async function gatherFileNodes( * */ const formatValidExtensions = extensions?.map((ext) => - String(ext).charAt(0) === '.' ? ext : `.${ext}` - ) ?? ['.md', '.mdx', '.markdown']; + String(ext).charAt(0) === `.` ? ext : `.${ext}` + ) ?? [`.md`, `.mdx`, `.markdown`]; // gather all the globs in the path ( [capture-groups], **, *) const [pathPrefix, ...globs] = path.split(/\/(?:\[|\*+)/); @@ -56,7 +56,7 @@ export default async function gatherFileNodes( // for each segment - gather names for capture groups // and calculate what to remove from matches ex: [name].md => remove .md from match const segments = globs.map((branch) => { - let index = branch.indexOf(']'); + const index = branch.indexOf(`]`); if (index === -1) return null; return { name: branch.slice(0, index), diff --git a/packages/source-filesystem/src/utils/tests/gatherFileNodes.test.ts b/packages/source-filesystem/src/utils/tests/gatherFileNodes.test.ts index 6cd5822e..1e7d3c21 100644 --- a/packages/source-filesystem/src/utils/tests/gatherFileNodes.test.ts +++ b/packages/source-filesystem/src/utils/tests/gatherFileNodes.test.ts @@ -3,71 +3,71 @@ import gatherFileNodes from '../gatherFileNodes.js'; import { readDirectory } from './mocks.js'; const dirStructure = { - Comedy: ['Nine Lives of Tomas Katz, The.md', 'Road to Wellville, The.md'], - Drama: ['Life for Sale (Life for Sale (Kotirauha).md', 'Lap Dance'], + Comedy: [`Nine Lives of Tomas Katz, The.md`, `Road to Wellville, The.md`], + Drama: [`Life for Sale (Life for Sale (Kotirauha).md`, `Lap Dance`], - Documentary: ['TerrorStorm: A History of Government-Sponsored Terrorism.md'], + Documentary: [`TerrorStorm: A History of Government-Sponsored Terrorism.md`], 'random file.md': true, deeply: { - nested: ['file.md'], + nested: [`file.md`], }, }; const opts = { - extensions: ['.md'], + extensions: [`.md`], readDirectory: readDirectory(dirStructure), }; -test('basic flat folder', async (t) => { - const result = await gatherFileNodes('.', opts); +test(`basic flat folder`, async (t) => { + const result = await gatherFileNodes(`.`, opts); t.snapshot(result); }); -test('basic case', async (t) => { - const result = await gatherFileNodes('deeply/nested', opts); +test(`basic case`, async (t) => { + const result = await gatherFileNodes(`deeply/nested`, opts); t.snapshot(result); - const result2 = await gatherFileNodes('./deeply/nested', opts); + const result2 = await gatherFileNodes(`./deeply/nested`, opts); t.snapshot(result2); }); -test('double level recursion', async (t) => { - const result = await gatherFileNodes('deeply/**/*.md', opts); +test(`double level recursion`, async (t) => { + const result = await gatherFileNodes(`deeply/**/*.md`, opts); t.snapshot(result); }); -test('double level recursion named', async (t) => { - const result = await gatherFileNodes('deeply/[a]/[b].md', opts); +test(`double level recursion named`, async (t) => { + const result = await gatherFileNodes(`deeply/[a]/[b].md`, opts); t.snapshot(result); }); -test('single level recursion', async (t) => { - const result = await gatherFileNodes('./*.md', opts as any); +test(`single level recursion`, async (t) => { + const result = await gatherFileNodes(`./*.md`, opts as any); t.snapshot(result); }); -test('double level recursion named without parent directory', async (t) => { - const result = await gatherFileNodes('./[genre]/[title].md', opts); +test(`double level recursion named without parent directory`, async (t) => { + const result = await gatherFileNodes(`./[genre]/[title].md`, opts); t.snapshot(result); }); -test('single level named', async (t) => { - const result = await gatherFileNodes('./[title].md', opts); +test(`single level named`, async (t) => { + const result = await gatherFileNodes(`./[title].md`, opts); t.snapshot(result); }); -test('double level first named', async (t) => { - const result = await gatherFileNodes('./[genre]/*.md', opts); +test(`double level first named`, async (t) => { + const result = await gatherFileNodes(`./[genre]/*.md`, opts); t.snapshot(result); }); -test('double level second named', async (t) => { - const result = await gatherFileNodes('./**/[title].md', opts); +test(`double level second named`, async (t) => { + const result = await gatherFileNodes(`./**/[title].md`, opts); t.snapshot(result); }); -test('triple level', async (t) => { - const result = await gatherFileNodes('./[random]/[name]/[title].md', opts); +test(`triple level`, async (t) => { + const result = await gatherFileNodes(`./[random]/[name]/[title].md`, opts); t.snapshot(result); }); diff --git a/packages/source-filesystem/src/utils/tests/mocks.ts b/packages/source-filesystem/src/utils/tests/mocks.ts index 2001e33f..76d73805 100644 --- a/packages/source-filesystem/src/utils/tests/mocks.ts +++ b/packages/source-filesystem/src/utils/tests/mocks.ts @@ -1,11 +1,15 @@ import type { FileNode } from '../../types'; -export function readDirectory(dirStructure: any) { - return async (path: string) => { - const relativePath = path.replace(process.cwd(), '').replace(/^\//, ''); - const nodes = relativePath.split('/'); +interface DirStructure { + [key: string]: boolean | string[] | DirStructure; +} + +export function readDirectory(dirStructure: DirStructure) { + return (path: string): FileNode[] => { + const relativePath = path.replace(process.cwd(), ``).replace(/^\//, ``); + const nodes = relativePath.split(`/`); let node = nodes.reduce((cur: any, next) => cur?.[next], dirStructure); - if (relativePath === '') node = dirStructure; + if (relativePath === ``) node = dirStructure; if (!node) return []; if (Array.isArray(node)) { @@ -17,14 +21,14 @@ export function readDirectory(dirStructure: any) { })) as unknown as FileNode[]; } - if (typeof node === 'boolean') { - console.error('tried read directory on file'); + if (typeof node === `boolean`) { + console.error(`tried read directory on file`); return []; } return Object.entries(node).map(([name, value]) => { return { - isDirectory: () => typeof value !== 'boolean', + isDirectory: () => typeof value !== `boolean`, path: `${relativePath}/${name}`, name, data: {}, diff --git a/packages/transformer-markdown/src/graphql/schema-helpers.ts b/packages/transformer-markdown/src/graphql/schema-helpers.ts index 71f55751..8389dae9 100644 --- a/packages/transformer-markdown/src/graphql/schema-helpers.ts +++ b/packages/transformer-markdown/src/graphql/schema-helpers.ts @@ -10,13 +10,13 @@ import { MarkdownTransformerConfig } from '../types'; * A GraphQL field for the time to read the content, if it exists. */ export const timeToRead = (config: MarkdownTransformerConfig) => () => ({ - type: () => 'Int', + type: () => `Int`, description: - 'How long (in minutes) it would take an average reader to read the main content.', + `How long (in minutes) it would take an average reader to read the main content.`, args: { speed: { - type: () => 'Int', - description: 'The reading speed in words per minute', + type: () => `Int`, + description: `The reading speed in words per minute`, defaultValue: 230, }, }, @@ -30,10 +30,10 @@ export const timeToRead = (config: MarkdownTransformerConfig) => () => ({ const plaintext = parentNode ? sanitizeHtml(parentNode.html, { - allowedAttributes: {}, - allowedTags: [], - }).replace(/\r?\n|\r/g, ' ') - : ''; + allowedAttributes: {}, + allowedTags: [], + }).replace(/\r?\n|\r/g, ` `) + : ``; return estimateTimeToRead(plaintext, args.speed); }, @@ -43,12 +43,12 @@ export const timeToRead = (config: MarkdownTransformerConfig) => () => ({ * A GraphQL field for an excerpt of the content, if it exists. */ export const excerpt = (config: MarkdownTransformerConfig) => () => ({ - type: 'String', - description: 'A plaintext excerpt taken from the main content', + type: `String`, + description: `A plaintext excerpt taken from the main content`, args: { length: { - type: () => 'Int', - description: 'The length of the excerpt in words', + type: () => `Int`, + description: `The length of the excerpt in words`, defaultValue: 200, }, }, @@ -62,10 +62,10 @@ export const excerpt = (config: MarkdownTransformerConfig) => () => ({ const plaintext = parentNode ? sanitizeHtml(parentNode.html, { - allowedAttributes: {}, - allowedTags: [], - }).replace(/\r?\n|\r/g, ' ') - : ''; + allowedAttributes: {}, + allowedTags: [], + }).replace(/\r?\n|\r/g, ` `) + : ``; return createExcerpt(plaintext, args.length); }, }); @@ -74,8 +74,8 @@ export const excerpt = (config: MarkdownTransformerConfig) => () => ({ * A GraphQL field for the content as HTML, if it exists. */ export const html = (config: MarkdownTransformerConfig) => () => ({ - type: () => 'String', - description: 'The content as HTML', + type: () => `String`, + description: `The content as HTML`, resolve: async (parentNode: any) => { if (!parentNode.html) { parentNode.html = await transformContentToHTML( diff --git a/packages/transformer-markdown/src/index.ts b/packages/transformer-markdown/src/index.ts index e6f62939..3cfa54cf 100644 --- a/packages/transformer-markdown/src/index.ts +++ b/packages/transformer-markdown/src/index.ts @@ -22,7 +22,7 @@ export const parse = ( return { _filename: input.basename, _path: input.path, - _slug: slugify(input.stem ?? ''), + _slug: slugify(input.stem ?? ``), ...input.data, ...data, _content: { diff --git a/packages/transformer-markdown/src/processors/excerpt.ts b/packages/transformer-markdown/src/processors/excerpt.ts index 3ed1dc7f..2d73f8e5 100644 --- a/packages/transformer-markdown/src/processors/excerpt.ts +++ b/packages/transformer-markdown/src/processors/excerpt.ts @@ -7,5 +7,5 @@ export default function createExcerpt(text: string, length: number): string { if (text.length <= length) { return text; } - return text.slice(0, length) + '…'; + return text.slice(0, length) + `…`; } diff --git a/packages/transformer-markdown/src/processors/markdown.ts b/packages/transformer-markdown/src/processors/markdown.ts index 9066e9e2..3e97e779 100644 --- a/packages/transformer-markdown/src/processors/markdown.ts +++ b/packages/transformer-markdown/src/processors/markdown.ts @@ -56,8 +56,8 @@ export function createMarkdownProcessor( } if (options.externalLinks) { const externalLinksConfig = { - target: options?.externalLinksTarget ?? '_blank', - rel: options?.externalLinksRel ?? ['nofollow', 'noopener', 'noreferrer'], + target: options?.externalLinksTarget ?? `_blank`, + rel: options?.externalLinksRel ?? [`nofollow`, `noopener`, `noreferrer`], }; toMDAST.use(external, externalLinksConfig as ExternalLinksOptions); } diff --git a/packages/transformer-markdown/src/processors/toHTML.ts b/packages/transformer-markdown/src/processors/toHTML.ts index 8192ca7a..be61af9b 100644 --- a/packages/transformer-markdown/src/processors/toHTML.ts +++ b/packages/transformer-markdown/src/processors/toHTML.ts @@ -7,6 +7,6 @@ export default async function transformContentToHTML( markdownConfig: MarkdownConfig ): Promise { const markdownProcessor = createMarkdownProcessor(markdownConfig); - const html = content ? String(await markdownProcessor.process(content)) : ''; + const html = content ? String(await markdownProcessor.process(content)) : ``; return html; } diff --git a/packages/transformer-yaml/src/index.ts b/packages/transformer-yaml/src/index.ts index c96052c9..0cb5bcd4 100644 --- a/packages/transformer-yaml/src/index.ts +++ b/packages/transformer-yaml/src/index.ts @@ -16,11 +16,11 @@ export const parse = (input: VFile): EntryNode => { console.log(console.warn(warning.toString())), }); - if (typeof doc === 'object') { + if (typeof doc === `object`) { return { _filename: input.basename, _path: input.path, - _slug: slugify(input.stem ?? ''), + _slug: slugify(input.stem ?? ``), ...input.data, ...doc, };