Skip to content

Packager - Fix absolute imports on Windows - #12530

Closed
janicduplessis wants to merge 4 commits into
react:masterfrom
janicduplessis:fix-absolute-module-windows
Closed

janicduplessis wants to merge 4 commits into
react:masterfrom
janicduplessis:fix-absolute-module-windows

Conversation

@janicduplessis

Copy link
Copy Markdown
Contributor

Absolute imports on Windows were broken, I'm not 100% sure when this happens but when I tested Exponent on Windows which uses rn-cli.config.js with

getTransformOptions() {
    return {
      reactNativePath: path.resolve('./node_modules/react-native'),
      reactPath: path.resolve('./node_modules/react'),
    };
  }

it seemed to use absolute paths for these modules.

I also tested absolute paths in node repl and it does work for absolute paths of different formats. C:/root/test.js, /root/test.js, C:\root\test.js all do resolve properly to the same module.

To fix this I resolve the absolute path using path.resolve on Windows. Noop on other platforms to avoid the overhead since it's not necessary.

Test plan

  • Tested that it fixed the bug I had when running Exponent on Windows.
  • Updated the absolute path test to use forward slashes since this is what happens in practice when using getTransformOptions. We can't test all cases on linux since adding the drive letter automatically doesn't work.

@janicduplessis janicduplessis changed the title Fix absolute module windows Packager - Fix absolute imports on Windows Feb 22, 2017
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: review-needed labels Feb 22, 2017
@janicduplessis

Copy link
Copy Markdown
Contributor Author

cc @cpojer

@janicduplessis

Copy link
Copy Markdown
Contributor Author

@jeanlauliac Could you have a look at this?

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Mar 1, 2017
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@jeanlauliac has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@jeanlauliac

jeanlauliac commented Mar 1, 2017 •

Copy link
Copy Markdown

Looks good, it should land today. Thank you!

@jeanlauliac
jeanlauliac requested review from jeanlauliac and removed request for jeanlauliac March 1, 2017 15:12
facebook-github-bot pushed a commit to react/metro that referenced this pull request Mar 1, 2017
Summary:
Absolute imports on Windows were broken, I'm not 100% sure when this happens but when I tested Exponent on Windows which uses `rn-cli.config.js` with
```js
getTransformOptions() {
    return {
      reactNativePath: path.resolve('./node_modules/react-native'),
      reactPath: path.resolve('./node_modules/react'),
    };
  }
```
it seemed to use absolute paths for these modules.

I also tested absolute paths in node repl and it does work for absolute paths of different formats. `C:/root/test.js`, `/root/test.js`, `C:\root\test.js` all do resolve properly to the same module.

To fix this I resolve the absolute path using `path.resolve` on Windows. Noop on other platforms to avoid the overhead since it's not necessary.

**Test plan**
- Tested that it fixed the bug I had when running Exponent on Windows.
- Updated the absolute path test to use forward slashes since this is what happens in practice when using `getTransformOptions`. We can't test all cases on linux since adding the drive letter au
Closes react/react-native#12530

Differential Revision: D4634699

Pulled By: jeanlauliac

fbshipit-source-id: 0cf6528069b79cba2e0f79f48f5a524d59b7091e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants