Skip to content

Commit 1ef2dba

Browse files
committed
remove aliases for production templates
1 parent bc76ffd commit 1ef2dba

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

apps/template-nextjs/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@graphprotocol/hypergraph/*": ["../../packages/hypergraph/src/*.js"],
2424
"@graphprotocol/hypergraph-react": ["../../packages/hypergraph-react/src/index.js"],
2525
"@graphprotocol/hypergraph-react/*": ["../../packages/hypergraph-react/src/*.js"],
26-
"@/*": ["./*"],
26+
"@/*": ["./*"]
2727
}
2828
},
2929
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],

apps/template-vite-react/tsconfig.app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@
4848
"src",
4949
"../../packages/hypergraph/src/**/*",
5050
"../../packages/hypergraph-react/src/**/*"
51-
],
51+
]
5252
}

packages/create-hypergraph/scripts/copy-template-dir.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,42 @@ class CopyTemplateDirService extends Effect.Service<CopyTemplateDirService>()(
7878
yield* fs.writeFileString(destPackageJsonPath, JSON.stringify(packageJson, null, 2));
7979
});
8080

81+
const updateTsconfigJsonWorkspaceDeps = (tsconfigJsonPath: string, destTsconfigJsonPath: string) =>
82+
Effect.gen(function* () {
83+
// read the tsconfig.json
84+
const tsconfigJson = yield* fs.readFileString(tsconfigJsonPath).pipe(Effect.map(JSON.parse));
85+
86+
// remove the paths for the hypergraph workspace deps
87+
tsconfigJson.compilerOptions.paths = Object.fromEntries(
88+
Object.entries(tsconfigJson.compilerOptions.paths).filter(
89+
([key]) => !key.startsWith('@graphprotocol/hypergraph'),
90+
),
91+
);
92+
93+
// remove hypergraph paths from the include array
94+
if (tsconfigJson.include && Array.isArray(tsconfigJson.include)) {
95+
tsconfigJson.include = tsconfigJson.include.filter(
96+
(path: string) => !path.startsWith('../../packages/hypergraph'),
97+
);
98+
}
99+
100+
yield* fs.writeFileString(destTsconfigJsonPath, JSON.stringify(tsconfigJson, null, 2));
101+
});
102+
103+
const updateViteConfigAliases = (viteConfigPath: string, destViteConfigPath: string) =>
104+
Effect.gen(function* () {
105+
// read the vite.config.ts
106+
const viteConfig = yield* fs.readFileString(viteConfigPath);
107+
108+
// Remove the hypergraph aliases from the Vite config using line-based filtering
109+
const updatedViteConfig = viteConfig
110+
.split('\n')
111+
.filter((line) => !line.match(/['"]@graphprotocol\/hypergraph(-react)?[^'"]*['"]\s*:/))
112+
.join('\n');
113+
114+
yield* fs.writeFileString(destViteConfigPath, updatedViteConfig);
115+
});
116+
81117
const copy = (src: string, dest: string, replaced: Record<string, string>): Effect.Effect<void, PlatformError> =>
82118
Effect.gen(function* () {
83119
yield* fs.makeDirectory(dest, { recursive: true });
@@ -97,6 +133,14 @@ class CopyTemplateDirService extends Effect.Service<CopyTemplateDirService>()(
97133
yield* updatePackageJsonWorkspaceDeps(srcPath, destPath, replaced);
98134
continue;
99135
}
136+
if (entry.name === 'tsconfig.app.json' || entry.name === 'tsconfig.json') {
137+
yield* updateTsconfigJsonWorkspaceDeps(srcPath, destPath);
138+
continue;
139+
}
140+
if (entry.name === 'vite.config.ts') {
141+
yield* updateViteConfigAliases(srcPath, destPath);
142+
continue;
143+
}
100144
yield* fs.copyFile(srcPath, destPath);
101145
}
102146
}

0 commit comments

Comments
 (0)