@@ -8,7 +8,7 @@ import { assert, cast, isNonNull, normalizeSlashes, trimExtension } from "../uti
88import { Chunk , modulesToBundleChunks , modulesToChunks } from "./chunk" ;
99import { createResolutionErrorDiagnostic } from "./diagnostics" ;
1010import { buildModule , Module } from "./module" ;
11- import { getPlugins , Plugin } from "./plugins" ;
11+ import { applyBailPlugin , applySinglePlugin , getPlugins , Plugin } from "./plugins" ;
1212import { Transpiler , TranspilerHost } from "./transpiler" ;
1313
1414export class Transpilation {
@@ -35,14 +35,15 @@ export class Transpilation {
3535
3636 this . outDir = this . options . outDir ?? this . rootDir ;
3737
38+ this . plugins = getPlugins ( this , extraPlugins ) ;
39+
3840 this . resolver = ResolverFactory . createResolver ( {
3941 extensions : [ ".lua" , ...this . implicitScriptExtensions ] ,
4042 conditionNames : [ "lua" , `lua:${ this . options . luaTarget ?? LuaTarget . Universal } ` ] ,
4143 fileSystem : this . host . resolutionFileSystem ?? fs ,
4244 useSyncFileSystemCalls : true ,
45+ plugins : this . plugins . flatMap ( p => p . getResolvePlugins ?.( this ) ?? [ ] ) ,
4346 } ) ;
44-
45- this . plugins = getPlugins ( this , extraPlugins ) ;
4647 }
4748
4849 public emit ( ) : Chunk [ ] {
@@ -99,6 +100,9 @@ export class Transpilation {
99100 }
100101
101102 public getModuleId ( module : Module ) {
103+ const pluginResult = applyBailPlugin ( this . plugins , p => p . getModuleId ?.( module , this ) ) ;
104+ if ( pluginResult !== undefined ) return pluginResult ;
105+
102106 const result = path . relative ( this . rootDir , trimExtension ( module . request ) ) ;
103107 // TODO: handle files on other drives
104108 assert ( ! path . isAbsolute ( result ) , `Invalid path: ${ result } ` ) ;
@@ -109,6 +113,9 @@ export class Transpilation {
109113 }
110114
111115 private mapModulesToChunks ( modules : Module [ ] ) : Chunk [ ] {
112- return isBundleEnabled ( this . options ) ? modulesToBundleChunks ( this , modules ) : modulesToChunks ( this , modules ) ;
116+ return (
117+ applySinglePlugin ( this . plugins , "mapModulesToChunks" ) ?.( modules , this ) ??
118+ ( isBundleEnabled ( this . options ) ? modulesToBundleChunks ( this , modules ) : modulesToChunks ( this , modules ) )
119+ ) ;
113120 }
114121}
0 commit comments