Skip to content

Commit b8e8b14

Browse files
authored
Move type:module declaration into package.json. (#4355)
* 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/...`.
1 parent 2544c14 commit b8e8b14

5 files changed

+20
-25
lines changed
File renamed without changes.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"keywords": [
3232
"matrix-org"
3333
],
34+
"type": "module",
3435
"main": "./src/index.ts",
3536
"browser": "./src/browser-index.ts",
3637
"matrix_src_main": "./src/index.ts",

scripts/release/pre-release.sh

-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@ do
1212
jq ".$i = .matrix_lib_$i" package.json > package.json.new && mv package.json.new package.json && yarn prettier --write package.json
1313
fi
1414
done
15-
16-
# Ensure that "type": "module" is present
17-
jq '.type = "module"' package.json > package.json.new && mv package.json.new package.json && yarn prettier --write package.json

scripts/switch_package_to_release.cjs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env node
2+
3+
const fsProm = require("fs/promises");
4+
5+
const PKGJSON = "package.json";
6+
7+
async function main() {
8+
const pkgJson = JSON.parse(await fsProm.readFile(PKGJSON, "utf8"));
9+
for (const field of ["main", "typings"]) {
10+
if (pkgJson["matrix_lib_" + field] !== undefined) {
11+
pkgJson[field] = pkgJson["matrix_lib_" + field];
12+
}
13+
}
14+
15+
await fsProm.writeFile(PKGJSON, JSON.stringify(pkgJson, null, 2));
16+
}
17+
18+
main();

scripts/switch_package_to_release.js

-22
This file was deleted.

scripts/switch_package_to_release.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
switch_package_to_release.cjs

0 commit comments

Comments
 (0)