Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/angular-migration-file-subpath.md
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading