From fb775a6d02424af1a6321b629ab7ab79dc06b76e Mon Sep 17 00:00:00 2001 From: Thomas Neil James Shadwell Date: Fri, 1 Mar 2024 02:35:36 +0000 Subject: [PATCH] Allow ts_project to see package.json (for esmodule resolution). https://github.com/vercel/next.js/issues/46078 --- MODULE.bazel.lock | 36 +++++++++++++++---- ci/BUILD.bazel | 18 ---------- js/npm/package_json/rules.bzl | 4 +-- ts/cmd/svgshot/BUILD.bazel | 15 -------- ts/cmd/svgshot/testing/BUILD.bazel | 31 ---------------- .../do_not_depend_on_typescript_test.ts | 13 ------- ts/do-sync/BUILD.bazel | 22 ------------ ts/do-sync/testing/BUILD.bazel | 2 +- ts/do-sync/testing/doSync_test.ts | 5 +-- ts/math/conv_test.ts | 7 ++-- ts/next.js/component/Redirect/app.tsx | 2 +- ts/next.js/component/Redirect/index.tsx | 2 +- ts/rules.bzl | 2 +- tsconfig.json | 4 +-- 14 files changed, 43 insertions(+), 120 deletions(-) delete mode 100644 ts/cmd/svgshot/testing/BUILD.bazel delete mode 100644 ts/cmd/svgshot/testing/do_not_depend_on_typescript_test.ts diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 964faf91b3..0e3a8c4dc4 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -641,12 +641,13 @@ "name": "apple_support~1.5.0~apple_cc_configure_extension~local_config_apple_cc_toolchains" } } - } + }, + "recordedRepoMappingEntries": [] } }, "@@bazel_tools//tools/cpp:cc_configure.bzl%cc_configure_extension": { "general": { - "bzlTransitiveDigest": "O9sf6ilKWU9Veed02jG9o2HM/xgV/UAyciuFBuxrFRY=", + "bzlTransitiveDigest": "mcsWHq3xORJexV5/4eCvNOLxFOQKV6eli3fkr+tEaqE=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -664,7 +665,14 @@ "name": "bazel_tools~cc_configure_extension~local_config_cc_toolchains" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "bazel_tools", + "bazel_tools", + "bazel_tools" + ] + ] } }, "@@bazel_tools//tools/osx:xcode_configure.bzl%xcode_configure_extension": { @@ -682,7 +690,8 @@ "remote_xcode": "" } } - } + }, + "recordedRepoMappingEntries": [] } }, "@@bazel_tools//tools/sh:sh_configure.bzl%sh_configure_extension": { @@ -698,12 +707,13 @@ "name": "bazel_tools~sh_configure_extension~local_config_sh" } } - } + }, + "recordedRepoMappingEntries": [] } }, "@@rules_java~7.1.0//java:extensions.bzl%toolchains": { "general": { - "bzlTransitiveDigest": "iUIRqCK7tkhvcDJCAfPPqSd06IHG0a8HQD0xeQyVAqw=", + "bzlTransitiveDigest": "D02GmifxnV/IhYgspsJMDZ/aE8HxAjXgek5gi6FSto4=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -1238,7 +1248,19 @@ "build_file": "\nconfig_setting(\n name = \"prefix_version_setting\",\n values = {\"java_runtime_version\": \"remotejdk_21\"},\n visibility = [\"//visibility:private\"],\n)\nconfig_setting(\n name = \"version_setting\",\n values = {\"java_runtime_version\": \"21\"},\n visibility = [\"//visibility:private\"],\n)\nalias(\n name = \"version_or_prefix_version_setting\",\n actual = select({\n \":version_setting\": \":version_setting\",\n \"//conditions:default\": \":prefix_version_setting\",\n }),\n visibility = [\"//visibility:private\"],\n)\ntoolchain(\n name = \"toolchain\",\n target_compatible_with = [\"@platforms//os:windows\", \"@platforms//cpu:x86_64\"],\n target_settings = [\":version_or_prefix_version_setting\"],\n toolchain_type = \"@bazel_tools//tools/jdk:runtime_toolchain_type\",\n toolchain = \"@remotejdk21_win//:jdk\",\n)\ntoolchain(\n name = \"bootstrap_runtime_toolchain\",\n # These constraints are not required for correctness, but prevent fetches of remote JDK for\n # different architectures. As every Java compilation toolchain depends on a bootstrap runtime in\n # the same configuration, this constraint will not result in toolchain resolution failures.\n exec_compatible_with = [\"@platforms//os:windows\", \"@platforms//cpu:x86_64\"],\n target_settings = [\":version_or_prefix_version_setting\"],\n toolchain_type = \"@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type\",\n toolchain = \"@remotejdk21_win//:jdk\",\n)\n" } } - } + }, + "recordedRepoMappingEntries": [ + [ + "rules_java~7.1.0", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_java~7.1.0", + "remote_java_tools", + "rules_java~7.1.0~toolchains~remote_java_tools" + ] + ] } } } diff --git a/ci/BUILD.bazel b/ci/BUILD.bazel index 10ad193427..4fa70e2a7e 100644 --- a/ci/BUILD.bazel +++ b/ci/BUILD.bazel @@ -43,15 +43,6 @@ js_binary( "//VERSION", "//project/ck3/recursive-vassals:mod_zip", "//project/ck3/recursive-vassals:patch", - "//ts/cmd/svgshot:npm_pkg.publish", - "//ts/cmd/svgshot:npm_pkg.tgz", - "//ts/cmd/svgshot:package.json", - "//ts/do-sync:npm_pkg.publish", - "//ts/do-sync:npm_pkg.tgz", - "//ts/do-sync:package.json", - "//ts/knowitwhenyouseeit:npm_pkg.publish", - "//ts/knowitwhenyouseeit:npm_pkg.tgz", - "//ts/knowitwhenyouseeit:package.json", ], entry_point = "postsubmit.js", ) @@ -63,15 +54,6 @@ js_binary( "//VERSION", "//project/ck3/recursive-vassals:mod_zip", "//project/ck3/recursive-vassals:patch", - "//ts/cmd/svgshot:npm_pkg.publish", - "//ts/cmd/svgshot:npm_pkg.tgz", - "//ts/cmd/svgshot:package.json", - "//ts/do-sync:npm_pkg.publish", - "//ts/do-sync:npm_pkg.tgz", - "//ts/do-sync:package.json", - "//ts/knowitwhenyouseeit:npm_pkg.publish", - "//ts/knowitwhenyouseeit:npm_pkg.tgz", - "//ts/knowitwhenyouseeit:package.json", ], entry_point = "submit.js", ) diff --git a/js/npm/package_json/rules.bzl b/js/npm/package_json/rules.bzl index 90fd2a8cf0..cea7620bbc 100644 --- a/js/npm/package_json/rules.bzl +++ b/js/npm/package_json/rules.bzl @@ -24,7 +24,7 @@ def package_json(name, targets, template, version, depSpec): ], args = [ "--out", - "../../../$(execpath package.json)", + "../../../$(execpath package_new.json)", "--base", "../../../$(location //:package_json)", "--query", @@ -38,5 +38,5 @@ def package_json(name, targets, template, version, depSpec): "--depOnlyOut", "../../../$(execpath " + depSpec + ")", ], - outs = ["package.json", depSpec], + outs = ["package_new.json", depSpec], ) diff --git a/ts/cmd/svgshot/BUILD.bazel b/ts/cmd/svgshot/BUILD.bazel index 8829db7d3e..e73e461c5a 100644 --- a/ts/cmd/svgshot/BUILD.bazel +++ b/ts/cmd/svgshot/BUILD.bazel @@ -1,5 +1,4 @@ load("//bzl:rules.bzl", "bazel_lint") -load("//js/npm:rules.bzl", "npm_pkg") load("//ts:rules.bzl", "ts_project") package(default_visibility = [ @@ -53,18 +52,4 @@ filegroup( srcs = glob(["examples/**/*"]) + ["README.md"], ) -npm_pkg( - name = "npm_pkg", - srcs = [":project"], - api_lock = ".api.lock", - entry_point = "index.ts", - major_version = "version/MAJOR", - minor_version = "version/MINOR", - patch_version = "version/PATCH", - pkg_json_base = "package.template.json", - readme = "README.md", - version_lock = ".version.lock", - visibility = ["//ci:__subpackages__"], -) - bazel_lint(name = "bazel_lint") diff --git a/ts/cmd/svgshot/testing/BUILD.bazel b/ts/cmd/svgshot/testing/BUILD.bazel deleted file mode 100644 index 98d22cfbb2..0000000000 --- a/ts/cmd/svgshot/testing/BUILD.bazel +++ /dev/null @@ -1,31 +0,0 @@ -load("@bazel_skylib//rules:copy_file.bzl", "copy_file") -load("//bzl:rules.bzl", "bazel_lint") -load("//ts:rules.bzl", "jest_test", "ts_project") - -ts_project( - name = "project", - srcs = glob(["*.ts"]), - deps = [ - "//:node_modules/@types/jest", - "//:node_modules/@types/node", - ], -) - -jest_test( - name = "tests", - srcs = ["do_not_depend_on_typescript_test.js"], - data = ["//ts/cmd/svgshot/testing:package_inert.json"], - deps = [":project"], -) - -# since package.json is now used for module resolution -# (by esm), we have to copy the package.json so that -# it doesn't get interpreted. In future, this should -# probably extend the root package.json? -copy_file( - name = "inert_package_json", - src = "//ts/cmd/svgshot:package.json", - out = "package_inert.json", -) - -bazel_lint(name = "bazel_lint") diff --git a/ts/cmd/svgshot/testing/do_not_depend_on_typescript_test.ts b/ts/cmd/svgshot/testing/do_not_depend_on_typescript_test.ts deleted file mode 100644 index db05b9fbb6..0000000000 --- a/ts/cmd/svgshot/testing/do_not_depend_on_typescript_test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import fs from 'fs/promises'; - -describe('svgshot', () => { - it('shoud not have a package.json with a dependency on typescript', async () => { - const package_json = JSON.parse( - ( - await fs.readFile('ts/cmd/svgshot/testing/package_inert.json') - ).toString() - ); - - expect(package_json.dependencies).not.toContain('typescript'); - }); -}); diff --git a/ts/do-sync/BUILD.bazel b/ts/do-sync/BUILD.bazel index 62bb3c9e24..f3d087e69d 100644 --- a/ts/do-sync/BUILD.bazel +++ b/ts/do-sync/BUILD.bazel @@ -1,6 +1,4 @@ load("//bzl:rules.bzl", "bazel_lint") -load("//js:rules.bzl", "js_library") -load("//js/npm:rules.bzl", "npm_pkg") load("//ts:rules.bzl", "ts_project") package(default_visibility = [ @@ -20,24 +18,4 @@ ts_project( deps = DEPS, ) -npm_pkg( - name = "npm_pkg", - srcs = [":do-sync"], - api_lock = ".api.lock", - entry_point = "index.d.ts", - major_version = "version/MAJOR", - minor_version = "version/MINOR", - patch_version = "version/PATCH", - pkg_json_base = "package.template.json", - readme = "README.md", - version_lock = ".version.lock", -) - -js_library( - name = "lib", - srcs = ["//ts/do-sync:npm_pkg"], - visibility = ["//:__subpackages__"], - deps = DEPS, -) - bazel_lint(name = "bazel_lint") diff --git a/ts/do-sync/testing/BUILD.bazel b/ts/do-sync/testing/BUILD.bazel index ebdbc5396a..14c35125d6 100644 --- a/ts/do-sync/testing/BUILD.bazel +++ b/ts/do-sync/testing/BUILD.bazel @@ -14,7 +14,7 @@ ts_project( "//:node_modules/@types/node", "//:node_modules/@types/sharp", "//:node_modules/sharp", - "//ts/do-sync:lib", + "//ts/do-sync", ], ) diff --git a/ts/do-sync/testing/doSync_test.ts b/ts/do-sync/testing/doSync_test.ts index 1680863914..3ae196ded5 100644 --- a/ts/do-sync/testing/doSync_test.ts +++ b/ts/do-sync/testing/doSync_test.ts @@ -1,9 +1,6 @@ import sharpT from 'sharp'; -import { - doSync, - JSONObject, -} from '#root/ts/do-sync/npm_pkg/npm_pkg_dir/index.js'; +import { doSync, JSONObject } from '#root/ts/do-sync/index.js'; const pixel = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=='; diff --git a/ts/math/conv_test.ts b/ts/math/conv_test.ts index 73a89099fc..3919305727 100644 --- a/ts/math/conv_test.ts +++ b/ts/math/conv_test.ts @@ -1,9 +1,12 @@ import * as cartesian from '#root/ts/math/cartesian.js'; +import { + Cartestian as C, + Euler as E, + Quaternion as Q, +} from '#root/ts/math/conv.js'; import * as euler_angle from '#root/ts/math/euler_angle.js'; import * as quaternion from '#root/ts/math/quaternion.js'; -import { Cartestian as C, Euler as E, Quaternion as Q } from './conv'; - describe('Conversions', () => { test('Quaternion from EulerAngles', () => { const eulerAngles = new euler_angle.EulerAngle( diff --git a/ts/next.js/component/Redirect/app.tsx b/ts/next.js/component/Redirect/app.tsx index f6fef35c72..2571c48879 100644 --- a/ts/next.js/component/Redirect/app.tsx +++ b/ts/next.js/component/Redirect/app.tsx @@ -4,7 +4,7 @@ * app router. */ -import Head from 'next/head'; +import Head from 'next/head.js'; import { useRouter } from 'next/navigation'; import { useEffect } from 'react'; diff --git a/ts/next.js/component/Redirect/index.tsx b/ts/next.js/component/Redirect/index.tsx index 143ddc0324..aa990993fb 100644 --- a/ts/next.js/component/Redirect/index.tsx +++ b/ts/next.js/component/Redirect/index.tsx @@ -1,5 +1,5 @@ import Head from 'next/head'; -import { useRouter } from 'next/router'; +import { useRouter } from 'next/router.js'; import { useEffect } from 'react'; export interface Props { diff --git a/ts/rules.bzl b/ts/rules.bzl index c952c852cf..d9528cc572 100644 --- a/ts/rules.bzl +++ b/ts/rules.bzl @@ -39,7 +39,7 @@ def ts_project(name, visibility = None, deps = [], ignores_lint = [], resolve_js _ts_project( name = name, - srcs = srcs, + srcs = srcs + ["//:package_json"], tsconfig = tsconfig, # swc injects this deps = deps + ["//:node_modules/regenerator-runtime"], diff --git a/tsconfig.json b/tsconfig.json index 9b48faae0f..31220549bc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,11 @@ { "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { - "module": "node16", + "module": "esnext", + "moduleResolution": "bundler", "target": "es2020", "strictFunctionTypes": true, "esModuleInterop": true, - "moduleResolution": "node16", "strict": true, "jsx": "react-jsx", "resolveJsonModule": true,