1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-23 19:32:14 +00:00

First @dzeio/config version

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2021-07-10 18:50:50 +02:00
parent 418c36efda
commit 588caedd84
Signed by: Florian Bouillon
GPG Key ID: 50BD648F12C86AB6
14 changed files with 5809 additions and 0 deletions

1
packages/config/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
next.config.js

View File

@ -0,0 +1,6 @@
.gitignore
.npmignore
package-lock.json
package.json
next.config.ts
tsconfig.json

9
packages/config/LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2021 Dzeio
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.

45
packages/config/README.md Normal file
View File

@ -0,0 +1,45 @@
# Dzeio Config
thoses are base configuration files for multiple items
## ESLint
Depending on your configuration add a `.eslintrc.json` to your repository and add the following code (remove the comments if you keep it a a json file)
```json
{
"extends": [
// Note: add only one file as they calls each ones out
// Base configuration for javascript
"./node_modules/@dzeio/config/eslint/base",
// React configuration
"./node_modules/@dzeio/config/eslint/react",
// Typescript configuration
"./node_modules/@dzeio/config/eslint/typescript",
// Typescript AND React configuration
"./node_modules/@dzeio/config/eslint/react-typescript",
]
}
```
## Typescript
```json
{
// Note: Only include one file
// Base Typescript configuration
"extends": "@dzeio/config/tsconfig.base.json",
// Base NextJS configuration
"extends": "@dzeio/config/tsconfig.nextjs.json",
}
```
## Copy-paste
files under the folder `copy-paste` are configurations that can't be extended so you'll have to copy/paste them into your repository

View File

@ -0,0 +1,126 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"plugins": [],
"rules": {
"arrow-body-style": "error",
"arrow-parens": [
"error",
"always"
],
"complexity": "off",
"constructor-super": "error",
"curly": "error",
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": [
"error",
"smart"
],
"guard-for-in": "error",
"id-blacklist": [
"error",
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined"
],
"id-match": "error",
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"max-classes-per-file": [
"error",
1
],
"max-len": [
"warn",
{
"code": 200
}
],
"new-parens": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-cond-assign": "error",
"no-debugger": "error",
"no-empty": "error",
"no-eval": "error",
"no-fallthrough": "off",
"no-invalid-this": "off",
"no-multiple-empty-lines": "error",
"no-new-wrappers": "error",
"no-shadow": [
"error",
{
"hoist": "all"
}
],
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-underscore-dangle": "off",
"no-unsafe-finally": "error",
"no-unused-expressions": [
"error",
{
"allowTernary": true
}
],
"no-unused-labels": "error",
"no-unused-vars": "off",
"no-var": "error",
"object-shorthand": "error",
"one-var": [
"error",
"never"
],
"prefer-const": "error",
"quote-props": [
"error",
"consistent-as-needed"
],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"radix": "error",
"semi": [
"error",
"never"
],
"space-before-function-paren": [
"error",
{
"anonymous": "never",
"asyncArrow": "always",
"named": "never"
}
],
"spaced-comment": "error",
"use-isnan": "error",
"valid-typeof": "off"
}
}

View File

@ -0,0 +1,6 @@
{
"extends": [
"./react",
"./typescript"
]
}

View File

@ -0,0 +1,15 @@
{
"extends": [
"./base",
"plugin:react/recommended"
],
"settings": {
"react": {
"version": "detect"
}
},
"plugins": [
"react"
],
"rules": {}
}

View File

@ -0,0 +1,95 @@
{
"extends": [
"./base",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": [
"error",
{
"default": "generic"
}
],
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "explicit"
}
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "none",
"requireLast": true
},
"singleline": {
"delimiter": "comma",
"requireLast": false
}
}
],
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-parameter-properties": "off",
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": [
"error",
{
"allowTernary": true
}
],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"quotes": "off",
"@typescript-eslint/quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"semi": "off",
"@typescript-eslint/semi": [
"error",
"never"
],
"space-before-function-paren": "off",
"@typescript-eslint/space-before-function-paren": [
"error",
{
"anonymous": "never",
"asyncArrow": "always",
"named": "never"
}
],
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unified-signatures": "error"
}
}

View File

