From dd7973e5e8a62b902f6b9b401a20017cc5249b96 Mon Sep 17 00:00:00 2001 From: "Michael J. Radwin" Date: Mon, 18 Dec 2023 08:49:39 -0800 Subject: [PATCH] Merge some bits of #365 into package, enabling package "type":"module" --- .gitignore | 1 + package-lock.json | 22 +++++++++++----------- package.json | 15 +++++++++++---- src/candles.js | 12 +++++------- src/hebcal.js | 2 +- src/index.js | 2 +- version.cjs | 12 ++++++++++++ 7 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 version.cjs diff --git a/.gitignore b/.gitignore index fd27359..0f477eb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ node_modules dist src/*.po.js +src/pkgVersion.js coverage .nyc_output diff --git a/package-lock.json b/package-lock.json index b2bab57..6ec9713 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hebcal/core", - "version": "5.0.2", + "version": "5.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@hebcal/core", - "version": "5.0.2", + "version": "5.0.3", "license": "GPL-2.0", "devDependencies": { "@babel/core": "^7.23.6", @@ -2831,9 +2831,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.10.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz", - "integrity": "sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg==", + "version": "20.10.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.5.tgz", + "integrity": "sha512-nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -4956,9 +4956,9 @@ "dev": true }, "node_modules/fastq": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", - "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.16.0.tgz", + "integrity": "sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA==", "dev": true, "dependencies": { "reusify": "^1.0.4" @@ -5397,9 +5397,9 @@ } }, "node_modules/gettext-parser/node_modules/readable-stream": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.2.tgz", - "integrity": "sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.1.tgz", + "integrity": "sha512-uQjbf34vmf/asGnOHQEw07Q4llgMACQZTWWa4MmICS0IKJoHbLwKCy71H3eR99Dw5iYejc6W+pqZZEeqRtUFAw==", "dev": true, "dependencies": { "abort-controller": "^3.0.0", diff --git a/package.json b/package.json index 6eec3ae..9cb2e0d 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "@hebcal/core", - "version": "5.0.2", + "version": "5.0.3", "author": "Michael J. Radwin (https://github.com/mjradwin)", "contributors": [ "Eyal Schachter (https://github.com/Scimonster)", - "Danny Sadinoff (https://github.com/dsadinoff)" + "Danny Sadinoff (https://github.com/dsadinoff)", + "Benny Powers (https://github.com/bennypowers)" ], "keywords": [ "hebcal", @@ -20,8 +21,13 @@ "zmanim" ], "description": "A perpetual Jewish Calendar API", - "main": "./dist/index.js", + "main": "./dist/index.cjs", "module": "./dist/index.mjs", + "type": "module", + "exports": { + "import": "./dist/index.mjs", + "require": "./dist/index.cjs" + }, "typings": "hebcal.d.ts", "engines": { "node": ">= 16.0.0" @@ -40,9 +46,10 @@ ], "scripts": { "build:rollup": "rollup -c", - "build": "npm run po2json && npm run build:rollup", + "build": "npm run po2json && npm run version && npm run build:rollup", "prepublish": "npm run build", "po2json": "node ./po2json.cjs po/*.po", + "version": "node ./version.cjs package.json src/pkgVersion.js", "readme": "npx -p jsdoc-to-markdown jsdoc2md dist/index.js", "pretest": "npm run build", "lint": "eslint src", diff --git a/src/candles.js b/src/candles.js index 7205b76..a25f4ff 100644 --- a/src/candles.js +++ b/src/candles.js @@ -4,10 +4,8 @@ import {Event, flags} from './event.js'; import {Locale} from './locale.js'; import {Zmanim} from './zmanim.js'; -const days = { - FRI: 5, - SAT: 6, -}; +const FRI = 5; +const SAT = 6; /** * @private @@ -20,11 +18,11 @@ const days = { */ export function makeCandleEvent(e, hd, dow, location, options) { let havdalahTitle = false; - let useHavdalahOffset = dow == days.SAT; + let useHavdalahOffset = dow === SAT; let mask = e ? e.getFlags() : flags.LIGHT_CANDLES; if (typeof e !== 'undefined') { // if linked event && dow == FRI, use Candle lighting time & title - if (dow != days.FRI) { + if (dow !== FRI) { if (mask & (flags.LIGHT_CANDLES_TZEIS | flags.CHANUKAH_CANDLES)) { useHavdalahOffset = true; } else if (mask & flags.YOM_TOV_ENDS) { @@ -32,7 +30,7 @@ export function makeCandleEvent(e, hd, dow, location, options) { useHavdalahOffset = true; } } - } else if (dow == days.SAT) { + } else if (dow === SAT) { havdalahTitle = true; mask = flags.LIGHT_CANDLES_TZEIS; } diff --git a/src/hebcal.js b/src/hebcal.js index d57e24a..fc88f6f 100644 --- a/src/hebcal.js +++ b/src/hebcal.js @@ -19,7 +19,7 @@ along with this program. If not, see . */ import {getBirthdayHD, getYahrzeitHD, greg, months} from '@hebcal/hdate'; -import {version as pkgVersion} from '../package.json'; +import {version as pkgVersion} from './pkgVersion.js'; import {DailyLearning} from './DailyLearning.js'; import {HebrewDateEvent} from './HebrewDateEvent.js'; import {ParshaEvent} from './ParshaEvent.js'; diff --git a/src/index.js b/src/index.js index 0b29701..8d87b64 100644 --- a/src/index.js +++ b/src/index.js @@ -16,4 +16,4 @@ export {HolidayEvent, AsaraBTevetEvent, MevarchimChodeshEvent, RoshChodeshEvent, RoshHashanaEvent} from './holidays.js'; export {DailyLearning} from './DailyLearning.js'; export {HebrewCalendar} from './hebcal.js'; -export {version} from '../package.json'; +export {version} from './pkgVersion.js'; diff --git a/version.cjs b/version.cjs new file mode 100644 index 0000000..05d228e --- /dev/null +++ b/version.cjs @@ -0,0 +1,12 @@ +/* eslint-disable require-jsdoc */ +const fs = require('fs'); + +const inpath = process.argv[2]; +const outpath = process.argv[3]; + +const contents = fs.readFileSync(inpath).toString(); +const manifest = JSON.parse(contents); +const line = `// DO NOT EDIT THIS AUTO-GENERATED FILE! +export const version = '${manifest.version}';\n`; + +fs.writeFileSync(outpath, line, {flags: 'w'});