1.0.0 β’ Published 9 months ago
@esplugins/no-internal-exports v1.0.0
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-exports
PNPM
pnpm add @esplugins/no-internal-exports
Yarn
yarn add @esplugins/no-internal-exports
Support
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
stripInternal
atcompilerOptions
to do not emit@internal
types ind.ts
!!TIP alternative for Types To mark type/interface/enum as internal and avoid removing them from
d.ts
you can use@dontexport
!
/** @internal */
const internalFunc1 = () => {};
/**
* @internal */
const internalFunc2 = () => {};
/**
* @internal
*/
const internalFunc3 = () => {};
1.0.0
9 months ago
1.0.0-prerelease.2
9 months ago
1.0.0-prerelease.1
9 months ago
1.0.0-prerelease
9 months ago