assemblerjs 1.1.21 → 1.1.22

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 (67) hide show
  1. package/dist/index11.js +2 -2
  2. package/dist/index11.mjs +2 -2
  3. package/dist/index13.js +1 -1
  4. package/dist/index13.mjs +1 -1
  5. package/dist/index16.js +1 -1
  6. package/dist/index16.mjs +1 -1
  7. package/dist/index17.js +1 -1
  8. package/dist/index17.mjs +1 -1
  9. package/dist/index18.js +1 -1
  10. package/dist/index18.mjs +1 -1
  11. package/dist/index19.js +1 -1
  12. package/dist/index19.mjs +1 -1
  13. package/dist/index2.js +2 -2
  14. package/dist/index2.mjs +2 -2
  15. package/dist/index20.js +1 -1
  16. package/dist/index20.mjs +1 -1
  17. package/dist/index21.js +1 -1
  18. package/dist/index21.mjs +1 -1
  19. package/dist/index22.js +3 -3
  20. package/dist/index22.mjs +3 -3
  21. package/dist/index23.js +3 -3
  22. package/dist/index23.mjs +3 -3
  23. package/dist/index24.js +2 -2
  24. package/dist/index24.mjs +2 -2
  25. package/dist/index25.js +1 -1
  26. package/dist/index25.mjs +1 -1
  27. package/dist/index26.js +1 -1
  28. package/dist/index26.mjs +1 -1
  29. package/dist/index29.js +158 -17
  30. package/dist/index29.mjs +157 -14
  31. package/dist/index3.js +1 -1
  32. package/dist/index3.mjs +1 -1
  33. package/dist/index30.js +43 -100
  34. package/dist/index30.mjs +43 -98
  35. package/dist/index31.js +71 -32
  36. package/dist/index31.mjs +71 -31
  37. package/dist/index32.js +51 -154
  38. package/dist/index32.mjs +51 -153
  39. package/dist/index33.js +28 -47
  40. package/dist/index33.mjs +28 -47
  41. package/dist/index34.js +161 -65
  42. package/dist/index34.mjs +161 -65
  43. package/dist/index35.js +58 -50
  44. package/dist/index35.mjs +58 -50
  45. package/dist/index36.js +18 -32
  46. package/dist/index36.mjs +15 -32
  47. package/dist/index37.js +99 -167
  48. package/dist/index37.mjs +97 -167
  49. package/dist/index38.js +16 -57
  50. package/dist/index38.mjs +16 -57
  51. package/dist/index39.js +38 -20
  52. package/dist/index39.mjs +37 -20
  53. package/dist/index4.js +7 -7
  54. package/dist/index4.mjs +7 -7
  55. package/dist/index42.js +29 -49
  56. package/dist/index42.mjs +28 -49
  57. package/dist/index44.js +49 -29
  58. package/dist/index44.mjs +49 -28
  59. package/dist/index45.js +25 -9
  60. package/dist/index45.mjs +25 -9
  61. package/dist/index49.js +1 -1
  62. package/dist/index49.mjs +1 -1
  63. package/dist/index50.js +1 -1
  64. package/dist/index50.mjs +1 -1
  65. package/dist/index51.js +1 -1
  66. package/dist/index51.mjs +1 -1
  67. package/package.json +1 -1
