Skip to content

Commit ff573d2

Browse files
committed
Types for configurator
1 parent 9cd4bb3 commit ff573d2

File tree

10 files changed

+37
-28
lines changed

10 files changed

+37
-28
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare namespace CoreJS {
2+
export function Configurator(options: Record<PropertyKey, any>): void;
3+
}

packages/core-js-types/src/base/configurator.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/build-entries-and-types/build-types.mjs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { features, proposals } from './entries-definitions.mjs';
2-
import { $namespace, $path, $proposal, $typeDummy } from './templates.mjs';
2+
import { $functionWithCustomType, $path, $proposal, $typeDummy } from './templates.mjs';
33
import { modules as AllModules } from '@core-js/compat/src/data.mjs';
44
import { getModulesMetadata } from './get-dependencies.mjs';
55
import { expandModules, modulesToStage } from './helpers.mjs';
@@ -42,7 +42,9 @@ function addType(tsVersion, subset, template, options) {
4242

4343
function addEntryTypes(tsVersion, template, options) {
4444
addType(tsVersion, 'index', template, { ...options, packageName: PACKAGE_NAME });
45-
addType(tsVersion, 'pure', template, { ...options, packageName: PACKAGE_NAME_PURE, prefix: TYPE_PREFIX });
45+
if (!options.noPure) {
46+
addType(tsVersion, 'pure', template, { ...options, packageName: PACKAGE_NAME_PURE, prefix: TYPE_PREFIX });
47+
}
4648
if (options.exportForSubset) {
4749
addType(tsVersion, options.subset, template, { ...options, packageName: PACKAGE_NAME });
4850
}
@@ -54,6 +56,7 @@ async function buildType(entry, options) {
5456
subset = entryFromNamespace ?? 'full',
5557
typeDummy = false,
5658
globalType = true,
59+
noPure = false,
5760
template, templateStable, templateActual, templateFull, filter, modules, enforceEntryCreation,
5861
customType, tsVersion, proposal, types, ownEntryPoint,
5962
} = options;
@@ -84,10 +87,13 @@ async function buildType(entry, options) {
8487
const level = entry.split('/').length - 1;
8588

8689
if (!types) {
87-
if (!enforceEntryCreation && !expandModules(modules[0], filter, AllModules).length) return;
88-
modules = expandModules(modules, filter, AllModules);
89-
const { types: typePaths } = await getModulesMetadata(modules);
90-
types = typePaths;
90+
types = [];
91+
if (!customType) {
92+
if (!enforceEntryCreation && !expandModules(modules[0], filter, AllModules).length) return;
93+
modules = expandModules(modules, filter, AllModules);
94+
const { types: typePaths } = await getModulesMetadata(modules);
95+
types = typePaths;
96+
}
9197
}
9298

9399
if (typesFilter) {
@@ -99,17 +105,17 @@ async function buildType(entry, options) {
99105
imports.index.add(type);
100106
imports[subset].add(type);
101107
}
102-
imports.pure.add(path.join('pure', type));
108+
if (!noPure) imports.pure.add(path.join('pure', type));
103109
});
104110

105111
if (customType) {
106112
if (globalType) {
107113
imports.index.add(customType);
108114
imports[subset].add(customType);
109115
}
110-
imports.pure.add(path.join('pure', customType));
116+
if (!noPure) imports.pure.add(path.join('pure', customType));
111117
}
112-
options = { ...options, modules, level, entry, types, subset };
118+
options = { ...options, modules, level, entry, types, subset, noPure };
113119

114120
addEntryTypes(tsVersion, template, options);
115121
if (!entry.endsWith('/')) { // add alias with .js ending
@@ -231,13 +237,14 @@ async function buildTypesForTSVersion(tsVersion) {
231237
await buildType('index', { template: $path, modules: ActualModules, tsVersion });
232238

233239
await buildType('configurator', {
240+
customType: 'configurator-custom',
234241
entryFromNamespace: 'configurator',
235-
template: $namespace,
242+
template: $functionWithCustomType,
236243
modules: ['configurator'],
237244
name: 'configurator',
238245
tsVersion,
239-
types: ['configurator'],
240246
exportForSubset: true,
247+
noPure: true,
241248
});
242249

243250
await prependImports(tsVersion);

scripts/build-entries-and-types/templates.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,13 @@ export const $typeDummy = p => ({
492492
}
493493
`,
494494
});
495+
496+
export const $functionWithCustomType = p => ({
497+
entry: '',
498+
types: dedent`
499+
declare module '${ buildModulePath(p) }' {
500+
const resultFunction: typeof ${ buildCoreJSTypeName('', p.name) };
501+
export = resultFunction;
502+
}
503+
`,
504+
});

tests/type-definitions/entries/configurator/import/configurator.ts renamed to tests/type-definitions/entries/configurator/entries.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import '@core-js/types/configurator';
2+
import configurator from 'core-js/configurator';
23

34
configurator({ something: 'value' });

tests/type-definitions/entries/configurator/global/configurator.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/type-definitions/entries/configurator/global/tsconfig.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/type-definitions/entries/configurator/import/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["./entries.ts"]
4+
}

tests/type-definitions/runner.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ tasks.push(
166166
{ args: ['-p', 'typescript@5.9', 'tsc', '-p', 'entries/proposals/tsconfig.json'] },
167167
{ args: ['-p', 'typescript@5.9', 'tsc', '-p', 'entries/global/tsconfig.json'] },
168168
{ args: ['-p', 'typescript@5.9', 'tsc', '-p', 'entries/pure/tsconfig.json'] },
169-
{ args: ['-p', 'typescript@5.9', 'tsc', '-p', 'entries/configurator/global/tsconfig.json'] },
170-
{ args: ['-p', 'typescript@5.9', 'tsc', '-p', 'entries/configurator/import/tsconfig.json'] },
169+
{ args: ['-p', 'typescript@5.9', 'tsc', '-p', 'entries/configurator/tsconfig.json'] },
171170
);
172171

173172
let envs;

0 commit comments

Comments
 (0)