@makano/rew 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/lib/civet/main.js +17239 -0
  2. package/lib/rew/cli/cli.js +34 -5
  3. package/lib/rew/cli/utils.js +43 -12
  4. package/lib/rew/const/default.js +2 -1
  5. package/lib/rew/const/ext.js +5 -0
  6. package/lib/rew/const/opt.js +7 -2
  7. package/lib/rew/const/usage.js +15 -0
  8. package/lib/rew/functions/export.js +1 -1
  9. package/lib/rew/functions/fs.js +6 -1
  10. package/lib/rew/functions/import.js +17 -12
  11. package/lib/rew/functions/require.js +17 -1
  12. package/lib/rew/functions/stdout.js +4 -0
  13. package/lib/rew/main.js +1 -13
  14. package/lib/rew/modules/compiler.js +103 -34
  15. package/lib/rew/modules/context.js +13 -1
  16. package/lib/rew/modules/runtime.js +37 -20
  17. package/lib/rew/pkgs/serve.js +373 -0
  18. package/lib/rew/pkgs/stream.js +10 -0
  19. package/lib/rew/pkgs/web.js +504 -0
  20. package/package.json +7 -5
  21. package/runtime.d.ts +718 -146
  22. package/jsconfig.json +0 -13
  23. package/lib/coffeescript/browser.js +0 -156
  24. package/lib/coffeescript/cake.js +0 -134
  25. package/lib/coffeescript/coffeescript.js +0 -465
  26. package/lib/coffeescript/command.js +0 -832
  27. package/lib/coffeescript/grammar.js +0 -1930
  28. package/lib/coffeescript/helpers.js +0 -513
  29. package/lib/coffeescript/index.js +0 -230
  30. package/lib/coffeescript/lexer.js +0 -2316
  31. package/lib/coffeescript/nodes.js +0 -9784
  32. package/lib/coffeescript/optparse.js +0 -258
  33. package/lib/coffeescript/parser.js +0 -20384
  34. package/lib/coffeescript/register.js +0 -120
  35. package/lib/coffeescript/repl.js +0 -328
  36. package/lib/coffeescript/rewriter.js +0 -1448
  37. package/lib/coffeescript/scope.js +0 -191
  38. package/lib/coffeescript/sourcemap.js +0 -244
@@ -1,120 +0,0 @@
1
- // Generated by CoffeeScript 2.7.0
2
- (function () {
3
- var CoffeeScript,
4
- Module,
5
- binary,
6
- cacheSourceMaps,
7
- child_process,
8
- ext,
9
- findExtension,
10
- fork,
11
- getRootModule,
12
- helpers,
13
- i,
14
- len,
15
- loadFile,
16
- nodeSourceMapsSupportEnabled,
17
- patchStackTrace,
18
- path,
19
- ref,
20
- ref1;
21
-
22
- CoffeeScript = require('./');
23
-
24
- child_process = require('child_process');
25
-
26
- helpers = require('./helpers');
27
-
28
- path = require('path');
29
-
30
- ({ patchStackTrace } = CoffeeScript);
31
-
32
- // Check if Node's built-in source map stack trace transformations are enabled.
33
- nodeSourceMapsSupportEnabled =
34
- typeof process !== 'undefined' &&
35
- process !== null &&
36
- (process.execArgv.includes('--enable-source-maps') ||
37
- ((ref = process.env.NODE_OPTIONS) != null ? ref.includes('--enable-source-maps') : void 0));
38
-
39
- if (!(Error.prepareStackTrace || nodeSourceMapsSupportEnabled)) {
40
- cacheSourceMaps = true;
41
- patchStackTrace();
42
- }
43
-
44
- // Load and run a CoffeeScript file for Node, stripping any `BOM`s.
45
- loadFile = function (module, filename) {
46
- var js, options;
47
- options = module.options || getRootModule(module).options || {};
48
- // Currently `CoffeeScript.compile` caches all source maps if present. They
49
- // are available in `getSourceMap` retrieved by `filename`.
50
- if (cacheSourceMaps || nodeSourceMapsSupportEnabled) {
51
- options.inlineMap = true;
52
- }
53
- js = CoffeeScript._compileFile(filename, options);
54
- return module._compile(js, filename);
55
- };
56
-
57
- // If the installed version of Node supports `require.extensions`, register
58
- // CoffeeScript as an extension.
59
- if (require.extensions) {
60
- ref1 = CoffeeScript.FILE_EXTENSIONS;
61
- for (i = 0, len = ref1.length; i < len; i++) {
62
- ext = ref1[i];
63
- require.extensions[ext] = loadFile;
64
- }
65
- // Patch Node's module loader to be able to handle multi-dot extensions.
66
- // This is a horrible thing that should not be required.
67
- Module = require('module');
68
- findExtension = function (filename) {
69
- var curExtension, extensions;
70
- extensions = path.basename(filename).split('.');
71
- if (extensions[0] === '') {
72
- // Remove the initial dot from dotfiles.
73
- extensions.shift();
74
- }
75
- // Start with the longest possible extension and work our way shortwards.
76
- while (extensions.shift()) {
77
- curExtension = '.' + extensions.join('.');
78
- if (Module._extensions[curExtension]) {
79
- return curExtension;
80
- }
81
- }
82
- return '.js';
83
- };
84
- Module.prototype.load = function (filename) {
85
- var extension;
86
- this.filename = filename;
87
- this.paths = Module._nodeModulePaths(path.dirname(filename));
88
- extension = findExtension(filename);
89
- Module._extensions[extension](this, filename);
90
- return (this.loaded = true);
91
- };
92
- }
93
-
94
- // If we're on Node, patch `child_process.fork` so that Coffee scripts are able
95
- // to fork both CoffeeScript files, and JavaScript files, directly.
96
- if (child_process) {
97
- ({ fork } = child_process);
98
- binary = require.resolve('../../bin/coffee');
99
- child_process.fork = function (path, args, options) {
100
- if (helpers.isCoffee(path)) {
101
- if (!Array.isArray(args)) {
102
- options = args || {};
103
- args = [];
104
- }
105
- args = [path].concat(args);
106
- path = binary;
107
- }
108
- return fork(path, args, options);
109
- };
110
- }
111
-
112
- // Utility function to find the `options` object attached to the topmost module.
113
- getRootModule = function (module) {
114
- if (module.parent) {
115
- return getRootModule(module.parent);
116
- } else {
117
- return module;
118
- }
119
- };
120
- }).call(this);
@@ -1,328 +0,0 @@
1
- // Generated by CoffeeScript 2.7.0
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;
17
-
18
- fs = require('fs');
19
-
20
- path = require('path');
21
-
22
- vm = require('vm');
23
-
24
- nodeREPL = require('repl');
25
-
26
- CoffeeScript = require('./');
27
-
28
- ({ merge, updateSyntaxError } = require('./helpers'));
29
-
30
- sawSIGINT = false;
31
-
32
- transpile = false;
33
-
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
- };
130
-
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
- };
138
-
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
- };
201
-
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
- };
252
-
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
- };
263
-
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:
285
- npm install --save-dev @babel/core
286
- or
287
- npm install --global @babel/core
288
- And you must save options to configure Babel in one of the places it looks to find its options.
289
- See https://coffeescript.org/#transpilation`);
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
- };
328
- }).call(this);