[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
In the compilerOptions of nest-cli.json you can specify an array of assets. Unfortunately the path for assets re-uses sourceRoot (where the project files are). As a consequence it is not possible to run nest build and include files from the project root using i.e. src as sourceRoot
UseCase: i am using typeorm and the ormconfig.js configuration file of typeorm, which is expected to be in the project root folder. Note: i have to place my configuration there (and not i.e. in app.module.ts) because i want to be able to use typeorm-cli as well (for the migrations) and i don't want to duplicate the configuration.
Problem: the ormconfig.json/ts/js is not copied to dist folder running nest build.
Adding "assets" : [ "ormconfig.js" ] does not work because assets uses src as root folder
Adding "assets" : [ "../ormconfig.js" ] does not work because src is considered as root which you can't go up
nest-cli.json
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
},
"exclude": ["node_modules", "dist"]
}
the sourceRoot should not be considered for assets, or it should be possible to specify an assetRoot in nest-cli.json, so that it is possible to put files (like ormconfig) in dist after nest build (without using additional tools like copyfiles)
"assets" : [ "ormconfig.js" ]
_ _ _ ___ _____ _____ _ _____
| \ | | | | |_ |/ ___|/ __ \| | |_ _|
| \| | ___ ___ | |_ | |\ `--. | / \/| | | |
| . ` | / _ \/ __|| __| | | `--. \| | | | | |
| |\ || __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/ \____/\_____/\___/
[System Information]
OS Version : Windows 10
NodeJS Version : v12.14.1
NPM Version : 6.13.4
[Nest CLI]
Nest CLI Version : 6.14.1
[Nest Platform Information]
@nestjsx/crud-typeorm version : 4.4.1
platform-express version : 6.11.1
@nestjsx/crud version : 4.4.1
passport version : 6.1.1
swagger version : 4.2.1
typeorm version : 6.2.0
common version : 6.11.1
config version : 0.1.0
core version : 6.11.1
TypeORM CLI allows you to specify which config should be used with the --config flag:
typeorm migration:generate --config src/ormconfig.js
Hence, you can move it into the src directory.
Hi Kamil,
using the cli yes it does allow to specify a location, but then it doesn't work anymore for running the nest app. Unfortunately it is only looking in the project root (at least according to the documentation:
https://typeorm.io/#/using-ormconfig
The goal is to have only one configuration - for the app and the migrations and for multiple environments (local development, cloud). I could import the file and pass it to TypeOrmModule.forRoot(<here>), but isn't that a bit hacky when ormconfig should be loaded by convention with a specific name and a specific location?
Thanks and best regards,
Matthias
Most helpful comment
Hi Kamil,
using the cli yes it does allow to specify a location, but then it doesn't work anymore for running the nest app. Unfortunately it is only looking in the project root (at least according to the documentation:
https://typeorm.io/#/using-ormconfig
The goal is to have only one configuration - for the app and the migrations and for multiple environments (local development, cloud). I could import the file and pass it to
TypeOrmModule.forRoot(<here>), but isn't that a bit hacky when ormconfig should be loaded by convention with a specific name and a specific location?Thanks and best regards,
Matthias