From ef7a742969cf9e34d598c80b3be1060c8bd07d73 Mon Sep 17 00:00:00 2001 From: Vladislav Ponomarev Date: Mon, 6 Nov 2023 02:05:00 +0500 Subject: [PATCH] Support for workers --- lib/parser.js | 18 ------------------ lib/parser.node.js | 23 +++++++++++++++++++++++ package.json | 9 ++++++++- test/parser.js | 2 +- test/parser_day_of_month.js | 2 +- test/stringify.js | 2 +- 6 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 lib/parser.node.js diff --git a/lib/parser.js b/lib/parser.js index 362a416c..83ed7b3a 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -95,22 +95,4 @@ CronParser.parseString = function parseString (data) { return response; }; -/** - * Parse crontab file - * - * @public - * @param {String} filePath Path to file - * @param {Function} callback - */ -CronParser.parseFile = function parseFile (filePath, callback) { - require('fs').readFile(filePath, function(err, data) { - if (err) { - callback(err); - return; - } - - return callback(null, CronParser.parseString(data.toString())); - }); -}; - module.exports = CronParser; diff --git a/lib/parser.node.js b/lib/parser.node.js new file mode 100644 index 00000000..cd1898b6 --- /dev/null +++ b/lib/parser.node.js @@ -0,0 +1,23 @@ +'use strict'; + +var CronParser = require('./parser'); + +/** + * Parse crontab file + * + * @public + * @param {String} filePath Path to file + * @param {Function} callback + */ +CronParser.parseFile = function parseFile (filePath, callback) { + require('fs').readFile(filePath, function(err, data) { + if (err) { + callback(err); + return; + } + + return callback(null, CronParser.parseString(data.toString())); + }); +}; + +module.exports = CronParser; diff --git a/package.json b/package.json index c8553434..668e9d96 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "cron-parser", "version": "4.9.0", "description": "Node.js library for parsing crontab instructions", - "main": "lib/parser.js", "types": "types/index.d.ts", "typesVersions": { "<4.1": { @@ -14,6 +13,14 @@ "directories": { "test": "test" }, + "exports": { + ".": { + "types": "./types/index.d.ts", + "worker": "./lib/parser.js", + "browser": "./lib/parser.js", + "default": "./lib/parser.node.js" + } + }, "scripts": { "test:tsd": "tsd", "test:unit": "TZ=UTC tap ./test/*.js", diff --git a/test/parser.js b/test/parser.js index fae90399..08bf329d 100644 --- a/test/parser.js +++ b/test/parser.js @@ -1,5 +1,5 @@ var test = require('tap').test; -var CronParser = require('../lib/parser'); +var CronParser = require('../lib/parser.node'); // Globals diff --git a/test/parser_day_of_month.js b/test/parser_day_of_month.js index 127a0d75..12881b8c 100644 --- a/test/parser_day_of_month.js +++ b/test/parser_day_of_month.js @@ -1,5 +1,5 @@ var test = require('tap').test; -var CronParser = require('../lib/parser'); +var CronParser = require('../lib/parser.node'); test('parse cron with last day in a month', function(t) { var options = { diff --git a/test/stringify.js b/test/stringify.js index 3643b827..b494b462 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -1,7 +1,7 @@ 'use strict'; var test = require('tap').test; -var CronParser = require('../lib/parser'); +var CronParser = require('../lib/parser.node'); test('stringify cron expression all stars no seconds', function (t) { try {