sparse-intern-71089
06/09/2021, 8:53 PMlittle-cartoon-10569
06/09/2021, 9:32 PMlittle-cartoon-10569
06/09/2021, 9:50 PM"module": "commonjs"
. The Pulumi files that the spec files import work fine with aliases.little-cartoon-10569
06/09/2021, 9:52 PMimport { x } from "@mymodule";
in my .ts files, but I need import { x } from "../../../../src/resources/mymodule";
in my .spec.ts files.echoing-zebra-28421
06/09/2021, 9:57 PM"_moduleAliases": {
"@application": "src/application",
"@config": "src/config",
"@domain": "src/domain",
"@interfaces": "src/interfaces",
"@api-route": "src/api-route"
},
little-cartoon-10569
06/09/2021, 9:58 PMechoing-zebra-28421
06/09/2021, 10:33 PM"module-alias": "^2.2.2"
little-cartoon-10569
06/09/2021, 10:39 PMlittle-cartoon-10569
06/09/2021, 10:52 PMmodule-alias/register
? Do you use require("module-alias")
in all your projects? I'm wondering if there's a way to do it using package.json or tsconfig.json.echoing-zebra-28421
06/09/2021, 11:02 PMnpm i --save module-alias
in the tsconfig.json
you define your paths:
In my case
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@application/*": ["application/*"],
"@config/*": ["config/*"],
"@domain/*": ["domain/*"],
"@api-route": ["api-route.ts"],
"@interfaces/*": ["interfaces/*"]
},
in the package.json
you define the _moduleAliases
in my case
"_moduleAliases": {
"@application": "src/application",
"@config": "src/config",
"@domain": "src/domain",
"@interfaces": "src/interfaces",
"@api-route": "src/api-route"
},
now in the index.ts
(in my case is handler.ts
) you add
import "module-alias/register";
little-cartoon-10569
06/09/2021, 11:02 PMlittle-cartoon-10569
06/09/2021, 11:03 PMechoing-zebra-28421
06/09/2021, 11:06 PMmy-project
-- src
-- index.ts
-- folder1
-- folder2
...
-- tsconfig.ts
...
little-cartoon-10569
06/09/2021, 11:21 PMcurved-pharmacist-41509
06/10/2021, 12:49 AMentry.ts
file which my package.json points to. it has
const path = require('path')
const tsConfig = require(__dirname + '/../../../tsconfig.base.json')
const tsConfigPaths = require('tsconfig-paths')
const args = {
baseUrl: path.resolve(__dirname + '/../../..'),
paths: tsConfig.compilerOptions.paths,
}
tsConfigPaths.register(args)
module.exports = require('./index')
curved-pharmacist-41509
06/10/2021, 12:49 AMcurved-pharmacist-41509
06/10/2021, 12:49 AMlittle-cartoon-10569
06/10/2021, 12:54 AMcurved-pharmacist-41509
06/10/2021, 12:54 AMcurved-pharmacist-41509
06/10/2021, 12:55 AMcurved-pharmacist-41509
06/10/2021, 12:55 AMcurved-pharmacist-41509
06/10/2021, 12:56 AMcurved-pharmacist-41509
06/10/2021, 12:57 AMnx up --affected