Skip to content

Commit 94c5430

Browse files
committed
fix(typesync | publish): get client dist to run in published package
1 parent 2c37ad2 commit 94c5430

File tree

7 files changed

+32
-47
lines changed

7 files changed

+32
-47
lines changed

apps/typesync/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/hypergraph-cli",
3-
"version": "0.0.0-alpha.8",
3+
"version": "0.0.0-alpha.13",
44
"type": "module",
55
"license": "MIT",
66
"description": "CLI toolchain to view existing types, select, pick, extend to create schemas and generate a @graphprotocol/hypergraph schema.",

apps/typesync/src/Database.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
import { fileURLToPath } from 'node:url';
2-
import * as NodeContext from '@effect/platform-node/NodeContext';
3-
import * as SqliteClient from '@effect/sql-sqlite-node/SqliteClient';
4-
import * as Migrator from '@effect/sql-sqlite-node/SqliteMigrator';
5-
import * as SqlClient from '@effect/sql/SqlClient';
6-
import * as SqlError from '@effect/sql/SqlError';
7-
import * as SqlResolver from '@effect/sql/SqlResolver';
8-
import * as SqlSchema from '@effect/sql/SqlSchema';
9-
import * as EffectArray from 'effect/Array';
10-
import * as Chunk from 'effect/Chunk';
11-
import * as Console from 'effect/Console';
12-
import * as Effect from 'effect/Effect';
13-
import * as Layer from 'effect/Layer';
14-
import * as Option from 'effect/Option';
15-
import * as Order from 'effect/Order';
16-
import * as Schema from 'effect/Schema';
17-
import * as Stream from 'effect/Stream';
2+
import { NodeContext } from '@effect/platform-node';
3+
import { SqlClient, SqlError, SqlResolver, SqlSchema } from '@effect/sql';
4+
import { SqliteMigrator as Migrator, SqliteClient } from '@effect/sql-sqlite-node';
5+
import { Chunk, Console, Effect, Array as EffectArray, Layer, Option, Order, Schema, Stream } from 'effect';
186

197
import * as TypesyncDomain from '../domain/Domain.js';
208
import * as Domain from './Domain.js';

apps/typesync/src/Generator.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { execSync } from 'node:child_process';
22
import * as fsSync from 'node:fs';
33
import * as nodePath from 'node:path';
4-
import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem';
5-
import * as FileSystem from '@effect/platform/FileSystem';
6-
import * as Path from '@effect/platform/Path';
4+
import { FileSystem, Path } from '@effect/platform';
5+
import { NodeFileSystem } from '@effect/platform-node';
76
import { Data, Effect } from 'effect';
87

98
import * as Domain from '../domain/Domain.js';

apps/typesync/src/Server.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
/** Defines the static file routes for serving the client dist directory with the built vite/react app */
2-
3-
import { dirname, resolve } from 'node:path';
42
import { fileURLToPath } from 'node:url';
53

6-
import * as HttpMiddleware from '@effect/platform/HttpMiddleware';
7-
import * as HttpRouter from '@effect/platform/HttpRouter';
8-
import * as HttpServer from '@effect/platform/HttpServer';
9-
import * as HttpServerResponse from '@effect/platform/HttpServerResponse';
10-
import * as Effect from 'effect/Effect';
11-
import * as Layer from 'effect/Layer';
12-
import * as Option from 'effect/Option';
13-
import * as Struct from 'effect/Struct';
4+
import { HttpMiddleware, HttpRouter, HttpServer, HttpServerResponse, Path } from '@effect/platform';
5+
import { Effect, String as EffectString, Layer, Option, Struct } from 'effect';
146

15-
import { Path } from '@effect/platform';
167
import * as Api from './Api.js';
178

18-
const __dirname = dirname(fileURLToPath(import.meta.url));
19-
const clientDist = resolve(__dirname, '..', 'client', 'dist');
20-
219
const FilesRouter = Effect.gen(function* () {
2210
const path = yield* Path.Path;
2311

12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = path.dirname(__filename);
14+
/**
15+
* This resolves an issue when running the cli in dev mode locally vs published mode.
16+
* In local dev mode, the __dirname will end with `src` as this file will be ran from the ./src directory.
17+
* When running in the compiled dist mode, the __dirname will end with `dist`.
18+
*
19+
* @todo clean this up and figure out a better way to derive
20+
*/
21+
const isLocal = EffectString.endsWith('src')(__dirname);
22+
const clientdist = isLocal
23+
? path.resolve(__dirname, '..', 'client', 'dist')
24+
: path.resolve(__dirname, 'client', 'dist');
25+
2426
return HttpRouter.empty.pipe(
2527
HttpRouter.get(
2628
'/',
27-
HttpServerResponse.file(path.join(clientDist, 'index.html')).pipe(
29+
HttpServerResponse.file(path.join(clientdist, 'index.html')).pipe(
2830
Effect.orElse(() => HttpServerResponse.empty({ status: 404 })),
2931
),
3032
),
@@ -37,7 +39,7 @@ const FilesRouter = Effect.gen(function* () {
3739
return HttpServerResponse.empty({ status: 404 });
3840
}
3941

40-
const assets = path.join(clientDist, 'assets');
42+
const assets = path.join(clientdist, 'assets');
4143
const normalized = path.normalize(path.join(assets, ...file.value.split('/')));
4244
if (!normalized.startsWith(assets)) {
4345
return HttpServerResponse.empty({ status: 404 });

apps/typesync/src/bin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env node
22

3-
import * as NodeContext from '@effect/platform-node/NodeContext';
4-
import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem';
5-
import * as NodeRuntime from '@effect/platform-node/NodeRuntime';
3+
import { NodeContext, NodeFileSystem, NodeRuntime } from '@effect/platform-node';
64
import * as Effect from 'effect/Effect';
75

86
import { run } from './Cli.js';

apps/typesync/src/subcommands/studio.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { createServer } from 'node:http';
2-
import * as Command from '@effect/cli/Command';
3-
import * as Options from '@effect/cli/Options';
4-
import * as NodeHttpServer from '@effect/platform-node/NodeHttpServer';
5-
import * as HttpServer from '@effect/platform/HttpServer';
6-
import * as Console from 'effect/Console';
7-
import * as Data from 'effect/Data';
8-
import * as Effect from 'effect/Effect';
9-
import * as Layer from 'effect/Layer';
2+
import { Command, Options } from '@effect/cli';
3+
import { HttpServer } from '@effect/platform';
4+
import { NodeHttpServer } from '@effect/platform-node';
5+
import { Console, Data, Effect, Layer } from 'effect';
106
import open, { type AppName, apps } from 'open';
117

128
import * as Server from '../Server.js';

scripts/package.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ const publishPkgJson = {
3535
main: pkgJson.main,
3636
module: pkgJson.module,
3737
types: pkgJson.types,
38+
exports: pkgJson.exports,
3839
sideEffects: pkgJson.sideEffects,
3940
peerDependencies: pkgJson.peerDependencies,
4041
dependencies: pkgJson.dependencies,
42+
...(pkgJson.bin ? { bin: pkgJson.bin } : {}),
4143
publishConfig: {
4244
provenance: false,
4345
},

0 commit comments

Comments
 (0)