-
Notifications
You must be signed in to change notification settings - Fork 52
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
Fix ESM exports #78
base: main
Are you sure you want to change the base?
Fix ESM exports #78
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
{ | ||
"ui": "tdd", | ||
"color": true | ||
} | ||
"color": true, | ||
"spec": [ | ||
"./lib/cjs/test/*.test.js", | ||
"./lib/esm/test/*.test.js" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env node | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import fs from 'fs/promises'; | ||
|
||
await fs.writeFile( | ||
new URL('../lib/esm/package.json', import.meta.url), | ||
JSON.stringify({ type: 'module' }, undefined, 2) + '\n' | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,14 @@ | |
"name": "jsonc-parser", | ||
"version": "3.2.1", | ||
"description": "Scanner and parser for JSON with comments.", | ||
"main": "./lib/umd/main.js", | ||
"typings": "./lib/umd/main.d.ts", | ||
"module": "./lib/esm/main.js", | ||
"main": "./lib/cjs/main.js", | ||
"exports": { | ||
".": { | ||
"import": "./lib/esm/main.js", | ||
"module": "./lib/esm/main.js", | ||
"default": "./lib/cjs/main.js" | ||
} | ||
}, | ||
"author": "Microsoft Corporation", | ||
"repository": { | ||
"type": "git", | ||
|
@@ -25,13 +30,12 @@ | |
"rimraf": "^5.0.5" | ||
}, | ||
"scripts": { | ||
"prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs", | ||
"compile": "tsc -p ./src && npm run lint", | ||
"compile-esm": "tsc -p ./src/tsconfig.esm.json", | ||
"prepack": "npm run clean && npm run test && npm run remove-sourcemap-refs", | ||
"compile": "tsc -b && node ./build/fix-esm.mjs && npm run lint", | ||
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that remove-sourcemap-refs job is useless. We can set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That breaks code coverage and source mapping when running tests. |
||
"clean": "rimraf lib", | ||
"watch": "tsc -w -p ./src", | ||
"test": "npm run compile && mocha ./lib/umd/test", | ||
"lint": "eslint src/**/*.ts" | ||
"watch": "tsc -w -b", | ||
"test": "npm run compile && mocha", | ||
"lint": "eslint ." | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./tsconfig.esm.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "./lib/cjs" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
{ | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "es6", | ||
"moduleResolution": "node", | ||
"module": "esnext", | ||
"moduleResolution": "node16", | ||
"sourceMap": true, | ||
"declaration": true, | ||
"stripInternal": true, | ||
"outDir": "../lib/esm", | ||
"outDir": "./lib/esm", | ||
"rootDir": "./src", | ||
"strict": true, | ||
"preserveConstEnums": true, | ||
"lib": [ | ||
"es2020" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"files": [], | ||
"references": [ | ||
{ "path": "./tsconfig.cjs.json" }, | ||
{ "path": "./tsconfig.esm.json" } | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the meaning of
"module"
exports?I didn't see it in nodejs docs and webpack docs. Where is it used for or where is the official doc for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It tells bundlers to use it, even when the module is
require
d from a CJS file. So it helps reduce bundle size and avoid the dual package hazard.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the
"import"
condition is more widely used in webpack, vite and node. Why should we add unofficial"module"
condition.