@balena/es-version

中文文档
1.0.4发布于 2026/02/19Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 12.7万

This module provides the ability to specify the default es version to include for balena modules.

原始使用文档

@balena/es-version

This module allows specifying a target es version for other modules to require, currently supported target versions:

  • es3 (default)
  • es5
  • es2015
  • es2016
  • es2017
  • es2018
  • es2019
  • es2020
  • es2021
  • es2022
  • esnext

Usage as a client

  1. Add @balena/es-version to your package.json with a ^ version specifier, eg
"@balena/es-version": "^1.0.0",

Note: If using locked dependences, eg package-lock.json/npm-shrinkwrap.json/etc, then make sure to also dedupe the module so that the same instance of the module is used everywhere.

  1. Within your module require it before anything else and set the desired version:
// Must be set before the first require of an @balena/es-version supporting module
require('@balena/es-version').set('es5');

and then the closest matching version will be used by any module that supports choosing the target version, with the priority being:

  1. exact match
  2. closest match under the desired version
  3. lowest supported version

Usage as a module provider

  1. Add @balena/es-version to your package.json with a ^ version specifier, eg
"@balena/es-version": "^1.0.0",
  1. Generate builds for the es versions you wish to support along with types for the shim you'll create, eg
"build-es5": "tsc --target es5 --outDir es5",
"build-es2015": "tsc --target es2015 --outDir es2015",
"build-es2018": "tsc --target es2018 --outDir es2018",
"build-types": "tsc --emitDeclarationOnly --outDir .",
"build": "npm run build-es5 && npm run build-es2015 && npm run build-es2018 && npm run build-types",
  1. Create a shim to use as your entry-point which loads the desired version, eg
// First get the es version to use:
var esVersion = require('@balena/es-version').get(['es5', 'es2015', 'es2018');
// Then include/return the correct version of your module, eg
module.exports = module.exports = require('./' + esVersion);

Note: This must be compatible with your lowest supported es version

  1. Point your package.json to the new shim and types, eg
"main": "index.js",
"types": "index.d.ts",
  1. It is also recommended to add a "browser" entry to a fixed es version in your package.json in order to support browser bundlers with default config, eg
"browser": "es5"

版本与发布记录

@balena/es-version 共发布 16 个版本,首次发布于 2020/05/26;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.4latest2026/02/198 个月前
1.0.4-build-add-npm-oidc-permissions-c6d7520512a1f915297e8208d53aa4905f690126-1build-add-npm-oidc-permissions2026/02/198 个月前
1.0.32023/09/063 年前
1.0.3-build-es2023-db4a7d2af00194a422431a73e3d57c2f5bd5382e-12023/09/063 年前
1.0.22022/10/314 年前
1.0.2-es-2022-fa3275fbb963e1d6708a20bb9e9ff3de3aae78e7-12022/10/314 年前

关于 @balena/es-version 的常见问题

@balena/es-version 是什么?

This module provides the ability to specify the default es version to include for balena modules.

如何安装 @balena/es-version?

在项目目录运行 npm install @balena/es-version,或使用 pnpm add / yarn add / bun add。

@balena/es-version 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@balena/es-version 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@balena/es-version 可以商用吗?

@balena/es-version 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@balena/es-version 的下载量有多少?

根据 npm 官方下载统计,@balena/es-version 在 2026/10/08 – 2026/11/06 这 30 天内被下载 127,488 次,日均约 4,250 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@balena/es-version 还在维护吗?

最新版本 1.0.4 发布于 2026/02/19(8 个月前);至今共发布 16 个版本,其中过去 12 个月发布了 2 个;首次发布于 2020/05/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。