From 54ed33ce35927ae88370cb6a2ddb42be1a416331 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:46:20 +0100 Subject: [PATCH 1/2] esmify the package --- bin/lts.js | 17 +++++++++-------- lib/index.js | 17 +++++++---------- package.json | 3 ++- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/bin/lts.js b/bin/lts.js index 1edcbf9..2822847 100644 --- a/bin/lts.js +++ b/bin/lts.js @@ -1,8 +1,9 @@ #!/usr/bin/env node 'use strict'; -const Path = require('path'); -const Bossy = require('bossy'); -const Lib = require('../lib'); +import { resolve } from 'node:path'; +import Bossy from 'bossy'; +import { create } from '../lib/index.js'; + const now = new Date(); const oneYearFromNow = new Date(); @@ -15,7 +16,7 @@ const cliArgs = { type: 'string', require: false, multiple: false, - default: Path.resolve(__dirname, '..', 'lts.json') + default: resolve(__dirname, '..', 'lts.json') }, 's': { description: 'Query start date', @@ -94,12 +95,12 @@ const options = { data: require(args.data), queryStart: new Date(args.start), queryEnd: new Date(args.end), - html: args.html ? Path.resolve(args.html) : null, - svg: args.svg ? Path.resolve(args.svg) : null, - png: args.png ? Path.resolve(args.png) : null, + html: args.html ? resolve(args.html) : null, + svg: args.svg ? resolve(args.svg) : null, + png: args.png ? resolve(args.png) : null, animate: args.animate, excludeMain: args.excludeMain, projectName: args.projectName }; -Lib.create(options); +create(options); diff --git a/lib/index.js b/lib/index.js index ca212ad..4dcbf18 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,7 @@ 'use strict'; -const Fs = require('fs'); -const D3 = require('d3'); -const D3Node = require('d3-node'); +import { writeFileSync } from 'node:fs'; +import D3 from 'd3'; +import D3Node from 'd3-node'; const styles = ` .current { @@ -91,8 +91,7 @@ function parseInput (data, queryStart, queryEnd, excludeMain, projectName) { return output; } - -function create (options) { +export function create (options) { const { queryStart, queryEnd, html, svg: svgFile, png, animate, excludeMain, projectName, margin: marginInput } = options; const data = parseInput(options.data, queryStart, queryEnd, excludeMain, projectName); const d3n = new D3Node({ svgStyles: styles, d3Module: D3 }); @@ -207,18 +206,16 @@ function create (options) { }); if (typeof html === 'string') { - Fs.writeFileSync(html, d3n.html()); + writeFileSync(html, d3n.html()); } if (typeof svgFile === 'string') { - Fs.writeFileSync(svgFile, d3n.svgString()); + writeFileSync(svgFile, d3n.svgString()); } if (typeof png === 'string') { const Svg2png = require('svg2png'); // Load this lazily. - Fs.writeFileSync(png, Svg2png.sync(Buffer.from(d3n.svgString()))); + writeFileSync(png, Svg2png.sync(Buffer.from(d3n.svgString()))); } } - -module.exports.create = create; diff --git a/package.json b/package.json index 7829b90..9e1d299 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.0.0", "description": "Generate the Node.js LTS schedule", "main": "lib/index.js", + "type": "module", "homepage": "https://github.com/nodejs/lts-schedule", "repository": { "type": "git", @@ -19,7 +20,7 @@ "lts": "bin/lts.js" }, "engines": { - "node": ">=4.0.0" + "node": ">=20" }, "dependencies": { "bossy": "3.0.4", From bd21d6a2e5ebba7e91c8a21f485ba8926464e56d Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:58:53 +0100 Subject: [PATCH 2/2] fix: require --- bin/lts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/lts.js b/bin/lts.js index 2822847..10220b9 100644 --- a/bin/lts.js +++ b/bin/lts.js @@ -92,7 +92,7 @@ if (args instanceof Error) { } const options = { - data: require(args.data), + data: await import(args.data), queryStart: new Date(args.start), queryEnd: new Date(args.end), html: args.html ? resolve(args.html) : null,