From dff0ea6104bfc9cac2ed6246c887c16dd1bb2c4c Mon Sep 17 00:00:00 2001 From: Yusaku Sato Date: Tue, 14 Oct 2025 10:06:29 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat(scaffold):=20eleventy=E3=81=AEincremen?= =?UTF-8?q?tal=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@d-zero/scaffold/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@d-zero/scaffold/package.json b/packages/@d-zero/scaffold/package.json index 49d11aaa..2a3b9967 100644 --- a/packages/@d-zero/scaffold/package.json +++ b/packages/@d-zero/scaffold/package.json @@ -17,7 +17,7 @@ "scripts": { "build": "yarn lint && npx @d-zero/builder", "build:only": "npx @d-zero/builder", - "dev": "npx eleventy --serve --watch", + "dev": "npx eleventy --serve --watch --incremental", "d": "yarn dev", "lint": "run-s \"lint:*\"", "lint:html": "npx markuplint \"./__assets/**/*.{pug,html}\"", From a02a197623b966b85f18bfce4e4435f47766a06d Mon Sep 17 00:00:00 2001 From: Yusaku Sato Date: Tue, 14 Oct 2025 10:11:47 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat(builder):=20cSS/JS=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=81=AB=E5=AF=BE=E3=81=97=E3=81=A6addDepend?= =?UTF-8?q?encies=E3=82=92=E4=BD=BF=E3=81=84=E4=BE=9D=E5=AD=98=E9=96=A2?= =?UTF-8?q?=E4=BF=82=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@d-zero/builder/src/compiler/css.ts | 8 +++++++- .../builder/src/eleventy-plugins/script.ts | 19 ++++++++++++++++++- .../builder/src/eleventy-plugins/style.ts | 8 +++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/@d-zero/builder/src/compiler/css.ts b/packages/@d-zero/builder/src/compiler/css.ts index 95c7fffe..4ea1a210 100644 --- a/packages/@d-zero/builder/src/compiler/css.ts +++ b/packages/@d-zero/builder/src/compiler/css.ts @@ -89,5 +89,11 @@ export async function compileCss( to: undefined, }); - return result.css; + const dependencies = result.messages + .filter( + (message) => message.type === 'dependency' && typeof message.file === 'string', + ) + .map((message) => message.file); + + return { css: result.css, dependencies }; } diff --git a/packages/@d-zero/builder/src/eleventy-plugins/script.ts b/packages/@d-zero/builder/src/eleventy-plugins/script.ts index 71c9c164..1cec6e1c 100644 --- a/packages/@d-zero/builder/src/eleventy-plugins/script.ts +++ b/packages/@d-zero/builder/src/eleventy-plugins/script.ts @@ -26,18 +26,35 @@ export const scriptPlugin: EleventyPlugin { const tmpPath = path.join(pluginConfig.tmpDir, inputPath); - await esbuild.build({ + const result = await esbuild.build({ entryPoints: [inputPath], bundle: true, alias: eleventyConfig.globalData.alias, outfile: tmpPath, minify: !!(eleventyConfig.globalData.minifier?.minifyJS ?? true), charset: 'utf8', + metafile: true, banner: { js: pluginConfig.banner, }, }); + const dependencies = result.metafile + ? Object.keys(result.metafile.inputs) + .filter( + (key) => + typeof key === 'string' && + !key.startsWith('<') && + !key.startsWith('node:'), + ) + .map((key) => path.resolve(key)) + : []; + + if (dependencies.length > 0) { + // @ts-ignore + this.addDependencies(inputPath, dependencies); + } + const content = await fs.readFile(tmpPath, 'utf8'); return content; }; diff --git a/packages/@d-zero/builder/src/eleventy-plugins/style.ts b/packages/@d-zero/builder/src/eleventy-plugins/style.ts index fbb57da1..8f99891d 100644 --- a/packages/@d-zero/builder/src/eleventy-plugins/style.ts +++ b/packages/@d-zero/builder/src/eleventy-plugins/style.ts @@ -29,14 +29,20 @@ export const stylePlugin: EleventyPlugin const absInputPath = path.resolve(inputPath); const cssMinify = !!(pluginConfig.minify ?? true); - let content = await compileCss(css, absInputPath, { + const { css: compiledCss, dependencies } = await compileCss(css, absInputPath, { alias: pluginConfig.alias, }); + let content = compiledCss; if (!cssMinify) { content = await prettifyCss(content); } + if (dependencies.length > 0) { + // @ts-ignore + this.addDependencies(inputPath, dependencies); + } + return `${pluginConfig.banner}\n${content}`; }; }, From 5f2e2f85b286ae9e706f224a0692ba8bd2840f9e Mon Sep 17 00:00:00 2001 From: Yusaku Sato Date: Wed, 22 Oct 2025 19:49:59 +0900 Subject: [PATCH 3/4] =?UTF-8?q?test(builder):=20compileCss=E3=81=AE?= =?UTF-8?q?=E8=BF=94=E3=81=99=E5=80=A4=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=AB?= =?UTF-8?q?=E4=BC=B4=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../@d-zero/builder/src/compiler/css.spec.ts | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/@d-zero/builder/src/compiler/css.spec.ts b/packages/@d-zero/builder/src/compiler/css.spec.ts index c2815de4..8c4e22e4 100644 --- a/packages/@d-zero/builder/src/compiler/css.spec.ts +++ b/packages/@d-zero/builder/src/compiler/css.spec.ts @@ -21,12 +21,12 @@ describe('compileCss', () => { }); // Verify cssnano minification - expect(result).not.toContain('\n'); - expect(result).not.toContain(' '); - expect(result).toContain('.button'); - expect(result).toContain('color:red'); - expect(result).toContain('background-color:blue'); - expect(result).toContain('margin:10px 20px'); + expect(result.css).not.toContain('\n'); + expect(result.css).not.toContain(' '); + expect(result.css).toContain('.button'); + expect(result.css).toContain('color:red'); + expect(result.css).toContain('background-color:blue'); + expect(result.css).toContain('margin:10px 20px'); }); it('should handle CSS comments properly', async () => { @@ -41,8 +41,8 @@ describe('compileCss', () => { alias: {}, }); - expect(result).not.toContain('Regular comment'); - expect(result).toContain('Important comment'); + expect(result.css).not.toContain('Regular comment'); + expect(result.css).toContain('Important comment'); }); it('should process complex CSS selectors and values', async () => { @@ -66,10 +66,10 @@ describe('compileCss', () => { alias: {}, }); - expect(result).toContain('.card>.header:before'); // ::before gets minified to :before - expect(result).toContain('content:""'); - expect(result).toContain('linear-gradient(90deg,red,#00f)'); // Actual minification result - expect(result).toContain('@media (min-width:768px)'); + expect(result.css).toContain('.card>.header:before'); // ::before gets minified to :before + expect(result.css).toContain('content:""'); + expect(result.css).toContain('linear-gradient(90deg,red,#00f)'); // Actual minification result + expect(result.css).toContain('@media (min-width:768px)'); }); it('should handle empty CSS', async () => { @@ -79,7 +79,7 @@ describe('compileCss', () => { alias: {}, }); - expect(result).toBe(''); + expect(result.css).toBe(''); }); it('should handle CSS with only comments', async () => { @@ -92,7 +92,7 @@ describe('compileCss', () => { alias: {}, }); - expect(result).toBe(''); + expect(result.css).toBe(''); }); it('should preserve only important comments', async () => { @@ -106,9 +106,9 @@ describe('compileCss', () => { alias: {}, }); - expect(result).toContain('License information'); - expect(result).toContain('Copyright information'); - expect(result).not.toContain('Regular comment'); + expect(result.css).toContain('License information'); + expect(result.css).toContain('Copyright information'); + expect(result.css).not.toContain('Regular comment'); }); }); @@ -120,7 +120,7 @@ describe('compileCss', () => { alias: {}, }); - expect(result).toBe(''); + expect(result.css).toBe(''); }); it('should throw error for unclosed block syntax', async () => { @@ -149,8 +149,8 @@ describe('compileCss', () => { }, }); - expect(result).toContain('.component'); - expect(result).toContain('color:green'); + expect(result.css).toContain('.component'); + expect(result.css).toContain('color:green'); }); }); }); @@ -182,8 +182,8 @@ describe('compileCss - File import functionality', () => { }, }); - expect(result).toContain('.button'); - expect(result).toContain('padding:1rem'); + expect(result.css).toContain('.button'); + expect(result.css).toContain('padding:1rem'); }); it('should throw error when importing non-existent file', async () => { From 89202e50d27a5101f38cf94e7e5e1f56d372f8aa Mon Sep 17 00:00:00 2001 From: Yusaku Sato Date: Tue, 28 Oct 2025 11:03:11 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor(builder):=20@ts-ignore=E3=81=AE?= =?UTF-8?q?=E9=99=A4=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@d-zero/builder/src/eleventy-plugins/script.ts | 6 +++--- packages/@d-zero/builder/src/eleventy-plugins/style.ts | 6 +++--- packages/@d-zero/builder/src/eleventy.types.ts | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/@d-zero/builder/src/eleventy-plugins/script.ts b/packages/@d-zero/builder/src/eleventy-plugins/script.ts index 1cec6e1c..5c8c2b2d 100644 --- a/packages/@d-zero/builder/src/eleventy-plugins/script.ts +++ b/packages/@d-zero/builder/src/eleventy-plugins/script.ts @@ -25,6 +25,7 @@ export const scriptPlugin: EleventyPlugin { const tmpPath = path.join(pluginConfig.tmpDir, inputPath); + const addDependencies = this.addDependencies; const result = await esbuild.build({ entryPoints: [inputPath], @@ -50,9 +51,8 @@ export const scriptPlugin: EleventyPlugin path.resolve(key)) : []; - if (dependencies.length > 0) { - // @ts-ignore - this.addDependencies(inputPath, dependencies); + if (addDependencies && dependencies.length > 0) { + addDependencies(inputPath, dependencies); } const content = await fs.readFile(tmpPath, 'utf8'); diff --git a/packages/@d-zero/builder/src/eleventy-plugins/style.ts b/packages/@d-zero/builder/src/eleventy-plugins/style.ts index 8f99891d..6dc34259 100644 --- a/packages/@d-zero/builder/src/eleventy-plugins/style.ts +++ b/packages/@d-zero/builder/src/eleventy-plugins/style.ts @@ -28,6 +28,7 @@ export const stylePlugin: EleventyPlugin return async () => { const absInputPath = path.resolve(inputPath); const cssMinify = !!(pluginConfig.minify ?? true); + const addDependencies = this.addDependencies; const { css: compiledCss, dependencies } = await compileCss(css, absInputPath, { alias: pluginConfig.alias, @@ -38,9 +39,8 @@ export const stylePlugin: EleventyPlugin content = await prettifyCss(content); } - if (dependencies.length > 0) { - // @ts-ignore - this.addDependencies(inputPath, dependencies); + if (addDependencies && dependencies.length > 0) { + addDependencies(inputPath, dependencies); } return `${pluginConfig.banner}\n${content}`; diff --git a/packages/@d-zero/builder/src/eleventy.types.ts b/packages/@d-zero/builder/src/eleventy.types.ts index ad4fa1d9..576228d0 100644 --- a/packages/@d-zero/builder/src/eleventy.types.ts +++ b/packages/@d-zero/builder/src/eleventy.types.ts @@ -43,6 +43,7 @@ export type EleventyTransformContext = { export type EleventyExtensionCompiler = { outputFileExtension?: string; + addDependencies?: (inputPath: string, dependencies: string[]) => void; compile: ( content: string, inputPath: string,