Commit Graph

19 Commits

Author SHA1 Message Date
Ben Newman
a467255d9c Use IPC message to handle .reload command in meteor shell.
I considered using a nonzero process.exit code, but I didn't want to run
any risk of reusing a meaningful code, and the accepted range of codes
unfortunately does not include parseInt("reload", 36), or 1657112629.

Should fix #10934.
2020-02-26 12:13:48 -05:00
Christian Klaussner
c9fb850b75 Don't use deprecated REPLServer.rli property. (#10888)
This property is deprecated since Node.js 12.
https://github.com/nodejs/node/pull/26260
2020-01-30 10:29:53 -05:00
Ben Newman
6bf22e668f Set cache directory correctly for meteor shell compilation.
Fixes #10189.
2018-09-05 14:32:08 -04:00
Jesse Rosenberger
aec76b766c Only import start from repl instead of the entire module.
It was previously necessary to have more from the `repl` module, but
it's sufficient to just have `start` now since we wrap the default
`eval`.
2017-11-30 19:57:00 +02:00
Jesse Rosenberger
0df8a5a516 Ensure that require and module are always set.
I previously had thought that a duplicate call to `setRequireAndModule`
encountered in code-path would no longer be necessary after some
consolidation in previous steps of this re-factor, but the test failure
seen here made it clear what was happening:

https://circleci.com/gh/meteor/meteor/12445

Specifically, if a module was imported in a piped command (that is to say,
when no TTY is present and the `evaluateAndExit` code-path is taken), as so:

    echo 'import { Meteor } from "meteor/meteor"' | meteor shell

...the `module` and `require` symbols were not set.  Conveniently, this is
the environment in effect when the `meteor self-test` suite is ran since
they do not have a TTY.

This moves the `setAndRequire` from the "interactive-only" function into
the general REPL setup and further harmonizes the code.
2017-11-28 18:35:04 +02:00
Jesse Rosenberger
724a801d70 Remove unnecessary setting of repl.context.
This is superfluous residue that I inadvertently created when splitting the
existing `startREPL` function into `setupREPL` and `enableInteractiveMode`.

The context is already set in `setupREPL` (to the exact same value as
here) by the time that this occurrence in `enableInteractiveMode` is called.
2017-11-28 18:31:26 +02:00
Jesse Rosenberger
c8b5f42d05 Modernization of shell-server package. 2017-11-28 16:58:11 +02:00
Jesse Rosenberger
e0682c553d Wrap default repl "eval" function, rather than duplicating logic.
Addresses feedback from @benjamn.

Rather than copying the `IsRecoverableError` and `isCodeRecoverable`
methods from the Node.js `repl` module source (in order to capture
so-called "Recoverable" errors), wrap the default "eval" function with
our relatively thin logic, thus avoiding the need to continually update
the definition of what's "recoverable" as Node's implementation evolves.
2017-11-28 16:55:27 +02:00
Jesse Rosenberger
15b24ff6d1 Again, correct the context of _ within meteor shell.
A truthy `useGlobal` option when calling Node's `repl.start()` will use
the `global` context, which will allow global Meteor variables (such as
the global `_` provided by the `underscore`) to be available in the context
of the REPL shell.  This sounds desirable, and in fact, the original
implementation set it as such, only to be later changed to `false` in
https://github.com/meteor/meteor/commit/7c7e52f2d2, specifically to
avoid the undesirable behavior of Node REPL stomping on the global `_`
variable with its own special-meaning `_` variable which is set to the
value of the most recently eval'd expression.

