Skip to content

Commit

Permalink
Fix: include typing-util.d.ts in published bundle (#54)
Browse files Browse the repository at this point in the history
* Include typing-util.d.ts in published bundle, add some more ts compilation tests

* Tweak tests and npm scripts

* Use latest npm
  • Loading branch information
ottokruse authored Feb 1, 2022
1 parent e3feb11 commit 809a48c
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
".": {
Expand Down Expand Up @@ -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\"",
Expand Down
2 changes: 1 addition & 1 deletion tests/cognito/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/import-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
21 changes: 21 additions & 0 deletions tests/import-tests/should-not-compile.ts
Original file line number Diff line number Diff line change
@@ -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!");
4 changes: 4 additions & 0 deletions tests/import-tests/tsconfig-should-not-compile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["./should-not-compile.ts"]
}
4 changes: 4 additions & 0 deletions tests/import-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["./typescript.ts"]
}
2 changes: 1 addition & 1 deletion tests/installation-and-basic-usage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["."]
}

0 comments on commit 809a48c

Please sign in to comment.