Skip to content

Prevent yarn watch to exit if TypeScript plugin is unable to compile #2853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025
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
15 changes: 10 additions & 5 deletions bin/build_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const args = parseArgs({

async function main() {
const packageRoot = path.resolve(process.cwd(), args.positionals[0]);
const isWatch = args.values.watch || false;

if (!fs.existsSync(packageRoot)) {
console.error(`The package directory "${packageRoot}" does not exist.`);
Expand Down Expand Up @@ -86,9 +87,9 @@ async function main() {
process.exit(1);
}

const rollupConfig = getRollupConfiguration({ packageRoot, inputFiles: inputScriptFiles });
const rollupConfig = getRollupConfiguration({ packageRoot, inputFiles: inputScriptFiles, isWatch });

if (args.values.watch) {
if (isWatch) {
console.log(
`Watching for JavaScript${inputStyleFile ? ' and CSS' : ''} files modifications in "${srcDir}" directory...`
);
Expand All @@ -103,9 +104,13 @@ async function main() {
}

const watcher = rollup.watch(rollupConfig);
watcher.on('event', ({ result }) => {
if (result) {
result.close();
watcher.on('event', (event) => {
if (event.code === 'ERROR') {
console.error('Error during build:', event.error);
}

if (event.result) {
event.result.close();
}
});
watcher.on('change', async (id, { event }) => {
Expand Down
5 changes: 3 additions & 2 deletions bin/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ const moveTypescriptDeclarationsPlugin = (packageRoot) => ({
/**
* @param {String} packageRoot
* @param {Array<String>} inputFiles
* @param {Boolean} isWatch
*/
function getRollupConfiguration({ packageRoot, inputFiles }) {
function getRollupConfiguration({ packageRoot, inputFiles, isWatch }) {
const packagePath = path.join(packageRoot, 'package.json');
const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
const peerDependencies = [
Expand Down Expand Up @@ -108,7 +109,7 @@ function getRollupConfiguration({ packageRoot, inputFiles }) {
typescript({
filterRoot: '.',
tsconfig: path.join(__dirname, '..', 'tsconfig.json'),
noEmitOnError: true,
noEmitOnError: !isWatch,
include: [
'src/**/*.ts',
// TODO: Remove for the next major release
Expand Down
Loading