simonhaenisch / rollup-plugin-typescript-paths

Rollup Plugin to automatically resolve path aliases set in the compilerOptions section of tsconfig.json.
https://npmjs.com/rollup-plugin-typescript-paths
MIT License
43 stars 12 forks source link

Rename exported function to match rollup plugin (tacit) naming convention #1

Closed juliendargelos closed 4 years ago

juliendargelos commented 4 years ago

Almost every rollup plugin exports a function whose name is a camel-cased version of the package name without the rollup-plugin- (or @rollup/plugin-) prefix. Since rollup-plugin-typescript-paths uses a named export, I cannot rename it without using the as keyword, and it kind of stands out among the other plugins:

import autoExternal from 'rollup-plugin-auto-external'
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import cleaner from 'rollup-plugin-cleaner'
import serve from 'rollup-plugin-serve'
import html from '@rollup/plugin-html'
import ts from 'rollup-plugin-ts'
import { resolveTypescriptPaths as typescriptPaths } from 'rollup-plugin-typescript-paths'
import { terser } from 'rollup-plugin-terser'
import { eslint } from 'rollup-plugin-eslint'

I know this pr is quite incidental, but would you consider it ?

simonhaenisch commented 4 years ago

Thanks for the PR and I see your point, but instead of renaming the export, how about adding

export default resolveTypescriptPaths;

so that you can import it as

import typescriptPaths from 'rollup-plugin-typescript-paths';

?

Because otherwise this is a breaking change, and a general naming convention is that functions should start with a verb in their name. I probably should have called the repo rollup-plugin-resolve-typescript-paths but that's such a long name 🤓

simonhaenisch commented 4 years ago

Hm just trying this out and simply adding export default works for es modules and typescript, but it's not a commonjs default export and therefore would need to be required as require('rollup-plugin-typescript-paths').default. To create a cjs default export, the syntax would be export =, but then the module can't have any other (named) exports. What official rollup plugins do is to use rollup to bundle the plugin into both a cjs and an es module but I can't be bothered.

simonhaenisch commented 4 years ago

I published it to npm as 1.2.1. I added

export const resolveTypescriptPaths = typescriptPaths;

export default typescriptPaths;

so that it doesn't break the previous named import and it's also possible to use the default import sytnax.