From 809a48cb2c835b8f08a15eb0b949e1718649c719 Mon Sep 17 00:00:00 2001 From: Otto Kruse Date: Tue, 1 Feb 2022 14:14:42 +0100 Subject: [PATCH] Fix: include typing-util.d.ts in published bundle (#54) * Include typing-util.d.ts in published bundle, add some more ts compilation tests * Tweak tests and npm scripts * Use latest npm --- .github/workflows/main.yml | 3 ++- package.json | 12 ++++++----- tests/cognito/package.json | 2 +- tests/import-tests/package.json | 2 +- tests/import-tests/should-not-compile.ts | 21 +++++++++++++++++++ .../tsconfig-should-not-compile.json | 4 ++++ tests/import-tests/tsconfig.json | 4 ++++ .../installation-and-basic-usage/package.json | 2 +- tests/unit/tsconfig.json | 4 ++++ 9 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 tests/import-tests/should-not-compile.ts create mode 100644 tests/import-tests/tsconfig-should-not-compile.json create mode 100644 tests/import-tests/tsconfig.json create mode 100644 tests/unit/tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7cfb56f..5b47974 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,12 +16,13 @@ jobs: node-version: "14" - name: install run: | + npm install -g npm npm install - name: test run: | npm run prettier:check npm run lint:check npm run test:unit - npm run dist + npm run pack-for-tests npm run test:install npm run test:import diff --git a/package.json b/package.json index d6448de..ead8907 100644 --- a/package.json +++ b/package.json @@ -12,18 +12,19 @@ "types": "index.d.ts", "module": "dist/esm/index.js", "files": [ - "dist", "asn1.d.ts", "assert.d.ts", "cognito-verifier.d.ts", + "dist", "error.d.ts", "https.d.ts", "index.d.ts", "jwk.d.ts", - "jwt.d.ts", "jwt-model.d.ts", "jwt-rsa.d.ts", - "safe-json-parse.d.ts" + "jwt.d.ts", + "safe-json-parse.d.ts", + "typing-util.d.ts" ], "exports": { ".": { @@ -94,12 +95,13 @@ "dist": "rm -rf dist && npm run dist:cjs && npm run dist:esm && npm run dist:types", "lint:check": "eslint . --ignore-path .gitignore --max-warnings 0", "lint": "eslint . --fix --ignore-path .gitignore --max-warnings 0", - "prepare": "npm run dist", + "pack-for-tests": "rm -f 'aws-jwt-verify-?.?.?.tgz' && npm pack && mv aws-jwt-verify-*.tgz aws-jwt-verify.tgz", + "prepack": "npm run dist", "prettier:check": "prettier --check .", "prettier": "prettier -w .", "test:all": "npm run prettier:check && npm run test:unit && npm run test:install && npm run test:import && npm run test:speed && npm run test:cognito", "test:cognito": "cd tests/cognito && npm run test", - "test:import": "cd tests/import-tests && npm i --prune --force && node esm.mjs && node commonjs.cjs && tsc typescript.ts && node typescript.js", + "test:import": "cd tests/import-tests && rm -rf node_modules package-lock.json && npm install && node esm.mjs && node commonjs.cjs && tsc && node typescript.js && COMPILE_ERRORS=$(2>&1 tsc -p tsconfig-should-not-compile.json || true) && ([ \"$COMPILE_ERRORS\" != \"\" ] || (echo \"Ooops I did compile successfully :(\"; false))", "test:install": "./tests/installation-and-basic-usage/run-tests.sh", "test:speed": "jest -t \"speed\"", "test:unit": "jest --collect-coverage -t \"unit\" --testMatch '**/*.test.ts' --reporters=\"jest-junit\" --reporters=\"default\"", diff --git a/tests/cognito/package.json b/tests/cognito/package.json index 78027ff..77cf580 100644 --- a/tests/cognito/package.json +++ b/tests/cognito/package.json @@ -9,7 +9,7 @@ "watch": "tsc -w", "test": "if [ -f outputs.json ]; then jest; else echo \"ERROR: Deploy stack with AWS resources first: cdk deploy -O outputs.json --toolkit-stack-name AwsJwtVerifyTest-toolkit\"; exit 1; fi", "cdk": "cdk", - "postinstall": "npm pack ../.. && mv aws-jwt-verify-*.tgz aws-jwt-verify.tgz && cd lib/lambda-authorizer && npm install --no-save --force --no-package-lock ../../aws-jwt-verify.tgz" + "postinstall": "(cd ../.. && npm run pack-for-tests) && cd lib/lambda-authorizer && npm install --no-save --force --no-package-lock ../../../../aws-jwt-verify.tgz" }, "devDependencies": { "@aws-cdk/assert": "1.129.0", diff --git a/tests/import-tests/package.json b/tests/import-tests/package.json index 0722cc8..3fa3536 100644 --- a/tests/import-tests/package.json +++ b/tests/import-tests/package.json @@ -6,6 +6,6 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "aws-jwt-verify": "file:../.." + "aws-jwt-verify": "file:../../aws-jwt-verify.tgz" } } diff --git a/tests/import-tests/should-not-compile.ts b/tests/import-tests/should-not-compile.ts new file mode 100644 index 0000000..5ddb5ef --- /dev/null +++ b/tests/import-tests/should-not-compile.ts @@ -0,0 +1,21 @@ +import { JwtRsaVerifier, CognitoJwtVerifier } from "aws-jwt-verify"; + +if (process.env.JUST_CHECKING_IF_THE_BELOW_TS_COMPILES_DONT_NEED_TO_RUN_IT) { + const cognitoVerifier = CognitoJwtVerifier.create({ + userPoolId: "", + }); + // This statement should not compile, + // because `tokenUse` and `clientId` were not provided yet at verifier level. + // Therefore, it should be mandatory now, to provide the 2nd argument, an object + // that specifies at least `tokenUse` and `clientId`: + cognitoVerifier.verify(""); + + const genericVerifier = JwtRsaVerifier.create({ issuer: "" }); + // This statement should not compile, + // because `audience` was not provided yet at verifier level. + // Therefore, it should be mandatory now, to provide the 2nd argument, an object + // that specifies at least `audience`: + genericVerifier.verify(""); +} + +throw new Error("I shouldn't have compiled!"); diff --git a/tests/import-tests/tsconfig-should-not-compile.json b/tests/import-tests/tsconfig-should-not-compile.json new file mode 100644 index 0000000..246de51 --- /dev/null +++ b/tests/import-tests/tsconfig-should-not-compile.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["./should-not-compile.ts"] +} diff --git a/tests/import-tests/tsconfig.json b/tests/import-tests/tsconfig.json new file mode 100644 index 0000000..7b6ac35 --- /dev/null +++ b/tests/import-tests/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["./typescript.ts"] +} diff --git a/tests/installation-and-basic-usage/package.json b/tests/installation-and-basic-usage/package.json index 0150dba..1221e98 100644 --- a/tests/installation-and-basic-usage/package.json +++ b/tests/installation-and-basic-usage/package.json @@ -11,7 +11,7 @@ "author": "", "license": "ISC", "dependencies": { - "aws-jwt-verify": "file:../.." + "aws-jwt-verify": "file:../../aws-jwt-verify.tgz" }, "devDependencies": { "@types/node": "^16.10.2", diff --git a/tests/unit/tsconfig.json b/tests/unit/tsconfig.json new file mode 100644 index 0000000..bb542f3 --- /dev/null +++ b/tests/unit/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["."] +}