-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bad sketches dont block run #471
Merged
funwithtriangles
merged 3 commits into
nudibranchrecords:alpha
from
cale-bradbury:fix/bad-sketches-dont-block-run
Dec 9, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,46 +1,61 @@ | ||
import { Result } from './types' | ||
import { SketchConfig, SketchModule, SketchModuleItem } from '@store/types' | ||
import { createUniqueId } from '@utils/createUniqueId' | ||
|
||
export const importSketchModule = async ( | ||
baseUrl: string, | ||
moduleId: string, | ||
): Promise<SketchModuleItem> => { | ||
const cacheBust = createUniqueId() | ||
): Promise<Result<SketchModuleItem>> => { | ||
try { | ||
const cacheBust = createUniqueId() | ||
|
||
// Get the sketch module | ||
const sketchPath = `${baseUrl}/${moduleId}/index.js?${cacheBust}` | ||
if ((await fetch(sketchPath)).status !== 200) { | ||
return Promise.reject(`Sketch module not found: ${sketchPath}`) | ||
} | ||
const sketchModule = await import(/* @vite-ignore */ sketchPath) | ||
const module: SketchModule = sketchModule.default | ||
// Get the sketch module | ||
const sketchPath = `${baseUrl}/${moduleId}/index.js?${cacheBust}` | ||
if ((await fetch(sketchPath)).status !== 200) { | ||
return Promise.reject(`Sketch module not found: ${sketchPath}`) | ||
} | ||
const sketchModule = await import(/* @vite-ignore */ sketchPath) | ||
const module: SketchModule = sketchModule.default | ||
|
||
// Get the sketch config | ||
const configPath = `${baseUrl}/${moduleId}/config.js?${cacheBust}` | ||
let config: SketchConfig | ||
if ((await fetch(configPath)).status !== 200) { | ||
// No config file found | ||
// Try instancing the sketch, and call getConfig() on it | ||
const tempModule = new module() | ||
config = tempModule.getConfig?.() | ||
if (!config) { | ||
return Promise.reject( | ||
`Sketch config not found: ${configPath} and no valid getConfig() function found in sketch`, | ||
) | ||
// Get the sketch config | ||
const configPath = `${baseUrl}/${moduleId}/config.js?${cacheBust}` | ||
let config: SketchConfig | ||
if ((await fetch(configPath)).status !== 200) { | ||
// No config file found | ||
// Try instancing the sketch, and call getConfig() on it | ||
const tempModule = new module() | ||
config = tempModule.getConfig?.() | ||
if (!config) { | ||
return Promise.reject( | ||
`Sketch config not found: ${configPath} and no valid getConfig() function found in sketch`, | ||
) | ||
} | ||
} else { | ||
const configModule = await import(/* @vite-ignore */ configPath) | ||
config = configModule.default | ||
} | ||
} else { | ||
const configModule = await import(/* @vite-ignore */ configPath) | ||
config = configModule.default | ||
} | ||
|
||
// A config could be missing a title, but it is a required parameter | ||
if (!config.title) { | ||
config.title = moduleId | ||
} | ||
// A config could be missing a title, but it is a required parameter | ||
if (!config.title) { | ||
config.title = moduleId | ||
} | ||
|
||
return { | ||
success: true, | ||
error: undefined, | ||
data: { | ||
moduleId, | ||
config, | ||
module, | ||
}, | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
|
||
return { | ||
moduleId, | ||
config, | ||
module, | ||
return { | ||
data: undefined, | ||
success: false, | ||
error: `[HEDRON] Sketch module failed to import: ${moduleId}`, | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type Result<T> = | ||
| { success: true; data: T; error: undefined } | ||
| { success: false; error: string; data: undefined } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we're now checking for this issue lower down, other functions are affected. Here we're just not doing the reimport stuff if the module failed to load.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this looks really nice, feel free to merge :)