Skip to content

Account for baseUrl when generating relative path from tsconfig #15

Description

@OliverJAsh

Steps to reproduce

Full reduced test case: https://github.com/OliverJAsh/copy-with-imports-base-url-test

Enable "copy-with-imports.path-relative-from-tsconfig": true.

tsconfig.json:

{
    "compilerOptions": {
        "baseUrl": "app"
    }
}

app/helpers/foo.ts:

export const foo = 1;

app/helpers/bar.ts:

import { foo } from "./foo";

// 1. copy this
console.log(foo)

app/helpers/baz.ts:

// 2. paste here

Actual

app/helpers/baz.ts:

import {foo} from 'app/helpers/foo';
// 2. paste here
console.log(foo)

Expected

app/helpers/baz.ts:

import {foo} from 'helpers/foo';
// 2. paste here
console.log(foo)
Screen.Recording.2021-12-06.at.10.57.02.mov

I think we need to account for config.compilerOptions.baseUrl here:

return path.relative(path.dirname(config.path), specifier);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions