Skip to content
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

Export Svelte internals #1340

Merged
merged 5 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ts/deck-options/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ts_library(
"lib",
"//ts/components",
"//ts/lib",
"//ts/sveltelib",
"@npm//@popperjs",
"@npm//svelte2tsx",
],
Expand Down
2 changes: 2 additions & 0 deletions ts/deck-options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
@typescript-eslint/no-explicit-any: "off",
*/

import "sveltelib/export-runtime";

import { getDeckOptionsInfo, DeckOptionsState } from "./lib";
import { setupI18n, ModuleName } from "lib/i18n";
import { checkNightMode } from "lib/nightmode";
Expand Down
2 changes: 2 additions & 0 deletions ts/editor/Components.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script context="module" lang="typescript">
import IconButton from "components/IconButton.svelte";
import LabelButton from "components/LabelButton.svelte";
import WithShortcut from "components/WithShortcut.svelte";
import WithContext from "components/WithContext.svelte";
import WithState from "components/WithState.svelte";

Expand All @@ -14,6 +15,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export const components = {
IconButton,
LabelButton,
WithShortcut,
WithContext,
WithState,
contextKeys: { ...contextKeys, ...editorContextKeys },
Expand Down
2 changes: 2 additions & 0 deletions ts/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
@typescript-eslint/no-explicit-any: "off",
*/

import "sveltelib/export-runtime";

import { filterHTML } from "html-filter";
import { updateActiveButtons } from "./toolbar";
import { setupI18n, ModuleName } from "lib/i18n";
Expand Down
19 changes: 19 additions & 0 deletions ts/lib/runtime-require.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

/* eslint
@typescript-eslint/no-explicit-any: "off",
*/

/// This can be extended to allow require() calls at runtime, for libraries
/// that are not included at bundling time.
export const runtimeLibraries = {};

// Export require() as a global.
(globalThis as any).require = function (name: string): unknown {
const lib = runtimeLibraries[name];
if (lib === undefined) {
throw new Error(`Cannot require(${name}) at runtime.`);
}
return lib;
};
1 change: 1 addition & 0 deletions ts/sveltelib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ts_library(
tsconfig = "//:tsconfig.json",
visibility = ["//visibility:public"],
deps = [
"//ts/lib",
"@npm//svelte",
"@npm//tslib",
],
Expand Down
11 changes: 11 additions & 0 deletions ts/sveltelib/export-runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
//
// Expose the Svelte runtime bundled with Anki, so that add-ons can require() it.
// If they were to bundle their own runtime, things like bindings and contexts
// would not work.

import { runtimeLibraries } from "lib/runtime-require";
import * as svelteRuntime from "svelte/internal";

runtimeLibraries["svelte/internal"] = svelteRuntime;
6 changes: 3 additions & 3 deletions ts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4215,9 +4215,9 @@ svelte2tsx@^0.1.133:
pascal-case "^3.1.1"

svelte@^3.25.0:
version "3.38.2"
resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.38.2.tgz#55e5c681f793ae349b5cc2fe58e5782af4275ef5"
integrity sha512-q5Dq0/QHh4BLJyEVWGe7Cej5NWs040LWjMbicBGZ+3qpFWJ1YObRmUDZKbbovddLC9WW7THTj3kYbTOFmU9fbg==
version "3.42.2"
resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.42.2.tgz#0246c175c820c1aeca07300c48573a15aae3c1e4"
integrity sha512-FOyNYKXb8wdE0Ot+Ctt2/OyDLsNBP8+V6PUE9ag6ZKeLslIou0LnMu1fhtWUA+HjzKTbAM1yj+4PFLtg/3pMJA==

symbol-tree@^3.2.4:
version "3.2.4"
Expand Down