Skip to content

Commit 68da376

Browse files
committed
minor #2853 Prevent yarn watch to exit if TypeScript plugin is unable to compile (Kocal)
This PR was merged into the 2.x branch. Discussion ---------- Prevent `yarn watch` to exit if TypeScript plugin is unable to compile | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | Fix #2850 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- 23b720b Prevent `yarn watch` to exit if TypeScript plugin is unable to compile
2 parents 493bc31 + 23b720b commit 68da376

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

bin/build_package.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const args = parseArgs({
2222

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

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

89-
const rollupConfig = getRollupConfiguration({ packageRoot, inputFiles: inputScriptFiles });
90+
const rollupConfig = getRollupConfiguration({ packageRoot, inputFiles: inputScriptFiles, isWatch });
9091

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

105106
const watcher = rollup.watch(rollupConfig);
106-
watcher.on('event', ({ result }) => {
107-
if (result) {
108-
result.close();
107+
watcher.on('event', (event) => {
108+
if (event.code === 'ERROR') {
109+
console.error('Error during build:', event.error);
110+
}
111+
112+
if (event.result) {
113+
event.result.close();
109114
}
110115
});
111116
watcher.on('change', async (id, { event }) => {

bin/rollup.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ const moveTypescriptDeclarationsPlugin = (packageRoot) => ({
7272
/**
7373
* @param {String} packageRoot
7474
* @param {Array<String>} inputFiles
75+
* @param {Boolean} isWatch
7576
*/
76-
function getRollupConfiguration({ packageRoot, inputFiles }) {
77+
function getRollupConfiguration({ packageRoot, inputFiles, isWatch }) {
7778
const packagePath = path.join(packageRoot, 'package.json');
7879
const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
7980
const peerDependencies = [
@@ -108,7 +109,7 @@ function getRollupConfiguration({ packageRoot, inputFiles }) {
108109
typescript({
109110
filterRoot: '.',
110111
tsconfig: path.join(__dirname, '..', 'tsconfig.json'),
111-
noEmitOnError: true,
112+
noEmitOnError: !isWatch,
112113
include: [
113114
'src/**/*.ts',
114115
// TODO: Remove for the next major release

0 commit comments

Comments
 (0)