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

Function loadEsbuildModules

ark/aot/unplugin.ts:1249–1315  ·  view source on GitHub ↗
(
		build: EsbuildPluginBuild,
		scan: EsbuildScanState,
		esbuildResolve: BundlerResolve
	)

Source from the content-addressed store, hash-verified

1247 }
1248 // each module watches what it read, which esbuild takes only from onLoad
1249 const loadEsbuildModules = (
1250 build: EsbuildPluginBuild,
1251 scan: EsbuildScanState,
1252 esbuildResolve: BundlerResolve
1253 ) => {
1254 build.onLoad({ filter: issueFeaturesFile }, () => {
1255 const issues = esbuildScan?.issues
1256 if (issues) return { contents: writeIssueFeatures(issues), loader: "js" }
1257 })
1258 build.onLoad({ filter: esbuildTransformed }, async args => {
1259 if (args.namespace !== "file") return
1260 const isTransformed =
1261 transformedFilter.include.test(args.path) &&
1262 !transformedFilter.exclude.test(args.path)
1263 if (!isTransformed && !scan.scanned) return
1264 if (isTransformed) loadedFiles.add(args.path)
1265 const code = readFileSync(args.path, "utf8")
1266 if (scan.scanned) addLoaded(scan.loaded, fileOf(args.path), code)
1267 if (!isTransformed) return
1268 const transformed = await transform(
1269 code,
1270 args.path,
1271 undefined,
1272 scan.scanned?.key,
1273 esbuildResolve
1274 )
1275 if (!transformed?.code && !transformed?.errors.length) return
1276 return {
1277 contents: appendSourceMap(transformed.code ?? code, transformed.map),
1278 loader:
1279 build.initialOptions.loader?.[extname(args.path)] ??
1280 esbuildLoaderOf(args.path),
1281 watchFiles: transformed.dependencies.filter(
1282 dependency => dependency !== args.path
1283 ),
1284 // together, as other hosts throw them
1285 errors:
1286 transformed.errors.length ?
1287 [{ text: transformed.errors.join("\n") }]
1288 : [],
1289 warnings: transformed.warnings.map(text => ({ text }))
1290 }
1291 })
1292 // a runtime module reading an issue feature, with each read written as
1293 // what it is, as other bundlers load it. esbuild inlines a constant
1294 // another module declares only as it prints, once it has decided what
1295 // the bundle holds: what a branch it folds there names is kept, and a
1296 // statement testing one is left behind as `!1`. Registered last, so the
1297 // load above has read the module as its file has it
1298 build.onLoad({ filter: issueFeatureReader }, args => {
1299 const issues = esbuildScan?.issues
1300 if (!issues || args.namespace !== "file") return
1301 const written = writeIssueFeaturesInto(
1302 args.path,
1303 readFileSync(args.path, "utf8"),
1304 issues
1305 )
1306 if (written !== undefined) {

Callers 1

unplugin.tsFile · 0.85

Calls 12

writeIssueFeaturesFunction · 0.90
addLoadedFunction · 0.90
fileOfFunction · 0.90
appendSourceMapFunction · 0.90
writeIssueFeaturesIntoFunction · 0.90
esbuildLoaderOfFunction · 0.85
onLoadMethod · 0.80
testMethod · 0.80
filterMethod · 0.80
transformFunction · 0.70
mapMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected