Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/module): Make jsc.paths work for a nest.js app #7852

Merged
merged 84 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
e6ed46a
Add a test
kdy1 Aug 24, 2023
dddd9a7
Add a test
kdy1 Aug 24, 2023
9cef589
Move
kdy1 Aug 24, 2023
014a149
.swcrc
kdy1 Aug 24, 2023
e45463f
Fix input
kdy1 Aug 24, 2023
d3a845f
More log
kdy1 Aug 24, 2023
149465e
log
kdy1 Aug 24, 2023
f0e79a0
More log
kdy1 Aug 24, 2023
20bd6a3
Better logging
kdy1 Aug 24, 2023
44fcccd
More log
kdy1 Aug 24, 2023
95cbd08
Log rel path
kdy1 Aug 24, 2023
6774a21
WIP
kdy1 Aug 24, 2023
a4d1917
More work
kdy1 Aug 24, 2023
7fda737
Fix
kdy1 Aug 24, 2023
a77eb47
Almost there
kdy1 Aug 24, 2023
b048a1f
More log
kdy1 Aug 24, 2023
4c94d27
More log
kdy1 Aug 24, 2023
27a8eba
More log
kdy1 Aug 24, 2023
fc16dac
Fix log
kdy1 Aug 24, 2023
600a9b7
Fix log
kdy1 Aug 24, 2023
70e4284
Better error message
kdy1 Aug 24, 2023
7422665
Use base_url
kdy1 Aug 24, 2023
3924ffc
log
kdy1 Aug 24, 2023
736ff45
More logic for `to_specifier`
kdy1 Aug 24, 2023
b165e9a
Move `to_specifier`
kdy1 Aug 24, 2023
8984c32
`.js`
kdy1 Aug 24, 2023
e08ad1b
Update test refs
kdy1 Aug 24, 2023
3b72769
Update test refs
kdy1 Aug 24, 2023
e4b037c
Update test refs
kdy1 Aug 24, 2023
eebf018
Remove wrong logic
kdy1 Aug 24, 2023
2e8db6c
Resolve twice
kdy1 Aug 24, 2023
2f8d16e
More try
kdy1 Aug 24, 2023
22b12e4
Update test refs
kdy1 Aug 24, 2023
3e6008b
preserve
kdy1 Aug 24, 2023
af4abd8
Update test refs
kdy1 Aug 24, 2023
66242c8
Update test refs
kdy1 Aug 24, 2023
38f50f4
Update test refs
kdy1 Aug 24, 2023
6e2ba27
Improve exact
kdy1 Aug 24, 2023
7681cc5
Use `replaced`
kdy1 Aug 24, 2023
9151e42
Update test refs
kdy1 Aug 24, 2023
6f5d99a
ts ext
kdy1 Aug 24, 2023
1606148
join with base url
kdy1 Aug 24, 2023
581951e
index.ts
kdy1 Aug 24, 2023
09e1918
replaced
kdy1 Aug 24, 2023
b142370
Update test refs
kdy1 Aug 24, 2023
617f76a
Update test refs
kdy1 Aug 24, 2023
eb037b9
warn
kdy1 Aug 24, 2023
1db266b
error message
kdy1 Aug 24, 2023
fe70369
Better error message
kdy1 Aug 24, 2023
fea81c0
order
kdy1 Aug 24, 2023
9fc96d1
Better loggign
kdy1 Aug 24, 2023
e5806b6
Try more
kdy1 Aug 24, 2023
42820f3
`invoke_inner_resolver`
kdy1 Aug 24, 2023
f8912be
error message
kdy1 Aug 24, 2023
cb940df
More log
kdy1 Aug 24, 2023
de011a5
Remove dbg
kdy1 Aug 24, 2023
520e094
More relative
kdy1 Aug 24, 2023
472b46a
log
kdy1 Aug 24, 2023
980c097
log
kdy1 Aug 24, 2023
38b86a9
log
kdy1 Aug 24, 2023
dddb54f
Fix input
kdy1 Aug 24, 2023
f8c9edf
Update test refs
kdy1 Aug 24, 2023
5072aeb
Fix input
kdy1 Aug 24, 2023
dc2a998
Fix input
kdy1 Aug 24, 2023
544c059
Fix input
kdy1 Aug 24, 2023
a48da11
Udpate test refs
kdy1 Aug 24, 2023
573ebf2
Fix input
kdy1 Aug 24, 2023
7183bd1
Update test refs
kdy1 Aug 24, 2023
049e003
Fix input
kdy1 Aug 24, 2023
a2e4b24
Update test refs
kdy1 Aug 24, 2023
d0880bd
Update test refs
kdy1 Aug 24, 2023
b5600fd
context
kdy1 Aug 24, 2023
f83cf32
absolute
kdy1 Aug 24, 2023
db6c5cc
Update test refs
kdy1 Aug 24, 2023
e869129
error message
kdy1 Aug 24, 2023
6862f65
Fix
kdy1 Aug 24, 2023
d6e58bb
windows
kdy1 Aug 24, 2023
1c9271c
windows
kdy1 Aug 24, 2023
acf0fc2
Fix input
kdy1 Aug 25, 2023
b04d125
Fix input
kdy1 Aug 25, 2023
8a6a489
Merge branch 'main' into jsc-paths-nest
swc-bot Aug 25, 2023
ecafea3
Update test refs
kdy1 Aug 25, 2023
1f05c33
Fix tsc.rs
kdy1 Aug 25, 2023
1cae650
Merge branch 'jsc-paths-nest' of github.com:kdy1/swc into jsc-paths-nest
kdy1 Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import styles from "./foo.ts/index";
import styles from "./foo.ts/index.js";
console.log(styles);
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
const _a = require("../packages/a/src/index");
const _a = require("../packages/a/src");
console.log(`${(0, _a.displayA)()}`);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
(async function() {
const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("../packages/a/src/index")));
const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("../packages/a/src")));
console.log(displayA());
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function test() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { test } from "core/utils/utilFile";
test();
export function utilFn() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "test", {
enumerable: true,
get: function() {
return test;
}
});
function test() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "utilFn", {
enumerable: true,
get: function() {
return utilFn;
}
});
const _utilFile = require("./utilFile");
(0, _utilFile.test)();
function utilFn() {}
10 changes: 7 additions & 3 deletions crates/swc/tests/fixture/deno/paths/issue-3447/input/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
}
},
"paths": {
"@moduleA/*": ["modules/01-moduleA/*"],
"@moduleB/*": ["modules/03-moduleB/*"]
"@moduleA/*": [
"modules/01-moduleA/*"
],
"@moduleB/*": [
"modules/02-moduleB/*"
]
}
},
"module": {
Expand All @@ -28,4 +32,4 @@
"noInterop": false,
"ignoreDynamic": true
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { sum } from "./modules/01-moduleA/utils";
export { multiply } from "./modules/03-moduleB/utils";
export { multiply } from "./modules/02-moduleB/utils";
console.log(sum(1, 2));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 4;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { NekoRoute } from "./src/lib/structures/route";
import { NekoRoute } from "./src/lib/structures/route/index.js";
console.log(NekoRoute);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 4;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import styles from "./src/foo.bar.baz.js";
import styles from "./src/foo.bar.baz";
console.log(styles);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _ = /*#__PURE__*/ _interop_require_default._(require("./index"));
const _ = /*#__PURE__*/ _interop_require_default._(require("."));
function bar() {
console.log(_.default);
}
17 changes: 17 additions & 0 deletions crates/swc/tests/fixture/jsc-paths/7603/1/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"baseUrl": "./src",
"paths": {
"*": [
"*"
]
}
},
"minify": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { UsersModule } from 'users/users.module';

