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.json
means "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-type
From Git:
yarn add -D @flex-development/toggle-pkg-type@flex-development/toggle-pkg-type
See 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 on
This 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
): Disabletype
if enabled, re-enable otherwiseoff
: Disabletype
fieldon
: Re-enabletype
field
This is a no-op under any of the following conditions:
- A
package.json
file is not found - The
type
field is not defined in the located manifest - The
#type
field is not defined in the located manifest (i.e. thetype
field 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
.