Skip to content

Commit

Permalink
Fix the exports of vscode-languageserver-types (#1297)
Browse files Browse the repository at this point in the history
* Fix the exports of vscode-languageserver-types

The `exports` field is needed for dual publishing CJS and ESM. The
`module` field on the other hand, is a non-standard property. Some
bundlers incorrectly interpret it, causing interop issues.

An additional `package.json` file is written to mark the ESM output as
actual ESM.

* Fix ESM for vscode-languageserver-textdocument

* update target to es6

---------

Co-authored-by: Dirk Bäumer <dirkb@microsoft.com>
Co-authored-by: Martin Aeschlimann <martinae@microsoft.com>
  • Loading branch information
3 people authored Sep 18, 2023
1 parent 4e057d5 commit a06b881
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
12 changes: 12 additions & 0 deletions build/bin/fix-esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
//@ts-check

const fs = require('fs');

const pkg = { type: 'module' };

fs.writeFileSync('lib/esm/package.json', JSON.stringify(pkg, undefined, 2) + '\n');
9 changes: 7 additions & 2 deletions textDocument/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
},
"main": "./lib/umd/main.js",
"typings": "./lib/umd/main",
"module": "./lib/esm/main.js",
"exports": {
".": {
"import": "./lib/esm/main.js",
"default": "./lib/umd/main.js"
}
},
"scripts": {
"prepublishOnly": "echo \"⛔ Can only publish from a secure pipeline ⛔\" && node ../build/npm/fail",
"prepack": "npm run all:publish",
Expand All @@ -24,7 +29,7 @@
"lint": "node ../node_modules/eslint/bin/eslint.js --ext ts src",
"test": "node ../node_modules/mocha/bin/_mocha",
"all": "npm run clean && npm run compile && npm run lint && npm run test",
"compile:esm": "node ../build/bin/tsc -b ./tsconfig.esm.publish.json",
"compile:esm": "node ../build/bin/tsc -b ./tsconfig.esm.publish.json && node ../build/bin/fix-esm",
"compile:umd": "node ../build/bin/tsc -b ./tsconfig.umd.publish.json",
"all:publish": "git clean -xfd . && npm install && npm run compile:esm && npm run compile:umd && npm run lint && npm run test",
"preversion": "npm test"
Expand Down
2 changes: 1 addition & 1 deletion textDocument/src/test/tsconfig.esm.publish.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"declaration": true,
"stripInternal": true,
"sourceMap": false,
"target": "es5",
"target": "es6",
"lib": [
"es2015"
],
Expand Down
2 changes: 1 addition & 1 deletion textDocument/src/tsconfig.esm.publish.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"declaration": true,
"stripInternal": true,
"sourceMap": false,
"target": "es5",
"target": "es6",
"lib": [
"es2015"
],
Expand Down
9 changes: 7 additions & 2 deletions types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
},
"main": "./lib/umd/main.js",
"typings": "./lib/umd/main",
"module": "./lib/esm/main.js",
"exports": {
".": {
"import": "./lib/esm/main.js",
"default": "./lib/umd/main.js"
}
},
"scripts": {
"prepublishOnly": "echo \"⛔ Can only publish from a secure pipeline ⛔\" && node ../build/npm/fail",
"prepack": "npm run all:publish",
Expand All @@ -24,7 +29,7 @@
"lint": "node ../node_modules/eslint/bin/eslint.js --ext ts src",
"test": "node ../node_modules/mocha/bin/_mocha",
"all": "npm run clean && npm run compile && npm run lint && npm run test",
"compile:esm": "node ../build/bin/tsc -b ./tsconfig.esm.publish.json",
"compile:esm": "node ../build/bin/tsc -b ./tsconfig.esm.publish.json && node ../build/bin/fix-esm",
"compile:umd": "node ../build/bin/tsc -b ./tsconfig.umd.publish.json",
"all:publish": "git clean -xfd . && npm install && npm run compile:esm && npm run compile:umd && npm run lint && npm run test",
"preversion": "npm test"
Expand Down
2 changes: 1 addition & 1 deletion types/src/test/tsconfig.esm.publish.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"declaration": true,
"stripInternal": true,
"sourceMap": false,
"target": "es5",
"target": "es6",
"lib": [
"es2015"
],
Expand Down
2 changes: 1 addition & 1 deletion types/src/tsconfig.esm.publish.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"declaration": true,
"stripInternal": true,
"sourceMap": false,
"target": "es5",
"target": "es6",
"lib": [
"es2015"
],
Expand Down

0 comments on commit a06b881

Please sign in to comment.