1.0.0 β€’ Published 9 months ago

@esplugins/no-internal-exports v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

image

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

EmojiMeaning
βœ…Completed
⏸️Paused
❌Aborted
πŸ› οΈIn Progress
πŸ’€Not Yet Started
❓Not Checked

Table of Support

PlatformNPMStatus
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 at compilerOptions to do not emit @internal types in d.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 = () => {};