@makano/rew 1.1.73 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/lib/coffeescript/browser.js +144 -139
  2. package/lib/coffeescript/cake.js +132 -133
  3. package/lib/coffeescript/coffeescript.js +437 -381
  4. package/lib/coffeescript/command.js +806 -724
  5. package/lib/coffeescript/grammar.js +1908 -2474
  6. package/lib/coffeescript/helpers.js +509 -473
  7. package/lib/coffeescript/index.js +228 -215
  8. package/lib/coffeescript/lexer.js +2282 -1909
  9. package/lib/coffeescript/nodes.js +9782 -9202
  10. package/lib/coffeescript/optparse.js +255 -227
  11. package/lib/coffeescript/parser.js +20305 -1265
  12. package/lib/coffeescript/register.js +107 -87
  13. package/lib/coffeescript/repl.js +307 -284
  14. package/lib/coffeescript/rewriter.js +1389 -1079
  15. package/lib/coffeescript/scope.js +176 -172
  16. package/lib/coffeescript/sourcemap.js +242 -227
  17. package/lib/rew/cli/cli.js +288 -186
  18. package/lib/rew/cli/log.js +31 -32
  19. package/lib/rew/cli/run.js +10 -12
  20. package/lib/rew/cli/utils.js +344 -176
  21. package/lib/rew/const/config_path.js +4 -0
  22. package/lib/rew/const/default.js +38 -35
  23. package/lib/rew/const/files.js +9 -9
  24. package/lib/rew/const/opt.js +8 -8
  25. package/lib/rew/css/theme.css +2 -2
  26. package/lib/rew/functions/core.js +55 -57
  27. package/lib/rew/functions/curl.js +23 -0
  28. package/lib/rew/functions/emitter.js +52 -55
  29. package/lib/rew/functions/exec.js +25 -21
  30. package/lib/rew/functions/export.js +18 -20
  31. package/lib/rew/functions/fs.js +55 -54
  32. package/lib/rew/functions/future.js +29 -21
  33. package/lib/rew/functions/id.js +8 -9
  34. package/lib/rew/functions/import.js +107 -93
  35. package/lib/rew/functions/map.js +13 -16
  36. package/lib/rew/functions/match.js +35 -26
  37. package/lib/rew/functions/path.js +8 -8
  38. package/lib/rew/functions/require.js +32 -33
  39. package/lib/rew/functions/sleep.js +2 -2
  40. package/lib/rew/functions/stdout.js +20 -20
  41. package/lib/rew/functions/types.js +96 -95
  42. package/lib/rew/html/ui.html +12 -13
  43. package/lib/rew/html/ui.js +205 -168
  44. package/lib/rew/main.js +14 -14
  45. package/lib/rew/misc/bin.js +37 -0
  46. package/lib/rew/misc/findAppInfo.js +16 -0
  47. package/lib/rew/misc/findAppPath.js +21 -0
  48. package/lib/rew/misc/req.js +7 -0
  49. package/lib/rew/misc/seededid.js +13 -0
  50. package/lib/rew/models/enum.js +12 -12
  51. package/lib/rew/models/struct.js +30 -32
  52. package/lib/rew/modules/compiler.js +237 -177
  53. package/lib/rew/modules/context.js +35 -22
  54. package/lib/rew/modules/fs.js +10 -10
  55. package/lib/rew/modules/runtime.js +17 -21
  56. package/lib/rew/modules/yaml.js +27 -30
  57. package/lib/rew/pkgs/conf.js +82 -75
  58. package/lib/rew/pkgs/data.js +12 -7
  59. package/lib/rew/pkgs/date.js +27 -28
  60. package/lib/rew/pkgs/env.js +6 -8
  61. package/lib/rew/pkgs/modules/data/bintree.js +52 -52
  62. package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
  63. package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
  64. package/lib/rew/pkgs/modules/data/queue.js +19 -20
  65. package/lib/rew/pkgs/modules/data/stack.js +19 -19
  66. package/lib/rew/pkgs/modules/threads/worker.js +36 -26
  67. package/lib/rew/pkgs/modules/ui/classes.js +182 -178
  68. package/lib/rew/pkgs/pkgs.js +9 -10
  69. package/lib/rew/pkgs/rune.js +400 -0
  70. package/lib/rew/pkgs/threads.js +57 -53
  71. package/lib/rew/pkgs/ui.js +148 -136
  72. package/lib/rew/qrew/compile.js +12 -0
  73. package/package.json +11 -4
@@ -1,305 +1,328 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- (function() {
3
- var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, replDefaults, runInContext, sawSIGINT, transpile, updateSyntaxError, vm;
2
+ (function () {
3
+ var CoffeeScript,
4
+ addHistory,
5
+ addMultilineHandler,
6
+ fs,
7
+ getCommandId,
8
+ merge,
9
+ nodeREPL,
10
+ path,
11
+ replDefaults,
12
+ runInContext,
13
+ sawSIGINT,
14
+ transpile,
15
+ updateSyntaxError,
16
+ vm;
4
17
 
5
- fs = require('fs');
18
+ fs = require('fs');
6
19
 
7
- path = require('path');
20
+ path = require('path');
8
21
 
9
- vm = require('vm');
22
+ vm = require('vm');
10
23
 
11
- nodeREPL = require('repl');
24
+ nodeREPL = require('repl');
12
25
 
13
- CoffeeScript = require('./');
26
+ CoffeeScript = require('./');
14
27
 
15
- ({merge, updateSyntaxError} = require('./helpers'));
28
+ ({ merge, updateSyntaxError } = require('./helpers'));
16
29
 
17
- sawSIGINT = false;
30
+ sawSIGINT = false;
18
31
 
19
- transpile = false;
32
+ transpile = false;
20
33
 
21
- replDefaults = {
22
- prompt: 'coffee> ',
23
- historyFile: (function() {
24
- var historyPath;
25
- historyPath = process.env.XDG_CACHE_HOME || process.env.HOME;
26
- if (historyPath) {
27
- return path.join(historyPath, '.coffee_history');
28
- }
29
- })(),
30
- historyMaxInputSize: 10240,
31
- eval: function(input, context, filename, cb) {
32
- var Assign, Block, Call, Code, Literal, Root, Value, ast, err, isAsync, js, ref, ref1, referencedVars, result, token, tokens;
33
- // XXX: multiline hack.
34
- input = input.replace(/\uFF00/g, '\n');
35
- // Node's REPL sends the input ending with a newline and then wrapped in
36
- // parens. Unwrap all that.
37
- input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
38
- // Node's REPL v6.9.1+ sends the input wrapped in a try/catch statement.
39
- // Unwrap that too.
40
- input = input.replace(/^\s*try\s*{([\s\S]*)}\s*catch.*$/m, '$1');
41
- // Require AST nodes to do some AST manipulation.
42
- ({Block, Assign, Value, Literal, Call, Code, Root} = require('./nodes'));
43
- try {
44
- // Tokenize the clean input.
45
- tokens = CoffeeScript.tokens(input);
46
- // Filter out tokens generated just to hold comments.
47
- if (tokens.length >= 2 && tokens[0].generated && ((ref = tokens[0].comments) != null ? ref.length : void 0) !== 0 && `${tokens[0][1]}` === '' && tokens[1][0] === 'TERMINATOR') {
48
- tokens = tokens.slice(2);
49
- }
50
- if (tokens.length >= 1 && tokens[tokens.length - 1].generated && ((ref1 = tokens[tokens.length - 1].comments) != null ? ref1.length : void 0) !== 0 && `${tokens[tokens.length - 1][1]}` === '') {
51
- tokens.pop();
52
- }
53
- // Collect referenced variable names just like in `CoffeeScript.compile`.
54
- referencedVars = (function() {
55
- var i, len, results;
56
- results = [];
57
- for (i = 0, len = tokens.length; i < len; i++) {
58
- token = tokens[i];
59
- if (token[0] === 'IDENTIFIER') {
60
- results.push(token[1]);
61
- }
62
- }
63
- return results;
64
- })();
65
- // Generate the AST of the tokens.
66
- ast = CoffeeScript.nodes(tokens).body;
67
- // Add assignment to `__` variable to force the input to be an expression.
68
- ast = new Block([new Assign(new Value(new Literal('__')), ast, '=')]);
69
- // Wrap the expression in a closure to support top-level `await`.
70
- ast = new Code([], ast);
71
- isAsync = ast.isAsync;
72
- // Invoke the wrapping closure.
73
- ast = new Root(new Block([new Call(ast)]));
74
- js = ast.compile({
75
- bare: true,
76
- locals: Object.keys(context),
77
- referencedVars,
78
- sharedScope: true
79
- });
80
- if (transpile) {
81
- js = transpile.transpile(js, transpile.options).code;
82
- // Strip `"use strict"`, to avoid an exception on assigning to
83
- // undeclared variable `__`.
84
- js = js.replace(/^"use strict"|^'use strict'/, '');
85
- }
86
- result = runInContext(js, context, filename);
87
- // Await an async result, if necessary.
88
- if (isAsync) {
89
- result.then(function(resolvedResult) {
90
- if (!sawSIGINT) {
91
- return cb(null, resolvedResult);
92
- }
93
- });
94
- return sawSIGINT = false;
95
- } else {
96
- return cb(null, result);
97
- }
98
- } catch (error) {
99
- err = error;
100
- // AST's `compile` does not add source code information to syntax errors.
101
- updateSyntaxError(err, input);
102
- return cb(err);
103
- }
104
- }
105
- };
34
+ replDefaults = {
35
+ prompt: 'coffee> ',
36
+ historyFile: (function () {
37
+ var historyPath;
38
+ historyPath = process.env.XDG_CACHE_HOME || process.env.HOME;
39
+ if (historyPath) {
40
+ return path.join(historyPath, '.coffee_history');
41
+ }
42
+ })(),
43
+ historyMaxInputSize: 10240,
44
+ eval: function (input, context, filename, cb) {
45
+ var Assign, Block, Call, Code, Literal, Root, Value, ast, err, isAsync, js, ref, ref1, referencedVars, result, token, tokens;
46
+ // XXX: multiline hack.
47
+ input = input.replace(/\uFF00/g, '\n');
48
+ // Node's REPL sends the input ending with a newline and then wrapped in
49
+ // parens. Unwrap all that.
50
+ input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
51
+ // Node's REPL v6.9.1+ sends the input wrapped in a try/catch statement.
52
+ // Unwrap that too.
53
+ input = input.replace(/^\s*try\s*{([\s\S]*)}\s*catch.*$/m, '$1');
54
+ // Require AST nodes to do some AST manipulation.
55
+ ({ Block, Assign, Value, Literal, Call, Code, Root } = require('./nodes'));
56
+ try {
57
+ // Tokenize the clean input.
58
+ tokens = CoffeeScript.tokens(input);
59
+ // Filter out tokens generated just to hold comments.
60
+ if (
61
+ tokens.length >= 2 &&
62
+ tokens[0].generated &&
63
+ ((ref = tokens[0].comments) != null ? ref.length : void 0) !== 0 &&
64
+ `${tokens[0][1]}` === '' &&
65
+ tokens[1][0] === 'TERMINATOR'
66
+ ) {
67
+ tokens = tokens.slice(2);
68
+ }
69
+ if (
70
+ tokens.length >= 1 &&
71
+ tokens[tokens.length - 1].generated &&
72
+ ((ref1 = tokens[tokens.length - 1].comments) != null ? ref1.length : void 0) !== 0 &&
73
+ `${tokens[tokens.length - 1][1]}` === ''
74
+ ) {
75
+ tokens.pop();
76
+ }
77
+ // Collect referenced variable names just like in `CoffeeScript.compile`.
78
+ referencedVars = (function () {
79
+ var i, len, results;
80
+ results = [];
81
+ for (i = 0, len = tokens.length; i < len; i++) {
82
+ token = tokens[i];
83
+ if (token[0] === 'IDENTIFIER') {
84
+ results.push(token[1]);
85
+ }
86
+ }
87
+ return results;
88
+ })();
89
+ // Generate the AST of the tokens.
90
+ ast = CoffeeScript.nodes(tokens).body;
91
+ // Add assignment to `__` variable to force the input to be an expression.
92
+ ast = new Block([new Assign(new Value(new Literal('__')), ast, '=')]);
93
+ // Wrap the expression in a closure to support top-level `await`.
94
+ ast = new Code([], ast);
95
+ isAsync = ast.isAsync;
96
+ // Invoke the wrapping closure.
97
+ ast = new Root(new Block([new Call(ast)]));
98
+ js = ast.compile({
99
+ bare: true,
100
+ locals: Object.keys(context),
101
+ referencedVars,
102
+ sharedScope: true,
103
+ });
104
+ if (transpile) {
105
+ js = transpile.transpile(js, transpile.options).code;
106
+ // Strip `"use strict"`, to avoid an exception on assigning to
107
+ // undeclared variable `__`.
108
+ js = js.replace(/^"use strict"|^'use strict'/, '');
109
+ }
110
+ result = runInContext(js, context, filename);
111
+ // Await an async result, if necessary.
112
+ if (isAsync) {
113
+ result.then(function (resolvedResult) {
114
+ if (!sawSIGINT) {
115
+ return cb(null, resolvedResult);
116
+ }
117
+ });
118
+ return (sawSIGINT = false);
119
+ } else {
120
+ return cb(null, result);
121
+ }
122
+ } catch (error) {
123
+ err = error;
124
+ // AST's `compile` does not add source code information to syntax errors.
125
+ updateSyntaxError(err, input);
126
+ return cb(err);
127
+ }
128
+ },
129
+ };
106
130
 
107
- runInContext = function(js, context, filename) {
108
- if (context === global) {
109
- return vm.runInThisContext(js, filename);
110
- } else {
111
- return vm.runInContext(js, context, filename);
112
- }
113
- };
131
+ runInContext = function (js, context, filename) {
132
+ if (context === global) {
133
+ return vm.runInThisContext(js, filename);
134
+ } else {
135
+ return vm.runInContext(js, context, filename);
136
+ }
137
+ };
114
138
 
115
- addMultilineHandler = function(repl) {
116
- var inputStream, multiline, nodeLineListener, origPrompt, outputStream, ref;
117
- ({inputStream, outputStream} = repl);
118
- // Node 0.11.12 changed API, prompt is now _prompt.
119
- origPrompt = (ref = repl._prompt) != null ? ref : repl.prompt;
120
- multiline = {
121
- enabled: false,
122
- initialPrompt: origPrompt.replace(/^[^> ]*/, function(x) {
123
- return x.replace(/./g, '-');
124
- }),
125
- prompt: origPrompt.replace(/^[^> ]*>?/, function(x) {
126
- return x.replace(/./g, '.');
127
- }),
128
- buffer: ''
129
- };
130
- // Proxy node's line listener
131
- nodeLineListener = repl.listeners('line')[0];
132
- repl.removeListener('line', nodeLineListener);
133
- repl.on('line', function(cmd) {
134
- if (multiline.enabled) {
135
- multiline.buffer += `${cmd}\n`;
136
- repl.setPrompt(multiline.prompt);
137
- repl.prompt(true);
138
- } else {
139
- repl.setPrompt(origPrompt);
140
- nodeLineListener(cmd);
141
- }
142
- });
143
- // Handle Ctrl-v
144
- return inputStream.on('keypress', function(char, key) {
145
- if (!(key && key.ctrl && !key.meta && !key.shift && key.name === 'v')) {
146
- return;
147
- }
148
- if (multiline.enabled) {
149
- // allow arbitrarily switching between modes any time before multiple lines are entered
150
- if (!multiline.buffer.match(/\n/)) {
151
- multiline.enabled = !multiline.enabled;
152
- repl.setPrompt(origPrompt);
153
- repl.prompt(true);
154
- return;
155
- }
156
- // no-op unless the current line is empty
157
- if ((repl.line != null) && !repl.line.match(/^\s*$/)) {
158
- return;
159
- }
160
- // eval, print, loop
161
- multiline.enabled = !multiline.enabled;
162
- repl.line = '';
163
- repl.cursor = 0;
164
- repl.output.cursorTo(0);
165
- repl.output.clearLine(1);
166
- // XXX: multiline hack
167
- multiline.buffer = multiline.buffer.replace(/\n/g, '\uFF00');
168
- repl.emit('line', multiline.buffer);
169
- multiline.buffer = '';
170
- } else {
171
- multiline.enabled = !multiline.enabled;
172
- repl.setPrompt(multiline.initialPrompt);
173
- repl.prompt(true);
174
- }
175
- });
176
- };
139
+ addMultilineHandler = function (repl) {
140
+ var inputStream, multiline, nodeLineListener, origPrompt, outputStream, ref;
141
+ ({ inputStream, outputStream } = repl);
142
+ // Node 0.11.12 changed API, prompt is now _prompt.
143
+ origPrompt = (ref = repl._prompt) != null ? ref : repl.prompt;
144
+ multiline = {
145
+ enabled: false,
146
+ initialPrompt: origPrompt.replace(/^[^> ]*/, function (x) {
147
+ return x.replace(/./g, '-');
148
+ }),
149
+ prompt: origPrompt.replace(/^[^> ]*>?/, function (x) {
150
+ return x.replace(/./g, '.');
151
+ }),
152
+ buffer: '',
153
+ };
154
+ // Proxy node's line listener
155
+ nodeLineListener = repl.listeners('line')[0];
156
+ repl.removeListener('line', nodeLineListener);
157
+ repl.on('line', function (cmd) {
158
+ if (multiline.enabled) {
159
+ multiline.buffer += `${cmd}\n`;
160
+ repl.setPrompt(multiline.prompt);
161
+ repl.prompt(true);
162
+ } else {
163
+ repl.setPrompt(origPrompt);
164
+ nodeLineListener(cmd);
165
+ }
166
+ });
167
+ // Handle Ctrl-v
168
+ return inputStream.on('keypress', function (char, key) {
169
+ if (!(key && key.ctrl && !key.meta && !key.shift && key.name === 'v')) {
170
+ return;
171
+ }
172
+ if (multiline.enabled) {
173
+ // allow arbitrarily switching between modes any time before multiple lines are entered
174
+ if (!multiline.buffer.match(/\n/)) {
175
+ multiline.enabled = !multiline.enabled;
176
+ repl.setPrompt(origPrompt);
177
+ repl.prompt(true);
178
+ return;
179
+ }
180
+ // no-op unless the current line is empty
181
+ if (repl.line != null && !repl.line.match(/^\s*$/)) {
182
+ return;
183
+ }
184
+ // eval, print, loop
185
+ multiline.enabled = !multiline.enabled;
186
+ repl.line = '';
187
+ repl.cursor = 0;
188
+ repl.output.cursorTo(0);
189
+ repl.output.clearLine(1);
190
+ // XXX: multiline hack
191
+ multiline.buffer = multiline.buffer.replace(/\n/g, '\uFF00');
192
+ repl.emit('line', multiline.buffer);
193
+ multiline.buffer = '';
194
+ } else {
195
+ multiline.enabled = !multiline.enabled;
196
+ repl.setPrompt(multiline.initialPrompt);
197
+ repl.prompt(true);
198
+ }
199
+ });
200
+ };
177
201
 
178
- // Store and load command history from a file
179
- addHistory = function(repl, filename, maxSize) {
180
- var buffer, fd, lastLine, readFd, size, stat;
181
- lastLine = null;
182
- try {
183
- // Get file info and at most maxSize of command history
184
- stat = fs.statSync(filename);
185
- size = Math.min(maxSize, stat.size);
186
- // Read last `size` bytes from the file
187
- readFd = fs.openSync(filename, 'r');
188
- buffer = Buffer.alloc(size);
189
- fs.readSync(readFd, buffer, 0, size, stat.size - size);
190
- fs.closeSync(readFd);
191
- // Set the history on the interpreter
192
- repl.history = buffer.toString().split('\n').reverse();
193
- if (stat.size > maxSize) {
194
- // If the history file was truncated we should pop off a potential partial line
195
- repl.history.pop();
196
- }
197
- if (repl.history[0] === '') {
198
- // Shift off the final blank newline
199
- repl.history.shift();
200
- }
201
- repl.historyIndex = -1;
202
- lastLine = repl.history[0];
203
- } catch (error) {}
204
- fd = fs.openSync(filename, 'a');
205
- repl.addListener('line', function(code) {
206
- if (code && code.length && code !== '.history' && code !== '.exit' && lastLine !== code) {
207
- // Save the latest command in the file
208
- fs.writeSync(fd, `${code}\n`);
209
- return lastLine = code;
210
- }
211
- });
212
- // XXX: The SIGINT event from REPLServer is undocumented, so this is a bit fragile
213
- repl.on('SIGINT', function() {
214
- return sawSIGINT = true;
215
- });
216
- repl.on('exit', function() {
217
- return fs.closeSync(fd);
218
- });
219
- // Add a command to show the history stack
220
- return repl.commands[getCommandId(repl, 'history')] = {
221
- help: 'Show command history',
222
- action: function() {
223
- repl.outputStream.write(`${repl.history.slice(0).reverse().join('\n')}\n`);
224
- return repl.displayPrompt();
225
- }
226
- };
227
- };
202
+ // Store and load command history from a file
203
+ addHistory = function (repl, filename, maxSize) {
204
+ var buffer, fd, lastLine, readFd, size, stat;
205
+ lastLine = null;
206
+ try {
207
+ // Get file info and at most maxSize of command history
208
+ stat = fs.statSync(filename);
209
+ size = Math.min(maxSize, stat.size);
210
+ // Read last `size` bytes from the file
211
+ readFd = fs.openSync(filename, 'r');
212
+ buffer = Buffer.alloc(size);
213
+ fs.readSync(readFd, buffer, 0, size, stat.size - size);
214
+ fs.closeSync(readFd);
215
+ // Set the history on the interpreter
216
+ repl.history = buffer.toString().split('\n').reverse();
217
+ if (stat.size > maxSize) {
218
+ // If the history file was truncated we should pop off a potential partial line
219
+ repl.history.pop();
220
+ }
221
+ if (repl.history[0] === '') {
222
+ // Shift off the final blank newline
223
+ repl.history.shift();
224
+ }
225
+ repl.historyIndex = -1;
226
+ lastLine = repl.history[0];
227
+ } catch (error) {}
228
+ fd = fs.openSync(filename, 'a');
229
+ repl.addListener('line', function (code) {
230
+ if (code && code.length && code !== '.history' && code !== '.exit' && lastLine !== code) {
231
+ // Save the latest command in the file
232
+ fs.writeSync(fd, `${code}\n`);
233
+ return (lastLine = code);
234
+ }
235
+ });
236
+ // XXX: The SIGINT event from REPLServer is undocumented, so this is a bit fragile
237
+ repl.on('SIGINT', function () {
238
+ return (sawSIGINT = true);
239
+ });
240
+ repl.on('exit', function () {
241
+ return fs.closeSync(fd);
242
+ });
243
+ // Add a command to show the history stack
244
+ return (repl.commands[getCommandId(repl, 'history')] = {
245
+ help: 'Show command history',
246
+ action: function () {
247
+ repl.outputStream.write(`${repl.history.slice(0).reverse().join('\n')}\n`);
248
+ return repl.displayPrompt();
249
+ },
250
+ });
251
+ };
228
252
 
229
- getCommandId = function(repl, commandName) {
230
- var commandsHaveLeadingDot;
231
- // Node 0.11 changed API, a command such as '.help' is now stored as 'help'
232
- commandsHaveLeadingDot = repl.commands['.help'] != null;
233
- if (commandsHaveLeadingDot) {
234
- return `.${commandName}`;
235
- } else {
236
- return commandName;
237
- }
238
- };
253
+ getCommandId = function (repl, commandName) {
254
+ var commandsHaveLeadingDot;
255
+ // Node 0.11 changed API, a command such as '.help' is now stored as 'help'
256
+ commandsHaveLeadingDot = repl.commands['.help'] != null;
257
+ if (commandsHaveLeadingDot) {
258
+ return `.${commandName}`;
259
+ } else {
260
+ return commandName;
261
+ }
262
+ };
239
263
 
240
- module.exports = {
241
- start: function(opts = {}) {
242
- var Module, build, major, minor, originalModuleLoad, repl;
243
- [major, minor, build] = process.versions.node.split('.').map(function(n) {
244
- return parseInt(n, 10);
245
- });
246
- if (major < 6) {
247
- console.warn("Node 6+ required for CoffeeScript REPL");
248
- process.exit(1);
249
- }
250
- CoffeeScript.register();
251
- process.argv = ['coffee'].concat(process.argv.slice(2));
252
- if (opts.transpile) {
253
- transpile = {};
254
- try {
255
- transpile.transpile = require('@babel/core').transform;
256
- } catch (error) {
257
- try {
258
- transpile.transpile = require('babel-core').transform;
259
- } catch (error) {
260
- console.error(`To use --transpile with an interactive REPL, @babel/core must be installed either in the current folder or globally:
264
+ module.exports = {
265
+ start: function (opts = {}) {
266
+ var Module, build, major, minor, originalModuleLoad, repl;
267
+ [major, minor, build] = process.versions.node.split('.').map(function (n) {
268
+ return parseInt(n, 10);
269
+ });
270
+ if (major < 6) {
271
+ console.warn('Node 6+ required for CoffeeScript REPL');
272
+ process.exit(1);
273
+ }
274
+ CoffeeScript.register();
275
+ process.argv = ['coffee'].concat(process.argv.slice(2));
276
+ if (opts.transpile) {
277
+ transpile = {};
278
+ try {
279
+ transpile.transpile = require('@babel/core').transform;
280
+ } catch (error) {
281
+ try {
282
+ transpile.transpile = require('babel-core').transform;
283
+ } catch (error) {
284
+ console.error(`To use --transpile with an interactive REPL, @babel/core must be installed either in the current folder or globally:
261
285
  npm install --save-dev @babel/core
262
286
  or
263
287
  npm install --global @babel/core
264
288
  And you must save options to configure Babel in one of the places it looks to find its options.
265
289
  See https://coffeescript.org/#transpilation`);
266
- process.exit(1);
267
- }
268
- }
269
- transpile.options = {
270
- filename: path.resolve(process.cwd(), '<repl>')
271
- };
272
- // Since the REPL compilation path is unique (in `eval` above), we need
273
- // another way to get the `options` object attached to a module so that
274
- // it knows later on whether it needs to be transpiled. In the case of
275
- // the REPL, the only applicable option is `transpile`.
276
- Module = require('module');
277
- originalModuleLoad = Module.prototype.load;
278
- Module.prototype.load = function(filename) {
279
- this.options = {
280
- transpile: transpile.options
281
- };
282
- return originalModuleLoad.call(this, filename);
283
- };
284
- }
285
- opts = merge(replDefaults, opts);
286
- repl = nodeREPL.start(opts);
287
- if (opts.prelude) {
288
- runInContext(opts.prelude, repl.context, 'prelude');
289
- }
290
- repl.on('exit', function() {
291
- if (!repl.closed) {
292
- return repl.outputStream.write('\n');
293
- }
294
- });
295
- addMultilineHandler(repl);
296
- if (opts.historyFile) {
297
- addHistory(repl, opts.historyFile, opts.historyMaxInputSize);
298
- }
299
- // Adapt help inherited from the node REPL
300
- repl.commands[getCommandId(repl, 'load')].help = 'Load code from a file into this REPL session';
301
- return repl;
302
- }
303
- };
304
-
290
+ process.exit(1);
291
+ }
292
+ }
293
+ transpile.options = {
294
+ filename: path.resolve(process.cwd(), '<repl>'),
295
+ };
296
+ // Since the REPL compilation path is unique (in `eval` above), we need
297
+ // another way to get the `options` object attached to a module so that
298
+ // it knows later on whether it needs to be transpiled. In the case of
299
+ // the REPL, the only applicable option is `transpile`.
300
+ Module = require('module');
301
+ originalModuleLoad = Module.prototype.load;
302
+ Module.prototype.load = function (filename) {
303
+ this.options = {
304
+ transpile: transpile.options,
305
+ };
306
+ return originalModuleLoad.call(this, filename);
307
+ };
308
+ }
309
+ opts = merge(replDefaults, opts);
310
+ repl = nodeREPL.start(opts);
311
+ if (opts.prelude) {
312
+ runInContext(opts.prelude, repl.context, 'prelude');
313
+ }
314
+ repl.on('exit', function () {
315
+ if (!repl.closed) {
316
+ return repl.outputStream.write('\n');
317
+ }
318
+ });
319
+ addMultilineHandler(repl);
320
+ if (opts.historyFile) {
321
+ addHistory(repl, opts.historyFile, opts.historyMaxInputSize);
322
+ }
323
+ // Adapt help inherited from the node REPL
324
+ repl.commands[getCommandId(repl, 'load')].help = 'Load code from a file into this REPL session';
325
+ return repl;
326
+ },
327
+ };
305
328
  }).call(this);