From 46b80ca7732004a44f13a64d8aa05d927c5f9d72 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 7 Oct 2021 11:34:00 +1000 Subject: [PATCH 1/3] move node_modules into root folder [action required] Recommend removing ts/node_modules folder before attempting to build after this update. This moves ts/node_modules into the root of the project to work around https://github.com/ankitects/anki/pull/1405#issuecomment-936213861 Also fixes the sass errors shown when running scripts/svelte-check --- .bazelignore | 2 +- .buildkite/linux/entrypoint | 4 ++-- .buildkite/mac/entrypoint | 4 ++-- .buildkite/windows/entrypoint.bat | 4 ++-- .gitignore | 1 + BUILD.bazel | 6 ++++-- WORKSPACE | 2 +- defs.bzl | 6 +++--- docs/development.md | 8 ++++---- ts/package.json => package.json | 2 +- scripts/copyright_headers.py | 2 +- scripts/svelte-check | 4 +++- ts/tsconfig.json | 3 +-- ts/update-licenses.sh | 4 ++-- ts/yarn.lock => yarn.lock | 0 15 files changed, 28 insertions(+), 24 deletions(-) rename ts/package.json => package.json (97%) rename ts/yarn.lock => yarn.lock (100%) diff --git a/.bazelignore b/.bazelignore index accce227b..3c3629e64 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1 +1 @@ -ts/node_modules +node_modules diff --git a/.buildkite/linux/entrypoint b/.buildkite/linux/entrypoint index b6b664731..af8a3b42b 100755 --- a/.buildkite/linux/entrypoint +++ b/.buildkite/linux/entrypoint @@ -11,7 +11,7 @@ BAZEL="bazel --output_user_root=/state/bazel --output_base=/state/bazel/anki" BUILDARGS="--config=ci --experimental_convenience_symlinks=ignore --disk_cache=/state/bazel/disk --repository_cache=/state/bazel/repo" # move existing node_modules into tree -test -e /state/node_modules && mv /state/node_modules ts/ +test -e /state/node_modules && mv /state/node_modules . $BAZEL build $BUILDARGS ... @@ -26,4 +26,4 @@ python scripts/copyright_headers.py echo "--- Cleanup" # if tests succeed, back up node_modules folder -mv ts/node_modules /state/ +mv node_modules /state/ diff --git a/.buildkite/mac/entrypoint b/.buildkite/mac/entrypoint index 547cb053e..23b21e6f7 100755 --- a/.buildkite/mac/entrypoint +++ b/.buildkite/mac/entrypoint @@ -7,7 +7,7 @@ BAZEL="bazel --output_user_root=~/bazel --output_base=~/bazel/anki" BUILDARGS="--config=ci --experimental_convenience_symlinks=ignore" # move existing node_modules into tree -test -e ~/node_modules && mv ~/node_modules ts/ +test -e ~/node_modules && mv ~/node_modules . $BAZEL build $BUILDARGS ... @@ -16,4 +16,4 @@ $BAZEL test $BUILDARGS ... echo "--- Cleanup" # if tests succeed, back up node_modules folder -mv ts/node_modules ~/ +mv node_modules ~/ diff --git a/.buildkite/windows/entrypoint.bat b/.buildkite/windows/entrypoint.bat index e9c9c47f5..637b0bdda 100755 --- a/.buildkite/windows/entrypoint.bat +++ b/.buildkite/windows/entrypoint.bat @@ -3,7 +3,7 @@ set BAZEL=\bazel\bazel.exe --output_user_root=\bazel\ankici --output_base=\bazel set BUILDARGS=--config=ci if exist \bazel\node_modules ( - move \bazel\node_modules ts\node_modules + move \bazel\node_modules .\node_modules ) :: rollup may fail on the first build, so we build once without checking return code @@ -37,4 +37,4 @@ IF %ERRORLEVEL% NEQ 0 exit /B 1 @REM echo Import succesful. echo --- Cleanup -move ts\node_modules \bazel\node_modules +move node_modules \bazel\node_modules diff --git a/.gitignore b/.gitignore index bf65a8816..e26510d69 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target user.bazelrc .dmypy.json rust-project.json +node_modules diff --git a/BUILD.bazel b/BUILD.bazel index f7c42abad..2e1218f56 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -33,5 +33,7 @@ pkg_tar( tags = ["manual"], ) -# for version info -exports_files(["defs.bzl"]) +exports_files([ + "defs.bzl", + "package.json", +]) diff --git a/WORKSPACE b/WORKSPACE index 26a551657..a6a9ab790 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,7 +1,7 @@ workspace( name = "ankidesktop", managed_directories = {"@npm": [ - "ts/node_modules", + "node_modules", ]}, ) diff --git a/defs.bzl b/defs.bzl index d165051eb..4c75a192b 100644 --- a/defs.bzl +++ b/defs.bzl @@ -43,12 +43,12 @@ def setup_deps(): python_runtime = "@python//:python", ) - node_repositories(package_json = ["@ankidesktop//ts:package.json"]) + node_repositories(package_json = ["@ankidesktop//:package.json"]) yarn_install( name = "npm", - package_json = "@ankidesktop//ts:package.json", - yarn_lock = "@ankidesktop//ts:yarn.lock", + package_json = "@ankidesktop//:package.json", + yarn_lock = "@ankidesktop//:yarn.lock", ) sass_repositories() diff --git a/docs/development.md b/docs/development.md index cff63dbb2..23166bf06 100644 --- a/docs/development.md +++ b/docs/development.md @@ -181,7 +181,7 @@ of `use` statements. The Bazel build products will make RA start up slowly out of the box. For a much nicer experience, add each of the bazel-* folders to Rust Analyzer's excludeDirs -settings, and ts/node_modules. Wildcards don't work unfortunately. Then adjust +settings, and node_modules. Wildcards don't work unfortunately. Then adjust VS Code's "watcher exclude", and add `**/bazel-*`. After running 'code' from the project root, it may take a minute or two to be @@ -203,12 +203,12 @@ Recording also requires `lame` to be in your system path. ## Build errors and cleaning If you get errors with @npm and node_modules in the message, try deleting the -ts/node_modules folder. +node_modules folder. 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 get -things to a fresh state, you can run `bazel clean --expunge`. Afte doing so, -make sure you remove the ts/node_modules folder, or subsequent build commands +things to a fresh state, you can run `bazel clean --expunge`. After doing so, +make sure you remove the node_modules folder, or subsequent build commands will fail with a "no such file or directory node_modules/anki" message. ## Tracing build problems diff --git a/ts/package.json b/package.json similarity index 97% rename from ts/package.json rename to package.json index e024d1b28..e4a38a57a 100644 --- a/ts/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "scripts": { "fix": "prettier --write */*.ts */*.svelte", - "postinstall": "patch-package" + "postinstall": "patch-package --patch-dir ts/patches" }, "dependencies": { "@fluent/bundle": "^0.17.0", diff --git a/scripts/copyright_headers.py b/scripts/copyright_headers.py index c24fc773b..3aed02dba 100644 --- a/scripts/copyright_headers.py +++ b/scripts/copyright_headers.py @@ -18,7 +18,7 @@ nonstandard_header = { ignored_folders = [ "bazel-", "qt/forms", - "ts/node_modules", + "node_modules", ] if not os.path.exists("WORKSPACE"): diff --git a/scripts/svelte-check b/scripts/svelte-check index 68433a505..a84d820e6 100755 --- a/scripts/svelte-check +++ b/scripts/svelte-check @@ -1,3 +1,5 @@ #!/bin/bash -SASS_PATH=$(pwd)/bazel-bin ts/node_modules/.bin/svelte-check --workspace ts +SASS_PATH=ts/sass:$(pwd)/bazel-bin/ts/sass \ + node_modules/.bin/svelte-check \ + --workspace ts diff --git a/ts/tsconfig.json b/ts/tsconfig.json index 75d7ed5af..7c93dc9dd 100644 --- a/ts/tsconfig.json +++ b/ts/tsconfig.json @@ -30,8 +30,7 @@ ], // uncomment for building with tsc directly // "outDir": "dist", - // "rootDir": "..", - "rootDir": ".", + "rootDir": "..", "rootDirs": [ ".", // for VS code diff --git a/ts/update-licenses.sh b/ts/update-licenses.sh index 3f0dd1f5d..348d5056e 100755 --- a/ts/update-licenses.sh +++ b/ts/update-licenses.sh @@ -3,6 +3,6 @@ set -e -./node_modules/.bin/license-checker-rseidelsohn --production --json \ +cd .. && ./node_modules/.bin/license-checker-rseidelsohn --production --json \ --excludePackages anki --relativeLicensePath \ - --relativeModulePath > licenses.json + --relativeModulePath > ts/licenses.json diff --git a/ts/yarn.lock b/yarn.lock similarity index 100% rename from ts/yarn.lock rename to yarn.lock From 1aaf8fce1e7b3e1773c60a8b97e3d8f9881bb098 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 7 Oct 2021 21:33:15 +1000 Subject: [PATCH 2/3] fix invalid arg to ButtonGroup revealed by typing fix --- ts/editor/MathjaxHandleInlineBlock.svelte | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ts/editor/MathjaxHandleInlineBlock.svelte b/ts/editor/MathjaxHandleInlineBlock.svelte index 0dac7cf79..87241ef78 100644 --- a/ts/editor/MathjaxHandleInlineBlock.svelte +++ b/ts/editor/MathjaxHandleInlineBlock.svelte @@ -17,7 +17,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html $: mathjaxElement = activeImage.parentElement!; - + + {#if isRtl} + + {/if} Date: Thu, 7 Oct 2021 21:29:21 +1000 Subject: [PATCH 3/3] svelte needs its shims to generate prop typing I erroneously removed them near the end of the ts_project work, and didn't realise the properties had broken. --- ts/svelte/svelte.bzl | 21 +++++++-------------- ts/svelte/svelte.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/ts/svelte/svelte.bzl b/ts/svelte/svelte.bzl index 07ebea648..4e6ffd3bd 100644 --- a/ts/svelte/svelte.bzl +++ b/ts/svelte/svelte.bzl @@ -3,17 +3,6 @@ load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "declaratio load("@io_bazel_rules_sass//:defs.bzl", "SassInfo") load("@build_bazel_rules_nodejs//:index.bzl", "js_library") -def _get_dep_sources(dep): - if SassInfo in dep: - return dep[SassInfo].transitive_sources - elif DeclarationInfo in dep: - return dep[DeclarationInfo].transitive_declarations - else: - return [] - -def _get_sources(deps): - return depset([], transitive = [_get_dep_sources(dep) for dep in deps]) - def _svelte(ctx): args = ctx.actions.args() args.use_param_file("@%s", use_always = True) @@ -25,18 +14,19 @@ def _svelte(ctx): args.add(ctx.outputs.css.path) args.add(ctx.var["BINDIR"]) args.add(ctx.var["GENDIR"]) + args.add_all(ctx.files._shims) ctx.actions.run( execution_requirements = {"supports-workers": "1"}, executable = ctx.executable._svelte_bin, outputs = [ctx.outputs.mjs, ctx.outputs.dts, ctx.outputs.css], - inputs = [ctx.file.entry_point], + inputs = [ctx.file.entry_point] + ctx.files._shims, mnemonic = "Svelte", arguments = [args], ) return [ - declaration_info(depset([ctx.outputs.dts]), deps = []), + declaration_info(depset([ctx.outputs.dts]), deps = [ctx.attr._shims]), ] svelte = rule( @@ -48,6 +38,10 @@ svelte = rule( executable = True, cfg = "host", ), + "_shims": attr.label( + default = Label("@npm//svelte2tsx:svelte2tsx__typings"), + allow_files = True, + ), }, outputs = { "mjs": "%{name}.svelte.mjs", @@ -82,7 +76,6 @@ def svelte_check(name = "svelte_check", srcs = []): "--fail-on-hints", ], data = [ - "//ts:tsconfig_bin", "@npm//sass", ] + srcs, env = {"SASS_PATH": "ts/sass"}, diff --git a/ts/svelte/svelte.ts b/ts/svelte/svelte.ts index e44804adc..958544446 100644 --- a/ts/svelte/svelte.ts +++ b/ts/svelte/svelte.ts @@ -90,8 +90,8 @@ const languageServiceHost: ts.LanguageServiceHost = { const languageService = ts.createLanguageService(languageServiceHost); -function compile(tsPath: string) { - parsedCommandLine.fileNames = [tsPath]; +function compile(tsPath: string, tsLibs: string[]) { + parsedCommandLine.fileNames = [tsPath, ...tsLibs]; const program = languageService.getProgram()!; const tsHost = ts.createCompilerHost(parsedCommandLine.options); const createdFiles = {}; @@ -124,8 +124,8 @@ function readFile(file) { }); } -async function writeDts(tsPath, dtsPath) { - const dtsSource = compile(tsPath); +async function writeDts(tsPath, dtsPath, tsLibs) { + const dtsSource = compile(tsPath, tsLibs); await writeFile(dtsPath, dtsSource); } @@ -192,12 +192,12 @@ async function writeJs( } async function compileSvelte(args) { - const [sveltePath, mjsPath, dtsPath, cssPath, binDir, genDir] = args; + const [sveltePath, mjsPath, dtsPath, cssPath, binDir, genDir, ...tsLibs] = args; const svelteSource = (await readFile(sveltePath)) as string; const mockTsPath = sveltePath + ".tsx"; writeTs(svelteSource, sveltePath, mockTsPath); - await writeDts(mockTsPath, dtsPath); + await writeDts(mockTsPath, dtsPath, tsLibs); await writeJs(svelteSource, sveltePath, mjsPath, cssPath, binDir, genDir); return true;