From 9ddbb27cb5b1d32eb7be073db33d0e5e689b2591 Mon Sep 17 00:00:00 2001 From: Ifycode Date: Thu, 9 Apr 2026 11:30:50 +0100 Subject: [PATCH 1/4] Fix: .bin path breakage in production & version bump to v1.0.4 --- .husky/pre-commit | 2 +- README.md | 4 ++-- bin/pkg.internal.cli.js | 32 +++++++++++++++++++------------- package-lock.json | 4 ++-- package.json | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 05ab555..e5f6132 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -npx @build-in-blocks/dev.setup@1.0.3 dev:internal:lint \ No newline at end of file +npx @build-in-blocks/dev.setup@1.0.4 dev:internal:lint \ No newline at end of file diff --git a/README.md b/README.md index 6053a00..2aa8473 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ export default { ```` "scripts": { - "prepare": "npx @build-in-blocks/dev.setup@1.0.3 dev:husky:setup:git" + "prepare": "npx @build-in-blocks/dev.setup@1.0.4 dev:husky:setup:git" // your other npm scripts in your project goes here as usual }, ```` @@ -200,7 +200,7 @@ export default { # ----------------------------------------------------------------- # This points to the shared library repository's "central" workflow # ----------------------------------------------------------------- - uses: build-in-blocks/dev.setup/.github/workflows/central-blocks-ci.yml@v1.0.3 + uses: build-in-blocks/dev.setup/.github/workflows/central-blocks-ci.yml@v1.0.4 with: run_tests: true # ------------------------------------------------- diff --git a/bin/pkg.internal.cli.js b/bin/pkg.internal.cli.js index 34b1caa..6d7912d 100755 --- a/bin/pkg.internal.cli.js +++ b/bin/pkg.internal.cli.js @@ -3,9 +3,9 @@ /*global console*/ import { fs, path, execSync, process } from '../config.root/external.packages.js'; -import { binPath, __dirname } from '../config.root/root.js'; +import { __dirname } from '../config.root/root.js'; -const internalCommand = '@build-in-blocks/dev.setup@1.0.3'; +const internalCommand = '@build-in-blocks/dev.setup@1.0.4'; const userAppArg = { huskyGitSetup: 'dev:husky:setup:git', @@ -30,19 +30,25 @@ if (pkgArgDetected) { // ----------------------------------------------- // Safely find binary paths for the internal tools // ----------------------------------------------- - const getBinPath = ({ pkgName, binSubPath }) => { - try { - return binPath({ pkgName, binSubPath }); - } catch { - return path.resolve(internalBinPath, pkgName); + const getBinPath = (pkgName) => { + //----------------------------------------------------------------- + // A. Look in the User App's .bin (Production or hoisted) + // B. Look in the Engine's .bin (Development i.e. local npm link) + // C. Return the .bin path that match based on environment detected + //----------------------------------------------------------------- + const paths = [path.resolve(userAppRoot, 'node_modules/.bin', pkgName), path.resolve(engineRoot, 'node_modules/.bin', pkgName)]; + + const found = paths.find((p) => fs.existsSync(p)); + + if (!found) { + throw new Error(`Binary for ${pkgName} not found. Try 'npm install'`); } + + return found; }; - //- - const huskyBin = getBinPath({ pkgName: 'husky', binSubPath: 'bin.js' }); - const lintStagedBin = getBinPath({ - pkgName: 'lint-staged', - binSubPath: 'bin/lint-staged.js', - }); + + const huskyBin = getBinPath('husky'); + const lintStagedBin = getBinPath('lint-staged'); // --------------------------------------------------------- // Set up husky to work with git i.e. initially generate the diff --git a/package-lock.json b/package-lock.json index 477d173..f88d892 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@build-in-blocks/dev.setup", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@build-in-blocks/dev.setup", - "version": "1.0.3", + "version": "1.0.4", "license": "AGPL-3.0", "dependencies": { "@eslint/js": "^10.0.1", diff --git a/package.json b/package.json index 2a0e780..6458970 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@build-in-blocks/dev.setup", - "version": "1.0.3", + "version": "1.0.4", "description": "Code linting, formatting, pre-commit hook and GitHub Actions Continuous Integration (CI) (including node version compatiblity check) development environment setup for your typescript code repository", "type": "module", "main": "config.programmed/eslint.helper.mjs", From e9e1abc9f6dabd0a4bc17f099dcca75ffcdac167 Mon Sep 17 00:00:00 2001 From: Ifycode Date: Thu, 9 Apr 2026 14:36:26 +0100 Subject: [PATCH 2/4] Fix: dev.resources installed for husky git setup user message cleanup --- bin/pkg.internal.cli.js | 30 ++++++++++++++++++++++++++---- config.root/blocks.packages.js | 7 +++++++ config.root/root.js | 6 +++++- package.json | 3 +++ 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 config.root/blocks.packages.js diff --git a/bin/pkg.internal.cli.js b/bin/pkg.internal.cli.js index 6d7912d..77fb12b 100755 --- a/bin/pkg.internal.cli.js +++ b/bin/pkg.internal.cli.js @@ -3,7 +3,8 @@ /*global console*/ import { fs, path, execSync, process } from '../config.root/external.packages.js'; -import { __dirname } from '../config.root/root.js'; +import { blocksTerminalLogger } from '../config.root/blocks.packages.js'; +import { internalPkgJSON, __dirname } from '../config.root/root.js'; const internalCommand = '@build-in-blocks/dev.setup@1.0.4'; @@ -23,6 +24,8 @@ if (pkgArgDetected) { // this library, or the web app that this library is used in). //----------------------------------------------------------------- const userAppRoot = process.cwd(); + const userAppPkgJSON = JSON.parse(fs.readFileSync(path.join(userAppRoot, 'package.json'), 'utf-8')); + //- const engineRoot = path.resolve(__dirname, '..'); const internalModulesPath = path.resolve(engineRoot, 'node_modules'); const internalBinPath = path.resolve(internalModulesPath, '.bin'); @@ -55,7 +58,7 @@ if (pkgArgDetected) { // husky folder, with content that includes pre-commit file. // --------------------------------------------------------- if (command === userAppArg.huskyGitSetup) { - console.log('🐶 Setting up @build-in-blocks git hooks...'); + console.log('[PREPARING] Setting up @build-in-blocks git hooks...'); try { execSync(`node "${huskyBin}"`, { stdio: 'inherit' }); const preCommitPath = path.join(userAppRoot, '.husky/pre-commit'); @@ -67,9 +70,28 @@ if (pkgArgDetected) { fs.writeFileSync(preCommitPath, hookContent, { mode: 0o755 }); - console.log('✅ Git hooks integrated successfully.'); + console.log('[SUCCESS] Git hooks integrated successfully.'); } catch { - console.error('❌ Git hook setup failed.'); + blocksTerminalLogger({ + startLoggerMessageOnNewLine: true, + internalPackage: { + fullName: internalPkgJSON.name, + }, + userApp: { + fullName: userAppPkgJSON.name, + errorMessage: 'Git hook setup failed.', + }, + errorSource: true, + suggestion: { + // prettier-ignore + messageList: [ + '→ [Step 1] Run "git init" at the root of your project to make it a git repository.', + '→ [Step 2] Add and commit one or more files to git.', + '→ [Step 3] Try the prepare script again, after you\'ve done steps 1 & 2 above.', + ], + }, + processExit: true, + }); } } diff --git a/config.root/blocks.packages.js b/config.root/blocks.packages.js new file mode 100644 index 0000000..e838de8 --- /dev/null +++ b/config.root/blocks.packages.js @@ -0,0 +1,7 @@ +import { blocksTerminalLogger } from '@build-in-blocks/dev.resources'; + +export { + //- + blocksTerminalLogger, + //- +}; diff --git a/config.root/root.js b/config.root/root.js index eb388a8..b3d4dbb 100644 --- a/config.root/root.js +++ b/config.root/root.js @@ -1,4 +1,4 @@ -import { path, fileURLToPath, createRequire } from './external.packages.js'; +import { fs, path, fileURLToPath, createRequire } from './external.packages.js'; // ------------------------------------------------ // ESM & Resolution Helpers: @@ -16,6 +16,9 @@ const binPath = ({ pkgName, binSubPath }) => { return path.join(_pkgRoot, binSubPath); }; +const internalProjectRoot = path.join(__dirname, '../', 'package.json'); +const internalPkgJSON = JSON.parse(fs.readFileSync(internalProjectRoot, 'utf-8')); + export { //------------------------------- // Export global access variables @@ -26,4 +29,5 @@ export { //- binPath, //- + internalPkgJSON, }; diff --git a/package.json b/package.json index 6458970..50f46d9 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,9 @@ "prettier": "^3.8.1", "typescript-eslint": "^8.56.1" }, + "devDependencies": { + "@build-in-blocks/dev.resources": "1.0.4" + }, "homepage": "https://github.com/build-in-blocks/dev.setup#readme", "bugs": { "url": "https://github.com/build-in-blocks/product-issue-reports/issues" From cf27f4374dfe1bd7811dc39b2605464ad64ccb5e Mon Sep 17 00:00:00 2001 From: Ifycode Date: Thu, 9 Apr 2026 14:57:56 +0100 Subject: [PATCH 3/4] Husky message clarity, lock file regeneration --- bin/pkg.internal.cli.js | 6 +++--- package-lock.json | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/pkg.internal.cli.js b/bin/pkg.internal.cli.js index 77fb12b..b8b189d 100755 --- a/bin/pkg.internal.cli.js +++ b/bin/pkg.internal.cli.js @@ -58,7 +58,7 @@ if (pkgArgDetected) { // husky folder, with content that includes pre-commit file. // --------------------------------------------------------- if (command === userAppArg.huskyGitSetup) { - console.log('[PREPARING] Setting up @build-in-blocks git hooks...'); + console.log('[PREPARING] Setting up husky git hooks...'); try { execSync(`node "${huskyBin}"`, { stdio: 'inherit' }); const preCommitPath = path.join(userAppRoot, '.husky/pre-commit'); @@ -70,7 +70,7 @@ if (pkgArgDetected) { fs.writeFileSync(preCommitPath, hookContent, { mode: 0o755 }); - console.log('[SUCCESS] Git hooks integrated successfully.'); + console.log('[SUCCESS] Husky git hooks integrated successfully.'); } catch { blocksTerminalLogger({ startLoggerMessageOnNewLine: true, @@ -79,7 +79,7 @@ if (pkgArgDetected) { }, userApp: { fullName: userAppPkgJSON.name, - errorMessage: 'Git hook setup failed.', + errorMessage: 'Husky git hook setup failed.', }, errorSource: true, suggestion: { diff --git a/package-lock.json b/package-lock.json index f88d892..cf30998 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,8 +20,18 @@ "bin": { "blocks.pkg.dev.setup": "bin/pkg.internal.cli.js", "dev.setup": "bin/pkg.internal.cli.js" + }, + "devDependencies": { + "@build-in-blocks/dev.resources": "1.0.4" } }, + "node_modules/@build-in-blocks/dev.resources": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@build-in-blocks/dev.resources/-/dev.resources-1.0.4.tgz", + "integrity": "sha512-6Xn1/+mU3LIGNcvYH8uM4goqVl6/EeWgDrwj87NkV8alOnn4MM4D1SeahQBbHSiFoaxDAWScKMVr2+1oXFzQxw==", + "dev": true, + "license": "AGPL-3.0" + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.9.1", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.9.1.tgz", From 88d23badde2753cddaf5b46823c0c9fb495dc19c Mon Sep 17 00:00:00 2001 From: Ifycode Date: Thu, 9 Apr 2026 14:59:23 +0100 Subject: [PATCH 4/4] Fix: Root README installation instruction minor fix --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2aa8473..7d6cc99 100644 --- a/README.md +++ b/README.md @@ -41,11 +41,17 @@ #### 1. Main package installation -Install our dev setup package as a `devDependency` in your project: +- Install our dev setup package as a `devDependency` in your project: -```` -npm install -D @build-in-blocks/dev.setup -```` + ```` + npm install -D @build-in-blocks/dev.setup --save-exact + ```` + +- Also make sure to install the resources package, so that your project's code can compile successfully without errors: + + ```` + npm install -D @build-in-blocks/dev.resources --save-exact + ```` #### 2. When to install `typescript`