From fe072a26b64eaab1d659bc94ba98a404de663e1f Mon Sep 17 00:00:00 2001 From: David Luecke Date: Fri, 1 Dec 2023 11:19:38 -0800 Subject: [PATCH 1/8] chore: Add a Pinion generator to initialise a new package (#3361) --- deno/README.md | 3 - generators/package.ts | 43 ++++ generators/package/index.tpl.ts | 13 ++ generators/package/license.tpl.ts | 33 +++ generators/package/package.json.tpl.ts | 58 +++++ generators/package/readme.md.tpl.ts | 30 +++ generators/package/test.tpl.ts | 19 ++ generators/package/tsconfig.json.tpl.ts | 16 ++ package-lock.json | 204 +++++++++++++----- package.json | 4 +- .../test/utils/provider.ts | 44 ++-- packages/memory/src/index.ts | 6 +- packages/mongodb/src/adapter.ts | 6 +- packages/schema/src/hooks/validate.ts | 4 +- 14 files changed, 395 insertions(+), 88 deletions(-) delete mode 100644 deno/README.md create mode 100644 generators/package.ts create mode 100644 generators/package/index.tpl.ts create mode 100644 generators/package/license.tpl.ts create mode 100644 generators/package/package.json.tpl.ts create mode 100644 generators/package/readme.md.tpl.ts create mode 100644 generators/package/test.tpl.ts create mode 100644 generators/package/tsconfig.json.tpl.ts diff --git a/deno/README.md b/deno/README.md deleted file mode 100644 index 9b5875bb10..0000000000 --- a/deno/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Feathers logo - -> **Important:** An experimental Deno first implementation is currently under development at https://github.com/feathersjs/feathers/pull/2828 diff --git a/generators/package.ts b/generators/package.ts new file mode 100644 index 0000000000..2793515f9f --- /dev/null +++ b/generators/package.ts @@ -0,0 +1,43 @@ +import type { Callable, PinionContext } from '@feathershq/pinion' +import { generator, install, prompt, runGenerators, toFile } from '@feathershq/pinion' + +export interface ModuleContext extends PinionContext { + name: string + uppername: string + description: string + moduleName: string + packagePath: Callable +} + +export const generate = (context: ModuleContext) => + generator(context) + .then( + prompt([ + { + type: 'input', + name: 'name', + message: 'What is the name of the module?' + }, + { + type: 'input', + name: 'description', + message: 'Write a short description' + } + ]) + ) + .then((ctx) => { + return { + ...ctx, + moduleName: `@feathersjs/${ctx.name}`, + uppername: ctx.name.charAt(0).toUpperCase() + ctx.name.slice(1), + packagePath: toFile('packages', ctx.name) + } + }) + .then(runGenerators(__dirname, 'package')) + .then( + install( + ['@types/node', 'shx', 'ts-node', 'typescript', 'mocha'], + true, + (context) => `npm --workspace packages/${context.name}` + ) + ) diff --git a/generators/package/index.tpl.ts b/generators/package/index.tpl.ts new file mode 100644 index 0000000000..676166608a --- /dev/null +++ b/generators/package/index.tpl.ts @@ -0,0 +1,13 @@ +import { generator, renderTemplate, toFile } from '@feathershq/pinion' +import { ModuleContext } from '../package' + +interface Context extends ModuleContext {} + +const template = ({ name }: Context) => ` +export function ${name}() { + return 'Hello from ${name}' +} +` + +export const generate = (context: Context) => + generator(context).then(renderTemplate(template, toFile(context.packagePath, 'src', 'index.ts'))) diff --git a/generators/package/license.tpl.ts b/generators/package/license.tpl.ts new file mode 100644 index 0000000000..173ed4e2e5 --- /dev/null +++ b/generators/package/license.tpl.ts @@ -0,0 +1,33 @@ +import { generator, renderTemplate, toFile } from '@feathershq/pinion' +import { ModuleContext } from '../package' + +interface Context extends ModuleContext {} + +export const generate = (context: Context) => + generator(context).then( + renderTemplate( + `The MIT License (MIT) + +Copyright (c) ${new Date().getFullYear()} Feathers Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + `, + toFile(context.packagePath, 'LICENSE') + ) + ) diff --git a/generators/package/package.json.tpl.ts b/generators/package/package.json.tpl.ts new file mode 100644 index 0000000000..ae9c8a1fd6 --- /dev/null +++ b/generators/package/package.json.tpl.ts @@ -0,0 +1,58 @@ +import { generator, toFile, writeJSON } from '@feathershq/pinion' +import { ModuleContext } from '../package' + +interface Context extends ModuleContext {} + +export const generate = (context: Context) => + generator(context).then( + writeJSON( + ({ moduleName, description, name }) => ({ + name: moduleName, + description, + version: '0.0.0', + homepage: 'https://feathersjs.com', + keywords: ['feathers'], + license: 'MIT', + repository: { + type: 'git', + url: 'git://github.com/feathersjs/feathers.git', + directory: `packages/${name}` + }, + author: { + name: 'Feathers contributor', + email: 'hello@feathersjs.com', + url: 'https://feathersjs.com' + }, + contributors: [], + bugs: { + url: 'https://github.com/feathersjs/feathers/issues' + }, + engines: { + node: '>= 20' + }, + files: ['CHANGELOG.md', 'LICENSE', 'README.md', 'src/**', 'lib/**', 'esm/**'], + // module: './esm/index.js', + main: './lib/index.js', + types: './src/index.ts', + exports: { + '.': { + // import: './esm/index.js', + require: './lib/index.js', + types: './src/index.ts' + } + }, + scripts: { + prepublish: 'npm run compile', + pack: 'npm pack --pack-destination ../generators/test/build', + compile: 'shx rm -rf lib/ && tsc && npm run pack', + test: 'mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts' + }, + publishConfig: { + access: 'public' + }, + dependencies: {}, + devDependencies: {} + }), + toFile('packages', context.name, 'package.json') + ) + ) diff --git a/generators/package/readme.md.tpl.ts b/generators/package/readme.md.tpl.ts new file mode 100644 index 0000000000..b5946f5f56 --- /dev/null +++ b/generators/package/readme.md.tpl.ts @@ -0,0 +1,30 @@ +import { generator, renderTemplate, toFile } from '@feathershq/pinion' +import { ModuleContext } from '../package' + +const template = ({ description, moduleName }: ModuleContext) => `# ${moduleName} + +[![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI) +[![Download Status](https://img.shields.io/npm/dm/${moduleName}.svg?style=flat-square)](https://www.npmjs.com/package/${moduleName}) +[![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx) + +> ${description} + +## Installation + +\`\`\` +npm install ${moduleName} --save +\`\`\` + +## Documentation + +Refer to the [Feathers API documentation](https://feathersjs.com/api) for more details. + +## License + +Copyright (c) ${new Date().getFullYear()} [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors) + +Licensed under the [MIT license](LICENSE). +` + +export const generate = (context: ModuleContext) => + generator(context).then(renderTemplate(template, toFile(context.packagePath, 'README.md'))) diff --git a/generators/package/test.tpl.ts b/generators/package/test.tpl.ts new file mode 100644 index 0000000000..c2b6f4f2e3 --- /dev/null +++ b/generators/package/test.tpl.ts @@ -0,0 +1,19 @@ +import { generator, renderTemplate, toFile } from '@feathershq/pinion' +import { ModuleContext } from '../package' + +interface Context extends ModuleContext {} + +const template = ({ moduleName, name }: Context) => /** ts */ `import { strict as assert } from 'assert' +import { ${name} } from '../src/index' + +describe('${moduleName}', () => { + it('initializes', () => { + assert.equal(${name}(), 'Hello from ${name}') + }) +}) +` + +export const generate = (context: Context) => + generator(context).then( + renderTemplate(template, toFile(context.packagePath, 'test', 'index.test.ts')) + ) diff --git a/generators/package/tsconfig.json.tpl.ts b/generators/package/tsconfig.json.tpl.ts new file mode 100644 index 0000000000..820b5a3a8d --- /dev/null +++ b/generators/package/tsconfig.json.tpl.ts @@ -0,0 +1,16 @@ +import { generator, toFile, writeJSON } from '@feathershq/pinion' +import { ModuleContext } from '../package' + +export const generate = (context: ModuleContext) => + generator(context).then( + writeJSON( + { + extends: '../../tsconfig', + include: ['src/**/*.ts'], + compilerOptions: { + outDir: 'lib' + } + }, + toFile(context.packagePath, 'tsconfig.json') + ) + ) diff --git a/package-lock.json b/package-lock.json index 42a3792c49..30e7e3e649 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "packages/*" ], "devDependencies": { + "@feathershq/pinion": "^0.4.0-pre.3", "@typescript-eslint/eslint-plugin": "^6.12.0", "@typescript-eslint/parser": "^6.12.0", "c8": "^8.0.1", @@ -2971,17 +2972,34 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@feathershq/api": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@feathershq/api/-/api-0.3.1.tgz", + "integrity": "sha512-jZRhz/3kQdlGC/bf//pTqPxqF+cAvz9OFNv4UhPeYRfLs4NmD9n/Rlis9hqFLZ6+MbY2jN78GUbomuGizDLT5A==", + "dev": true, + "dependencies": { + "@feathersjs/authentication-client": "^5.0.6", + "@feathersjs/feathers": "^5.0.6", + "@feathersjs/socketio-client": "^5.0.6", + "socket.io-client": "^4.6.2" + }, + "engines": { + "node": ">= 16" + } + }, "node_modules/@feathershq/pinion": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@feathershq/pinion/-/pinion-0.3.5.tgz", - "integrity": "sha512-mH7s62TlQKCbej2yFF139mAE9eEAvGmek0HkRW3pk7xWLMGXR94wbsW+KBMg6UHFPz71pevfb27tnF7zhKa1/g==", + "version": "0.4.0-pre.3", + "resolved": "https://registry.npmjs.org/@feathershq/pinion/-/pinion-0.4.0-pre.3.tgz", + "integrity": "sha512-nAH/PnivnqSooWs/TLnQIrswr0Sr10xZ9wRu9oXkdrSbaTnz16ZdP3dL2nkNU5B1r+A/i30JT6QM0Sq8bowb9A==", + "dev": true, "dependencies": { - "@types/inquirer": "^8.2.1", - "@types/yargs": "^17.0.10", - "chalk": "^4.0.1", + "@feathershq/api": "^0.3.1", + "@types/inquirer": "^9.0.3", + "chalk": "^4.0.0", + "commander": "^10.0.1", "inquirer": "^8.0.0", - "ts-node": "^10.9.1", - "yargs": "^17.5.1" + "open": "^8.4.0", + "ts-node": "^10.9.1" }, "bin": { "pinion": "bin/pinion" @@ -2994,42 +3012,13 @@ "url": "https://github.com/sponsors/daffl" } }, - "node_modules/@feathershq/pinion/node_modules/cliui": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", - "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.1", - "wrap-ansi": "^7.0.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@feathershq/pinion/node_modules/yargs": { - "version": "17.7.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", - "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", - "dependencies": { - "cliui": "^8.0.1", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.3", - "y18n": "^5.0.5", - "yargs-parser": "^21.1.1" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@feathershq/pinion/node_modules/yargs-parser": { - "version": "21.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", - "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "node_modules/@feathershq/pinion/node_modules/commander": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", + "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", + "dev": true, "engines": { - "node": ">=12" + "node": ">=14" } }, "node_modules/@feathersjs/adapter-commons": { @@ -3056,6 +3045,10 @@ "resolved": "packages/authentication-oauth", "link": true }, + "node_modules/@feathersjs/blablfdsjkl": { + "resolved": "packages/blablfdsjkl", + "link": true + }, "node_modules/@feathersjs/cli": { "resolved": "packages/cli", "link": true @@ -5305,9 +5298,10 @@ "integrity": "sha512-/K3ds8TRAfBvi5vfjuz8y6+GiAYBZ0x4tXv1Av6CWBWn0IlADc+ZX9pMq7oU0fNQPnBwIZl3rmeLp6SBApbxSQ==" }, "node_modules/@types/inquirer": { - "version": "8.2.6", - "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-8.2.6.tgz", - "integrity": "sha512-3uT88kxg8lNzY8ay2ZjP44DKcRaTGztqeIvN2zHvhzIBH/uAPaL75aBtdNRKbA7xXoMbBt5kX0M00VKAnfOYlA==", + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-9.0.7.tgz", + "integrity": "sha512-Q0zyBupO6NxGRZut/JdmqYKOnN95Eg5V8Csg3PGKkP+FnvsUZx1jAyK7fztIszxxMuoBA6E3KXWvdZVXIpx60g==", + "dev": true, "dependencies": { "@types/through": "*", "rxjs": "^7.2.0" @@ -5442,9 +5436,9 @@ } }, "node_modules/@types/node": { - "version": "20.10.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.0.tgz", - "integrity": "sha512-D0WfRmU9TQ8I9PFx9Yc+EBHw+vSpIub4IDvQivcp26PtPrdMGAq5SDcpXEo/epqa/DXotVpekHiLNTg3iaKXBQ==", + "version": "20.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.1.tgz", + "integrity": "sha512-T2qwhjWwGH81vUEx4EXmBKsTJRXFXNZTL4v0gi01+zyBmCwzE6TyHszqX01m+QHTEq+EZNo13NeJIdEqf+Myrg==", "dependencies": { "undici-types": "~5.26.4" } @@ -5516,9 +5510,9 @@ } }, "node_modules/@types/through": { - "version": "0.0.30", - "resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz", - "integrity": "sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==", + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.33.tgz", + "integrity": "sha512-HsJ+z3QuETzP3cswwtzt2vEIiHBk/dCcHGhbmG5X3ecnwFD/lPrMpliGXxSCg03L9AhrdwA4Oz/qfspkDW+xGQ==", "dependencies": { "@types/node": "*" } @@ -5549,17 +5543,17 @@ } }, "node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", + "version": "17.0.32", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", + "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", "dependencies": { "@types/yargs-parser": "*" } }, "node_modules/@types/yargs-parser": { - "version": "21.0.0", - "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz", - "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==" + "version": "21.0.3", + "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz", + "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==" }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "6.12.0", @@ -23419,6 +23413,30 @@ "url": "https://github.com/sponsors/daffl" } }, + "packages/blabla": { + "name": "@feathersjs/blabla", + "version": "0.0.0", + "extraneous": true, + "license": "MIT", + "devDependencies": { + "@types/node": "^20.10.1", + "mocha": "^10.2.0", + "shx": "^0.3.4", + "ts-node": "^10.9.1", + "typescript": "^5.3.2" + }, + "engines": { + "node": ">= 20" + } + }, + "packages/blablfdsjkl": { + "version": "0.0.0", + "license": "MIT", + "devDependencies": {}, + "engines": { + "node": ">= 20" + } + }, "packages/cli": { "name": "@feathersjs/cli", "version": "5.0.12", @@ -23716,6 +23734,51 @@ "url": "https://github.com/sponsors/daffl" } }, + "packages/generators/node_modules/@feathershq/pinion": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@feathershq/pinion/-/pinion-0.3.5.tgz", + "integrity": "sha512-mH7s62TlQKCbej2yFF139mAE9eEAvGmek0HkRW3pk7xWLMGXR94wbsW+KBMg6UHFPz71pevfb27tnF7zhKa1/g==", + "dependencies": { + "@types/inquirer": "^8.2.1", + "@types/yargs": "^17.0.10", + "chalk": "^4.0.1", + "inquirer": "^8.0.0", + "ts-node": "^10.9.1", + "yargs": "^17.5.1" + }, + "bin": { + "pinion": "bin/pinion" + }, + "engines": { + "node": ">= 14" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/daffl" + } + }, + "packages/generators/node_modules/@types/inquirer": { + "version": "8.2.10", + "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-8.2.10.tgz", + "integrity": "sha512-IdD5NmHyVjWM8SHWo/kPBgtzXatwPkfwzyP3fN1jF2g9BWt5WO+8hL2F4o2GKIYsU40PpqeevuUWvkS/roXJkA==", + "dependencies": { + "@types/through": "*", + "rxjs": "^7.2.0" + } + }, + "packages/generators/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, "packages/generators/node_modules/type-fest": { "version": "4.8.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.8.2.tgz", @@ -23728,6 +23791,31 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "packages/generators/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "packages/generators/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "engines": { + "node": ">=12" + } + }, "packages/knex": { "name": "@feathersjs/knex", "version": "5.0.12", diff --git a/package.json b/package.json index cba164d025..bd65ac705e 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,11 @@ "update-dependencies": "ncu -u && lerna exec -- ncu -u --dep prod,dev,optional,peer -x node-fetch,chalk,\"@sinclair/typebox\"", "clean": "find . -name node_modules -exec rm -rf '{}' + && find . -name package-lock.json -exec rm -rf '{}' +", "test:deno": "deno test --config deno/tsconfig.json deno/test.ts", - "test": "npm run lint && npm run compile && c8 lerna run test --ignore @feathersjs/tests" + "test": "npm run lint && npm run compile && c8 lerna run test --ignore @feathersjs/tests", + "generate:package": "pinion run generators/package.ts" }, "devDependencies": { + "@feathershq/pinion": "^0.4.0-pre.3", "@typescript-eslint/eslint-plugin": "^6.12.0", "@typescript-eslint/parser": "^6.12.0", "c8": "^8.0.1", diff --git a/packages/authentication-oauth/test/utils/provider.ts b/packages/authentication-oauth/test/utils/provider.ts index 77eafa7a84..7a63e25e87 100644 --- a/packages/authentication-oauth/test/utils/provider.ts +++ b/packages/authentication-oauth/test/utils/provider.ts @@ -68,10 +68,10 @@ const oauth1 = (port: number) => provider === 'getpocket' ? res.end(qs.stringify({ code: 'code' })) : provider === 'sellsy' - ? res.end( - 'authentification_url=https://apifeed.sellsy.com/0/login.php&oauth_token=token&oauth_token_secret=secret&oauth_callback_confirmed=true' - ) - : res.end(qs.stringify({ oauth_token: 'token', oauth_token_secret: 'secret' })) + ? res.end( + 'authentification_url=https://apifeed.sellsy.com/0/login.php&oauth_token=token&oauth_token_secret=secret&oauth_callback_confirmed=true' + ) + : res.end(qs.stringify({ oauth_token: 'token', oauth_token_secret: 'secret' })) }) } else if (/authorize_url/.test(url)) { const location = callback + '?' + qs.stringify({ oauth_token: 'token', oauth_verifier: 'verifier' }) @@ -180,26 +180,26 @@ const oauth2 = (port: number) => provider === 'concur' ? res.end(' token refresh ') : provider === 'withings' - ? res.end( - JSON.stringify({ - body: { + ? res.end( + JSON.stringify({ + body: { + access_token: 'token', + refresh_token: 'refresh', + expires_in: 3600 + } + }) + ) + : res.end( + JSON.stringify({ access_token: 'token', refresh_token: 'refresh', - expires_in: 3600 - } - }) - ) - : res.end( - JSON.stringify({ - access_token: 'token', - refresh_token: 'refresh', - expires_in: 3600, - id_token: openid ? sign({ typ: 'JWT' }, { nonce: 'whatever' }, 'signature') : undefined, - open_id: provider === 'tiktok' ? 'id' : undefined, - uid: provider === 'weibo' ? 'id' : undefined, - openid: provider === 'wechat' ? 'openid' : undefined - }) - ) + expires_in: 3600, + id_token: openid ? sign({ typ: 'JWT' }, { nonce: 'whatever' }, 'signature') : undefined, + open_id: provider === 'tiktok' ? 'id' : undefined, + uid: provider === 'weibo' ? 'id' : undefined, + openid: provider === 'wechat' ? 'openid' : undefined + }) + ) }) } else if (/authorize_error_message/.test(url)) { on.authorize({ url, query, headers }) diff --git a/packages/memory/src/index.ts b/packages/memory/src/index.ts index 1843eeda86..543592aec1 100644 --- a/packages/memory/src/index.ts +++ b/packages/memory/src/index.ts @@ -196,7 +196,11 @@ export class MemoryAdapter< async _patch(id: null, data: PatchData | Partial, params?: ServiceParams): Promise async _patch(id: Id, data: PatchData | Partial, params?: ServiceParams): Promise - async _patch(id: NullableId, data: PatchData | Partial, _params?: ServiceParams): Promise + async _patch( + id: NullableId, + data: PatchData | Partial, + _params?: ServiceParams + ): Promise async _patch( id: NullableId, data: PatchData | Partial, diff --git a/packages/mongodb/src/adapter.ts b/packages/mongodb/src/adapter.ts index 7112890b1b..5b60b7dd7e 100644 --- a/packages/mongodb/src/adapter.ts +++ b/packages/mongodb/src/adapter.ts @@ -303,7 +303,11 @@ export class MongoDbAdapter< async _patch(id: null, data: PatchData | Partial, params?: ServiceParams): Promise async _patch(id: AdapterId, data: PatchData | Partial, params?: ServiceParams): Promise - async _patch(id: NullableAdapterId, data: PatchData | Partial, _params?: ServiceParams): Promise + async _patch( + id: NullableAdapterId, + data: PatchData | Partial, + _params?: ServiceParams + ): Promise async _patch( id: NullableAdapterId, _data: PatchData | Partial, diff --git a/packages/schema/src/hooks/validate.ts b/packages/schema/src/hooks/validate.ts index 7b76a8c8ab..37bcfb0a60 100644 --- a/packages/schema/src/hooks/validate.ts +++ b/packages/schema/src/hooks/validate.ts @@ -36,8 +36,8 @@ export const validateData = (schema: Schema | DataVa typeof (schema as Schema).validate === 'function' ? (schema as Schema).validate.bind(schema) : typeof schema === 'function' - ? schema - : (schema as any)[context.method] + ? schema + : (schema as any)[context.method] if (validator) { try { From 7fd8300908d64548bdd4ff6fcc307b704640810e Mon Sep 17 00:00:00 2001 From: David Luecke Date: Tue, 5 Dec 2023 18:05:17 -0800 Subject: [PATCH 2/8] chore: Fix website build and disable language selection (#3367) --- docs/.vitepress/components.d.ts | 10 +- docs/.vitepress/config.ts | 11 - docs/.vitepress/highlight.ts | 95 - docs/.vitepress/style/main.postcss | 38 +- docs/.vitepress/theme/FeathersLayout.vue | 2 - docs/api/client/rest.md | 6 +- docs/api/client/socketio.md | 8 +- docs/auto-imports.d.ts | 6 +- docs/package.json | 46 +- package-lock.json | 32825 ++++++++++-------- package.json | 14 +- packages/adapter-commons/package.json | 2 +- packages/adapter-tests/package.json | 2 +- packages/authentication-client/package.json | 2 +- packages/authentication-local/package.json | 2 +- packages/authentication-oauth/package.json | 2 +- packages/authentication/package.json | 2 +- packages/cli/package.json | 4 +- packages/client/package.json | 4 +- packages/commons/package.json | 2 +- packages/configuration/package.json | 2 +- packages/errors/package.json | 2 +- packages/express/package.json | 2 +- packages/feathers/package.json | 2 +- packages/generators/package.json | 4 +- packages/knex/package.json | 2 +- packages/koa/package.json | 2 +- packages/memory/package.json | 2 +- packages/mongodb/package.json | 2 +- packages/rest-client/package.json | 2 +- packages/schema/package.json | 4 +- packages/socketio-client/package.json | 2 +- packages/socketio/package.json | 2 +- packages/tests/package.json | 2 +- packages/transport-commons/package.json | 2 +- packages/typebox/package.json | 2 +- 36 files changed, 19165 insertions(+), 13954 deletions(-) delete mode 100644 docs/.vitepress/highlight.ts diff --git a/docs/.vitepress/components.d.ts b/docs/.vitepress/components.d.ts index f4fb8aafe9..febaf90a5b 100644 --- a/docs/.vitepress/components.d.ts +++ b/docs/.vitepress/components.d.ts @@ -1,11 +1,11 @@ -// generated by unplugin-vue-components -// We suggest you to commit this file into source control +/* eslint-disable */ +/* prettier-ignore */ +// @ts-nocheck +// Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { Badges: typeof import('./components/Badges.vue')['default'] BlockQuote: typeof import('./components/BlockQuote.vue')['default'] diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index b6a966ff46..ac98489661 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -1,5 +1,4 @@ import { defineConfig } from 'vitepress' -import { highlight } from './highlight' import { discord, font, github, ogImage, ogUrl, twitter, feathersDescription, feathersName } from './meta' import sidebar from './config.sidebar' import nav from './config.nav' @@ -47,16 +46,6 @@ export default defineConfig({ ], lastUpdated: true, markdown: { - config: async (md) => { - md.set({ - highlight: await highlight({ - light: 'vitesse-light', - dark: 'vitesse-dark' - }) - }) - - return md - }, theme: { light: 'vitesse-light', dark: 'vitesse-dark' diff --git a/docs/.vitepress/highlight.ts b/docs/.vitepress/highlight.ts deleted file mode 100644 index d70dc971f6..0000000000 --- a/docs/.vitepress/highlight.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { IThemeRegistration, getHighlighter, HtmlRendererOptions } from 'shiki' -import type { ThemeOptions } from 'vitepress' -import { getJavaScript, PRETTIERRC } from '@feathersjs/generators/lib/commons' -import prettier from 'prettier' - -/** - * 2 steps: - * - * 1. convert attrs into line numbers: - * {4,7-13,16,23-27,40} -> [4,7,8,9,10,11,12,13,16,23,24,25,26,27,40] - * 2. convert line numbers into line options: - * [{ line: number, classes: string[] }] - */ -const attrsToLines = (attrs: string): HtmlRendererOptions['lineOptions'] => { - const result: number[] = [] - if (!attrs.trim()) { - return [] - } - attrs - .split(',') - .map((v) => v.split('-').map((v) => parseInt(v, 10))) - .forEach(([start, end]) => { - if (start && end) { - result.push(...Array.from({ length: end - start + 1 }, (_, i) => start + i)) - } else { - result.push(start) - } - }) - return result.map((v) => ({ - line: v, - classes: ['highlighted'] - })) -} - -export async function highlight( - theme: ThemeOptions = 'material-palenight' -): Promise<(str: string, lang: string, attrs: string) => string> { - const hasSingleTheme = typeof theme === 'string' || 'name' in theme - const getThemeName = (themeValue: IThemeRegistration) => - typeof themeValue === 'string' ? themeValue : themeValue.name - - const highlighter = await getHighlighter({ - themes: hasSingleTheme ? [theme] : [theme.dark, theme.light] - }) - const preRE = /^/ - const vueRE = /-vue$/ - - const highlightCode = (str: string, lang: string, attrs: string, additionalClass: string = '') => { - const vPre = vueRE.test(lang) ? '' : 'v-pre' - lang = lang.replace(vueRE, '').toLowerCase() - - const lineOptions = attrsToLines(attrs) - - if (hasSingleTheme) { - return highlighter - .codeToHtml(str, { lang, lineOptions, theme: getThemeName(theme) }) - .replace(preRE, `
`)
-    }
-
-    const dark = highlighter
-      .codeToHtml(str, { lang, lineOptions, theme: getThemeName(theme.dark) })
-      .replace(preRE, `
`)
-
-    const light = highlighter
-      .codeToHtml(str, { lang, lineOptions, theme: getThemeName(theme.light) })
-      .replace(preRE, `
`)
-
-    return dark + light
-  }
-
-  return (code: string, lang: string, attrs: string) => {
-    if (lang === 'ts' || lang === 'typescript') {
-      const prettierOptions = {
-        ...PRETTIERRC,
-        printWidth: 90
-      }
-
-      const javascript = getJavaScript(code)
-      const formattedJS = prettier.format(javascript, {
-        ...prettierOptions,
-        parser: 'babel'
-      })
-      const formattedTS = prettier.format(code, {
-        ...prettierOptions,
-        parser: 'typescript'
-      })
-      const tsCode = highlightCode(formattedTS, lang, attrs, 'language-selectable')
-      const jsCode = highlightCode(formattedJS, 'js', '', 'language-selectable')
-
-      return tsCode + jsCode
-    }
-
-    return highlightCode(code, lang, attrs)
-  }
-}
diff --git a/docs/.vitepress/style/main.postcss b/docs/.vitepress/style/main.postcss
index bbd32a60e2..2e6670f070 100644
--- a/docs/.vitepress/style/main.postcss
+++ b/docs/.vitepress/style/main.postcss
@@ -1,8 +1,18 @@
 @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap');
 
 :root body {
-  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
-    'Open Sans', 'Helvetica Neue', sans-serif !important;
+  font-family:
+    'Poppins',
+    -apple-system,
+    BlinkMacSystemFont,
+    'Segoe UI',
+    Roboto,
+    Oxygen,
+    Ubuntu,
+    Cantarell,
+    'Open Sans',
+    'Helvetica Neue',
+    sans-serif !important;
 }
 html {
   -webkit-tap-highlight-color: transparent;
@@ -12,6 +22,12 @@ html {
 .home-page .VPNavBar {
   border-bottom: none;
 }
+
+.home-page .VPNav {
+  --vp-nav-bg-color: transparent;
+  --vp-c-gutter: transparent;
+}
+
 /* Remove the search button from the home page. Keyboard shortcut still works. */
 .home-page #docsearch {
   /* display: none; */
@@ -99,24 +115,6 @@ body .bg-base-100 {
     backdrop-filter: none;
     -webkit-backdrop-filter: none;
   }
-  #app:not('.home-page') .VPNav.no-sidebar {
-    backdrop-filter: saturate(50%) blur(2px);
-    -webkit-backdrop-filter: saturate(50%) blur(2px);
-    background: none;
-  }
-  .dark #app .VPNav.no-sidebar {
-    backdrop-filter: saturate(50%) blur(2px);
-    -webkit-backdrop-filter: saturate(50%) blur(2px);
-    background: none;
-  }
-  #app:not('.home-page') .VPNavBar.has-sidebar .content[data-v-1dc33fef] {
-    backdrop-filter: saturate(50%) blur(2px);
-    -webkit-backdrop-filter: saturate(50%) blur(2px);
-    background: #ffffffcc;
-  }
-  .dark #app:not('.home-page') .VPNavBar.has-sidebar .content[data-v-1dc33fef] {
-    background: #242424cc;
-  }
 }
 
 /* Overrides */
diff --git a/docs/.vitepress/theme/FeathersLayout.vue b/docs/.vitepress/theme/FeathersLayout.vue
index 033c35e569..3b1ac2b8e6 100644
--- a/docs/.vitepress/theme/FeathersLayout.vue
+++ b/docs/.vitepress/theme/FeathersLayout.vue
@@ -1,7 +1,6 @@