Skip to content

Commit

Permalink
fix(scully): fix premature compilation of the config (scullyio#1158)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderElias authored Dec 3, 2020
1 parent 354b506 commit ff03767
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion libs/scully/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/scully",
"version": "1.0.6",
"version": "1.0.7",
"description": "Scully CLI",
"repository": {
"type": "GIT",
Expand Down
12 changes: 7 additions & 5 deletions libs/scully/src/lib/renderPlugins/launchedBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Browser, launch, LaunchOptions } from 'puppeteer';
import { BehaviorSubject, from, merge, Observable, of, timer, interval } from 'rxjs';
import { filter, shareReplay, switchMap, take, tap, delayWhen, throttleTime, catchError } from 'rxjs/operators';
import { BehaviorSubject, from, interval, merge, Observable, of, timer } from 'rxjs';
import { catchError, delayWhen, filter, shareReplay, switchMap, take, throttleTime } from 'rxjs/operators';
import { captureException } from '../utils/captureMessage';
import { showBrowser } from '../utils/cli-options';
import { loadConfig, scullyConfig } from '../utils/config';
import { green, log, logError } from '../utils/log';
import { captureException } from '../utils/captureMessage';
import { log, logError } from '../utils/log';
import { waitForIt } from './puppeteerRenderPlugin';

const launches = new BehaviorSubject<void>(undefined);
/**
* Returns an Observable with that will fire with the launched puppeteer in there.
*/
export const launchedBrowser$: Observable<Browser> = from(loadConfig).pipe(
export const launchedBrowser$: Observable<Browser> = of('').pipe(
/** load config only after a subscription is made */
switchMap(loadConfig),
/** give the system a bit of breathing room, and prevent race */
switchMap(() => from(waitForIt(50))),
switchMap(() => merge(obsBrowser(), launches)),
Expand Down
8 changes: 7 additions & 1 deletion libs/scully/src/lib/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ const loadIt = async () => {
};

/** export the config as a promise, so you can wait for it when you need config during 'boot' */
export const loadConfig = loadIt();
let promisedConfig: Promise<ScullyConfig>;
export const loadConfig = () => {
if (!promisedConfig) {
promisedConfig = loadIt();
}
return promisedConfig;
};

export const updateScullyConfig = async (config: Partial<ScullyConfig>) => {
/** note, an invalid config will abort the entire program. */
Expand Down
2 changes: 1 addition & 1 deletion libs/scully/src/lib/utils/handlers/defaultAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const generateAll = Symbol('generateAll');
registerPlugin(scullySystem, generateAll, plugin);

async function plugin(localBaseFilter = baseFilter): Promise<HandledRoute[]> {
await loadConfig;
await loadConfig();
try {
// maintain progress ui
/** handleTravesal execute the guessParser and create a list of route.routes */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { HandledRoute } from '../../routerPlugins/';
export const handleUnknownRoute: RequestHandler = async (req, res, next) => {
if (req.accepts('html')) {
/** only handle 404 on html requests specially */
await loadConfig;
await loadConfig();
const distFolder = join(scullyConfig.homeFolder, scullyConfig.hostFolder || scullyConfig.distFolder);
const distIndex = join(distFolder, '/index.html');
const dist404 = join(distFolder, '/404.html');
Expand Down
2 changes: 1 addition & 1 deletion libs/scully/src/lib/utils/serverstuff/staticServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let dataServerInstance: { close: () => void };
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function staticServer(port?: number) {
try {
await loadConfig;
await loadConfig();
port = port || scullyConfig.staticPort;
const hostName = scullyConfig.hostName;
const scullyServer = express();
Expand Down
2 changes: 1 addition & 1 deletion libs/scully/src/lib/watchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function isBuildThere(config: ScullyConfig) {

let wss;
async function enableLiveReloadServer() {
await loadConfig;
await loadConfig();
try {
log('enable reload on port', scullyConfig.reloadPort);
// tslint:disable-next-line:only-arrow-functions
Expand Down
2 changes: 1 addition & 1 deletion libs/scully/src/scully.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ https://scully.io/docs/learn/getting-started/installation/
let err;
/** load the config, and use the defaults when there is an error */
try {
scullyConfig = await loadConfig;
scullyConfig = await loadConfig();
} catch (e) {
scullyConfig = scullyDefaults as ScullyConfig;
/** store the error */
Expand Down

0 comments on commit ff03767

Please sign in to comment.