Skip to content

Commit

Permalink
Merge pull request #668 from kamilmysliwiec/fix/webpack-bundling-issues
Browse files Browse the repository at this point in the history
fix(): webpack properly bundles optional packages
  • Loading branch information
michaelyali committed Feb 11, 2021
2 parents 7888637 + 4c33082 commit 9b72ac0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
19 changes: 11 additions & 8 deletions packages/crud/src/crud/swagger.helper.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { HttpStatus } from '@nestjs/common';
import { objKeys, isString, isFunction } from '@nestjsx/util';
import { RequestQueryBuilder } from '@nestjsx/crud-request';
const pluralize = require('pluralize');

import { isString, objKeys } from '@nestjsx/util';
import { MergedCrudOptions, ParamsOptions } from '../interfaces';
import { BaseRouteName } from '../types';
import { safeRequire } from '../util';
import { R } from './reflection.helper';
import { ParamsOptions, MergedCrudOptions } from '../interfaces';
import { BaseRouteName } from '../types';
const pluralize = require('pluralize');

export const swagger = safeRequire('@nestjs/swagger');
export const swaggerConst = safeRequire('@nestjs/swagger/dist/constants');
export const swaggerPkgJson = safeRequire('@nestjs/swagger/package.json');
export const swagger = safeRequire('@nestjs/swagger', () => require('@nestjs/swagger'));
export const swaggerConst = safeRequire('@nestjs/swagger/dist/constants', () =>
require('@nestjs/swagger/dist/constants'),
);
export const swaggerPkgJson = safeRequire('@nestjs/swagger/package.json', () =>
require('@nestjs/swagger/package.json'),
);

export class Swagger {
static operationsMap(modelName): { [key in BaseRouteName]: string } {
Expand Down
5 changes: 2 additions & 3 deletions packages/crud/src/crud/validation.helper.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { ValidationPipe } from '@nestjs/common';
import { isFalse, isNil } from '@nestjsx/util';

import { CrudValidationGroups } from '../enums';
import { CreateManyDto, CrudOptions, MergedCrudOptions } from '../interfaces';
import { safeRequire } from '../util';
import { ApiProperty } from './swagger.helper';

const validator = safeRequire('class-validator');
const transformer = safeRequire('class-transformer');
const validator = safeRequire('class-validator', () => require('class-validator'));
const transformer = safeRequire('class-transformer', () => require('class-transformer'));

class BulkDto<T> implements CreateManyDto<T> {
bulk: T[];
Expand Down
4 changes: 2 additions & 2 deletions packages/crud/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function safeRequire<T = any>(path: string): T | null {
export function safeRequire<T = any>(path: string, loader?: () => T): T | null {
try {
const pack = require(path);
const pack = loader ? loader() : require(path);
return pack;
} catch (_) {
/* istanbul ignore next */
Expand Down

0 comments on commit 9b72ac0

Please sign in to comment.