From b263c5952f69d4eaee138c620b607c19371090e3 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Sun, 18 Apr 2021 17:47:14 +0200 Subject: [PATCH 1/2] Avoid newline conflicts when switching between Windows and Unix --- tsconfig.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tsconfig.json b/tsconfig.json index db5bec82..a9e61294 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,9 @@ // this is necessary for the automatic typing of the adapter config "resolveJsonModule": true, + // Avoid conflicts with line endings in compiled files + "newLine": "lf", + // Set this to false if you want to disable the very strict rules (not recommended) "strict": true, // Or enable some of those features for more fine-grained control From 03707d7a7db43d685aa9ae807e3bb0091bc199c9 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Sun, 18 Apr 2021 17:47:56 +0200 Subject: [PATCH 2/2] Make build script handling more flexible --- dist/index.js | 35 +++++++++++++++++++++++++---------- src/index.ts | 37 +++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2163d457..63edc9d9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -201,9 +201,15 @@ class DevServer { // figure out if we need parcel (React) const pkg = this.readPackageJson(); const scripts = pkg.scripts; - if (scripts && scripts['watch:parcel']) { - // use parcel - await this.startParcel(); + if (scripts) { + if (scripts['watch:react']) { + // use React with default script name + await this.startReact(); + } + else if (scripts['watch:parcel']) { + // use React with legacy script name + await this.startReact('watch:parcel'); + } } this.startBrowserSync(this.getPort(config.adminPort, HIDDEN_BROWSER_SYNC_PORT_OFFSET)); // browser-sync proxy @@ -349,10 +355,12 @@ class DevServer { } return generator.toJSON(); } - async startParcel() { - this.log.notice('Starting parcel'); - this.log.debug('Waiting for first successful parcel build...'); - await this.spawnAndAwaitOutput('npm', ['run', 'watch:parcel'], this.rootDir, 'Built in', { shell: true }); + async startReact(scriptName = 'watch:react') { + this.log.notice('Starting React build'); + this.log.debug('Waiting for first successful React build...'); + await this.spawnAndAwaitOutput('npm', ['run', scriptName], this.rootDir, /(done in|watching (files )?for)/i, { + shell: true, + }); } startBrowserSync(port) { this.log.notice('Starting browser-sync'); @@ -435,7 +443,7 @@ class DevServer { async startTscWatch() { this.log.notice('Starting tsc --watch'); this.log.debug('Waiting for first successful tsc build...'); - await this.spawnAndAwaitOutput('npm', ['run', 'watch:ts', '--', '--preserveWatchOutput'], this.rootDir, 'Watching for', { shell: true }); + await this.spawnAndAwaitOutput('npm', ['run', 'watch:ts' /*, '--', '--preserveWatchOutput'*/], this.rootDir, /watching (files )?for/i, { shell: true }); } startFileSync(destinationDir) { this.log.notice(`Starting file system sync from ${this.rootDir}`); @@ -719,8 +727,15 @@ class DevServer { (_a = proc.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => { const str = data.toString('utf-8'); console.log(str.trimEnd()); - if (str.includes(awaitMsg)) { - resolve(proc); + if (typeof awaitMsg === 'string') { + if (str.includes(awaitMsg)) { + resolve(proc); + } + } + else { + if (awaitMsg.test(str)) { + resolve(proc); + } } }); proc.on('exit', (code) => reject(`Exited with ${code}`)); diff --git a/src/index.ts b/src/index.ts index e990e50d..26a341a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -243,9 +243,14 @@ class DevServer { // figure out if we need parcel (React) const pkg = this.readPackageJson(); const scripts = pkg.scripts; - if (scripts && scripts['watch:parcel']) { - // use parcel - await this.startParcel(); + if (scripts) { + if (scripts['watch:react']) { + // use React with default script name + await this.startReact(); + } else if (scripts['watch:parcel']) { + // use React with legacy script name + await this.startReact('watch:parcel'); + } } this.startBrowserSync(this.getPort(config.adminPort, HIDDEN_BROWSER_SYNC_PORT_OFFSET)); @@ -418,10 +423,12 @@ class DevServer { return generator.toJSON(); } - private async startParcel(): Promise { - this.log.notice('Starting parcel'); - this.log.debug('Waiting for first successful parcel build...'); - await this.spawnAndAwaitOutput('npm', ['run', 'watch:parcel'], this.rootDir, 'Built in', { shell: true }); + private async startReact(scriptName = 'watch:react'): Promise { + this.log.notice('Starting React build'); + this.log.debug('Waiting for first successful React build...'); + await this.spawnAndAwaitOutput('npm', ['run', scriptName], this.rootDir, /(done in|watching (files )?for)/i, { + shell: true, + }); } private startBrowserSync(port: number): void { @@ -519,9 +526,9 @@ class DevServer { this.log.debug('Waiting for first successful tsc build...'); await this.spawnAndAwaitOutput( 'npm', - ['run', 'watch:ts', '--', '--preserveWatchOutput'], + ['run', 'watch:ts' /*, '--', '--preserveWatchOutput'*/], this.rootDir, - 'Watching for', + /watching (files )?for/i, { shell: true }, ); } @@ -832,7 +839,7 @@ class DevServer { command: string, args: ReadonlyArray, cwd: string, - awaitMsg: string, + awaitMsg: string | RegExp, options?: cp.SpawnOptions, ): Promise { return new Promise((resolve, reject) => { @@ -840,8 +847,14 @@ class DevServer { proc.stdout?.on('data', (data: Buffer) => { const str = data.toString('utf-8'); console.log(str.trimEnd()); - if (str.includes(awaitMsg)) { - resolve(proc); + if (typeof awaitMsg === 'string') { + if (str.includes(awaitMsg)) { + resolve(proc); + } + } else { + if (awaitMsg.test(str)) { + resolve(proc); + } } }); proc.on('exit', (code) => reject(`Exited with ${code}`));