-
Notifications
You must be signed in to change notification settings - Fork 364
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
[SDK-1379] Export constructor #385
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { whenReady } from '../support/utils'; | ||
|
||
describe('initialisation', function() { | ||
beforeEach(cy.resetTests); | ||
|
||
it('should expose a factory method and constructor', function(done) { | ||
whenReady().then(win => { | ||
assert.isFunction( | ||
win.createAuth0Client, | ||
'The createAuth0Client function should be declared on the window.' | ||
); | ||
assert.isFunction( | ||
win.Auth0Client, | ||
'The Auth0Client constructor should be declared on the window.' | ||
); | ||
done(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,16 @@ const getPlugins = shouldMinify => { | |
sourcemaps() | ||
]; | ||
}; | ||
const footer = `('Auth0Client' in this) && this.console && this.console.warn && this.console.warn('Auth0Client already declared on the global namespace'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the changes to this file in context of the PR description - should this be something separate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exposes the constructor on the window object (as Similar to how Marionette provides the alias There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the idea here is to provide a warning in the browser console when there is already an @adamjmcgrath can you remind me of the behaviour here? Does it override it, or do we not override it in favour of the object that was already there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't override |
||
this && this.${EXPORT_NAME} && (this.Auth0Client = this.Auth0Client || this.${EXPORT_NAME}.Auth0Client);`; | ||
|
||
let bundles = [ | ||
{ | ||
input: 'src/index.ts', | ||
input: 'src/index.cjs.ts', | ||
output: { | ||
name: EXPORT_NAME, | ||
file: 'dist/auth0-spa-js.development.js', | ||
footer, | ||
format: 'umd' | ||
}, | ||
plugins: [ | ||
|
@@ -62,11 +65,12 @@ let bundles = [ | |
if (isProduction) { | ||
bundles = bundles.concat( | ||
{ | ||
input: 'src/index.ts', | ||
input: 'src/index.cjs.ts', | ||
output: [ | ||
{ | ||
name: EXPORT_NAME, | ||
file: pkg.browser, | ||
file: 'dist/auth0-spa-js.production.js', | ||
footer, | ||
format: 'umd' | ||
} | ||
], | ||
|
@@ -86,7 +90,7 @@ if (isProduction) { | |
plugins: getPlugins(isProduction) | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
input: 'src/index.cjs.ts', | ||
output: [ | ||
{ | ||
name: EXPORT_NAME, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import createAuth0Client, { Auth0Client } from './index'; | ||
|
||
export default Object.assign(createAuth0Client, { | ||
Auth0Client, | ||
createAuth0Client | ||
}); |
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.
Why is this removed?
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.
Webpack resolves the library by checking the package properties in this order: "browser" -> "module" -> "main"
This is designed so that if you have a library that provides a different flavour for nodejs and the browser (like
axios
)We only have one flavour, browser, but we do want to provide an optimized es module version to webpack (or any build tool that prefers es modules). So if we delete "browser" webpack will use module and get the benefits of esm (tree shaking, named exports), things that use commonjs (like browserify) will use "main"