{"action":"created","issue":{"url":"https://api.github.com/repos/aws/amazon-cognito-identity-js/issues/108","repository_url":"https://api.github.com/repos/aws/amazon-cognito-identity-js","labels_url":"https://api.github.com/repos/aws/amazon-cognito-identity-js/issues/108/labels{/name}","comments_url":"https://api.github.com/repos/aws/amazon-cognito-identity-js/issues/108/comments","events_url":"https://api.github.com/repos/aws/amazon-cognito-identity-js/issues/108/events","html_url":"https://github.com/aws/amazon-cognito-identity-js/pull/108","id":171579855,"number":108,"title":"Modernize Javascript, tooling, UMD build (eg Webpack).","user":{"login":"simonbuchan","id":1840547,"avatar_url":"https://avatars.githubusercontent.com/u/1840547?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbuchan","html_url":"https://github.com/simonbuchan","followers_url":"https://api.github.com/users/simonbuchan/followers","following_url":"https://api.github.com/users/simonbuchan/following{/other_user}","gists_url":"https://api.github.com/users/simonbuchan/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbuchan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbuchan/subscriptions","organizations_url":"https://api.github.com/users/simonbuchan/orgs","repos_url":"https://api.github.com/users/simonbuchan/repos","events_url":"https://api.github.com/users/simonbuchan/events{/privacy}","received_events_url":"https://api.github.com/users/simonbuchan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-08-17T05:52:35Z","updated_at":"2016-08-18T21:17:23Z","closed_at":"2016-08-18T01:49:56Z","pull_request":{"url":"https://api.github.com/repos/aws/amazon-cognito-identity-js/pulls/108","html_url":"https://github.com/aws/amazon-cognito-identity-js/pull/108","diff_url":"https://github.com/aws/amazon-cognito-identity-js/pull/108.diff","patch_url":"https://github.com/aws/amazon-cognito-identity-js/pull/108.patch"},"body":"Fixes #48.\r\n\r\nUse modern tooling while maintaining compatibility:\r\n- Add npm scripts to run local dev tool packages: eg `npm run build`\r\n- linting with ESLint, using the most popular preset `airbnb-base` (i.e. no react) as much as possible\r\n- build bundle with `webpack` as UMD\r\n- transpile with `babel`, using `es2015` preset\r\n- docs are still jsdoc :)\r\n\r\nLinting now checks jsdocs aggressively, so I fiiled them out (double-checking I got these right would help!)\r\n\r\n`airbnb-base` ruleset is fairly aggressive, in particular it rejects `if { ...; return x; } else { ... }`, so some re-ordering was needed (done with IntelliJ intentions to avoid typos)\r\n\r\nWebpack configured to build a UMD bundle now, so it is usable directly from bundlers.\r\n- In node / requirejs / amd usage, uses `require(\"aws-sdk\")`\r\n- In `<script>` / concat usage, still uses global `AWSCognito` for compat.\r\n- `jsbn` (for `BigInteger`) and `sjcl` deps are npm peer dependencies excluded from the bundle to respect licensing concerns by AWS.\r\n\r\nWith babel now tranpiling, use es2015 modules and classes for source.\r\n\r\nI would like to get some node tests in there with `ava`, but it would require factoring out the browser dependencies, mostly the `localStorage` stuff if the `aws-sdk` import can be shimmed.\r\n\r\nExample webpack client usage is mostly working around npm `aws-sdk` not being UMD (?):\r\n\r\n```\r\n// aws-sdk's `browser` package prop pointing at `lib/browser.js` is picked up by default,\r\n// but doesn't webpack correctly due to still having dynamic `require()` calls that match\r\n// server-only code.\r\n// Simple fix is to point it at the bundle, a better fix would be disabling the automatic\r\n// resolve contexts: https://webpack.github.io/docs/configuration.html#automatically-created-contexts-defaults-module-xxxcontextxxx\r\n// but then you need to include the services yourself, see aws-sdk/dist-tools/service-collector\r\n\r\nvar AWS_SDK_MAIN = require.resolve('aws-sdk/dist/aws-sdk.min.js');\r\n\r\nmodule.exports = {\r\n  // entry, outputs as usual...\r\n  resolve: {\r\n    alias: {\r\n      'aws-sdk$': AWS_SDK_MAIN\r\n    }\r\n  },\r\n  module: {\r\n    noParse: /aws-sdk/, // shut up warnings about it being already built\r\n    loaders: [\r\n      { test: AWS_SDK_MAIN, loader: 'exports?AWS' },\r\n      // ... your loaders, eg js -> babel\r\n    ]\r\n  }\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/aws/amazon-cognito-identity-js/issues/comments/240859778","html_url":"https://github.com/aws/amazon-cognito-identity-js/pull/108#issuecomment-240859778","issue_url":"https://api.github.com/repos/aws/amazon-cognito-identity-js/issues/108","id":240859778,"user":{"login":"simonbuchan","id":1840547,"avatar_url":"https://avatars.githubusercontent.com/u/1840547?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbuchan","html_url":"https://github.com/simonbuchan","followers_url":"https://api.github.com/users/simonbuchan/followers","following_url":"https://api.github.com/users/simonbuchan/following{/other_user}","gists_url":"https://api.github.com/users/simonbuchan/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbuchan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbuchan/subscriptions","organizations_url":"https://api.github.com/users/simonbuchan/orgs","repos_url":"https://api.github.com/users/simonbuchan/repos","events_url":"https://api.github.com/users/simonbuchan/events{/privacy}","received_events_url":"https://api.github.com/users/simonbuchan/received_events","type":"User","site_admin":false},"created_at":"2016-08-18T21:17:23Z","updated_at":"2016-08-18T21:17:23Z","body":"@itrestian sure, I'd like to figure out if there's a decent way to deal with `aws-sdk` and possibly mention other bundler options like rollup, but I can get this example added at least.\r\n\r\nAs the updated example comment mentions I'm currently using a slightly more fiddly build which means you don't need a custom `aws-sdk` build, but I'd like to see what other options there are, eg `import S3 from 'aws-sdk!s3'`."}}
{"actor":{"display_login":"simonbuchan"}}