Skip to content

Commit

Permalink
fix: add node 16 to valid types and be more strict about version in e…
Browse files Browse the repository at this point in the history
…sbuild types (#1161)
  • Loading branch information
danez committed Jul 29, 2022
1 parent ab6e35e commit 5a364ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/runtimes/node/bundlers/esbuild/bundler_target.ts
@@ -1,6 +1,11 @@
import { FeatureFlags } from '../../../../feature_flags'
import { ModuleFormat } from '../../utils/module_format'
import { DEFAULT_NODE_VERSION, getNodeSupportMatrix } from '../../utils/node_version'
import {
DEFAULT_NODE_VERSION,
getNodeSupportMatrix,
NodeVersionString,
ShortNodeVersionString,
} from '../../utils/node_version'
import { getClosestPackageJson } from '../../utils/package_json'

const versionMap = {
Expand All @@ -11,14 +16,13 @@ const versionMap = {
'16.x': 'node16',
} as const

type VersionKeys = keyof typeof versionMap
type VersionValues = typeof versionMap[VersionKeys]
type VersionValues = typeof versionMap[keyof typeof versionMap]

const getBundlerTarget = (suppliedVersion?: string): VersionValues => {
const getBundlerTarget = (suppliedVersion?: NodeVersionString): VersionValues => {
const version = normalizeVersion(suppliedVersion)

if (version && version in versionMap) {
return versionMap[version as VersionKeys]
return versionMap[version]
}

return versionMap[`${DEFAULT_NODE_VERSION}.x`]
Expand All @@ -45,10 +49,10 @@ const getModuleFormat = async (
}
}

const normalizeVersion = (version?: string) => {
const match = version && version.match(/^nodejs(.*)$/)
const normalizeVersion = (version?: NodeVersionString): ShortNodeVersionString | undefined => {
const match = version && (version.match(/^nodejs(.*)$/) as [string, ShortNodeVersionString])

return match ? match[1] : version
return match ? match[1] : (version as ShortNodeVersionString)
}

export { getBundlerTarget, getModuleFormat }
5 changes: 3 additions & 2 deletions src/runtimes/node/utils/node_version.ts
@@ -1,6 +1,7 @@
/* eslint-disable no-magic-numbers */
type SupportedVersionNumbers = 8 | 10 | 12 | 14
export type NodeVersionString = `${SupportedVersionNumbers}.x` | `nodejs${SupportedVersionNumbers}.x`
type SupportedVersionNumbers = 8 | 10 | 12 | 14 | 16
export type ShortNodeVersionString = `${SupportedVersionNumbers}.x`
export type NodeVersionString = ShortNodeVersionString | `nodejs${SupportedVersionNumbers}.x`

export interface NodeVersionSupport {
esm: boolean
Expand Down

1 comment on commit 5a364ba

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 6.2s

largeDepsNft: 30.1s

largeDepsZisi: 44.8s

Please sign in to comment.