-
Notifications
You must be signed in to change notification settings - Fork 85
fix(browser-repl)!: keep operation in progress COMPASS-8576 MONGOSH-1966 #2284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 32 commits
a339feb
6e7d247
98430ee
4a95d91
5d48859
8587f0d
2e85187
8ca4f52
5ab819b
45946cb
4a7f4e9
5cf7a44
e3bf5f7
a87e420
85143c0
e54962a
50313a7
7c3a692
e24af9f
3567fcb
705f4ff
be07c02
686cbc9
b34b9a4
757ef7c
72d16b3
72a438b
d0b920d
9b15c06
add38a0
6f20f37
37e3c8b
4e66b19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,8 @@ | |
| "depcheck": "depcheck", | ||
| "compile": "tsc -p tsconfig.json", | ||
| "prettier": "prettier", | ||
| "reformat": "npm run prettier -- --write . && npm run eslint --fix" | ||
| "reformat": "npm run prettier -- --write . && npm run eslint --fix", | ||
| "sync-to-compass": "node scripts/sync-to-compass.js" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useful in combination with this. Based on https://github.com/mongodb-js/compass/blob/main/packages/compass-web/scripts/sync-dist-to-mms.js This way you can save a file in browser-repl in mongosh and it hot-reloads in compass. |
||
| }, | ||
| "config": { | ||
| "unsafe-perm": true | ||
|
|
@@ -76,6 +77,9 @@ | |
| "@mongodb-js/prettier-config-devtools": "^1.0.1", | ||
| "@mongodb-js/tsconfig-mongosh": "^1.0.0", | ||
| "@pmmmwh/react-refresh-webpack-plugin": "^0.5.8", | ||
| "@testing-library/dom": "^8.20.1", | ||
| "@testing-library/react": "^12.1.5", | ||
| "@testing-library/user-event": "^13.5.0", | ||
| "@types/numeral": "^2.0.2", | ||
| "@types/react": "^16.9.17", | ||
| "@types/react-dom": "^18.0.8", | ||
|
|
@@ -96,6 +100,7 @@ | |
| "karma-mocha-reporter": "^2.2.5", | ||
| "karma-typescript": "^5.5.4", | ||
| "karma-webpack": "^5.0.0", | ||
| "lodash": "^4.17.21", | ||
| "path-browserify": "^1.0.1", | ||
| "prettier": "^2.8.8", | ||
| "prop-types": "^15.7.2", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* eslint-disable no-console */ | ||
| 'use strict'; | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const child_process = require('child_process'); | ||
| const { debounce } = require('lodash'); | ||
lerouxb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!process.env.COMPASS_HOME) { | ||
| throw new Error('Missing required environment variable $COMPASS_HOME.'); | ||
| } | ||
|
|
||
| const packageDir = path.resolve(__dirname, '..'); | ||
| const srcDir = path.resolve(__dirname, '..', 'src'); | ||
| const libDir = path.resolve(__dirname, '..', 'lib'); | ||
|
|
||
| const destDir = path.dirname( | ||
| child_process.execFileSync( | ||
| 'node', | ||
| ['-p', "require.resolve('@mongosh/browser-repl')"], | ||
| { cwd: process.env.COMPASS_HOME, encoding: 'utf-8' } | ||
| ) | ||
| ); | ||
|
|
||
| console.log({ packageDir, srcDir, libDir, destDir }); | ||
|
|
||
| const compileAndCopy = debounce( | ||
| function () { | ||
| try { | ||
| child_process.execFileSync('npm', ['run', 'compile'], { | ||
| cwd: packageDir, | ||
| encoding: 'utf-8', | ||
| }); | ||
| } catch (err) { | ||
| if (err.code) { | ||
| // Spawning child process failed | ||
| console.error(err.code); | ||
| } else { | ||
| // Child was spawned but exited with non-zero exit code | ||
| // Error contains any stdout and stderr from the child | ||
| const { stdout, stderr } = err; | ||
|
|
||
| console.log(stdout); | ||
| console.error(stderr); | ||
| } | ||
| } | ||
| fs.cpSync(libDir, destDir, { recursive: true }); | ||
| console.log('done.'); | ||
| }, | ||
| 1_000, | ||
| { | ||
| leading: true, | ||
| trailing: true, | ||
| } | ||
| ); | ||
|
|
||
| const srcWatcher = fs.watch( | ||
| srcDir, | ||
| { recursive: true }, | ||
| function (eventType, filename) { | ||
| console.log(eventType, filename); | ||
| compileAndCopy(); | ||
| } | ||
| ); | ||
|
|
||
| function cleanup() { | ||
| srcWatcher.close(); | ||
| } | ||
|
|
||
| for (const evt of ['SIGINT', 'SIGTERM']) { | ||
| process.on(evt, cleanup); | ||
| } | ||
|
|
||
| // do an initial copy on startup | ||
| compileAndCopy(); | ||
Uh oh!
There was an error while loading. Please reload this page.