Skip to content

Commit

Permalink
Revert to exportig derby instance from index; not publishing types
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck committed Oct 26, 2023
1 parent 8dfdc9b commit f02ec7d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
8 changes: 8 additions & 0 deletions src/Derby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class Derby extends DerbyBase {
createApp(name: string, filename: string, options) {
return new this.App(this, name, filename, options);
}

use(plugin, options) {
return racer.util.use.call(this, plugin, options);
}

serverUse(plugin, options) {
return racer.util.serverUse.call(this, plugin, options);
}
}

if (!racer.util.isServer) {
Expand Down
13 changes: 13 additions & 0 deletions src/DerbyForServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AppBase } from './App';
import { AppForServer } from './AppForServer';
import { DerbyBase } from './Derby';
import { PageForServer } from './PageForServer';

export class DerbyForServer extends DerbyBase {
App: typeof AppForServer = AppForServer;
Page: typeof PageForServer = PageForServer;

createApp(name: string, filename: string, options: any): AppBase<object> {
return new this.App(this, name, filename, options);
}
}
40 changes: 7 additions & 33 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
import { util } from 'racer';
import { Derby } from './Derby';

import { AppBase as AppClass, type App } from './App';
import { type AppForServer } from './AppForServer';
import { PageBase as PageClass } from './Page';

/* eslint-disable @typescript-eslint/no-var-requires */
if (util.isServer) {
// @ts-expect-error Required tomfoolery for isomorphic things
AppClass = require('./App').App;
// @ts-expect-error Required tomfoolery for isomorphic things
PageClass = require('./Page').Page;
} else {
// @ts-expect-error Required tomfoolery for isomorphic things
AppClass = require('./AppForServer').AppForServer;
// @ts-expect-error Required tomfoolery for isomorphic things
PageClass = require('./PageForServer').PageForServer;
}
/* eslint-enable @typescript-eslint/no-var-requires */

export { Component } from './components';
export { AppClass as App };
export { PageClass as Page };
export { type PageParams, type QueryParams } from './routes';
export { Dom } from './Dom';
export { util };

export function createApp(name: string, filename: string, options) {
if (util.isServer) {
return new (AppClass as unknown as typeof AppForServer)({ Page: PageClass }, name, filename, options);
} else {
return new (AppClass as unknown as typeof App)({ Page: PageClass }, name, filename, options);
}
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const util = require('racer').util;

const DerbyClass = util.isServer
? util.serverRequire(module, './DerbyForServer').DerbyForServer
: Derby;
export = new DerbyClass();
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"noImplicitUseStrict": true,
"outDir": "dist",
"target": "ES5",
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"sourceMap": false,
"declaration": false,
"declarationMap": false,
},
"include": [
"src/**/*"
Expand Down

0 comments on commit f02ec7d

Please sign in to comment.