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

Require sibling index.js regression #296

Open
albertfdp opened this issue May 21, 2018 · 1 comment
Open

Require sibling index.js regression #296

albertfdp opened this issue May 21, 2018 · 1 comment
Labels

Comments

@albertfdp
Copy link

albertfdp commented May 21, 2018

It seems that requiring a sibling index.js file in a folder with the require('.') notation stopped working since #253

I usually have the following structure for components:

|-- components
|    -- Button
|        -- index.js
|        -- spec.js

and I'd require the file on spec.js with:

const Button = require('.');

This stopped working on 3.1.0 and I need to require('./index.js') which is a bit cumbersome and also in nodejs it's standard to resolve require('.') to the sibling index.js file.

This is an example breaking test, which passes before 7dc2da6

describe('when requiring a sibling index.js', () => {
    const siblingAliasTransformOpts = {
      babelrc: false,
      plugins: [
        [plugin, {
          root: ['./src'],
        }],
      ],
    };

    it('should resolve an index.js on a folder name', () => {
      testWithImport(
        '.',
        '.',
        siblingAliasTransformOpts,
      );
    });
  });
  ● module-resolver › when requiring a sibling index.js › should resolve an index.js on a folder name

    expect(received).toBe(expected) // Object.is equality

    Expected value to be:
      "import something from \".\";"
    Received:
      "import something from \"./src\";"

      10 |     const result = transform(code, transformerOpts);
      11 |
    > 12 |     expect(result.code).toBe(`import something from "${output}";`);
      13 |   }
      14 |
      15 |   describe('exports', () => {

I'm happy to help with a PR or to complement with more details. Thanks!

@fatfisz
Copy link
Contributor

fatfisz commented May 21, 2018

Seems like a legit bug.

Thanks for volunteering to create a PR - that's the spirit! I'd only recommend adding filename to the test options (can point e.g. to './test/testproject/src/components/App.js' because it has a sibling index.js file) and using './test/testproject/src' as root.

@tleunen tleunen added the bug label Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants