Skip to content

Commit 3088620

Browse files
authored
Improve launch performance by skipping wrapper script (#207)
1 parent 12e8733 commit 3088620

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

lib/src/async-compiler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ import {spawn} from 'child_process';
66
import {Observable} from 'rxjs';
77
import {takeUntil} from 'rxjs/operators';
88

9-
import {compilerPath} from './compiler-path';
9+
import {compilerCommand} from './compiler-path';
1010

1111
/**
1212
* An asynchronous wrapper for the embedded Sass compiler that exposes its stdio
1313
* streams as Observables.
1414
*/
1515
export class AsyncEmbeddedCompiler {
1616
/** The underlying process that's being wrapped. */
17-
private readonly process = spawn(compilerPath, {windowsHide: true});
17+
private readonly process = spawn(
18+
compilerCommand[0],
19+
compilerCommand.slice(1),
20+
{windowsHide: true}
21+
);
1822

1923
/** The child process's exit event. */
2024
readonly exit$ = new Promise<number | null>(resolve => {

lib/src/compiler-path.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as fs from 'fs';
66
import * as p from 'path';
77
import {isErrnoException} from './utils';
88

9-
/** The path to the embedded compiler executable. */
10-
export const compilerPath = (() => {
9+
/** The full command for the embedded compiler executable. */
10+
export const compilerCommand = (() => {
1111
// find for development
1212
for (const path of ['vendor', '../../../lib/src/vendor']) {
1313
const executable = p.resolve(
@@ -18,15 +18,33 @@ export const compilerPath = (() => {
1818
}`
1919
);
2020

21-
if (fs.existsSync(executable)) return executable;
21+
if (fs.existsSync(executable)) return [executable];
2222
}
2323

2424
try {
25-
return require.resolve(
26-
`sass-embedded-${process.platform}-${process.arch}/` +
27-
'dart-sass-embedded/dart-sass-embedded' +
28-
(process.platform === 'win32' ? '.bat' : '')
29-
);
25+
return [
26+
require.resolve(
27+
`sass-embedded-${process.platform}-${process.arch}/` +
28+
'dart-sass-embedded/src/dart' +
29+
(process.platform === 'win32' ? '.exe' : '')
30+
),
31+
require.resolve(
32+
`sass-embedded-${process.platform}-${process.arch}/` +
33+
'dart-sass-embedded/src/dart-sass-embedded.snapshot'
34+
),
35+
];
36+
} catch (ignored) {
37+
// ignored
38+
}
39+
40+
try {
41+
return [
42+
require.resolve(
43+
`sass-embedded-${process.platform}-${process.arch}/` +
44+
'dart-sass-embedded/dart-sass-embedded' +
45+
(process.platform === 'win32' ? '.bat' : '')
46+
),
47+
];
3048
} catch (e: unknown) {
3149
if (!(isErrnoException(e) && e.code === 'MODULE_NOT_FOUND')) {
3250
throw e;

lib/src/sync-compiler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
import {Subject} from 'rxjs';
66

77
import {SyncProcess} from './sync-process';
8-
import {compilerPath} from './compiler-path';
8+
import {compilerCommand} from './compiler-path';
99

1010
/**
1111
* A synchronous wrapper for the embedded Sass compiler that exposes its stdio
1212
* streams as Observables.
1313
*/
1414
export class SyncEmbeddedCompiler {
1515
/** The underlying process that's being wrapped. */
16-
private readonly process = new SyncProcess(compilerPath, {windowsHide: true});
16+
private readonly process = new SyncProcess(
17+
compilerCommand[0],
18+
compilerCommand.slice(1),
19+
{windowsHide: true}
20+
);
1721

1822
/** The buffers emitted by the child process's stdout. */
1923
readonly stdout$ = new Subject<Buffer>();

0 commit comments

Comments
 (0)