11/**@target web */
2- import webpack from 'webpack'
32
4- import { type VariableDeclarator , type Identifier , type Expression , type CallExpression } from 'estree'
3+ import { type VariableDeclarator , type Identifier , type Expression , type CallExpression } from 'estree' ;
54import { AlphaTabWebPackPluginOptions } from './AlphaTabWebPackPluginOptions' ;
6- import { AlphaTabWorkletDependency } from './AlphaTabWorkletDependency' ;
7- import { getWorkerRuntime , parseModuleUrl , tapJavaScript } from './Utils' ;
5+ import { getWorkerRuntime , parseModuleUrl , tapJavaScript , webPackWithAlphaTab , webpackTypes } from './Utils' ;
86
9- const AlphaTabWorkletSpecifierTag = Symbol ( " alphatab worklet specifier tag" ) ;
10- const workletIndexMap = new WeakMap < webpack . ParserState , number > ( ) ;
7+ const AlphaTabWorkletSpecifierTag = Symbol ( ' alphatab worklet specifier tag' ) ;
8+ const workletIndexMap = new WeakMap < webpackTypes . ParserState , number > ( ) ;
119
1210/**
1311 * Configures the Audio Worklet aspects within webpack.
1412 * The counterpart which this plugin detects sits in alphaTab.main.ts
15- * @param pluginName
16- * @param options
17- * @param compiler
18- * @param compilation
19- * @param normalModuleFactory
20- * @param cachedContextify
21- * @returns
13+ * @param pluginName
14+ * @param options
15+ * @param compiler
16+ * @param compilation
17+ * @param normalModuleFactory
18+ * @param cachedContextify
19+ * @returns
2220 */
23- export function configureAudioWorklet ( pluginName : string ,
21+ export function configureAudioWorklet (
22+ webPackWithAlphaTab : webPackWithAlphaTab ,
23+ pluginName : string ,
2424 options : AlphaTabWebPackPluginOptions ,
25- compiler : webpack . Compiler , compilation : webpack . Compilation , normalModuleFactory : any , cachedContextify : ( s : string ) => string ) {
25+ compiler : webpackTypes . Compiler ,
26+ compilation : webpackTypes . Compilation ,
27+ normalModuleFactory : any ,
28+ cachedContextify : ( s : string ) => string
29+ ) {
2630 if ( options . audioWorklets === false ) {
2731 return ;
2832 }
2933
30- compilation . dependencyFactories . set (
31- AlphaTabWorkletDependency ,
32- normalModuleFactory
33- ) ;
34- compilation . dependencyTemplates . set (
35- AlphaTabWorkletDependency ,
36- new AlphaTabWorkletDependency . Template ( )
37- ) ;
34+ webPackWithAlphaTab . alphaTab . registerWorkletDependency ( compilation , normalModuleFactory ) ;
3835
3936 const handleAlphaTabWorklet = ( parser : any , expr : CallExpression ) => {
4037 const [ arg1 ] = expr . arguments ;
@@ -49,7 +46,7 @@ export function configureAudioWorklet(pluginName: string,
4946 }
5047
5148 const runtime = getWorkerRuntime ( parser , compilation , cachedContextify , workletIndexMap ) ;
52- const block = new webpack . AsyncDependenciesBlock ( {
49+ const block = new webPackWithAlphaTab . webpack . AsyncDependenciesBlock ( {
5350 entryOptions : {
5451 chunkLoading : false ,
5552 wasmLoading : false ,
@@ -59,10 +56,10 @@ export function configureAudioWorklet(pluginName: string,
5956
6057 block . loc = expr . loc ;
6158
62- const workletBootstrap = new AlphaTabWorkletDependency (
59+ const workletBootstrap = webPackWithAlphaTab . alphaTab . createWorkletDependency (
6360 url . string ,
6461 [ expr . range ! [ 0 ] , expr . range ! [ 1 ] ] ,
65- compiler . options . output . workerPublicPath ,
62+ compiler . options . output . workerPublicPath
6663 ) ;
6764 workletBootstrap . loc = expr . loc ! ;
6865 block . addDependency ( workletBootstrap ) ;
@@ -72,11 +69,11 @@ export function configureAudioWorklet(pluginName: string,
7269 } ;
7370
7471 const parserPlugin = ( parser : any ) => {
75- const pattern = " alphaTabWorklet" ;
76- const itemMembers = " addModule" ;
72+ const pattern = ' alphaTabWorklet' ;
73+ const itemMembers = ' addModule' ;
7774
7875 parser . hooks . preDeclarator . tap ( pluginName , ( decl : VariableDeclarator ) => {
79- if ( decl . id . type === " Identifier" && decl . id . name === pattern ) {
76+ if ( decl . id . type === ' Identifier' && decl . id . name === pattern ) {
8077 parser . tagVariable ( decl . id . name , AlphaTabWorkletSpecifierTag ) ;
8178 return true ;
8279 }
@@ -90,7 +87,7 @@ export function configureAudioWorklet(pluginName: string,
9087 parser . hooks . callMemberChain
9188 . for ( AlphaTabWorkletSpecifierTag )
9289 . tap ( pluginName , ( expression : CallExpression , members : string [ ] ) => {
93- if ( itemMembers !== members . join ( "." ) ) {
90+ if ( itemMembers !== members . join ( '.' ) ) {
9491 return ;
9592 }
9693 return handleAlphaTabWorklet ( parser , expression ) ;
0 commit comments