diff --git a/scripts/postbuild.js b/scripts/postbuild.js index ca947a498..039e2f617 100644 --- a/scripts/postbuild.js +++ b/scripts/postbuild.js @@ -63,13 +63,7 @@ if (existsSync(cliSourcePath)) { }; } -// Conditionally add postinstall script (only if scripts/ directory exists) const scriptsSourcePath = path.join(packagePath, 'scripts'); -if (existsSync(scriptsSourcePath)) { - packageJson.scripts = { - postinstall: 'node ./scripts/postinstall.mjs', - }; -} // Write the modified package.json to the build folder await writeFile( diff --git a/scripts/postbuild.test.js b/scripts/postbuild.test.js index 06658c7b0..4ecfddf62 100644 --- a/scripts/postbuild.test.js +++ b/scripts/postbuild.test.js @@ -1,4 +1,10 @@ -import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { + existsSync, + mkdirSync, + readFileSync, + rmSync, + writeFileSync, +} from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; @@ -109,4 +115,26 @@ describe('Postbuild Script', () => { './index.global.js' ); }); + + it('should not add postinstall when package scripts are bundled', async () => { + const postbuildPath = path.join(__dirname, 'postbuild.js'); + const { execSync } = await import('node:child_process'); + + mkdirSync(path.join(testDir, 'scripts'), { recursive: true }); + writeFileSync( + path.join(testDir, 'scripts', 'postinstall.mjs'), + 'console.log("installing skills");\n' + ); + + execSync(`node ${postbuildPath}`, { cwd: testDir }); + + const generatedPackageJson = JSON.parse( + readFileSync(path.join(testDir, 'dist', 'package.json'), 'utf8') + ); + + expect(generatedPackageJson.scripts).toBeUndefined(); + expect( + existsSync(path.join(testDir, 'dist', 'scripts', 'postinstall.mjs')) + ).toBe(true); + }); });