Skip to content

Commit

Permalink
Move type:module declaration into package.json. (#4355)
Browse files Browse the repository at this point in the history
* Rename `switch_package_to_release.js` to `.cjs`

Slightly surprisingly, the symlink is enough to make `node
switch_package_to_release.js` work.

* Rename .eslintrc.js to .cjs

Again, declare this as commonjs

* Move `type:module` declaration into package.json.

matrix-js-sdk is built into ECMAScript modules, and we should declare it as
such. See https://nodejs.org/api/packages.html#type. Failure to do so causes
problems for javascript projects attempting to build against matrix-js-sdk: see #4347.

Previously, we did this as part of the package.json switcheroo, but that is
unnecessarily fragile.

matrix-react-sdk, element-web, etc are unaffected by this, because they use the
typescript files directly, by importing `matrix-js-sdk/src/...`.
  • Loading branch information
richvdh authored and dbkr committed Aug 21, 2024
1 parent 43e5887 commit 7ef4062
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
File renamed without changes.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
"keywords": [
"matrix-org"
],
"main": "./lib/index.js",
"browser": "./lib/browser-index.js",
"type": "module",
"main": "./src/index.js",
"browser": "./src/browser-index.js",
"matrix_src_main": "./src/index.ts",
"matrix_src_browser": "./src/browser-index.ts",
"matrix_lib_main": "./lib/index.js",
Expand Down
3 changes: 0 additions & 3 deletions scripts/release/pre-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ do
jq ".$i = .matrix_lib_$i" package.json > package.json.new && mv package.json.new package.json && yarn prettier --write package.json
fi
done

# Ensure that "type": "module" is present
jq '.type = "module"' package.json > package.json.new && mv package.json.new package.json && yarn prettier --write package.json
18 changes: 18 additions & 0 deletions scripts/switch_package_to_release.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node

const fsProm = require("fs/promises");

const PKGJSON = "package.json";

async function main() {
const pkgJson = JSON.parse(await fsProm.readFile(PKGJSON, "utf8"));
for (const field of ["main", "typings"]) {
if (pkgJson["matrix_lib_" + field] !== undefined) {
pkgJson[field] = pkgJson["matrix_lib_" + field];
}
}

await fsProm.writeFile(PKGJSON, JSON.stringify(pkgJson, null, 2));
}

main();
22 changes: 0 additions & 22 deletions scripts/switch_package_to_release.js

This file was deleted.

1 change: 1 addition & 0 deletions scripts/switch_package_to_release.js

0 comments on commit 7ef4062

Please sign in to comment.