diff --git a/packages/core-js-builder/index.d.ts b/packages/core-js-builder/index.d.ts index 8bf70a6fecd1..00912b588082 100644 --- a/packages/core-js-builder/index.d.ts +++ b/packages/core-js-builder/index.d.ts @@ -1,40 +1,4 @@ -type StringOrRegExp = string | RegExp; - -type Modules = StringOrRegExp | readonly StringOrRegExp[]; - -type Target = - | 'android' - | 'bun' - | 'chrome' - | 'chrome-android' - | 'deno' - | 'edge' - | 'electron' - | 'firefox' - | 'firefox-android' - | 'hermes' - | 'ie' - | 'ios' - | 'node' - | 'opera' - | 'opera-android' - | 'phantom' - | 'quest' - | 'react-native' - | 'rhino' - | 'safari' - | 'samsung'; - -type BrowserslistQuery = string | ReadonlyArray; - -type Environments = { - [target in Target]?: string | number; -}; - -type Targets = Environments & { - browsers?: Environments | BrowserslistQuery, - esmodules?: boolean, -}; +import type compat from "core-js-compat"; type Format = 'bundle' | 'esm' | 'cjs'; @@ -50,13 +14,9 @@ type Summary = { console?: SummaryEntry, }; -type Options = { - /** entry / module / namespace / an array of them, by default - all `core-js` modules */ - modules?: Modules, - /** a blacklist, entry / module / namespace / an array of them, by default - empty list */ - exclude?: Modules, - /** optional browserslist or core-js-compat format query */ - targets?: Targets | BrowserslistQuery, +type CompatOptions = Exclude[0], undefined>; + +type Options = Pick & { /** output format, 'bundle' by default, can be 'cjs' or 'esm', and in this case * the result will not be bundled and will contain imports of required modules */ format?: Format, diff --git a/packages/core-js-compat/index.d.ts b/packages/core-js-compat/index.d.ts new file mode 100644 index 000000000000..1b66f051a207 --- /dev/null +++ b/packages/core-js-compat/index.d.ts @@ -0,0 +1,93 @@ +type StringOrRegExp = string | RegExp; + +type Modules = StringOrRegExp | readonly StringOrRegExp[]; + +type ModuleName = string; + +type Target = + | 'android' + | 'bun' + | 'chrome' + | 'chrome-android' + | 'deno' + | 'edge' + | 'electron' + | 'firefox' + | 'firefox-android' + | 'hermes' + | 'ie' + | 'ios' + | 'node' + | 'opera' + | 'opera-android' + | 'phantom' + | 'quest' + | 'react-native' + | 'rhino' + | 'safari' + | 'samsung'; + +type BrowserslistQuery = string | ReadonlyArray; + +type Environments = { + [target in Target]?: string | number; +}; + +type Targets = Environments & { + browsers?: Environments | BrowserslistQuery, + esmodules?: boolean, +}; + +type Options = { + /** entry / module / namespace / an array of them, by default - all `core-js` modules */ + modules?: Modules, + /** a blacklist, entry / module / namespace / an array of them, by default - empty list */ + exclude?: Modules, + /** optional browserslist or core-js-compat format query */ + targets?: Targets | BrowserslistQuery, + /** used `core-js` version, by default the latest */ + version?: string, + /** inverse of the result, shows modules that are NOT required for the target environment */ + inverse?: boolean, + /** + * @deprecated use `modules` instead + */ + filter?: Modules +}; + +type TargetVersion = string; + +type Output = { + /** array of required modules */ + list: ModuleName[], + /** object with targets for each module */ + targets: { + [module: ModuleName]: { + [target in Target]?: TargetVersion + } + } +} + +type CompatData = { + [module: ModuleName]: { + [target in Target]?: TargetVersion + } +}; + +declare const ExportedCompatObject: { + compat(options?: Options): Output, + + /** The subset of modules which available in the passed `core-js` version */ + getModulesListForTargetVersion(version: string): readonly ModuleName[], + + /** Full list compatibility data */ + data: CompatData, + + /** map of modules by `core-js` entry points */ + entries: {[entry_point: string]: readonly ModuleName[]}, + + /** Full list of modules */ + modules: readonly ModuleName[] +} + +export = ExportedCompatObject diff --git a/packages/core-js-compat/package.json b/packages/core-js-compat/package.json index 4a4ea247974a..2604bb79dc0d 100644 --- a/packages/core-js-compat/package.json +++ b/packages/core-js-compat/package.json @@ -19,6 +19,7 @@ }, "sideEffects": false, "main": "index.js", + "types": "index.d.ts", "dependencies": { "browserslist": "^4.21.5" }