Repository navigation
fix(514): keep dotted alias imports and non-JS alias imports on their module - #2975
Conversation
Signed-off-by: Antonio Espinosa <antespi@gmail.com>
A path-alias import of a dotted TypeScript file (~/cats/cat.service) must keep the dotted name, but an alias import of a non-JS file (~/styles/globals.css, ~/styles.css?url) must still drop its extension, as it does on main. Keeping every extension sent the CSS imports away from their module nodes. The alias branch of cbm_pipeline_resolve_module now decides from the file path, because filename dots and path separators both become dots in a qualified name: - an explicit JS/TS or JSON extension names its module; - a module at exactly the imported path wins (styles.css, also beside styles.css.ts or styles/css.ts); - else a dotted-name module at that path plus a module extension wins (theme.css.ts imported as ~/theme.css); - else the extension drops, as on main. A bundler ?query and a #fragment are cut before the extension is read. The shared alias resolver in path_alias.c is back to main's behaviour, so doc links keep the file identity they had. Refs DeusData#514 Signed-off-by: chidev <chicagowebdev@gmail.com>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
An alias import of ~/dir?name/file was cut at the question mark and reached src/dir.ts. Only a question mark in the file name starts a bundler query. The dotted-alias test now also checks the Module label. Refs DeusData#514 Signed-off-by: chidev <chicagowebdev@gmail.com>
…port The alias resolver removes a spelled module extension. The module-name helper then read the next dotted part as another extension, so ~/tokens.css.ts reached tokens.css and ~/worker.task.mjs.ts reached worker.task.mjs when both files exist. What is left after the resolver removed a spelled extension is now the whole file stem. Refs DeusData#514 Signed-off-by: chidev <chicagowebdev@gmail.com>
subprocess_tree_rss_measures_contained_descendants compared two independently spawned process trees, one idle and one whose descendant touched 128 MiB, and required the loaded total to be at least 96 MiB above the idle total. Two separate trees need not start from the same footprint. On the hosted Windows CLANG64 leg they did not: the loaded tree measured only 78 MiB above the idle one (167 MiB vs 245 MiB), and the test failed on two unrelated PRs within two days (DeusData#2965 on 889170c, DeusData#2975 run 43499140720). The diagnosis that the two separate trees are the cause comes from DeusData#2965. The test now samples ONE tree twice, and every wait in the handshake is a blocking pipe read instead of a poll of a ready file: - The test creates two pipes, "up" (tree to test) and "down" (test to tree): FIFOs in its private temporary directory on POSIX, named pipes named after that directory's unique leaf on Windows. The __cbm_rss_tree_root role connects both as its first action and starts one __cbm_rss_tree_hold descendant that inherits the connected ends (fork on POSIX, an explicit two-handle inherit list on Windows); the root then drops its own copies. - The descendant writes 'I'; the test takes the idle sample and writes 'L'; the descendant touches every page of a 192 MiB load and writes 'R'; the test takes the loaded sample and closes its ends, which releases the descendant to free the load and exit. - A descendant that dies closes its ends, so the waiting read returns end-of-file instead of blocking. No handshake step has a sleep, a poll interval or a deadline. The floor stays at 96 MiB and is now half the load: the root does not grow between the two samples, so a probe that counts only the root misses the floor by 96 MiB, and a probe that counts the descendant clears it with 96 MiB to spare. The two member-fault tests use the same handshake and keep their assertions. Production code is unchanged. Evidence: - macOS arm64, ASan: subprocess suite 60 passed, 2 skipped (the Windows-only Job Object probes); the rewritten test passed 20 of 20 consecutive runs, idle 43 MiB and loaded 259 MiB in every run. - Binding: with the macOS probe temporarily limited to the root process, the test fails at the floor assertion (idle 33 MiB, loaded 33 MiB); restoring the probe returns the suite to green. - Linux arm64 container, gcc ASan: subprocess suite 60 passed, 2 skipped; the rewritten test passed 20 of 20 consecutive runs, idle 462 MiB and loaded 654 MiB in every run. - Windows: both changed files compile with -fsyntax-only -Wall -Wextra -Werror under llvm-mingw for x86_64 and aarch64. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
DeusData
left a comment
There was a problem hiding this comment.
Thank you @chidev, this is exactly the split we asked for, and it is a pleasure to review. Keeping @antespi's original preserve dotted filename commit with his authorship and sign-off, and building the item 5 fix on top of it, is the right way to carry his work forward. Thanks again to @antespi as well: the dotted-basename idea goes back to his work in #2402 and #2900, and nest users get the benefit of it here.
The way you solved item 5 is better than the simple fix we suggested. A qualified name cannot tell styles.css from styles/css.ts, so letting the file path decide (explicit module extension first, then a module at exactly the imported path, then a dotted module at that path plus a module extension, else main's behaviour) is the right call. The tests are strong. Each edge checks the exact target file and the Module label, there are decoys for the name-guess fallback (css, service, tokens, frag), and the ?url, #fragment, .mjs/.cjs/.mts/.cts/.json and tokens.css beside tokens.css.ts cases are all pinned. It was also good to see you catch and fix two faults in your own commit 2 (the ? in a folder name, and the spelled .ts read twice), each with its own test, and to list the known limits plainly in the description.
What we checked on our side, on the head commit 57205dc:
- Scope: only the dotted alias fix and item 5. The net diff touches
pass_pkgmap.cand two test files;path_alias.candtest_path_alias.cend up unchanged against main, and nothing from the barrel work is included. - RED/GREEN: with main's
pass_pkgmap.cand your tests, edge_imports fails 3 tests for the right reasons (cat.serviceandtheme.cssmiss their modules, one of them lands on the decoycssfunction and one on thesrc/catfolder, and~/tokens.css.tsreachestokens.css). With your code they pass. The?folder test passes on main too, as your description says; it guards commit 3. For the record, the "86 passed, 2 failed" in the description predates commit 4: with all four commits' tests it is 87 passed, 3 failed on main's code. - Suites (ASan/UBSan build): edge_imports, pipeline, parallel, ts_lsp, path_alias, complexity, fqn and doc_mentions_ts, 1115 passed, none failed. In the repro suite, your new
repro_issue514_ctor_param_property_alias_import_callerspasses. The olderrepro_issue514_data_flow_surfaces_arg_exprfails here too, at line 171 with "project not found or not indexed", so your private HOME setup was not the cause. The repro harness restoresCBM_CACHE_DIRafter indexing, which is the same thing your newrh514_trace_inboundhelper works around. This PR does not touch that test, and we will look at it separately. - Real repositories, main's code against yours, with both the parallel and the sequential resolver:
- nestjs/nest: 25 IMPORTS edges gained, 1 lost, all 26 judged by hand. The gains are spec and sample files that import dotted modules through tsconfig paths (
unknown-dependencies.exception,shared.utils,cli-colors.util,route-paramtypes.enum,load-package.util, ...) and now reach the right module. The one lost edge was wrong on main:StandardSchemaSerializerInterceptorwas bound to an unrelatedLateHeadersController.interceptormethod by name, and now reachesstandard-schema-serializer.interceptor.ts. Six CALLS that were name guesses (unique_name,suffix_match) now resolve through the import map to the same functions, and one newsuper.createIOServercall reachesIoAdapter.createIOServer. No TESTS edge changes. - trpc/trpc: no IMPORTS, CALLS or TESTS change at all. In particular
import '~/styles/globals.css'reaches the same CSS module as on main, so the item 5 regression from #2900 is gone. - The sequential and parallel resolvers give the same change on both repositories, repeated runs are identical, and a Go repository (caddy) indexes byte-identically with and without this change.
- nestjs/nest: 25 IMPORTS edges gained, 1 lost, all 26 judged by hand. The gains are spec and sample files that import dotted modules through tsconfig paths (
- A small probe repository with tsconfig paths:
@/app.module,~/user.model,~/types/global.dand~/types/global.d.ts, and default and namespace imports of~/cats/cat.servicenow reach their modules (main had no edge for any of them).~/lib,~/lib/index,~/lib/index.ts(the/indexcase from our first #2900 review),.json,.css,.scssand?reactimports reach the same targets as on main. - The new lookups run in the IMPORTS phase after every Module node exists, in both pipelines, so the result does not depend on file order. They are constant work per import, and the complexity guard stays green.
- clang-format and cppcheck are clean on
pass_pkgmap.c, and the memory-core linter passes. The branch merges cleanly with current main; main's recent changes topath_alias.candpass_pkgmap.cdo not interact with this one, so there is no need to merge main in.
We have nothing more to ask for here. One small note: main has moved on since, so we used GitHub's update-branch to merge current main into your branch (4a8ae8d); your commits are unchanged, please pull before pushing again. Once CI is green on that head we will merge it.
Thanks again to both of you. This closes a real gap for NestJS and monorepo users, and the barrel part in #2900 can now move on separately.
|
One more merge of current main into this branch (f267c48), via GitHub's update-branch: main just merged #2360, which also touches src/pipeline/pass_pkgmap.c and tests/test_edge_imports.c, so CI needs a fresh run on top of it. Your commits are unchanged; please pull before pushing again. We will merge once it is green. Thank you! |
|
Merged in 08a7a58. Thank you, @chidev, for turning this into exactly the split we asked for and for the careful tests, and thank you again to @antespi, whose dotted-basename work from #2402 and #2900 is the first commit here. NestJS-style dotted modules ( |
Written with Claude Code (an AI agent) on behalf of @chidev, who reviewed it and is accountable for it.
What does this PR do?
This is the split you asked for in the review of #2900: the dotted-basename commit together with item 5 of that review, on current main (a3e9c91). Part of #514. It does not close the issue.
fix(514): preserve dotted filename, unchanged, with his sign-off.path_alias.candtests/test_path_alias.cback to main's state and makes the decision in the alias branch ofcbm_pipeline_resolve_module(alias_module_qninpass_pkgmap.c). The net diff against main is 3 files, 366 lines added, 6 removed.?in a folder name (~/dir?name/file) was cut as a bundler query and reachedsrc/dir.ts. Only a?in the file name starts a query now..ts, and the new code then read the next dotted part as another extension.~/tokens.css.tsreachedtokens.cssand~/worker.task.mjs.tsreachedworker.task.mjswhen both files exist. What is left after the resolver removed a spelled extension is now the whole file stem.A qualified name cannot tell
styles.cssfromstyles/css.ts, because filename dots and path separators both become dots. So the file path decides, in this order:~/styles.css, also besidestyles.css.tsorstyles/css.ts).~/theme.cssreachestheme.css.ts;~/cats/cat.servicereachescat.service.ts).A bundler
?queryand a#fragmenton the file name are cut before the extension is read. The shared alias resolver is unchanged, so doc links keep the file identity they have on main.Evidence
Machine: Apple M3 Ultra, macOS 26.2, no sanitizer (
SANITIZE=). My runs used a separateBUILD_DIRand a privateHOME; the commands below are the same without those two settings.pass_pkgmap.cscripts/test.sh SANITIZE= --suites edge_importsscripts/test.sh SANITIZE= --suites path_alias,edge_imports,doc_mentions_ts,fqnpass_pkgmap.cCBM_TEST_ONLY=edge_imports:ei_typescript_alias_import_keeps_question_mark_folder,... build/c/test-runner edge_importssrc/user.ts -> src/dir.ts, expectedsrc/dir?name/file.tsmake -f Makefile.cbm SANITIZE= build/c/test-repro-runner && CBM_REPRO_ONLY=repro_issue514 build/c/test-repro-runnerThe two tests that fail with main's production code:
ei_typescript_dotted_alias_import_targets_source_module(tests/test_edge_imports.c:663).ei_typescript_alias_import_non_js_file_targets_its_module, on three of its 17 edges:src/app.ts -> src/cats/cat.service.ts,src/panel.ts -> src/theme.css.ts,src/cat-user.ts -> src/cat.service.ts.The other 14 edges of the second test pass on main. They are the guard for item 5:
~/styles/globals.css,~/styles.css?url,styles.cssbesidestyles/css.ts,tokens.cssbesidetokens.css.ts(plain and?url), a#fragmentimport with a same-name decoy function in another folder, and.mjs .cjs .mts .cts .jsonfiles. Each expects the exact target file and theModulelabel. The third new test,ei_typescript_alias_import_keeps_question_mark_folder, passes on main and guards commit 3; it is not built on Windows, where a file name cannot hold?.Known limits
cat.service.tsandcat/service.tsstill share one qualified name. This PR does not change how module names are built; the test pins which file an alias import reaches when both exist.~/a.bwith onlya/b.tson disk:.bis not an indexed extension, so the name stays whole and reachesa/b.ts, because the two share one qualified name. Main drops.b.~/theme.css.tswritten in full beside atheme.cssfile now reachestheme.css.ts(commit 4; testei_typescript_alias_import_spelled_ext_on_dotted_name, which fails on commit 3's code withsrc/a.ts -> src/tokens.cssandsrc/b.ts -> src/worker.task.mjs). Main reachestheme.cssthere. Not covered: a doubled extension such as~/a.ts.ts.tests/repro/repro_issue514.c, the new testrepro_issue514_ctor_param_property_alias_import_callerspasses. The olderrepro_issue514_data_flow_surfaces_arg_exprfails at line 171 in my local run. The response isproject not found or not indexed, which points at my privateHOMEsetup and not at this change. I did not run it on a3e9c91 without this change, so CI is the check for it. This PR does not touch that test.lint-cilocally.clang-format20.1.8 reports no difference onsrc/pipeline/pass_pkgmap.c.Checklist
git commit -s);scripts/check-dco.sh origin/main..HEADpasses for both commitsmake -f Makefile.cbm test): only the suites in the table were runmake -f Makefile.cbm lint-ci): not run locally