fix external consumption of ts rules, and simplify import path

This commit is contained in:
Damien Elmes 2020-11-05 11:01:30 +10:00
parent f93f01b3e9
commit 264dd8f1ea
34 changed files with 89 additions and 86 deletions

View file

@ -1,5 +1,5 @@
workspace(
name = "anki",
name = "net_ankiweb_anki",
managed_directories = {"@npm": [
"ts/node_modules",
]},

View file

@ -1,7 +1,7 @@
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
load("@anki//cargo:crates.bzl", "raze_fetch_remote_crates")
load("@net_ankiweb_anki//cargo:crates.bzl", "raze_fetch_remote_crates")
load(":python.bzl", "setup_local_python")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
@ -29,15 +29,9 @@ def setup_deps():
native.register_toolchains("@python//:python3_toolchain")
# pip_install(
# name = "py_deps",
# python_interpreter_target = "@python//:python",
# requirements = "@anki//pip:requirements.txt",
# )
pip_import(
name = "py_deps",
requirements = "@anki//pip:requirements.txt",
requirements = "@net_ankiweb_anki//pip:requirements.txt",
python_runtime = "@python//:python",
)
@ -46,13 +40,12 @@ def setup_deps():
python_runtime = "@python//:python",
)
node_repositories(package_json = ["@anki//ts:package.json"])
node_repositories(package_json = ["@net_ankiweb_anki//ts:package.json"])
yarn_install(
name = "npm",
package_json = "@anki//ts:package.json",
# strict_visibility = True,
yarn_lock = "@anki//ts:yarn.lock",
package_json = "@net_ankiweb_anki//ts:package.json",
yarn_lock = "@net_ankiweb_anki//ts:yarn.lock",
)
sass_repositories()

View file

@ -79,9 +79,18 @@ not being installed.
## More
For info on running tests, building wheels and so on, please see [Development](./development.md).
For info on running tests, building wheels and so on, please see
[Development](./development.md).
Note that where the instructions on that page say "bazel", please use ".\bazel"
instead. This runs bazel.bat inside the Anki source folder, instead of
calling Bazel directly. This takes care of setting up the path and output folder
correctly, which avoids issues with long path names.
## Cleaning notes
Unlike the old Make system, a "clean build" should almost never be required
unless you are debugging issues with the build system. But if you need to run
"bazel clean --expunge", make sure you remove the ts/node_modules folder
afterwards, or it will cause a "no such file or directory node_modules/anki"
error on the subsequent build on Windows.

View file

@ -1,8 +1,8 @@
<script lang="ts">
import { I18n } from "anki/ts/lib/i18n";
import pb from "anki/ts/lib/backend_proto";
import { I18n } from "anki/i18n";
import pb from "anki/backend_proto";
import { buildNextLearnMsg } from "./lib";
import { bridgeLink } from "anki/ts/lib/bridgecommand";
import { bridgeLink } from "anki/bridgecommand";
export let info: pb.BackendProto.CongratsInfoOut;
export let i18n: I18n;

View file

