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
MergeStrategy seems to be completely broken (mergeWith failure) #11337
Comments
Could you provide the versions used? I cannot answer with certainty without knowing the versions but this PR (#11274) will most likely correct the behavior. |
version 0.6.8 dup repo https://github.com/gatimus/schematics-merge-strategy |
Could you try with the RC of 0.7? I fixed a lot of issues by reworking the whole Tree implementation, should have fixed a few of those merging issues (amongst others, e.g. branching). |
Dupe of #11246. Let's keep this one for tracking though as it has more information. |
Still duplicating on 0.7.0-rc.3 https://github.com/gatimus/schematics-merge-strategy/tree/RC-0.7 |
This is making me cry 😢 |
Is this already fixed? const templateSource = apply(url('./project-files'), [
template({ ...strings, ...options }),
move(options.path),
forEach((fileEntry: FileEntry) => {
if (host.exists(fileEntry.path)) {
host.overwrite(fileEntry.path, fileEntry.content);
}
return fileEntry;
}),
]); |
Hi, For me, the issue appears after upgrading my schematics "dependencies" from:
to:
Version v0.6.8's @joeson1 : i tried your workaround, but it didn't help 😞 ... |
@joeson1 where do you assign |
@tinesoft I get the exact same behavior with v0.6.8 as with v0.7.3 |
I believe this is the same issue as #12088. I originally commented this on #12088: The issue occurs on HostTree merge. I've detailed the simplified propagation below:
|
I'm still having this issue, in case someone needs to know it's still not fixed. Using version 0.8.6 |
I have the same issue qith |
@egervari and @bautistaaa could you let me know if this workaround works for you? |
As others have stated, this still seems to be an issue... I've reproduced with 0.6.8 and 0.7.2... Based on one of the suggestions in the thread linked by @cgatian, I was able to formulate a workaround for my specific situation... In my method, I was attempting to call move() within the rules array of apply()... Essentially the source url() was a subdirectory of my 'files' directory in my schematic - and the destination in move() was a subdirectory of the project tree. So, I had the schematics source assets in: \schematics\ng-add\files\help\my-help\index.html And I wanted my schematics source assets to be dropped in the projects source directory: \src\help\my-help\index.html. When calling url('./files/help') and move('.', '/src/'), I would get "src/help/my-help/index.html already exists. The Schematic workflow failed." To work around this, I changed my folder structure in my schematics assets to match the project folder structure - so instead of '\schematics\ng-add\files\help....' I used '\schematics\ng-add\files\src\help....'. I then updated url to be "url('./files')" and move to be "move('.')"... So now instead of explicitly setting the URL source as a subfolder containing the assets, it's just using the whole 'files' directory to overlay on top of the root of the project (move('.')). I ran across this workaround when I by chance notice that I only got the 'already exists' error when operating on subfolders of the project - but in my troubleshooting, I realized that things behaved as expected when operating against the root of the project... Here's a sample of my updated method which now works as desired in case it assists: /** Add help assets to application */
// NOTE: work around due to busted MergeStrategy - https://github.com/angular/angular-cli/issues/11337
function addHelpToApplicationRoot(options: Schema) {
return (tree: Tree, context: SchematicContext) => {
context.logger.info(`Adding help assets to application help.`);
const rule = mergeWith(
apply(url('./files'), [
forEach((fileEntry) => {
if (tree.exists(fileEntry.path)) {
tree.overwrite(fileEntry.path, fileEntry.content);
return null;
}
return fileEntry;
}),
move('.')
]),
);
return rule(tree, context);
};
} Seems that the important detail, at least in my case, was to make my 'files' assets be structured in a way that matches the project's folder structure rather than relying on url() and move() to work on specific subfolders. |
@mattezell Thank you for workaround example. However, I'd assume that you don't need this "move('.')" - everything should work even w/o it. |
I have the same problem not using a Source but trying to create/override custom stuff in the Tree. There's no simple way via MergeStrategy to avoid the My hacky intuition thought that using |
I believe this is exactly what |
Hi, I experience the same issue. Setup
Observed behaviour
Versions
Repro Stepsgit clone https://github.com/GregOnNet/merge-strategie-issue.git
cd merge-strategie-issue
npm install
npm test # Everything is fine
npm run build
schematics .:overwrite
# ERROR
ERROR! /.prettierrc already exists.
The Schematic workflow failed. See above. If I can provide any further information, please let me know. 👍 |
- workaorund introduce due angular/angular-cli#11337
- workaorund introduce due angular/angular-cli#11337
Is there any plan to fix this? Any current workarounds? |
@tscislo this is my current workaround: export function overwriteIfExists(host: Tree): Rule {
return forEach(fileEntry => {
if (host.exists(fileEntry.path)) {
host.overwrite(fileEntry.path, fileEntry.content);
return null;
}
return fileEntry;
});
}
export function mySchematic(options: MyOptions): Rule {
return (host: Tree, context: SchematicContext) => {
/* ...logic... */
const templateSource = apply(
url('./files'),
[
template({
...strings,
...options
}),
move(options.path),
options.overwrite ? overwriteIfExists(host) : noop()
]
);
return mergeWith(templateSource);
};
} derived from other variations in answers here https://stackoverflow.com/questions/48957132/how-to-overwrite-file-with-angular-schematics |
For me even workarounds did not work. |
A note about the workaround using manual forEach and overwrite. |
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes angular#11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This fixes #11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Re-post of angular/devkit#745
Bug Report or Feature Request (mark with an
x
)Area
Versions
Node v8.11.1
NPM 5.8.0
Mac OS High Sierra
Repro steps
Use the following schematic
The log given by the failure
Desired functionality
All files should be overwritten.
Mention any other details that might be useful
I tried every MergeStrategy possible (AllowOverwriteConflict, etc.), same result.
angular/devkit#745
https://stackoverflow.com/questions/48957132/how-to-overwrite-file-with-angular-schematics
The text was updated successfully, but these errors were encountered: