Skip to content

Commit

Permalink
fix: ts build removeComments
Browse files Browse the repository at this point in the history
  • Loading branch information
saisilinus committed Apr 26, 2022
1 parent fd42ff5 commit e94887f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ Compile your TS files to JS by running `yarn compile`
yarn compile
```

Manually fix remaining linting errors in the JS files

## Linting Errors After Compiling

After compiling, you are likely to get linting errors since some were disabled through comments in TypeScript files. Currently, the following files get linting errors after running `yarn compile`:
Expand Down
2 changes: 1 addition & 1 deletion dist/modules/errors/error.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion dist/modules/toJSON/toJSON.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-param-reassign */
/**
* A mongoose schema plugin which applies the following in the toJSON transform call:
* - removes __v, createdAt, updatedAt, and any path that has private: true
* - replaces _id with id
*/
const deleteAtPath = (obj, path, index) => {
if (index === path.length - 1) {
// eslint-disable-next-line no-param-reassign
delete obj[path[index]];
return;
}
Expand All @@ -16,17 +16,23 @@ const toJSON = (schema) => {
if (schema.options.toJSON && schema.options.toJSON.transform) {
transform = schema.options.toJSON.transform;
}
// eslint-disable-next-line no-param-reassign
schema.options.toJSON = Object.assign(schema.options.toJSON || {}, {
transform(doc, ret, options) {
Object.keys(schema.paths).forEach((path) => {
if (schema.paths[path].options && schema.paths[path].options.private) {
deleteAtPath(ret, path.split('.'), 0);
}
});
// eslint-disable-next-line no-param-reassign
ret.id = ret._id.toString();
// eslint-disable-next-line no-param-reassign
delete ret._id;
// eslint-disable-next-line no-param-reassign
delete ret.__v;
// eslint-disable-next-line no-param-reassign
delete ret.createdAt;
// eslint-disable-next-line no-param-reassign
delete ret.updatedAt;
if (transform) {
return transform(doc, ret, options);
Expand Down
2 changes: 1 addition & 1 deletion dist/modules/toJSON/toJSON.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/modules/errors/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-unused-vars */
import { Request, Response, NextFunction } from 'express';
import mongoose from 'mongoose';
import httpStatus from 'http-status';
Expand All @@ -18,6 +17,7 @@ export const errorConverter = (err: any, _req: Request, _res: Response, next: Ne
next(error);
};

// eslint-disable-next-line no-unused-vars
export const errorHandler = (err: ApiError, _req: Request, res: Response, _next: NextFunction) => {
let { statusCode, message } = err;
if (config.env === 'production' && !err.isOperational) {
Expand Down
7 changes: 7 additions & 0 deletions src/modules/toJSON/toJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Document } from 'mongoose';

const deleteAtPath = (obj: any, path: any, index: number) => {
if (index === path.length - 1) {
// eslint-disable-next-line no-param-reassign
delete obj[path[index]];
return;
}
Expand All @@ -21,6 +22,7 @@ const toJSON = (schema: any) => {
transform = schema.options.toJSON.transform;
}

// eslint-disable-next-line no-param-reassign
schema.options.toJSON = Object.assign(schema.options.toJSON || {}, {
transform(doc: Document, ret: any, options: Record<string, any>) {
Object.keys(schema.paths).forEach((path) => {
Expand All @@ -29,10 +31,15 @@ const toJSON = (schema: any) => {
}
});

// eslint-disable-next-line no-param-reassign
ret.id = ret._id.toString();
// eslint-disable-next-line no-param-reassign
delete ret._id;
// eslint-disable-next-line no-param-reassign
delete ret.__v;
// eslint-disable-next-line no-param-reassign
delete ret.createdAt;
// eslint-disable-next-line no-param-reassign
delete ret.updatedAt;
if (transform) {
return transform(doc, ret, options);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
"removeComments": false, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
Expand Down

0 comments on commit e94887f

Please sign in to comment.