Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"chalk": "^4.1.2",
"commander": "^14.0.0",
"csv-parse": "^6.1.0",
"fs-extra": "^11.3.0",
"glob": "^11.0.3",
"ignore": "^7.0.5",
"js-yaml": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion test/test-installation-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

const path = require('node:path');
const os = require('node:os');
const fs = require('fs-extra');
const fs = require('../tools/installer/fs-native');
const { Installer } = require('../tools/installer/core/installer');
const { ManifestGenerator } = require('../tools/installer/core/manifest-generator');
const { OfficialModules } = require('../tools/installer/modules/official-modules');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
const { bmadDir } = await installer.findBmadDir(projectDir);

// Check if bmad directory exists
const fs = require('fs-extra');
const fs = require('../fs-native');
if (!(await fs.pathExists(bmadDir))) {
await prompts.log.warn('No BMAD installation found in the current directory.');
await prompts.log.message(`Expected location: ${bmadDir}`);
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/commands/uninstall.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../fs-native');
const prompts = require('../prompts');
const { Installer } = require('../core/installer');

Expand Down
2 changes: 1 addition & 1 deletion tools/installer/core/existing-install.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../fs-native');
const yaml = require('yaml');
const { Manifest } = require('./manifest');

Expand Down
2 changes: 1 addition & 1 deletion tools/installer/core/install-paths.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../fs-native');
const { getProjectRoot } = require('../project-root');
const { BMAD_FOLDER_NAME } = require('../ide/shared/path-utils');

Expand Down
2 changes: 1 addition & 1 deletion tools/installer/core/installer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../fs-native');
const { Manifest } = require('./manifest');
const { OfficialModules } = require('../modules/official-modules');
const { IdeManager } = require('../ide/manager');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/core/manifest-generator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../fs-native');
const yaml = require('yaml');
const crypto = require('node:crypto');
const csv = require('csv-parse/sync');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/core/manifest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../fs-native');
const crypto = require('node:crypto');
const { getProjectRoot } = require('../project-root');
const prompts = require('../prompts');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/file-ops.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('./fs-native');
const path = require('node:path');
const crypto = require('node:crypto');

Expand Down
111 changes: 111 additions & 0 deletions tools/installer/fs-native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Drop-in replacement for fs-extra using native node:fs APIs.
// Eliminates graceful-fs monkey-patching that causes non-deterministic
// file loss during multi-module installs on macOS (issue #1779).
const fsp = require('node:fs/promises');
const fs = require('node:fs');
const path = require('node:path');

async function pathExists(p) {
try {
await fsp.access(p);
return true;
} catch {
return false;
}
}

async function ensureDir(dir) {
await fsp.mkdir(dir, { recursive: true });
}

async function remove(p) {
await fsp.rm(p, { recursive: true, force: true });
}

async function copy(src, dest, options = {}) {
Comment thread
bmadcode marked this conversation as resolved.
const filterFn = options.filter;
const overwrite = options.overwrite !== false;
const srcStat = await fsp.stat(src);

if (srcStat.isFile()) {
if (filterFn && !(await filterFn(src, dest))) return;
await fsp.mkdir(path.dirname(dest), { recursive: true });
if (!overwrite) {
try {
await fsp.access(dest);
if (options.errorOnExist) throw new Error(`${dest} already exists`);
return;
} catch (error) {
if (error.message.includes('already exists')) throw error;
}
}
await fsp.copyFile(src, dest);
return;
}

if (srcStat.isDirectory()) {
if (filterFn && !(await filterFn(src, dest))) return;
await fsp.mkdir(dest, { recursive: true });
const entries = await fsp.readdir(src, { withFileTypes: true });
for (const entry of entries) {
await copy(path.join(src, entry.name), path.join(dest, entry.name), options);
}
}
}

async function move(src, dest) {
try {
await fsp.rename(src, dest);
} catch (error) {
if (error.code === 'EXDEV') {
await copy(src, dest);
await fsp.rm(src, { recursive: true, force: true });
} else {
throw error;
}
}
}

function readJsonSync(p) {
return JSON.parse(fs.readFileSync(p, 'utf8'));
}

async function writeJson(p, data, options = {}) {
const spaces = options.spaces ?? 2;
await fsp.writeFile(p, JSON.stringify(data, null, spaces) + '\n', 'utf8');
}

module.exports = {
Comment thread
bmadcode marked this conversation as resolved.
// Native async (node:fs/promises)
readFile: fsp.readFile,
writeFile: fsp.writeFile,
stat: fsp.stat,
readdir: fsp.readdir,
access: fsp.access,
rename: fsp.rename,
unlink: fsp.unlink,
chmod: fsp.chmod,
mkdir: fsp.mkdir,
mkdtemp: fsp.mkdtemp,
copyFile: fsp.copyFile,
rm: fsp.rm,

// fs-extra compatible helpers (native implementations)
pathExists,
ensureDir,
remove,
copy,
move,
readJsonSync,
writeJson,

// Sync methods from core node:fs
existsSync: fs.existsSync.bind(fs),
readFileSync: fs.readFileSync.bind(fs),
writeFileSync: fs.writeFileSync.bind(fs),
createReadStream: fs.createReadStream.bind(fs),
pathExistsSync: fs.existsSync.bind(fs),

// Constants
constants: fs.constants,
};
2 changes: 1 addition & 1 deletion tools/installer/ide/_config-driven.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const os = require('node:os');
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../fs-native');
const yaml = require('yaml');
const prompts = require('../prompts');
const csv = require('csv-parse/sync');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/ide/platform-codes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('../fs-native');
const path = require('node:path');
const yaml = require('yaml');

Expand Down
2 changes: 1 addition & 1 deletion tools/installer/ide/shared/skill-manifest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../../fs-native');
const yaml = require('yaml');

/**
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/message-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('./fs-native');
const path = require('node:path');
const yaml = require('yaml');
const prompts = require('./prompts');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/modules/community-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('../fs-native');
const os = require('node:os');
const path = require('node:path');
const { execSync } = require('node:child_process');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/modules/custom-module-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('../fs-native');
const os = require('node:os');
const path = require('node:path');
const { execSync } = require('node:child_process');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/modules/external-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('../fs-native');
const os = require('node:os');
const path = require('node:path');
const { execSync } = require('node:child_process');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/modules/official-modules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('../fs-native');
const yaml = require('yaml');
const prompts = require('../prompts');
const { getProjectRoot, getSourcePath, getModulePath } = require('../project-root');
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/modules/plugin-resolver.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('../fs-native');
const path = require('node:path');
const yaml = require('yaml');

Expand Down
2 changes: 1 addition & 1 deletion tools/installer/project-root.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('node:path');
const fs = require('fs-extra');
const fs = require('./fs-native');

/**
* Find the BMAD project root directory by looking for package.json
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/ui.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('node:path');
const os = require('node:os');
const fs = require('fs-extra');
const fs = require('./fs-native');
const { CLIUtils } = require('./cli-utils');
const { ExternalModuleManager } = require('./modules/external-manager');
const { getProjectRoot } = require('./project-root');
Expand Down
2 changes: 1 addition & 1 deletion tools/migrate-custom-module-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This should be run once to update existing installations
*/

const fs = require('fs-extra');
const fs = require('./installer/fs-native');
const path = require('node:path');
const yaml = require('yaml');
const chalk = require('chalk');
Expand Down
Loading