Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(.husky/commit-msg): remove npx usage #589

Merged
merged 11 commits into from
Jul 30, 2024
14 changes: 13 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ jobs:
# Staying on v3 due to incomplete migration guide for v4
uses: google-github-actions/release-please-action@v3
with:
changelog-types: '[ { "type": "feat", "section": "Features", "hidden": false }, { "type": "fix", "section": "Bug fixes", "hidden": false }, { "type": "build", "section": "Dependencies", "hidden": false }, { "type": "chore", "section": "Miscellaneous", "hidden": false }, { "type": "ci", "section": "Continuous integration", "hidden": false }, { "type": "perf", "section": "Improvements", "hidden": false }, { "type": "refactor", "section": "Improvements", "hidden": false }, { "type": "style", "section": "Miscellaneous", "hidden": false }, { "type": "docs", "section": "Documentation", "hidden": false }]'
changelog-types: >
[
{ "section": "Bug fixes", "type": "fix", "hidden": false },
{ "section": "Continuous integration", "type": "ci", "hidden": false },
{ "section": "Dependencies", "type": "build", "hidden": false },
{ "section": "Documentation", "type": "docs", "hidden": false },
{ "section": "Features", "type": "feat", "hidden": false },
{ "section": "Improvements", "type": "perf", "hidden": false },
{ "section": "Improvements", "type": "refactor", "hidden": false },
{ "section": "Miscellaneous", "type": "chore", "hidden": false },
{ "section": "Miscellaneous", "type": "style", "hidden": false },
{ "section": "Tests", "type": "test", "hidden": false }
]
release-type: node
package-name: node-poppler

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
if: github.event.pull_request.draft == false
strategy:
matrix:
node-version: [18, 20]
node-version: [18, 20, 22]
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -127,7 +127,9 @@ jobs:

- name: Install Ubuntu dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get -y install poppler-data poppler-utils
run: |
sudo apt-get -q update
sudo apt-get -y --no-install-recommends install poppler-data poppler-utils

- name: Run tests
run: npm run jest:coverage
Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npx --no-install commitlint --edit $1
commitlint --edit $1
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"author": "Frazer Smith <[email protected]>",
"funding": "https://github.com/sponsors/Fdawgs",
"engines": {
"node": ">=18.0.0"
"node": ">=18"
},
"scripts": {
"build": "tsc",
Expand Down Expand Up @@ -86,30 +86,31 @@
"testTimeout": 60000
},
"devDependencies": {
"@commitlint/cli": "^19.1.0",
"@commitlint/config-conventional": "^19.1.0",
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
"@types/jest": "^29.5.12",
"@types/semver": "^7.5.8",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-regexp": "^2.3.0",
"eslint-plugin-security": "^2.1.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jsdoc": "^48.9.1",
"eslint-plugin-promise": "^7.0.0",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-security": "^3.0.1",
"glob": "^10.3.10",
"husky": "^9.0.11",
"husky": "^9.1.3",
"jest": "^29.7.0",
"license-checker": "^25.0.1",
"prettier": "^3.2.5",
"prettier": "^3.3.3",
"spdx-copyleft": "^1.0.0",
"typescript": "^5.4.2"
"typescript": "^5.5.4"
},
"dependencies": {
"camelcase": "^6.3.0",
"semver": "^7.6.0",
"semver": "^7.6.3",
"upath": "^2.0.1"
}
}
69 changes: 34 additions & 35 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,46 @@

"use strict";

const { execFile } = require("node:child_process");
const { execFile, spawnSync } = require("node:child_process");
const { access, readFile, unlink } = require("node:fs/promises");
const { promisify } = require("node:util");
const { glob } = require("glob");
const { lt } = require("semver");
const { joinSafe } = require("upath");
const { joinSafe, normalizeTrim } = require("upath");

const execFileAsync = promisify(execFile);
const { Poppler } = require("./index");

const testDirectory = `${__dirname}/../test_resources/test_files/`;
const file = `${testDirectory}pdf_1.3_NHS_Constitution.pdf`;

const windowsPath = joinSafe(
__dirname,
"lib",
"win32",
"poppler-24.02.0",
"Library",
"bin"
);
let testBinaryPath;
switch (process.platform) {
// macOS
case "darwin":
testBinaryPath = "/usr/local/bin";
break;

case "linux":
testBinaryPath = "/usr/bin";
break;

// Windows OS
case "win32":
default:
testBinaryPath = windowsPath;
break;
/**
* @description Returns the path to the poppler-util binaries based on the OS.
* @returns {string} The path to the poppler-util binaries.
*/
function getTestBinaryPath() {
const { platform } = process;
const which = spawnSync(platform === "win32" ? "where" : "which", [
"pdfinfo",
]).stdout.toString();
let popplerPath = /(.+)pdfinfo/u.exec(which)?.[1];

if (platform === "win32" && !popplerPath) {
popplerPath = joinSafe(
__dirname,
"lib",
"win32",
"poppler-24.02.0",
"Library",
"bin"
);
}

return normalizeTrim(popplerPath);
}

const testBinaryPath = getTestBinaryPath();

describe("Node-Poppler module", () => {
afterEach(async () => {
// Remove leftover test files
Expand All @@ -66,6 +67,10 @@ describe("Node-Poppler module", () => {
({ platform } = process);
});

beforeEach(() => {
jest.resetModules();
});

afterEach(() => {
// Restore the process platform
Object.defineProperty(process, "platform", {
Expand All @@ -78,19 +83,13 @@ describe("Node-Poppler module", () => {
expect(poppler.popplerPath).toBe(testBinaryPath);
});

/**
* @todo Fix this test, mocking of "node:" scheme not supported yet.
* @see {@link https://github.com/jestjs/jest/pull/14297 | Jest PR #14297}
*/
// eslint-disable-next-line jest/no-disabled-tests -- Blocked by Jest PR #14297
it.skip("Throws an Error if the binary path is not found", () => {
it("Throws an Error if the binary path is not found", () => {
Object.defineProperty(process, "platform", {
value: "mockOS",
});

// Ensure the mock is used by the UnRTF constructor
jest.resetModules();
jest.mock("node:child_process", () => ({
jest.doMock("node:child_process", () => ({
...jest.requireActual("node:child_process"),
spawnSync: jest.fn(() => ({
stdout: {
toString: () => "",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"moduleResolution": "NodeNext",
"outDir": "types",
"resolveJsonModule": true,
"target": "ES2022"
"target": "ES2023"
},
"include": ["src/index.js"]
}