diff --git a/dist/esbuild-plugin.js b/dist/esbuild-plugin.js index ed1e014..1f48a81 100644 --- a/dist/esbuild-plugin.js +++ b/dist/esbuild-plugin.js @@ -55,14 +55,13 @@ const hanamiEsbuild = (options) => { // To this: // // { - // 'public/assets/admin/app-ITGLRDE7.js': 'slices/admin/assets/js/app.js' + // 'public/assets/admin/app-ITGLRDE7.js': true // } function extractEsbuildCompiledEntrypoints(esbuildOutputs) { const entryPoints = {}; for (const key in esbuildOutputs) { - const output = esbuildOutputs[key]; - if (output.entryPoint) { - entryPoints[key] = output.entryPoint; + if (!key.endsWith(".map")) { + entryPoints[key] = true; } } return entryPoints; diff --git a/src/esbuild-plugin.ts b/src/esbuild-plugin.ts index dc9fa4a..896ef47 100644 --- a/src/esbuild-plugin.ts +++ b/src/esbuild-plugin.ts @@ -83,18 +83,16 @@ const hanamiEsbuild = (options: PluginOptions): Plugin => { // To this: // // { - // 'public/assets/admin/app-ITGLRDE7.js': 'slices/admin/assets/js/app.js' + // 'public/assets/admin/app-ITGLRDE7.js': true // } function extractEsbuildCompiledEntrypoints( esbuildOutputs: Record, - ): Record { - const entryPoints: Record = {}; + ): Record { + const entryPoints: Record = {}; for (const key in esbuildOutputs) { - const output = esbuildOutputs[key]; - - if (output.entryPoint) { - entryPoints[key] = output.entryPoint; + if (!key.endsWith(".map")) { + entryPoints[key] = true; } } @@ -124,7 +122,7 @@ const hanamiEsbuild = (options: PluginOptions): Plugin => { const processAssetDirectory = ( pattern: string, - compiledEntryPoints: Record, + compiledEntryPoints: Record, options: PluginOptions, ): string[][] => { const dirPath = path.dirname(pattern); diff --git a/test/hanami-assets.test.ts b/test/hanami-assets.test.ts index b7c8c9c..b626f73 100644 --- a/test/hanami-assets.test.ts +++ b/test/hanami-assets.test.ts @@ -11,6 +11,7 @@ const watchTimeout = 60000; // ms (60 seconds) // Helper function to create a test environment async function createTestEnvironment() { // Create temporary directories + await fs.ensureDir(path.join(dest, "app/assets/css")); await fs.ensureDir(path.join(dest, "app/assets/js")); await fs.ensureDir(path.join(dest, "app/assets/js/nested")); await fs.ensureDir(path.join(dest, "app/assets/images/nested")); @@ -160,6 +161,35 @@ describe("hanami-assets", () => { }); }); + test("handles CSS", async () => { + const entryPoint = path.join(dest, "app/assets/js/app.js"); + await fs.writeFile(entryPoint, 'import "../css/app.css";'); + const cssFile = path.join(dest, "app/assets/css/app.css"); + await fs.writeFile(cssFile, ".btn { background: #f00; }"); + + await assets.run({ root: dest, argv: ["--path=app", "--target=public/assets"] }); + + const entryPointExists = await fs.pathExists(path.join("public/assets/app-6PW7FGD5.js")); + expect(entryPointExists).toBe(true); + const cssExists = await fs.pathExists(path.join("public/assets/app-HYVEQYF6.css")); + expect(cssExists).toBe(true); + + const manifestContent = await fs.readFile( + path.join(dest, "public/assets/assets.json"), + "utf-8", + ); + const manifest = JSON.parse(manifestContent); + + expect(manifest).toEqual({ + "app.css": { + url: "/assets/app-HYVEQYF6.css", + }, + "app.js": { + url: "/assets/app-6PW7FGD5.js", + }, + }); + }) + test("handles TypeScript", async () => { const entryPoint1 = path.join(dest, "app/assets/js/app.ts"); await fs.writeFile(entryPoint1, "console.log('Hello from TS!');");