-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
bug(migrations): migration-v13 unresolved TS project for non-buildable / test target without tsconfig path projects #23930
Comments
Thanks for the issue! With custom builders it is not safe/trivial to determine a path to an actual target tsconfig that works, and the migration would then fail down the road (causing even more confusion). I believe that is also not something we want to make any guarantees for. As it seems we currently do not even check for an official builder (we do in At first glance, I think there are two options:
|
@devversion I've updated my original issue with corrected information as my initial thoughts proved to be incorrect. After more investigation, I can narrow this down a bit more. Some library projects may not have a This definitely makes it more difficult to determine a tsconfig path. Especially as there may not be a standard convention for the lib's tsconfig file name. As you've stated, you already do not look for an official builder, that was a mistake on my part. Perhaps you can confirm this sentiment:
|
@Coly010 I have discussed this a little more with the CLI team and it looks like we could change this to a warning where we just point to the changelog. Would that work for you? I'm a little confused about:
Is the update process still completing gracefully right now with just a warning? or does it stop migration other projects/targets in the workspace? I think the expected thing (at least for me), would be to continue migrating whatever project/target is possible, but just printing a yellow/red warning for the targets that could not be migrated. thoughts? |
@devversion Say I have a workspace of structure:
However, let's assume that The migration will successfully find If it does benefit from the migration because it has been used in |
@Coly010 yeah, you are right. It looks like we just print a warning already.
That's a very interesting case. I think the answer is "partially". It depends on what files are referenced through/how the library tsconfig is composed. I imagine a scenario where only certain files are part of the TS resolution (when it visits an import), but some other files remain unvisited but would be technically part of another e.g. entry-point. I think we should ensure that the migration never actually deals with files which are outside of the current project. We do this currently by relying on TypeScript to determine external files, but AFAICT it only skips source files in
Agreed, that is confusing. I think we should never migrate the |
@devversion I agree that it would probably be better to skip visiting However, in that scenario, is it, or can it be made possible, to allow the migration to be run manually with a flag such as e.g. in the scenario outlined, I've written a migration script using Nx Devkit which aims to perform the same migration. As you can see, it doesn't require the TSConfig at all, but that leaves me to ask, have I missed something in my thought process here? Is there a reason there is a TS Program being created? export default async function (tree: Tree, schema: { projects: string[] }) {
for (const project of schema.projects) {
const projectConfig = readProjectConfiguration(tree, project);
if (!projectConfig.sourceRoot) {
continue;
}
visitNotIgnoredFiles(tree, projectConfig.sourceRoot, (filePath) => {
if (filePath.endsWith('.scss') || filePath.endsWith('.css')) {
// run migration
const content = tree.read(filePath, 'utf-8');
if (!content) {
return;
}
const migratedContent = content.replace(
/@(?:import|use) +['"]~@angular\/.*['"].*;?/g,
(match) => {
const index = match.indexOf('~@angular');
return match.slice(0, index) + match.slice(index + 1);
}
);
if (migratedContent && migratedContent !== content) {
tree.write(filePath, migratedContent);
}
}
});
}
await formatFiles(tree);
} |
It's true that this migration could technically run without a TS program here, but the migration has just leveraged the update tool we built for all types of migrations, and I think for the sake of a consistent way to have migrations - this is not too bad. The update tool relies on the TypeScript program as it analyzes the sources and also determines inline templates, inline stylesheets etc. so it's actually doing much more than just checking for Obviously the specific migration you mentioned does not even migrate inline templates, but you get the idea; and this issue does not seem to be about this specific migration as the TS program issue will appear with any future |
@devversion yeah exactly, the real issue here is that the TS Program will have similar future issues during migration 🙂 |
yeah, I think we need some more thoughts on this. I think a first step is to stop migrating other projects/targets (as mentioned before), and then we should look for ways that allow specification of a tsconfig. I like the idea of a |
I'm closing this one since the v13 migrations are long gone by now. |
Is this a regression?
The previous version in which this bug was not present was
No response
Description
When running the migration (migration-v13), the following is printed to the console:
Could not find TypeScript project for project: project-name
This appears to be the result of the logic that is being used to find the TSConfig file for the project in theangular.json
.It is looking for
test
targets that use the@angular-devkit/build-angular:karma
builder, ignoring that there might be other builders being used for thetest
target that contain a path to thetsconfig
file.After more investigation, I can narrow this down a bit more.
it's related to the
getTargetTsconfigPath
function.Some library projects may not have a
build
target by default, and theirtest
target may be usingjest
which does not contain atsconfig
property.This definitely makes it more difficult to determine a tsconfig path. Especially as there may not be a standard convention for the lib's tsconfig file name.
Reproduction
Steps to reproduce:
1. Change thetest
target's builder of any project using Angular Material2. Try run the migrationExpected Behavior
It should run the migration with no errors / warnings.
Actual Behavior
It does not find the tsconfig for the project therefore the migration logs warnings.
Environment
The text was updated successfully, but these errors were encountered: