@lincyaw/compiler 1.0.0-rc.109 → 1.0.0-rc.110
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/package.json +2 -2
- package/src/compiler.ts +4 -2
- package/src/plugins.ts +17 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/compiler",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.110",
|
|
4
4
|
"description": "Presmium's compiler: structured JSON documents to runtime IR, plugin loading, compile-time execution and its cache, checks and the renderers",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"semver": "^7.8.5",
|
|
38
38
|
"send": "1.2.1",
|
|
39
39
|
"yaml": "^2.9.1",
|
|
40
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
40
|
+
"@lincyaw/kernel": "1.0.0-rc.110"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/content-disposition": "^0.5.9",
|
package/src/compiler.ts
CHANGED
|
@@ -525,8 +525,10 @@ export class Compiler {
|
|
|
525
525
|
const dirs = new Set(operators.plugins.map(loaded => loaded.dir))
|
|
526
526
|
const plugins = [...operators.plugins, ...deck.plugins.filter(loaded => !dirs.has(loaded.dir))]
|
|
527
527
|
const problems = [...operators.problems, ...deck.problems]
|
|
528
|
-
|
|
529
|
-
|
|
528
|
+
const loaded = { key, plugins, problems }
|
|
529
|
+
// Failed discovery must be retried after a package is installed or repaired.
|
|
530
|
+
this.#plugins = problems.length === 0 ? loaded : undefined
|
|
531
|
+
return loaded
|
|
530
532
|
}
|
|
531
533
|
|
|
532
534
|
}
|
package/src/plugins.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface PluginSources {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const jiti = createJiti(import.meta.url)
|
|
35
|
+
const failedEntries = new Set<string>()
|
|
35
36
|
|
|
36
37
|
export async function loadPlugin(name: string, deckDir: string, sources?: PluginSources): Promise<{ loaded?: LoadedPlugin, problem?: PluginProblem }> {
|
|
37
38
|
const problem = (severity: Severity, message: string): PluginProblem => ({ name, severity, message })
|
|
@@ -139,13 +140,28 @@ async function loadFrom(name: string, dir: string, problem: (severity: Severity,
|
|
|
139
140
|
if (!existsSync(file)) {
|
|
140
141
|
return { loaded: { name, dir }, problem: problem('warning', `plugin "${name}": ${NODE_PLUGIN_EXPORT} points to missing file ${target}; only its components are used`) }
|
|
141
142
|
}
|
|
142
|
-
const
|
|
143
|
+
const retry = failedEntries.has(file)
|
|
144
|
+
failedEntries.add(file)
|
|
145
|
+
let plugin: unknown
|
|
146
|
+
if (retry) {
|
|
147
|
+
// Re-evaluate failed entries; native ESM imports can retain an invalid export after repair.
|
|
148
|
+
delete jiti.cache[file]
|
|
149
|
+
const [kernel, contracts, node] = await Promise.all([
|
|
150
|
+
import('@lincyaw/kernel'), import('@lincyaw/kernel/contracts'), import('@lincyaw/kernel/node'),
|
|
151
|
+
])
|
|
152
|
+
const loader = createJiti(import.meta.url, { virtualModules: {
|
|
153
|
+
'@lincyaw/kernel': kernel, '@lincyaw/kernel/contracts': contracts, '@lincyaw/kernel/node': node,
|
|
154
|
+
} })
|
|
155
|
+
const module = await loader.evalModule(readFileSync(file, 'utf8'), { filename: file, async: true, forceTranspile: true })
|
|
156
|
+
plugin = isRecord(module) && module.default !== undefined ? module.default : module
|
|
157
|
+
} else plugin = await jiti.import(file, { default: true })
|
|
143
158
|
if (!isNodePlugin(plugin)) throw new Error(`default export of ${NODE_PLUGIN_EXPORT} is not a PresmiumNodePlugin`)
|
|
144
159
|
const incompatible = plugin.kernel === undefined ? undefined : kernelIncompatibility(plugin.kernel)
|
|
145
160
|
if (incompatible) {
|
|
146
161
|
const version = plugin.version ? ` ${plugin.version}` : ''
|
|
147
162
|
return { problem: problem('error', `plugin "${name}" (${plugin.id}${version}) is not loaded: ${incompatible}`) }
|
|
148
163
|
}
|
|
164
|
+
failedEntries.delete(file)
|
|
149
165
|
return { loaded: { name, dir, plugin, entry: file } }
|
|
150
166
|
} catch (error) {
|
|
151
167
|
return { problem: problem('error', `cannot load plugin "${name}": ${errorMessage(error)}`) }
|