Skip to content

Commit 9e526bb

Browse files
Konakona-chanmilahu
authored andcommitted
Use ESModules instead of module.exports debug-js#786
1 parent f851b00 commit 9e526bb

File tree

7 files changed

+359
-393
lines changed

7 files changed

+359
-393
lines changed

karma.conf.js karma.conf.cjs

+11-9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module.exports = function (config) {
66

77
// List of files / patterns to load in the browser
88
files: [
9-
'src/browser.js',
10-
'src/common.js',
11-
'test.js'
9+
{
10+
pattern: 'test.js', type: 'module',
11+
},
1212
],
1313

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

3939
preprocessors: {
4040
// *Sigh* what a glob, folks!
41-
'{{!(node_modules),*.js},!(node_modules)/**/*.js}': ['browserify']
41+
'{{!(node_modules),*.js},!(node_modules)/**/*.js}': ['browserify'],
4242
},
4343

4444
browserify: {
4545
debug: true,
46-
transform: ['brfs']
46+
transform: [['babelify', {
47+
presets: ['@babel/preset-env'],
48+
}]],
4749
},
4850

4951
// Continuous Integration mode
5052
// if true, Karma captures browsers, runs the tests and exits
51-
singleRun: true,
53+
singleRun: false,
5254

5355
// Concurrency level
5456
// how many browser should be started simultaneous
55-
concurrency: 1
57+
concurrency: 1,
5658
});
5759
};

package.json

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "debug",
3-
"version": "4.3.2",
3+
"version": "5.0.0-canary.0",
4+
"type": "module",
45
"repository": {
56
"type": "git",
67
"url": "git://github.com/visionmedia/debug.git"
@@ -27,33 +28,36 @@
2728
"lint": "xo",
2829
"test": "npm run test:node && npm run test:browser && npm run lint",
2930
"test:node": "istanbul cover _mocha -- test.js",
30-
"test:browser": "karma start --single-run",
31+
"test:browser": "karma start karma.conf.cjs --single-run",
32+
"debug:test:browser": "karma start karma.conf.cjs",
3133
"test:coverage": "cat ./coverage/lcov.info | coveralls"
3234
},
3335
"dependencies": {
34-
"ms": "2.1.2"
36+
"ms": "3.0.0-canary.1"
3537
},
3638
"devDependencies": {
37-
"brfs": "^2.0.1",
38-
"browserify": "^16.2.3",
39-
"coveralls": "^3.0.2",
39+
"@babel/core": "^7.15.8",
40+
"@babel/preset-env": "^7.15.8",
41+
"babelify": "^10.0.0",
42+
"browserify": "^17.0.0",
43+
"coveralls": "^3.1.1",
4044
"istanbul": "^0.4.5",
41-
"karma": "^3.1.4",
42-
"karma-browserify": "^6.0.0",
43-
"karma-chrome-launcher": "^2.2.0",
44-
"karma-mocha": "^1.3.0",
45-
"mocha": "^5.2.0",
46-
"mocha-lcov-reporter": "^1.2.0",
47-
"xo": "^0.23.0"
45+
"karma": "^6.3.4",
46+
"karma-browserify": "^8.1.0",
47+
"karma-chrome-launcher": "^3.1.0",
48+
"karma-mocha": "^2.0.1",
49+
"mocha": "^9.1.2",
50+
"mocha-lcov-reporter": "^1.3.0",
51+
"xo": "^0.45.0"
4852
},
4953
"peerDependenciesMeta": {
5054
"supports-color": {
5155
"optional": true
5256
}
5357
},
54-
"main": "./src/index.js",
58+
"exports": "./src/index.js",
5559
"browser": "./src/browser.js",
5660
"engines": {
57-
"node": ">=6.0"
61+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
5862
}
5963
}

src/browser.js

+24-39
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,18 @@
33
/**
44
* This is the web browser implementation of `debug()`.
55
*/
6+
import humanize from 'ms';
67

7-
exports.formatArgs = formatArgs;
8-
exports.save = save;
9-
exports.load = load;
10-
exports.useColors = useColors;
11-
exports.storage = localstorage();
12-
exports.destroy = (() => {
13-
let warned = false;
8+
export {
9+
formatArgs, save, load, useColors, setupFormatters,
10+
};
1411

15-
return () => {
16-
if (!warned) {
17-
warned = true;
18-
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
19-
}
20-
};
21-
})();
12+
export const storage = localstorage();
2213

2314
/**
2415
* Colors.
2516
*/
26-
27-
exports.colors = [
17+
export const colors = [
2818
'#0000CC',
2919
'#0000FF',
3020
'#0033CC',
@@ -100,7 +90,7 @@ exports.colors = [
10090
'#FF9900',
10191
'#FF9933',
10292
'#FFCC00',
103-
'#FFCC33'
93+
'#FFCC33',
10494
];
10595

10696
/**
@@ -142,14 +132,13 @@ function useColors() {
142132
*
143133
* @api public
144134
*/
145-
146135
function formatArgs(args) {
147136
args[0] = (this.useColors ? '%c' : '') +
148137
this.namespace +
149138
(this.useColors ? ' %c' : ' ') +
150139
args[0] +
151140
(this.useColors ? '%c ' : ' ') +
152-
'+' + module.exports.humanize(this.diff);
141+
'+' + humanize(this.diff);
153142

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

191180
/**
192181
* Save `namespaces`.
@@ -197,9 +186,9 @@ exports.log = console.debug || console.log || (() => {});
197186
function save(namespaces) {
198187
try {
199188
if (namespaces) {
200-
exports.storage.setItem('debug', namespaces);
189+
storage.setItem('debug', namespaces);
201190
} else {
202-
exports.storage.removeItem('debug');
191+
storage.removeItem('debug');
203192
}
204193
} catch (error) {
205194
// Swallow
@@ -216,7 +205,7 @@ function save(namespaces) {
216205
function load() {
217206
let r;
218207
try {
219-
r = exports.storage.getItem('debug');
208+
r = storage.getItem('debug');
220209
} catch (error) {
221210
// Swallow
222211
// XXX (@Qix-) should we be logging these?
@@ -240,7 +229,6 @@ function load() {
240229
* @return {LocalStorage}
241230
* @api private
242231
*/
243-
244232
function localstorage() {
245233
try {
246234
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
@@ -252,18 +240,15 @@ function localstorage() {
252240
}
253241
}
254242

255-
module.exports = require('./common')(exports);
256-
257-
const {formatters} = module.exports;
258-
259-
/**
260-
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
261-
*/
262-
263-
formatters.j = function (v) {
264-
try {
265-
return JSON.stringify(v);
266-
} catch (error) {
267-
return '[UnexpectedJSONParseError]: ' + error.message;
268-
}
269-
};
243+
function setupFormatters(formatters) {
244+
/**
245+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
246+
*/
247+
formatters.j = function (v) {
248+
try {
249+
return JSON.stringify(v);
250+
} catch (error) {
251+
return '[UnexpectedJSONParseError]: ' + error.message;
252+
}
253+
};
254+
}

0 commit comments

Comments
 (0)