plop
plop copied to clipboard
Escape special characters in append unique actions
This PR was originally made by @soulfresh in the node-plop dedicated repo and moved over by hand to me: https://github.com/plopjs/node-plop/pull/207
What does this PR do?
Updates the append action to escape special characters in the replacement text when using the unique configuration.
Resolves https://github.com/plopjs/plop/issues/275.
Here is the failing scenario:
// index.js template
/* PLOP_INJECT_EXPORT */
export * from './foo';
// plopfile.js action definition
ACTION: {
type: 'append',
data: {},
path: indexFilePath,
template: "export * from './foo';",
pattern: '/* PLOP_INJECT_EXPORT */',
unique: true,
}
// index.js file result
/* PLOP_INJECT_EXPORT */
export * from './foo';
export * from './foo';
This PR ensures the duplicates don't end up in the output.
Relates to https://github.com/plopjs/plop/issues/174