diff --git a/lib/assets.js b/lib/assets.js index fc1e9c31..218a3dfe 100644 --- a/lib/assets.js +++ b/lib/assets.js @@ -20,6 +20,7 @@ const Assets = { const { inline, reportData, + jsFiles, assetsPath, outputDir, htmlFile, @@ -44,9 +45,11 @@ const Assets = { const jsList = []; // deps - jsList.push({ - filename: 'monocart-coverage-app.js', - str: Assets.getFileContent('monocart-coverage-app') + jsFiles.forEach((id) => { + jsList.push({ + filename: `${id}.js`, + str: Assets.getFileContent(id) + }); }); // html content diff --git a/lib/v8/v8.js b/lib/v8/v8.js index 65c3b607..9a76f16a 100644 --- a/lib/v8/v8.js +++ b/lib/v8/v8.js @@ -352,10 +352,12 @@ const handleV8HtmlReport = async (reportData, reportOptions, options) => { const outputDir = path.dirname(reportPath); const htmlFile = path.basename(reportPath); + const jsFiles = ['monocart-coverage-app']; // console.log(jsFiles); const htmlOptions = { reportData, + jsFiles, inline, assetsPath, outputDir, diff --git a/package.json b/package.json index 3944a668..c403a457 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "istanbul-lib-coverage": "^3.2.2", "istanbul-lib-report": "^3.0.1", "istanbul-reports": "^3.1.7", - "lz-utils": "^2.0.2", + "lz-utils": "^2.1.0", "minimatch": "9.0.5", "monocart-locator": "^1.0.2" }, diff --git a/packages/loader/package.json b/packages/loader/package.json deleted file mode 100644 index 5bb222f3..00000000 --- a/packages/loader/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "monocart-coverage-loader", - "version": "2.9.3", - "private": true, - "main": "dist/monocart-coverage-loader.js", - "files": [ - "dist" - ], - "license": "MIT", - "dependencies": {}, - "devDependencies": {} -} diff --git a/packages/loader/src/index.js b/packages/loader/src/index.js deleted file mode 100644 index ad2148e9..00000000 --- a/packages/loader/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import inflate from 'lz-utils/inflate'; -const compressed = '{compressed_placeholder}'; -inflate(compressed).then((res) => { - const script = document.createElement('script'); - script.innerHTML = res; - document.body.appendChild(script); -}); diff --git a/scripts/conf.cli.js b/scripts/conf.cli.js index 45880eb8..f0aeaa0d 100644 --- a/scripts/conf.cli.js +++ b/scripts/conf.cli.js @@ -58,7 +58,7 @@ const copyVendor = (EC, toPath) => { }; const buildAssets = (EC, toPath) => { - const { deflateSync } = require('lz-utils'); + const { createScriptLoader } = require('lz-utils'); const toJs = path.resolve(toPath, 'monocart-coverage-assets.js'); @@ -78,16 +78,8 @@ const buildAssets = (EC, toPath) => { if (!fs.existsSync(appPath)) { return; } - const loaderPath = path.resolve(__dirname, '../packages/loader/dist/monocart-coverage-loader.js'); - if (!fs.existsSync(loaderPath)) { - return; - } - const appContent = fs.readFileSync(appPath).toString('utf-8'); - const loaderContent = fs.readFileSync(loaderPath).toString('utf-8'); - - return loaderContent.replace('{compressed_placeholder}', deflateSync(appContent)); - + return createScriptLoader(appContent); } }]; diff --git a/test/package.json b/test/package.json index 76c6e650..7ab13104 100644 --- a/test/package.json +++ b/test/package.json @@ -19,7 +19,7 @@ "mocha": "^10.7.0", "open": "^10.1.0", "playwright": "^1.45.3", - "puppeteer": "^22.13.1", + "puppeteer": "^22.14.0", "rollup": "^4.19.0", "swc-loader": "^0.2.6", "ts-loader": "^9.5.1", diff --git a/test/test-merge.js b/test/test-merge.js index 0d107ff6..be111b39 100644 --- a/test/test-merge.js +++ b/test/test-merge.js @@ -15,6 +15,8 @@ const coverageOptions = { 'v8' ], + inline: true, + // merge from exists raw dirs inputDir: './docs/node-vm/raw, ./docs/cli/raw, ./wrong-raw-dir',