DuyTa's picture
Upload folder using huggingface_hub
bc20498 verified
raw
history blame
1.14 kB
'use strict';
const toJSONCallback = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c8 ignore stop */)(require('to-json-callback'));
const { dedent } = require('../utils.js');
const { js: jsHooks, code: codeHooks } = require('../hooks.js');
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
module.exports = class Hook {
constructor(interpreter, hooks = {}) {
const { main, worker } = hooks;
this.interpreter = interpreter;
this.onWorker = main?.onWorker;
// ignore onWorker as that's main only
for (const key of jsHooks.slice(1))
this[key] = worker?.[key];
for (const key of codeHooks)
this[key] = worker?.[key];
}
toJSON() {
const hooks = {};
// ignore onWorker as that's main only
for (const key of jsHooks.slice(1)) {
if (this[key]) hooks[key] = toJSONCallback(this[key]);
}
// code related: exclude `onReady` callback
for (const key of codeHooks) {
if (this[key]) hooks[key] = dedent(this[key]());
}
return hooks;
}
}
/* c8 ignore stop */