Skip to content

Commit a122966

Browse files
authored
Fix matrix-js-sdk linking on Windows (element-hq#33491)
* Fix matrix-js-sdk linking on Windows * Linting
1 parent ab904bb commit a122966

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

developer_guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Set up your local development link by creating a `.link-config` file with conten
4545
matrix-js-sdk=/path/to/matrix-js-sdk
4646
```
4747

48+
**Note for Windows users**: Your link config path might need escaping. For example, `matrix-js-sdk=C:\\path\\to\\matrix-js-sdk`.
49+
4850
Switch to the `apps/web` directory: `cd apps/web`
4951

5052
Configure the app by copying `config.sample.json` to `config.json` and
@@ -57,6 +59,8 @@ pnpm install
5759
pnpm start
5860
```
5961

62+
**Note for Windows users**: `pnpm start` needs to be run from a terminal with bash/shell support.
63+
6064
Wait a few seconds for the initial build to finish; you should see something like:
6165

6266
```

scripts/pnpm-link.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,31 @@ try {
3232
const dependencyPath = join(nodeModulesPath, dependency);
3333

3434
try {
35-
const stat = await fs.stat(dependencyPath);
36-
if (stat.isSymbolicLink()) {
37-
const linkPath = await fs.readlink(dependencyPath);
38-
if (linkPath === path) {
39-
// already done
40-
continue;
35+
try {
36+
const stat = await fs.lstat(dependencyPath);
37+
console.log(`Existing is ${stat.isSymbolicLink() ? "symlink" : "directory"}`);
38+
if (stat.isSymbolicLink()) {
39+
const linkPath = await fs.readlink(dependencyPath);
40+
if (linkPath === path) {
41+
// already done
42+
continue;
43+
} else {
44+
await fs.unlink(dependencyPath);
45+
}
4146
} else {
42-
await fs.unlink(dependencyPath);
47+
await fs.rm(dependencyPath, { recursive: true });
48+
}
49+
} catch (e: any) {
50+
// fs.lstat throws ENOENT if the path doesn't exist (on Windows)
51+
if (e.code === "ENOENT") {
52+
console.log("Received ENOENT error on dependency path - assuming it doesn't exist");
53+
} else {
54+
throw e;
4355
}
44-
} else {
45-
await fs.rm(dependencyPath, { recursive: true });
4656
}
4757

4858
console.log(`Linking ${dependency} to ${path}`);
49-
await fs.symlink(path, dependencyPath);
59+
await fs.symlink(path, dependencyPath, "junction"); // use a junction type to avoid EPERM errors on Windows
5060

5161
const pkgJson = await fs.readFile(join(path, "package.json"), "utf-8");
5262
const pkgManager = JSON.parse(pkgJson)["packageManager"]?.split("@").at(0) ?? "yarn";

0 commit comments

Comments
 (0)