Skip to content

Commit b03d912

Browse files
chore: fix circular ESM import + fix output spec
1 parent bde85e6 commit b03d912

File tree

6 files changed

+47641
-41
lines changed

6 files changed

+47641
-41
lines changed

Diff for: README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ The module exports a function that parses a given API JSON object and returns
2828
an array of lines to create the definition file
2929

3030
```js
31-
const { generateDefinitions } = require('@electron/typescript-definitions')
31+
import { generateDefinitions } from '@electron/typescript-definitions'
32+
3233
const apiPath = './vendor/electron/docs/api.json'
3334

34-
const definitionLines = generateDefinitions({ electronApi: require(apiPath) })
35+
const definitionLines = generateDefinitions({ electronApi: loadJSON(apiPath) })
3536
// definitionLines will be an strin representation of the definition file
3637
```
3738

Diff for: src/bin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ runner.text = chalk.cyan(`Generating API in directory: ${chalk.yellow(`"${resolv
6262
const start = Date.now();
6363
const resolvedFilePath = path.resolve(resolvedOutDir, './electron.d.ts');
6464

65-
fs.promises.mkdir(resolvedOutDir, { recursive: true }).then(() =>
65+
fs.promises.mkdir(resolvedOutDir, { recursive: true }).then(async () =>
6666
generateDefinitions({
67-
electronApi: require(resolvedApi),
67+
electronApi: JSON.parse(await fs.promises.readFile(resolvedApi, 'utf-8')),
6868
})
6969
.then((data) => fs.promises.writeFile(resolvedFilePath, data))
7070
.then(() =>

Diff for: src/dynamic-param-interfaces.ts

+2
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,5 @@ export class DynamicParamInterfaces {
295295
static createParamInterface = createParamInterface;
296296
static flushParamInterfaces = flushParamInterfaces;
297297
}
298+
299+
utils.setParamInterfaces(DynamicParamInterfaces);

Diff for: src/utils.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ import { DynamicParamInterfaces } from './dynamic-param-interfaces.js';
1616
const debug = d('utils');
1717

1818
let paramInterfaces: typeof DynamicParamInterfaces;
19-
const lazyParamInterfaces = () => {
20-
if (!paramInterfaces) {
21-
paramInterfaces = require('./dynamic-param-interfaces').DynamicParamInterfaces;
22-
}
23-
return paramInterfaces;
19+
20+
export const setParamInterfaces = (provided: typeof DynamicParamInterfaces) => {
21+
paramInterfaces = provided;
2422
};
2523

2624
export const extendArray = <T>(arr1: T[], arr2: T[]): T[] => {
@@ -176,10 +174,7 @@ export const typify = (
176174
inner.type === 'Object'
177175
? {
178176
...inner,
179-
type: lazyParamInterfaces().createParamInterface(
180-
inner as any,
181-
maybeInnerReturnTypeName,
182-
),
177+
type: paramInterfaces.createParamInterface(inner as any, maybeInnerReturnTypeName),
183178
}
184179
: inner,
185180
);

0 commit comments

Comments
 (0)