Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps-dev): replace standard with neostandard #779

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/fastify-cli/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-cli/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/fastify-cli.svg?style=flat)](https://www.npmjs.com/package/fastify-cli)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Command line tools for [Fastify](https://github.com/fastify/fastify).
Generate, write, and run an application with one single command!
Expand Down Expand Up @@ -326,15 +326,15 @@ if your project uses `@fastify/swagger`, `fastify-cli` can generate and write ou

```diff
"devDependencies": {
+ "standard": "^11.0.1",
+ "neostandard": "^0.11.9",
}

"scripts": {
+ "pretest": "standard",
+ "pretest": "eslint",
"test": "node --test test/**/*.test.js",
"start": "fastify start -l info app.js",
"dev": "fastify start -l info -P app.js",
+ "lint": "standard --fix"
+ "lint": "eslint --fix"
},
```

Expand Down
10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

module.exports = require('neostandard')({
ignores: [
...require('neostandard').resolveIgnoresFromGitignore(),
'test/data/parsing-error.js',
'test/data/undefinedVariable.js',
],
ts: true
})
8 changes: 4 additions & 4 deletions helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fastify from 'fastify'

declare module 'fastify-cli/helper.js' {
module helper {
export function build(args: Array<string>, additionalOptions?: Object, serverOptions?: Object): ReturnType<typeof fastify>;
}
module helper {
export function build (args: Array<string>, additionalOptions?: Object, serverOptions?: Object): ReturnType<typeof fastify>
}

export = helper;
export = helper
}
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"fastify": "cli.js"
},
"scripts": {
"lint": "standard",
"lint:fix": "standard --fix",
"lint": "eslint",
"lint:fix": "eslint --fix",
"pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'",
"test": "npm run unit:suites && c8 --clean npm run test:cli-and-typescript",
"unit:cjs": "node suite-runner.js \"templates/app/test/**/*.test.js\"",
Expand Down Expand Up @@ -46,12 +46,6 @@
"url": "https://github.com/fastify/fastify-cli/issues"
},
"homepage": "https://github.com/fastify/fastify-cli#readme",
"standard": {
"ignore": [
"test/data/parsing-error.js",
"test/data/undefinedVariable.js"
]
},
"dependencies": {
"@fastify/deepmerge": "^2.0.0",
"chalk": "^4.1.2",
Expand Down Expand Up @@ -81,11 +75,11 @@
"cross-env": "^7.0.3",
"fastify-tsconfig": "^2.0.0",
Fdawgs marked this conversation as resolved.
Show resolved Hide resolved
"minimatch": "^9.0.5",
"neostandard": "^0.12.0",
"proxyquire": "^2.1.3",
"rimraf": "^3.0.2",
"simple-get": "^4.0.0",
"sinon": "^19.0.2",
"standard": "^17.0.0",
"strip-ansi": "^6.0.1",
"tap": "^16.1.0",
"ts-node": "^10.4.0",
Expand Down
18 changes: 8 additions & 10 deletions templates/app-ts-esm/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import * as path from 'node:path';
import AutoLoad, {AutoloadPluginOptions} from '@fastify/autoload';
import { FastifyPluginAsync } from 'fastify';
import * as path from 'node:path'
import AutoLoad, { AutoloadPluginOptions } from '@fastify/autoload'
import { FastifyPluginAsync } from 'fastify'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

export type AppOptions = {
// Place your custom options for app below here.
} & Partial<AutoloadPluginOptions>;

} & Partial<AutoloadPluginOptions>

// Pass --options via CLI arguments in command to enable these options.
const options: AppOptions = {
}

const app: FastifyPluginAsync<AppOptions> = async (
fastify,
opts
fastify,
opts
): Promise<void> => {
// Place here your custom code!

Expand All @@ -26,7 +25,7 @@
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
void fastify.register(AutoLoad, {

Check failure on line 28 in templates/app-ts-esm/src/app.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'

Check failure on line 28 in templates/app-ts-esm/src/app.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'
dir: path.join(__dirname, 'plugins'),
options: opts,
forceESM: true
Expand All @@ -34,13 +33,12 @@

// This loads all plugins defined in routes
// define your routes in one of these
void fastify.register(AutoLoad, {

Check failure on line 36 in templates/app-ts-esm/src/app.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'

Check failure on line 36 in templates/app-ts-esm/src/app.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'
dir: path.join(__dirname, 'routes'),
options: opts,
forceESM: true
})
}

};

export default app;
export default app
export { app, options }
4 changes: 2 additions & 2 deletions templates/app-ts-esm/src/routes/example/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FastifyPluginAsync } from "fastify"
import { FastifyPluginAsync } from 'fastify'