@ -1,10 +1,10 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { setupI18n } from "anki/ts/lib/i18n";
import CongratsPage from "anki/ts/congrats/CongratsPage.svelte";
import { setupI18n } from "anki/i18n";
import CongratsPage from "./CongratsPage.svelte";
import { getCongratsInfo } from "./lib";
import { checkNightMode } from "anki/ts/lib/nightmode";
import { checkNightMode } from "anki/nightmode";
export async function congrats(target: HTMLDivElement): Promise<void> {
checkNightMode();

View file

@ -1,10 +1,10 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import pb from "anki/ts/lib/backend_proto";
import { postRequest } from "anki/ts/lib/postrequest";
import { naturalUnit, unitAmount, unitName } from "anki/ts/lib/time";
import type { I18n } from "anki/ts/lib/i18n";
import pb from "anki/backend_proto";
import { postRequest } from "anki/postrequest";
import { naturalUnit, unitAmount, unitName } from "anki/time";
import type { I18n } from "anki/i18n";
export async function getCongratsInfo(): Promise<pb.BackendProto.CongratsInfoOut> {
return pb.BackendProto.CongratsInfoOut.decode(

View file

@ -1,11 +1,11 @@
<script lang="typescript">
import { RevlogRange, GraphRange } from "./graph-helpers";
import type { TableDatum } from "./graph-helpers";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import type { HistogramData } from "./histogram-graph";
import { gatherData, buildHistogram } from "./added";
import type { GraphData } from "./added";
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import HistogramGraph from "./HistogramGraph.svelte";
import GraphRangeRadios from "./GraphRangeRadios.svelte";
import TableData from "./TableData.svelte";

View file

@ -2,8 +2,8 @@
import { defaultGraphBounds, GraphRange, RevlogRange } from "./graph-helpers";
import AxisTicks from "./AxisTicks.svelte";
import { renderButtons } from "./buttons";
import type pb from "anki/ts/lib/backend_proto";
import type { I18n } from "anki/ts/lib/i18n";
import type pb from "anki/backend_proto";
import type { I18n } from "anki/i18n";
import NoDataOverlay from "./NoDataOverlay.svelte";
import GraphRangeRadios from "./GraphRangeRadios.svelte";

View file

@ -4,8 +4,8 @@
import { defaultGraphBounds, RevlogRange } from "./graph-helpers";
import { gatherData, renderCalendar } from "./calendar";
import type { GraphData } from "./calendar";
import type pb from "anki/ts/lib/backend_proto";
import type { I18n } from "anki/ts/lib/i18n";
import type pb from "anki/backend_proto";
import type { I18n } from "anki/i18n";
export let sourceData: pb.BackendProto.GraphsOut | null = null;
export let revlogRange: RevlogRange;

View file

@ -2,8 +2,8 @@
import { defaultGraphBounds } from "./graph-helpers";
import { gatherData, renderCards } from "./card-counts";
import type { GraphData, TableDatum } from "./card-counts";
import type pb from "anki/ts/lib/backend_proto";
import type { I18n } from "anki/ts/lib/i18n";
import type pb from "anki/backend_proto";
import type { I18n } from "anki/i18n";
export let sourceData: pb.BackendProto.GraphsOut;
export let i18n: I18n;

View file

@ -1,9 +1,9 @@
<script lang="typescript">
import type { HistogramData } from "./histogram-graph";
import { gatherData, prepareData } from "./ease";
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import HistogramGraph from "./HistogramGraph.svelte";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import type { TableDatum } from "./graph-helpers";
import TableData from "./TableData.svelte";

View file

@ -1,11 +1,11 @@
<script lang="typescript">
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import type { HistogramData } from "./histogram-graph";
import { GraphRange, RevlogRange } from "./graph-helpers";
import type { TableDatum } from "./graph-helpers";
import { gatherData, buildHistogram } from "./future-due";
import type { GraphData } from "./future-due";
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import HistogramGraph from "./HistogramGraph.svelte";
import GraphRangeRadios from "./GraphRangeRadios.svelte";
import TableData from "./TableData.svelte";

View file

@ -1,7 +1,7 @@
<script lang="typescript">
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import { RevlogRange, GraphRange } from "./graph-helpers";
import { timeSpan, MONTH, YEAR } from "anki/ts/lib/time";
import { timeSpan, MONTH, YEAR } from "anki/time";
export let i18n: I18n;
export let revlogRange: RevlogRange;

View file

@ -3,8 +3,8 @@
</script>
<script lang="typescript">
import type { I18n } from "anki/ts/lib/i18n";
import type pb from "anki/ts/lib/backend_proto";
import type { I18n } from "anki/i18n";
import type pb from "anki/backend_proto";
import { getGraphData, RevlogRange } from "./graph-helpers";
import IntervalsGraph from "./IntervalsGraph.svelte";
import EaseGraph from "./EaseGraph.svelte";

View file

@ -4,7 +4,7 @@
import AxisTicks from "./AxisTicks.svelte";
import { defaultGraphBounds } from "./graph-helpers";
import NoDataOverlay from "./NoDataOverlay.svelte";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
export let data: HistogramData | null = null;
export let i18n: I18n;

View file

@ -2,8 +2,8 @@
import { defaultGraphBounds, RevlogRange, GraphRange } from "./graph-helpers";
import AxisTicks from "./AxisTicks.svelte";
import { renderHours } from "./hours";
import type pb from "anki/ts/lib/backend_proto";
import type { I18n } from "anki/ts/lib/i18n";
import type pb from "anki/backend_proto";
import type { I18n } from "anki/i18n";
import NoDataOverlay from "./NoDataOverlay.svelte";
import GraphRangeRadios from "./GraphRangeRadios.svelte";

View file

@ -1,6 +1,6 @@
<script lang="typescript">
import { timeSpan, MONTH } from "anki/ts/lib/time";
import type { I18n } from "anki/ts/lib/i18n";
import { timeSpan, MONTH } from "anki/time";
import type { I18n } from "anki/i18n";
import type { HistogramData } from "./histogram-graph";
import {
gatherIntervalData,
@ -8,7 +8,7 @@
prepareIntervalData,
} from "./intervals";
import type { IntervalGraphData } from "./intervals";
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import HistogramGraph from "./HistogramGraph.svelte";
import type { TableDatum } from "./graph-helpers";
import TableData from "./TableData.svelte";

View file

@ -1,5 +1,5 @@
<script lang="typescript">
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import type { GraphBounds } from "./graph-helpers";
export let bounds: GraphBounds;
export let i18n: I18n;

View file

@ -4,8 +4,8 @@
import type { TableDatum } from "./graph-helpers";
import { gatherData, renderReviews } from "./reviews";
import type { GraphData } from "./reviews";
import type pb from "anki/ts/lib/backend_proto";
import type { I18n } from "anki/ts/lib/i18n";
import type pb from "anki/backend_proto";
import type { I18n } from "anki/i18n";
import NoDataOverlay from "./NoDataOverlay.svelte";
import GraphRangeRadios from "./GraphRangeRadios.svelte";
import TableData from "./TableData.svelte";

View file

@ -1,5 +1,5 @@
<script lang="typescript">
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import type { TableDatum } from "./graph-helpers";
export let i18n: I18n;

View file

@ -1,8 +1,8 @@
<script lang="typescript">
import { gatherData } from "./today";
import type { TodayData } from "./today";
import type pb from "anki/ts/lib/backend_proto";
import type { I18n } from "anki/ts/lib/i18n";
import type pb from "anki/backend_proto";
import type { I18n } from "anki/i18n";
export let sourceData: pb.BackendProto.GraphsOut | null = null;
export let i18n: I18n;

View file

@ -6,13 +6,13 @@
@typescript-eslint/no-explicit-any: "off",
*/
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import { extent, histogram, sum } from "d3-array";
import { scaleLinear, scaleSequential } from "d3-scale";
import type { HistogramData } from "./histogram-graph";
import { interpolateBlues } from "d3-scale-chromatic";
import type { I18n } from "anki/ts/lib/i18n";
import { dayLabel } from "anki/ts/lib/time";
import type { I18n } from "anki/i18n";
import { dayLabel } from "anki/time";
import { GraphRange } from "./graph-helpers";
import type { TableDatum } from "./graph-helpers";

View file

@ -1,9 +1,9 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { setupI18n } from "anki/ts/lib/i18n";
import GraphsPage from "anki/ts/graphs/GraphsPage.svelte";
import { checkNightMode } from "anki/ts/lib/nightmode";
import { setupI18n } from "anki/i18n";
import GraphsPage from "./GraphsPage.svelte";
import { checkNightMode } from "anki/nightmode";
export function graphs(target: HTMLDivElement): void {
setupI18n().then((i18n) => {

View file

@ -6,7 +6,7 @@
@typescript-eslint/no-explicit-any: "off",
*/
import pb from "anki/ts/lib/backend_proto";
import pb from "anki/backend_proto";
import { interpolateRdYlGn } from "d3-scale-chromatic";
import "d3-transition";
import { select, mouse } from "d3-selection";
@ -19,7 +19,7 @@ import {
GraphRange,
millisecondCutoffForRange,
} from "./graph-helpers";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import { sum } from "d3-array";
type ButtonCounts = [number, number, number, number];

View file

@ -6,7 +6,7 @@
@typescript-eslint/no-explicit-any: "off",
*/
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import { interpolateBlues } from "d3-scale-chromatic";
import "d3-transition";
import { select, mouse } from "d3-selection";
@ -14,7 +14,7 @@ import { scaleLinear, scaleSequential } from "d3-scale";
import { showTooltip, hideTooltip } from "./tooltip";
import { GraphBounds, setDataAvailable, RevlogRange } from "./graph-helpers";
import { timeDay, timeYear, timeWeek } from "d3-time";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
export interface GraphData {
// indexed by day, where day is relative to today

View file

@ -6,8 +6,8 @@
@typescript-eslint/no-explicit-any: "off",
*/
import { CardQueue } from "anki/ts/lib/cards";
import type pb from "anki/ts/lib/backend_proto";
import { CardQueue } from "anki/cards";
import type pb from "anki/backend_proto";
import { schemeGreens, schemeBlues } from "d3-scale-chromatic";
import "d3-transition";
import { select } from "d3-selection";
@ -16,7 +16,7 @@ import { pie, arc } from "d3-shape";
import { interpolate } from "d3-interpolate";
import type { GraphBounds } from "./graph-helpers";
import { cumsum } from "d3-array";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
type Count = [string, number];
export interface GraphData {

View file

@ -6,13 +6,13 @@
@typescript-eslint/no-explicit-any: "off",
*/
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import { extent, histogram, sum } from "d3-array";
import { scaleLinear, scaleSequential } from "d3-scale";
import { CardQueue } from "anki/ts/lib/cards";
import { CardQueue } from "anki/cards";
import type { HistogramData } from "./histogram-graph";
import { interpolateRdYlGn } from "d3-scale-chromatic";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import type { TableDatum } from "./graph-helpers";
export interface GraphData {

View file

@ -6,14 +6,14 @@
@typescript-eslint/no-explicit-any: "off",
*/
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import { extent, histogram, rollup, sum, Bin } from "d3-array";
import { scaleLinear, scaleSequential } from "d3-scale";
import { CardQueue } from "anki/ts/lib/cards";
import { CardQueue } from "anki/cards";
import type { HistogramData } from "./histogram-graph";
import { interpolateGreens } from "d3-scale-chromatic";
import { dayLabel } from "anki/ts/lib/time";
import type { I18n } from "anki/ts/lib/i18n";
import { dayLabel } from "anki/time";
import type { I18n } from "anki/i18n";
import { GraphRange } from "./graph-helpers";
import type { TableDatum } from "./graph-helpers";

View file

@ -6,9 +6,9 @@
@typescript-eslint/no-explicit-any: "off",
@typescript-eslint/ban-ts-ignore: "off" */
import pb from "anki/ts/lib/backend_proto";
import pb from "anki/backend_proto";
import type { Selection } from "d3-selection";
import { postRequest } from "anki/ts/lib/postrequest";
import { postRequest } from "anki/postrequest";
export async function getGraphData(
search: string,

View file

@ -6,7 +6,7 @@
@typescript-eslint/no-explicit-any: "off",
*/
import pb from "anki/ts/lib/backend_proto";
import pb from "anki/backend_proto";
import { interpolateBlues } from "d3-scale-chromatic";
import "d3-transition";
import { select, mouse } from "d3-selection";
@ -20,7 +20,7 @@ import {
millisecondCutoffForRange,
} from "./graph-helpers";
import { area, curveBasis } from "d3-shape";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
type ButtonCounts = [number, number, number, number];

View file

@ -6,15 +6,15 @@
@typescript-eslint/no-explicit-any: "off",
*/
import type pb from "anki/ts/lib/backend_proto";
import type pb from "anki/backend_proto";
import { extent, histogram, quantile, sum, mean } from "d3-array";
import { scaleLinear, scaleSequential } from "d3-scale";
import { CardQueue } from "anki/ts/lib/cards";
import { CardQueue } from "anki/cards";
import type { HistogramData } from "./histogram-graph";
import { interpolateBlues } from "d3-scale-chromatic";
import type { I18n } from "anki/ts/lib/i18n";
import type { I18n } from "anki/i18n";
import type { TableDatum } from "./graph-helpers";
import { timeSpan } from "anki/ts/lib/time";
import { timeSpan } from "anki/time";
export interface IntervalGraphData {
intervals: number[];

View file

@ -6,7 +6,7 @@
@typescript-eslint/no-explicit-any: "off",
*/
import pb from "anki/ts/lib/backend_proto";
import pb from "anki/backend_proto";
import {
interpolateBlues,
interpolateGreens,
@ -22,8 +22,8 @@ import { GraphBounds, setDataAvailable, GraphRange } from "./graph-helpers";
import type { TableDatum } from "./graph-helpers";
import { area, curveBasis } from "d3-shape";
import { min, histogram, sum, max, Bin, cumsum } from "d3-array";
import { timeSpan, dayLabel } from "anki/ts/lib/time";
import type { I18n } from "anki/ts/lib/i18n";
import { timeSpan, dayLabel } from "anki/time";
import type { I18n } from "anki/i18n";
interface Reviews {
mature: number;

View file

@ -1,9 +1,9 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import pb from "anki/ts/lib/backend_proto";
import { studiedToday } from "anki/ts/lib/time";
import type { I18n } from "anki/ts/lib/i18n";
import pb from "anki/backend_proto";
import { studiedToday } from "anki/time";
import type { I18n } from "anki/i18n";
export interface TodayData {
title: string;

View file

@ -28,6 +28,7 @@ ts_library(
data = [
"backend_proto",
],
module_name = "anki",
tsconfig = "//:tsconfig.json",
visibility = ["//visibility:public"],
deps = [