From 3565b0f3823bb520a4d323fccf128c2be0e51d23 Mon Sep 17 00:00:00 2001 From: eastagiletracker <310448263+eastagiletracker@users.noreply.github.com> Date: Thu, 13 Aug 2026 15:27:59 +0700 Subject: [PATCH] fix[faustwp-cli]: resolve blockset globs against the build directory --- .changeset/blockset-glob-project-path.md | 5 ++ packages/faustwp-cli/src/blockset.ts | 10 ++- .../tests/blockset/fetchBlockFiles.test.ts | 65 +++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 .changeset/blockset-glob-project-path.md create mode 100644 packages/faustwp-cli/tests/blockset/fetchBlockFiles.test.ts diff --git a/.changeset/blockset-glob-project-path.md b/.changeset/blockset-glob-project-path.md new file mode 100644 index 000000000..4786859b2 --- /dev/null +++ b/.changeset/blockset-glob-project-path.md @@ -0,0 +1,5 @@ +--- +"@faustwp/cli": patch +--- + +fix[faustwp-cli]: resolve `faust blockset` globs against the build directory so blocks are discovered on Windows and under project paths containing glob characters diff --git a/packages/faustwp-cli/src/blockset.ts b/packages/faustwp-cli/src/blockset.ts index 7e2e65321..e9da9a5ee 100644 --- a/packages/faustwp-cli/src/blockset.ts +++ b/packages/faustwp-cli/src/blockset.ts @@ -85,7 +85,11 @@ export function parsePhpAssetFile(phpContent: string): PhpAsset { * @returns {Promise} - An array of paths to block.json files. */ export async function fetchBlockFiles(): Promise { - return glob(`${FAUST_BUILD_DIR}/**/block.json`, { + // Search from `cwd` rather than interpolating the path into the pattern: + // a project path is data, and glob would read its `\` and `[]` as syntax. + return glob('**/block.json', { + cwd: FAUST_BUILD_DIR, + absolute: true, ignore: IGNORE_NODE_MODULES, }); } @@ -128,7 +132,9 @@ export async function processBlockFiles(files: string[]): Promise { } // Remove any other PHP files - const phpFiles = await glob(`${destDir}/**/*.php`, { + const phpFiles = await glob('**/*.php', { + cwd: destDir, + absolute: true, ignore: IGNORE_NODE_MODULES, }); await Promise.all(phpFiles.map((file) => fs.remove(file))); diff --git a/packages/faustwp-cli/tests/blockset/fetchBlockFiles.test.ts b/packages/faustwp-cli/tests/blockset/fetchBlockFiles.test.ts new file mode 100644 index 000000000..0b70d90a6 --- /dev/null +++ b/packages/faustwp-cli/tests/blockset/fetchBlockFiles.test.ts @@ -0,0 +1,65 @@ +import fs from 'fs-extra'; +import os from 'os'; +import path from 'path'; + +// A project path is data, not pattern syntax: `[1]` here stands in for any glob +// character a real checkout may contain, and for the `\` separators every +// Windows path is built from. +const PROJECT_DIR_NAME = 'my site[1]'; + +describe('blockset file discovery', () => { + let projectDir: string; + let cwdSpy: jest.SpyInstance; + + beforeEach(async () => { + const tmpDir = await fs.realpath( + await fs.mkdtemp(path.join(os.tmpdir(), 'faust-blockset-')), + ); + projectDir = path.join(tmpDir, PROJECT_DIR_NAME); + await fs.ensureDir(projectDir); + + cwdSpy = jest.spyOn(process, 'cwd').mockReturnValue(projectDir); + jest.resetModules(); + }); + + afterEach(async () => { + const tmpDir = path.dirname(projectDir); + cwdSpy.mockRestore(); + await fs.remove(tmpDir); + }); + + async function seedCompiledBlock(buildDir: string): Promise { + const blockDir = path.join(buildDir, 'MyCustomBlock'); + await fs.ensureDir(blockDir); + await fs.writeJson(path.join(blockDir, 'block.json'), { + name: 'faust/my-custom-block', + }); + await fs.writeFile(path.join(blockDir, 'render.php'), ' { + const { FAUST_BUILD_DIR, fetchBlockFiles } = await import( + '../../src/blockset' + ); + const blockDir = await seedCompiledBlock(FAUST_BUILD_DIR); + + await expect(fetchBlockFiles()).resolves.toEqual([ + path.join(blockDir, 'block.json'), + ]); + }); + + it('removes PHP files from processed blocks when the project path contains glob syntax', async () => { + const { BLOCKS_DIR, FAUST_BUILD_DIR, processBlockFiles } = await import( + '../../src/blockset' + ); + const blockDir = await seedCompiledBlock(FAUST_BUILD_DIR); + + await processBlockFiles([path.join(blockDir, 'block.json')]); + + const destDir = path.join(BLOCKS_DIR, 'MyCustomBlock'); + expect(await fs.pathExists(path.join(destDir, 'block.json'))).toBe(true); + expect(await fs.pathExists(path.join(destDir, 'render.php'))).toBe(false); + }); +});