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

chore: lint repository with eslint config and format with prettier #739

Merged
merged 5 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{
"extends": [
"@nuxtjs/eslint-config-typescript"
],
"extends": ["eslint-config-unjs"],
"rules": {
"import/no-named-as-default-member": "off",
"import/default": "off",
"no-console": "off"
"space-before-function-paren": 0,
"arrow-parens": 0,
"comma-dangle": 0,
"semi": 0,
"unicorn/prevent-abbreviations": 0,
"quotes": 0,
"keyword-spacing": 0,
"no-undef": 0,
"unicorn/catch-error-name": 0,
"unicorn/no-null": 0,
"unicorn/no-useless-undefined": 0,
"unicorn/no-await-expression-member": 0,
"unicorn/no-array-push-push": 0,
"unicorn/filename-case": 0
}
}
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ Examples:

- [ ] I have linked an issue or discussion.
- [ ] I have updated the documentation accordingly.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: "16"
cache: pnpm
- run: pnpm install
- run: pnpm lint
Expand Down
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
42 changes: 18 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![npm-edge version][npm-edge-version-src]][npm-edge-version-href]
[![npm-edge downloads][npm-edge-downloads-src]][npm-edge-downloads-href]

<!-- [![GitHub Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href] -->

<h1 align="center">⚗️ Nitro</h1>
Expand All @@ -12,18 +12,18 @@

Nitro provides a powerful toolchain and a runtime framework from the [UnJS](https://github.com/unjs) ecosystem to build and deploy **any JavaScript server, anywhere!**

❯ 🐇 **Rapid development** experience with hot module replacement <br>
❯ 😌 **Multi-provider** deployments with a single codebase and zero-configuration<br>
❯ 💼 **Portable and compact** deployments without `node_modules` dependency <br>
❯ 📁 **Directory structure** aware to register API routes and more with zero configuration <br>
❯ 🤏 **Minimal Design** to fit into any solution with minimum overhead <br>
❯ 🚀 **Code-splitting** and async chunk loading for fast server startup time <br>
❯ 👕 **TypeScript** fully supported <br>
❯ 💾 **Multi-driver storage** and caching layer <br>
❯ 💰 **Route caching** and static **pre-rendering** with built-in crawler <br>
❯ 🐱 **Hackable** to extend almost any part of nitro using options <br>
❯ ✨ **Auto imports** for lazy folks and a tidy minimal codebase <br>
❯ 🏛️ **Best-effort compatibility** for using legacy npm packages and mocking Node.js modules <br>
❯ 🐇 **Rapid development** experience with hot module replacement <br>
❯ 😌 **Multi-provider** deployments with a single codebase and zero-configuration<br>
❯ 💼 **Portable and compact** deployments without `node_modules` dependency <br>
❯ 📁 **Directory structure** aware to register API routes and more with zero configuration <br>
❯ 🤏 **Minimal Design** to fit into any solution with minimum overhead <br>
❯ 🚀 **Code-splitting** and async chunk loading for fast server startup time <br>
❯ 👕 **TypeScript** fully supported <br>
❯ 💾 **Multi-driver storage** and caching layer <br>
❯ 💰 **Route caching** and static **pre-rendering** with built-in crawler <br>
❯ 🐱 **Hackable** to extend almost any part of nitro using options <br>
❯ ✨ **Auto imports** for lazy folks and a tidy minimal codebase <br>
❯ 🏛️ **Best-effort compatibility** for using legacy npm packages and mocking Node.js modules <br>

## Who is using Nitro?

Expand All @@ -49,7 +49,7 @@ cd nitro-app
1️⃣ Create `routes/index.ts`:

```ts [routes/index.ts]
export default defineEventHandler(() => 'nitro is amazing!')
export default defineEventHandler(() => "nitro is amazing!");
```

2️⃣ Start development server:
Expand All @@ -66,7 +66,7 @@ Check `.nitro/dev/index.mjs` if want to know what is happening

```bash
npx nitropack build
````
```

4️⃣ Output is in the `.output` directory and ready to be deployed on almost any VPS with no dependencies. You can locally try it too:

Expand All @@ -76,34 +76,28 @@ node .output/server/index.mjs

That's it you got it! Read the [documentation](https://nitro.unjs.io) to learn more.



<hr>
<h3 align="center">🌱 nitro is young and under development</h3>

Check [🐛 open issues](https://github.com/unjs/nitro/issues) for the known issues and roadmap and tell us [💡your ideas](https://github.com/unjs/nitro/discussions/new)!
<hr>
Check [🐛 open issues](https://github.com/unjs/nitro/issues) for the known issues and roadmap and tell us [💡your ideas](https://github.com/unjs/nitro/discussions/new)!

<hr>

## License

Made with 💛 Published under [MIT](./LICENSE).

<!-- Badges -->

[npm-version-src]: https://flat.badgen.net/npm/v/nitropack?style=flat-square&label=stable
[npm-version-href]: https://npmjs.com/package/nitropack

[npm-downloads-src]: https://flat.badgen.net/npm/dm/nitropack?style=flat-square&label=stable
[npm-downloads-href]: https://npmjs.com/package/nitropack

[npm-edge-version-src]: https://flat.badgen.net/npm/v/nitropack-edge?style=flat-square&label=edge
[npm-edge-version-href]: https://npmjs.com/package/nitropack-edge

[npm-edge-downloads-src]: https://flat.badgen.net/npm/dm/nitropack-edge?style=flat-square&label=edge
[npm-edge-downloads-href]: https://npmjs.com/package/nitropack-edge

[github-actions-src]: https://flat.badgen.net/github/status/unjs/nitro?style=flat-square
[github-actions-href]: https://github.com/unjs/nitro/actions?query=workflow%3Aci

[codecov-src]: https://flat.badgen.net/codecov/c/gh/unjs/nitro/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/nitro
28 changes: 13 additions & 15 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { defineBuildConfig } from 'unbuild'
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
declaration: true,
name: 'nitro',
name: "nitro",
entries: [
'src/index',
'src/cli',
{ input: 'src/runtime/', outDir: 'dist/runtime', format: 'esm' }
"src/index",
"src/cli",
{ input: "src/runtime/", outDir: "dist/runtime", format: "esm" },
],
dependencies: [
'@cloudflare/kv-asset-handler',
'@netlify/functions',
'@nuxt/devalue',
'destr',
'ofetch',
'ora'
"@cloudflare/kv-asset-handler",
"@netlify/functions",
"@nuxt/devalue",
"destr",
"ofetch",
"ora",
],
externals: [
'@nuxt/schema'
]
})
externals: ["@nuxt/schema"],
});
2 changes: 1 addition & 1 deletion examples/api-routes/api/hello.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default defineEventHandler(() => 'Nitro is amazing!')
export default defineEventHandler(() => "Nitro is amazing!");
4 changes: 3 additions & 1 deletion examples/api-routes/api/hello/[name].ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default defineEventHandler(event => `Hello ${event.context.params.name}!`)
export default defineEventHandler(
(event) => `Hello ${event.context.params.name}!`
);
2 changes: 1 addition & 1 deletion examples/api-routes/api/test.get.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default defineEventHandler(() => 'Test get handler')
export default defineEventHandler(() => "Test get handler");
2 changes: 1 addition & 1 deletion examples/api-routes/api/test.post.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default defineEventHandler(() => 'Test post handler')
export default defineEventHandler(() => "Test post handler");
5 changes: 2 additions & 3 deletions examples/api-routes/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { defineNitroConfig } from 'nitropack'
import { defineNitroConfig } from "nitropack";