const example: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
fastify.get('/', async function (request, reply) {
return 'this is an example'
})
}

export default example;
export default example
2 changes: 1 addition & 1 deletion templates/app-ts-esm/src/routes/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const root: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
})
}

export default root;
export default root
2 changes: 1 addition & 1 deletion templates/app-ts-esm/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

export type TestContext = {
after: typeof test.after
};
}

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
Expand All @@ -29,7 +29,7 @@
const app = await helper.build(argv, await config())

// Tear down our app after we are done
t.after(() => void app.close())

Check failure on line 32 in templates/app-ts-esm/test/helper.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'

Check failure on line 32 in templates/app-ts-esm/test/helper.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'

return app
}
Expand Down
14 changes: 7 additions & 7 deletions templates/app-ts/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'node:path';
import AutoLoad, {AutoloadPluginOptions} from '@fastify/autoload';
import { FastifyPluginAsync, FastifyServerOptions } from 'fastify';
import { join } from 'node:path'
import AutoLoad, { AutoloadPluginOptions } from '@fastify/autoload'
import { FastifyPluginAsync, FastifyServerOptions } from 'fastify'

export interface AppOptions extends FastifyServerOptions, Partial<AutoloadPluginOptions> {

Expand All @@ -10,8 +10,8 @@
}

const app: FastifyPluginAsync<AppOptions> = async (
fastify,
opts
fastify,
opts
): Promise<void> => {
// Place here your custom code!

Expand All @@ -20,18 +20,18 @@
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
void fastify.register(AutoLoad, {

Check failure on line 23 in templates/app-ts/src/app.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'

Check failure on line 23 in templates/app-ts/src/app.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'
dir: join(__dirname, 'plugins'),
options: opts
})

// This loads all plugins defined in routes
// define your routes in one of these
void fastify.register(AutoLoad, {

Check failure on line 30 in templates/app-ts/src/app.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'

Check failure on line 30 in templates/app-ts/src/app.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'
dir: join(__dirname, 'routes'),
options: opts
})
};
}

export default app;
export default app
export { app, options }
4 changes: 2 additions & 2 deletions templates/app-ts/src/routes/example/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FastifyPluginAsync } from "fastify"
import { FastifyPluginAsync } from 'fastify'

const example: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
fastify.get('/', async function (request, reply) {
return 'this is an example'
})
}

export default example;
export default example
2 changes: 1 addition & 1 deletion templates/app-ts/src/routes/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const root: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
})
}

export default root;
export default root
4 changes: 2 additions & 2 deletions templates/app-ts/test/helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// This file contains code that we reuse between our tests.
const helper = require('fastify-cli/helper.js')
import * as path from 'node:path'
import * as test from 'node:test'
const helper = require('fastify-cli/helper.js')

export type TestContext = {
after: typeof test.after
};
}

const AppPath = path.join(__dirname, '..', 'src', 'app.ts')

Expand All @@ -26,7 +26,7 @@
const app = await helper.build(argv, await config())

// Tear down our app after we are done
t.after(() => void app.close())

Check failure on line 29 in templates/app-ts/test/helper.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'

Check failure on line 29 in templates/app-ts/test/helper.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected 'undefined' and instead saw 'void'

return app
}
Expand Down
18 changes: 9 additions & 9 deletions templates/eject-ts/server.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Read the .env file.
import * as dotenv from "dotenv";
dotenv.config();
import * as dotenv from 'dotenv'

// Require the framework
import Fastify from "fastify";
import Fastify from 'fastify'

// Require library to exit fastify process, gracefully (if possible)
import closeWithGrace from "close-with-grace";
import closeWithGrace from 'close-with-grace'
dotenv.config()

// Instantiate Fastify with some config
const app = Fastify({
logger: true,
});
})

// Register your application as a normal plugin.
app.register(import("./app"));
app.register(import('./app'))

