From 31a1b4c8aa63b65e022ca98075ac1bdd0e1e1439 Mon Sep 17 00:00:00 2001 From: Ryo Armanda Date: Fri, 2 Apr 2021 00:16:39 +0800 Subject: [PATCH] Correctly process incomplete active urls to refer to index files --- packages/cli/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/cli/index.js b/packages/cli/index.js index a8ff64ebf9..bd4b1e706e 100755 --- a/packages/cli/index.js +++ b/packages/cli/index.js @@ -141,7 +141,10 @@ program const addHandler = (filePath) => { logger.info(`[${new Date().toLocaleTimeString()}] Reload for file add: ${filePath}`); logger.info('Synchronizing opened pages list before reload'); - const normalizedActiveUrls = liveServer.getActiveUrls().map(url => fsUtil.removeExtension(url)); + const normalizedActiveUrls = liveServer.getActiveUrls().map((url) => { + const completeUrl = path.extname(url) === '' ? path.join(url, 'index') : url; + return fsUtil.removeExtension(completeUrl); + }); site.changeCurrentOpenedPages(normalizedActiveUrls); Promise.resolve('').then(() => { if (site.isFilepathAPage(filePath) || site.isDependencyOfPage(filePath)) { @@ -156,7 +159,10 @@ program const changeHandler = (filePath) => { logger.info(`[${new Date().toLocaleTimeString()}] Reload for file change: ${filePath}`); logger.info('Synchronizing opened pages list before reload'); - const normalizedActiveUrls = liveServer.getActiveUrls().map(url => fsUtil.removeExtension(url)); + const normalizedActiveUrls = liveServer.getActiveUrls().map((url) => { + const completeUrl = path.extname(url) === '' ? path.join(url, 'index') : url; + return fsUtil.removeExtension(completeUrl); + }); site.changeCurrentOpenedPages(normalizedActiveUrls); Promise.resolve('').then(() => { if (path.basename(filePath) === SITE_CONFIG_NAME) { @@ -174,7 +180,10 @@ program const removeHandler = (filePath) => { logger.info(`[${new Date().toLocaleTimeString()}] Reload for file deletion: ${filePath}`); logger.info('Synchronizing opened pages list before reload'); - const normalizedActiveUrls = liveServer.getActiveUrls().map(url => fsUtil.removeExtension(url)); + const normalizedActiveUrls = liveServer.getActiveUrls().map((url) => { + const completeUrl = path.extname(url) === '' ? path.join(url, 'index') : url; + return fsUtil.removeExtension(completeUrl); + }); site.changeCurrentOpenedPages(normalizedActiveUrls); Promise.resolve('').then(() => { if (site.isFilepathAPage(filePath) || site.isDependencyOfPage(filePath)) {