Skip to content

Commit b4d9d13

Browse files
fix: only export value types for things that are actually exported
1 parent 109db51 commit b4d9d13

File tree

4 files changed

+80
-55
lines changed

4 files changed

+80
-55
lines changed

base/base_footer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module 'electron' {
2-
export = Electron;
2+
export = Electron.CrossProcessExports;
33
}
44

55
declare module 'electron/main' {
@@ -15,14 +15,14 @@ declare module 'electron/renderer' {
1515
}
1616

1717
interface NodeRequireFunction {
18-
(moduleName: 'electron'): typeof Electron;
18+
(moduleName: 'electron'): typeof Electron.CrossProcessExports;
1919
(moduleName: 'electron/main'): typeof Electron.Main;
2020
(moduleName: 'electron/common'): typeof Electron.Common;
2121
(moduleName: 'electron/renderer'): typeof Electron.Renderer;
2222
}
2323

2424
interface NodeRequire {
25-
(moduleName: 'electron'): typeof Electron;
25+
(moduleName: 'electron'): typeof Electron.CrossProcessExports;
2626
(moduleName: 'electron/main'): typeof Electron.Main;
2727
(moduleName: 'electron/common'): typeof Electron.Common;
2828
(moduleName: 'electron/renderer'): typeof Electron.Renderer;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"license": "MIT",
2323
"devDependencies": {
2424
"@continuous-auth/semantic-release-npm": "2.0.0",
25-
"@electron/docs-parser": "^0.11.0",
25+
"@electron/docs-parser": "^0.12.0",
2626
"@types/debug": "^4.1.4",
2727
"@types/fs-extra": "^5.0.5",
2828
"@types/lodash": "^4.14.123",

src/master-interfaces.ts

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const generateMasterInterfaces = (
1313
const MainNamespace = ['namespace Main {'];
1414
const RendererNamespace = ['namespace Renderer {'];
1515
const MainInterfaceForRemote = ['interface RemoteMainInterface {'];
16+
const CrossProcessExportsNamespace = ['namespace CrossProcessExports {'];
1617
const constDeclarations: string[] = [];
1718
const EMRI: Record<string, boolean> = {};
1819

@@ -34,39 +35,58 @@ export const generateMasterInterfaces = (
3435
API.forEach((module, index) => {
3536
if (module.name === 'process') return;
3637
let TargetNamespace;
37-
const isClass =
38-
module.type === 'Class' ||
39-
API.some(
40-
(tModule, tIndex) =>
41-
index !== tIndex && tModule.name.toLowerCase() === module.name.toLowerCase(),
42-
);
43-
const moduleString = isClass
44-
? ` class ${_.upperFirst(module.name)} extends Electron.${_.upperFirst(module.name)} {}`
45-
: '';
38+
const isClass = module.type === 'Class';
4639
if (module.type === 'Structure') {
4740
// We must be a structure or something
4841
return;
4942
}
43+
const moduleString =
44+
isClass && module.process.exported
45+
? ` class ${_.upperFirst(module.name)} extends Electron.${_.upperFirst(module.name)} {}`
46+
: '';
5047
const newConstDeclarations: string[] = [];
51-
if (!isClass || module.name !== classify(module.name)) {
48+
if ((!isClass || module.name !== classify(module.name)) && module.process.exported) {
5249
if (isClass) {
5350
newConstDeclarations.push(
5451
`type ${classify(module.name)} = ${_.upperFirst(module.name)};`,
5552
`const ${classify(module.name)}: typeof ${_.upperFirst(module.name)};`,
5653
);
5754
} else {
58-
newConstDeclarations.push(`const ${classify(module.name)}: ${_.upperFirst(module.name)};`);
55+
// In the case where this module is actually the static methods on a Class type
56+
if (
57+
API.some(
58+
(tModule, tIndex) =>
59+
index !== tIndex &&
60+
tModule.name.toLowerCase() === module.name.toLowerCase() &&
61+
tModule.type === 'Class',
62+
) &&
63+
!isClass
64+
) {
65+
newConstDeclarations.push(
66+
`const ${classify(module.name)}: typeof ${_.upperFirst(module.name)};`,
67+
);
68+
} else {
69+
newConstDeclarations.push(
70+
`const ${classify(module.name)}: ${_.upperFirst(module.name)};`,
71+
);
72+
}
5973
}
6074
}
6175
constDeclarations.push(...newConstDeclarations);
62-
if (module.process.main && module.process.renderer) {
63-
TargetNamespace = CommonNamespace;
64-
} else if (module.process.main) {
65-
TargetNamespace = MainNamespace;
66-
} else if (module.process.renderer) {
67-
TargetNamespace = RendererNamespace;
76+
if (module.process.exported) {
77+
if (module.process.main && module.process.renderer) {
78+
TargetNamespace = CommonNamespace;
79+
} else if (module.process.main) {
80+
TargetNamespace = MainNamespace;
81+
} else if (module.process.renderer) {
82+
TargetNamespace = RendererNamespace;
83+
}
6884
}
69-
if (module.process.main && !EMRI[classify(module.name).toLowerCase()]) {
85+
if (
86+
module.process.main &&
87+
module.process.exported &&
88+
!EMRI[classify(module.name).toLowerCase()]
89+
) {
7090
MainInterfaceForRemote.push(
7191
` ${classify(module.name)}: ${isClass ? 'typeof ' : ''}${_.upperFirst(module.name)};`,
7292
);
@@ -75,9 +95,12 @@ export const generateMasterInterfaces = (
7595
debug(classify(module.name).toLowerCase(), EMRI[classify(module.name).toLowerCase()]);
7696
if (!EMRI[classify(module.name).toLowerCase()]) {
7797
if (moduleString) TargetNamespace.push(moduleString);
98+
if (moduleString) CrossProcessExportsNamespace.push(moduleString);
7899
}
79100
EMRI[classify(module.name).toLowerCase()] = true;
80-
TargetNamespace.push(...newConstDeclarations.map(s => ` ${s.substr(0, s.length - 1)}`));
101+
const declarations = newConstDeclarations.map(s => ` ${s.substr(0, s.length - 1)}`);
102+
TargetNamespace.push(...declarations);
103+
CrossProcessExportsNamespace.push(...declarations);
81104
}
82105
});
83106

@@ -88,11 +111,13 @@ export const generateMasterInterfaces = (
88111
CommonNamespace.push(alias);
89112
MainNamespace.push(alias);
90113
RendererNamespace.push(alias);
114+
CrossProcessExportsNamespace.push(alias);
91115
}
92116

93117
CommonNamespace.push('}');
94118
MainNamespace.push('}');
95119
RendererNamespace.push('}');
120+
CrossProcessExportsNamespace.push('}');
96121

97122
const withSemicolons = (lines: string[]) => {
98123
return lines.map(l => (l.endsWith('{') || l.endsWith('}') ? l : `${l};`));
@@ -101,5 +126,6 @@ export const generateMasterInterfaces = (
101126
addToOutput(withSemicolons(CommonNamespace));
102127
addToOutput(withSemicolons(MainNamespace));
103128
addToOutput(withSemicolons(RendererNamespace));
129+
addToOutput(withSemicolons(CrossProcessExportsNamespace));
104130
addToOutput(constDeclarations);
105131
};

yarn.lock

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
read-pkg "^4.0.0"
2828
registry-auth-token "^3.3.1"
2929

30-
"@electron/docs-parser@^0.11.0":
31-
version "0.11.0"
32-
resolved "https://registry.yarnpkg.com/@electron/docs-parser/-/docs-parser-0.11.0.tgz#182a9732d2fc7b40e3f506d3ab1a06270cdae6e4"
33-
integrity sha512-i+OSWXXchoKVorR6cANqPKYJ1ccLAp+YCPTB+IJVWZ+Xtp6V2VXqLsjoy4mD32ss4CdX/6MLX62pb2sjGmmR6w==
30+
"@electron/docs-parser@^0.12.0":
31+
version "0.12.0"
32+
resolved "https://registry.yarnpkg.com/@electron/docs-parser/-/docs-parser-0.12.0.tgz#a1ae37164bf93f9cabcb1d51f19146a0a7f07168"
33+
integrity sha512-/z9XUi5z752tpNa+fC+STtGKKOT9lQ9PgU15MMSUtOHRVbNfoQfGoFQaiUKi5uqH+UnAwBZ+p8PHId30KtVxCA==
3434
dependencies:
3535
"@types/markdown-it" "^10.0.0"
3636
chai "^4.2.0"
@@ -164,11 +164,6 @@
164164
into-stream "^4.0.0"
165165
lodash "^4.17.4"
166166

167-
"@types/color-name@^1.1.1":
168-
version "1.1.1"
169-
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
170-
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
171-
172167
"@types/debug@^4.1.4":
173168
version "4.1.4"
174169
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.4.tgz#56eec47706f0fd0b7c694eae2f3172e6b0b769da"
@@ -201,9 +196,9 @@
201196
integrity sha512-t2szdkwmg2JJyuCM20e8kR2X59WCE5Zkl4bzm1u1Oukjm79zpbiAv+QjnwLnuuV0WHEcX2NgUItu0pAMKuOPww==
202197

203198
"@types/linkify-it@*":
204-
version "2.1.0"
205-
resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-2.1.0.tgz#ea3dd64c4805597311790b61e872cbd1ed2cd806"
206-
integrity sha512-Q7DYAOi9O/+cLLhdaSvKdaumWyHbm7HAk/bFwwyTuU0arR5yyCeW5GOoqt4tJTpDRxhpx9Q8kQL6vMpuw9hDSw==
199+
version "3.0.1"
200+
resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-3.0.1.tgz#4d26a9efe3aa2caf829234ec5a39580fc88b6001"
201+
integrity sha512-pQv3Sygwxxh6jYQzXaiyWDAHevJqWtqDUv6t11Sa9CPGiXny66II7Pl6PR8QO5OVysD6HYOkHMeBgIjLnk9SkQ==
207202

208203
"@types/lodash@^4.14.123":
209204
version "4.14.123"
@@ -342,11 +337,10 @@ ansi-styles@^3.2.1:
342337
color-convert "^1.9.0"
343338

344339
ansi-styles@^4.1.0:
345-
version "4.2.1"
346-
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359"
347-
integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==
340+
version "4.3.0"
341+
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937"
342+
integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==
348343
dependencies:
349-
"@types/color-name" "^1.1.1"
350344
color-convert "^2.0.1"
351345

352346
ansicolors@~0.3.2:
@@ -910,9 +904,9 @@ cli-spinners@^2.0.0:
910904
integrity sha512-8B00fJOEh1HPrx4fo5eW16XmE1PcL1tGpGrxy63CXGP9nHdPBN63X75hA1zhvQuhVztJWLqV58Roj2qlNM7cAA==
911905

912906
cli-spinners@^2.2.0:
913-
version "2.2.0"
914-
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.2.0.tgz#e8b988d9206c692302d8ee834e7a85c0144d8f77"
915-
integrity sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==
907+
version "2.6.0"
908+
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.6.0.tgz#36c7dc98fb6a9a76bd6238ec3f77e2425627e939"
909+
integrity sha512-t+4/y50K/+4xcCRosKkA7W4gTr1MySvLV0q+PxmG7FJ5g+66ChKurYjxBCjHggHH3HA5Hh9cy+lcUGWDqVH+4Q==
916910

917911
cli-table3@^0.5.0, cli-table3@^0.5.1:
918912
version "0.5.1"
@@ -1453,9 +1447,9 @@ ensure-posix-path@^1.0.0:
14531447
integrity sha512-VWU0/zXzVbeJNXvME/5EmLuEj2TauvoaTz6aFYK1Z92JCBlDlZ3Gu0tuGR42kpW1754ywTs+QB0g5TP0oj9Zaw==
14541448

14551449
entities@~2.0.0:
1456-
version "2.0.0"
1457-
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.0.tgz#68d6084cab1b079767540d80e56a39b423e4abf4"
1458-
integrity sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==
1450+
version "2.0.3"
1451+
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.3.tgz#5c487e5742ab93c15abb5da22759b8590ec03b7f"
1452+
integrity sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==
14591453

14601454
env-ci@^3.0.0:
14611455
version "3.2.0"
@@ -2048,11 +2042,16 @@ got@^6.7.1:
20482042
unzip-response "^2.0.1"
20492043
url-parse-lax "^1.0.0"
20502044

2051-
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
2045+
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2:
20522046
version "4.2.4"
20532047
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
20542048
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
20552049

2050+
graceful-fs@^4.1.6, graceful-fs@^4.2.0:
2051+
version "4.2.6"
2052+
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.6.tgz#ff040b2b0853b23c3d31027523706f1885d76bee"
2053+
integrity sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==
2054+
20562055
20572056
version "1.10.5"
20582057
resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"
@@ -4138,9 +4137,9 @@ onetime@^2.0.0:
41384137
mimic-fn "^1.0.0"
41394138

41404139
onetime@^5.1.0:
4141-
version "5.1.0"
4142-
resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.0.tgz#fff0f3c91617fe62bb50189636e99ac8a6df7be5"
4143-
integrity sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==
4140+
version "5.1.2"
4141+
resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e"
4142+
integrity sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==
41444143
dependencies:
41454144
mimic-fn "^2.1.0"
41464145

@@ -4170,9 +4169,9 @@ ora@^3.4.0:
41704169
wcwidth "^1.0.1"
41714170

41724171
ora@^4.0.3:
4173-
version "4.0.3"
4174-
resolved "https://registry.yarnpkg.com/ora/-/ora-4.0.3.tgz#752a1b7b4be4825546a7a3d59256fa523b6b6d05"
4175-
integrity sha512-fnDebVFyz309A73cqCipVL1fBZewq4vwgSHfxh43vVy31mbyoQ8sCH3Oeaog/owYOs/lLlGVPCISQonTneg6Pg==
4172+
version "4.1.1"
4173+
resolved "https://registry.yarnpkg.com/ora/-/ora-4.1.1.tgz#566cc0348a15c36f5f0e979612842e02ba9dddbc"
4174+
integrity sha512-sjYP8QyVWBpBZWD6Vr1M/KwknSw6kJOz41tvGMlwWeClHBtYKTbHMki1PsLZnxKpXMPbTKv9b3pjQu3REib96A==
41764175
dependencies:
41774176
chalk "^3.0.0"
41784177
cli-cursor "^3.1.0"
@@ -5523,9 +5522,9 @@ supports-color@^5.0.0, supports-color@^5.3.0:
55235522
has-flag "^3.0.0"
55245523

55255524
supports-color@^7.1.0:
5526-
version "7.1.0"
5527-
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1"
5528-
integrity sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==
5525+
version "7.2.0"
5526+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
5527+
integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
55295528
dependencies:
55305529
has-flag "^4.0.0"
55315530

0 commit comments

Comments
 (0)