Skip to content

Commit 816cc78

Browse files
committed
Export ES2015 modules.
Fixes #83.
1 parent f01d749 commit 816cc78

7 files changed

Lines changed: 52 additions & 23 deletions

File tree

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

.babelrc.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const ignore = [
2+
'**/__test__/**',
3+
]
4+
const presets = [
5+
["@babel/flow"],
6+
["@babel/react"],
7+
["@babel/env"],
8+
]
9+
const plugins = [
10+
"@babel/plugin-transform-runtime",
11+
"@babel/plugin-proposal-object-rest-spread",
12+
"@babel/plugin-proposal-class-properties",
13+
]
14+
15+
module.exports = {
16+
env: {
17+
development: {
18+
ignore,
19+
presets,
20+
plugins,
21+
},
22+
production: {
23+
ignore,
24+
presets,
25+
plugins,
26+
},
27+
test: {
28+
presets,
29+
plugins,
30+
},
31+
module: {
32+
ignore,
33+
presets: [
34+
["@babel/flow"],
35+
["@babel/env", { targets: '', modules: false }],
36+
],
37+
plugins,
38+
},
39+
}
40+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ coverage
22
dist-lib
33
dist-popup
44
lib
5+
module
56
node_modules

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "solid-auth-client",
33
"version": "2.2.10",
44
"description": "Opaquely authenticates solid clients",
5-
"main": "lib/index.js",
6-
"modules": "src/index.js",
5+
"main": "lib/index-default.js",
6+
"module": "module/index.js",
77
"engines": {
88
"node": ">=8.0.0"
99
},
@@ -13,8 +13,7 @@
1313
"dist-lib",
1414
"dist-popup",
1515
"lib",
16-
"src",
17-
"!*/__test__"
16+
"module"
1817
],
1918
"repository": "git@github.com:solid/solid-auth-client.git",
2019
"author": "Daniel Friedman <dfriedman58@gmail.com>",
@@ -39,8 +38,9 @@
3938
"test:dev": "npm run jest -- --watch",
4039
"test:debug": "node --debug-brk ./node_modules/.bin/jest --runInBand src",
4140
"coverage:report": "cat ./coverage/lcov.info | coveralls",
42-
"build": "npm run build:lib && npm run build:lib:umd && npm run build:popup:template",
43-
"build:lib": "rm -rf lib && babel --ignore '__test__' src -d lib",
41+
"build": "npm run build:lib && npm run build:module && npm run build:lib:umd && npm run build:popup:template",
42+
"build:lib": "rm -rf lib && babel src --env-name production -d lib",
43+
"build:module": "rm -rf module && babel src --env-name module -d module",
4444
"build:lib:umd": "webpack --config=./webpack/webpack.lib.config.js -p",
4545
"build:demo": "webpack --config=./webpack/webpack.demo.config.js -p",
4646
"build:popup": "webpack --config=./webpack/webpack.popup.config.js -p && rm ./dist-popup/popup.bundle.js && bin/solid-auth-client.js generate-popup '' dist-popup/popup.html",

src/index-default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Expose the default export for compatibility
2+
module.exports = require('./').default

src/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const SolidAuthClient = require('./solid-auth-client').default
1+
import SolidAuthClient from './solid-auth-client'
22

33
// Export a singleton instance of SolidAuthClient
44
const auth = new SolidAuthClient()
5+
export default auth
56

67
// Bind methods to instance, so they can be invoked as regular functions
78
// (e.g., to pass around the fetch function)
@@ -12,10 +13,6 @@ Object.getOwnPropertyNames(SolidAuthClient.prototype).forEach(property => {
1213
}
1314
})
1415

15-
// Export the instance as an object for backward compatibility
16-
// (should become a default export)
17-
module.exports = auth
18-
1916
// Expose window.SolidAuthClient for backward compatibility
2017
if (typeof window !== 'undefined') {
2118
if ('SolidAuthClient' in window) {

webpack/webpack.lib.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
output: {
2020
filename: '[name].bundle.js',
2121
path: path.resolve(outputDir),
22+
libraryExport: 'default',
2223
library: {
2324
root: ['solid', 'auth'],
2425
amd: 'solid-auth-client',

0 commit comments

Comments
 (0)