// delay is the number of milliseconds for the graceful close to finish
closeWithGrace({ delay: parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY) || 500 }, async function ({ signal, err, manual }) {
Expand All @@ -27,7 +27,7 @@ closeWithGrace({ delay: parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY) || 500 }
// Start listening.
app.listen({ port: parseInt(process.env.PORT) || 3000 }, (err: any) => {
if (err) {
app.log.error(err);
process.exit(1);
app.log.error(err)
process.exit(1)
}
});
})
2 changes: 1 addition & 1 deletion test/data/custom-import.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* global GLOBAL_MODULE_3 */
globalThis.GLOBAL_MODULE_3 = true // eslint-disable-line
globalThis.GLOBAL_MODULE_3 = true
console.log('this is module to be preloaded that sets GLOBAL_MODULE_3=', GLOBAL_MODULE_3)
2 changes: 1 addition & 1 deletion test/data/custom-import2.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* global GLOBAL_MODULE_4 */
globalThis.GLOBAL_MODULE_4 = true // eslint-disable-line
globalThis.GLOBAL_MODULE_4 = true
console.log('this is module to be preloaded that sets GLOBAL_MODULE_4=', GLOBAL_MODULE_4)
84 changes: 42 additions & 42 deletions test/templates/app-ts.test.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
import { fastify } from 'fastify';
import { test, TestContext } from 'node:test';
const sgetOriginal = require('simple-get').concat
import { fastify } from 'fastify'
import { test, TestContext } from 'node:test'

import { AddressInfo } from "net";
import appDefault, { app } from '../../templates/app-ts/src/app';
import { AddressInfo } from 'net'
import appDefault, { app } from '../../templates/app-ts/src/app'
const sgetOriginal = require('simple-get').concat

const sget = (opts: Record<string, any>): Record<string, any> => {
return new Promise((resolve, reject) => {
sgetOriginal(opts, (err: Error, response: any, body: any) => {
if (err) return reject(err)
return resolve({ response, body })
})
return new Promise((resolve, reject) => {
sgetOriginal(opts, (err: Error, response: any, body: any) => {
if (err) return reject(err)
return resolve({ response, body })
})
})
}

test('should print routes for TS app', async (t: TestContext) => {
t.plan(4)
test('should print routes for TS app', async (t: TestContext) => {
t.plan(4)

const fastifyApp = fastify({}, );
await app(fastifyApp, {});
await fastifyApp.ready();
await fastifyApp.listen({ port: 3000 })
const fastifyApp = fastify({})
await app(fastifyApp, {})
await fastifyApp.ready()
await fastifyApp.listen({ port: 3000 })

const { response, body } = await sget({
method: 'GET',
url: `http://localhost:${(fastifyApp.server.address() as AddressInfo).port}`
})
t.assert.equal(response.statusCode, 200)
t.assert.equal(response.headers['content-length'], '' + body.length)
t.assert.deepStrictEqual(JSON.parse(body), { root: true })
const { response, body } = await sget({
method: 'GET',
url: `http://localhost:${(fastifyApp.server.address() as AddressInfo).port}`
})
t.assert.equal(response.statusCode, 200)
t.assert.equal(response.headers['content-length'], '' + body.length)
t.assert.deepStrictEqual(JSON.parse(body), { root: true })

await fastifyApp.close();
t.assert.ok('server closed')
await fastifyApp.close()
t.assert.ok('server closed')
})

test('should print routes for default TS app', async (t: TestContext) => {
t.plan(4)

const fastifyApp = fastify({}, );
await appDefault(fastifyApp, {});
await fastifyApp.ready();
await fastifyApp.listen({ port: 3000 })

const { response, body } = await sget({
method: 'GET',
url: `http://localhost:${(fastifyApp.server.address() as AddressInfo).port}`
})
t.assert.equal(response.statusCode, 200)
t.assert.equal(response.headers['content-length'], '' + body.length)
t.assert.deepStrictEqual(JSON.parse(body), { root: true })

await fastifyApp.close();
t.assert.ok('server closed')
t.plan(4)

const fastifyApp = fastify({})
await appDefault(fastifyApp, {})
await fastifyApp.ready()
await fastifyApp.listen({ port: 3000 })

const { response, body } = await sget({
method: 'GET',
url: `http://localhost:${(fastifyApp.server.address() as AddressInfo).port}`
})
t.assert.equal(response.statusCode, 200)
t.assert.equal(response.headers['content-length'], '' + body.length)
t.assert.deepStrictEqual(JSON.parse(body), { root: true })

await fastifyApp.close()
t.assert.ok('server closed')
})
Loading