From 0e09f06b0230565e930ab0d3eba5abf08c79f894 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 10 Jun 2024 02:33:07 +0000 Subject: [PATCH] Fixed exports (again). --- src/combine.js | 2 +- src/handlers/css.js | 2 +- src/handlers/html.js | 2 +- src/handlers/js.js | 2 +- src/handlers/twig.js | 2 +- src/handlers/webmanifest.js | 2 +- src/housekeep.js | 2 +- src/index.js | 2 +- src/trim.js | 8 +++++--- src/utils.js | 6 +++--- 10 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/combine.js b/src/combine.js index e1f66ce..12d0a7a 100644 --- a/src/combine.js +++ b/src/combine.js @@ -3,7 +3,7 @@ const readline = require('readline'); const { join: pathJoin } = require('path'); const { trim, trimStart, trimEnd } = require('./trim.js'); -exports.folder = async (root, options) => { +module.exports.folder = async (root, options) => { const macroPrefix = options.prefix || '#'; const entryPoint = options.entry || ''; diff --git a/src/handlers/css.js b/src/handlers/css.js index 97c4753..78b5860 100644 --- a/src/handlers/css.js +++ b/src/handlers/css.js @@ -3,7 +3,7 @@ const combine = require('../combine.js'); const { join: pathJoin, dirname } = require('path'); const { strtr, shortHash, writeFile } = require('../utils.js'); -exports = function(env) { +module.exports = function(env) { const PREFIX = '@'; const DEFAULT_ENTRY = 'main.css'; diff --git a/src/handlers/html.js b/src/handlers/html.js index 1c87757..22d1a3e 100644 --- a/src/handlers/html.js +++ b/src/handlers/html.js @@ -2,7 +2,7 @@ const { minify: htmlminify } = require('html-minifier-terser'); const { join: pathJoin, dirname } = require('path'); const { strtr, shortHash, writeFile } = require('../utils.js'); -exports = function(env) { +module.exports = function(env) { const MINIFY_OPTS = { collapseBooleanAttributes: true, collapseWhitespace: true, diff --git a/src/handlers/js.js b/src/handlers/js.js index 8a27833..70dff10 100644 --- a/src/handlers/js.js +++ b/src/handlers/js.js @@ -4,7 +4,7 @@ const { minify: htmlminify } = require('html-minifier-terser'); const { join: pathJoin, } = require('path'); const { strtr, shortHash, writeFile } = require('../utils.js'); -exports = function(env) { +module.exports = function(env) { const PREFIX = '#'; const DEFAULT_ENTRY = 'main.js'; const DEFAULT_VARS_TARGET = 'window'; diff --git a/src/handlers/twig.js b/src/handlers/twig.js index c987cd8..7fccbe3 100644 --- a/src/handlers/twig.js +++ b/src/handlers/twig.js @@ -3,7 +3,7 @@ const { minify: htmlminify } = require('html-minifier-terser'); const { join: pathJoin, dirname } = require('path'); const { strtr, shortHash, writeFile } = require('../utils.js'); -exports = function(env) { +module.exports = function(env) { const MINIFY_OPTS = { collapseBooleanAttributes: true, collapseWhitespace: true, diff --git a/src/handlers/webmanifest.js b/src/handlers/webmanifest.js index 4ca2b82..df33c59 100644 --- a/src/handlers/webmanifest.js +++ b/src/handlers/webmanifest.js @@ -2,7 +2,7 @@ const fs = require('fs'); const { join: pathJoin, dirname } = require('path'); const { strtr, shortHash, writeFile } = require('../utils.js'); -exports = function(env) { +module.exports = function(env) { return { process: async (task, vars) => { let body = JSON.parse(fs.readFileSync(pathJoin(env.source, task.source))); diff --git a/src/housekeep.js b/src/housekeep.js index ea7f00f..db0c668 100644 --- a/src/housekeep.js +++ b/src/housekeep.js @@ -1,7 +1,7 @@ const fs = require('fs'); const { join: pathJoin } = require('path'); -exports.housekeep = path => { +module.exports.housekeep = path => { const files = fs.readdirSync(path).map(fileName => { const stats = fs.statSync(pathJoin(path, fileName)); return { diff --git a/src/index.js b/src/index.js index 01bfcfd..24a5bdb 100644 --- a/src/index.js +++ b/src/index.js @@ -23,7 +23,7 @@ const DEFAULT_ENV = { }, }; -exports.process = async (env, tasks) => { +module.exports.process = async (env, tasks) => { if(typeof env.source !== 'string') throw 'env.source must be a path to the source directories'; if(typeof env.public !== 'string') diff --git a/src/trim.js b/src/trim.js index e1ba52a..e5e7f7f 100644 --- a/src/trim.js +++ b/src/trim.js @@ -16,6 +16,8 @@ const trim = (str, chars = " \n\r\t\v\0", flags = 0) => { return str; }; -exports.trimStart = (str, chars) => trim(str, chars, 0x01); -exports.trimEnd = (str, chars) => trim(str, chars, 0x02); -exports.trim = (str, chars) => trim(str, chars, 0x03); +module.exports = { + trimStart: (str, chars) => trim(str, chars, 0x01), + trimEnd: (str, chars) => trim(str, chars, 0x02), + trim: (str, chars) => trim(str, chars, 0x03), +} diff --git a/src/utils.js b/src/utils.js index 7defc77..634f86c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,17 +2,17 @@ const crypto = require('crypto'); const fs = require('fs'); const { dirname } = require('path'); -exports.strtr = (str, replacements) => str.toString().replace( +module.exports.strtr = (str, replacements) => str.toString().replace( /{([^}]+)}/g, (match, key) => replacements[key] || match ); -exports.shortHash = text => { +module.exports.shortHash = text => { const hash = crypto.createHash('sha256'); hash.update(text); return hash.digest('hex').substring(0, 8); }; -exports.writeFile = (path, data) => { +module.exports.writeFile = (path, data) => { const folderPath = dirname(path); if(!fs.existsSync(folderPath)) fs.mkdirSync(folderPath, { recursive: true });