Don't break when options._flags is undefined entirely

pull/2/head
Sven Slootweg 4 years ago
parent 92bcf4fdca
commit 3efa28c9f1

@ -18,7 +18,7 @@ module.exports = function (state) {
let allCss = ""; let allCss = "";
let loaderItem; let loaderItem;
let entryPoint = (options._flags.entries != null) let entryPoint = (options._flags != null && options._flags.entries != null)
// Get the (absolute!) path of the folder containing the initial entry file, as a reference point for relative paths in the output // Get the (absolute!) path of the folder containing the initial entry file, as a reference point for relative paths in the output
? path.dirname(path.resolve(options._flags.entries[0])) ? path.dirname(path.resolve(options._flags.entries[0]))
// ... or, if no entry file is specified, go off the current working directory // ... or, if no entry file is specified, go off the current working directory
@ -27,13 +27,13 @@ module.exports = function (state) {
return stream((item) => { return stream((item) => {
// And the same for the loader shim path. All this relative-path stuff is to prevent absolute filesystem URLs from leaking into the output, as those might contain sensitive information. // And the same for the loader shim path. All this relative-path stuff is to prevent absolute filesystem URLs from leaking into the output, as those might contain sensitive information.
let relativeLoaderPath = path.relative(path.dirname(item.file), loaderShimPath); let relativeLoaderPath = path.relative(path.dirname(item.file), loaderShimPath);
if (isCss(item)) { if (isCss(item)) {
return Promise.try(() => { return Promise.try(() => {
return processFile(item); return processFile(item);
}).then(({ result, icssExports }) => { }).then(({ result, icssExports }) => {
allCss += `/* from ${path.relative(entryPoint, item.file)} */\n\n${result.css}\n\n`; allCss += `/* from ${path.relative(entryPoint, item.file)} */\n\n${result.css}\n\n`;
if (!item.__icssify__discardable) { if (!item.__icssify__discardable) {
return { return {
... item, ... item,
@ -56,6 +56,7 @@ module.exports = function (state) {
source: loaderItem.source.replace('"## CONTENT MARKER ##"', JSON.stringify(allCss)) source: loaderItem.source.replace('"## CONTENT MARKER ##"', JSON.stringify(allCss))
}; };
} else { } else {
// FIXME: Can occur if some dependency also gets processed and require()s a CSS file, but does not specify icssify as a transform (but the using project does) -- like with ui-lib + site-builder
throw new Error("Processed CSS, but global loader was not encountered. This should never happen, please report it as a bug!"); throw new Error("Processed CSS, but global loader was not encountered. This should never happen, please report it as a bug!");
} }
} }

Loading…
Cancel
Save