@teambit/objects 0.0.0-954d6f571aee6bc531ee0f72477d0437dd1d5edc → 0.0.0-960e0bf4cf25e0be7edb19f5b7d7076021eff436

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.
@@ -1,42 +0,0 @@
1
- import isRelative from 'is-relative-path';
2
- import path from 'path';
3
-
4
- import type { ScopeJson } from '@teambit/legacy.scope';
5
-
6
- export type ContentTransformer = (content: Buffer) => Buffer;
7
-
8
- function loadHooks(scopePath: string, scopeJson: ScopeJson): any | undefined {
9
- const hooksPath = scopeJson.hooksPath;
10
- if (hooksPath) {
11
- const hooksFinalPath = isRelative(hooksPath) ? path.join(scopePath, hooksPath) : hooksPath;
12
- // eslint-disable-next-line global-require, import/no-dynamic-require
13
- const hooks = require(hooksFinalPath);
14
- return hooks;
15
- }
16
- return undefined;
17
- }
18
-
19
- export function onPersist(scopePath: string, scopeJson: ScopeJson): ContentTransformer {
20
- const defaultFunc = (content) => content;
21
- const hooks = loadHooks(scopePath, scopeJson);
22
- if (hooks) {
23
- const onReadFunction = hooks.onPersist;
24
- if (onReadFunction) {
25
- return onReadFunction;
26
- }
27
- }
28
- return defaultFunc;
29
- }
30
-
31
- export function onRead(scopePath: string, scopeJson: ScopeJson): ContentTransformer {
32
- const defaultFunc = (content) => content;
33
-
34
- const hooks = loadHooks(scopePath, scopeJson);
35
- if (hooks) {
36
- const onReadFunction = hooks.onRead;
37
- if (onReadFunction) {
38
- return onReadFunction;
39
- }
40
- }
41
- return defaultFunc;
42
- }