Script is not compatible with Windows systems #2

Open
opened 2025-02-06 10:38:01 +01:00 by zhujoel · 0 comments
zhujoel commented 2025-02-06 10:38:01 +01:00 (Migrated from github.com)

Hello,

While attempting to build some CodeMirror repositories locally with npm run prepare, I noticed that the formatting didn't apply (e.g. comments were not converted to JSDoc).

I managed to investigate the root-cause down to this script, which I have found is not compatible with Windows systems.

For example, here are a couple changes I made to readAndMangleComments:

  1. Windows uses CR, and not LF as line break, so we can adapt the search regex to include \r?.
file = file.replace(/(?<=^|\r?\n)(?:([ \t]*)\/\/\/.*\r?\n)+/g, (comment, space) => {
   // ...
})
  1. Windows uses \ for file path, as opposed to / on Unix, so replacing the file name when doing the directory search is hacky but works.
let file = ts.sys.readFile(name);
let windowsName = name.replaceAll("/", "\\");
if (file && dirs.includes((0, path_1.dirname)(windowsName)))

I am opening this issue mostly to document the behaviour, as it might help others who get stuck in this. 🙂

Hello, While attempting to build some CodeMirror repositories locally with `npm run prepare`, I noticed that the formatting didn't apply (e.g. comments were not converted to JSDoc). I managed to investigate the root-cause down to this script, which I have found is not compatible with Windows systems. For example, here are a couple changes I made to `readAndMangleComments`: 1. Windows uses CR, and not LF as line break, so we can adapt the search regex to include `\r?`. ``` file = file.replace(/(?<=^|\r?\n)(?:([ \t]*)\/\/\/.*\r?\n)+/g, (comment, space) => { // ... }) ``` 2. Windows uses `\` for file path, as opposed to `/` on Unix, so replacing the file name when doing the directory search is hacky but works. ``` let file = ts.sys.readFile(name); let windowsName = name.replaceAll("/", "\\"); if (file && dirs.includes((0, path_1.dirname)(windowsName))) ``` I am opening this issue mostly to document the behaviour, as it might help others who get stuck in this. 🙂
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
marijn/buildtool#2
No description provided.