Skip to content

Commit

Permalink
refactor(middleware): get rid of util.format (#3160)
Browse files Browse the repository at this point in the history
  • Loading branch information
lusarz authored and johnjbarton committed Oct 3, 2018
1 parent 18a750d commit 637b553
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

const path = require('path')
const util = require('util')
const url = require('url')
const _ = require('lodash')

Expand All @@ -28,10 +27,6 @@ function urlparse (urlStr) {
const common = require('./common')

const VERSION = require('../constants').VERSION
const SCRIPT_TAG = '<script type="%s" src="%s" %s></script>'
const CROSSORIGIN_ATTRIBUTE = 'crossorigin="anonymous"'
const LINK_TAG_CSS = '<link type="text/css" href="%s" rel="stylesheet">'
const LINK_TAG_HTML = '<link href="%s" rel="import">'
const SCRIPT_TYPE = {
'js': 'text/javascript',
'dart': 'application/dart',
Expand Down Expand Up @@ -202,21 +197,21 @@ function createKarmaMiddleware (
scriptUrls.push(filePath)

if (fileType === 'css' || (!fileType && fileExt === '.css')) {
scriptTags.push(util.format(LINK_TAG_CSS, filePath))
scriptTags.push(`<link type="text/css" href="${filePath}" rel="stylesheet">`)
continue
}

if (fileType === 'html' || (!fileType && fileExt === '.html')) {
scriptTags.push(util.format(LINK_TAG_HTML, filePath))
scriptTags.push(`<link href="${filePath}" rel="import">`)
continue
}

// The script tag to be placed
const scriptFileType = (fileType || fileExt.substring(1))
const scriptType = (SCRIPT_TYPE[scriptFileType] || 'text/javascript')

const crossOriginAttribute = includeCrossOriginAttribute ? CROSSORIGIN_ATTRIBUTE : ''
scriptTags.push(util.format(SCRIPT_TAG, scriptType, filePath, crossOriginAttribute))
const crossOriginAttribute = includeCrossOriginAttribute ? 'crossorigin="anonymous"' : ''
scriptTags.push(`<script type="${scriptType}" src="${filePath}" ${crossOriginAttribute}></script>`)
}

// TODO(vojta): don't compute if it's not in the template
Expand All @@ -227,7 +222,7 @@ function createKarmaMiddleware (
// double quotes should not be allowed!
filePath = filePath.replace(/'/g, '\\\'')

return util.format(" '%s': '%s'", filePath, file.sha)
return ` '${filePath}': '${file.sha}'`
})

const clientConfig = 'window.__karma__.config = ' + JSON.stringify(client) + ';\n'
Expand Down

0 comments on commit 637b553

Please sign in to comment.