Skip to content

fix(bazel): handle *.mts / *.cts extensions in strict deps test #2738

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion bazel/ts_project/strict_deps/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const manifest: StrictDepsManifest = JSON.parse(await fs.readFile(manifestExecPa
* Regex matcher to extract a npm package name, potentially with scope from a subpackage import path.
*/
const moduleSpeciferMatcher = /^(@[\w\d-_]+\/)?([\w\d-_]+)/;
const extensionRemoveRegex = /\.[mc]?(js|(d\.)?ts)$/;
const extensionRemoveRegex = /\.[mc]?(js|(d\.)?[mc]?ts)$/;
const allowedModuleNames = new Set<string>(manifest.allowedModuleNames);
const allowedSources = new Set<string>(
manifest.allowedSources.map((s) => s.replace(extensionRemoveRegex, '')),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("//bazel/ts_project/strict_deps:index.bzl", "strict_deps_test")

strict_deps_test(
name = "import_from_mts_cts_extensions",
srcs = ["index.ts"],
deps = [":mts_cts_extensions"],
)

ts_project(
name = "mts_cts_extensions",
srcs = [
"common_extension.cts",
"module_extension.mts",
],
declaration = True,
deps = ["//bazel:node_modules/@types/node"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const commonValue = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {commonValue} from './common_extension.cjs';

// This file compiles to CommonJS, so it needs a dynamic import for TS
// to allow a dependency on an ESM file.
export const mod = import('./module_extension.mjs');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const moduleValue = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"strict": true,
"lib": ["esnext", "DOM"],
"declaration": true
}
}