From 1e3270de484ba58fc3ec7db5f83c982de7380982 Mon Sep 17 00:00:00 2001 From: Akash P <2557058+imaksp@users.noreply.github.com> Date: Thu, 15 Oct 2026 16:24:48 +0530 Subject: [PATCH] fix(angular): migration schematic no longer aborts on file subpath imports TypeScript probes `directoryExists` with paths that are files during module resolution; `Tree.getDir()` throws on those. Report them as non-directories. Fixes #12032 Co-Authored-By: Claude Opus 5.5 --- .changeset/angular-migration-file-subpath.md | 5 ++ .../migrate-from-experimental.test.ts | 51 +++++++++++++++++++ .../migrate-from-experimental/workspace.ts | 2 + 3 files changed, 58 insertions(+) create mode 100644 .changeset/angular-migration-file-subpath.md diff --git a/.changeset/angular-migration-file-subpath.md b/.changeset/angular-migration-file-subpath.md new file mode 100644 index 0000000000..f669f15635 --- /dev/null +++ b/.changeset/angular-migration-file-subpath.md @@ -0,0 +1,5 @@ +--- +'@tanstack/angular-query': patch +--- + +Fix the `migrate-from-experimental` schematic aborting with `Path "…" is a file.` when a project source imports a package subpath that names a file, such as `@noble/hashes/sha3.js`. diff --git a/packages/angular-query/schematics-build/migrate-from-experimental.test.ts b/packages/angular-query/schematics-build/migrate-from-experimental.test.ts index aae554ba48..2d2a609516 100644 --- a/packages/angular-query/schematics-build/migrate-from-experimental.test.ts +++ b/packages/angular-query/schematics-build/migrate-from-experimental.test.ts @@ -956,6 +956,57 @@ export type { QueryKey } from '@tanstack/query-core';`, }, ) + it('resolves imports of package subpaths that name a file', async () => { + // TypeScript probes `directoryExists` with candidate paths that are files, like + // `/node_modules/@noble/hashes/sha3.js`; that must not abort the migration. + const { runner, tree } = setup( + `import { QueryClient } from '@tanstack/angular-query-experimental'; +import { sha3_256 } from '@noble/hashes/sha3.js';`, + ) + tree.create( + '/angular.json', + JSON.stringify({ + version: 1, + projects: { + app: { + root: '', + sourceRoot: 'src', + architect: { build: { options: { tsConfig: 'tsconfig.json' } } }, + }, + }, + }), + ) + tree.create( + '/tsconfig.json', + JSON.stringify({ + compilerOptions: { module: 'ES2022', moduleResolution: 'bundler' }, + files: ['src/app.ts'], + }), + ) + tree.create( + '/node_modules/@noble/hashes/package.json', + JSON.stringify({ + name: '@noble/hashes', + type: 'module', + exports: { './sha3.js': './sha3.js' }, + }), + ) + tree.create('/node_modules/@noble/hashes/sha3.js', 'export {}') + tree.create( + '/node_modules/@noble/hashes/sha3.d.ts', + 'export declare const sha3_256: unknown', + ) + const result = await runner.runSchematic( + 'migrate-from-experimental', + {}, + tree, + ) + expect(result.readContent('/src/app.ts')).not.toContain( + '@tanstack/angular-query-experimental', + ) + expect(result.readContent('/src/app.ts')).toContain(packageJson.name) + }) + it('discovers package-based Nx libraries and respects their tsconfigs', async () => { const legacy = `import { QueryClient } from '@tanstack/angular-query-experimental';` const { runner, tree } = setup(legacy) diff --git a/packages/angular-query/schematics/migrate-from-experimental/workspace.ts b/packages/angular-query/schematics/migrate-from-experimental/workspace.ts index c49ef5f95d..6709724b3f 100644 --- a/packages/angular-query/schematics/migrate-from-experimental/workspace.ts +++ b/packages/angular-query/schematics/migrate-from-experimental/workspace.ts @@ -132,6 +132,8 @@ function configuredSources(tree: Tree, configPath: string) { host.readFile = readFile host.realpath = (path) => path host.directoryExists = (path) => { + // TypeScript also probes file paths here; `getDir` throws on those. + if (tree.exists(path)) return false const directory = tree.getDir(path) return directory.subfiles.length > 0 || directory.subdirs.length > 0 }