mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-11 17:50:01 -06:00
* chore: use import type across repo * chore: use import type across repo * chore: use import type across repo * chore: use import type across repo * update exports * update test * update import type * update types * use import type in driver * correctly export function * revert test * remove unrelated code * revert code * improve type imports * override for reporter
33 lines
946 B
TypeScript
33 lines
946 B
TypeScript
import RewritingStream from 'parse5-html-rewriting-stream'
|
|
import * as htmlRules from './html-rules'
|
|
import type stream from 'stream'
|
|
import type { DeferSourceMapRewriteFn } from './js'
|
|
|
|
// the HTML rewriter passes inline JS to the JS rewriter, hence
|
|
// the lack of basic `rewriteHtml` or `HtmlRewriter` exports here
|
|
|
|
export function HtmlJsRewriter (url: string, deferSourceMapRewrite?: DeferSourceMapRewriteFn): stream.Transform {
|
|
const rewriter = new RewritingStream()
|
|
|
|
htmlRules.install(url, rewriter, deferSourceMapRewrite)
|
|
|
|
return rewriter
|
|
}
|
|
|
|
export function rewriteHtmlJs (url: string, html: string, deferSourceMapRewrite?: DeferSourceMapRewriteFn): Promise<string> {
|
|
let out = ''
|
|
const rewriter = HtmlJsRewriter(url, deferSourceMapRewrite)
|
|
|
|
rewriter.on('data', (chunk) => {
|
|
out += chunk
|
|
})
|
|
|
|
rewriter.end(html)
|
|
|
|
return new Promise<string>((resolve) => {
|
|
rewriter.on('end', () => {
|
|
resolve(out)
|
|
})
|
|
})
|
|
}
|