Skip to content

Commit

Permalink
Bind modules/<depname>/public.ts to Public.<depname>
Browse files Browse the repository at this point in the history
  • Loading branch information
Blckbrry-Pi authored and NathanFlurry committed May 18, 2024
1 parent 15572c7 commit 44b0347
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion artifacts/runtime_archive.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/build/gen/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export { compileTestHelper } from "./test.ts";
export { compileScriptHelper } from "./script.ts";

export { compileModuleTypeHelper } from "./module_type.ts";
export { compileModulePublicUtilsHelper } from "./module_public_utils.ts";
export { compilePublicUtilsHelpers } from "./public_utils.ts";
export { compileTypeHelpers } from "./type.ts";

export async function getUserConfigImport(module: Module, moduleRoot: string) {
Expand Down
1 change: 1 addition & 0 deletions src/build/gen/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function compileModuleHelper(

// Export block
helper.chunk.withNewlinesPerChunk(2)
.append`export * as Module from "./public.ts";`
.append`
/**
* Empty Request/Response type.
Expand Down
20 changes: 20 additions & 0 deletions src/build/gen/module_public_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { genAllPublicUtils, Module, Project, publicGenPath } from "../../project/mod.ts";
import { camelify } from "../../types/case_conversions.ts";
import { GeneratedCodeBuilder } from "./mod.ts";

export async function compileModulePublicUtilsHelper(
project: Project,
module: Module,
) {
const reexport = new GeneratedCodeBuilder(publicGenPath(project, module));
const utilsPath = reexport.relative(genAllPublicUtils(project));

for (const dependency of Object.keys(module.config.dependencies || {})) {
reexport.append`
// Reexports public utils for ${dependency}
export { ${camelify(dependency)} } from ${JSON.stringify(utilsPath)};
`;
}

await reexport.write();
}
2 changes: 2 additions & 0 deletions src/build/gen/module_type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { genDependencyTypedefPath, Module, Project, typeGenPath } from "../../project/mod.ts";
import { GeneratedCodeBuilder } from "./mod.ts";
import { camelify } from "../../types/case_conversions.ts";
import { compileModulePublicUtilsHelper } from "./module_public_utils.ts";

export async function compileModuleTypeHelper(
project: Project,
Expand Down Expand Up @@ -50,4 +51,5 @@ export async function compileModuleTypeHelper(
);

await typeHelper.write();
await compileModulePublicUtilsHelper(project, module);
}
41 changes: 41 additions & 0 deletions src/build/gen/public_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { genAllPublicUtils, genModulePublicUtils, Project, publicPath } from "../../project/mod.ts";
import { GeneratedCodeBuilder } from "./mod.ts";
import { camelify } from "../../types/case_conversions.ts";
import { exists } from "../../deps.ts";

export async function compilePublicUtilsHelpers(project: Project) {
const allPublicUtils = new GeneratedCodeBuilder(genAllPublicUtils(project));

for (const module of project.modules.values()) {
const reexporter = new GeneratedCodeBuilder(genModulePublicUtils(project, module), 2);

// If it exists, reexport the `public.ts` file for this module
if (await exists(publicPath(module), { isFile: true })) {
reexporter.append`
export * from ${JSON.stringify(reexporter.relative(publicPath(module)))};
`;
}

// Export the module's name as a constant
reexporter.append`export const __CANONICAL_MODULE_NAME = "${module.name}";`;

await reexporter.write();
}

// Generate the `all.ts` file
for (const module of project.modules.values()) {
const importPath = allPublicUtils.relative(
genModulePublicUtils(
project,
module,
),
);
// Export the module's public utils under the module's name
allPublicUtils.append`
// Public utils for ${module.name}
export * as ${camelify(module.name)} from ${JSON.stringify(importPath)};
`;
}

await allPublicUtils.write();
}
3 changes: 3 additions & 0 deletions src/build/gen/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { genDependencyCaseConversionMapPath, genDependencyTypedefPath, Project } from "../../project/mod.ts";
import { GeneratedCodeBuilder } from "./mod.ts";
import { camelify, pascalify } from "../../types/case_conversions.ts";
import { compilePublicUtilsHelpers } from "./public_utils.ts";

export async function compileTypeHelpers(project: Project) {
const typedefPath = genDependencyTypedefPath(project);
Expand Down Expand Up @@ -124,4 +125,6 @@ export async function compileTypeHelpers(project: Project) {

await dependencyTypedef.write();
await dependencyCaseConversionMap.write();

await compilePublicUtilsHelpers(project);
}
2 changes: 1 addition & 1 deletion src/build_state/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { verbose } from "../term/status.ts";
import { crypto, encodeHex } from "./deps.ts";

// TODO: Replace this with the OpenGB version instead since it means we'll change . We need to compile this in the build artifacts.
export const CACHE_VERSION = 5;
export const CACHE_VERSION = 6;

export interface Cache {
persist: CachePersist;
Expand Down

0 comments on commit 44b0347

Please sign in to comment.