This was once again changed to `true` to fix the lost tab-completion
functionality, thanks to https://github.com/meteor/meteor/commit/2443d83226,
which also implelented special mutator on `_` to avoid breaking
it.  As it's probably clear now, this has been a struggle, and because
of Node using its own `Object.defineProperty('_', ...)` as of Node.js 6
(in https://github.com/nodejs/node/pull/5535/files), this problem has
surfaced again, as reported in https://github.com/meteor/meteor/issues/9276.

This changes the behavior to another implementation which starts with
`useGlobal` set to `false`, but then sets the context immediately to
`global`, which seems to avoid the problem.

It's possible that another option might be to set explicitly set the
`underscoreAssigned` attribute on the `repl` after starting it, however
since that's an internal, undocumented property, it might be best to avoid.

This does maintain the existing behavior of our special
double-underscore variable, in order to get the value of the last
REPL expression, in the same manner as `_` would in a normal REPL, by
accessing the internal `last` property.  Since this is also undocumented
(on our end), this seemed reasonable.
2017-11-22 01:12:22 +02:00
Jesse Rosenberger
545a7e1df2 Stop stripping parens from ES classes used in the REPL.
As Node.js 8 natively supports ECMAScript classes, this code shouldn't
be necessary anymore.
2017-11-21 22:28:40 +02:00
Jesse Rosenberger
5849af067b Use the (now) repl-exported Recoverable error.
In order to catch so-called "recoverable" REPL errors (for example,
commands in the process of being inputted which are syntax errors until
they are completed/recovered), it had previously been necessary to
intentionally cause such an error and save the error's prototype for
future use.

Node 6 changed this by exporting the Error directly from the `repl`
module, and this commit represents the changes necessary to remove that
(now unnecessary) behavior.

This also takes the opportunity to update the `isRecoverableError` (and
related) functions which had previously been borrowed from the `repl`
module source, to their newer versions.
2017-11-21 22:28:40 +02:00
Jesse Rosenberger
83eba20918 Remove unused _inTemplateLiteral stored on repl instance. 2017-11-21 22:28:40 +02:00
Ben Newman
ac2595ad92 Merge branch 'devel' into release-1.5.1 2017-06-27 09:36:42 -04:00
Antonio Tapiador del Dujo
0b1a1ef59f Make require and module visible for meteor shell scripts 2017-06-27 09:31:43 -04:00
Antonio Tapiador del Dujo
2bcfb073c4 Remove parentheses wrapper of evaluateAndExit commmand
The prevented to run certain commands in scripts,
like `import { Foo } from './bar'`

See https://github.com/meteor/meteor/issues/8823
2017-06-27 09:31:43 -04:00
Jesse Rosenberger
4a9ddb6404 Add TODO about Node.js 6 repl changes.
Just a note to revisit this/clean-up in Node 6 as the `Recoverable` is now exported from Node 6's `eval` and this is no longer necessary.

* https://github.com/nodejs/node/blob/v6.x/lib/repl.js#L1398
* https://nodejs.org/api/repl.html#repl_custom_evaluation_functions
2017-03-03 17:16:39 +02:00
Matt McCutchen
28309de07b Shell: Don't be confused by SyntaxErrors thrown by command execution.
Apply the check for a SyntaxError indicating an incomplete command only
to the ECMAScript translation and parsing of a command and not to the
execution, following the example of Node's defaultEval function.

Fixes #8290.
2017-03-02 16:23:30 -05:00
Jesse Rosenberger
23c52ff002 meteor shell should pass its TTY width to the server on connect
Previously, the width (or "columns") for the readline shell was being obtained on the server.  This causes problems for clients which are connecting to the server which are sized differently.

The client will still have problems if they resize AFTER they are connected to the REPL, but at least they have the option of being a different size.

A more complete solution would be to have the client listen on process.stdout "resize" and pass that to the server when it occurs, but I'm not sure of an easy way to do that with the current communication (perhaps pause-reconfigure-unpause?).

Fixes meteor/meteor#5346
2016-12-12 12:57:16 +02:00
Ben Newman
3c7f83778f Move server-side component of meteor shell into a package. (#7624)
This will make it much easier to fix bugs and make improvements going
forward, since they won't have to wait for the next release of Meteor.

One functional change: when the parent process exits, it no longer forces
all connected shell clients to disconnect, which is actually a more
convenient behavior, because it gives the clients a chance to reconnect
when/if the server starts up again, and it's easy enough to kill the
clients if that's what you want.
2016-08-11 09:11:40 -04:00