Skip to content
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

fix id checking #1496

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Changes from 2 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
25 changes: 14 additions & 11 deletions packages/creator/src/createItemTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,30 +550,33 @@ export function _templatizeResources(
let dataString = JSON.stringify(fileJson);
if (fileJson && idTest.test(dataString)) {
const ids: string[] = dataString.match(idTest) as string[];
const verifiedIds: string[] = [];
const promises = [];
const idLookup = [];
ids.forEach((id) => {
idLookup.push(id);
if (verifiedIds.indexOf(id) === -1) {
verifiedIds.push(id);
if (idLookup.indexOf(id) === -1) {
idLookup.push(id);
promises.push(isItem(id, srcAuthentication));
idLookup.push(id);
promises.push(isGroup(id, srcAuthentication));
}
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
Promise.all(promises).then((results) => {
const verifiedIds = [];
results.forEach((isValid, i) => {
if (isValid) {
const id: string = idLookup[i];
// templatize the itemId--but only once per unique id
const regEx = new RegExp(id, "gm");
dataString = dataString.replace(regEx, "{{" + id + ".itemId}}");

// update the dependencies
if (itemTemplate.dependencies.indexOf(id) === -1) {
itemTemplate.dependencies.push(id);
if (verifiedIds.indexOf(id) < 0 && id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can id be zero?
  • How about checking it before looking it up in verifiedIds?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be an item id string

// templatize the itemId--but only once per unique id
const regEx = new RegExp(id, "gm");
dataString = dataString.replace(regEx, "{{" + id + ".itemId}}");

// update the dependencies
if (itemTemplate.dependencies.indexOf(id) === -1) {
itemTemplate.dependencies.push(id);
}
verifiedIds.push(id);
}
}
});
Expand Down
Loading