Skip to content

Commit fca039d

Browse files
committedJul 14, 2020
fix: Add a nicer exported ESM wrapper and tweak the commonjs exported module
1 parent 5badee6 commit fca039d

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed
 

‎bin/web-ext

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
var webExt = require('../dist/web-ext').default;
3+
var webExt = require('../dist/web-ext');
44
var path = require('path');
55
var absolutePackageDir = path.join(path.resolve(__dirname), '..');
66

‎index.mjs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This module provides a nicer ESM module wrapper around the module generated by webpack.
2+
3+
// NOTE: disabled eslint rules:
4+
// - import/extensions: we need the explicit .js here to force node to look for the .js file instead of
5+
// looking for a .mjs file.
6+
// - import/no-unresolved: the dist/web-ext.js file has likely not build yet when this runs in the CI jobs
7+
// and this is also covered by automated tests (which would catch an unresolved import issue here).
8+
//
9+
// eslint-disable-next-line import/extensions, import/no-unresolved
10+
import webext from './dist/web-ext.js';
11+
12+
export default webext;
13+
export const {cmd, main, util} = webext;

‎package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
"version": "4.3.0",
44
"description": "A command line tool to help build, run, and test web extensions",
55
"main": "dist/web-ext.js",
6+
"exports": {
7+
"import": "./index.mjs",
8+
"require": "./dist/web-ext.js"
9+
},
610
"files": [
711
"CODE_OF_CONDUCT.md",
12+
"README.md",
813
"dist/*.js",
9-
"src/**"
14+
"src/**",
15+
"index.mjs"
1016
],
1117
"engines": {
1218
"node": ">=10.0.0",

‎scripts/lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
},
1515
eslint: {
1616
files: [
17-
'.', './src/**/*.js', './tests/**/*.js', './scripts/**',
17+
'.', './index.mjs', './src/**/*.js', './tests/**/*.js', './scripts/**',
1818
],
1919
},
2020
mocha: {

‎webpack.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ module.exports = {
2929
path: path.join(__dirname, 'dist'),
3030
filename: 'web-ext.js',
3131
libraryTarget: 'commonjs2',
32+
// Force webpack bundled module to export the content
33+
// of the default export.
34+
libraryExport: 'default',
3235
},
3336
module: {
3437
rules,

0 commit comments

Comments
 (0)
Please sign in to comment.