Skip to content

Commit

Permalink
feat: add support for ESM extensions (#668)
Browse files Browse the repository at this point in the history
* feat: add support for ESM extensions

* chore: put proper prop into expect-error
  • Loading branch information
rxri authored Dec 8, 2023
1 parent 57f5a45 commit 44750a7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/extensions/extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
const { user, repo, branch, filePath } = getParamsFromGithubRaw(extensionManifest.extensionURL);
if (!user || !repo || !branch || !filePath) return;
script.src = `https://cdn.jsdelivr.${tld}/gh/${user}/${repo}@${branch}/${filePath}`;
if (filePath.endsWith(".mjs")) script.type = "module";
}

script.src = `${script.src}?time=${Date.now()}`;
Expand All @@ -93,6 +94,7 @@ import {
injectColourScheme(activeScheme);

// Add to Spicetify.Config
// @ts-expect-error: `color_scheme` is read-only type in types
Spicetify.Config.color_scheme = themeManifest.activeScheme;
if (localStorage.getItem(LOCALSTORAGE_KEYS.albumArtBasedColor) === "true") {
initAlbumArtBasedColor(activeScheme);
Expand All @@ -117,6 +119,7 @@ import {
injectUserCSS(userCSS);

// Add to Spicetify.Config
// @ts-expect-error: `current_theme` is read-only type in types
Spicetify.Config.current_theme = themeManifest.manifest?.name;

// Inject any included js
Expand All @@ -130,7 +133,9 @@ import {
// If it's a github raw script, use jsdelivr
if (isGithubRawUrl(script)) {
const { user, repo, branch, filePath } = getParamsFromGithubRaw(script);
if (!user || !repo || !branch || !filePath) return;
src = `https://cdn.jsdelivr.${tld}/gh/${user}/${repo}@${branch}/${filePath}`;
if (filePath.endsWith(".mjs")) newScript.type = "module";
}
// console.log({src});
newScript.src = `${src}?time=${Date.now()}`;
Expand Down Expand Up @@ -164,7 +169,9 @@ import {
window.sessionStorage.setItem("marketplace-request-tld", tld);

// Save to Spicetify.Config for use when removing a theme
// @ts-expect-error: Config doesn't have a `local_theme` property
Spicetify.Config.local_theme = Spicetify.Config.current_theme;
// @ts-expect-error: Config doesn't have a `local_color_scheme` property
Spicetify.Config.local_color_scheme = Spicetify.Config.color_scheme;
const installedThemeKey = localStorage.getItem(LOCALSTORAGE_KEYS.themeInstalled);
if (installedThemeKey) initializeTheme(installedThemeKey);
Expand Down

0 comments on commit 44750a7

Please sign in to comment.