Skip to content

Commit

Permalink
Replace import.meta.resolve calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Feb 6, 2024
1 parent 43c630e commit 5429910
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,31 @@ async function findFsProjFile(configDir) {
return fsprojFiles.length > 0 ? fsprojFiles[0] : null;
}

/**
@returns {Promise<string>}
*/
async function getFableLibrary() {
const fableLibraryInOwnNodeModules = path.join(
currentDir,
"node_modules/fable-library",
);
try {
await fs.access(fableLibraryInOwnNodeModules, fs.constants.F_OK);
return normalizePath(fableLibraryInOwnNodeModules);
} catch (e) {
return normalizePath(path.join(currentDir, "../fable-library"));
}
}

/**
* Retrieves the project file and its compiled files.
* @param {string} fableLibrary - Location of the fable-library node module.
* @param {string} configuration - Release or Debug
* @param {string} project - The name or path of the project.
* @returns {Promise<{projectOptions: FSharpProjectOptions, compiledFiles: Map<string, string>}>} A promise that resolves to an object containing the project options and compiled files.
* @throws {Error} If the result from the endpoint is not a success case.
*/
async function getProjectFile(configuration, project) {
const fableLibraryArray = await import.meta.resolve("fable-library/Array");
const fableLibrary = path.dirname(fableLibraryArray);

async function getProjectFile(fableLibrary, configuration, project) {
/** @type {FSharpDiscriminatedUnion} */
const result = await endpoint.send("fable/init", {
configuration,
Expand Down Expand Up @@ -113,7 +127,13 @@ export default function fablePlugin(config = {}) {
buildStart: async function (options) {
try {
this.info(`[buildStart] Initial compile started of ${fsproj}`);
const projectResponse = await getProjectFile(configuration, fsproj);
const fableLibrary = await getFableLibrary();
this.info(`[buildStart] fable-library located at ${fableLibrary}`);
const projectResponse = await getProjectFile(
fableLibrary,
configuration,
fsproj,
);
this.info(`[buildStart] Initial compile completed of ${fsproj}`);
projectOptions = projectResponse.projectOptions;
const compiledFSharpFiles = projectResponse.compiledFiles;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-fable",
"version": "0.0.5",
"version": "0.0.6",
"homepage": "https://nojaf.com/vite-plugin-fable/",
"description": "",
"main": "index.js",
Expand Down

0 comments on commit 5429910

Please sign in to comment.