-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin-system): Updated the resolver implementation to use `enhan…
…ced-resolve` package
- Loading branch information
1 parent
cd93fe2
commit bda2c10
Showing
11 changed files
with
2,242 additions
and
4,655 deletions.
There are no files selected for viewing
761 changes: 144 additions & 617 deletions
761
docs/api-reports/packages/plugin-system/api-report.md
Large diffs are not rendered by default.
Oops, something went wrong.
5,480 changes: 2,011 additions & 3,469 deletions
5,480
docs/api-reports/packages/plugin-system/documents-model.api.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,50 @@ | ||
import { isFile } from "@storm-stack/file-system"; | ||
import { ResolverFactory } from "oxc-resolver"; | ||
import fs from "node:fs"; | ||
import { StormError } from "@storm-stack/errors"; | ||
import { isString } from "@storm-stack/utilities"; | ||
import { CachedInputFileSystem, ResolverFactory } from "enhanced-resolve"; | ||
import { PluginSystemErrorCode } from ".."; | ||
|
||
/** | ||
* Create a resolver factory | ||
* | ||
* @param tsconfig - The path to the tsconfig file | ||
* @returns The resolver factory | ||
*/ | ||
export const createResolver = (tsconfig: string): ResolverFactory => { | ||
const resolverFactory = new ResolverFactory({ | ||
tsconfig: { | ||
configFile: isFile(tsconfig) ? tsconfig : `${tsconfig}/tsconfig.json`, | ||
}, | ||
descriptionFiles: ["package.json", "plugin.json"], | ||
}); | ||
export const createResolver = (rootPath?: string): ((request: string) => Promise<string>) => { | ||
const resolverFactory = ResolverFactory.createResolver({ | ||
fileSystem: new CachedInputFileSystem(fs, 4000), | ||
extensions: [".js", ".json"], | ||
descriptionFiles: ["package.json", "plugin.json"] | ||
}); | ||
|
||
return resolverFactory; | ||
return (request: string) => { | ||
const resolveContext = { | ||
issuer: rootPath | ||
}; | ||
|
||
return new Promise((resolve, reject) => { | ||
resolverFactory.resolve( | ||
resolveContext, | ||
rootPath ? rootPath : __dirname, | ||
request, | ||
{}, | ||
(error, result) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
if (!result || !isString(result)) { | ||
reject( | ||
StormError.create({ | ||
code: PluginSystemErrorCode.module_not_found, | ||
message: `Cannot find plugin ${request}` | ||
}) | ||
); | ||
} | ||
|
||
resolve(result as string); | ||
} | ||
} | ||
); | ||
}); | ||
}; | ||
}; |
Oops, something went wrong.