export default defineNitroConfig({
})
export default defineNitroConfig({});
4 changes: 2 additions & 2 deletions examples/api-routes/routes/[...].ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default defineEventHandler(() => {
<li><a href="/api/hello/world">/api/hello/world</a></li>
<li><a href="/api/test">/api/test</a></li>
</ul>
`
})
`;
});
5 changes: 2 additions & 3 deletions examples/cached-handler/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { defineNitroConfig } from 'nitropack'
import { defineNitroConfig } from "nitropack";

export default defineNitroConfig({
})
export default defineNitroConfig({});
6 changes: 3 additions & 3 deletions examples/cached-handler/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default defineCachedEventHandler(async () => {
await new Promise(resolve => setTimeout(resolve, 1000))
return `Response generated at ${new Date().toISOString()} (took 1 second)`
})
await new Promise((resolve) => setTimeout(resolve, 1000));
return `Response generated at ${new Date().toISOString()} (took 1 second)`;
});
8 changes: 4 additions & 4 deletions examples/custom-error-handler/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NitroErrorHandler } from 'nitropack'
import type { NitroErrorHandler } from "nitropack";

export default <NitroErrorHandler> function (error, event) {
event.res.end('[custom error handler] ' + error.stack)
}
export default <NitroErrorHandler>function (error, event) {
event.res.end("[custom error handler] " + error.stack);
};
10 changes: 5 additions & 5 deletions examples/custom-error-handler/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineNitroConfig } from 'nitropack'
import errorHandler from './error'
import { defineNitroConfig } from "nitropack";
import errorHandler from "./error";

export default defineNitroConfig({
errorHandler: '~/error',
devErrorHandler: errorHandler
})
errorHandler: "~/error",
devErrorHandler: errorHandler,
});
4 changes: 2 additions & 2 deletions examples/custom-error-handler/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default defineEventHandler(() => {
throw new Error('Example Error!')
})
throw new Error("Example Error!");
});
5 changes: 2 additions & 3 deletions examples/hello-world/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { defineNitroConfig } from 'nitropack'
import { defineNitroConfig } from "nitropack";

