Skip to content

Commit 9d7eebd

Browse files
committed
Added proposal type entry-points & tests
1 parent f6447d2 commit 9d7eebd

File tree

10 files changed

+65
-22
lines changed

10 files changed

+65
-22
lines changed

packages/core-js-types/package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,39 @@
3737
"exports": {
3838
".": {
3939
"types@>=5.6": "./dist/56/actual.d.ts",
40-
"types": "./dist/56/actual.d.ts",
40+
"types": "./dist/52/actual.d.ts",
4141
"default": "./dist/56/actual.d.ts"
4242
},
4343
"./actual": {
4444
"types@>=5.6": "./dist/56/actual.d.ts",
45-
"types": "./dist/56/actual.d.ts",
45+
"types": "./dist/52/actual.d.ts",
4646
"default": "./dist/56/actual.d.ts"
4747
},
4848
"./es": {
4949
"types@>=5.6": "./dist/56/es.d.ts",
50-
"types": "./dist/56/es.d.ts",
50+
"types": "./dist/52/es.d.ts",
5151
"default": "./dist/56/es.d.ts"
5252
},
5353
"./full": {
5454
"types@>=5.6": "./dist/56/full.d.ts",
55-
"types": "./dist/56/full.d.ts",
55+
"types": "./dist/52/full.d.ts",
5656
"default": "./dist/56/full.d.ts"
5757
},
5858
"./pure": {
5959
"types@>=5.6": "./dist/56/pure.d.ts",
60-
"types": "./dist/56/pure.d.ts",
60+
"types": "./dist/52/pure.d.ts",
6161
"default": "./dist/56/pure.d.ts"
6262

6363
},
6464
"./stable": {
6565
"types@>=5.6": "./dist/56/stable.d.ts",
66-
"types": "./dist/56/stable.d.ts",
66+
"types": "./dist/52/stable.d.ts",
6767
"default": "./dist/56/stable.d.ts"
68+
},
69+
"./proposals/*": {
70+
"types@>=5.6": "./dist/56/proposals/*.d.ts",
71+
"types": "./dist/52/proposals/*.d.ts",
72+
"default": "./dist/56/proposals/*.d.ts"
6873
}
6974
},
7075
"sideEffects": false

scripts/build-types/index.mjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function buildType(entry, options) {
2323
entryFromNamespace,
2424
subset = entryFromNamespace ?? 'full',
2525
template, templateStable, templateActual, templateFull, filter, modules, enforceEntryCreation,
26-
customType, tsVersion,
26+
customType, tsVersion, proposal,
2727
} = options;
2828

2929
switch (subset) {
@@ -75,6 +75,12 @@ async function buildType(entry, options) {
7575

7676
await outputFile(filePath, `${ tpl.dts }${ tpl.dts ? '\n\n' : '' }`, { flag: 'a' });
7777
await outputFile(filePathPure, `${ tplPure.dts }${ tplPure.dts ? '\n\n' : '' }`, { flag: 'a' });
78+
79+
if (proposal) {
80+
const filePathProposal = buildFilePath(tsVersion, entry);
81+
const proposalImports = buildImports(types, 1);
82+
await outputFile(filePathProposal, `${ proposalImports }\n`, { flag: 'a' });
83+
}
7884
}
7985

8086
async function getVersions() {
@@ -110,10 +116,14 @@ function buildFilePath(tsVersion, subset) {
110116
return path.join(config.buildDir, tsVersion.toString(), `${ subset }.d.ts`);
111117
}
112118

119+
function buildImports(importsList, level = 0) {
120+
return Array.from(importsList, it => `/// <reference types="./${ '../'.repeat(level) }types/${ it }.d.ts" />`).join('\n')
121+
}
122+
113123
async function prependImports(version) {
114124
for (const subset of Object.keys(imports)) {
115125
const filePath = buildFilePath(version, subset);
116-
const importLines = Array.from(imports[subset], it => `/// <reference types="./types/${ it }.d.ts" />`).join('\n');
126+
const importLines = buildImports(imports[subset]);
117127
const originalContent = await fs.readFile(filePath, 'utf8');
118128
await outputFile(filePath, `${ importLines }\n\n${ originalContent }`);
119129
}
@@ -133,7 +143,7 @@ async function buildTypesForTSVersion(tsVersion) {
133143
}
134144

135145
for (const [name, definition] of Object.entries(proposals)) {
136-
await buildType(`proposals/${ name }`, { ...definition, template: $proposal, tsVersion });
146+
await buildType(`proposals/${ name }`, { ...definition, template: $proposal, tsVersion, proposal: true });
137147
}
138148

139149
await buildType('es/index', { template: $path, modules: ESModules, subset: 'es', tsVersion });

tests/type-definitions/entries.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import '@core-js/types/stable';
2+
Iterator.concat([]);
3+
// @ts-expect-error
4+
Iterator.zipKeyed([]);
5+
6+
import '@core-js/types/proposals/array-unique';
7+
const uniqueArr: number[] = [1, 2, 2, 3, 3, 3].uniqueBy();

tests/type-definitions/runner.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ const prepareEnvironment = async function (environments, coreJsTypes) {
113113
};
114114

115115
await $`npx -p [email protected] tsc`;
116-
await $`npx -p [email protected] -p @types/node@24 tsc -p tsconfig.require.json`;
116+
await $`npx -p [email protected] tsc -p tsconfig.templates.import.json`;
117+
await $`npx -p [email protected] tsc -p tsconfig.entries.json`;
118+
await $`npx -p [email protected] -p @types/node@24 tsc -p tsconfig.templates.require.json`;
119+
117120
const numCPUs = os.cpus().length;
118121
await prepareEnvironment(envs, types);
119122
await runLimited(taskConfigs, Math.max(numCPUs - 1, 1));
File renamed without changes.
File renamed without changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"target": "esnext",
5+
"module": "esnext",
6+
"esModuleInterop": true,
7+
"moduleResolution": "node",
8+
"noEmit": true
9+
},
10+
"include": [
11+
"./entries.ts"
12+
]
13+
}

tests/type-definitions/tsconfig.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@
55
"module": "esnext",
66
"esModuleInterop": true,
77
"moduleResolution": "node",
8-
"noEmit": true,
9-
"types": [
10-
"@core-js/types/pure"
11-
]
8+
"noEmit": true
129
},
1310
"include": [
14-
"./*.ts"
15-
],
16-
"exclude": [
17-
"./entries.require.ts"
11+
"./builder.ts",
12+
"./compat.ts"
1813
]
1914
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"types": [
5+
"@core-js/types/pure"
6+
]
7+
},
8+
"include": [
9+
"./templates.import.ts"
10+
]
11+
}

tests/type-definitions/tsconfig.require.json renamed to tests/type-definitions/tsconfig.templates.require.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"types": [
5-
"@core-js/types",
5+
"@core-js/types/pure",
66
"@types/node"
77
]
88
},
99
"include": [
10-
"./entries.require.ts"
11-
],
12-
"exclude": []
10+
"./templates.require.ts"
11+
]
1312
}

0 commit comments

Comments
 (0)