Skip to content

Commit 24a45f9

Browse files
authoredAug 16, 2021
fix(ts): correct entry point (#4829)
The entry point used to be: ```ts export { default } from './index.es'; export * from './connectors'; export * from './helpers'; export * from './types'; export * from './widgets'; export * from './lib/routers'; ``` While really the entry point should be the same as index.es.ts, as otherwise the js bundle doesn't match the declaration. This commit fixes that by no longer generating an entry point, and renaming index.es.d.ts to index.d.ts in the built files. In the same commit I also move the declaration-related configuration files to the subfolder to make the root a little cleaner
1 parent d06f82c commit 24a45f9

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed
 

‎api-extractor.json ‎scripts/build/api-extractor.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
33

4+
"projectFolder": "../../",
5+
"mainEntryPointFilePath": "<projectFolder>/es/index.d.ts",
6+
"dtsRollup": {
7+
"enabled": false
8+
},
9+
410
"apiReport": {
511
"enabled": false
612
},
@@ -40,9 +46,5 @@
4046
"logLevel": "none"
4147
}
4248
}
43-
},
44-
"mainEntryPointFilePath": "es/index.d.ts",
45-
"dtsRollup": {
46-
"enabled": false
4749
}
4850
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"extends": "./tsconfig",
2+
"extends": "../../tsconfig",
33
"compilerOptions": {
44
"stripInternal": true,
55
"noEmit": false,
66
"declaration": true,
77
"emitDeclarationOnly": true,
88
"allowJs": true
99
},
10-
"include": ["src", "./global.d.ts"],
11-
"exclude": ["**/__tests__"]
10+
"include": ["../../src", "../../global.d.ts"],
11+
"exclude": ["../../**/__tests__"]
1212
}

‎scripts/build/types.js

+10-26
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
/* eslint-disable import/no-commonjs, no-console */
44

5-
const fs = require('fs');
65
const path = require('path');
76
const shell = require('shelljs');
87

98
console.log(`Compiling definitions...`);
109

11-
shell.exec(`tsc -p tsconfig.declaration.json --outDir es/`);
10+
shell.exec(
11+
`tsc -p ${path.join(__dirname, 'tsconfig.declaration.json')} --outDir es/`
12+
);
1213

1314
// replace block ts-ignore comments with line ones to support TS < 3.9
1415
shell.sed(
@@ -18,36 +19,19 @@ shell.sed(
1819
path.join(__dirname, '../../es/**/*.d.ts')
1920
);
2021

22+
// expose only the es entry point, not the umd entry point
23+
shell.mv(
24+
path.join(__dirname, '../../es/index.es.d.ts'),
25+
path.join(__dirname, '../../es/index.d.ts')
26+
);
27+
2128
console.log();
2229
console.log(`Validating definitions...`);
2330

2431
const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor');
2532

26-
const publicExports = [
27-
// 'components' -> does not contains index.d.ts yet
28-
'connectors',
29-
// 'lib', -> Api extractor "import * as ___ from ___;" is not supported yet for local files
30-
// 'middleware',
31-
'helpers',
32-
'types',
33-
'widgets', // -> It does not compile as WidgetFactory is not imported in all files
34-
'lib/routers',
35-
];
36-
37-
fs.writeFileSync(
38-
path.join(__dirname, '../../', 'es/index.d.ts'),
39-
[
40-
`export { default } from './index.es';`,
41-
...publicExports
42-
.map(publicExport => `./${publicExport}`)
43-
.map(exportedFile => {
44-
return `export * from '${exportedFile}';`;
45-
}),
46-
].join('\r\n')
47-
);
48-
4933
const extractorConfig = ExtractorConfig.loadFileAndPrepare(
50-
path.resolve(path.join(__dirname, '../../', 'api-extractor.json'))
34+
path.resolve(path.join(__dirname, 'api-extractor.json'))
5135
);
5236

5337
const result = Extractor.invoke(extractorConfig, {

0 commit comments

Comments
 (0)
Please sign in to comment.