Skip to content

Commit

Permalink
feat: use tuple as arg value type
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwa committed Jul 18, 2021
1 parent ebf1b14 commit 6b999d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/esw/src/shared/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { tuple } from './utils'

export enum ProcessCode {
OK,
ERROR
Expand All @@ -16,18 +18,18 @@ export const BUILD_ARGS_SPEC = {
},
'--chunkNames': String,
'--color': Boolean,
'--conditions': [String] as [typeof String],
'--conditions': tuple([String]),
// '--define'
'--entryNames': String,
'--entryPoints': [String] as [typeof String],
'--external': [String] as [typeof String],
'--entryPoints': tuple([String]),
'--external': tuple([String]),
// '--footer'
'--format': function (val: string) {
return ['cjs', 'esm', 'iife'].includes(val) ? val : null
},
'--globalName': String,
'--incremental': Boolean,
'--inject': [String] as [typeof String],
'--inject': tuple([String]),
'--jsx': function (val: string) {
return ['transform', 'preserve'].includes(val) ? val : null
},
Expand All @@ -48,13 +50,13 @@ export const BUILD_ARGS_SPEC = {
: null
},
'--logLimit': Number,
'--mainFields': [String] as [typeof String],
'--mainFields': tuple([String]),
'--metafile': Boolean,
'--minify': Boolean,
'--minifyIdentifiers': Boolean,
'--minifySyntax': Boolean,
'--minifyWhitespace': Boolean,
'--nodePaths': [String] as [typeof String],
'--nodePaths': tuple([String]),
// '--outExtension'
'--outbase': String,
'--outdir': String,
Expand All @@ -64,16 +66,16 @@ export const BUILD_ARGS_SPEC = {
// '--plugins'
'--preserveSymlinks': Boolean,
'--publicPath': String,
'--pure': [String] as [typeof String],
'--resolveExtensions': [String] as [typeof String],
'--pure': tuple([String]),
'--resolveExtensions': tuple([String]),
'--sourceRoot': String,
'--sourcemap': function (val: string) {
return ['true', 'false'].includes(val) ? val === 'true' : val
},
'--sourcesContent': Boolean,
'--splitting': Boolean,
// '--stdin'
'--target': [String] as [typeof String],
'--target': tuple([String]),
'--treeShaking': function (val: string) {
return val === 'true' || (val === 'ignore-annotations' ? val : null)
},
Expand Down
5 changes: 5 additions & 0 deletions packages/esw/src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export function isDef<V>(value: V): value is NonNullable<V> {
return value !== null && value !== void 0
}

// https://github.com/microsoft/TypeScript/pull/39094#Spreads_in_array_literals
export function tuple<T extends unknown[]>(args: [...T]) {
return args
}

0 comments on commit 6b999d5

Please sign in to comment.