tsconfig-replace-paths icon indicating copy to clipboard operation
tsconfig-replace-paths copied to clipboard

Rare bug in outFile

Open steveruizok opened this issue 3 years ago • 1 comments

I've generally used this package with a config that uses an outDir, however I gave outFile a shot and noticed a few misses!

In a project where I had a folder named types with an index.ts, my import is import types from "~types". When I build this to a single declaration file with outFile, the import is (in certain places) converted to import("types"), rather than `import("types/index").

The types are being processed, but perhaps incorrectly.

It's always where the type is imported "inline" as shown:

declare module "lib/TLBush/TLBush" {
    import RBush from 'rbush';
    import type { TLShape } from "lib/TLShape/index";
    export class TLBush<S extends TLShape> extends RBush<S> {
        toBBox: (shape: S) => import("types").TLBounds;
    }
}

The correct result would be:

declare module "lib/TLBush/TLBush" {
    import RBush from 'rbush';
    import type { TLShape } from "lib/TLShape/index";
    export class TLBush<S extends TLShape> extends RBush<S> {
        toBBox: (shape: S) => import("types/index").TLBounds;
    }
}

Without tsconfig-replace-paths, I get:

declare module "lib/TLBush/TLBush" {
    import RBush from 'rbush';
    import type { TLShape } from "lib/TLShape/index";
    export class TLBush<S extends TLShape> extends RBush<S> {
        toBBox: (shape: S) => import("~types").TLBounds;
    }
}

Which also shows an error.

Another example where the import is resolved to ./types rather than types/index.

declare module "lib/TLApp/TLSceneGraph/TLSceneGraph" {
    import { TLApp, TLShape } from "lib/index";
    export class TLSceneGraph<S extends TLShape> {
        constructor(app: TLApp<S>, document: TLDocumentModel<S>);
        app: TLApp<S>;
       // snip
        toJSON: () => {
            shapes: {
                [k: string]: import("./types").TLShapeModel;
            };
            bindings: {
                [k: string]: TLBinding;
            };
        };
    }
}

(P.S. Thanks for this package, it's great!)

steveruizok avatar Feb 06 '22 11:02 steveruizok

I've tried replicating, but I'm unsuccessful.

My tsconfig has "~types": ["./src/props"]

File has import { RootProps } from '~types'

Output is import { RootProps } from '../../props';

It doesn't output to '../../props/index', but it doesn't need to in my case.

Am I missing something?

jonkwheeler avatar Jun 11 '22 14:06 jonkwheeler