MCPcopy Create free account
hub / github.com/arktypeio/arktype / bundle

Function bundle

ark/repo/bundle.ts:15–137  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13import { packagesByScope, repoDirs } from "./shared.ts"
14
15export const bundle = async (): Promise<void> => {
16 const modulePaths = walkPaths(fromCwd("out"), {
17 include: path => path.endsWith(".js")
18 })
19 const entryPoints = publicEntryPoints(process.cwd())
20 // a runtime bundled with an issues module of its own, by that module
21 const variants = [
22 [fromCwd("out", "schemaRuntimeNone.js"), "issuesNone.js"],
23 [fromCwd("out", "schemaRuntimeLean.js"), "issuesLean.js"],
24 [fromCwd("out", "schemaRuntimeNoneLean.js"), "issuesNoneLean.js"]
25 ].filter(([runtime]) => entryPoints.includes(runtime))
26 const schemaRuntimeEntry = fromCwd("out", "schemaRuntime.js")
27 const sharedPlugins: Plugin[] = [
28 {
29 name: "externalize-issue-features",
30 setup: build => {
31 build.onResolve(
32 { filter: /(?:^|[/\\])issueFeatures(?:\.js)?$/ },
33 () => ({ path: "./shared/issueFeatures.js", external: true })
34 )
35 }
36 },
37 {
38 name: "externalize-schema-runtime",
39 setup: build => {
40 build.onResolve(
41 { filter: /^(?:arktype|@ark)\/schema\/runtime$/ },
42 args =>
43 args.importer === schemaRuntimeEntry ?
44 undefined
45 : { path: "arktype/schema/runtime", external: true }
46 )
47 }
48 }
49 ]
50 const opts = {
51 bundle: true,
52 format: "esm",
53 platform: "neutral",
54 charset: "utf8",
55 absWorkingDir: process.cwd(),
56 write: false,
57 logLevel: "warning",
58 external: ["node:*"],
59 plugins: sharedPlugins
60 } satisfies BuildOptions
61 // a module several entries import evaluates once only if they share one build
62 const { outputFiles, metafile } = await build({
63 ...opts,
64 metafile: true,
65 entryPoints: entryPoints.filter(
66 path =>
67 path !== issueFeaturesPath() &&
68 !variants.some(([runtime]) => runtime === path)
69 ),
70 outdir: fromCwd("out"),
71 splitting: true
72 })

Callers 1

build.tsFile · 0.90

Calls 15

walkPathsFunction · 0.90
fromCwdFunction · 0.90
rmRfFunction · 0.90
writeFileFunction · 0.90
publicEntryPointsFunction · 0.85
issueFeaturesPathFunction · 0.85
joinFunction · 0.85
binEntryPointsFunction · 0.85
developmentEntryPointsFunction · 0.85
precompiledSourcesFunction · 0.85
reexportImportsFunction · 0.85

Tested by

no test coverage detected