Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin): don't prefix absolute win paths #2788

Merged
merged 1 commit into from Apr 24, 2023

Conversation

mikejpeters
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Compilation fails on Windows in certain cases when using the GraphQL plugin because absolute paths are prefixed with ./.

Issue Number: #2661

What is the new behavior?

Don't prefix absolute paths on Windows with ./.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

I think this is a temporary solution at best. I'm not sure the posix version of path methods should be being used for all the logic in the plugin, since things like posix.relative() do not behave properly with windows paths. I could maybe create another pull request to switch to the non-posix path methods, but not sure if I'm missing an important reason it's in use.

I also wanted to add a test but it's tricky:

describe('plugin-utils', () => {
  describe('replaceImportPath', () => {
  
    it('should not replace path on windows', () => {
      const actual = replaceImportPath(
          'import("C:\\\\project\\\\src\\\\author.model").Author',
          'C:\\project\\src\\post.model.ts',
      );

      expect(actual).toStrictEqual({
        typeReference: '"require("C:\\\\project\\\\src\\\\author.model").Author',
        importPath: 'C:/project/src/author.model',
      });
    });

This test fails if run on Linux, since path.isAbsolute('C:/...') only returns true when run on Windows. I didn't want to complicate things by using Jest to mock path functions. Something like jest-os-detection allows specifying whether a test should be skipped/run depending on the OS, but this is only very useful if CI also runs the test suite on Windows, and I didn't want to make too many changes for this pull request.

@kamilmysliwiec kamilmysliwiec merged commit 361b059 into nestjs:master Apr 24, 2023
1 check passed
@kamilmysliwiec
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants