-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1163 from zloirock/ts-definitions
- Loading branch information
Showing
9 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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<string>; | ||
|
||
type Environments = { | ||
[target in Target]?: string | number; | ||
}; | ||
|
||
type Targets = Environments & { | ||
browsers?: Environments | BrowserslistQuery, | ||
esmodules?: boolean, | ||
}; | ||
|
||
type Format = 'bundle' | 'esm' | 'cjs'; | ||
|
||
type SummaryEntry = boolean | { | ||
size?: boolean, | ||
modules?: boolean, | ||
}; | ||
|
||
type Summary = { | ||
/** in the console, you could specify required parts or set `true` for enable all of them */ | ||
comment?: SummaryEntry, | ||
/** in the comment, you could specify required parts or set `true` for enable all of them */ | ||
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, | ||
/** 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, | ||
/** optional target filename, if it's missed a file will not be created */ | ||
filename?: string, | ||
/** shows summary for the bundle, disabled by default */ | ||
summary?: Summary, | ||
}; | ||
|
||
declare function builder(options?: Options): Promise<string>; | ||
|
||
export = builder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import builder from 'core-js-builder'; | ||
|
||
const a: Promise<string> = builder({ targets: { node: 17 } }); | ||
const b: string = await builder({ targets: { node: 17 } }); | ||
|
||
await builder(); | ||
await builder({}); | ||
await builder({ modules: 'core-js/actual' }); | ||
await builder({ modules: 'es.array.push' }); | ||
await builder({ modules: /^es\.array\./ }); | ||
await builder({ modules: ['core-js/actual', /^es\.array\./] }); | ||
await builder({ exclude: 'core-js/actual' }); | ||
await builder({ exclude: 'es.array.push' }); | ||
await builder({ exclude: /^es\.array\./ }); | ||
await builder({ exclude: ['core-js/actual', /^es\.array\./] }); | ||
await builder({ modules: 'core-js/actual', exclude: /^es\.array\./ }); | ||
await builder({ targets: '> 1%' }); | ||
await builder({ targets: ['defaults', 'last 5 versions'] }); | ||
await builder({ targets: { esmodules: true, node: 'current', browsers: ['> 1%'] } }); | ||
await builder({ targets: { chrome: '26', firefox: 4 } }); | ||
await builder({ targets: { browsers: { chrome: '26', firefox: 4 } } }); | ||
await builder({ targets: { chrome: '26', firefox: 4, esmodules: true, node: 'current', browsers: ['> 1%'] } }); | ||
await builder({ format: 'bundle' }); | ||
await builder({ format: 'esm' }); | ||
await builder({ format: 'cjs' }); | ||
await builder({ filename: '/foo/bar/baz.js' }); | ||
await builder({ summary: { comment: true } }); | ||
await builder({ summary: { comment: { size: true } } }); | ||
await builder({ summary: { comment: { size: false, modules: true } } }); | ||
await builder({ summary: { console: true } }); | ||
await builder({ summary: { console: { size: true } } }); | ||
await builder({ summary: { console: { size: false, modules: true } } }); | ||
await builder({ summary: { console: { size: false, modules: true }, comment: { size: false, modules: true } } }); | ||
await builder({ | ||
modules: 'core-js/actual', | ||
exclude: /^es\.array\./, | ||
targets: { | ||
android: 1, | ||
bun: '1', | ||
chrome: 1, | ||
'chrome-android': '1', | ||
deno: 1, | ||
edge: '1', | ||
electron: 1, | ||
firefox: '1', | ||
'firefox-android': 1, | ||
hermes: '1', | ||
ie: 1, | ||
ios: '1', | ||
opera: 1, | ||
'opera-android': '1', | ||
phantom: 1, | ||
quest: '1', | ||
'react-native': 1, | ||
rhino: '1', | ||
safari: 1, | ||
samsung: '1', | ||
node: 'current', | ||
esmodules: true, | ||
browsers: ['> 1%'], | ||
}, | ||
format: 'bundle', | ||
filename: '/foo/bar/baz.js', | ||
summary: { | ||
console: { size: false, modules: true }, | ||
comment: { size: false, modules: true }, | ||
}, | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "tests/type-definitions", | ||
"devDependencies": { | ||
"typescript": "^4.9.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
await $`tsc`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"target": "esnext", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"noEmit": true | ||
}, | ||
"include": [ | ||
"*.ts" | ||
] | ||
} |