From 45a141a9d9f7b9d3e34445441550934833fbbace Mon Sep 17 00:00:00 2001 From: Cotton Hou Date: Thu, 8 Aug 2024 20:26:51 +0800 Subject: [PATCH] wip --- README.md | 1 + src/cli/help.ts | 2 ++ src/cli/parse.ts | 4 ++++ src/collect.ts | 2 ++ src/presets/index.ts | 22 ++++++++++++++++++---- tests/presets/index.test.ts | 16 ++++++++++++++++ 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1466795..6c2dd6b 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Input source is reading from `stdin`. ### Built-in Presets +- `--all` - `--lodash`: pkg naming starts by `lodash.` or equals to `lodash` - `--nolyfill`: list of names from https://github.com/SukkaW/nolyfill (**1.0.34**) - `--relief`: list of names from https://github.com/es-tooling/module-replacements (**2.3.2**) diff --git a/src/cli/help.ts b/src/cli/help.ts index 35635c7..ddaff2b 100644 --- a/src/cli/help.ts +++ b/src/cli/help.ts @@ -17,6 +17,8 @@ Usage: Builtin Presets: + --all + --lodash --nolyfill (via SukkaW/nolyfill v1.0.34) diff --git a/src/cli/parse.ts b/src/cli/parse.ts index 49acc20..d9af5b8 100644 --- a/src/cli/parse.ts +++ b/src/cli/parse.ts @@ -33,6 +33,10 @@ export function parse (args: Iterable): Flags { short: 'v', }, + all: { + type: 'boolean', + }, + // presets lodash: { diff --git a/src/collect.ts b/src/collect.ts index c48bf1e..12a6134 100644 --- a/src/collect.ts +++ b/src/collect.ts @@ -19,6 +19,8 @@ export interface Flags { invert?: boolean; + all?: boolean; + lodash?: boolean; nolyfill?: boolean; diff --git a/src/presets/index.ts b/src/presets/index.ts index 9871f35..2280d23 100644 --- a/src/presets/index.ts +++ b/src/presets/index.ts @@ -7,7 +7,7 @@ export { nolyfill }; import * as relief from './relief.ts'; export { relief }; -import type { Predicate } from '../common.ts'; +import { type Predicate, or } from '../common.ts'; @@ -17,6 +17,8 @@ export type Param = Partial>>; export type Toggle = + | 'all' + | 'lodash' | 'nolyfill' @@ -31,21 +33,33 @@ export type Toggle = +const on = (t: Toggle) => (p: Param) => p[t] === true; + +const on_all = on('all'); + +const all_OR_lodash = or(on_all, on('lodash')); +const all_OR_nolyfill = or(on_all, on('nolyfill')); +const all_OR_relief = or(on_all, on('relief')); + + + + + export function * gen_presets ( param: Param, ): Iterable> { - if (param.lodash === true) { + if (all_OR_lodash(param)) { yield lodash.check; } - if (param.nolyfill === true) { + if (all_OR_nolyfill(param)) { yield nolyfill.check; } - if (param.relief === true) { + if (all_OR_relief(param)) { yield * [ relief.native_check, diff --git a/tests/presets/index.test.ts b/tests/presets/index.test.ts index e98d522..55639ab 100644 --- a/tests/presets/index.test.ts +++ b/tests/presets/index.test.ts @@ -8,6 +8,8 @@ import { lookup, make_predicate } from '../../src/common.ts'; import { gen_presets, + lodash, + nolyfill, relief, } from '../../src/presets/index.ts'; @@ -20,6 +22,20 @@ describe('presets', function () { describe('gen_presets', function () { + it(`gens all`, function () { + + const presets = Array.from(gen_presets({ all: true })); + + asserts.assertEquals(presets, [ + lodash.check, + nolyfill.check, + relief.native_check, + relief.micro_check, + relief.preferred_check, + ]); + + }); + it(`gens all reliefs`, function () { const all = Array.of(