Skip to content

Commit 91ffe12

Browse files
Copilotfgreinacher
andcommitted
Simplify template expansion to always apply templates
Co-authored-by: fgreinacher <[email protected]>
1 parent 9698daf commit 91ffe12

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

lib/publish.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,40 +56,42 @@ export default async (pluginConfig, context) => {
5656
debug("milestones: %o", milestones);
5757

5858
if (assets && assets.length > 0) {
59-
// Apply template expansion to assets BEFORE globbing, but only when templates are present
60-
const needsTemplateExpansion = (str) => str && typeof str === 'string' && str.includes('${');
61-
59+
// Apply template expansion to assets BEFORE globbing (original approach but moved before)
6260
const templatedAssets = assets.map((asset) => {
6361
if (isPlainObject(asset)) {
6462
const templatedAsset = { ...asset };
65-
if (asset.path && needsTemplateExpansion(asset.path)) {
66-
templatedAsset.path = template(asset.path)(context);
63+
if (asset.path) {
64+
if (Array.isArray(asset.path)) {
65+
templatedAsset.path = asset.path.map(pattern => template(pattern)(context));
66+
} else {
67+
templatedAsset.path = template(asset.path)(context);
68+
}
6769
}
68-
if (asset.url && needsTemplateExpansion(asset.url)) {
70+
if (asset.url) {
6971
templatedAsset.url = template(asset.url)(context);
7072
}
71-
if (asset.label && needsTemplateExpansion(asset.label)) {
73+
if (asset.label) {
7274
templatedAsset.label = template(asset.label)(context);
7375
}
74-
if (asset.type && needsTemplateExpansion(asset.type)) {
76+
if (asset.type) {
7577
templatedAsset.type = template(asset.type)(context);
7678
}
77-
if (asset.filepath && needsTemplateExpansion(asset.filepath)) {
79+
if (asset.filepath) {
7880
templatedAsset.filepath = template(asset.filepath)(context);
7981
}
80-
if (asset.target && needsTemplateExpansion(asset.target)) {
82+
if (asset.target) {
8183
templatedAsset.target = template(asset.target)(context);
8284
}
83-
if (asset.status && needsTemplateExpansion(asset.status)) {
85+
if (asset.status) {
8486
templatedAsset.status = template(asset.status)(context);
8587
}
8688
return templatedAsset;
8789
} else if (Array.isArray(asset)) {
88-
// Handle array of glob patterns - only apply templates if needed
89-
return asset.map(pattern => needsTemplateExpansion(pattern) ? template(pattern)(context) : pattern);
90+
// Handle array of glob patterns
91+
return asset.map(pattern => template(pattern)(context));
9092
} else {
91-
// String asset path - only apply template if needed
92-
return needsTemplateExpansion(asset) ? template(asset)(context) : asset;
93+
// String asset path
94+
return template(asset)(context);
9395
}
9496
});
9597

@@ -106,16 +108,13 @@ export default async (pluginConfig, context) => {
106108

107109
await Promise.all(
108110
allAssets.map(async (asset) => {
109-
// Templates may have been expanded before globbing, but we need to handle remaining cases
110-
const needsTemplateExpansion = (str) => str && typeof str === 'string' && str.includes('${');
111-
112111
const path = isPlainObject(asset) ? asset.path : asset;
113-
const _url = asset.url ? (needsTemplateExpansion(asset.url) ? template(asset.url)(context) : asset.url) : undefined;
114-
const label = asset.label ? (needsTemplateExpansion(asset.label) ? template(asset.label)(context) : asset.label) : undefined;
115-
const type = asset.type ? (needsTemplateExpansion(asset.type) ? template(asset.type)(context) : asset.type) : undefined;
116-
const filepath = asset.filepath ? (needsTemplateExpansion(asset.filepath) ? template(asset.filepath)(context) : asset.filepath) : undefined;
117-
const target = asset.target ? (needsTemplateExpansion(asset.target) ? template(asset.target)(context) : asset.target) : undefined;
118-
const status = asset.status ? (needsTemplateExpansion(asset.status) ? template(asset.status)(context) : asset.status) : undefined;
112+
const _url = asset.url;
113+
const label = asset.label;
114+
const type = asset.type;
115+
const filepath = asset.filepath;
116+
const target = asset.target;
117+
const status = asset.status;
119118

120119
if (_url) {
121120
assetsList.push({ label, rawUrl: _url, type, filepath });

0 commit comments

Comments
 (0)