Toggle type fields in package.json files
This package lets you toggle type fields in package.json files.
toggle-pkg-type was created as a workaround for evanw/esbuild#2026.
Use this package when you use default exports and also ship code in ES module and CommonJS format.
The original issue was closed as "working as intended", but the solution provided is not suitable for all users:
Setting
"type": "module"in yourpackage.jsonmeans "I need to use node's behavior" for both Webpack and esbuild. If you don't need node's behavior, then just remove"type": "module"from yourpackage.json.
This logic does not account for needing "type": "module" in development, but not when building CommonJS modules (i.e
running tests or using a custom loader).
This package is ESM only.
yarn add -D @flex-development/toggle-pkg-typeFrom Git:
yarn add -D @flex-development/toggle-pkg-type@flex-development/toggle-pkg-typeSee Git - Protocols | Yarn for details on requesting a specific branch, commit, or tag.
Usage
$ toggle-pkg-type [off|on] [options]
Options
-i, --id Module id of package directory or manifest (default process.env.npm_package_json)
-v, --version Displays current version
-h, --help Displays this message
Examples
$ toggle-pkg-type
$ toggle-pkg-type --id /path/to/manifest
$ toggle-pkg-type off
$ toggle-pkg-type onThis package exports no identifiers. The default export is toggle.
Enable or disable the type field in a package.json file.
The field is disabled by changing the field name to #type. The field value will not be modified.
Command Manifest:
NIL(null,undefined): Disabletypeif enabled, re-enable otherwiseoff: Disabletypefieldon: Re-enabletypefield
This is a no-op under any of the following conditions:
- A
package.jsonfile is not found - The
typefield is not defined in the located manifest - The
#typefield is not defined in the located manifest (i.e. thetypefield was not previously disabled)
{Nilable<Command>?}[command=null]— Toggle command{mlly.ModuleId?}[id='.']— Module id of package directory or manifest
{void} Nothing when complete.
This package is fully typed with TypeScript.
See CONTRIBUTING.md.