@coderline/alphatab-webpack 1.7.0-alpha.1617 → 1.7.0-alpha.1626
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AlphaTabAudioWorklet.mjs +114 -0
- package/dist/AlphaTabWebPackPlugin.d.ts +10 -0
- package/dist/AlphaTabWebPackPlugin.mjs +311 -0
- package/dist/AlphaTabWebPackPluginOptions.d.ts +30 -0
- package/dist/AlphaTabWebPackPluginOptions.mjs +36 -0
- package/dist/AlphaTabWebWorker.mjs +101 -0
- package/dist/AlphaTabWebWorkerDependency.mjs +102 -0
- package/dist/AlphaTabWorkerRuntimeModule.mjs +105 -0
- package/dist/AlphaTabWorkletDependency.mjs +123 -0
- package/dist/AlphaTabWorkletStartRuntimeModule.mjs +89 -0
- package/dist/Utils.d.ts +6 -0
- package/dist/Utils.mjs +104 -0
- package/dist/alphaTab.webpack.d.ts +1 -57
- package/dist/alphaTab.webpack.mjs +2 -684
- package/package.json +11 -8
- package/dist/alphaTab.webpack.js +0 -745
- package/dist/alphaTab.webpack.min.mjs +0 -36
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab WebPack Plugin v1.7.0-alpha.1626 (develop, build 1626)
|
|
3
|
+
*
|
|
4
|
+
* Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
7
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
8
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
9
|
+
*
|
|
10
|
+
* This library uses code from WebPack (https://github.com/webpack/webpack/), licensed under:
|
|
11
|
+
*
|
|
12
|
+
* Copyright JS Foundation and other contributors
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
15
|
+
* a copy of this software and associated documentation files (the
|
|
16
|
+
* 'Software'), to deal in the Software without restriction, including
|
|
17
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
18
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
19
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
20
|
+
* the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be
|
|
23
|
+
* included in all copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
26
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
27
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
28
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
29
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
30
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
31
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
32
|
+
*
|
|
33
|
+
* @preserve
|
|
34
|
+
* @license
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { tapJavaScript, parseModuleUrl, getWorkerRuntime } from './Utils.mjs';
|
|
38
|
+
|
|
39
|
+
const AlphaTabWorkletSpecifierTag = Symbol('alphatab worklet specifier tag');
|
|
40
|
+
const workletIndexMap = new WeakMap();
|
|
41
|
+
/**
|
|
42
|
+
* Configures the Audio Worklet aspects within webpack.
|
|
43
|
+
* The counterpart which this plugin detects sits in alphaTab.main.ts
|
|
44
|
+
* @param pluginName
|
|
45
|
+
* @param options
|
|
46
|
+
* @param compiler
|
|
47
|
+
* @param compilation
|
|
48
|
+
* @param normalModuleFactory
|
|
49
|
+
* @param cachedContextify
|
|
50
|
+
* @returns
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
function configureAudioWorklet(webPackWithAlphaTab, pluginName, options, compiler, compilation, normalModuleFactory, cachedContextify) {
|
|
54
|
+
if (options.audioWorklets === false) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
webPackWithAlphaTab.alphaTab.registerWorkletDependency(compilation, normalModuleFactory);
|
|
58
|
+
const handleAlphaTabWorklet = (parser, expr) => {
|
|
59
|
+
const [arg1] = expr.arguments;
|
|
60
|
+
const parsedUrl = parseModuleUrl(parser, arg1);
|
|
61
|
+
if (!parsedUrl) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const [url] = parsedUrl;
|
|
65
|
+
if (!url.isString()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const runtime = getWorkerRuntime(parser, compilation, cachedContextify, workletIndexMap);
|
|
69
|
+
const block = new webPackWithAlphaTab.webpack.AsyncDependenciesBlock({
|
|
70
|
+
entryOptions: {
|
|
71
|
+
chunkLoading: false,
|
|
72
|
+
wasmLoading: false,
|
|
73
|
+
runtime: runtime,
|
|
74
|
+
library: {
|
|
75
|
+
// prevent any built-in/default library settings
|
|
76
|
+
// to be active for this chunk
|
|
77
|
+
type: 'at-worklet'
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
block.loc = expr.loc;
|
|
82
|
+
const workletBootstrap = webPackWithAlphaTab.alphaTab.createWorkletDependency(url.string, [expr.range[0], expr.range[1]], compiler.options.output.workerPublicPath);
|
|
83
|
+
workletBootstrap.loc = expr.loc;
|
|
84
|
+
block.addDependency(workletBootstrap);
|
|
85
|
+
parser.state.module.addBlock(block);
|
|
86
|
+
return true;
|
|
87
|
+
};
|
|
88
|
+
const parserPlugin = (parser) => {
|
|
89
|
+
const pattern = 'alphaTabWorklet';
|
|
90
|
+
const itemMembers = 'addModule';
|
|
91
|
+
parser.hooks.preDeclarator.tap(pluginName, (decl) => {
|
|
92
|
+
if (decl.id.type === 'Identifier' && decl.id.name === pattern) {
|
|
93
|
+
parser.tagVariable(decl.id.name, AlphaTabWorkletSpecifierTag);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
});
|
|
98
|
+
parser.hooks.pattern.for(pattern).tap(pluginName, (pattern) => {
|
|
99
|
+
parser.tagVariable(pattern.name, AlphaTabWorkletSpecifierTag);
|
|
100
|
+
return true;
|
|
101
|
+
});
|
|
102
|
+
parser.hooks.callMemberChain
|
|
103
|
+
.for(AlphaTabWorkletSpecifierTag)
|
|
104
|
+
.tap(pluginName, (expression, members) => {
|
|
105
|
+
if (itemMembers !== members.join('.')) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
return handleAlphaTabWorklet(parser, expression);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
tapJavaScript(normalModuleFactory, pluginName, parserPlugin);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { configureAudioWorklet };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AlphaTabWebPackPluginOptions } from './AlphaTabWebPackPluginOptions';
|
|
2
|
+
import type { webpackTypes } from './Utils';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class AlphaTabWebPackPlugin {
|
|
7
|
+
options: AlphaTabWebPackPluginOptions;
|
|
8
|
+
constructor(options?: AlphaTabWebPackPluginOptions);
|
|
9
|
+
apply(compiler: webpackTypes.Compiler): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab WebPack Plugin v1.7.0-alpha.1626 (develop, build 1626)
|
|
3
|
+
*
|
|
4
|
+
* Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
7
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
8
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
9
|
+
*
|
|
10
|
+
* This library uses code from WebPack (https://github.com/webpack/webpack/), licensed under:
|
|
11
|
+
*
|
|
12
|
+
* Copyright JS Foundation and other contributors
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
15
|
+
* a copy of this software and associated documentation files (the
|
|
16
|
+
* 'Software'), to deal in the Software without restriction, including
|
|
17
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
18
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
19
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
20
|
+
* the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be
|
|
23
|
+
* included in all copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
26
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
27
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
28
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
29
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
30
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
31
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
32
|
+
*
|
|
33
|
+
* @preserve
|
|
34
|
+
* @license
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import fs from 'node:fs';
|
|
38
|
+
import * as path from 'node:path';
|
|
39
|
+
import * as url from 'node:url';
|
|
40
|
+
import { injectWorkerRuntimeModule } from './AlphaTabWorkerRuntimeModule.mjs';
|
|
41
|
+
import { configureAudioWorklet } from './AlphaTabAudioWorklet.mjs';
|
|
42
|
+
import { configureWebWorker } from './AlphaTabWebWorker.mjs';
|
|
43
|
+
import { injectWebWorkerDependency } from './AlphaTabWebWorkerDependency.mjs';
|
|
44
|
+
import { injectWorkletRuntimeModule } from './AlphaTabWorkletStartRuntimeModule.mjs';
|
|
45
|
+
import { injectWorkletDependency } from './AlphaTabWorkletDependency.mjs';
|
|
46
|
+
|
|
47
|
+
/**@target web */
|
|
48
|
+
const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
|
|
49
|
+
const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
|
|
50
|
+
const relativePathToRequest = (relativePath) => {
|
|
51
|
+
if (relativePath === '') {
|
|
52
|
+
return './.';
|
|
53
|
+
}
|
|
54
|
+
if (relativePath === '..') {
|
|
55
|
+
return '../.';
|
|
56
|
+
}
|
|
57
|
+
if (relativePath.startsWith('../')) {
|
|
58
|
+
return relativePath;
|
|
59
|
+
}
|
|
60
|
+
return `./${relativePath}`;
|
|
61
|
+
};
|
|
62
|
+
const absoluteToRequest = (context, maybeAbsolutePath) => {
|
|
63
|
+
if (maybeAbsolutePath[0] === '/') {
|
|
64
|
+
if (maybeAbsolutePath.length > 1 && maybeAbsolutePath[maybeAbsolutePath.length - 1] === '/') {
|
|
65
|
+
// this 'path' is actually a regexp generated by dynamic requires.
|
|
66
|
+
// Don't treat it as an absolute path.
|
|
67
|
+
return maybeAbsolutePath;
|
|
68
|
+
}
|
|
69
|
+
const querySplitPos = maybeAbsolutePath.indexOf('?');
|
|
70
|
+
let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
|
|
71
|
+
resource = relativePathToRequest(path.posix.relative(context, resource));
|
|
72
|
+
return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
|
|
73
|
+
}
|
|
74
|
+
if (WINDOWS_ABS_PATH_REGEXP.test(maybeAbsolutePath)) {
|
|
75
|
+
const querySplitPos = maybeAbsolutePath.indexOf('?');
|
|
76
|
+
let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
|
|
77
|
+
resource = path.win32.relative(context, resource);
|
|
78
|
+
if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) {
|
|
79
|
+
resource = relativePathToRequest(resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, '/'));
|
|
80
|
+
}
|
|
81
|
+
return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
|
|
82
|
+
}
|
|
83
|
+
// not an absolute path
|
|
84
|
+
return maybeAbsolutePath;
|
|
85
|
+
};
|
|
86
|
+
const _contextify = (context, request) => {
|
|
87
|
+
return request
|
|
88
|
+
.split('!')
|
|
89
|
+
.map(r => absoluteToRequest(context, r))
|
|
90
|
+
.join('!');
|
|
91
|
+
};
|
|
92
|
+
const makeCacheableWithContext = (fn) => {
|
|
93
|
+
const cache = new WeakMap();
|
|
94
|
+
const cachedFn = (context, identifier, associatedObjectForCache) => {
|
|
95
|
+
if (!associatedObjectForCache) {
|
|
96
|
+
return fn(context, identifier);
|
|
97
|
+
}
|
|
98
|
+
let innerCache = cache.get(associatedObjectForCache);
|
|
99
|
+
if (innerCache === undefined) {
|
|
100
|
+
innerCache = new Map();
|
|
101
|
+
cache.set(associatedObjectForCache, innerCache);
|
|
102
|
+
}
|
|
103
|
+
let cachedResult;
|
|
104
|
+
let innerSubCache = innerCache.get(context);
|
|
105
|
+
if (innerSubCache === undefined) {
|
|
106
|
+
innerSubCache = new Map();
|
|
107
|
+
innerCache.set(context, innerSubCache);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
cachedResult = innerSubCache.get(identifier);
|
|
111
|
+
}
|
|
112
|
+
if (cachedResult !== undefined) {
|
|
113
|
+
return cachedResult;
|
|
114
|
+
}
|
|
115
|
+
const result = fn(context, identifier);
|
|
116
|
+
innerSubCache.set(identifier, result);
|
|
117
|
+
return result;
|
|
118
|
+
};
|
|
119
|
+
cachedFn.bindContextCache = (context, associatedObjectForCache) => {
|
|
120
|
+
let innerSubCache;
|
|
121
|
+
if (associatedObjectForCache) {
|
|
122
|
+
let innerCache = cache.get(associatedObjectForCache);
|
|
123
|
+
if (innerCache === undefined) {
|
|
124
|
+
innerCache = new Map();
|
|
125
|
+
cache.set(associatedObjectForCache, innerCache);
|
|
126
|
+
}
|
|
127
|
+
innerSubCache = innerCache.get(context);
|
|
128
|
+
if (innerSubCache === undefined) {
|
|
129
|
+
innerSubCache = new Map();
|
|
130
|
+
innerCache.set(context, innerSubCache);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
innerSubCache = new Map();
|
|
135
|
+
}
|
|
136
|
+
const boundFn = (identifier) => {
|
|
137
|
+
const cachedResult = innerSubCache.get(identifier);
|
|
138
|
+
if (cachedResult !== undefined) {
|
|
139
|
+
return cachedResult;
|
|
140
|
+
}
|
|
141
|
+
const result = fn(context, identifier);
|
|
142
|
+
innerSubCache.set(identifier, result);
|
|
143
|
+
return result;
|
|
144
|
+
};
|
|
145
|
+
return boundFn;
|
|
146
|
+
};
|
|
147
|
+
return cachedFn;
|
|
148
|
+
};
|
|
149
|
+
const contextify = makeCacheableWithContext(_contextify);
|
|
150
|
+
/**
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
class AlphaTabWebPackPlugin {
|
|
154
|
+
_webPackWithAlphaTab;
|
|
155
|
+
options;
|
|
156
|
+
constructor(options) {
|
|
157
|
+
this.options = options ?? {};
|
|
158
|
+
}
|
|
159
|
+
apply(compiler) {
|
|
160
|
+
// here we create all plugin related class implementations using
|
|
161
|
+
// the webpack instance provided to this plugin (not as global import)
|
|
162
|
+
// after that we use the helper and factory functions we add to webpack
|
|
163
|
+
const webPackWithAlphaTab = {
|
|
164
|
+
webpack: compiler.webpack,
|
|
165
|
+
alphaTab: {}
|
|
166
|
+
};
|
|
167
|
+
if ('alphaTab' in compiler.webpack.util.serialization.register) {
|
|
168
|
+
// prevent multi registration
|
|
169
|
+
webPackWithAlphaTab.alphaTab = compiler.webpack.util.serialization.register.alphaTab;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
compiler.webpack.util.serialization.register.alphaTab = webPackWithAlphaTab.alphaTab;
|
|
173
|
+
injectWebWorkerDependency(webPackWithAlphaTab);
|
|
174
|
+
injectWorkerRuntimeModule(webPackWithAlphaTab);
|
|
175
|
+
injectWorkletDependency(webPackWithAlphaTab);
|
|
176
|
+
injectWorkletRuntimeModule(webPackWithAlphaTab);
|
|
177
|
+
}
|
|
178
|
+
this._webPackWithAlphaTab = webPackWithAlphaTab;
|
|
179
|
+
this._configureSoundFont(compiler);
|
|
180
|
+
this._configure(compiler);
|
|
181
|
+
}
|
|
182
|
+
_configureSoundFont(compiler) {
|
|
183
|
+
if (this.options.assetOutputDir === false) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// register soundfont as resource
|
|
187
|
+
compiler.options.module.rules.push({
|
|
188
|
+
test: /\.sf2/,
|
|
189
|
+
type: 'asset/resource'
|
|
190
|
+
});
|
|
191
|
+
compiler.options.module.rules.push({
|
|
192
|
+
test: /\.sf3/,
|
|
193
|
+
type: 'asset/resource'
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
_configure(compiler) {
|
|
197
|
+
const pluginName = this.constructor.name;
|
|
198
|
+
const cachedContextify = contextify.bindContextCache(compiler.context, compiler.root);
|
|
199
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation, { normalModuleFactory }) => {
|
|
200
|
+
this._webPackWithAlphaTab.alphaTab.registerWebWorkerRuntimeModule(pluginName, compilation);
|
|
201
|
+
this._webPackWithAlphaTab.alphaTab.registerWorkletRuntimeModule(pluginName, compilation);
|
|
202
|
+
configureAudioWorklet(this._webPackWithAlphaTab, pluginName, this.options, compiler, compilation, normalModuleFactory, cachedContextify);
|
|
203
|
+
configureWebWorker(this._webPackWithAlphaTab, pluginName, this.options, compiler, compilation, normalModuleFactory, cachedContextify);
|
|
204
|
+
this._configureAssetCopy(this._webPackWithAlphaTab, pluginName, compiler, compilation);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
_configureAssetCopy(webPackWithAlphaTab, pluginName, compiler, compilation) {
|
|
208
|
+
if (this.options.assetOutputDir === false) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const options = this.options;
|
|
212
|
+
compilation.hooks.processAssets.tapAsync({
|
|
213
|
+
name: pluginName,
|
|
214
|
+
stage: this._webPackWithAlphaTab.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
215
|
+
}, async (_, callback) => {
|
|
216
|
+
let alphaTabSourceDir = options.alphaTabSourceDir;
|
|
217
|
+
if (!alphaTabSourceDir) {
|
|
218
|
+
try {
|
|
219
|
+
const isEsm = typeof import.meta.url === 'string';
|
|
220
|
+
if (isEsm) {
|
|
221
|
+
alphaTabSourceDir = url.fileURLToPath(import.meta.resolve('@coderline/alphatab'));
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
alphaTabSourceDir = require.resolve('@coderline/alphatab');
|
|
225
|
+
}
|
|
226
|
+
alphaTabSourceDir = path.resolve(alphaTabSourceDir, '..');
|
|
227
|
+
// walk up to package.json
|
|
228
|
+
while (alphaTabSourceDir) {
|
|
229
|
+
if (await fs.promises
|
|
230
|
+
.access(path.join(alphaTabSourceDir, 'package.json'), fs.constants.F_OK)
|
|
231
|
+
.then(() => true)
|
|
232
|
+
.catch(() => false)) {
|
|
233
|
+
// found package directory
|
|
234
|
+
alphaTabSourceDir = path.resolve(alphaTabSourceDir, 'dist');
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
// reached root
|
|
239
|
+
const parent = path.resolve(alphaTabSourceDir, '..');
|
|
240
|
+
if (parent === alphaTabSourceDir) {
|
|
241
|
+
alphaTabSourceDir = undefined;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
alphaTabSourceDir = parent;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
alphaTabSourceDir = compilation.getPath('node_modules/@coderline/alphatab/dist/');
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
let isValidAlphaTabSourceDir;
|
|
254
|
+
if (alphaTabSourceDir) {
|
|
255
|
+
try {
|
|
256
|
+
await fs.promises.access(path.join(alphaTabSourceDir, 'alphaTab.mjs'), fs.constants.F_OK);
|
|
257
|
+
isValidAlphaTabSourceDir = true;
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
isValidAlphaTabSourceDir = false;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
isValidAlphaTabSourceDir = false;
|
|
265
|
+
}
|
|
266
|
+
if (!isValidAlphaTabSourceDir) {
|
|
267
|
+
compilation.errors.push(new this._webPackWithAlphaTab.webpack.WebpackError('Could not find alphaTab, please ensure it is installed into node_modules or configure alphaTabSourceDir'));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const outputPath = (options.assetOutputDir ?? compiler.options.output.path);
|
|
271
|
+
if (!outputPath) {
|
|
272
|
+
compilation.errors.push(new this._webPackWithAlphaTab.webpack.WebpackError('Need output.path configured in application to store asset files.'));
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
async function copyFiles(subdir) {
|
|
276
|
+
const fullDir = path.join(alphaTabSourceDir, subdir);
|
|
277
|
+
compilation.contextDependencies.add(path.normalize(fullDir));
|
|
278
|
+
const files = await fs.promises.readdir(fullDir, { withFileTypes: true });
|
|
279
|
+
await fs.promises.mkdir(path.join(outputPath, subdir), { recursive: true });
|
|
280
|
+
await Promise.all(files
|
|
281
|
+
.filter(f => f.isFile())
|
|
282
|
+
.map(async (file) => {
|
|
283
|
+
// node v20.12.0 has parentPath pointing to the path (not the file)
|
|
284
|
+
// see https://github.com/nodejs/node/pull/50976
|
|
285
|
+
const sourceFilename = path.join(file.parentPath ?? file.path, file.name);
|
|
286
|
+
await fs.promises.copyFile(sourceFilename, path.join(outputPath, subdir, file.name));
|
|
287
|
+
const assetFileName = `${subdir}/${file.name}`;
|
|
288
|
+
const existingAsset = compilation.getAsset(assetFileName);
|
|
289
|
+
const data = await fs.promises.readFile(sourceFilename);
|
|
290
|
+
const source = new webPackWithAlphaTab.webpack.sources.RawSource(data);
|
|
291
|
+
if (existingAsset) {
|
|
292
|
+
compilation.updateAsset(assetFileName, source, {
|
|
293
|
+
copied: true,
|
|
294
|
+
sourceFilename
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
compilation.emitAsset(assetFileName, source, {
|
|
299
|
+
copied: true,
|
|
300
|
+
sourceFilename
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
await Promise.all([copyFiles('font'), copyFiles('soundfont')]);
|
|
306
|
+
callback();
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export { AlphaTabWebPackPlugin };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export interface AlphaTabWebPackPluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The location where alphaTab can be found.
|
|
7
|
+
* (default: node_modules/@coderline/alphatab/dist)
|
|
8
|
+
*/
|
|
9
|
+
alphaTabSourceDir?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The location where assets of alphaTab should be placed.
|
|
12
|
+
* Set it to false to disable the copying of assets like fonts.
|
|
13
|
+
* (default: compiler.options.output.path)
|
|
14
|
+
*/
|
|
15
|
+
assetOutputDir?: string | false;
|
|
16
|
+
/**
|
|
17
|
+
* Whether alphaTab should configure the audio worklet support in WebPack.
|
|
18
|
+
* This might break support for audio playback unless audio worklet support is added
|
|
19
|
+
* through other means to WebPack.
|
|
20
|
+
* (default: true)
|
|
21
|
+
*/
|
|
22
|
+
audioWorklets?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether alphaTab should configure the web worklet support in WebPack.
|
|
25
|
+
* This might break support for audio playback and background unless audio worklet support is added
|
|
26
|
+
* through other means to WebPack.
|
|
27
|
+
* (default: true)
|
|
28
|
+
*/
|
|
29
|
+
webWorkers?: boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab WebPack Plugin v1.7.0-alpha.1626 (develop, build 1626)
|
|
3
|
+
*
|
|
4
|
+
* Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
7
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
8
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
9
|
+
*
|
|
10
|
+
* This library uses code from WebPack (https://github.com/webpack/webpack/), licensed under:
|
|
11
|
+
*
|
|
12
|
+
* Copyright JS Foundation and other contributors
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
15
|
+
* a copy of this software and associated documentation files (the
|
|
16
|
+
* 'Software'), to deal in the Software without restriction, including
|
|
17
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
18
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
19
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
20
|
+
* the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be
|
|
23
|
+
* included in all copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
26
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
27
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
28
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
29
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
30
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
31
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
32
|
+
*
|
|
33
|
+
* @preserve
|
|
34
|
+
* @license
|
|
35
|
+
*/
|
|
36
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab WebPack Plugin v1.7.0-alpha.1626 (develop, build 1626)
|
|
3
|
+
*
|
|
4
|
+
* Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
7
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
8
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
9
|
+
*
|
|
10
|
+
* This library uses code from WebPack (https://github.com/webpack/webpack/), licensed under:
|
|
11
|
+
*
|
|
12
|
+
* Copyright JS Foundation and other contributors
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
15
|
+
* a copy of this software and associated documentation files (the
|
|
16
|
+
* 'Software'), to deal in the Software without restriction, including
|
|
17
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
18
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
19
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
20
|
+
* the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be
|
|
23
|
+
* included in all copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
26
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
27
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
28
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
29
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
30
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
31
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
32
|
+
*
|
|
33
|
+
* @preserve
|
|
34
|
+
* @license
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { tapJavaScript, parseModuleUrl, getWorkerRuntime } from './Utils.mjs';
|
|
38
|
+
|
|
39
|
+
const workerIndexMap = new WeakMap();
|
|
40
|
+
/**
|
|
41
|
+
* Configures the WebWorker aspects within webpack.
|
|
42
|
+
* The counterpart which this plugin detects sits in alphaTab.main.ts
|
|
43
|
+
* @param pluginName
|
|
44
|
+
* @param options
|
|
45
|
+
* @param compiler
|
|
46
|
+
* @param compilation
|
|
47
|
+
* @param normalModuleFactory
|
|
48
|
+
* @param cachedContextify
|
|
49
|
+
* @returns
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
function configureWebWorker(webPackWithAlphaTab, pluginName, options, compiler, compilation, normalModuleFactory, cachedContextify) {
|
|
53
|
+
if (options.audioWorklets === false) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
webPackWithAlphaTab.alphaTab.registerWebWorkerDependency(compilation, normalModuleFactory);
|
|
57
|
+
new webPackWithAlphaTab.webpack.javascript.EnableChunkLoadingPlugin('import-scripts').apply(compiler);
|
|
58
|
+
const handleAlphaTabWorker = (parser, expr) => {
|
|
59
|
+
const [arg1, arg2] = expr.arguments;
|
|
60
|
+
const parsedUrl = parseModuleUrl(parser, arg1);
|
|
61
|
+
if (!parsedUrl) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const [url, range] = parsedUrl;
|
|
65
|
+
if (!url.isString()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const runtime = getWorkerRuntime(parser, compilation, cachedContextify, workerIndexMap);
|
|
69
|
+
const block = new webPackWithAlphaTab.webpack.AsyncDependenciesBlock({
|
|
70
|
+
entryOptions: {
|
|
71
|
+
chunkLoading: 'import-scripts',
|
|
72
|
+
wasmLoading: false,
|
|
73
|
+
runtime: runtime,
|
|
74
|
+
library: {
|
|
75
|
+
// prevent any built-in/default library settings
|
|
76
|
+
// to be active for this chunk
|
|
77
|
+
type: 'at-worker'
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
block.loc = expr.loc;
|
|
82
|
+
const workletBootstrap = webPackWithAlphaTab.alphaTab.createWebWorkerDependency(url.string, range, compiler.options.output.workerPublicPath);
|
|
83
|
+
workletBootstrap.loc = expr.loc;
|
|
84
|
+
block.addDependency(workletBootstrap);
|
|
85
|
+
parser.state.module.addBlock(block);
|
|
86
|
+
const dep1 = new webPackWithAlphaTab.webpack.dependencies.ConstDependency(`{ type: ${compilation.options.output.module ? '"module"' : 'undefined'} }`, arg2.range);
|
|
87
|
+
dep1.loc = expr.loc;
|
|
88
|
+
parser.state.module.addPresentationalDependency(dep1);
|
|
89
|
+
parser.walkExpression(expr.callee);
|
|
90
|
+
parser.walkExpression(arg1.callee);
|
|
91
|
+
return true;
|
|
92
|
+
};
|
|
93
|
+
const parserPlugin = (parser) => {
|
|
94
|
+
parser.hooks.new
|
|
95
|
+
.for('alphaTab.Environment.alphaTabWorker')
|
|
96
|
+
.tap(pluginName, (expr) => handleAlphaTabWorker(parser, expr));
|
|
97
|
+
};
|
|
98
|
+
tapJavaScript(normalModuleFactory, pluginName, parserPlugin);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { configureWebWorker };
|