diff --git a/bench/index.js b/bench/index.js index 6485288..334c466 100644 --- a/bench/index.js +++ b/bench/index.js @@ -1,10 +1,12 @@ -/* eslint-disable no-unused-vars */ -import { html } from "ghtml"; -import { Bench } from "tinybench"; -import { writeFileSync } from "node:fs"; -import { Buffer } from "node:buffer"; +"use strict"; + +const { html } = require(".."); +const { Bench } = require("tinybench"); +const { writeFileSync } = require("node:fs"); const bench = new Bench({ time: 500 }); + +// eslint-disable-next-line no-unused-vars let result = ""; bench.add("simple HTML formatting", () => { @@ -108,13 +110,15 @@ bench.add("sparse escape", () => { result = html`
${`${"noescape".repeat(250)}<>`.repeat(5)}
`; }); -await bench.warmup(); -await bench.run(); +(async () => { + await bench.warmup(); + await bench.run(); -const table = bench.table(); -globalThis.console.table(table); + const table = bench.table(); + globalThis.console.table(table); -writeFileSync( - "bench/results.json", - Buffer.from(JSON.stringify(table), "utf8").toString("base64"), -); + writeFileSync( + "bench/results.json", + Buffer.from(JSON.stringify(table), "utf8").toString("base64"), + ); +})(); diff --git a/bin/src/index.js b/bin/src/index.js index d771402..fb1319f 100755 --- a/bin/src/index.js +++ b/bin/src/index.js @@ -1,6 +1,8 @@ #!/usr/bin/env node -import { generateHashesAndReplace } from "./utils.js"; -import process from "node:process"; + +"use strict"; + +const { generateHashesAndReplace } = require("./utils.js"); const parseArguments = (args) => { let roots = null; diff --git a/bin/src/utils.js b/bin/src/utils.js index 58e8818..61787ff 100644 --- a/bin/src/utils.js +++ b/bin/src/utils.js @@ -1,7 +1,9 @@ -import { Glob } from "glob"; -import { createHash } from "node:crypto"; -import { readFile, writeFile } from "node:fs/promises"; -import { win32, posix } from "node:path"; +"use strict"; + +const { Glob } = require("glob"); +const { createHash } = require("node:crypto"); +const { readFile, writeFile } = require("node:fs/promises"); +const { win32, posix } = require("node:path"); const generateFileHash = async (filePath) => { try { @@ -77,7 +79,7 @@ const updateFilePathsWithHashes = async ( } }; -export const generateHashesAndReplace = async ({ +const generateHashesAndReplace = async ({ roots, refs, prefix, @@ -130,3 +132,5 @@ export const generateHashesAndReplace = async ({ skipPatterns, ); }; + +module.exports.generateHashesAndReplace = generateHashesAndReplace; diff --git a/eslint.config.js b/eslint.config.mjs similarity index 63% rename from eslint.config.js rename to eslint.config.mjs index f170edf..793bc82 100644 --- a/eslint.config.js +++ b/eslint.config.mjs @@ -1,7 +1,15 @@ import grules from "grules"; +import globals from "globals"; export default [ ...grules, + { + languageOptions: { + globals: { + ...globals.node, + }, + }, + }, { rules: { "no-await-in-loop": "off", diff --git a/package.json b/package.json index 299002c..183e777 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "author": "Gürgün Dayıoğlu", "license": "MIT", "version": "3.0.13", - "type": "module", + "type": "commonjs", "bin": "./bin/src/index.js", "main": "./src/index.js", "exports": { @@ -27,6 +27,7 @@ "devDependencies": { "@fastify/pre-commit": "^2.1.0", "c8": "^10.1.2", + "globals": "^15.11.0", "grules": "^0.25.10", "tinybench": "^2.9.0", "typescript": ">=5.6.2" diff --git a/src/includeFile.js b/src/includeFile.js index 1a27b80..322c2b1 100644 --- a/src/includeFile.js +++ b/src/includeFile.js @@ -1,4 +1,6 @@ -import { readFileSync } from "node:fs"; +"use strict"; + +const { readFileSync } = require("node:fs"); const cache = new Map(); @@ -6,7 +8,7 @@ const cache = new Map(); * @param {string} path path * @returns {string} string */ -export const includeFile = (path) => { +const includeFile = (path) => { let file = cache.get(path); if (file === undefined) { @@ -16,3 +18,5 @@ export const includeFile = (path) => { return file; }; + +module.exports.includeFile = includeFile; diff --git a/src/index.js b/src/index.js index 6877592..e559021 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +"use strict"; + const _isArray = Array.isArray; const _iterator = Symbol.iterator; @@ -56,7 +58,7 @@ const escapeFunction = (string) => { * @param {...any} expressions expressions * @returns {string} string */ -export const html = (literals, ...expressions) => { +const html = (literals, ...expressions) => { let accumulator = ""; for (let i = 0; i !== expressions.length; ++i) { @@ -83,7 +85,7 @@ export const html = (literals, ...expressions) => { * @yields {string} string * @returns {Generator