export default defineNitroConfig({
})
export default defineNitroConfig({});
2 changes: 1 addition & 1 deletion examples/hello-world/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default defineEventHandler(() => '<h1>nitro is amazing!</h1>')
export default defineEventHandler(() => "<h1>nitro is amazing!</h1>");
4 changes: 2 additions & 2 deletions examples/middleware/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default defineEventHandler((event) => {
event.context.auth = { name: 'User ' + Math.round(Math.random() * 100) }
})
event.context.auth = { name: "User " + Math.round(Math.random() * 100) };
});
5 changes: 2 additions & 3 deletions examples/middleware/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { defineNitroConfig } from 'nitropack'
import { defineNitroConfig } from "nitropack";

export default defineNitroConfig({
})
export default defineNitroConfig({});
6 changes: 3 additions & 3 deletions examples/middleware/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default defineEventHandler(event => ({
auth: event.context.auth
}))
export default defineEventHandler((event) => ({
auth: event.context.auth,
}));
8 changes: 3 additions & 5 deletions examples/plugins/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { defineNitroConfig } from 'nitropack'
import { defineNitroConfig } from "nitropack";

export default defineNitroConfig({
plugins: [
'~/plugins/test'
]
})
plugins: ["~/plugins/test"],
});
4 changes: 2 additions & 2 deletions examples/plugins/plugins/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default defineNitroPlugin((_nitroApp) => {
console.log('Nitro plugin!')
})
console.log("Nitro plugin!");
});
4 changes: 2 additions & 2 deletions examples/plugins/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { eventHandler } from 'h3'
import { eventHandler } from "h3";

export default eventHandler(() => '<h1>Hello Nitro!</h1>')
export default eventHandler(() => "<h1>Hello Nitro!</h1>");
4 changes: 2 additions & 2 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["."]
"extends": "../tsconfig.json",
"include": ["."]
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"docs:build": "vitepress build docs",
"docs:dev": "vitepress dev docs",
"docs:serve": "vitepress serve docs",
"lint": "eslint --ext .ts,.mjs,.cjs .",
"lint": "eslint --ext .ts,.mjs,.cjs . && prettier -c src test",
"nitro": "jiti ./src/cli.ts",
"prepack": "pnpm build",
"release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
Expand Down Expand Up @@ -80,8 +80,8 @@
"mlly": "^1.0.0",
"mri": "^1.2.0",
"node-fetch-native": "^1.0.1",
"ohash": "^1.0.0",
"ofetch": "^1.0.0",
"ohash": "^1.0.0",
"pathe": "^1.0.0",
"perfect-debounce": "^0.1.3",
"pkg-types": "^1.0.1",
Expand All @@ -102,16 +102,14 @@
"unstorage": "^1.0.1"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "^11.0.0",
"@types/aws-lambda": "^8.10.109",
"@types/etag": "^1.8.1",
"@types/fs-extra": "^9.0.13",
"@types/http-proxy": "^1.17.9",
"@types/node-fetch": "^2.6.2",
"@types/object-hash": "^2.2.1",
"@types/semver": "^7.3.13",
"@types/serve-static": "^1.15.0",
"@vitest/coverage-c8": "^0.25.5",
"@vitest/coverage-c8": "^0.25.6",
"c8": "^7.12.0",
"changelogen": "^0.4.0",
"edge-runtime": "2.0.2",
Expand All @@ -120,9 +118,10 @@
"execa": "^6.1.0",
"expect-type": "^0.15.0",
"miniflare": "^2.11.0",
"prettier": "^2.8.1",
"typescript": "^4.9.4",
"unbuild": "^1.0.2",
"vitest": "^0.25.5"
"vitest": "^0.25.6"
},
"packageManager": "pnpm@7.18.1",
"engines": {
Expand Down
5 changes: 2 additions & 3 deletions playground/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { defineNitroConfig } from '../src'
import { defineNitroConfig } from "../src";

export default defineNitroConfig({
})
export default defineNitroConfig({});
4 changes: 2 additions & 2 deletions playground/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { eventHandler } from 'h3'
import { eventHandler } from "h3";

export default eventHandler(() => '<h1>Hello Nitro!</h1>')
export default eventHandler(() => "<h1>Hello Nitro!</h1>");
14 changes: 4 additions & 10 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
"extends": "./.nitro/types/tsconfig.json",
"compilerOptions": {
"paths": {
"nitropack": [
"../src/index"
],
"#internal/nitro": [
"../src/runtime/index"
],
"#internal/nitro/*": [
"../src/runtime/*"
]
},
"nitropack": ["../src/index"],
"#internal/nitro": ["../src/runtime/index"],
"#internal/nitro/*": ["../src/runtime/*"]
}
}
}
Loading