Skip to content

Commit 057cc25

Browse files
Merge pull request #3253 from nestjs/revert-3235-esm-compatible-require
Revert "feat: make generated require() ESM compatible"
2 parents 7e9d114 + be2ba16 commit 057cc25

File tree

3 files changed

+22
-39
lines changed

3 files changed

+22
-39
lines changed

lib/plugin/utils/plugin-utils.ts

-15
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,6 @@ export function hasPropertyKey(
137137
.some((item) => item.name.getText() === key);
138138
}
139139

140-
function getOutputExtension(fileName: string): string {
141-
if (fileName.endsWith('.mts')) {
142-
return '.mjs';
143-
} else if (fileName.endsWith('.cts')) {
144-
return '.cjs';
145-
} else{
146-
return ".js";
147-
}
148-
}
149-
150140
export function replaceImportPath(
151141
typeReference: string,
152142
fileName: string,
@@ -200,10 +190,6 @@ export function replaceImportPath(
200190
if (indexPos >= 0) {
201191
relativePath = relativePath.slice(0, indexPos);
202192
}
203-
} else {
204-
// Add appropriate extension for non-node_modules imports
205-
const extension = getOutputExtension(fileName);
206-
relativePath += extension;
207193
}
208194

209195
typeReference = typeReference.replace(importPath, relativePath);
@@ -217,7 +203,6 @@ export function replaceImportPath(
217203
importPath: relativePath
218204
};
219205
}
220-
221206
return {
222207
typeReference: typeReference.replace('import', 'require'),
223208
importPath: relativePath

test/plugin/fixtures/parameter-property.dto.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ParameterPropertyDto {
2929
this.protectedValue = protectedValue;
3030
}
3131
static _OPENAPI_METADATA_FACTORY() {
32-
return { readonlyValue: { required: false, type: () => String }, privateValue: { required: true, type: () => String, nullable: true }, publicValue: { required: true, type: () => [require("./parameter-property.dto.js").ItemDto] }, protectedValue: { required: true, type: () => String, default: "1234" } };
32+
return { readonlyValue: { required: false, type: () => String }, privateValue: { required: true, type: () => String, nullable: true }, publicValue: { required: true, type: () => [require("./parameter-property.dto").ItemDto] }, protectedValue: { required: true, type: () => String, default: "1234" } };
3333
}
3434
}
3535
export var LettersEnum;
@@ -43,7 +43,7 @@ export class ItemDto {
4343
this.enumValue = enumValue;
4444
}
4545
static _OPENAPI_METADATA_FACTORY() {
46-
return { enumValue: { required: true, enum: require("./parameter-property.dto.js").LettersEnum } };
46+
return { enumValue: { required: true, enum: require("./parameter-property.dto").LettersEnum } };
4747
}
4848
}
4949
`;

test/plugin/fixtures/serialized-meta.fixture.ts

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// @ts-nocheck
22
export default async () => {
33
const t = {
4-
['./cats/dto/pagination-query.dto.js']: await import(
5-
'./cats/dto/pagination-query.dto.js'
4+
['./cats/dto/pagination-query.dto']: await import(
5+
'./cats/dto/pagination-query.dto'
66
),
7-
['./cats/dto/create-cat.dto.js']: await import(
8-
'./cats/dto/create-cat.dto.js'
9-
),
10-
['./cats/dto/tag.dto.js']: await import('./cats/dto/tag.dto.js'),
11-
['./cats/classes/cat.class.js']: await import('./cats/classes/cat.class.js')
7+
['./cats/dto/create-cat.dto']: await import('./cats/dto/create-cat.dto'),
8+
['./cats/dto/tag.dto']: await import('./cats/dto/tag.dto'),
9+
['./cats/classes/cat.class']: await import('./cats/classes/cat.class')
1210
};
1311
return {
1412
'@nestjs/swagger': {
@@ -23,16 +21,16 @@ export default async () => {
2321
constrainedLimit: { required: false, type: () => Number },
2422
enum: {
2523
required: true,
26-
enum: t['./cats/dto/pagination-query.dto.js'].LettersEnum
24+
enum: t['./cats/dto/pagination-query.dto'].LettersEnum
2725
},
2826
enumArr: {
2927
required: true,
30-
enum: t['./cats/dto/pagination-query.dto.js'].LettersEnum,
28+
enum: t['./cats/dto/pagination-query.dto'].LettersEnum,
3129
isArray: true
3230
},
3331
letters: {
3432
required: true,
35-
enum: t['./cats/dto/pagination-query.dto.js'].LettersEnum,
33+
enum: t['./cats/dto/pagination-query.dto'].LettersEnum,
3634
isArray: true
3735
},
3836
beforeDate: { required: true, type: () => Date },
@@ -62,11 +60,11 @@ export default async () => {
6260
options: { required: false, type: () => [Object] },
6361
enum: {
6462
required: true,
65-
enum: t['./cats/dto/pagination-query.dto.js'].LettersEnum
63+
enum: t['./cats/dto/pagination-query.dto'].LettersEnum
6664
},
6765
enumArr: {
6866
required: true,
69-
enum: t['./cats/dto/pagination-query.dto.js'].LettersEnum
67+
enum: t['./cats/dto/pagination-query.dto'].LettersEnum
7068
},
7169
uppercaseString: { required: true, type: () => String },
7270
lowercaseString: { required: true, type: () => String },
@@ -139,30 +137,30 @@ export default async () => {
139137
options: { required: false, type: () => [Object] },
140138
enum: {
141139
required: true,
142-
enum: t['./cats/dto/pagination-query.dto.js'].LettersEnum
140+
enum: t['./cats/dto/pagination-query.dto'].LettersEnum
143141
},
144142
state: {
145143
required: false,
146144
description: 'Available language in the application',
147145
example: 'FR',
148-
enum: t['./cats/dto/create-cat.dto.js'].CategoryState
146+
enum: t['./cats/dto/create-cat.dto'].CategoryState
149147
},
150148
enumArr: {
151149
required: true,
152-
enum: t['./cats/dto/pagination-query.dto.js'].LettersEnum
150+
enum: t['./cats/dto/pagination-query.dto'].LettersEnum
153151
},
154152
enumArr2: {
155153
required: true,
156-
enum: t['./cats/dto/pagination-query.dto.js'].LettersEnum,
154+
enum: t['./cats/dto/pagination-query.dto'].LettersEnum,
157155
isArray: true
158156
},
159157
tag: {
160158
required: true,
161-
type: () => t['./cats/dto/tag.dto.js'].TagDto
159+
type: () => t['./cats/dto/tag.dto'].TagDto
162160
},
163161
multipleTags: {
164162
required: true,
165-
type: () => [t['./cats/dto/tag.dto.js'].TagDto]
163+
type: () => [t['./cats/dto/tag.dto'].TagDto]
166164
},
167165
nested: {
168166
required: true,
@@ -199,11 +197,11 @@ export default async () => {
199197
import('./cats/cats.controller'),
200198
{
201199
CatsController: {
202-
create: { type: t['./cats/classes/cat.class.js'].Cat },
203-
findOne: { type: t['./cats/classes/cat.class.js'].Cat },
200+
create: { type: t['./cats/classes/cat.class'].Cat },
201+
findOne: { type: t['./cats/classes/cat.class'].Cat },
204202
findAll: {},
205-
createBulk: { type: t['./cats/classes/cat.class.js'].Cat },
206-
createAsFormData: { type: t['./cats/classes/cat.class.js'].Cat },
203+
createBulk: { type: t['./cats/classes/cat.class'].Cat },
204+
createAsFormData: { type: t['./cats/classes/cat.class'].Cat },
207205
getWithEnumParam: {},
208206
getWithRandomQuery: {}
209207
}

0 commit comments

Comments
 (0)