Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

fix: add node 16 to valid types and be more strict about version in esbuild types #1161

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/runtimes/node/bundlers/esbuild/bundler_target.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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