Skip to content

Commit ae08ce7

Browse files
committed
chore: 🤖 update
1 parent 0f73904 commit ae08ce7

File tree

14 files changed

+384
-426
lines changed

14 files changed

+384
-426
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A clear and concise description of what you expected to happen.
2222

2323
**Environment (please complete the following information):**
2424

25-
- @hyperse/ts-node version:
25+
- @hyperse/html-webpack-plugin-loader version:
2626
- Nodejs version
2727

2828
**Additional context**

.github/workflows/ci-integrity.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
runs-on: ubuntu-latest
4444
strategy:
4545
matrix:
46-
node-version: [18.x]
46+
node-version: [20.x]
4747
steps:
4848
- uses: actions/checkout@v4
4949

.github/workflows/release-or-version-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
# @link https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
2020
fetch-depth: 0
2121

22-
- name: Use Node.js 18.x
22+
- name: Use Node.js 20.x
2323
uses: actions/setup-node@v4
2424
with:
25-
node-version: 18.x
25+
node-version: 20.x
2626

2727
- name: 📥 Install Dependencies
2828
run: yarn --frozen-lockfile

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"name": "Debug Test File",
1111
"runtimeExecutable": "npm",
1212
"runtimeArgs": ["run-script", "test-unit"],
13-
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
13+
"skipFiles": ["<node_internals>/**"],
1414
"args": ["${relativeFile}"],
1515
"env": {}
1616
}

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
"type": "module",
1818
"exports": {
1919
"./loader": {
20-
"import": "./dist/loader/loader.js"
20+
"import": "./dist/loader/htmlLoader.cjs"
2121
},
2222
".": {
2323
"types": "./dist/index.d.ts",
24-
"require": "./dist/index.cjs",
2524
"import": "./dist/index.js"
2625
},
2726
"./package.json": "./package.json"
@@ -53,7 +52,6 @@
5352
}
5453
},
5554
"dependencies": {
56-
"loader-utils": "^3.3.1",
5755
"parse5": "^7.3.0"
5856
},
5957
"devDependencies": {
@@ -64,12 +62,11 @@
6462
"@hyperse/eslint-config-hyperse": "^1.4.5",
6563
"@hyperse/ts-node": "^1.0.3",
6664
"@types/loader-runner": "^2.2.8",
67-
"@types/loader-utils": "^2.0.6",
6865
"@types/node": "^24.0.1",
6966
"commitizen": "^4.3.1",
7067
"cz-conventional-changelog": "^3.3.0",
7168
"eslint": "^9.28.0",
72-
"execa": "^9.6.0",
69+
"html-webpack-plugin": "^5.6.3",
7370
"husky": "^9.1.7",
7471
"lint-staged": "^16.1.0",
7572
"loader-runner": "^4.3.0",

scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function buildAll() {
2828
external: externals,
2929
outExtension() {
3030
return {
31-
js: `.js`,
31+
js: `.cjs`,
3232
};
3333
},
3434
},

src/loader/htmlLoader.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
import { getOptions } from 'loader-utils';
21
import type { LoaderContext } from 'webpack';
2+
import { parseTemplate } from '../parser/parseTemplate.js';
33

44
// Define the loader options type
55
interface LoaderOptions {
6-
transform?: boolean;
7-
// Add more option types as needed
6+
title?: string;
7+
favicon?: string;
8+
headMetaTags?: string[];
9+
headStyles?: string[];
10+
headScripts?: string[];
11+
headInlineScripts?: string[];
12+
bodyScripts?: string[];
13+
bodyInlineScripts?: string[];
814
}
915

1016
export default function htmlLoader(
1117
this: LoaderContext<LoaderOptions>,
1218
source: string
1319
): string {
1420
// Get and validate options
15-
const options = getOptions(this) as LoaderOptions;
21+
const options = this.getOptions;
1622

17-
// Get the resource path
23+
// Skip .js files (unless it's explicitly enforced)
1824
if (!/\.html$/.test(this.resourcePath)) {
1925
return source;
2026
}
2127

2228
// Example transformation
23-
let transformedSource = source;
24-
if (options.transform) {
25-
// Add your transformation logic here
26-
transformedSource = source.toUpperCase(); // Example transformation
27-
}
29+
const transformedSource = parseTemplate(source);
2830

2931
// You can use this.emitFile to emit additional files
3032
// this.emitFile('output.txt', 'Some content');
@@ -33,5 +35,5 @@ export default function htmlLoader(
3335
// this.callback(null, transformedSource, sourceMap, meta);
3436

3537
// Return the transformed source
36-
return `module.exports.default = module.exports = ${JSON.stringify(transformedSource)}`;
38+
return `export default ${JSON.stringify(transformedSource)}`;
3739
}

tests/fixtures/basic/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = 'common';

tests/fixtures/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
<meta name="apple-mobile-web-app-status-bar-style" content="black">
1515
<meta name="viewport"
1616
content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover">
17-
<title></title>
18-
<script></script>
19-
<script>!function (e) { var t, n = 1, i = 1; !function (r, o) { var a = e.document, c = a.documentElement, u = navigator.userAgent.toLowerCase().indexOf("android") > -1; (i = e.devicePixelRatio || 1) > 3 && (i = 3), u && (i = 1), console.log("current devicePixelRatio:", i), c.setAttribute("data-dpr", i.toString()); var d, l = a.querySelector('meta[name="viewport"]'); function m() { var e = document.documentElement.clientWidth; t = e / o * (r / i) * i, a.documentElement.style.fontSize = String(t) + "px" } l || (n = 1 / i, (l = a.createElement("meta")).setAttribute("name", "viewport"), a.head.appendChild(l), l.setAttribute(["content", "width=device-width,user-scalable=no,initial-scale=", n, ",maximum-scale=", n, ",minimum-scale=", n].join(""))), e.addEventListener("resize", (function () { clearTimeout(d), d = setTimeout(m, 300) }), !1), e.addEventListener("onload", m, !1), m() }(100, 750), window.fabricViewport = { currRem: t, currDpr: i, currScale: n, dpiPX2px: function (e) { return parseFloat(e.toString()) / t * 100 + "px" }, px2DPIpx: function (e) { return parseFloat(e.toString()) / 100 * t + "px" }, px2rem: function (e) { return parseFloat(e.toString()) / 100 + "rem" } } }(window)</script>
2017
</head>
2118

2219
<body>

tests/htmlLoader.test.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
// import fs from 'fs';
1+
import fs from 'fs';
22
import { describe, expect, it } from 'vitest';
3-
// import { testLoader } from './testLoader.js';
4-
// import { getDirname } from './testUtils.js';
3+
import { getDirname, testLoader } from './testUtils.js';
54

65
describe('htmlLoader', () => {
7-
it('should return the correct html', () => {
8-
// const result = testLoader({
9-
// resource: './test.txt',
10-
// loaders: [getDirname(import.meta.url, '../dist/loader/htmlLoader.cjs')],
11-
// context: {
12-
// loaderOptions: {
13-
// /* options */
14-
// },
15-
// },
16-
// readResource: fs.readFile.bind(fs),
17-
// });
18-
expect(true).toBe(true);
6+
it('should return the correct html', async () => {
7+
const result = await testLoader({
8+
resource: getDirname(import.meta.url, './fixtures/index.html'),
9+
loaders: [getDirname(import.meta.url, '../dist/loader/htmlLoader.cjs')],
10+
context: {
11+
loaderOptions: {
12+
/* options */
13+
},
14+
},
15+
readResource: fs.readFile.bind(fs),
16+
});
17+
expect(result).toBe(true);
1918
});
2019
});

0 commit comments

Comments
 (0)