Skip to content

Conversation

tyduptyler13
Copy link
Contributor

See #13 and #16

Comment on lines +11 to +14
"types": [
"node",
"node-fetch"
]
Copy link
Contributor Author

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"
Copy link
Contributor Author

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

Comment on lines +1 to +14
{
"extends": "../tsconfig.json",
"files": [
"FusionAuthClientTest.ts"
],
"compilerOptions": {
"types": [
"node",
"node-fetch",
"mocha",
"chai"
]
}
} No newline at end of file
Copy link
Contributor Author

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)

Comment on lines +64 to +67
"browserify-shim": {
"node-fetch": "cross-fetch",
"form-data": "global:FormData"
},
Copy link
Contributor Author

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",
Copy link
Contributor Author

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

Comment on lines +22 to +24
"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",
Copy link
Contributor Author

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

Comment on lines +22 to +24
"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",
Copy link
Contributor Author

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

@tyduptyler13 tyduptyler13 linked an issue Apr 27, 2020 that may be closed by this pull request
@robotdan robotdan merged commit ea9dbf2 into master Apr 28, 2020
@johnjeffers johnjeffers deleted the types-fix branch April 7, 2025 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReferenceError: FormData is not defined Typescript type definitions incomplete for NodeJS

2 participants