Skip to content

Commit

Permalink
Merge pull request #29 from Sparticuz/feature/esm
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparticuz authored Feb 8, 2023
2 parents 24f9733 + 6e8b7f4 commit bab2d23
Show file tree
Hide file tree
Showing 13 changed files with 1,209 additions and 1,306 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// eslint-disable-next-line import/no-extraneous-dependencies, n/no-unpublished-require
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
extends: ["@sparticuz/eslint-config"],
parserOptions: {
ecmaVersion: 2021,
ecmaVersion: 2022,
project: "./tsconfig.json",
sourceType: "module",
},
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ const options = {
await decrypt(options);
```
## CJS
If you use CJS, you'll need to specify the function you want to require.
```
const decrypt = require("node-qpdf").decrypt;
```
## Coverage
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------|---------|----------|---------|---------|-------------------
Expand Down
2,410 changes: 1,159 additions & 1,251 deletions package-lock.json

Large diffs are not rendered by default.

65 changes: 32 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
"name": "node-qpdf2",
"version": "4.1.0",
"description": "A Content Preserving transformations on PDFs wrapped around QPDF",
"main": "./dist/index.js",
"scripts": {
"test": "c8 --reporter=lcov --reporter=text --all --include=src ava test/ --timeout=30s",
"lint": "eslint --ignore-path .gitignore '**/*.[jt]s'",
"build": "tsc -p tsconfig.build.json"
},
"engines": {
"node": ">=14.18.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Sparticuz/node-qpdf2.git"
},
"keywords": [
"pdf",
"qpdf",
Expand All @@ -31,33 +18,45 @@
"rc4-128",
"rc4-40"
],
"author": "Kyle McNally <[email protected]>",
"homepage": "https://github.com/Sparticuz/node-qpdf2",
"bugs": {
"url": "https://github.com/Sparticuz/node-qpdf2/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Sparticuz/node-qpdf2.git"
},
"license": "MIT",
"author": "Kyle McNally <[email protected]>",
"type": "module",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --ignore-path .gitignore '**/*.[jt]s'",
"test": "c8 --reporter=lcov --reporter=text --all --include=src ava test/ --timeout=30s"
},
"ava": {
"extensions": [
"ts"
],
"require": [
"ts-node/register/transpile-only"
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm/transpile-only"
]
},
"types": "./dist/index.d.ts",
"bugs": {
"url": "https://github.com/Sparticuz/node-qpdf2/issues"
},
"homepage": "https://github.com/Sparticuz/node-qpdf2",
"devDependencies": {
"@rushstack/eslint-patch": "^1.2.0",
"@sparticuz/eslint-config": "^7.1.11",
"@tsconfig/node14": "^1.0.3",
"@types/node": "^14.18.29",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"ava": "^5.1.0",
"@sparticuz/eslint-config": "^7.2.0",
"@tsconfig/node16-strictest-esm": "^1.0.3",
"@types/node": "^18.13.0",
"ava": "^5.2.0",
"c8": "^7.12.0",
"eslint": "^8.31.0",
"prettier": "^2.8.1",
"eslint": "^8.33.0",
"prettier": "^2.8.4",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"typescript": "^4.9.5"
},
"engines": {
"node": ">=16"
}
}
4 changes: 2 additions & 2 deletions src/decrypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileExists } from "./utils";
import execute from "./spawn";
import { fileExists } from "./utils.js";
import execute from "./spawn.js";

export interface DecryptSettings {
/** The path for the encrypted pdf */
Expand Down
4 changes: 2 additions & 2 deletions src/encrypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import execute from "./spawn";
import { fileExists, hyphenate } from "./utils";
import execute from "./spawn.js";
import { fileExists, hyphenate } from "./utils.js";

const EncryptDefaults = {
keyLength: 256,
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type { DecryptSettings } from "./decrypt";
export { decrypt } from "./decrypt";
export type { EncryptOptions } from "./encrypt";
export { encrypt } from "./encrypt";
export type { DecryptSettings } from "./decrypt.js";
export { decrypt } from "./decrypt.js";
export type { EncryptOptions } from "./encrypt.js";
export { encrypt } from "./encrypt.js";
6 changes: 3 additions & 3 deletions src/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export default (callArguments: string[]): Promise<Buffer> => {
reject(error);
});
process.on("close", (code) => {
if (code !== 0) {
if (code === 0) {
resolve(Buffer.from(stdout.join("")));
} else {
// There is a problem from qpdf
reject(Buffer.from(stderr.join("")).toLocaleString());
} else {
resolve(Buffer.from(stdout.join("")));
}
});
});
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export const hyphenate = (variable: string): string =>
* @param file the path of the file to be tested.
*/
export const fileExists = (file: string): boolean => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
return !!existsSync(file);
};
2 changes: 1 addition & 1 deletion test/decrypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "ava";
import { decrypt } from "../src/decrypt";
import { decrypt } from "../src/decrypt.js";

test("Should not work if no input file is specified", async (t) => {
// @ts-expect-error This is what I'm testing
Expand Down
2 changes: 1 addition & 1 deletion test/encrypt-and-decrypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "ava";
import { encrypt, decrypt } from "../src";
import { encrypt, decrypt } from "../src/index.js";

const input = "test/example.pdf";

Expand Down
2 changes: 1 addition & 1 deletion test/encrypt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from "ava";
import { copyFile } from "node:fs/promises";
import { encrypt } from "../src/encrypt";
import { encrypt } from "../src/encrypt.js";

const input = "test/example.pdf";
const password = "1234";
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"extends": "@tsconfig/node16-strictest-esm/tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "dist",
Expand Down

0 comments on commit bab2d23

Please sign in to comment.