Skip to content

Commit 8f6181f

Browse files
authored
chore(workflow): use local report template when dev (#958)
* chore(workflow): config ts default formatter * chore(workflow): enable generate report when dev
1 parent 0dd6910 commit 8f6181f

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
"[jsonc]": {
3030
"editor.defaultFormatter": "biomejs.biome"
3131
},
32+
"[json]": {
33+
"editor.defaultFormatter": "biomejs.biome"
34+
},
35+
"[typescript]": {
36+
"editor.defaultFormatter": "biomejs.biome"
37+
},
3238
"[plaintext]": {
3339
"editor.defaultFormatter": "esbenp.prettier-vscode"
3440
},

packages/core/modern.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'node:path';
12
import { defineConfig, moduleTools } from '@modern-js/module-tools';
23
import { version } from './package.json';
34

@@ -15,6 +16,9 @@ export default defineConfig({
1516
target: 'es2020',
1617
define: {
1718
__VERSION__: version,
19+
__DEV_REPORT_PATH__: process.env.USE_DEV_REPORT
20+
? path.resolve(__dirname, '../../apps/report/dist/index.html')
21+
: '',
1822
},
1923
splitting: true,
2024
sourceMap: true,

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"scripts": {
2626
"dev": "npm run build:watch",
2727
"build": "modern build",
28-
"build:watch": "modern build -w --no-clear",
28+
"build:watch": "USE_DEV_REPORT=1 modern build -w --no-clear",
2929
"new": "modern new",
3030
"upgrade": "modern upgrade",
3131
"test": "vitest --run",

packages/core/src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ export const groupedActionDumpFileExt = 'web-dump.json';
2525

2626
const reportInitializedMap = new Map<string, boolean>();
2727

28+
declare const __DEV_REPORT_PATH__: string;
29+
2830
function getReportTpl() {
31+
if (__DEV_REPORT_PATH__) {
32+
return fs.readFileSync(__DEV_REPORT_PATH__, 'utf-8');
33+
}
2934
const reportTpl = 'REPLACE_ME_WITH_REPORT_HTML';
3035

3136
return reportTpl;
@@ -52,7 +57,7 @@ export function insertScriptBeforeClosingHtml(
5257
const tailStr = buffer.toString('utf8');
5358
const htmlEndIdx = tailStr.lastIndexOf(htmlEndTag);
5459
if (htmlEndIdx === -1) {
55-
throw new Error('No </html> found');
60+
throw new Error(`No </html> found in file:${filePath}`);
5661
}
5762

5863
// calculate the correct byte position: char position to byte position

0 commit comments

Comments
 (0)