Skip to content

Require sibling index.js regression #296

@albertfdp

Description

@albertfdp

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions