Skip to content

Commit 683f585

Browse files
committedFeb 16, 2025··
Use dynamic imports in CronFileParser to avoid breaking the browser environment (fixes #362)
1 parent 9b1e0f3 commit 683f585

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎src/CronFileParser.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import fs from 'fs/promises';
2-
import { readFileSync } from 'fs';
3-
41
import { CronExpression } from './CronExpression';
52
import { CronExpressionParser } from './CronExpressionParser';
63

@@ -21,7 +18,8 @@ export class CronFileParser {
2118
* @throws If file cannot be read
2219
*/
2320
static async parseFile(filePath: string): Promise<CronFileParserResult> {
24-
const data = await fs.readFile(filePath, 'utf8');
21+
const { readFile } = await import('fs/promises');
22+
const data = await readFile(filePath, 'utf8');
2523
return CronFileParser.#parseContent(data);
2624
}
2725

@@ -32,6 +30,8 @@ export class CronFileParser {
3230
* @throws If file cannot be read
3331
*/
3432
static parseFileSync(filePath: string): CronFileParserResult {
33+
// eslint-disable-next-line @typescript-eslint/no-require-imports
34+
const { readFileSync } = require('fs');
3535
const data = readFileSync(filePath, 'utf8');
3636
return CronFileParser.#parseContent(data);
3737
}

0 commit comments

Comments
 (0)
Please sign in to comment.