-
Notifications
You must be signed in to change notification settings - Fork 28
Fix types for typescript client #18
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
Conversation
"types": [ | ||
"node", | ||
"node-fetch" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This restricts the default imported types so that we don't automatically get browser types (these literally mean look in the node_modules/@types/
dir for type imports by the same name). Previously we imported all known types (which was a problem).
"build", | ||
"dist" | ||
"dist", | ||
"test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We exclude test so we can use its own tsconfig
{ | ||
"extends": "../tsconfig.json", | ||
"files": [ | ||
"FusionAuthClientTest.ts" | ||
], | ||
"compilerOptions": { | ||
"types": [ | ||
"node", | ||
"node-fetch", | ||
"mocha", | ||
"chai" | ||
] | ||
} | ||
} No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This inherits the parent tsconfig and adds the test file + the test framework types (for type resolution)
"browserify-shim": { | ||
"node-fetch": "cross-fetch", | ||
"form-data": "global:FormData" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is some magic handwaving but basically when we compile the browser version of this project we replace any imports of node-fetch with cross-fetch (so that we can use the default import and name it fetch). We also import form-data for nodejs's benefit and replace it at browser time with the FormData
class in the browser.
"build-browser": "mkdir -p dist && npx browserify index.ts --standalone FusionAuth --debug -p [ tsify --target=es5 ] -o dist/fusionauth-typescript-client.js", | ||
"build-browser-min": "mkdir -p dist && npx browserify index.ts --standalone FusionAuth --debug -p [ tsify --target=es5 ] -t uglifyify | npx uglifyjs --source-map base -o dist/fusionauth-typescript-client.min.js", | ||
"pretest": "npx tsc && mkdir -p dist && npx browserify test/FusionAuthClientTest.ts --debug -t envify -p [ tsify --target=es5 ] -t uglifyify | npx uglifyjs --source-map base -o dist/fusionauth-typescript-client-test.min.js", | ||
"test": "npx mocha build/test/FusionAuthClientTest.js && npx karma start", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little safer on platforms that might pull our repo and not have mocha or karma globally
"build-browser": "mkdir -p dist && npx browserify index.ts --standalone FusionAuth --debug -p [ tsify --target=es5 ] -t browserify-shim -o dist/fusionauth-typescript-client.js", | ||
"build-browser-min": "mkdir -p dist && npx browserify index.ts --standalone FusionAuth --debug -p [ tsify --target=es5 ] -t browserify-shim -t uglifyify | npx uglifyjs --source-map base -o dist/fusionauth-typescript-client.min.js", | ||
"pretest": "npx tsc && npx tsc -p test && mkdir -p dist && npx browserify test/FusionAuthClientTest.ts --debug -t envify -p [ tsify --target=es5 -p test ] -t browserify-shim -t uglifyify | npx uglifyjs --source-map base -o dist/fusionauth-typescript-client-test.min.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the shim to all of our build command lines
"build-browser": "mkdir -p dist && npx browserify index.ts --standalone FusionAuth --debug -p [ tsify --target=es5 ] -t browserify-shim -o dist/fusionauth-typescript-client.js", | ||
"build-browser-min": "mkdir -p dist && npx browserify index.ts --standalone FusionAuth --debug -p [ tsify --target=es5 ] -t browserify-shim -t uglifyify | npx uglifyjs --source-map base -o dist/fusionauth-typescript-client.min.js", | ||
"pretest": "npx tsc && npx tsc -p test && mkdir -p dist && npx browserify test/FusionAuthClientTest.ts --debug -t envify -p [ tsify --target=es5 -p test ] -t browserify-shim -t uglifyify | npx uglifyjs --source-map base -o dist/fusionauth-typescript-client-test.min.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also add a second tsc command here that uses the tsconfig in the test directory
See #13 and #16