forked from json5/json5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This large commit enhances support for JavaScript modules. This adds `lib/index.mjs`, which re-exports `lib/index.js` as a default export and `parse` and `stringify` as named exports. The `module` field in `package.json` now points to this file as the entry point for `import` statements in versions of Node.js that support modules. With this change, `import` statements in Node.js no longer need to use the path `json5/dist/index.mjs`, and should import the module as `json5` instead. `test/index.mjs` ensures that `lib/index.js` and `lib/index.mjs` export the same instance. This follows the guidance in approach json5#1 of [Writing dual packages while avoiding or minimizing hazards][guidance]. `rollup.config.js` now uses `lib/index.mjs` as its entry point for building browser bundles for JavaScript modules environments. It now writes browser bundles to `dist/json5.umd.js` and `dist/json5.esm.js`, as well as minified versions. These are the new canonical paths for browser bundles. The legacy `dist/index.*` paths still exist for backward compatibility, but they will be removed in the next major version. All files in `build` and `lib` now explicitly require `lib/index.js` to ensure that `lib/index.mjs` is not imported. All files in `test` now require the package root to simulate the default behavior of the version of Node.js being tested. [guidance]: https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#writing-dual-packages-while-avoiding-or-minimizing-hazards squash
- Loading branch information
1 parent
577c856
commit 26525f4
Showing
14 changed files
with
84 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import parse = require('./parse') | ||
import stringify = require('./stringify') | ||
|
||
export {parse, stringify} | ||
export default {parse, stringify} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters