Skip to content

Commit 647a204

Browse files
authored
Merge pull request #462 from Inist-CNRS/detach-2
feat: 🎸 add [detach]
2 parents 56ca7b8 + 22c6668 commit 647a204

File tree

16 files changed

+855
-14
lines changed

16 files changed

+855
-14
lines changed

.github/workflows/node.js.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
node-version: [12.x, 14.x, 16.x, 18.x, 20.x, 22.x, 24.x]
20+
node-version: [14.x, 16.x, 18.x, 20.x, 22.x, 24.x]
2121
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2222

2323
steps:
@@ -47,6 +47,7 @@ jobs:
4747
- name: Testing all packages
4848
env:
4949
LD_LIBRARY_PATH: '/deps/lib'
50+
DEBUG: 'ezs:error,ezs:warn'
5051
run: yarn run ci:test
5152

5253
- name: Coveralls Parallel

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"packages/*"
66
],
77
"engines": {
8-
"node": ">=12.0.0",
8+
"node": ">=14.0.0",
99
"yarn": ">= 1.0.0",
1010
"npm": "Please use Yarn instead of NPM to install dependencies. See: https://yarnpkg.com/lang/en/docs/install/"
1111
},

packages/core/bin/ezs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2-
require('app-module-path/cwd');
3-
require('../lib/cli').default(console.error);
2+
import 'app-module-path/cwd.js';
3+
import cli from '../src/cli.js';
44

5+
cli(console.error);

packages/core/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@
5454
"transformer"
5555
],
5656
"license": "MIT",
57-
"main": "./lib/index.js",
57+
"type": "module",
58+
"exports": {
59+
"import": "./src/index.js",
60+
"require": "./lib/index.js"
61+
},
5862
"publishConfig": {
5963
"access": "public"
6064
},

packages/core/src/compactor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const z = chooseZ();
2222

2323
export function compressStream(ezs, opts = {}) {
2424
const encoding = opts['Content-Encoding'] || opts['content-encoding'] || 'identity';
25-
if (typeof z.createGunzip === 'function' && encoding === 'gzip') {
25+
if (z && typeof z.createGunzip === 'function' && encoding === 'gzip') {
2626
debug('ezs:debug')('ezs will use zlib to compress stream.');
2727
return z.createGzip();
2828
}
@@ -32,7 +32,7 @@ export function compressStream(ezs, opts = {}) {
3232

3333
export function uncompressStream(ezs, opts = {}) {
3434
const encoding = opts['Content-Encoding'] || opts['content-encoding'] || 'identity';
35-
if (typeof z.createGunzip === 'function' && encoding === 'gzip') {
35+
if (z && typeof z.createGunzip === 'function' && encoding === 'gzip') {
3636
debug('ezs:debug')('ezs will use zlib to uncompress stream.');
3737
return z.createGunzip();
3838
}

packages/core/src/constants.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import fs from 'fs';
2+
import path from 'path';
13
import filenameRegex from 'filename-regex';
2-
import pckg from '../package.json' with { type: 'json' };
4+
import filedirname from 'filedirname';
5+
6+
const [, dirname] = filedirname();
7+
const pckg = JSON.parse(fs.readFileSync(path.resolve(dirname, '../package.json')));
38

49
export const VERBOSE = 'ezs:*,-ezs:debug,-ezs:trace';
510
export const VERSION = pckg.version;

packages/core/src/file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ function findFileIn(paths, name) {
2525
export function useFile(ezs, name) {
2626
const names = [
2727
name,
28-
'@ezs/'.concat(name.replace(/^@ezs\//, '')),
29-
'ezs-'.concat(name.replace(/^ezs-/, '')),
28+
'@ezs/'.concat(String(name).replace(/^@ezs\//, '')),
29+
'ezs-'.concat(String(name).replace(/^ezs-/, '')),
3030
];
3131
const plugName1 = names.map((n) => check(n)).filter(Boolean).shift();
3232
const plugName2 = names.map((n) => findFileIn(ezs.getPath(), n)).filter(Boolean).shift();

packages/core/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ ezs.parseFile = (filename) => Script(ezs.loadScript(filename));
5454
ezs.catch = (func) => new Catcher(func);
5555
ezs.toBuffer = (options) => new Output(options);
5656
ezs.use = (plugin) => Statement.set(ezs, plugin);
57+
ezs.useFiles = (files) => {
58+
if (files) {
59+
files.map(file=> Statement.load(ezs, file));
60+
}
61+
return Statement.list();
62+
};
5763
ezs.addPath = (p) => ezs.settings.pluginPaths.push(p);
5864
ezs.getPath = () => ezs.settings.pluginPaths;
5965
ezs.getCache = () => ezsCache;

packages/core/src/json.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Expression from './expression.js';
22

33
function parse(data) {
4+
if (!data) return data;
45
return JSON.parse(data, (key, value) => {
56
if (value && typeof value === 'string' && value.indexOf('Expression::') === 0) {
67
return new Expression(JSON.parse(value.replace('Expression::', '')));
@@ -10,6 +11,7 @@ function parse(data) {
1011
}
1112

1213
function stringify(data) {
14+
if (!data) return data;
1315
return JSON.stringify(data);
1416
}
1517

packages/core/src/statement.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { useFile } from './file.js';
33
import transit from './statements/transit.js';
44

55
const pluginsModules = {};
6+
const pluginsFiles = [];
67
const pluginsList = {};
78

89
function set(ezs, plugin) {
910
if (typeof plugin !== 'object') {
1011
throw new Error(
11-
"Statement is not loaded. It's not a valid plugin (should be an object).",
12+
'Statement is not loaded. It\'s not a valid plugin (should be an object).',
1213
);
1314
}
1415
const pluginList = plugin.default ? plugin.default : plugin; // ES6 hack
@@ -35,6 +36,7 @@ function load(ezs, name) {
3536
);
3637
}
3738
if (!pluginsModules[fileName]) {
39+
pluginsFiles.push(fileName);
3840
pluginsModules[fileName] = import(fileName);
3941
pluginsModules[fileName].then((funcs) => {
4042
set(ezs, funcs);
@@ -93,9 +95,14 @@ function exists(ezs, pluginName) {
9395
return pluginsList[pluginName] !== undefined;
9496
}
9597

98+
function list() {
99+
return pluginsFiles;
100+
}
101+
96102
export default {
97103
get,
98104
set,
99105
load,
100106
exists,
107+
list,
101108
};

0 commit comments

Comments
 (0)