@o-lang/olang 1.0.17 ā 1.0.19
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.
- package/cli.js +33 -8
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -86,25 +86,43 @@ function createResolverChain(resolvers, verbose = false) {
|
|
|
86
86
|
return wrapped;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Load a single resolver ā NO fallback to defaultMockResolver
|
|
91
|
+
*/
|
|
89
92
|
function loadSingleResolver(specifier) {
|
|
90
|
-
if (!specifier)
|
|
93
|
+
if (!specifier) {
|
|
94
|
+
throw new Error('Empty resolver specifier provided');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let resolver;
|
|
91
98
|
try {
|
|
92
|
-
|
|
93
|
-
if (typeof resolver !== 'function') throw new Error(`Resolver must export a function`);
|
|
94
|
-
console.log(` š¦ Loaded resolver: ${specifier}`);
|
|
95
|
-
return resolver;
|
|
99
|
+
resolver = require(specifier);
|
|
96
100
|
} catch (e1) {
|
|
97
101
|
try {
|
|
98
102
|
const absolutePath = path.resolve(process.cwd(), specifier);
|
|
99
|
-
|
|
103
|
+
resolver = require(absolutePath);
|
|
100
104
|
console.log(` š Loaded resolver: ${absolutePath}`);
|
|
101
|
-
return resolver;
|
|
102
105
|
} catch (e2) {
|
|
103
106
|
throw new Error(
|
|
104
107
|
`Failed to load resolver '${specifier}':\n npm: ${e1.message}\n file: ${e2.message}`
|
|
105
108
|
);
|
|
106
109
|
}
|
|
107
110
|
}
|
|
111
|
+
|
|
112
|
+
if (typeof resolver !== 'function') {
|
|
113
|
+
throw new Error(`Resolver must export a function`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ā
Enforce that resolvers self-identify
|
|
117
|
+
if (!resolver.resolverName || typeof resolver.resolverName !== 'string') {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Resolver from '${specifier}' is missing a valid .resolverName property.\n` +
|
|
120
|
+
`All O-Lang resolvers must export: \`module.exports.resolverName = "MyResolver";\``
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
console.log(` š¦ Loaded resolver: ${specifier} (name: ${resolver.resolverName})`);
|
|
125
|
+
return resolver;
|
|
108
126
|
}
|
|
109
127
|
|
|
110
128
|
/**
|
|
@@ -186,10 +204,17 @@ program
|
|
|
186
204
|
console.log(' š Parsed Workflow:', JSON.stringify(workflow, null, 2));
|
|
187
205
|
}
|
|
188
206
|
|
|
189
|
-
// ā
Pass allowedResolvers to loadResolverChain
|
|
190
207
|
const allowedSet = new Set(workflow.allowedResolvers.map(r => r.trim()));
|
|
191
208
|
const resolver = loadResolverChain(options.resolver, options.verbose, allowedSet);
|
|
192
209
|
|
|
210
|
+
// š Warn if allowed resolvers declared but none loaded
|
|
211
|
+
if (workflow.allowedResolvers.length > 0 && resolver._chain.length === 0) {
|
|
212
|
+
console.warn(
|
|
213
|
+
`\nā ļø Warning: Workflow allows [${workflow.allowedResolvers.join(', ')}],\n` +
|
|
214
|
+
` but no matching resolvers were loaded. Use -r <path> to provide them.\n`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
193
218
|
const result = await execute(workflow, options.input, resolver, options.verbose);
|
|
194
219
|
console.log('\n=== Workflow Result ===');
|
|
195
220
|
console.log(JSON.stringify(result, null, 2));
|
package/package.json
CHANGED