@esplugins/no-internal-exports
v1.0.0
Published
Esbuild plugin for not exporting @internal functions/types/variables
Downloads
7
Maintainers
Readme
If you ever wanted to export @internal Functions/Variables/Types but you was worried about exporting that outside
with entry files Dont Worry Right know you can export them in your codebase and protect them to
not being exported in entry file.
// index.ts (Entry file)
// @/functions - its `/src/functions/index.ts` path to export barrel
export * from "@/functions"
// functions/index.ts
export * from "./nameValidator"
// @/functions/nameValidator.ts
/** @internal */
export const MAX_LENGTH = 256 as const;
/** @internal */
export const MAX_SAFE_NAME_LENGTH = MAX_LENGTH - 6 ;
/** @internal */
export const MyErrorList = {"TOO_LONG":{...},...code}
export const nameValidator = (name:string) => {...code}
export default nameValidator;
// nameValidator.test.ts
// Importing to check that error case drop correct error
import { MyErrorList } from "@/functions/nameValidator.ts"// index.js - final build output
// Note that, every element with @internal is not exported!
export { nameValidator };📜 List of Contents
Install
NPM
npm install @esplugins/no-internal-exportsPNPM
pnpm add @esplugins/no-internal-exportsYarn
yarn add @esplugins/no-internal-exportsSupport
There you can check support for other bundlers!
Status
| Emoji | Meaning | | ----- | --------------- | | ✅ | Completed | | ⏸️ | Paused | | ❌ | Aborted | | 🛠️ | In Progress | | 💤 | Not Yet Started | | ❓ | Not Checked |
Table of Support
| Platform | NPM | Status | | -------- | --- | ------------ | | Esbuild | - | ✅ | | TSUP | - | ✅ | | Vite | - | 💤 || ✅❓ | | Webpack | - | 💤 | | Rollup | - | 💤 | | Parcel | - | 💤 | | Rollup | - | 💤 |
Implementation
Esbuild
import noInternalExport from "@esplugins/no-internal-exports";
return esbuild.build({
entryPoints: ["src/index.ts"],
// bundle: true, Do like you want there, just example
// outfile: "out.js", -||-
plugins: [noInternalExport]
});TSUP
import { defineConfig } from "tsup";
import noInternalExport from "@esplugins/no-internal-exports";
export default defineConfig({
entry: ["src/index.ts"],
// target: "es2022", Do like you want there, just example
// format: ["esm"], -||-
// clean: true, -||-
// splitting: false, -||-
// platform: "node", -||-
// keepNames: true, -||-
esbuildPlugins: [noInternalExport]
});Usage
Just use @internal in multi-line comment before Function/Variable/Type. (Like in JSDocs/TSDocs)
[!TIP] To Typescript config you can add
stripInternalatcompilerOptionsto do not emit@internaltypes ind.ts!
[!TIP] alternative for Types To mark type/interface/enum as internal and avoid removing them from
d.tsyou can use@dontexport!
/** @internal */
const internalFunc1 = () => {};
/**
* @internal */
const internalFunc2 = () => {};
/**
* @internal
*/
const internalFunc3 = () => {};