1
1
/**@target web */
2
- import webpack from 'webpack'
3
2
4
- import { type VariableDeclarator , type Identifier , type Expression , type CallExpression } from 'estree'
3
+ import { type VariableDeclarator , type Identifier , type Expression , type CallExpression } from 'estree' ;
5
4
import { AlphaTabWebPackPluginOptions } from './AlphaTabWebPackPluginOptions' ;
6
- import { AlphaTabWorkletDependency } from './AlphaTabWorkletDependency' ;
7
- import { getWorkerRuntime , parseModuleUrl , tapJavaScript } from './Utils' ;
5
+ import { getWorkerRuntime , parseModuleUrl , tapJavaScript , webPackWithAlphaTab , webpackTypes } from './Utils' ;
8
6
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 > ( ) ;
11
9
12
10
/**
13
11
* Configures the Audio Worklet aspects within webpack.
14
12
* 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
22
20
*/
23
- export function configureAudioWorklet ( pluginName : string ,
21
+ export function configureAudioWorklet (
22
+ webPackWithAlphaTab : webPackWithAlphaTab ,
23
+ pluginName : string ,
24
24
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
+ ) {
26
30
if ( options . audioWorklets === false ) {
27
31
return ;
28
32
}
29
33
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 ) ;
38
35
39
36
const handleAlphaTabWorklet = ( parser : any , expr : CallExpression ) => {
40
37
const [ arg1 ] = expr . arguments ;
@@ -49,7 +46,7 @@ export function configureAudioWorklet(pluginName: string,
49
46
}
50
47
51
48
const runtime = getWorkerRuntime ( parser , compilation , cachedContextify , workletIndexMap ) ;
52
- const block = new webpack . AsyncDependenciesBlock ( {
49
+ const block = new webPackWithAlphaTab . webpack . AsyncDependenciesBlock ( {
53
50
entryOptions : {
54
51
chunkLoading : false ,
55
52
wasmLoading : false ,
@@ -59,10 +56,10 @@ export function configureAudioWorklet(pluginName: string,
59
56
60
57
block . loc = expr . loc ;
61
58
62
- const workletBootstrap = new AlphaTabWorkletDependency (
59
+ const workletBootstrap = webPackWithAlphaTab . alphaTab . createWorkletDependency (
63
60
url . string ,
64
61
[ expr . range ! [ 0 ] , expr . range ! [ 1 ] ] ,
65
- compiler . options . output . workerPublicPath ,
62
+ compiler . options . output . workerPublicPath
66
63
) ;
67
64
workletBootstrap . loc = expr . loc ! ;
68
65
block . addDependency ( workletBootstrap ) ;
@@ -72,11 +69,11 @@ export function configureAudioWorklet(pluginName: string,
72
69
} ;
73
70
74
71
const parserPlugin = ( parser : any ) => {
75
- const pattern = " alphaTabWorklet" ;
76
- const itemMembers = " addModule" ;
72
+ const pattern = ' alphaTabWorklet' ;
73
+ const itemMembers = ' addModule' ;
77
74
78
75
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 ) {
80
77
parser . tagVariable ( decl . id . name , AlphaTabWorkletSpecifierTag ) ;
81
78
return true ;
82
79
}
@@ -90,7 +87,7 @@ export function configureAudioWorklet(pluginName: string,
90
87
parser . hooks . callMemberChain
91
88
. for ( AlphaTabWorkletSpecifierTag )
92
89
. tap ( pluginName , ( expression : CallExpression , members : string [ ] ) => {
93
- if ( itemMembers !== members . join ( "." ) ) {
90
+ if ( itemMembers !== members . join ( '.' ) ) {
94
91
return ;
95
92
}
96
93
return handleAlphaTabWorklet ( parser , expression ) ;
0 commit comments