Skip to content

Commit f3d9271

Browse files
committed
fix: resolve issues #1, #2, #3
- Fix #1: Move deps to dependencies - Fix #2: Use node:path for cross-platform - Fix #3: Recursive traversal (already fixed)
1 parent 20a645f commit f3d9271

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@
3535
"prepublishOnly": "pnpm build",
3636
"release": "release-it"
3737
},
38+
"dependencies": {
39+
"html-minifier-terser": "^7.2.0",
40+
"lightningcss": "^1.30.2"
41+
},
3842
"devDependencies": {
3943
"@antfu/eslint-config": "^6.2.0",
4044
"@types/html-minifier-terser": "^7.0.2",
4145
"@types/node": "^24.9.2",
4246
"astro": "^5.15.3",
4347
"eslint": "^9.18.0",
44-
"html-minifier-terser": "^7.2.0",
45-
"lightningcss": "^1.28.2",
4648
"release-it": "^19.0.5",
4749
"tsdown": "^0.15.12",
4850
"typescript": "^5.9.3",

src/single-file-builder.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { FileInfo, FileSystemAdapter, SingleFileConfig } from './types'
2+
import * as path from 'node:path'
23
import { minify } from 'html-minifier-terser'
34
import { CssInliner } from './css-inliner'
45
import { CssTransformer } from './css-transformer'
@@ -9,7 +10,7 @@ export class SingleFileBuilder {
910
constructor(private fs: FileSystemAdapter) {}
1011

1112
async build(buildDir: string, config: SingleFileConfig): Promise<void> {
12-
const folder = buildDir.endsWith('/') ? buildDir : `${buildDir}/`
13+
const folder = buildDir
1314

1415
// Find all files recursively
1516
const files = this.findAllFiles(folder)
@@ -55,7 +56,7 @@ export class SingleFileBuilder {
5556

5657
// Delete empty folders
5758
this.fs.readDir(folder).forEach((f) => {
58-
const file = `${folder}${f}`
59+
const file = path.join(folder, f)
5960
try {
6061
const stats = this.fs.stat(file)
6162
if (stats.isDirectory() && this.fs.readDir(file).length === 0) {
@@ -70,14 +71,14 @@ export class SingleFileBuilder {
7071

7172
private findAllFiles(folder: string): string[] {
7273
return this.fs.readDir(folder).reduce<string[]>((acc, f) => {
73-
const file = `${folder}${f}`
74+
const file = path.join(folder, f)
7475
const stats = this.fs.stat(file)
7576

7677
if (stats.isFile()) {
7778
acc.push(file)
7879
}
7980
else if (stats.isDirectory()) {
80-
acc = acc.concat(this.findAllFiles(`${file}/`))
81+
acc = acc.concat(this.findAllFiles(file))
8182
}
8283

8384
return acc
@@ -87,10 +88,10 @@ export class SingleFileBuilder {
8788
private openFiles(files: string[], fileType: 'html' | 'css'): FileInfo[] {
8889
return files
8990
.filter(i => i.endsWith(`.${fileType}`))
90-
.map(path => ({
91-
contents: this.fs.readFile(path, 'utf8'),
92-
path,
93-
fileName: path.split('/').pop()!,
91+
.map(filePath => ({
92+
contents: this.fs.readFile(filePath, 'utf8'),
93+
path: filePath,
94+
fileName: path.basename(filePath),
9495
}))
9596
}
9697
}

test/integration/astro-island.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
2-
import type { TransformOptions } from 'lightningcss'
3-
import { Buffer } from 'node:buffer'
41
import * as fs from 'node:fs'
5-
import * as path from 'node:path'
62
import * as os from 'node:os'
3+
import * as path from 'node:path'
4+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
75
import { NodeFileSystemAdapter } from '../../src/file-system-adapter'
86
import { SingleFileBuilder } from '../../src/single-file-builder'
97

10-
describe('Astro Island Support', () => {
8+
describe('astro Island Support', () => {
119
let tmpDir: string
1210
let adapter: NodeFileSystemAdapter
1311
let builder: SingleFileBuilder
@@ -121,9 +119,8 @@ describe('Astro Island Support', () => {
121119

122120
await builder.build(tmpDir, {})
123121

124-
const result = fs.readFileSync(htmlPath, 'utf8')
125-
126122
// Future: could inline JS as base64
123+
// const result = fs.readFileSync(htmlPath, 'utf8')
127124
// expect(result).toContain('data:text/javascript;base64,')
128125

129126
// For now, just verify JS file is preserved

0 commit comments

Comments
 (0)