0

I'm working on a two-package project using Typescript & React-Native:

PackageA(which is leaf package) contains a REST client and mocks

MyOwnLibrary
- src
  -tests
    _mocks_
      -restClientMock.ts
  -restClient.ts

Right now, I can import stuff using something like 'import { restClient } from 'MyOwnLibrary/lib/tests/_mocks'

But, I want to consume the mocks like import { restClient } from 'MyOwnLibrary/mocks'

Any ideas how to get this done?

SDEZero
  • 363
  • 2
  • 13
  • I know I could add "paths" in tsconfig in my top level package so that it could resolve correct. I'm wondering if anything could be done in lower package level? – SDEZero Dec 26 '19 at 23:39

1 Answers1

0

Use tsc -init command to make tsconfig.json file

Open file and edit baseUrl and paths

 "baseUrl": "MyOwnLibrary/src",    /* Base directory */
    "paths": {
      "MyOwnLibrary/mocks" : [    /* Whatever name you want to use */
        "tests/_mocks/restClientMock.ts"   /* Path to your module */
      ]
    },  

then, you can simply import like this:

import { restClient } from 'MyOwnLibrary/mocks' /* Imports from MyOwnLibrary/src/tests/_mocks/restClientMock */
Blayke
  • 119
  • 3
  • 11