Skip to content
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

Use ESModules instead of module.exports (#786) #852

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use ESModules instead of module.exports #786
Konakona-chan committed Oct 11, 2021
commit 58040d0cd08f55ad3e7d2dca27a20a4d68b53f05
20 changes: 11 additions & 9 deletions karma.conf.js → karma.conf.cjs
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ module.exports = function (config) {

// List of files / patterns to load in the browser
files: [
'src/browser.js',
'src/common.js',
'test.js'
{
pattern: 'test.js', type: 'module',
},
],

// Test results reporter to use
@@ -32,26 +32,28 @@ module.exports = function (config) {
customLaunchers: {
HeadlessChrome: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
flags: ['--no-sandbox'],
},
},

preprocessors: {
// *Sigh* what a glob, folks!
'{{!(node_modules),*.js},!(node_modules)/**/*.js}': ['browserify']
'{{!(node_modules),*.js},!(node_modules)/**/*.js}': ['browserify'],
},

browserify: {
debug: true,
transform: ['brfs']
transform: [['babelify', {
presets: ['@babel/preset-env'],
}]],
},

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
singleRun: false,

// Concurrency level
// how many browser should be started simultaneous
concurrency: 1
concurrency: 1,
});
};
34 changes: 19 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "debug",
"version": "4.3.2",
"version": "5.0.0-canary.0",
"type": "module",
"repository": {
"type": "git",
"url": "git://github.com/visionmedia/debug.git"
@@ -27,33 +28,36 @@
"lint": "xo",
"test": "npm run test:node && npm run test:browser && npm run lint",
"test:node": "istanbul cover _mocha -- test.js",
"test:browser": "karma start --single-run",
"test:browser": "karma start karma.conf.cjs --single-run",
"debug:test:browser": "karma start karma.conf.cjs",
"test:coverage": "cat ./coverage/lcov.info | coveralls"
},
"dependencies": {
"ms": "2.1.2"
"ms": "3.0.0-canary.1"
},
"devDependencies": {
"brfs": "^2.0.1",
"browserify": "^16.2.3",
"coveralls": "^3.0.2",
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"coveralls": "^3.1.1",
"istanbul": "^0.4.5",
"karma": "^3.1.4",
"karma-browserify": "^6.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.2.0",
"xo": "^0.23.0"
"karma": "^6.3.4",
"karma-browserify": "^8.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",
"mocha": "^9.1.2",
"mocha-lcov-reporter": "^1.3.0",
"xo": "^0.45.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
},
"main": "./src/index.js",
"exports": "./src/index.js",
"browser": "./src/browser.js",
"engines": {
"node": ">=6.0"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}
63 changes: 24 additions & 39 deletions src/browser.js
Original file line number Diff line number Diff line change
@@ -3,28 +3,18 @@
/**
* This is the web browser implementation of `debug()`.
*/
import humanize from 'ms';

exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
exports.storage = localstorage();
exports.destroy = (() => {
let warned = false;
export {
formatArgs, save, load, useColors, setupFormatters,
};

return () => {
if (!warned) {
warned = true;
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
}
};
})();
export const storage = localstorage();

/**
* Colors.
*/

exports.colors = [
export const colors = [
'#0000CC',
'#0000FF',
'#0033CC',
@@ -100,7 +90,7 @@ exports.colors = [
'#FF9900',
'#FF9933',
'#FFCC00',
'#FFCC33'
'#FFCC33',
];

/**
@@ -142,14 +132,13 @@ function useColors() {
*
* @api public
*/

function formatArgs(args) {
args[0] = (this.useColors ? '%c' : '') +
this.namespace +
(this.useColors ? ' %c' : ' ') +
args[0] +
(this.useColors ? '%c ' : ' ') +
'+' + module.exports.humanize(this.diff);
'+' + humanize(this.diff);

if (!this.useColors) {
return;
@@ -186,7 +175,7 @@ function formatArgs(args) {
*
* @api public
*/
exports.log = console.debug || console.log || (() => {});
export const log = console.debug || console.log || (() => { });

/**
* Save `namespaces`.
@@ -197,9 +186,9 @@ exports.log = console.debug || console.log || (() => {});
function save(namespaces) {
try {
if (namespaces) {
exports.storage.setItem('debug', namespaces);
storage.setItem('debug', namespaces);
} else {
exports.storage.removeItem('debug');
storage.removeItem('debug');
}
} catch (error) {
// Swallow
@@ -216,7 +205,7 @@ function save(namespaces) {
function load() {
let r;
try {
r = exports.storage.getItem('debug');
r = storage.getItem('debug');
} catch (error) {
// Swallow
// XXX (@Qix-) should we be logging these?
@@ -240,7 +229,6 @@ function load() {
* @return {LocalStorage}
* @api private
*/

function localstorage() {
try {
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
@@ -252,18 +240,15 @@ function localstorage() {
}
}

module.exports = require('./common')(exports);

const {formatters} = module.exports;

/**
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
*/

formatters.j = function (v) {
try {
return JSON.stringify(v);
} catch (error) {
return '[UnexpectedJSONParseError]: ' + error.message;
}
};
function setupFormatters(formatters) {
/**
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
*/
formatters.j = function (v) {
try {
return JSON.stringify(v);
} catch (error) {
return '[UnexpectedJSONParseError]: ' + error.message;
}
};
}
Loading