Skip to content
Open
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
6 changes: 0 additions & 6 deletions scripts/postbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 29 additions & 1 deletion scripts/postbuild.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});