Skip to content

Commit

Permalink
Fix type issues with loadStyles options and compiler types
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck committed Mar 18, 2024
1 parent 8de6f6d commit bdbb99e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export abstract class AppBase extends EventEmitter {
}

abstract _init(options?: AppOptions);
loadViews(_viewFilename, _viewName) { }
loadViews(_viewFilename, _viewName?) { }
loadStyles(_filename, _options) { }

component(constructor: ComponentConstructor | SingletonComponentConstructor): this;
Expand Down
15 changes: 9 additions & 6 deletions src/AppForServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

import * as racer from 'racer';

const util = racer.util;
import { AppBase } from './App';
import { type DerbyBase } from './Derby';
import { type StyleCompilerOptions } from './files';
import { PageForServer } from './PageForServer';
import parsing = require('./parsing');
import * as derbyTemplates from './templates';

const util = racer.util;

interface Agent {
send(message: Record<string, unknown>): void;
}
Expand Down Expand Up @@ -42,7 +45,7 @@ function htmlCompiler(file) {
return file;
}

type CompilerFunciton = (file: string, filename?: string, options?: unknown) => unknown;
type CompilerFunciton = (file: string, filename?: string, options?: unknown) => string;

function watchOnce(filenames, callback) {
const watcher = chokidar.watch(filenames);
Expand Down Expand Up @@ -76,7 +79,7 @@ export class AppForServer extends AppBase {
watchFiles: boolean;
router: any;

constructor(derby, name: string, filename: string, options) {
constructor(derby: DerbyBase, name: string, filename: string, options) {
super(derby, name, filename, options);
this._init(options);
}
Expand Down Expand Up @@ -208,23 +211,23 @@ export class AppForServer extends AppBase {
this.scriptMapUrl = (this.scriptMapBaseUrl || serialized.scriptMapBaseUrl) + serialized.scriptMapUrl;
}

loadViews(filename, namespace) {
loadViews(filename: string, namespace?: string) {
const data = files.loadViewsSync(this, filename, namespace);
parsing.registerParsedViews(this, data.views);
if (this.watchFiles) this._watchViews(data.files, filename, namespace);
// Make chainable
return this;
}

loadStyles(filename, options) {
loadStyles(filename: string, options?: StyleCompilerOptions) {
this._loadStyles(filename, options);
const stylesView = this.views.find('Styles');
stylesView.source += '<view is="' + filename + '"></view>';
// Make chainable
return this;
}

private _loadStyles(filename, options) {
private _loadStyles(filename: string, options?: StyleCompilerOptions) {
const styles = files.loadStylesSync(this, filename, options);

let filepath = '';
Expand Down
11 changes: 8 additions & 3 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import * as path from 'node:path';
import * as racer from 'racer';
import * as resolve from 'resolve';

import { type AppForServer } from './AppForServer';
import * as parsing from './parsing';

export function loadViewsSync(app, sourceFilename, namespace) {
export function loadViewsSync(app: AppForServer, sourceFilename: string, namespace: string) {
let views = [];
let files = [];
const filename = resolve.sync(sourceFilename, {
Expand Down Expand Up @@ -43,15 +44,19 @@ export function loadViewsSync(app, sourceFilename, namespace) {
files = files.concat(imported.files);
}

const htmlFile = compiler(file, filename);
const htmlFile = compiler(file, filename) as string;
const parsedViews = parsing.parseViews(htmlFile, namespace, filename, onImport);
return {
views: views.concat(parsedViews),
files: files.concat(filename)
};
}

export function loadStylesSync(app, sourceFilename, options) {
export interface StyleCompilerOptions extends Record<string, unknown> {
compress?: boolean;
}

export function loadStylesSync(app: AppForServer, sourceFilename: string, options?: StyleCompilerOptions) {
if (options == null) {
options = { compress: racer.util.isProduction };
}
Expand Down

0 comments on commit bdbb99e

Please sign in to comment.