@swissup/pwa-easy-slide
Version:
Easy slide(r) integration into venia-ui
53 lines (44 loc) • 1.64 kB
JavaScript
const SECURITY_HEADER_DEFINITION = 'veniaSecurityHeaders';
const EXTENSION_DEFINITION = 'swissupEasySlideSecurityHeaders';
module.exports = targets => {
const builtins = targets.of('@magento/pwa-buildpack');
builtins.specialFeatures.tap(flags => {
flags[targets.name] = {
upward: true,
esModules: true,
cssModules: true,
i18n: true
};
});
targets
.of('@magento/pagebuilder')
.customContentTypes.tap(contentTypes => {
contentTypes.add({
contentType: 'EasySlider',
importPath: require.resolve(
"../lib/components/ContentTypes/EasySlider/index.js"
)
});
});
builtins.transformUpward.tapPromise(async definitions => {
if (!definitions[SECURITY_HEADER_DEFINITION]
|| !definitions[EXTENSION_DEFINITION]
) {
throw new Error(
`${
targets.name
} could not find its own definition in the emitted upward.yml`
);
}
const csp = definitions[SECURITY_HEADER_DEFINITION]
.inline['content-security-policy'].template;
const fixes = definitions[EXTENSION_DEFINITION]
.inline['content-security-policy'].template.default.fixes;
for (const fix of fixes) {
csp.default.inline = csp.default.inline.replace(fix.from, fix.to);
for (const match of csp.when) {
match.use.inline = match.use.inline.replace(fix.from, fix.to);
}
}
});
}