Skip to content

Add support for Glob-Patterns in "noResolvePaths"#1475

Merged
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
CoroModLoader:glob-matching
Aug 24, 2023
Merged

Add support for Glob-Patterns in "noResolvePaths"#1475
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
CoroModLoader:glob-matching

Conversation

@Curve
Copy link
Copy Markdown
Contributor

@Curve Curve commented Aug 24, 2023

Add support for glob patterns in noResolvePaths using picomatch.

Also supplies 0 as the duration for the CachedInputFileSystem as updated typing requires so.
This change should not change any caching behavior as it explicitly causes the current behavior to be used (see here)

Fixes #1161.

@Curve
Copy link
Copy Markdown
Contributor Author

Curve commented Aug 24, 2023

Could we maybe have a new release after this is merged? - We'd desperately need this for a project ^^

Copy link
Copy Markdown
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but before merging this I would like to have some tests added here: https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/test/transpile/module-resolution.spec.ts#L444

The test can simply check if there are no diagnostics for non-existing noResolvePaths (with a glob pattern), and that existing files are still resolved.

Something along these lines:

    test("can ignore everything with glob pattern", () => {
        util.testModule`
            import * as a from "a";
            import * as bc from "b/c";
            import * as d from "./d";
            import * as ef from "./e/f";

            import 
        `
        .addExtraFile("a.d.ts", "export function foo1(): void;")
        .addExtraFile("b/c.d.ts", "export function foo2(): void;")
        .addExtraFile("d.d.ts", "export function foo3(): void;")
        .addExtraFile("e/f.d.ts", "export function foo4(): void;")
        .setOptions({ noResolvePaths: ["*"] })
        .expectToHaveNoDiagnostics();
    });

    test("can ignore specific files with glob pattern", () => {
        util.testModule`
            import * as a from "ignoreme1";
            import * as b from "ignoreme2";

            import * as c from "actualfile";

            export const result = c.foo();
        `
        .addExtraFile("a.d.ts", "export function foo1(): void;")
        .addExtraFile("b.d.ts", "export function foo2(): void;")
        .addExtraFile("actualfile.ts", "export function foo() { return 'foo'; }")
        .setOptions({ noResolvePaths: ["ignoreme*"] })
        .expectToHaveNoDiagnostics()
        .expectToEqual({ result: "foo" });
    });

(I haven't tested these to you might have to tweak them a little)

@Curve
Copy link
Copy Markdown
Contributor Author

Curve commented Aug 24, 2023

Alright, will add them shortly

@Curve Curve requested a review from Perryvw August 24, 2023 16:10
@Curve
Copy link
Copy Markdown
Contributor Author

Curve commented Aug 24, 2023

I've now added 3 tests

  • Test if noResolvePaths works with simple-glob pattern
    • This is a modified version of your second suggested test case, which also includes a lua file to preload the missing file as to not error out at runtime
  • Test if globbed noResolvePaths works with require()
  • Test if globbed noResolvePaths works within a lua file

@Perryvw Perryvw merged commit be032ce into TypeScriptToLua:master Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow noResolvePaths to be a pattern

2 participants