diff --git a/.eslintignore b/.eslintignore index c052660a..b9470778 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,2 @@ node_modules/ -dist/* +dist/ diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3b8e2752..8de94045 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,10 +1,10 @@ module.exports = { + root: true, env: { browser: true, - es2021: true, - node: true + node: true, + es2024: true }, - root: true, parserOptions: { ecmaVersion: 'latest', sourceType: 'module' @@ -24,13 +24,8 @@ module.exports = { } ], rules: { - 'no-unused-vars': 0, - 'import/no-cycle': 2, - 'prettier/prettier': [ - 'error', - { - endOfLine: require('os').EOL === '\r\n' ? 'crlf' : 'lf' - } - ] + 'no-unused-vars': 'off', + 'import/no-cycle': 'error', + 'import/no-named-as-default': 'off' } }; diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 6343dcc8..6ce17cf8 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -8,12 +8,12 @@ #### Expected behaviour - #### Actual behaviour + #### Reproduction steps - + + - diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 859c4425..1ae9eaa8 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -10,24 +10,24 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout Repository - uses: actions/checkout@v4 + - name: Checkout Repository + uses: actions/checkout@v4 - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '18.x.x' + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18.x.x' - - name: Install Dependencies - run: npm ci + - name: Install Dependencies + run: npm ci - - name: Build Project - run: npm run build + - name: Build Project + run: npm run build - - name: Commit and Push /dist Directory - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add -f dist/ - git commit -m "Build the dist files after merge." - git push -f + - name: Commit and Push /dist Directory + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add -f dist/ + git commit -m "Build the dist files after merge." + git push -f diff --git a/.github/workflows/eslint-check.yml b/.github/workflows/eslint-check.yml index 62fff57d..ced32323 100644 --- a/.github/workflows/eslint-check.yml +++ b/.github/workflows/eslint-check.yml @@ -1,6 +1,6 @@ name: ESLint check -on: [ pull_request ] +on: [pull_request] jobs: eslint: diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index c23e98f8..e8c755e6 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -2,7 +2,7 @@ name: Unit tests on: pull_request: - branches: [ master ] + branches: [master] jobs: testing: @@ -23,4 +23,4 @@ jobs: - name: Run unit tests run: npm run unit:test env: - CI: true \ No newline at end of file + CI: true diff --git a/.gitignore b/.gitignore index 2541cf9f..2ec1eb07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,21 @@ -node_modules/ +.cache/ +.cert/ +.vscode/ +dist/ log/ -tests/_temp +node_modules/ tmp/ -dist/ -.cert/ +tests/_temp/ +tests/**/_results/ -.DS_Store -.cache -.vscode .env .eslintcache - -tests/**/_results/ - +.DS_Store resources.json +**/*.jpeg +**/*.jpg **/*.png **/*.pdf **/*.svg -**/*.jpeg **/*.log diff --git a/.husky/pre-commit b/.husky/pre-commit index 23f686fd..c2f708b1 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1,2 @@ -npm run lint +npx lint-staged npm run unit:test diff --git a/.lintstagedrc b/.lintstagedrc index 9893929d..27fe4b1b 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,3 +1,4 @@ { - "lib/**/\*.{js,json}": ["eslint", "npx prettier --write"] + "*.{js,ts}": ["npm run lint"], + "*.{json,css,md}": ["npm run format"] } diff --git a/.prettierignore b/.prettierignore index b2c47ad0..9472174b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ node_modules/ -dist/* -README.md +dist/ + +samples/cli/infileNotJson.json diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 986543e8..00000000 --- a/.prettierrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "semi": true, - "singleQuote": true, - "tabWidth": 2, - "printWidth": 80, - "trailingComma": "none" -} diff --git a/.prettierrc.cjs b/.prettierrc.cjs new file mode 100644 index 00000000..08045407 --- /dev/null +++ b/.prettierrc.cjs @@ -0,0 +1,8 @@ +module.exports = { + trailingComma: 'none', + endOfLine: 'auto', + tabWidth: 2, + printWidth: 80, + semi: true, + singleQuote: true +}; diff --git a/CHANGELOG.md b/CHANGELOG.md index 9254b1bb..c6e8ac1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,30 @@ +# 4.1.0 + +_Enhancements:_ + +- Made corrections and enhancements to all configuration files (`ESLint`, `Prettier`, `lint-staged`, `Husky`, `Jest`, `Nodemon`, ignore files, templates, documentation, and workflow files). +- Corrected `package.json` by adding and optimizing content and scripts. +- Made various corrections, mostly stylistic and visual, to the `CHANGELOG.md` and `README.md` files. +- Removed the unnecessary `install.js` file. +- Enhancements in samples and tests. +- Renamed all files to use `camelCase` notation. +- Linted and formatted all files. + # 4.0.2 _Hotfix_: -- Fixed missing 'msg' and 'public' bundle in 4.0.1 on NPM. +- Fixed missing `msg` and `public` folders for a bundle in `v4.0.1` on NPM. _Fixes:_ -- Made chart userOptions available within `customCode` as variable `options` [(#551)](https://github.com/highcharts/node-export-server/issues/551). +- Made chart `userOptions` available within `customCode` as variable `options` [(#551)](https://github.com/highcharts/node-export-server/issues/551). # 4.0.1 _Hotfix_: -- Fixed missing 'dist' bundle in 4.0.0 on NPM. +- Fixed missing `dist` folder for a bundle in `v4.0.0` on NPM. # 4.0.0 @@ -30,7 +42,7 @@ _Breaking Changes:_ _New Features:_ -- Implemented debug mode, including new environment variables, a config section, 'console' event listener, and npm script for debugging the headful Puppeteer browser. +- Implemented debug mode, including new environment variables, a config section, `console` event listener, and npm script for debugging the headful Puppeteer browser. - Added the `HIGHCHARTS_CACHE_PATH` option available through `.env` to set a custom directory for the fetched files. - Added a moving average indicator for the exporting success rate ratio. @@ -41,10 +53,10 @@ _Enhancements:_ - Introduced two new types of custom errors: `ExportError` for functionality-related errors and `HttpError` for server-related errors. - Introduced a new error logging mechanism with stack tracing using new function called `logWithStack`. - Expanded some error logs with request IDs. -- Set headless mode to 'shell' for better performance, utilizing an older yet more efficient headless instance. +- Set headless mode to `shell` for better performance, utilizing an older yet more efficient headless instance. - Set the `defaultViewport` to null and optimized code to trigger `setViewport` only once, reducing performance impact during export. - Removed unnecessary initial page on browser launch using `waitForInitialPage` and the `--no-startup-window` Chrome flag. -- Revised Chromium flags sent to the browser, now located in the args array within the config file. +- Revised Chromium flags sent to the browser, now located in the `args` array within the config file. - Optimized code by reducing evaluate function calls to enhance performance and minimize jumping between NodeJS and browser processes. - Optimized and moved chart creation initialization scripts from the HTML template to a separate module named `highcharts.js`. - Optimized the `clearPage` function to ensure content cleaning is only performed once, during resource release. @@ -54,13 +66,13 @@ _Enhancements:_ - Optimized adding and releasing additional JS and CSS resources. - Made corrections for gracefully shutting down resources, including running servers, ongoing intervals, browser instance, created pages, and workers pool. - Updated `createImage` and `createPDF` functions with faster execution options including `optimizeForSpeed` and `quality`. -- Set `waitUntil` to 'domcontentloaded' for `setContent` and `goto` functions to improve performance. +- Set `waitUntil` to `'domcontentloaded'` for `setContent` and `goto` functions to improve performance. - Replaced browser's deprecated `isConnected()` with the `connected` property. - Added information on all available pool resources. - Numerous minor improvements for performance and stability. - Moved the `listenToProcessExits` from the `pool` to the `other` section of the options. - Replaced the temporary benchmark module with a simpler server benchmark for evaluating export time. -- Removed unnecessary separate `body-parser` package (already implemented in Express v4.16+). +- Removed unnecessary separate `body-parser` package (already implemented in Express `v4.16+`). - Added parsing of envs based on `zod` package. - Added unit tests for certain parts of the code. - Added the `shutdownCleanUp` function for resource release (ending intervals, closing servers, destroying the pool and browser) on shutdown. It will be called in the process exit handlers. @@ -69,11 +81,13 @@ _Enhancements:_ - Added several new functions to the `highcharts-export-server` module, including `initPool`, `logWithStack`, `setLogLevel`, `enableFileLogging`, `manualConfig`, `printLogo`, and `printUsage`. - Added a new `initLogging` function where the `setLogLevel` and `enableFileLogging` logic are consolidated into one place. - Added a new utility function, `isObjectEmpty`. +- Added two new logging options, `--logToConsole` and `--logToFile`, to explicitly set where log messages are sent. - Added a new logging level (`5`) for benchmarking logs. -- Added legacy names of options to the `defaultConfig` and `mapToNewConfig` function in order to support the old, PhantomJS-based structure of options. +- Added legacy names of options to the `defaultConfig` and `mapToNewConfig` function in order to support the old, `PhantomJS` based structure of options. - Added a new process event handler for the `SIGHUP` signal. - Added `mapChart` and `ganttChart` constructors in the exporting UI [(#503)](https://github.com/highcharts/node-export-server/issues/503). -- Added the series-on-point module [(#532)](https://github.com/highcharts/node-export-server/issues/532). +- Added the `series-on-point` module [(#532)](https://github.com/highcharts/node-export-server/issues/532). +- Added other missing modules (`navigator` and `textpath`). - Updates were made to the `config.js` file. - Updated the `killPool` function. - The `uncaughtException` handler now kills the pool, browser, and terminates the process with exit code 1, when enabled. @@ -90,18 +104,18 @@ _Enhancements:_ _Fixes:_ -- Fixed `multer` related error: 'Field value too long'. +- Fixed `multer` related error: `'Field value too long'`. - Fixed the SSL handshake error [(#307)](https://github.com/highcharts/node-export-server/issues/307). - Fixed missing background color transparency [(#492)](https://github.com/highcharts/node-export-server/issues/492). - Fixed missing `foreignObject` elements issue. - Fixed type compatibility issues in the `pairArgumentValue` function, arising from CLI string arguments. -- Fixed the 'httpsProxyAgent is not a constructor' issue with the `https-proxy-agent` module. +- Fixed the `'httpsProxyAgent is not a constructor'` issue with the `https-proxy-agent` module. - Fixed the issue of being unable to run both HTTP and HTTPS servers simultaneously. - Fixed the issue with the `multiselect` type of values in prompt functionality triggered by the `--createConfig` option. - Fixed the error handling in the `postWork` function which resulted in doubled errors. - Fixed the deprecated description of the pool from the `generic-pool` to `tarn` notation, triggered by the `getPoolInfo` and `getPoolInfoJSON` functions. - Fixed the issue of not gracefully terminating the process when an error occurs and a pool or browser already exists. -- Fixed the 'Could not clear the content of the page... - Target closed' error. +- Fixed the `'Could not clear the content of the page... - Target closed'` error. - Made minor corrections to ESLint and Prettier configuration. - Other minor stability, linting and text corrections have been implemented. @@ -148,15 +162,15 @@ _Fixes:_ # 3.0.2 -- Changed the priority of loading options to: config -> custom JSON -> envs -> CLI. +- Changed the priority of loading options to: `config -> custom JSON -> envs -> CLI`. - Corrected the The unhandledRejection error, message: Protocol error: Connection closed. Most likely the page has been closed, an error related to closing the browser earlier than closing each of an active page. -- Refactored the way options are set (the setOptions function). -- Corrected straight inject with JS functions in chart's options (e.g. formatter), when the allowCodeExecution is set to true. -- Organized code into two separate functions (singleExport and batchExport). +- Refactored the way options are set (the `setOptions` function). +- Corrected straight inject with JS functions in chart's options (e.g. formatter), when the `allowCodeExecution` is set to true. +- Organized code into two separate functions (`singleExport` and `batchExport`). - Corrected reseting global options for Highcharts between each export. - Corrections for the linter. - Samples and tests corrections. -- Added sample for the loadConfig option. +- Added sample for the `loadConfig` option. - Updated README. - Other small fixes. @@ -168,7 +182,7 @@ _Fixes:_ _Fixes and enhancements:_ -- Replaced PhantomJS with Puppeteer. +- Replaced `PhantomJS` with `Puppeteer`. - Updated the config handling system to optionally load JSON files, and improved environment var loading. - Rewrote the HC caching system: it's now easier to include custom modules/dependency lists in your own deployments. - The install step no longer requires interaction when installing. @@ -189,35 +203,33 @@ This version is not backwards compatible out of the box! _Breaking changes:_ -- Log destinations must now exist before starting file logging +- Log destinations must now exist before starting file logging. - When running in server mode, the following options are now disabled by default: - `callback` - `resources` - `customCode` -Disabled options can be enabled by adding the `--allowCodeExecution` flag when -starting the server. Using this flag is not recommended, and should not be -done unless the server is sandboxed and not reachable on the public internet. +Disabled options can be enabled by adding the `--allowCodeExecution` flag when starting the server. Using this flag is not recommended, and should not be done unless the server is sandboxed and not reachable on the public internet. _Changelog:_ - Added the `--allowCodeExecution` flag which is now required to be set when exporting pure JavaScript, using additional external resources, or using callback when running in server mode. - Removed the `mkdirp` dependency. - SVG exporting will now block JavaScript entirely. -- Added the `navigationLocked` flag to the Phantom page, which blocks e.g. `