Skip to content

Commit

Permalink
fix: Parcel example doesn't work with new monaco-editor versions (#433)
Browse files Browse the repository at this point in the history
- Patch monaco-editor in order to get esm-parcel sample working
  - Aside: Looks like CI didn't catch this?
- Fix both `0.45.0` and `0.46.0` monaco-editor versions resolve in the
repo
- Bumped parcel version
- Replaces `~0.46.0` monaco-editor versions with `^0.46.0` for
consistency, and so we don't need 2 lines in packages.json#resolutions

This seems like more of a Parcel issue than a monaco-editor one, so I've
opened an issue on them:
parcel-bundler/parcel#9549
  • Loading branch information
maxburs committed Feb 28, 2024
1 parent 8b93015 commit 110f6ea
Show file tree
Hide file tree
Showing 6 changed files with 595 additions and 598 deletions.
18 changes: 18 additions & 0 deletions .yarn/patches/monaco-editor-npm-0.46.0-fb69b10c11.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/esm/vs/base/common/platform.js b/esm/vs/base/common/platform.js
index d507327daec3cdf5027bd886f898c364c5433ecd..9dc769654606b60bc71922dd40f2146db97dcbb9 100644
--- a/esm/vs/base/common/platform.js
+++ b/esm/vs/base/common/platform.js
@@ -26,9 +26,11 @@ if (typeof $globalThis.vscode !== 'undefined' && typeof $globalThis.vscode.proce
// Native environment (sandboxed)
nodeProcess = $globalThis.vscode.process;
}
-else if (typeof process !== 'undefined') {
+// Work around bug in Parcel causing $globalThis.process !== process
+// https://github.com/parcel-bundler/parcel/issues/9549
+else if (typeof $globalThis.process !== 'undefined') {
// Native environment (non-sandboxed)
- nodeProcess = process;
+ nodeProcess = $globalThis.process;
}
const isElectronProcess = typeof ((_a = nodeProcess === null || nodeProcess === void 0 ? void 0 : nodeProcess.versions) === null || _a === void 0 ? void 0 : _a.electron) === 'string';
const isElectronRenderer = isElectronProcess && (nodeProcess === null || nodeProcess === void 0 ? void 0 : nodeProcess.type) === 'renderer';
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"wait-on": "^7.0.1"
},
"resolutions": {
"monaco-editor@^0.46.0": "patch:monaco-editor@npm%3A0.46.0#./.yarn/patches/monaco-editor-npm-0.46.0-fb69b10c11.patch"
}
}
4 changes: 2 additions & 2 deletions package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@types/xregexp": "^4.4.0",
"concurrently": "^8.2.1",
"http-server": "^14.1.1",
"monaco-editor": "~0.46.0",
"monaco-editor": "^0.46.0",
"rimraf": "^5.0.1",
"rollup": "^3.29.2",
"terser": "^5.19.4",
Expand All @@ -67,6 +67,6 @@
"xregexp": "^5.1.1"
},
"peerDependencies": {
"monaco-editor": "~0.46.0"
"monaco-editor": "^0.46.0"
}
}
2 changes: 1 addition & 1 deletion samples/amd-webpack-react-cross-origin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@kusto/monaco-kusto": "workspace:*",
"express": "^4.18.2",
"monaco-editor": "~0.45.0",
"monaco-editor": "^0.46.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
19 changes: 19 additions & 0 deletions samples/esm-parcel/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Monaco Kusto Parcel example

See [../../README.md] for general esm setup instructions

## Parcel-specific changes

### Add `{ "alias": { "process": false } }` to `package.json`

@kusto/language-server includes node-specific code. Configure Parcel avoiding including `node_modules/process` in our bundle.

Parcel docs on disabling `process` shimming: https://parceljs.org/features/dependency-resolution/#package-aliases
Parcel docs on shimming globals: https://parceljs.org/features/node-emulation/#shimming-builtin-node-globals

### Patch monaco-editor to use globalThis.process instead of process

Recent monaco versions use `typeof process` to check if it's running in a node environment. Parcel doesn't have the ability to make this check return `false` so we need to patch monaco to use `globalThis.process` instead.

The yarn patch file this repo uses can be seen at `/.yarn/patches/monaco-editor-npm-0.46.0-fb69b10c11.patch`.

Yarn docs for patching packages: https://yarnpkg.com/cli/patch

Parcel issue tracking this: https://github.com/parcel-bundler/parcel/issues/9549

0 comments on commit 110f6ea

Please sign in to comment.