{"id":19584787,"url":"https://github.com/flex-development/toggle-pkg-type","last_synced_at":"2025-08-02T07:10:59.024Z","repository":{"id":60607480,"uuid":"544197801","full_name":"flex-development/toggle-pkg-type","owner":"flex-development","description":"Toggle type fields in package.json files","archived":false,"fork":false,"pushed_at":"2024-06-13T18:14:29.000Z","size":2649,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-03T09:07:38.781Z","etag":null,"topics":["cjs","commonjs","default-exports","esbuild","esm","interop","module","package-json","toggle","type","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/flex-development/toggle-pkg-type","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flex-development.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["flex-development"]}},"created_at":"2022-10-01T22:37:47.000Z","updated_at":"2023-11-27T23:53:45.000Z","dependencies_parsed_at":"2023-02-04T09:31:39.823Z","dependency_job_id":"9fbcf032-71c3-4da7-a4cf-d619c62366fe","html_url":"https://github.com/flex-development/toggle-pkg-type","commit_stats":{"total_commits":88,"total_committers":2,"mean_commits":44.0,"dds":0.4772727272727273,"last_synced_commit":"18bfe040d91c2ca6caab0a383b779e83e180dec4"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/flex-development/toggle-pkg-type","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ftoggle-pkg-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ftoggle-pkg-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ftoggle-pkg-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ftoggle-pkg-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flex-development","download_url":"https://codeload.github.com/flex-development/toggle-pkg-type/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ftoggle-pkg-type/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268348162,"owners_count":24236294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cjs","commonjs","default-exports","esbuild","esm","interop","module","package-json","toggle","type","typescript"],"created_at":"2024-11-11T07:49:45.098Z","updated_at":"2025-08-02T07:10:59.003Z","avatar_url":"https://github.com/flex-development.png","language":"JavaScript","funding_links":["https://github.com/sponsors/flex-development"],"categories":[],"sub_categories":[],"readme":"# toggle-pkg-type\n\n[![github release](https://img.shields.io/github/v/release/flex-development/toggle-pkg-type.svg?include_prereleases\u0026sort=semver)](https://github.com/flex-development/toggle-pkg-type/releases/latest)\n[![npm](https://img.shields.io/npm/v/@flex-development/toggle-pkg-type.svg)](https://npmjs.com/package/@flex-development/toggle-pkg-type)\n[![codecov](https://codecov.io/gh/flex-development/toggle-pkg-type/branch/main/graph/badge.svg?token=TSNEYCXRO3)](https://codecov.io/gh/flex-development/toggle-pkg-type)\n[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)\n[![license](https://img.shields.io/github/license/flex-development/toggle-pkg-type.svg)](LICENSE.md)\n[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits\u0026logoColor=ffffff)](https://conventionalcommits.org/)\n[![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript\u0026logoColor=ffffff)](https://typescriptlang.org/)\n[![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat\u0026logo=vitest\u0026logoColor=ffffff)](https://vitest.dev/)\n[![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\u0026logo=yarn\u0026logoColor=ffffff)](https://yarnpkg.com/)\n\nToggle [`type`][1] fields in `package.json` files\n\n## Contents\n\n- [What is this?](#what-is-this)\n- [When should I use this?](#when-should-i-use-this)\n- [Install](#install)\n- [Use](#use)\n- [API](#api)\n  - [`toggle([command][, id])`](#togglecommand-id)\n- [Types](#types)\n  - [Type Definitions](#type-definitions)\n- [Contribute](#contribute)\n\n## What is this?\n\nThis package lets you toggle [`type`][1] fields in `package.json` files.\n\n## When should I use this?\n\n`toggle-pkg-type` was created as a workaround for [`evanw/esbuild#2026`][2].\n\nUse this package when you use `default` exports and also [ship code in ES module and CommonJS format][3].\n\nThe original issue was closed as \"working as intended\", but the solution provided is not suitable for all users:\n\n\u003e Setting `\"type\": \"module\"` in your `package.json` means \"I need to use node's behavior\" for both Webpack and esbuild.\n\u003e If you don't need node's behavior, then just remove `\"type\": \"module\"` from your `package.json`.\n\nThis logic does not account for needing `\"type\": \"module\"` in development, but not when building CommonJS modules (i.e\nrunning tests or using a custom [loader][4]).\n\n## Install\n\nThis package is [ESM only][5].\n\n```sh\nyarn add -D @flex-development/toggle-pkg-type\n```\n\nFrom Git:\n\n```sh\nyarn add -D @flex-development/toggle-pkg-type@flex-development/toggle-pkg-type\n```\n\n\u003cblockquote\u003e\n  \u003csmall\u003e\n    See \u003ca href='https://yarnpkg.com/features/protocols#git'\u003eGit - Protocols | Yarn\u003c/a\u003e\n    \u0026nbsp;for details on requesting a specific branch, commit, or tag.\n  \u003c/small\u003e\n\u003c/blockquote\u003e\n\n## Use\n\n```sh\n  Usage\n    $ toggle-pkg-type [off|on] [options]\n\n  Options\n    -i, --id         Module id of package directory or manifest  (default process.env.npm_package_json)\n    -v, --version    Displays current version\n    -h, --help       Displays this message\n\n  Examples\n    $ toggle-pkg-type\n    $ toggle-pkg-type --id /path/to/manifest\n    $ toggle-pkg-type off\n    $ toggle-pkg-type on\n```\n\n## API\n\nThis package exports no identifiers. The default export is `toggle`.\n\n### `toggle([command][, id])`\n\nEnable or disable the [`type`][1] field in a `package.json` file.\n\nThe field is disabled by changing the field name to `#type`. The field value will not be modified.\n\nCommand Manifest:\n\n- `NIL` (`null`, `undefined`): Disable `type` if enabled, re-enable otherwise\n- `off`: Disable `type` field\n- `on`: Re-enable `type` field\n\nThis is a **no-op** under any of the following conditions:\n\n- A `package.json` file is not found\n- The `type` field is not defined in the located manifest\n- The `#type` field is not defined in the located manifest (i.e. the `type` field was not previously disabled)\n\n#### Parameters\n\n- `{Nilable\u003cCommand\u003e?}` **`[command=null]`** \u0026mdash; Toggle command\n- `{mlly.ModuleId?}` **`[id='.']`** \u0026mdash; Module id of package directory or manifest\n\n#### Returns\n\n`{void}` Nothing when complete.\n\n#### Source\n\n\u003e [`src/toggle.ts`](src/toggle.ts)\n\n## Types\n\nThis package is fully typed with [TypeScript][6].\n\n### Type Definitions\n\n- [`Command`](src/types/command.ts)\n\n## Contribute\n\nSee [`CONTRIBUTING.md`](CONTRIBUTING.md).\n\n[1]: https://nodejs.org/api/packages.html#type\n[2]: https://github.com/evanw/esbuild/issues/2026\n[3]: https://github.com/flex-development/aggregate-error-ponyfill/blob/main/package.json#L33-L42\n[4]: https://nodejs.org/api/esm.html#loaders\n[5]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n[6]: https://www.typescriptlang.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Ftoggle-pkg-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflex-development%2Ftoggle-pkg-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Ftoggle-pkg-type/lists"}