@Module({
imports: [UsersModule],
controllers: [],
providers: [],
})
export class AppModule {}
8 changes: 8 additions & 0 deletions crates/swc/tests/fixture/jsc-paths/7603/1/input/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from 'app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(5002);
}
bootstrap();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateUserDto {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateUserDto } from 'users/dto/create-user.dto';

export class UpdateUserDto extends PartialType(CreateUserDto) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class User {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersController } from 'users/users.controller';
import { UsersService } from 'users/users.service';

describe('UsersController', () => {
let controller: UsersController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
providers: [UsersService],
}).compile();

controller = module.get<UsersController>(UsersController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { UsersService } from 'users/users.service';
import { CreateUserDto } from 'users/dto/create-user.dto';
import { UpdateUserDto } from 'users/dto/update-user.dto';

@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {}

@Post()
create(@Body() createUserDto: CreateUserDto) {
return this.usersService.create(createUserDto);
}

@Get()
findAll() {
return this.usersService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.usersService.findOne(+id);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
return this.usersService.update(+id, updateUserDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.usersService.remove(+id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { UsersService } from 'users/users.service';
import { UsersController } from 'users/users.controller';

@Module({
controllers: [UsersController],
providers: [UsersService],
})
export class UsersModule { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersService } from 'users/users.service';

describe('UsersService', () => {
let service: UsersService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UsersService],
}).compile();

service = module.get<UsersService>(UsersService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateUserDto } from 'users/dto/create-user.dto';
import { UpdateUserDto } from 'users/dto/update-user.dto';

@Injectable()
export class UsersService {
create(createUserDto: CreateUserDto) {
return 'This action adds a new user';
}

findAll() {
return `This action returns all users`;
}

findOne(id: number) {
return `This action returns a #${id} user`;
}

update(id: number, updateUserDto: UpdateUserDto) {
return `This action updates a #${id} user`;
}

remove(id: number) {
return `This action removes a #${id} user`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
import { Module } from "@nestjs/common";
import { UsersModule } from "./users/users.module";
export var AppModule = function AppModule() {
"use strict";
_class_call_check(this, AppModule);
};
AppModule = _ts_decorate([
Module({
imports: [
UsersModule
],
controllers: [],
providers: []
})
], AppModule);
34 changes: 34 additions & 0 deletions crates/swc/tests/fixture/jsc-paths/7603/1/output/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
function bootstrap() {
return _bootstrap.apply(this, arguments);
}
function _bootstrap() {
_bootstrap = _async_to_generator(function() {
var app;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
return [
4,
NestFactory.create(AppModule)
];
case 1:
app = _state.sent();
return [
4,
app.listen(5002)
];
case 2:
_state.sent();
return [
2
];
}
});
});
return _bootstrap.apply(this, arguments);
}
bootstrap();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
export var CreateUserDto = function CreateUserDto() {
"use strict";
_class_call_check(this, CreateUserDto);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _inherits } from "@swc/helpers/_/_inherits";
import { _ as _create_super } from "@swc/helpers/_/_create_super";
import { PartialType } from "@nestjs/mapped-types";
import { CreateUserDto } from "./create-user.dto";
export var UpdateUserDto = /*#__PURE__*/ function(_PartialType) {
"use strict";
_inherits(UpdateUserDto, _PartialType);
var _super = _create_super(UpdateUserDto);
function UpdateUserDto() {
_class_call_check(this, UpdateUserDto);
return _super.apply(this, arguments);
}
return UpdateUserDto;
}(PartialType(CreateUserDto));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
export var User = function User() {
"use strict";
_class_call_check(this, User);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import { Test } from "@nestjs/testing";
import { UsersController } from "./users.controller";
import { UsersService } from "./users.service";
describe("UsersController", function() {
var controller;
beforeEach(/*#__PURE__*/ _async_to_generator(function() {
var module;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
return [
4,
Test.createTestingModule({
controllers: [
UsersController
],
providers: [
UsersService
]
}).compile()
];
case 1:
module = _state.sent();
controller = module.get(UsersController);
return [
2
];
}
});
}));
it("should be defined", function() {
expect(controller).toBeDefined();
});
});