• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Inist-CNRS / ezs / 17267738980

27 Aug 2025 01:12PM UTC coverage: 95.388% (-0.1%) from 95.519%
17267738980

Pull #462

github

web-flow
Merge 22c6668dc into 56ca7b899
Pull Request #462: feat: 🎸 add [detach]

2220 of 2404 branches covered (92.35%)

Branch coverage included in aggregate %.

34 of 38 new or added lines in 6 files covered. (89.47%)

4 existing lines in 2 files now uncovered.

4584 of 4729 relevant lines covered (96.93%)

80855.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.89
/packages/core/src/index.js
1
import { PassThrough } from 'readable-stream';
2
import debug from 'debug';
3
import writeTo from 'stream-write';
4
import LRU from 'lru-cache';
5
import Engine from './engine.js';
6
import Script, { parseCommand } from './script.js';
7
import File from './file.js';
8
import Output from './output.js';
9
import Commands from './commands.js';
10
import Catcher from './catcher.js';
11
import Statements from './statements/index.js';
12
import Statement from './statement.js';
13
import Meta from './meta.js';
14
import Server from './server/index.js';
15
import settings from './settings.js';
16
import { compressStream, uncompressStream } from './compactor.js';
17

18
const onlyOne = (item) => (Array.isArray(item) ? item.shift() : item);
22,048!
19

20
const ezs = (name, options, environment) => new Engine(ezs, Statement.get(ezs, name, options), options, environment);
51,833✔
21
const ezsCache = new LRU(settings.cache);
1,074✔
22

23
ezs.serializeError = (err) => JSON.stringify(err, Object.getOwnPropertyNames(err).sort());
12,102✔
24
ezs.memoize = (key, func) => {
1,074✔
25
    if (!key || !settings.cacheEnable) {
195,036✔
26
        return func();
185,696✔
27
    }
28
    const cached = ezsCache.get(key);
9,340✔
29
    if (cached) {
9,340✔
30
        return cached;
4,568✔
31
    }
32
    const tocache = func();
4,772✔
33
    if (tocache) {
4,772✔
34
        ezsCache.set(key, tocache);
1,074✔
35
    }
36
    return tocache;
4,772✔
37
};
38
ezs.settings = settings;
1,074✔
39
ezs.objectMode = () => ({
60,093✔
40
    objectMode: true,
41
    highWaterMark: settings.highWaterMark.object,
42
});
43
ezs.bytesMode = () => ({
1,074✔
44
    objectMode: false,
45
    highWaterMark: ezs.settings.highWaterMark.bytes,
46
});
47
ezs.encodingMode = () => ({
1,074✔
48
    'Content-Encoding': settings.encoding,
49
});
50
ezs.metaString = (commands, options) => ezs.memoize(`ezs.metaFile>${commands}`, () => new Meta(ezs, commands, options));
1,074✔
51
ezs.metaFile = (filename, options) => ezs.memoize(`ezs.metaFile>${filename}`, () => new Meta(ezs, ezs.loadScript(filename), options));
1,074✔
52
ezs.parseString = (commands) => Script(commands);
11,168✔
53
ezs.parseFile = (filename) => Script(ezs.loadScript(filename));
1,074✔
54
ezs.catch = (func) => new Catcher(func);
14,502✔
55
ezs.toBuffer = (options) => new Output(options);
1,074✔
56
ezs.use = (plugin) => Statement.set(ezs, plugin);
16,536✔
57
ezs.useFiles = (files) => {
1,074✔
58
    if (files) {
114!
NEW
59
        files.map(file=> Statement.load(ezs, file));
×
60
    }
61
    return Statement.list();
114✔
62
};
63
ezs.addPath = (p) => ezs.settings.pluginPaths.push(p);
1,074✔
64
ezs.getPath = () => ezs.settings.pluginPaths;
33,126✔
65
ezs.getCache = () => ezsCache;
1,074✔
66
ezs.loadScript = (file) => ezs.memoize(`ezs.loadScript>${file}`, () => File(ezs, file));
11,546✔
67
ezs.compileScript = (script) => new Commands(ezs.parseString(script));
11,144✔
68
ezs.parseCommand = (command) => ezs.memoize(`ezs.parseCommand>${command}`, () => parseCommand(command));
34,206✔
69
ezs.createCommand = (commandIN, environment) => {
1,074✔
70
    const command = typeof commandIN === 'object' ? commandIN : ezs.parseCommand(commandIN);
31,854✔
71
    if (!command.name) {
31,854✔
72
        throw new Error(`Bad command : ${command.name}`);
18✔
73
    }
74
    if (command.use) {
31,836✔
75
        Statement.load(ezs, command.use);
84✔
76
    }
77
    if (Statement.exists(ezs, command.mode)) {
31,830✔
78
        return ezs(command.mode, { commands: [{ name: command.name, args: command.args }] }, environment);
6✔
79
    }
80
    return ezs(command.name, command.args, environment);
31,824✔
81
};
82
ezs.compileCommands = (commands, environment) => {
1,074✔
83
    if (!Array.isArray(commands)) {
12,050✔
84
        throw new Error('Pipeline works with an array of commands.');
6✔
85
    }
86
    const cmds = [...commands];
12,044✔
87
    const streams = cmds.map((command) => ezs.createCommand(command, environment));
31,316✔
88
    if (streams.length === 0) {
12,032✔
89
        return [new PassThrough(ezs.objectMode())];
6✔
90
    }
91
    return streams;
12,026✔
92
};
93
ezs.createCommands = (params) => {
1,074✔
94
    const { file } = params;
11,024✔
95
    const fileContent = ezs.loadScript(file);
11,024✔
96
    const { script = fileContent } = params;
11,024✔
97
    const cmd1 = ezs.compileScript(script).get();
11,024✔
98
    const { command } = params;
11,024✔
99
    const cmd2 = [].concat(command).map(ezs.parseCommand).filter(Boolean);
11,024✔
100
    const { commands = cmd1.concat(cmd2) } = params;
11,024✔
101
    const { prepend, append } = params;
11,024✔
102
    const prepend2Pipeline = ezs.parseCommand(onlyOne(prepend));
11,024✔
103
    const append2Pipeline = ezs.parseCommand(onlyOne(append));
11,024✔
104
    if (prepend2Pipeline) {
11,024✔
105
        commands.unshift(prepend2Pipeline);
6✔
106
    }
107
    if (append2Pipeline) {
11,024✔
108
        commands.push(append2Pipeline);
6✔
109
    }
110
    if (!commands || commands.length === 0) {
11,024✔
111
        throw new Error('Invalid parmeter for createCommands');
84✔
112
    }
113
    return commands;
10,940✔
114
};
115
ezs.writeTo = writeTo;
1,074✔
116
ezs.createPipeline = (input, commands, trap) => {
1,074✔
117
    const output = commands.reduce((amont, aval) => amont.pipe(aval), input);
32,646✔
118
    if (!trap || !trap.write) {
12,330✔
119
        return output;
12,294✔
120
    }
121
    let isEmpty = true;
36✔
122
    return output
36✔
123
        .pipe(ezs.catch((e) => {
124
            trap.write(JSON.parse(ezs.serializeError(e))); // see engine.js createErrorWith
120✔
125
            return false; // do not catch the error
120✔
126
        }))
127
        .once('error', (e) => {
128
            trap.write(JSON.parse(ezs.serializeError(e))); // see engine.js createErrorWith
18✔
129
            trap.end();
18✔
130
        })
131
        .on('data', () => isEmpty = false)
120✔
132
        .once('end', () => {
133
            if (isEmpty) {
18✔
134
                trap.write(JSON.parse(ezs.serializeError(new Error('No data came out of the pipeline')))); // see engine.js createErrorWith
6✔
135
            }
136
            trap.end();
18✔
137
        });
138
};
139
ezs.compress = (options) => compressStream(ezs, options);
1,074✔
140
ezs.uncompress = (options) => uncompressStream(ezs, options);
1,074✔
141
ezs.createStream = (options) => new PassThrough(options);
8,152✔
142
ezs.createServer = (port, path) => Server.createServer(ezs, port, path);
1,074✔
143
ezs.createCluster = (port, path) => Server.createCluster(ezs, port, path);
1,074✔
144
ezs.createTrap = (file, env) => {
1,074✔
145
    if (!file) {
11,084✔
146
        return;
11,048✔
147
    }
148
    const input = ezs.createStream(ezs.objectMode());
36✔
149
    ezs.createPipeline(input, ezs.compileCommands(ezs.createCommands({ file }), env))
36✔
150
        .once('error', (e) => {
151
            debug('ezs:warn')(`The trap failed, ${file} stopped`, ezs.serializeError(e));
6✔
152
        })
153
        .once('end', () => true)
30✔
154
        .on('data', () => true);
84✔
155
    return input;
36✔
156
};
157
ezs.use(Statements);
1,074✔
158

159
//module.exports = ezs;
160
export default ezs;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc