@coderline/alphatab-vite 1.7.0-alpha.1612 → 1.7.0-alpha.1625

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.
@@ -0,0 +1,143 @@
1
+ /*!
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1625 (develop, build 1625)
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 Vite (https://github.com/vitejs/vite/), licensed under:
11
+ *
12
+ * MIT License
13
+ * Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * 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
+
41
+ /**
42
+ * @public
43
+ */
44
+ function copyAssetsPlugin(options) {
45
+ let resolvedConfig;
46
+ let output = false;
47
+ return {
48
+ name: 'vite-plugin-alphatab-copy',
49
+ enforce: 'pre',
50
+ configResolved(config) {
51
+ resolvedConfig = config;
52
+ },
53
+ buildEnd() {
54
+ // reset for watch mode
55
+ output = false;
56
+ },
57
+ async buildStart() {
58
+ // run copy only once even if multiple bundles are generated
59
+ if (output) {
60
+ return;
61
+ }
62
+ output = true;
63
+ let alphaTabSourceDir = options.alphaTabSourceDir;
64
+ if (!alphaTabSourceDir) {
65
+ try {
66
+ const isEsm = typeof import.meta.url === 'string';
67
+ if (isEsm) {
68
+ alphaTabSourceDir = url.fileURLToPath(import.meta.resolve('@coderline/alphatab'));
69
+ }
70
+ else {
71
+ alphaTabSourceDir = require.resolve('@coderline/alphatab');
72
+ }
73
+ alphaTabSourceDir = path.resolve(alphaTabSourceDir, '..');
74
+ // walk up to package.json
75
+ while (alphaTabSourceDir) {
76
+ if (await fs.promises
77
+ .access(path.join(alphaTabSourceDir, 'package.json'), fs.constants.F_OK)
78
+ .then(() => true)
79
+ .catch(() => false)) {
80
+ // found package directory
81
+ alphaTabSourceDir = path.resolve(alphaTabSourceDir, 'dist');
82
+ break;
83
+ }
84
+ else {
85
+ // reached root
86
+ const parent = path.resolve(alphaTabSourceDir, '..');
87
+ if (parent === alphaTabSourceDir) {
88
+ alphaTabSourceDir = undefined;
89
+ }
90
+ else {
91
+ alphaTabSourceDir = parent;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ catch {
97
+ alphaTabSourceDir = path.join(resolvedConfig.root, 'node_modules/@coderline/alphatab/dist/');
98
+ }
99
+ }
100
+ let isValidAlphaTabSourceDir;
101
+ if (alphaTabSourceDir) {
102
+ try {
103
+ await fs.promises.access(path.join(alphaTabSourceDir, 'alphaTab.mjs'), fs.constants.F_OK);
104
+ isValidAlphaTabSourceDir = true;
105
+ }
106
+ catch {
107
+ isValidAlphaTabSourceDir = false;
108
+ }
109
+ }
110
+ else {
111
+ isValidAlphaTabSourceDir = false;
112
+ }
113
+ if (!isValidAlphaTabSourceDir) {
114
+ resolvedConfig.logger.error('Could not find alphaTab, please ensure it is installed into node_modules or configure alphaTabSourceDir');
115
+ return;
116
+ }
117
+ const outputPath = (options.assetOutputDir ?? resolvedConfig.publicDir);
118
+ if (!outputPath) {
119
+ return;
120
+ }
121
+ async function copyFiles(subdir) {
122
+ const fullDir = path.join(alphaTabSourceDir, subdir);
123
+ const files = await fs.promises.readdir(fullDir, {
124
+ withFileTypes: true
125
+ });
126
+ await fs.promises.mkdir(path.join(outputPath, subdir), {
127
+ recursive: true
128
+ });
129
+ await Promise.all(files
130
+ .filter(f => f.isFile())
131
+ .map(async (file) => {
132
+ // node v20.12.0 has parentPath pointing to the path (not the file)
133
+ // see https://github.com/nodejs/node/pull/50976
134
+ const sourceFilename = path.join(file.parentPath ?? file.path, file.name);
135
+ await fs.promises.copyFile(sourceFilename, path.join(outputPath, subdir, file.name));
136
+ }));
137
+ }
138
+ await Promise.all([copyFiles('font'), copyFiles('soundfont')]);
139
+ }
140
+ };
141
+ }
142
+
143
+ export { copyAssetsPlugin };
@@ -0,0 +1,5 @@
1
+ import type { AlphaTabVitePluginOptions } from './AlphaTabVitePluginOptions';
2
+ /**
3
+ * @public
4
+ */
5
+ export declare function importMetaUrlPlugin(options: AlphaTabVitePluginOptions): Plugin;
@@ -0,0 +1,197 @@
1
+ /*!
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1625 (develop, build 1625)
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 Vite (https://github.com/vitejs/vite/), licensed under:
11
+ *
12
+ * MIT License
13
+ * Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ *
33
+ * @preserve
34
+ * @license
35
+ */
36
+
37
+ import path__default from 'node:path';
38
+ import MagicString from 'magic-string';
39
+ import { fileToUrl } from './bridge/asset.mjs';
40
+ import { cleanUrl, injectQuery, evalValue } from './bridge/utils.mjs';
41
+ import { tryOptimizedDepResolve } from './bridge/optimizer.mjs';
42
+ import { tryFsResolve } from './bridge/resolve.mjs';
43
+ import { AlphaTabWorkerTypes, workerFileToUrl, WORKER_FILE_ID } from './bridge/worker.mjs';
44
+
45
+ // This file contains a customized and adapted version of the Vite built-in workerImportMetaUrl plugin
46
+ // https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/workerImportMetaUrl.ts
47
+ // The main adaptions are:
48
+ // - Custom syntax detection for workers and audio worklets
49
+ // - Custom worker types and worker URLs to not overlap with the original plugin
50
+ // With https://github.com/vitejs/vite/pull/16422 integrated this custom code should not be needed anymore
51
+ // Original Sources Licensed under:
52
+ // MIT License
53
+ // Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
54
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
55
+ // of this software and associated documentation files (the "Software"), to deal
56
+ // in the Software without restriction, including without limitation the rights
57
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
58
+ // copies of the Software, and to permit persons to whom the Software is
59
+ // furnished to do so, subject to the following conditions:
60
+ // The above copyright notice and this permission notice shall be included in all
61
+ // copies or substantial portions of the Software.
62
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
65
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
67
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
68
+ // SOFTWARE.
69
+ const alphaTabWorkerPatterns = [
70
+ ['alphaTabWorker', 'new', 'alphaTabUrl', 'import.meta.url'],
71
+ ['alphaTabWorklet.addModule', 'new', 'alphaTabUrl', 'import.meta.url']
72
+ ];
73
+ function includesAlphaTabWorker(code) {
74
+ for (const pattern of alphaTabWorkerPatterns) {
75
+ let position = 0;
76
+ for (const match of pattern) {
77
+ position = code.indexOf(match, position);
78
+ if (position === -1) {
79
+ break;
80
+ }
81
+ }
82
+ if (position !== -1) {
83
+ return true;
84
+ }
85
+ }
86
+ return false;
87
+ }
88
+ function getWorkerType(code, match) {
89
+ if (match[1].includes('.addModule')) {
90
+ return AlphaTabWorkerTypes.AudioWorklet;
91
+ }
92
+ const endOfMatch = match.indices[0][1];
93
+ const startOfOptions = code.indexOf('{', endOfMatch);
94
+ if (startOfOptions === -1) {
95
+ return AlphaTabWorkerTypes.WorkerClassic;
96
+ }
97
+ const endOfOptions = code.indexOf('}', endOfMatch);
98
+ if (endOfOptions === -1) {
99
+ return AlphaTabWorkerTypes.WorkerClassic;
100
+ }
101
+ const endOfWorkerCreate = code.indexOf(')', endOfMatch);
102
+ if (startOfOptions > endOfWorkerCreate || endOfOptions > endOfWorkerCreate) {
103
+ return AlphaTabWorkerTypes.WorkerClassic;
104
+ }
105
+ let workerOptions = code.slice(startOfOptions, endOfOptions + 1);
106
+ try {
107
+ workerOptions = evalValue(workerOptions);
108
+ }
109
+ catch {
110
+ return AlphaTabWorkerTypes.WorkerClassic;
111
+ }
112
+ if (typeof workerOptions === 'object' && workerOptions?.type === 'module') {
113
+ return AlphaTabWorkerTypes.WorkerModule;
114
+ }
115
+ return AlphaTabWorkerTypes.WorkerClassic;
116
+ }
117
+ /**
118
+ * @public
119
+ */
120
+ function importMetaUrlPlugin(options) {
121
+ let resolvedConfig;
122
+ let isBuild;
123
+ let preserveSymlinks;
124
+ const isWorkerActive = options.webWorkers !== false;
125
+ const isWorkletActive = options.audioWorklets !== false;
126
+ const isActive = isWorkerActive || isWorkletActive;
127
+ return {
128
+ name: 'vite-plugin-alphatab-url',
129
+ enforce: 'pre',
130
+ configResolved(config) {
131
+ resolvedConfig = config;
132
+ isBuild = config.command === 'build';
133
+ preserveSymlinks = config.resolve.preserveSymlinks;
134
+ },
135
+ shouldTransformCachedModule({ code }) {
136
+ if (isActive && isBuild && resolvedConfig.build.watch && includesAlphaTabWorker(code)) {
137
+ return true;
138
+ }
139
+ return;
140
+ },
141
+ async transform(code, id, options) {
142
+ if (!isActive || options?.ssr || !includesAlphaTabWorker(code)) {
143
+ return;
144
+ }
145
+ let s;
146
+ const alphaTabWorkerPattern = /\b(alphaTabWorker|alphaTabWorklet\.addModule)\s*\(\s*(new\s+[^ (]+alphaTabUrl\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg;
147
+ let match = alphaTabWorkerPattern.exec(code);
148
+ while (match) {
149
+ const workerType = getWorkerType(code, match);
150
+ let typeActive = false;
151
+ switch (workerType) {
152
+ case AlphaTabWorkerTypes.WorkerClassic:
153
+ case AlphaTabWorkerTypes.WorkerModule:
154
+ typeActive = isWorkerActive;
155
+ break;
156
+ case AlphaTabWorkerTypes.AudioWorklet:
157
+ typeActive = isWorkletActive;
158
+ break;
159
+ }
160
+ if (!typeActive) {
161
+ match = alphaTabWorkerPattern.exec(code);
162
+ continue;
163
+ }
164
+ s ??= new MagicString(code);
165
+ const url = code.slice(match.indices[3][0] + 1, match.indices[3][1] - 1);
166
+ let file = path__default.resolve(path__default.dirname(id), url);
167
+ file =
168
+ tryFsResolve(file, preserveSymlinks) ??
169
+ tryOptimizedDepResolve(resolvedConfig, options?.ssr === true, url, id, preserveSymlinks) ??
170
+ file;
171
+ let builtUrl;
172
+ if (isBuild) {
173
+ builtUrl = await workerFileToUrl(resolvedConfig, file);
174
+ }
175
+ else {
176
+ builtUrl = await fileToUrl(cleanUrl(file), resolvedConfig);
177
+ builtUrl = injectQuery(builtUrl, `${WORKER_FILE_ID}&type=${workerType}`);
178
+ }
179
+ s.update(match.indices[3][0], match.indices[3][1],
180
+ // add `'' +` to skip vite:asset-import-meta-url plugin
181
+ `new URL('' + ${JSON.stringify(builtUrl)}, import.meta.url)`);
182
+ match = alphaTabWorkerPattern.exec(code);
183
+ }
184
+ if (s) {
185
+ return {
186
+ code: s.toString(),
187
+ map: resolvedConfig.command === 'build' && resolvedConfig.build.sourcemap
188
+ ? s.generateMap({ hires: 'boundary', source: id })
189
+ : null
190
+ };
191
+ }
192
+ return null;
193
+ }
194
+ };
195
+ }
196
+
197
+ export { importMetaUrlPlugin };
@@ -0,0 +1,5 @@
1
+ import type { AlphaTabVitePluginOptions } from './AlphaTabVitePluginOptions';
2
+ /**
3
+ * @public
4
+ */
5
+ export declare function workerPlugin(options: AlphaTabVitePluginOptions): Plugin;
@@ -0,0 +1,201 @@
1
+ /*!
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1625 (develop, build 1625)
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 Vite (https://github.com/vitejs/vite/), licensed under:
11
+ *
12
+ * MIT License
13
+ * Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ *
33
+ * @preserve
34
+ * @license
35
+ */
36
+
37
+ import * as path from 'node:path';
38
+ import MagicString from 'magic-string';
39
+ import { encodeURIPath } from './bridge/utils.mjs';
40
+ import { createToImportMetaURLBasedRelativeRuntime, toOutputFilePathInJS } from './bridge/build.mjs';
41
+ import { ENV_PUBLIC_PATH } from './bridge/constants.mjs';
42
+ import 'node:fs';
43
+ import 'vite';
44
+ import { workerCache, isSameContent, AlphaTabWorkerTypes, WORKER_ASSET_ID, WORKER_FILE_ID } from './bridge/worker.mjs';
45
+
46
+ // This file contains a customized and adapted version of the Vite built-in worker plugin
47
+ // https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/worker.ts
48
+ // This is more or less a 1:1 copy of the original worker plugin with following adaptions:
49
+ // - Only handle syntax variants known to be used in alphaTab
50
+ // - Use the alphaTab URL markers
51
+ // - Some refactoring for better code understanding
52
+ // With https://github.com/vitejs/vite/pull/16422 integrated this custom code might not be needed anymore
53
+ // Some adjustment for audio worklet in vite might be needed to treat them as type "module" workers
54
+ // Original Sources Licensed under:
55
+ // MIT License
56
+ // Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
57
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
58
+ // of this software and associated documentation files (the "Software"), to deal
59
+ // in the Software without restriction, including without limitation the rights
60
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
+ // copies of the Software, and to permit persons to whom the Software is
62
+ // furnished to do so, subject to the following conditions:
63
+ // The above copyright notice and this permission notice shall be included in all
64
+ // copies or substantial portions of the Software.
65
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
68
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
70
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
71
+ // SOFTWARE.
72
+ const workerFileRE = new RegExp(`(?:\\?|&)${WORKER_FILE_ID}&type=(\\w+)(?:&|$)`);
73
+ const workerAssetUrlRE = new RegExp(`${WORKER_ASSET_ID}([a-z\\d]{8})__`, 'g');
74
+ /**
75
+ * @public
76
+ */
77
+ function workerPlugin(options) {
78
+ let resolvedConfig;
79
+ let isBuild;
80
+ let isWorker;
81
+ const isWorkerActive = options.webWorkers !== false;
82
+ const isWorkletActive = options.audioWorklets !== false;
83
+ const isActive = isWorkerActive || isWorkletActive;
84
+ return {
85
+ name: 'vite-plugin-alphatab-worker',
86
+ configResolved(config) {
87
+ resolvedConfig = config;
88
+ isBuild = config.command === 'build';
89
+ isWorker = config.isWorker;
90
+ },
91
+ buildStart() {
92
+ if (!isActive || isWorker) {
93
+ return;
94
+ }
95
+ workerCache.set(resolvedConfig, {
96
+ assets: new Map(),
97
+ bundle: new Map(),
98
+ fileNameHash: new Map()
99
+ });
100
+ },
101
+ load(id) {
102
+ if (isActive && isBuild && id.includes(WORKER_FILE_ID)) {
103
+ return '';
104
+ }
105
+ return;
106
+ },
107
+ shouldTransformCachedModule({ id }) {
108
+ if (isActive && isBuild && resolvedConfig.build.watch && id.includes(WORKER_FILE_ID)) {
109
+ return true;
110
+ }
111
+ return;
112
+ },
113
+ async transform(raw, id) {
114
+ if (!isActive) {
115
+ return;
116
+ }
117
+ const match = workerFileRE.exec(id);
118
+ if (!match) {
119
+ return;
120
+ }
121
+ // inject env to worker file, might be needed by imported scripts
122
+ const envScriptPath = JSON.stringify(path.posix.join(resolvedConfig.base, ENV_PUBLIC_PATH));
123
+ const workerType = match[1];
124
+ let injectEnv = '';
125
+ switch (workerType) {
126
+ case AlphaTabWorkerTypes.WorkerClassic:
127
+ injectEnv = `importScripts(${envScriptPath})\n`;
128
+ break;
129
+ case AlphaTabWorkerTypes.WorkerModule:
130
+ case AlphaTabWorkerTypes.AudioWorklet:
131
+ injectEnv = `import ${envScriptPath}\n`;
132
+ break;
133
+ }
134
+ if (injectEnv) {
135
+ const s = new MagicString(raw);
136
+ s.prepend(injectEnv);
137
+ return {
138
+ code: s.toString(),
139
+ map: s.generateMap({ hires: 'boundary' })
140
+ };
141
+ }
142
+ return;
143
+ },
144
+ renderChunk(code, chunk, outputOptions) {
145
+ // when building the worker URLs are replaced with some placeholders
146
+ // here we replace those placeholders with the final file names respecting chunks
147
+ let s;
148
+ const result = () => {
149
+ return (s && {
150
+ code: s.toString(),
151
+ map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: 'boundary' }) : null
152
+ });
153
+ };
154
+ workerAssetUrlRE.lastIndex = 0;
155
+ if (workerAssetUrlRE.test(code)) {
156
+ const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(outputOptions.format, resolvedConfig.isWorker);
157
+ s = new MagicString(code);
158
+ workerAssetUrlRE.lastIndex = 0;
159
+ // Replace "VITE_WORKER_ASSET__5aa0ddc0" using relative paths
160
+ const workerMap = workerCache.get(resolvedConfig.mainConfig || resolvedConfig);
161
+ const { fileNameHash } = workerMap;
162
+ let match = workerAssetUrlRE.exec(code);
163
+ while (match) {
164
+ const [full, hash] = match;
165
+ const filename = fileNameHash.get(hash);
166
+ const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', resolvedConfig, toRelativeRuntime);
167
+ const replacementString = typeof replacement === 'string'
168
+ ? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
169
+ : `"+${replacement.runtime}+"`;
170
+ s.update(match.index, match.index + full.length, replacementString);
171
+ match = workerAssetUrlRE.exec(code);
172
+ }
173
+ }
174
+ return result();
175
+ },
176
+ generateBundle(_, bundle) {
177
+ if (isWorker) {
178
+ return;
179
+ }
180
+ const workerMap = workerCache.get(resolvedConfig);
181
+ for (const asset of workerMap.assets.values()) {
182
+ const duplicateAsset = bundle[asset.fileName];
183
+ if (duplicateAsset) {
184
+ const content = duplicateAsset.type === 'asset' ? duplicateAsset.source : duplicateAsset.code;
185
+ // don't emit if the file name and the content is same
186
+ if (isSameContent(content, asset.source)) {
187
+ return;
188
+ }
189
+ }
190
+ this.emitFile({
191
+ type: 'asset',
192
+ fileName: asset.fileName,
193
+ source: asset.source
194
+ });
195
+ }
196
+ workerMap.assets.clear();
197
+ }
198
+ };
199
+ }
200
+
201
+ export { workerPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coderline/alphatab-vite",
3
- "version": "1.7.0-alpha.1612",
3
+ "version": "1.7.0-alpha.1625",
4
4
  "description": "A plugin for Vite to bundle alphaTab into your webapps.",
5
5
  "keywords": [
6
6
  "guitar",
@@ -29,12 +29,16 @@
29
29
  "clean": "rimraf dist",
30
30
  "lint": "biome lint",
31
31
  "typecheck": "tsc --noEmit",
32
- "build": "vite build --mode esm && vite build --mode cjs",
32
+ "build": "vite build",
33
33
  "test": "mocha"
34
34
  },
35
35
  "dependencies": {
36
+ "magic-string": "^0.30.21",
36
37
  "vite": "^7.2.2"
37
38
  },
39
+ "engines": {
40
+ "node": ">=20.19.0"
41
+ },
38
42
  "devDependencies": {
39
43
  "@biomejs/biome": "^2.2.6",
40
44
  "@microsoft/api-extractor": "^7.53.3",
@@ -45,15 +49,15 @@
45
49
  "chai": "^6.2.1",
46
50
  "mocha": "^11.7.5",
47
51
  "rimraf": "^6.1.0",
52
+ "rollup-plugin-node-externals": "^8.1.2",
48
53
  "terser": "^5.44.1",
49
54
  "tslib": "^2.8.1",
50
55
  "tsx": "^4.20.6",
51
56
  "typescript": "^5.9.3"
52
57
  },
53
58
  "files": [
54
- "/dist/alphaTab*.js",
55
- "/dist/alphaTab*.mjs",
56
- "/dist/alphaTab*.ts",
59
+ "/dist/**",
60
+ "!/dist/types",
57
61
  "LICENSE",
58
62
  "LICENSE.header",
59
63
  "README.md"