Skip to content

Commit 070c719

Browse files
committed
Add index.d.ts & rebuild all type entry points & move test-type-definitions to test-raw command
1 parent 3e569d3 commit 070c719

File tree

9 files changed

+37
-36
lines changed

9 files changed

+37
-36
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"debug-get-dependencies": "npm run zxi time tests/debug-get-dependencies/debug-get-dependencies.mjs",
4141
"lint": "run-s prepare lint-raw",
4242
"lint-raw": "run-s build-types test-eslint bundle-package test-publint",
43-
"test": "run-s prepare test-raw test-type-definitions",
44-
"test-raw": "run-s lint-raw bundle-tests test-unit test-promises test-entries test-compat-data test-compat-tools test-builder test-babel-plugin check",
43+
"test": "run-s prepare test-raw",
44+
"test-raw": "run-s lint-raw test-type-definitions bundle-tests test-unit test-promises test-entries test-compat-data test-compat-tools test-builder test-babel-plugin check",
4545
"test-eslint": "npm run zxi time tests/eslint/runner.mjs",
4646
"test-publint": "npm run zxi time tests/publint/runner.mjs",
4747
"test-unit": "run-s test-unit-karma test-unit-node test-unit-bun",

packages/core-js-types/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"email": "zloirock@zloirock.ru",
2626
"url": "http://zloirock.ru"
2727
},
28-
"types": "./actual.d.ts",
28+
"types": "./index.d.ts",
2929
"sideEffects": false,
3030
"typesVersions": {
3131
">=5.6": {
@@ -41,9 +41,9 @@
4141
},
4242
"exports": {
4343
".": {
44-
"types@>=5.6": "./dist/ts5-6/actual.d.ts",
45-
"types": "./dist/ts5-2/actual.d.ts",
46-
"default": "./dist/ts5-6/actual.d.ts"
44+
"types@>=5.6": "./dist/ts5-6/index.d.ts",
45+
"types": "./dist/ts5-2/index.d.ts",
46+
"default": "./dist/ts5-6/index.d.ts"
4747
},
4848
"./actual": {
4949
"types@>=5.6": "./dist/ts5-6/actual.d.ts",

scripts/build-types/index.mjs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const imports = {
2525
actual: new Set(),
2626
full: new Set(),
2727
pure: new Set(),
28+
index: new Set(),
2829
};
2930

3031
async function buildType(entry, options) {
@@ -68,22 +69,24 @@ async function buildType(entry, options) {
6869
if (filter) modules = modules.filter(it => filter.has(it));
6970

7071
types.forEach(type => {
72+
imports.index.add(type);
7173
imports[subset].add(type);
7274
imports.pure.add(path.join('pure', type));
7375
});
7476
if (customType) {
77+
imports.index.add(customType);
7578
imports[subset].add(customType);
7679
imports.pure.add(customType);
7780
}
7881

79-
const filePath = buildFilePath(tsVersion, subset);
80-
const filePathPure = buildFilePath(tsVersion, 'pure');
82+
const indexPath = buildFilePath(tsVersion, 'index');
83+
const purePath = buildFilePath(tsVersion, 'pure');
8184

8285
const tplPure = template({ ...options, modules, rawModules, level, entry, types, packageName: PACKAGE_NAME_PURE, prefix: TYPE_PREFIX });
8386
const tpl = template({ ...options, modules, rawModules, level, entry, types, packageName: PACKAGE_NAME });
8487

85-
await outputFile(filePathPure, `${ tplPure.dts }${ tplPure.dts ? '\n\n' : '' }`, { flag: 'a' });
86-
await outputFile(filePath, `${ tpl.dts }${ tpl.dts ? '\n\n' : '' }`, { flag: 'a' });
88+
await outputFile(indexPath, `${ tpl.dts }${ tpl.dts ? '\n\n' : '' }`, { flag: 'a' });
89+
await outputFile(purePath, `${ tplPure.dts }${ tplPure.dts ? '\n\n' : '' }`, { flag: 'a' });
8790

8891
if (!entry.endsWith('/')) {
8992
const entryWithExt = `${ entry }.js`;
@@ -92,19 +95,19 @@ async function buildType(entry, options) {
9295
const tplWithExt = template({ ...options, modules, rawModules, level, types, entry: entryWithExt,
9396
packageName: PACKAGE_NAME });
9497

95-
await outputFile(filePathPure, `${ tplPureWithExt.dts }${ tplPureWithExt.dts ? '\n\n' : '' }`, { flag: 'a' });
96-
await outputFile(filePath, `${ tplWithExt.dts }${ tplWithExt.dts ? '\n\n' : '' }`, { flag: 'a' });
98+
await outputFile(indexPath, `${ tplWithExt.dts }${ tplWithExt.dts ? '\n\n' : '' }`, { flag: 'a' });
99+
await outputFile(purePath, `${ tplPureWithExt.dts }${ tplPureWithExt.dts ? '\n\n' : '' }`, { flag: 'a' });
97100
}
98101

99102
if (entry.endsWith('/index')) {
100-
const entryWithoutIndex = entry.replace(/index$/, '');
103+
const entryWithoutIndex = entry.replace(/\/index$/, '');
101104
const tplPureWithoutIndex = template({ ...options, modules, rawModules, level, entry: entryWithoutIndex, types,
102105
packageName: PACKAGE_NAME_PURE, prefix: TYPE_PREFIX });
103106
const tplWithoutIndex = template({ ...options, modules, rawModules, level, types, entry: entryWithoutIndex,
104107
packageName: PACKAGE_NAME });
105108

106-
await outputFile(filePathPure, `${ tplPureWithoutIndex.dts }${ tplPureWithoutIndex.dts ? '\n\n' : '' }`, { flag: 'a' });
107-
await outputFile(filePath, `${ tplWithoutIndex.dts }${ tplWithoutIndex.dts ? '\n\n' : '' }`, { flag: 'a' });
109+
await outputFile(indexPath, `${ tplWithoutIndex.dts }${ tplWithoutIndex.dts ? '\n\n' : '' }`, { flag: 'a' });
110+
await outputFile(purePath, `${ tplPureWithoutIndex.dts }${ tplPureWithoutIndex.dts ? '\n\n' : '' }`, { flag: 'a' });
108111
}
109112

110113
if (proposal) {
@@ -136,8 +139,11 @@ async function prependImports(version) {
136139
for (const subset of Object.keys(imports)) {
137140
const filePath = buildFilePath(version, subset);
138141
const importLines = buildImports(imports[subset]);
139-
const originalContent = await fs.readFile(filePath, 'utf8');
140-
await outputFile(filePath, `${ importLines }\n\n${ originalContent }`);
142+
let originalContent = '';
143+
if (await pathExists(filePath)) {
144+
originalContent = await fs.readFile(filePath, 'utf8');
145+
}
146+
await outputFile(filePath, `${ importLines }\n\n${ originalContent }`, { flag: 'w' });
141147
}
142148
}
143149

@@ -200,17 +206,14 @@ async function buildPackageJson(breakpoints, namespaces) {
200206
});
201207
packageJson.exports = {};
202208
Object.entries(namespaces).forEach(([namespace, options]) => {
203-
const namespaceKey = namespace ? `./${ namespace }${ options.isDir ? '/*' : '' }` : '.';
209+
const namespaceKey = namespace !== 'index' ? `./${ namespace }${ options.isDir ? '/*' : '' }` : '.';
204210
packageJson.exports[namespaceKey] = {};
205211
breakpoints.forEach((breakpoint, index) => {
206212
const isLast = index === breakpoints.length - 1;
207213
const breakpointString = `ts${ breakpoint.toString().replace('.', '-') }`;
208214
packageJson.exports[namespaceKey][`types${ isLast ? '' : `@>=${ breakpoint }` }`] = `./dist/${ breakpointString }/${ namespace }${ options.isDir ? '/*' : '' }.d.ts`;
209215
});
210216
packageJson.exports[namespaceKey].default = `./dist/ts${ defaultBreakpoint.toString().replace('.', '-') }/${ namespace }${ options.isDir ? '/*' : '' }.d.ts`;
211-
if (options.default) {
212-
packageJson.exports['.'] = packageJson.exports[namespaceKey];
213-
}
214217
});
215218
const exportsKeys = Object.keys(packageJson.exports).sort();
216219
const exports = {};
@@ -228,12 +231,13 @@ if (VERSION) {
228231
await remove(BUILD_DIR);
229232
tsVersionBreakpoints.forEach(async version => await buildTypesForTSVersion(version));
230233
const namespaces = {
231-
es: { isDir: false, default: false },
232-
stable: { isDir: false, default: false },
233-
actual: { isDir: false, default: true },
234-
full: { isDir: false, default: false },
235-
pure: { isDir: false, default: false },
236-
proposals: { isDir: true, default: false },
234+
es: { isDir: false },
235+
stable: { isDir: false },
236+
actual: { isDir: false },
237+
full: { isDir: false },
238+
pure: { isDir: false },
239+
proposals: { isDir: true },
240+
index: { isDir: false },
237241
};
238242
await buildPackageJson(tsVersionBreakpoints, namespaces);
239243
}

scripts/build-types/package.tpl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"email": "zloirock@zloirock.ru",
2626
"url": "http://zloirock.ru"
2727
},
28-
"types": "./actual.d.ts",
28+
"types": "./index.d.ts",
2929
"sideEffects": false
3030
}

tests/type-definitions/entries.pure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ new $date();
44
import $date2 from '@core-js/pure/full/date/index.js';
55
new $date2();
66

7-
import $date3 from '@core-js/pure/full/date/';
7+
import $date3 from '@core-js/pure/full/date';
88
new $date3();

tests/type-definitions/global/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"include": ["./**/*.ts"],
44
"compilerOptions": {
55
"types": [
6-
"@core-js/types/full"
6+
"@core-js/types"
77
]
88
}
99
}

tests/type-definitions/global/web/dom-exception.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// todo add after it becomes possible to create a type
2-
// import '@core-js/full';
3-
// import '@core-js/types';
2+
// import 'core-js/full';
43
//
54
// const ex1 = new DOMException();
65
// const ex2 = new DOMException('Some message');

tests/type-definitions/global/web/self.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// todo add after it becomes possible to create a type
2-
// import '@core-js/full';
3-
// import '@core-js/types';
2+
// import 'core-js/full';
43
//
54
// const ref: typeof globalThis = self;
65
//

tests/type-definitions/global/web/url-search-params.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// todo add after it becomes possible to create a type
2-
// import '@core-js/full';
3-
// import '@core-js/types';
2+
// import 'core-js/full';
43
//
54
// const u0 = new URLSearchParams();
65
// const u1 = new URLSearchParams('a=1&b=2');

0 commit comments

Comments
 (0)