-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9671d60
commit f536dd9
Showing
5 changed files
with
113 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { getLogger } from "../../log.ts"; | ||
import { PushFailure, PushHandler } from "../../typegate/hooks.ts"; | ||
import { createArtifactMeta } from "../utils/deno.ts"; | ||
|
||
const logger = getLogger("typegate"); | ||
|
||
export class DenoFailure extends Error { | ||
failure: PushFailure; | ||
|
||
constructor(message: string) { | ||
super(message); | ||
this.failure = { reason: "DenoImportError", message }; | ||
} | ||
} | ||
|
||
export const cacheModules: PushHandler = async ( | ||
typegraph, | ||
_secretManager, | ||
_response, | ||
artifactStore, | ||
) => { | ||
const { title } = typegraph.types[0]; | ||
const { artifacts } = typegraph.meta; | ||
|
||
for (const mat of typegraph.materializers) { | ||
if (mat.name === "module") { | ||
const matData = mat.data; | ||
const entryPoint = artifacts[matData.entryPoint as string]; | ||
const moduleMeta = createArtifactMeta(title, entryPoint); | ||
const depMetas = (matData.deps as string[]).map((dep) => | ||
createArtifactMeta(title, artifacts[dep]), | ||
); | ||
const entryModulePath = await artifactStore.getLocalPath( | ||
moduleMeta, | ||
depMetas, | ||
); | ||
|
||
logger.info("Caching deno imports"); | ||
|
||
try { | ||
await import(entryModulePath); | ||
} catch (error) { | ||
console.error(error.stack); | ||
|
||
throw new DenoFailure( | ||
`An error occured when trying to import '${entryPoint.path}'`, | ||
); | ||
} | ||
} | ||
} | ||
|
||
return typegraph; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
import { ArtifactMeta } from "../../typegate/artifacts/mod.ts"; | ||
import { Artifact } from "../../typegraph/types.ts"; | ||
|
||
export function createArtifactMeta( | ||
typegraphName: string, | ||
artifact: Artifact, | ||
): ArtifactMeta { | ||
return { | ||
typegraphName, | ||
hash: artifact.hash, | ||
sizeInBytes: artifact.size, | ||
relativePath: artifact.path, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters