Skip to content

Conversation

@janicduplessis
Copy link
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
Contributor Author

cc @cpojer

@janicduplessis
Copy link
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
Contributor

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

@jeanlauliac
Copy link

jeanlauliac commented Mar 1, 2017

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 facebook/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 facebook/react-native#12530

Differential Revision: D4634699

Pulled By: jeanlauliac

fbshipit-source-id: 0cf6528069b79cba2e0f79f48f5a524d59b7091e
dudeinthemirror pushed a commit to dudeinthemirror/react-native 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 facebook#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