Skip to content

Conversation

@cawfeecoder
Copy link

Description

This adds the ability for exports to contextually determine whether index.{js,ts,tsx,jsx} is located at the top level (i.e. src/index.) or within a sub-folder (i.e. src/button/index.) to determine what the appropriate named export should be.

In the case of a sub-folder, the export becomes "./${sub_folder}" instead of "./index" (old behavior).

This resolves #3

Nicholas Frush added 2 commits November 25, 2021 00:25
…r index.js is located under to determine whether it is the main import or a named export
@UpperCod
Copy link
Member

Thanks for the feature, @atomico/exports was created to keep a name pattern from the file name, example:

src
  |- component-1
  |  |- component-1.jsx
  |  |- component-1.test.js
  |  |- component-1.css
  |- component-2
  |  |- component-2.jsx
  |  |- component-2.test.js
  |  |- component-2.css
npx exports src/*/*.{js,jsx,ts,tsx} --main component-1 --exports
{
  "exports": {
    ".": "dist/component-1.js",
    "component-2": "dist/component-2.js"
  }
}

It is a pattern that inherits from the Stencil development model, but I think we can add it as requested, for this we must consider the following:

  1. the subfolder is only conditional on the use of index.js
  2. there can be more than one export from the folder

it could be something like this:

const parsedPath = path.parse(output);
const { name } = {
  name:
    parsedPath.name === "index"
      ? path.parse(parsedPath.dir).name
      : parsedPath.name,
};

when detecting the use of index as a name it moves to the sub-folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Allow exports to use sub-folder as a name

2 participants