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

feat(compiler): Support ESM subpath imports #5572

Merged
merged 7 commits into from
Feb 7, 2025

Conversation

siketyan
Copy link
Contributor

@siketyan siketyan commented Jan 12, 2025

In my understand TypeSpec typically follows the ESM module resolution algorithm. Subpath exports are already supported, but subpath imports are not yet. This pull request proposes to add support for ESM subpath imports in TypeSpec files.

For details of subpath imports, refer https://nodejs.org/api/packages.html#subpath-imports and https://nodejs.org/api/esm.html#resolution-algorithm-specification.

Example usage

If we have a imports declaration in package.json:

{
  "name": "@contoso/tsp",
  "imports": {
    "#utils": "./src/utils.tsp",
  },
}

We can now import #utils from tsp files:

import "#utils";

@siketyan siketyan changed the title feat: Support ESM subpath imports feat(compiler): Support ESM subpath imports Jan 12, 2025
Copy link
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, we'll have to confirm with the team that we do indeed want to support that fully but I don't really see why not.

Copy link
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with the Team and we are all good to add this! Will be part of the febuary release(next week).

Thanks for the contribution!

@siketyan
Copy link
Contributor Author

siketyan commented Feb 7, 2025

Thank you for picking up this and the follow-up commits 🙏 looking forward to the next release!

@timotheeguerin timotheeguerin added this pull request to the merge queue Feb 7, 2025
Merged via the queue into microsoft:main with commit 254f6b9 Feb 7, 2025
19 checks passed
dmnorc pushed a commit to dmnorc/typespec that referenced this pull request Feb 18, 2025
In my understand TypeSpec typically follows the ESM module resolution
algorithm. Subpath exports are already supported, but subpath imports
are not yet. This pull request proposes to add support for ESM subpath
imports in TypeSpec files.

For details of subpath imports, refer
https://nodejs.org/api/packages.html#subpath-imports and
https://nodejs.org/api/esm.html#resolution-algorithm-specification.

## Example usage

If we have a `imports` declaration in `package.json`:

```json
{
  "name": "@contoso/tsp",
  "imports": {
    "#utils": "./src/utils.tsp",
  },
}
```

We can now import `#utils` from tsp files:

```tsp
import "#utils";
```

---------

Signed-off-by: Naoki Ikeguchi <[email protected]>
Co-authored-by: Timothee Guerin <[email protected]>
Co-authored-by: Timothee Guerin <[email protected]>
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.

2 participants