diff --git a/README.md b/README.md index 8fa3edb4..ca4a4fab 100644 --- a/README.md +++ b/README.md @@ -92,13 +92,13 @@ import JSON5 from 'json5' #### UMD ```html - + ``` #### Modules ```html ``` diff --git a/build/es5.js b/build/es5.js index 1123c534..957c7c97 100644 --- a/build/es5.js +++ b/build/es5.js @@ -1,6 +1,6 @@ require('core-js/fn/string/code-point-at') require('core-js/fn/string/from-code-point') -const JSON5 = require('../lib') +const JSON5 = require('../lib/index.js') module.exports = JSON5 diff --git a/build/package.js b/build/package.js index 9abf3f79..39f5f769 100644 --- a/build/package.js +++ b/build/package.js @@ -1,7 +1,7 @@ const fs = require('fs') const path = require('path') -const JSON5 = require('../lib') +const JSON5 = require('../lib/index.js') const pkg = require('../package.json') diff --git a/lib/cli.js b/lib/cli.js index 93cb8092..e88a36e7 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -3,7 +3,7 @@ const fs = require('fs') const path = require('path') const pkg = require('../package.json') -const JSON5 = require('./') +const JSON5 = require('./index.js') const argv = parseArgs() diff --git a/lib/index.mjs b/lib/index.mjs new file mode 100644 index 00000000..e8840d05 --- /dev/null +++ b/lib/index.mjs @@ -0,0 +1,7 @@ +/* eslint-disable node/no-unsupported-features/es-syntax */ + +import JSON5 from './index.js' + +export const parse = JSON5.parse +export const stringify = JSON5.stringify +export default JSON5 diff --git a/lib/register.js b/lib/register.js index 935cdbaf..6eea8de8 100644 --- a/lib/register.js +++ b/lib/register.js @@ -1,5 +1,5 @@ const fs = require('fs') -const JSON5 = require('./') +const JSON5 = require('./index.js') // eslint-disable-next-line node/no-deprecated-api require.extensions['.json5'] = function (module, filename) { diff --git a/package.json b/package.json index 70e5f669..723f9d27 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,10 @@ "version": "2.2.1", "description": "JSON for Humans", "main": "lib/index.js", - "module": "dist/index.mjs", + "module": "lib/index.mjs", "bin": "lib/cli.js", - "browser": "dist/index.js", + "browser": "dist/json5.umd.js", + "unpkg": "dist/json5.umd.js", "types": "lib/index.d.ts", "files": [ "lib/", diff --git a/package.json5 b/package.json5 index 027a098a..650261fb 100644 --- a/package.json5 +++ b/package.json5 @@ -4,9 +4,10 @@ version: '2.2.1', description: 'JSON for Humans', main: 'lib/index.js', - module: 'dist/index.mjs', + module: 'lib/index.mjs', bin: 'lib/cli.js', - browser: 'dist/index.js', + browser: 'dist/json5.umd.js', + unpkg: 'dist/json5.umd.js', types: 'lib/index.d.ts', files: [ 'lib/', diff --git a/rollup.config.js b/rollup.config.js index 871066d8..a4d36dfd 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -8,11 +8,19 @@ module.exports = [ // ES5 Non-minified { input: 'build/es5.js', - output: { - file: pkg.browser, - format: 'umd', - name: 'JSON5', - }, + output: [ + { + file: pkg.browser, + format: 'umd', + name: 'JSON5', + }, + { + // Legacy path + file: 'dist/index.js', + format: 'umd', + name: 'JSON5', + }, + ], plugins: [ resolve(), commonjs(), @@ -22,11 +30,19 @@ module.exports = [ // ES5 Minified { input: 'build/es5.js', - output: { - file: pkg.browser.replace(/\.js$/, '.min.js'), - format: 'umd', - name: 'JSON5', - }, + output: [ + { + file: pkg.browser.replace(/\.js$/, '.min.js'), + format: 'umd', + name: 'JSON5', + }, + { + // Legacy path + file: 'dist/index.min.js', + format: 'umd', + name: 'JSON5', + }, + ], plugins: [ resolve(), commonjs(), @@ -36,11 +52,18 @@ module.exports = [ }, // ES6 Modules Non-minified { - input: 'lib/index.js', - output: { - file: pkg.browser.replace(/\.js$/, '.mjs'), - format: 'esm', - }, + input: 'lib/index.mjs', + output: [ + { + file: pkg.browser.replace(/\.umd\.js$/, '.esm.js'), + format: 'esm', + }, + { + // Legacy path + file: 'dist/index.mjs', + format: 'esm', + }, + ], plugins: [ resolve(), commonjs(), @@ -48,11 +71,18 @@ module.exports = [ }, // ES6 Modules Minified { - input: 'lib/index.js', - output: { - file: pkg.browser.replace(/\.js$/, '.min.mjs'), - format: 'esm', - }, + input: 'lib/index.mjs', + output: [ + { + file: pkg.browser.replace(/\.umd\.js$/, '.esm.min.mjs'), + format: 'esm', + }, + { + // Legacy path + file: 'dist/index.min.mjs', + format: 'esm', + }, + ], plugins: [ resolve(), commonjs(), diff --git a/test/errors.js b/test/errors.js index 1d1657c6..115dea94 100644 --- a/test/errors.js +++ b/test/errors.js @@ -1,5 +1,5 @@ const assert = require('assert') -const JSON5 = require('../lib') +const JSON5 = require('..') require('tap').mochaGlobals() diff --git a/test/index.mjs b/test/index.mjs new file mode 100644 index 00000000..e09bdb41 --- /dev/null +++ b/test/index.mjs @@ -0,0 +1,8 @@ +/* eslint-disable import/no-duplicates, node/no-unsupported-features/es-syntax */ + +import JSON5Modules from '..' +import JSON5CommonJS from '../lib/index.js' + +import t from 'tap' + +t.strictSame(JSON5Modules, JSON5CommonJS, 'Modules export and CommonJS export are the same') diff --git a/test/parse.js b/test/parse.js index 59fbdd15..e87f98b7 100644 --- a/test/parse.js +++ b/test/parse.js @@ -1,6 +1,6 @@ const assert = require('assert') const sinon = require('sinon') -const JSON5 = require('../lib') +const JSON5 = require('..') require('tap').mochaGlobals() diff --git a/test/stringify.js b/test/stringify.js index a0c494f0..9933885a 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -1,5 +1,5 @@ const assert = require('assert') -const JSON5 = require('../lib') +const JSON5 = require('..') require('tap').mochaGlobals()