1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/webpack-dev-server/lib/utils/runOpen.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
'use strict';
const open = require('opn');
const isAbsoluteUrl = require('is-absolute-url');
function runOpen(uri, options, log) {
// https://github.com/webpack/webpack-dev-server/issues/1990
let openOptions = { wait: false };
2024-01-16 21:26:16 +08:00
let openOptionValue = '';
2023-12-18 13:12:25 +08:00
if (typeof options.open === 'string') {
openOptions = Object.assign({}, openOptions, { app: options.open });
2024-01-16 21:26:16 +08:00
openOptionValue = `: "${options.open}"`;
} else if (typeof options.open === 'object') {
openOptions = options.open;
openOptionValue = `: "${JSON.stringify(options.open)}"`;
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
const pages =
typeof options.openPage === 'string'
? [options.openPage]
: options.openPage || [''];
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
return Promise.all(
pages.map((page) => {
const pageUrl = page && isAbsoluteUrl(page) ? page : `${uri}${page}`;
return open(pageUrl, openOptions).catch(() => {
log.warn(
`Unable to open "${pageUrl}" in browser${openOptionValue}. If you are running in a headless environment, please do not use the --open flag`
);
});
})
);
2023-12-18 13:12:25 +08:00
}
module.exports = runOpen;