Skip to content

Commit

Permalink
fix: fix NODE_ENV type declaration error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebugo committed May 20, 2023
1 parent 66daa6e commit 17925c5
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
build
23 changes: 17 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
"extends": [
"next",
"airbnb",
"plugin:cypress/recommended"
"airbnb-typescript",
"plugin:cypress/recommended",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"eslint-plugin-jsx-a11y",
"cypress"
],
"plugins": ["eslint-plugin-jsx-a11y", "cypress", "@typescript-eslint"],
"rules": {
"function-call-argument-newline": ["off"],
"function-paren-newline": ["off"],
Expand All @@ -35,6 +37,15 @@
"react/no-danger": ["off"],
"@next/next/no-html-link-for-pages": ["off"],
"@next/next/no-img-element": ["off"],
"linebreak-style": ["off"]
"linebreak-style": ["off"],
"@typescript-eslint/no-unused-vars": [
"warn",
{
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-empty-function": ["warn"],
"prefer-const": "error"
}
}
11 changes: 11 additions & 0 deletions @types/console.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare global {
interface Console {
green(message?: any, ...optionalParams: any[]): void;
blue(message?: any, ...optionalParams: any[]): void;
red(message?: any, ...optionalParams: any[]): void;
}
}

// If this file has no import/export statements (i.e. is a script)
// convert it into a module by adding an empty export statement.
export {};
11 changes: 11 additions & 0 deletions @types/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
readonly NODE_ENV: 'development' | 'production' | 'test' | 'build';
}
}
}

// If this file has no import/export statements (i.e. is a script)
// convert it into a module by adding an empty export statement.
export {};
5 changes: 5 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@
"@semantic-release/git": "^9.0.0",
"@semantic-release/npm": "^7.0.10",
"@semantic-release/release-notes-generator": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"babel-loader": "^8.1.0",
"cross-env": "^7.0.2",
"cypress": "^6.0.0",
"eslint": "8.34.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-next": "13.1.6",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-cypress": "2.12.1",
Expand All @@ -160,7 +163,8 @@
"postcss": "^8.1.3",
"postcss-loader": "~3.0.0",
"postcss-preset-env": "^6.7.0",
"supertest": "^6.3.1"
"supertest": "^6.3.1",
"typescript": "5.0.4"
},
"standard-version": {
"skip": {
Expand Down
3 changes: 2 additions & 1 deletion src/server.js → src/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PORT } from './config';
import app from './app';
import NodeEnv from './shared/constants/NodeEnv';

const server = app.listen(PORT, () => {
console.green(`🟢 Server started on port ${PORT}`);

/* Used to test server build */
if (process.env.NODE_ENV === 'build') {
if (NodeEnv === 'build') {
console.blue('🧪 Testing server build');
setTimeout(() => {
console.green('✅ Build test passed');
Expand Down
3 changes: 3 additions & 0 deletions src/shared/constants/NodeEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const NodeEnv: 'development' | 'production' | 'test' | 'build' = process.env.NODE_ENV;

export default NodeEnv;
35 changes: 28 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
"target": "es5"
},
"include": ["./src/**/*"]
}
"compilerOptions": {
"outDir": "./build",
"allowJs": true,
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": [
"./src/**/*"
, "@types" ],
"exclude": [
"node_modules"
]
}

0 comments on commit 17925c5

Please sign in to comment.