assemblerjs 1.1.14 → 1.1.16

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.
Files changed (64) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index13.js +1 -1
  3. package/dist/index13.mjs +1 -1
  4. package/dist/index18.js +1 -1
  5. package/dist/index18.mjs +1 -1
  6. package/dist/index19.js +1 -1
  7. package/dist/index19.mjs +1 -1
  8. package/dist/index20.js +1 -1
  9. package/dist/index20.mjs +1 -1
  10. package/dist/index21.js +1 -1
  11. package/dist/index21.mjs +1 -1
  12. package/dist/index22.js +1 -1
  13. package/dist/index22.mjs +1 -1
  14. package/dist/index23.js +1 -1
  15. package/dist/index23.mjs +1 -1
  16. package/dist/index24.js +1 -1
  17. package/dist/index24.mjs +1 -1
  18. package/dist/index27.js +1 -1
  19. package/dist/index27.mjs +1 -1
  20. package/dist/index31.js +35 -148
  21. package/dist/index31.mjs +34 -148
  22. package/dist/index32.js +16 -44
  23. package/dist/index32.mjs +16 -44
  24. package/dist/index33.js +97 -71
  25. package/dist/index33.mjs +97 -71
  26. package/dist/index34.js +26 -42
  27. package/dist/index34.mjs +26 -42
  28. package/dist/index35.js +157 -30
  29. package/dist/index35.mjs +156 -30
  30. package/dist/index36.js +41 -153
  31. package/dist/index36.mjs +41 -153
  32. package/dist/index37.js +73 -16
  33. package/dist/index37.mjs +73 -16
  34. package/dist/index38.js +51 -36
  35. package/dist/index38.mjs +51 -35
  36. package/dist/index39.js +28 -102
  37. package/dist/index39.mjs +28 -102
  38. package/dist/index4.js +13 -8
  39. package/dist/index4.mjs +13 -8
  40. package/dist/index40.js +156 -22
  41. package/dist/index40.mjs +156 -22
  42. package/dist/index41.js +61 -46
  43. package/dist/index41.mjs +61 -46
  44. package/dist/index42.js +44 -18
  45. package/dist/index42.mjs +44 -17
  46. package/dist/index43.js +22 -28
  47. package/dist/index43.mjs +21 -27
  48. package/dist/index44.js +940 -192
  49. package/dist/index44.mjs +940 -192
  50. package/dist/index45.js +2 -942
  51. package/dist/index45.mjs +2 -942
  52. package/dist/index46.js +2 -2
  53. package/dist/index46.mjs +2 -2
  54. package/dist/index47.js +29 -2
  55. package/dist/index47.mjs +28 -2
  56. package/dist/index48.js +189 -9
  57. package/dist/index48.mjs +189 -9
  58. package/dist/index49.js +9 -34
  59. package/dist/index49.mjs +9 -34
  60. package/dist/index50.js +32 -59
  61. package/dist/index50.mjs +32 -58
  62. package/dist/index51.js +71 -0
  63. package/dist/index51.mjs +66 -0
  64. package/package.json +1 -1
package/dist/index39.js CHANGED
@@ -2,110 +2,36 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const transversalManager = require('./index13.js');
6
- const affect = require('./index12.js');
7
-
8
- class TransversalWeaver {
9
- static weave(n, r, o) {
10
- const c = transversalManager.TransversalManager.getInstance(o);
11
- const s = c.getAspectsForTarget(r);
12
- const a = Object.getPrototypeOf(n);
13
- const f = Object.getOwnPropertyNames(a).some((t)=>{
14
- if (t === 'constructor') return false;
15
- const n = Object.getOwnPropertyDescriptor(a, t);
16
- if (!n) return false;
17
- const r = n.value && typeof n.value === 'function';
18
- const o = n.get && typeof n.get === 'function';
19
- if (!r && !o) return false;
20
- const c = affect.getAffectedMethods(a, t);
21
- return c.length > 0;
22
- });
23
- if (s.length === 0 && !f) {
24
- return n;
25
- }
26
- return new Proxy(n, {
27
- get (t, e, n) {
28
- const r = Reflect.get(t, e, n);
29
- if (typeof r !== 'function') {
30
- return r;
31
- }
32
- return function(...n) {
33
- const o = String(e);
34
- const a = {
35
- target: t,
36
- methodName: o,
37
- args: n
38
- };
39
- const f = c.getAdvicesForJoinPoint(a, s, t, e);
40
- return TransversalWeaver.executeAdviceChain(f, r, t, n, a);
41
- };
42
- }
43
- });
44
- }
45
- static executeAdviceChain(t, e, n, r, o) {
46
- const c = t.filter((t)=>t.type === 'before');
47
- const s = t.filter((t)=>t.type === 'around');
48
- const a = t.filter((t)=>t.type === 'after');
49
- try {
50
- for (const t of c){
51
- const e = {
52
- ...o,
53
- config: t.config
54
- };
55
- t.method.call(t.transversalInstance, e);
56
- }
57
- let t;
58
- if (s.length > 0) {
59
- t = this.buildAroundChain(s, e, n, r, o);
60
- } else {
61
- t = e.apply(n, r);
62
- }
63
- if (t instanceof Promise) {
64
- return t.then((t)=>{
65
- for (const e of a){
66
- const n = {
67
- ...o,
68
- result: t
69
- };
70
- e.method.call(e.transversalInstance, n);
71
- }
72
- return t;
73
- }).catch((t)=>{
74
- o.error = t;
75
- throw t;
76
- });
77
- }
78
- for (const e of a){
79
- const n = {
80
- ...o,
81
- result: t,
82
- config: e.config
83
- };
84
- e.method.call(e.transversalInstance, n);
85
- }
86
- return t;
87
- } catch (t) {
88
- o.error = t;
89
- throw t;
90
- }
5
+ class ContextProvider {
6
+ createPublicContext() {
7
+ return {
8
+ has: this.assembler.has.bind(this.assembler),
9
+ require: this.assembler.require.bind(this.assembler),
10
+ concrete: this.assembler.concrete.bind(this.assembler),
11
+ tagged: this.assembler.tagged.bind(this.assembler),
12
+ dispose: this.assembler.dispose.bind(this.assembler),
13
+ global: this.assembler.global.bind(this.assembler),
14
+ on: this.assembler.on.bind(this.assembler),
15
+ once: this.assembler.once.bind(this.assembler),
16
+ off: this.assembler.off.bind(this.assembler),
17
+ events: this.assembler.channels
18
+ };
91
19
  }
92
- static buildAroundChain(t, e, n, r, o) {
93
- let c = 0;
94
- const s = ()=>{
95
- if (c < t.length) {
96
- const e = t[c++];
97
- const n = {
98
- ...o,
99
- proceed: s,
100
- config: e.config
101
- };
102
- return e.method.call(e.transversalInstance, n);
103
- } else {
104
- return e.apply(n, r);
105
- }
20
+ createPrivateContext(s) {
21
+ return {
22
+ ...s,
23
+ register: this.assembler.register.bind(this.assembler),
24
+ use: this.assembler.use.bind(this.assembler),
25
+ addGlobal: this.assembler.addGlobal.bind(this.assembler),
26
+ prepareInitHook: this.assembler.prepareInitHook.bind(this.assembler),
27
+ emit: this.assembler.emit.bind(this.assembler),
28
+ addChannels: this.assembler.addChannels.bind(this.assembler),
29
+ removeChannels: this.assembler.removeChannels.bind(this.assembler)
106
30
  };
107
- return s();
31
+ }
32
+ constructor(s){
33
+ this.assembler = s;
108
34
  }
109
35
  }
110
36
 
111
- exports.TransversalWeaver = TransversalWeaver;
37
+ exports.ContextProvider = ContextProvider;
package/dist/index39.mjs CHANGED
@@ -1,107 +1,33 @@
1
- import { TransversalManager } from './index13.mjs';
2
- import { getAffectedMethods } from './index12.mjs';
3
-
4
- class TransversalWeaver {
5
- static weave(n, r, o) {
6
- const c = TransversalManager.getInstance(o);
7
- const s = c.getAspectsForTarget(r);
8
- const a = Object.getPrototypeOf(n);
9
- const f = Object.getOwnPropertyNames(a).some((t)=>{
10
- if (t === 'constructor') return false;
11
- const n = Object.getOwnPropertyDescriptor(a, t);
12
- if (!n) return false;
13
- const r = n.value && typeof n.value === 'function';
14
- const o = n.get && typeof n.get === 'function';
15
- if (!r && !o) return false;
16
- const c = getAffectedMethods(a, t);
17
- return c.length > 0;
18
- });
19
- if (s.length === 0 && !f) {
20
- return n;
21
- }
22
- return new Proxy(n, {
23
- get (t, e, n) {
24
- const r = Reflect.get(t, e, n);
25
- if (typeof r !== 'function') {
26
- return r;
27
- }
28
- return function(...n) {
29
- const o = String(e);
30
- const a = {
31
- target: t,
32
- methodName: o,
33
- args: n
34
- };
35
- const f = c.getAdvicesForJoinPoint(a, s, t, e);
36
- return TransversalWeaver.executeAdviceChain(f, r, t, n, a);
37
- };
38
- }
39
- });
40
- }
41
- static executeAdviceChain(t, e, n, r, o) {
42
- const c = t.filter((t)=>t.type === 'before');
43
- const s = t.filter((t)=>t.type === 'around');
44
- const a = t.filter((t)=>t.type === 'after');
45
- try {
46
- for (const t of c){
47
- const e = {
48
- ...o,
49
- config: t.config
50
- };
51
- t.method.call(t.transversalInstance, e);
52
- }
53
- let t;
54
- if (s.length > 0) {
55
- t = this.buildAroundChain(s, e, n, r, o);
56
- } else {
57
- t = e.apply(n, r);
58
- }
59
- if (t instanceof Promise) {
60
- return t.then((t)=>{
61
- for (const e of a){
62
- const n = {
63
- ...o,
64
- result: t
65
- };
66
- e.method.call(e.transversalInstance, n);
67
- }
68
- return t;
69
- }).catch((t)=>{
70
- o.error = t;
71
- throw t;
72
- });
73
- }
74
- for (const e of a){
75
- const n = {
76
- ...o,
77
- result: t,
78
- config: e.config
79
- };
80
- e.method.call(e.transversalInstance, n);
81
- }
82
- return t;
83
- } catch (t) {
84
- o.error = t;
85
- throw t;
86
- }
1
+ class ContextProvider {
2
+ createPublicContext() {
3
+ return {
4
+ has: this.assembler.has.bind(this.assembler),
5
+ require: this.assembler.require.bind(this.assembler),
6
+ concrete: this.assembler.concrete.bind(this.assembler),
7
+ tagged: this.assembler.tagged.bind(this.assembler),
8
+ dispose: this.assembler.dispose.bind(this.assembler),
9
+ global: this.assembler.global.bind(this.assembler),
10
+ on: this.assembler.on.bind(this.assembler),
11
+ once: this.assembler.once.bind(this.assembler),
12
+ off: this.assembler.off.bind(this.assembler),
13
+ events: this.assembler.channels
14
+ };
87
15
  }
88
- static buildAroundChain(t, e, n, r, o) {
89
- let c = 0;
90
- const s = ()=>{
91
- if (c < t.length) {
92
- const e = t[c++];
93
- const n = {
94
- ...o,
95
- proceed: s,
96
- config: e.config
97
- };
98
- return e.method.call(e.transversalInstance, n);
99
- } else {
100
- return e.apply(n, r);
101
- }
16
+ createPrivateContext(s) {
17
+ return {
18
+ ...s,
19
+ register: this.assembler.register.bind(this.assembler),
20
+ use: this.assembler.use.bind(this.assembler),
21
+ addGlobal: this.assembler.addGlobal.bind(this.assembler),
22
+ prepareInitHook: this.assembler.prepareInitHook.bind(this.assembler),
23
+ emit: this.assembler.emit.bind(this.assembler),
24
+ addChannels: this.assembler.addChannels.bind(this.assembler),
25
+ removeChannels: this.assembler.removeChannels.bind(this.assembler)
102
26
  };
103
- return s();
27
+ }
28
+ constructor(s){
29
+ this.assembler = s;
104
30
  }
105
31
  }
106
32
 
107
- export { TransversalWeaver };
33
+ export { ContextProvider };
package/dist/index4.js CHANGED
@@ -3,28 +3,33 @@
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const core = require('@assemblerjs/core');
6
- const injectableManager = require('./index31.js');
7
- const objectManager = require('./index32.js');
8
- const hookManager = require('./index33.js');
9
- const assemblerBuilder = require('./index34.js');
10
- const contextProvider = require('./index35.js');
11
- const debugLogger = require('./index36.js');
6
+ const injectableManager = require('./index35.js');
7
+ const objectManager = require('./index36.js');
8
+ const hookManager = require('./index37.js');
9
+ const assemblerBuilder = require('./index38.js');
10
+ const contextProvider = require('./index39.js');
11
+ const debugLogger = require('./index40.js');
12
+ const cycleDetector = require('./index41.js');
12
13
  const eventManager = require('./index6.js');
13
14
 
14
15
  class Assembler extends eventManager.EventManager {
15
16
  static enableDebug(e) {
16
17
  debugLogger.DebugLogger.enable(e);
18
+ if (e?.detectCycles === true) {
19
+ cycleDetector.CycleDetector.enable();
20
+ }
17
21
  }
18
22
  static disableDebug() {
19
23
  debugLogger.DebugLogger.disable();
24
+ cycleDetector.CycleDetector.disable();
20
25
  }
21
26
  static build(e, t) {
22
27
  const r = debugLogger.DebugLogger.getInstance();
23
28
  const a = performance.now();
24
29
  r.logBuildStart(e);
25
30
  const n = new Assembler();
26
- const o = new assemblerBuilder.AssemblerBuilder(n);
27
- const c = o.build(e, t);
31
+ const s = new assemblerBuilder.AssemblerBuilder(n);
32
+ const c = s.build(e, t);
28
33
  const l = performance.now() - a;
29
34
  r.logBuildEnd(e, l);
30
35
  return c;
package/dist/index4.mjs CHANGED
@@ -1,26 +1,31 @@
1
1
  import { clearInstance } from '@assemblerjs/core';
2
- import { InjectableManager } from './index31.mjs';
3
- import { ObjectManager } from './index32.mjs';
4
- import { HookManager } from './index33.mjs';
5
- import { AssemblerBuilder } from './index34.mjs';
6
- import { ContextProvider } from './index35.mjs';
7
- import { DebugLogger } from './index36.mjs';
2
+ import { InjectableManager } from './index35.mjs';
3
+ import { ObjectManager } from './index36.mjs';
4
+ import { HookManager } from './index37.mjs';
5
+ import { AssemblerBuilder } from './index38.mjs';
6
+ import { ContextProvider } from './index39.mjs';
7
+ import { DebugLogger } from './index40.mjs';
8
+ import { CycleDetector } from './index41.mjs';
8
9
  import { EventManager } from './index6.mjs';
9
10
 
10
11
  class Assembler extends EventManager {
11
12
  static enableDebug(e) {
12
13
  DebugLogger.enable(e);
14
+ if (e?.detectCycles === true) {
15
+ CycleDetector.enable();
16
+ }
13
17
  }
14
18
  static disableDebug() {
15
19
  DebugLogger.disable();
20
+ CycleDetector.disable();
16
21
  }
17
22
  static build(e, t) {
18
23
  const r = DebugLogger.getInstance();
19
24
  const a = performance.now();
20
25
  r.logBuildStart(e);
21
26
  const n = new Assembler();
22
- const o = new AssemblerBuilder(n);
23
- const c = o.build(e, t);
27
+ const s = new AssemblerBuilder(n);
28
+ const c = s.build(e, t);
24
29
  const l = performance.now() - a;
25
30
  r.logBuildEnd(e, l);
26
31
  return c;
package/dist/index40.js CHANGED
@@ -2,33 +2,167 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- class PointcutMatcher {
6
- static parse(t) {
7
- const e = t.match(/^execution\(([^.]+)\.([^)]+)\)$/);
8
- if (!e) {
9
- throw new Error(`Invalid pointcut expression: ${t}`);
5
+ function o(o) {
6
+ if (o === undefined) return 'undefined';
7
+ if (o === null) return 'null';
8
+ if (typeof o === 'function') {
9
+ if (o.name) return o.name;
10
+ if (o.constructor?.name && o.constructor.name !== 'Function') {
11
+ return o.constructor.name;
10
12
  }
11
- const [, c, r] = e;
12
- return new ExecutionPointcutMatcher(c, r);
13
+ return 'AnonymousFunction';
13
14
  }
15
+ if (typeof o === 'object') {
16
+ if (o.name && typeof o.name === 'string') {
17
+ return o.name;
18
+ }
19
+ const e = o.constructor?.name;
20
+ if (e && e !== 'Object') {
21
+ return e;
22
+ }
23
+ return '[Object]';
24
+ }
25
+ return String(o);
14
26
  }
15
- let ExecutionPointcutMatcher = class ExecutionPointcutMatcher {
16
- matches(t) {
17
- const e = t.target.constructor.name;
18
- const c = t.methodName;
19
- return this.classRegex.test(e) && this.methodRegex.test(c);
20
- }
21
- patternToRegex(t) {
22
- if (t === '*') {
23
- return /.*/;
27
+ let NoOpDebugLogger = class NoOpDebugLogger {
28
+ configure(o) {}
29
+ log(o, e, t) {}
30
+ logBuildStart(o) {}
31
+ logBuildEnd(o, e) {}
32
+ logRegistration(o) {}
33
+ logHook(o, e, t) {}
34
+ logPhaseStart(o, e) {}
35
+ logPhaseEnd(o, e, t) {}
36
+ logResolution(o, e, t) {}
37
+ logConstruction(o) {}
38
+ };
39
+ let ActiveDebugLogger = class ActiveDebugLogger {
40
+ configure(o) {
41
+ this.options = {
42
+ ...this.options,
43
+ ...o,
44
+ logPhases: {
45
+ ...this.options.logPhases,
46
+ ...o.logPhases || {}
47
+ }
48
+ };
49
+ }
50
+ logBuildStart(o) {
51
+ this.log('info', 'Build started', {
52
+ entry: o.name
53
+ });
54
+ }
55
+ logBuildEnd(o, e) {
56
+ const t = {
57
+ entry: o.name
58
+ };
59
+ if (e !== undefined) t.duration = `${e.toFixed(2)}ms`;
60
+ this.log('info', 'Build completed', t);
61
+ }
62
+ logRegistration(e) {
63
+ if (!this.shouldLog('registration')) return;
64
+ this.log('info', 'Registration', {
65
+ identifier: o(e.identifier),
66
+ isSingleton: e.isSingleton,
67
+ dependencies: e.dependencies.map((e)=>o(e)),
68
+ tags: e.tags
69
+ });
70
+ }
71
+ logHook(e, t, n) {
72
+ if (!this.shouldLog('hooks')) return;
73
+ const s = this.options.logTimings ? performance.now() : 0;
74
+ this.log('info', `Hook: ${e}`, {
75
+ target: o(t),
76
+ config: n
77
+ });
78
+ if (this.options.logTimings) {
79
+ return ()=>{
80
+ const o = performance.now() - s;
81
+ this.log('info', `Hook: ${e} completed`, {
82
+ duration: `${o.toFixed(2)}ms`
83
+ });
84
+ };
85
+ }
86
+ }
87
+ logPhaseStart(o, e) {
88
+ this.log('info', `Phase: ${o} started`, e);
89
+ }
90
+ logPhaseEnd(o, e, t) {
91
+ const n = e !== undefined ? {
92
+ duration: `${e.toFixed(2)}ms`
93
+ } : {};
94
+ if (t) {
95
+ Object.assign(n, t);
24
96
  }
25
- const e = t.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
26
- return new RegExp(`^${e}$`);
97
+ this.log('info', `Phase: ${o} ended`, Object.keys(n).length > 0 ? n : undefined);
27
98
  }
28
- constructor(t, e){
29
- this.classRegex = this.patternToRegex(t);
30
- this.methodRegex = this.patternToRegex(e);
99
+ logResolution(o, e, t) {
100
+ if (!this.shouldLog('resolution')) return;
101
+ this.log('info', `Resolving: ${o}`, {
102
+ strategy: `${e} strategy`,
103
+ cache: t ? 'hit' : 'miss'
104
+ });
105
+ }
106
+ logConstruction(o) {
107
+ if (!this.shouldLog('construction')) return;
108
+ this.log('info', `Constructing: ${o}`);
109
+ }
110
+ shouldLog(o) {
111
+ return !this.options.logPhases || this.options.logPhases[o] !== false;
112
+ }
113
+ log(o, e, t) {
114
+ if (this.options.logger) {
115
+ this.options.logger(o, e, t);
116
+ } else {
117
+ const n = `[Assembler:${o}]`;
118
+ const s = this.options.useColors !== false ? this.colorize(o, n) : n;
119
+ if (t) {
120
+ console.log(`${s} ${e}`, t);
121
+ } else {
122
+ console.log(`${s} ${e}`);
123
+ }
124
+ }
125
+ }
126
+ colorize(o, e) {
127
+ const t = {
128
+ info: '\x1b[36m',
129
+ warn: '\x1b[33m',
130
+ error: '\x1b[31m',
131
+ reset: '\x1b[0m'
132
+ };
133
+ const n = t[o] || t.info;
134
+ return `${n}${e}${t.reset}`;
135
+ }
136
+ constructor(){
137
+ this.options = {
138
+ enabled: true,
139
+ logPhases: {
140
+ registration: true,
141
+ resolution: true,
142
+ construction: true,
143
+ hooks: true,
144
+ cache: true
145
+ },
146
+ logTimings: false,
147
+ logDependencyTree: true,
148
+ useColors: true
149
+ };
31
150
  }
32
151
  };
152
+ class DebugLogger {
153
+ static getInstance() {
154
+ return DebugLogger.instance;
155
+ }
156
+ static enable(o) {
157
+ DebugLogger.instance = new ActiveDebugLogger();
158
+ if (o) {
159
+ DebugLogger.instance.configure(o);
160
+ }
161
+ }
162
+ static disable() {
163
+ DebugLogger.instance = new NoOpDebugLogger();
164
+ }
165
+ }
166
+ DebugLogger.instance = new NoOpDebugLogger();
33
167
 
34
- exports.PointcutMatcher = PointcutMatcher;
168
+ exports.DebugLogger = DebugLogger;