Skip to content

Commit

Permalink
fix(): fix windows webpack relative paths issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Aug 20, 2020
1 parent 8846c9f commit e96f2a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/plugin/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { head } from 'lodash';
import { dirname, posix } from 'path';
import { posix } from 'path';
import * as ts from 'typescript';
import {
getDecoratorName,
Expand Down Expand Up @@ -119,9 +119,10 @@ export function replaceImportPath(typeReference: string, fileName: string) {
if (!importPath) {
return undefined;
}
importPath = convertPath(importPath);
importPath = importPath.slice(2, importPath.length - 1);

let relativePath = posix.relative(dirname(fileName), importPath);
let relativePath = posix.relative(posix.dirname(fileName), importPath);
relativePath = relativePath[0] !== '.' ? './' + relativePath : relativePath;

const nodeModulesText = 'node_modules';
Expand Down Expand Up @@ -252,3 +253,14 @@ export function extractTypeArgumentIfArray(type: ts.Type) {
function isOptionalBoolean(text: string) {
return typeof text === 'string' && text === 'boolean | undefined';
}

/**
* Converts Windows specific file paths to posix
* @param windowsPath
*/
function convertPath(windowsPath: string) {
return windowsPath
.replace(/^\\\\\?\\/, '')
.replace(/\\/g, '/')
.replace(/\/\/+/g, '/');
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestjs/swagger",
"version": "4.5.12",
"version": "4.5.12-next.1",
"description": "Nest - modern, fast, powerful node.js web framework (@swagger)",
"author": "Kamil Mysliwiec",
"license": "MIT",
Expand Down

0 comments on commit e96f2a0

Please sign in to comment.