package/dist/index34.js CHANGED
@@ -2,84 +2,180 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const core = require('@assemblerjs/core');
6
- const debugLogger = require('./index37.js');
7
-
8
- class HookManager {
9
- prepareInitHook(o, t) {
10
- this.initCache.push({
11
- instance: o,
12
- configuration: t
5
+ function e(e) {
6
+ if (e === undefined) return 'undefined';
7
+ if (e === null) return 'null';
8
+ if (typeof e === 'function') {
9
+ if (e.name) return e.name;
10
+ if (e.constructor?.name && e.constructor.name !== 'Function') {
11
+ return e.constructor.name;
12
+ }
13
+ return 'AnonymousFunction';
14
+ }
15
+ if (typeof e === 'object') {
16
+ const o = e.constructor?.name;
17
+ if (o && o !== 'Object') {
18
+ return o;
19
+ }
20
+ if (e.name && typeof e.name === 'string') {
21
+ return e.name;
22
+ }
23
+ return '[Object]';
24
+ }
25
+ return String(e);
26
+ }
27
+ let NoOpDebugLogger = class NoOpDebugLogger {
28
+ configure(e) {}
29
+ log(e, o, t) {}
30
+ logBuildStart(e) {}
31
+ logBuildEnd(e, o) {}
32
+ logRegistration(e) {}
33
+ logHook(e, o, t) {}
34
+ logPhaseStart(e, o) {}
35
+ logPhaseEnd(e, o, t) {}
36
+ logResolution(e, o, t) {}
37
+ logConstruction(e) {}
38
+ logInjection(e, o) {}
39
+ };
40
+ let ActiveDebugLogger = class ActiveDebugLogger {
41
+ configure(e) {
42
+ this.options = {
43
+ ...this.options,
44
+ ...e,
45
+ logPhases: {
46
+ ...this.options.logPhases,
47
+ ...e.logPhases || {}
48
+ }
49
+ };
50
+ }
51
+ logBuildStart(e) {
52
+ this.log('info', 'Build started', {
53
+ entry: e.name
54
+ });
55
+ }
56
+ logBuildEnd(e, o) {
57
+ const t = {
58
+ entry: e.name
59
+ };
60
+ if (o !== undefined) t.duration = `${o.toFixed(2)}ms`;
61
+ this.log('info', 'Build completed', t);
62
+ }
63
+ logRegistration(o) {
64
+ if (!this.shouldLog('registration')) return;
65
+ this.log('info', 'Registration', {
66
+ identifier: e(o.identifier),
67
+ isSingleton: o.isSingleton,
68
+ dependencies: o.dependencies.map((o)=>e(o)),
69
+ tags: o.tags
13
70
  });
14
- return this.initCache;
15
71
  }
16
- callInitHooks(o) {
17
- for (const t of this.initCache){
18
- HookManager.callHookImmediate(t.instance, 'onInit', o, t.configuration);
72
+ logHook(o, t, n) {
73
+ if (!this.shouldLog('hooks')) return;
74
+ const i = this.options.logTimings ? performance.now() : 0;
75
+ this.log('info', `Hook: ${o}`, {
76
+ target: e(t),
77
+ config: n
78
+ });
79
+ if (this.options.logTimings) {
80
+ return ()=>{
81
+ const e = performance.now() - i;
82
+ this.log('info', `Hook: ${o} completed`, {
83
+ duration: `${e.toFixed(2)}ms`
84
+ });
85
+ };
19
86
  }
20
87
  }
21
- callInitedHooks(o) {
22
- for (const t of [
23
- ...this.initCache
24
- ].reverse()){
25
- HookManager.callHookImmediate(t.instance, 'onInited', o, t.configuration);
88
+ logPhaseStart(e, o) {
89
+ this.log('info', `Phase: ${e} started`, o);
90
+ }
91
+ logPhaseEnd(e, o, t) {
92
+ const n = o !== undefined ? {
93
+ duration: `${o.toFixed(2)}ms`
94
+ } : {};
95
+ if (t) {
96
+ Object.assign(n, t);
26
97
  }
98
+ this.log('info', `Phase: ${e} ended`, Object.keys(n).length > 0 ? n : undefined);
27
99
  }
28
- clearCache() {
29
- this.initCache.length = 0;
100
+ logResolution(e, o, t) {
101
+ if (!this.shouldLog('resolution')) return;
102
+ this.log('info', `Resolving: ${e}`, {
103
+ strategy: `${o} strategy`,
104
+ cache: t ? 'hit' : 'miss'
105
+ });
30
106
  }
31
- getCache() {
32
- return this.initCache;
107
+ logConstruction(e) {
108
+ if (!this.shouldLog('construction')) return;
109
+ this.log('info', `Constructing: ${e}`);
33
110
  }
34
- constructor(){
35
- this.initCache = [];
111
+ logInjection(e, o) {
112
+ if (!this.shouldLog(e === 'use' ? 'injectionUse' : 'injectionGlobal')) return;
113
+ this.log('info', `Injecting: @${e === 'use' ? 'Use' : 'Global'}`, o);
36
114
  }
37
- }
38
- HookManager.callHook = (e, i, n, a)=>{
39
- const c = debugLogger.DebugLogger.getInstance();
40
- const r = c.logHook(i, e, a);
41
- return new Promise((t, c)=>{
42
- const s = e[i];
43
- if (s) {
44
- if (core.isAsync(s)) {
45
- s.bind(e)(n, a).then(()=>{
46
- if (r) r();
47
- t();
48
- }).catch((o)=>{
49
- if (r) r();
50
- c(o);
51
- });
52
- return;
53
- }
54
- try {
55
- s.bind(e)(n, a);
56
- if (r) r();
57
- t();
58
- } catch (o) {
59
- if (r) r();
60
- c(o);
61
- }
115
+ shouldLog(e) {
116
+ return !this.options.logPhases || this.options.logPhases[e] !== false;
117
+ }
118
+ log(e, o, t) {
119
+ if (this.options.logger) {
120
+ this.options.logger(e, o, t);
62
121
  } else {
63
- if (r) r();
64
- t();
122
+ const n = `[Assembler:${e}]`;
123
+ const i = this.options.useColors !== false ? this.colorize(e, n) : n;
124
+ if (t) {
125
+ console.log(`${i} ${o}`, t);
126
+ } else {
127
+ console.log(`${i} ${o}`);
128
+ }
65
129
  }
66
- });
130
+ }
131
+ colorize(e, o) {
132
+ const t = {
133
+ info: '\x1b[36m',
134
+ warn: '\x1b[33m',
135
+ error: '\x1b[31m',
136
+ reset: '\x1b[0m'
137
+ };
138
+ const n = t[e] || t.info;
139
+ return `${n}${o}${t.reset}`;
140
+ }
141
+ constructor(){
142
+ this.options = {
143
+ enabled: true,
144
+ logPhases: {
145
+ registration: true,
146
+ registrationUse: true,
147
+ registrationGlobals: true,
148
+ resolution: true,
149
+ construction: true,
150
+ hooks: true,
151
+ cache: true,
152
+ injectionUse: true,
153
+ injectionGlobal: true
154
+ },
155
+ logTimings: false,
156
+ logDependencyTree: true,
157
+ useColors: true
158
+ };
159
+ }
67
160
  };
68
- HookManager.callHookImmediate = (e, i, n, a)=>{
69
- const c = debugLogger.DebugLogger.getInstance();
70
- const r = c.logHook(i, e, a);
71
- const s = e[i];
72
- if (s) {
73
- if (core.isAsync(s)) {
74
- s.bind(e)(n, a).catch(()=>{});
75
- if (r) r();
161
+ class DebugLogger {
162
+ static getInstance() {
163
+ return DebugLogger.instance;
164
+ }
165
+ static enable(e) {
166
+ if (e?.enabled === false) {
167
+ DebugLogger.instance = new NoOpDebugLogger();
76
168
  return;
77
169
  }
78
- s.bind(e)(n, a);
79
- if (r) r();
80
- } else {
81
- if (r) r();
170
+ DebugLogger.instance = new ActiveDebugLogger();
171
+ if (e) {
172
+ DebugLogger.instance.configure(e);
173
+ }
82
174
  }
83
- };
175
+ static disable() {
176
+ DebugLogger.instance = new NoOpDebugLogger();
177
+ }
178
+ }
179
+ DebugLogger.instance = new NoOpDebugLogger();
84
180
 
85
- exports.HookManager = HookManager;
181
+ exports.DebugLogger = DebugLogger;
package/dist/index34.mjs CHANGED
@@ -1,81 +1,177 @@
1
- import { isAsync } from '@assemblerjs/core';
2
- import { DebugLogger } from './index37.mjs';
3
-
4
- class HookManager {
5
- prepareInitHook(o, t) {
6
- this.initCache.push({
7
- instance: o,
8
- configuration: t
1
+ function e(e) {
2
+ if (e === undefined) return 'undefined';
3
+ if (e === null) return 'null';
4
+ if (typeof e === 'function') {
5
+ if (e.name) return e.name;
6
+ if (e.constructor?.name && e.constructor.name !== 'Function') {
7
+ return e.constructor.name;
8
+ }
9
+ return 'AnonymousFunction';
10
+ }
11
+ if (typeof e === 'object') {
12
+ const o = e.constructor?.name;
13
+ if (o && o !== 'Object') {
14
+ return o;
15
+ }
16
+ if (e.name && typeof e.name === 'string') {
17
+ return e.name;
18
+ }
19
+ return '[Object]';
20
+ }
21
+ return String(e);
22
+ }
23
+ let NoOpDebugLogger = class NoOpDebugLogger {
24
+ configure(e) {}
25
+ log(e, o, t) {}
26
+ logBuildStart(e) {}
27
+ logBuildEnd(e, o) {}
28
+ logRegistration(e) {}
29
+ logHook(e, o, t) {}
30
+ logPhaseStart(e, o) {}
31
+ logPhaseEnd(e, o, t) {}
32
+ logResolution(e, o, t) {}
33
+ logConstruction(e) {}
34
+ logInjection(e, o) {}
35
+ };
36
+ let ActiveDebugLogger = class ActiveDebugLogger {
37
+ configure(e) {
38
+ this.options = {
39
+ ...this.options,
40
+ ...e,
41
+ logPhases: {
42
+ ...this.options.logPhases,
43
+ ...e.logPhases || {}
44
+ }
45
+ };
46
+ }
47
+ logBuildStart(e) {
48
+ this.log('info', 'Build started', {
49
+ entry: e.name
50
+ });
51
+ }
52
+ logBuildEnd(e, o) {
53
+ const t = {
54
+ entry: e.name
55
+ };
56
+ if (o !== undefined) t.duration = `${o.toFixed(2)}ms`;
57
+ this.log('info', 'Build completed', t);
58
+ }
59
+ logRegistration(o) {
60
+ if (!this.shouldLog('registration')) return;
61
+ this.log('info', 'Registration', {
62
+ identifier: e(o.identifier),
63
+ isSingleton: o.isSingleton,
64
+ dependencies: o.dependencies.map((o)=>e(o)),
65
+ tags: o.tags
9
66
  });
10
- return this.initCache;
11
67
  }
12
- callInitHooks(o) {
13
- for (const t of this.initCache){
14
- HookManager.callHookImmediate(t.instance, 'onInit', o, t.configuration);
68
+ logHook(o, t, n) {
69
+ if (!this.shouldLog('hooks')) return;
70
+ const i = this.options.logTimings ? performance.now() : 0;
71
+ this.log('info', `Hook: ${o}`, {
72
+ target: e(t),
73
+ config: n
74
+ });
75
+ if (this.options.logTimings) {
76
+ return ()=>{
77
+ const e = performance.now() - i;
78
+ this.log('info', `Hook: ${o} completed`, {
79
+ duration: `${e.toFixed(2)}ms`
80
+ });
81
+ };
15
82
  }
16
83
  }
17
- callInitedHooks(o) {
18
- for (const t of [
19
- ...this.initCache
20
- ].reverse()){
21
- HookManager.callHookImmediate(t.instance, 'onInited', o, t.configuration);
84
+ logPhaseStart(e, o) {
85
+ this.log('info', `Phase: ${e} started`, o);
86
+ }
87
+ logPhaseEnd(e, o, t) {
88
+ const n = o !== undefined ? {
89
+ duration: `${o.toFixed(2)}ms`
90
+ } : {};
91
+ if (t) {
92
+ Object.assign(n, t);
22
93
  }
94
+ this.log('info', `Phase: ${e} ended`, Object.keys(n).length > 0 ? n : undefined);
23
95
  }
24
- clearCache() {
25
- this.initCache.length = 0;
96
+ logResolution(e, o, t) {
97
+ if (!this.shouldLog('resolution')) return;
98
+ this.log('info', `Resolving: ${e}`, {
99
+ strategy: `${o} strategy`,
100
+ cache: t ? 'hit' : 'miss'
101
+ });
26
102
  }
27
- getCache() {
28
- return this.initCache;
103
+ logConstruction(e) {
104
+ if (!this.shouldLog('construction')) return;
105
+ this.log('info', `Constructing: ${e}`);
29
106
  }
30
- constructor(){
31
- this.initCache = [];
107
+ logInjection(e, o) {
108
+ if (!this.shouldLog(e === 'use' ? 'injectionUse' : 'injectionGlobal')) return;
109
+ this.log('info', `Injecting: @${e === 'use' ? 'Use' : 'Global'}`, o);
32
110
  }
33
- }
34
- HookManager.callHook = (e, i, n, a)=>{
35
- const c = DebugLogger.getInstance();
36
- const r = c.logHook(i, e, a);
37
- return new Promise((t, c)=>{
38
- const s = e[i];
39
- if (s) {
40
- if (isAsync(s)) {
41
- s.bind(e)(n, a).then(()=>{
42
- if (r) r();
43
- t();
44
- }).catch((o)=>{
45
- if (r) r();
46
- c(o);
47
- });
48
- return;
49
- }
50
- try {
51
- s.bind(e)(n, a);
52
- if (r) r();
53
- t();
54
- } catch (o) {
55
- if (r) r();
56
- c(o);
57
- }
111
+ shouldLog(e) {
112
+ return !this.options.logPhases || this.options.logPhases[e] !== false;
113
+ }
114
+ log(e, o, t) {
115
+ if (this.options.logger) {
116
+ this.options.logger(e, o, t);
58
117
  } else {
59
- if (r) r();
60
- t();
118
+ const n = `[Assembler:${e}]`;
119
+ const i = this.options.useColors !== false ? this.colorize(e, n) : n;
120
+ if (t) {
121
+ console.log(`${i} ${o}`, t);
122
+ } else {
123
+ console.log(`${i} ${o}`);
124
+ }
61
125
  }
62
- });
126
+ }
127
+ colorize(e, o) {
128
+ const t = {
129
+ info: '\x1b[36m',
130
+ warn: '\x1b[33m',
131
+ error: '\x1b[31m',
132
+ reset: '\x1b[0m'
133
+ };
134
+ const n = t[e] || t.info;
135
+ return `${n}${o}${t.reset}`;
136
+ }
137
+ constructor(){
138
+ this.options = {
139
+ enabled: true,
140
+ logPhases: {
141
+ registration: true,
142
+ registrationUse: true,
143
+ registrationGlobals: true,
144
+ resolution: true,
145
+ construction: true,
146
+ hooks: true,
147
+ cache: true,
148
+ injectionUse: true,
149
+ injectionGlobal: true
150
+ },
151
+ logTimings: false,
152
+ logDependencyTree: true,
153
+ useColors: true
154
+ };
155
+ }
63
156
  };
64
- HookManager.callHookImmediate = (e, i, n, a)=>{
65
- const c = DebugLogger.getInstance();
66
- const r = c.logHook(i, e, a);
67
- const s = e[i];
68
- if (s) {
69
- if (isAsync(s)) {
70
- s.bind(e)(n, a).catch(()=>{});
71
- if (r) r();
157
+ class DebugLogger {
158
+ static getInstance() {
159
+ return DebugLogger.instance;
160
+ }
161
+ static enable(e) {
162
+ if (e?.enabled === false) {
163
+ DebugLogger.instance = new NoOpDebugLogger();
72
164
  return;
73
165
  }
74
- s.bind(e)(n, a);
75
- if (r) r();
76
- } else {
77
- if (r) r();
166
+ DebugLogger.instance = new ActiveDebugLogger();
167
+ if (e) {
168
+ DebugLogger.instance.configure(e);
169
+ }
78
170
  }
79
- };
171
+ static disable() {
172
+ DebugLogger.instance = new NoOpDebugLogger();
173
+ }
174
+ }
175
+ DebugLogger.instance = new NoOpDebugLogger();
80
176
 
81
- export { HookManager };
177
+ export { DebugLogger };
package/dist/index35.js CHANGED
@@ -2,60 +2,68 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const hookManager = require('./index34.js');
6
- const debugLogger = require('./index37.js');
7
- const cycleDetector = require('./index38.js');
8
- const injectableManager = require('./index32.js');
9
- const schema = require('./index30.js');
10
-
11
- class AssemblerBuilder {
12
- build(n, r) {
13
- const i = debugLogger.DebugLogger.getInstance();
14
- schema.setDefinitionValue('singleton', true, n);
15
- i.logPhaseStart('registration');
16
- const l = this.assembler.register([
17
- n
18
- ]);
19
- const c = this.assembler.injectableManager.getRegisteredIdentifiers();
20
- i.logPhaseEnd('registration', undefined, {
21
- registered: c
22
- });
23
- const h = cycleDetector.CycleDetector.getInstance().detect(this.assembler.injectableManager.getInjectables(), (e)=>injectableManager.formatIdentifier(e));
24
- if (h.length > 0) {
25
- for (const e of h){
26
- i.log('error', 'Circular dependency detected', {
27
- cycle: e.cycle,
28
- path: e.path
29
- });
5
+ let AbstractCycleDetector = class AbstractCycleDetector {
6
+ };
7
+ let NoOpCycleDetector = class NoOpCycleDetector extends AbstractCycleDetector {
8
+ detect() {
9
+ return [];
10
+ }
11
+ };
12
+ let ActiveCycleDetector = class ActiveCycleDetector extends AbstractCycleDetector {
13
+ detect(e, t) {
14
+ const c = [];
15
+ const s = new Set();
16
+ for (const [n] of e){
17
+ if (s.has(n)) continue;
18
+ const r = [];
19
+ const o = new Set();
20
+ if (this.hasCycleDFS(n, r, o, s, e)) {
21
+ const e = r.findIndex((e)=>e === n);
22
+ if (e >= 0) {
23
+ const s = r.slice(e).map((e)=>t(e));
24
+ c.push({
25
+ cycle: s,
26
+ path: s.join(' ')
27
+ });
28
+ }
30
29
  }
31
30
  }
32
- i.logPhaseStart('resolution');
33
- const g = this.assembler.require(l.identifier, r);
34
- i.logPhaseEnd('resolution');
35
- const m = this.assembler.hookManager.getCache().find((e)=>e.instance === g);
36
- if (!m) {
37
- throw new Error('Root instance not found in assemblages cache.');
31
+ return c;
32
+ }
33
+ hasCycleDFS(e, t, c, s, n) {
34
+ if (c.has(e)) {
35
+ t.push(e);
36
+ return true;
37
+ }
38
+ if (s.has(e)) {
39
+ return false;
38
40
  }
39
- const b = this.assembler.hookManager.getCache().indexOf(m);
40
- this.assembler.hookManager.getCache().splice(b, 1);
41
- i.logPhaseStart('hooks:onInit');
42
- this.assembler.hookManager.callInitHooks(this.assembler.publicContext);
43
- const d = r ? {
44
- ...l.configuration,
45
- ...r
46
- } : l.configuration;
47
- hookManager.HookManager.callHookImmediate(g, 'onInit', this.assembler.publicContext, d);
48
- i.logPhaseEnd('hooks:onInit');
49
- i.logPhaseStart('hooks:onInited');
50
- this.assembler.hookManager.callInitedHooks(this.assembler.publicContext);
51
- hookManager.HookManager.callHookImmediate(g, 'onInited', this.assembler.publicContext, d);
52
- i.logPhaseEnd('hooks:onInited');
53
- this.assembler.hookManager.clearCache();
54
- return g;
41
+ t.push(e);
42
+ c.add(e);
43
+ const r = n.get(e);
44
+ if (r?.dependencies && r.dependencies.length > 0) {
45
+ for (const e of r.dependencies){
46
+ if (this.hasCycleDFS(e, t, c, s, n)) {
47
+ return true;
48
+ }
49
+ }
50
+ }
51
+ c.delete(e);
52
+ s.add(e);
53
+ return false;
54
+ }
55
+ };
56
+ class CycleDetector {
57
+ static getInstance() {
58
+ return CycleDetector.instance;
59
+ }
60
+ static enable() {
61
+ CycleDetector.instance = new ActiveCycleDetector();
55
62
  }
56
- constructor(e){
57
- this.assembler = e;
63
+ static disable() {
64
+ CycleDetector.instance = new NoOpCycleDetector();
58
65
  }
59
66
  }
67
+ CycleDetector.instance = new NoOpCycleDetector();
60
68
 
61
- exports.AssemblerBuilder = AssemblerBuilder;
69
+ exports.CycleDetector = CycleDetector;