@ -0,0 +1,125 @@
import { NextConfig, defaultConfig } from 'next/dist/next-server/server/config-shared'
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
// @ts-expect-error next-pre-css has no typing available
import preCSS from 'next-pre-css'
/**
* Return a default NextJS hardened configuration with experimental features enabled and headers preset
*/
export const config = (additionnalHost: string): typeof defaultConfig & NextConfig => ({
// Experimentals
experimental: {
plugins: true,
profiling: process.env.NODE_ENV === 'developpment',
sprFlushToDisk: true,
workerThreads: true,
pageEnv: true,
optimizeImages: true,
optimizeCss: true,
scrollRestoration: true,
stats: process.env.NODE_ENV === 'developpment',
gzipSize: process.env.NODE_ENV === 'developpment',
externalDir: true,
conformance: true,
// Bugged
// https://github.com/vercel/next.js/issues/18913
// reactRoot: true,
},
// Non experimental config
// target: 'serverless',
cleanDistDir: true,
trailingSlash: false,
excludeDefaultMomentLocales: true,
poweredByHeader: false,
reactStrictMode: true,
// Futures
future: {
strictPostcssConfiguration: true,
},
// Headers and rewrites
async headers() {
// CSS no CSP, x-xss-protection
const CSP = {
key: 'Content-Security-Policy',
value:
// default-src is set to self because prefetch-src is not working propelly see: https://bugs.chromium.org/p/chromium/issues/detail?id=801561
"default-src 'self'; " +
"frame-ancestors 'none'; " +
"form-action 'self'; " +
"manifest-src 'self'; " +
"prefetch-src 'self'; " +
`script-src 'self' 'unsafe-inline' 'unsafe-eval' ${additionnalHost}; ` +
"style-src 'self' 'unsafe-inline'; " +
"img-src data: 'self'; " +
"font-src 'self'; " +
`connect-src 'self' ${additionnalHost}; ` +
"base-uri 'self';"
}
const XXssProtection = {
key: 'X-XSS-Protection',
value: '1; mode=block'
}
// JS no x-xss-protection
const headers = [{
key: 'X-Frame-Options',
value: 'DENY'
}, {
key: 'X-Content-Type-Options',
value: 'nosniff'
}, {
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin'
}, {
key: 'Permissions-Policy',
value: 'geolocation=(), microphone=(), interest-cohort=()'
}, {
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload'
}, {
key: 'X-Download-Options',
value: 'noopen'
}, {
key: 'Expect-CT',
value: 'max-age=86400, enforce'
}]
const excludedExtensions = ['js', 'css', 'json', 'ico', 'png']
.map((ext) => `(?!\\.${ext}$)`).join('|')
return [{
source: `/:path*((?!^\\/_next\\/image)|${excludedExtensions})`,
headers: [...headers, XXssProtection, CSP]
}, {
source: '/',
headers: [...headers, XXssProtection, CSP]
}, {
// No CSP, XXssProtection
source: `/:path*(\\.${excludedExtensions}$)`,
headers: headers
}, {
// No CSP, XXssProtection
source: '/_next/image:path*',
headers: headers
}]
},
})
export const plugins = [preCSS, {
cssModules: true,
cssLoaderOptions: {
localIdentName: "[hash:base64:6]",
},
[PHASE_DEVELOPMENT_SERVER]: {
cssLoaderOptions: {
localIdentName: "[path][name]__[local]"
}
}
}]

5287
packages/config/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
{
"name": "@dzeio/config",
"version": "0.0.0",
"description": "global configuration files for programming",
"author": "Avior",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dzeiocom/libs.git",
"directory": "packages/config"
},
"devDependencies": {
"next": "^11.0.1",
"typescript": "^4.3.5"
},
"peerDependencies": {
"@typescript-eslint/parser": "^4.28.2",
"next": "^11.0.1",
"next-pre-css": "^1.0.0"
},
"peerDependenciesMeta": {
"next": {
"optional": true
},
"next-pre-css": {
"optional": true
},
"@typescript-eslint/parser": {
"optional": true
}
},
"scripts": {
"prepublishOnly": "tsc"
}
}

View File

@ -0,0 +1,36 @@
{
"compilerOptions": {
// Compilation
"target": "ES2020", // Follow NodeJS oldest supported LTS and compare with https://node.green
"module": "commonjs",
"resolveJsonModule": true,
"moduleResolution": "node",
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"allowJs": true,
"pretty": true,
"allowSyntheticDefaultImports": true,
// Type Checking
"forceConsistentCasingInFileNames": true,
"alwaysStrict": true,
"strict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
},
"exclude": [
"node_modules"
]
}

View File

@ -0,0 +1,8 @@
{
"files": ["./next.config.ts"],
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./",
"rootDir": "./"
}
}

View File

@ -0,0 +1,15 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "ES5",
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"noEmit": true,
"module": "ESNext",
"jsx": "preserve",
"isolatedModules": true
}
}