@coderline/alphatab-vite 1.7.0-alpha.1628 → 1.7.0-alpha.1629
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/AlphaTabVitePluginOptions.cjs +38 -0
- package/dist/AlphaTabVitePluginOptions.mjs +1 -1
- package/dist/alphaTab.vite.cjs +45 -0
- package/dist/alphaTab.vite.mjs +1 -1
- package/dist/alphaTabVitePlugin.cjs +57 -0
- package/dist/alphaTabVitePlugin.mjs +1 -1
- package/dist/bridge/asset.cjs +87 -0
- package/dist/bridge/asset.mjs +1 -1
- package/dist/bridge/build.cjs +242 -0
- package/dist/bridge/build.mjs +1 -1
- package/dist/bridge/config.cjs +38 -0
- package/dist/bridge/config.mjs +1 -1
- package/dist/bridge/constants.cjs +88 -0
- package/dist/bridge/constants.mjs +1 -1
- package/dist/bridge/fsUtils.cjs +60 -0
- package/dist/bridge/fsUtils.mjs +1 -1
- package/dist/bridge/index.cjs +69 -0
- package/dist/bridge/index.mjs +1 -1
- package/dist/bridge/optimizer.cjs +172 -0
- package/dist/bridge/optimizer.mjs +1 -1
- package/dist/bridge/plugins.cjs +51 -0
- package/dist/bridge/plugins.mjs +1 -1
- package/dist/bridge/resolve.cjs +75 -0
- package/dist/bridge/resolve.mjs +1 -1
- package/dist/bridge/typeUtils.cjs +38 -0
- package/dist/bridge/typeUtils.mjs +1 -1
- package/dist/bridge/utils.cjs +164 -0
- package/dist/bridge/utils.mjs +1 -1
- package/dist/bridge/worker.cjs +207 -0
- package/dist/bridge/worker.mjs +1 -1
- package/dist/copyAssetsPlugin.cjs +168 -0
- package/dist/copyAssetsPlugin.mjs +1 -1
- package/dist/importMetaPlugin.cjs +201 -0
- package/dist/importMetaPlugin.mjs +1 -1
- package/dist/workerPlugin.cjs +224 -0
- package/dist/workerPlugin.mjs +1 -1
- package/package.json +13 -4
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab Vite Plugin v1.7.0-alpha.1629 (develop, build 1629)
|
|
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
|
+
'use strict';
|
|
38
|
+
|
|
39
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
40
|
+
|
|
41
|
+
const path = require('node:path');
|
|
42
|
+
const MagicString = require('magic-string');
|
|
43
|
+
const bridge_utils = require('./bridge/utils.cjs');
|
|
44
|
+
const bridge_build = require('./bridge/build.cjs');
|
|
45
|
+
const bridge_constants = require('./bridge/constants.cjs');
|
|
46
|
+
require('node:fs');
|
|
47
|
+
require('vite');
|
|
48
|
+
const bridge_worker = require('./bridge/worker.cjs');
|
|
49
|
+
|
|
50
|
+
function _interopNamespaceDefault(e) {
|
|
51
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
52
|
+
if (e) {
|
|
53
|
+
for (const k in e) {
|
|
54
|
+
if (k !== 'default') {
|
|
55
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
56
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: () => e[k]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
n.default = e;
|
|
64
|
+
return Object.freeze(n);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
68
|
+
|
|
69
|
+
// This file contains a customized and adapted version of the Vite built-in worker plugin
|
|
70
|
+
// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/worker.ts
|
|
71
|
+
// This is more or less a 1:1 copy of the original worker plugin with following adaptions:
|
|
72
|
+
// - Only handle syntax variants known to be used in alphaTab
|
|
73
|
+
// - Use the alphaTab URL markers
|
|
74
|
+
// - Some refactoring for better code understanding
|
|
75
|
+
// With https://github.com/vitejs/vite/pull/16422 integrated this custom code might not be needed anymore
|
|
76
|
+
// Some adjustment for audio worklet in vite might be needed to treat them as type "module" workers
|
|
77
|
+
// Original Sources Licensed under:
|
|
78
|
+
// MIT License
|
|
79
|
+
// Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
|
80
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
81
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
82
|
+
// in the Software without restriction, including without limitation the rights
|
|
83
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
84
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
85
|
+
// furnished to do so, subject to the following conditions:
|
|
86
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
87
|
+
// copies or substantial portions of the Software.
|
|
88
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
89
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
90
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
91
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
92
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
93
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
94
|
+
// SOFTWARE.
|
|
95
|
+
const workerFileRE = new RegExp(`(?:\\?|&)${bridge_worker.WORKER_FILE_ID}&type=(\\w+)(?:&|$)`);
|
|
96
|
+
const workerAssetUrlRE = new RegExp(`${bridge_worker.WORKER_ASSET_ID}([a-z\\d]{8})__`, 'g');
|
|
97
|
+
/**
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
function workerPlugin(options) {
|
|
101
|
+
let resolvedConfig;
|
|
102
|
+
let isBuild;
|
|
103
|
+
let isWorker;
|
|
104
|
+
const isWorkerActive = options.webWorkers !== false;
|
|
105
|
+
const isWorkletActive = options.audioWorklets !== false;
|
|
106
|
+
const isActive = isWorkerActive || isWorkletActive;
|
|
107
|
+
return {
|
|
108
|
+
name: 'vite-plugin-alphatab-worker',
|
|
109
|
+
configResolved(config) {
|
|
110
|
+
resolvedConfig = config;
|
|
111
|
+
isBuild = config.command === 'build';
|
|
112
|
+
isWorker = config.isWorker;
|
|
113
|
+
},
|
|
114
|
+
buildStart() {
|
|
115
|
+
if (!isActive || isWorker) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
bridge_worker.workerCache.set(resolvedConfig, {
|
|
119
|
+
assets: new Map(),
|
|
120
|
+
bundle: new Map(),
|
|
121
|
+
fileNameHash: new Map()
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
load(id) {
|
|
125
|
+
if (isActive && isBuild && id.includes(bridge_worker.WORKER_FILE_ID)) {
|
|
126
|
+
return '';
|
|
127
|
+
}
|
|
128
|
+
return;
|
|
129
|
+
},
|
|
130
|
+
shouldTransformCachedModule({ id }) {
|
|
131
|
+
if (isActive && isBuild && resolvedConfig.build.watch && id.includes(bridge_worker.WORKER_FILE_ID)) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
},
|
|
136
|
+
async transform(raw, id) {
|
|
137
|
+
if (!isActive) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const match = workerFileRE.exec(id);
|
|
141
|
+
if (!match) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
// inject env to worker file, might be needed by imported scripts
|
|
145
|
+
const envScriptPath = JSON.stringify(path__namespace.posix.join(resolvedConfig.base, bridge_constants.ENV_PUBLIC_PATH));
|
|
146
|
+
const workerType = match[1];
|
|
147
|
+
let injectEnv = '';
|
|
148
|
+
switch (workerType) {
|
|
149
|
+
case bridge_worker.AlphaTabWorkerTypes.WorkerClassic:
|
|
150
|
+
injectEnv = `importScripts(${envScriptPath})\n`;
|
|
151
|
+
break;
|
|
152
|
+
case bridge_worker.AlphaTabWorkerTypes.WorkerModule:
|
|
153
|
+
case bridge_worker.AlphaTabWorkerTypes.AudioWorklet:
|
|
154
|
+
injectEnv = `import ${envScriptPath}\n`;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (injectEnv) {
|
|
158
|
+
const s = new MagicString(raw);
|
|
159
|
+
s.prepend(injectEnv);
|
|
160
|
+
return {
|
|
161
|
+
code: s.toString(),
|
|
162
|
+
map: s.generateMap({ hires: 'boundary' })
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
},
|
|
167
|
+
renderChunk(code, chunk, outputOptions) {
|
|
168
|
+
// when building the worker URLs are replaced with some placeholders
|
|
169
|
+
// here we replace those placeholders with the final file names respecting chunks
|
|
170
|
+
let s;
|
|
171
|
+
const result = () => {
|
|
172
|
+
return (s && {
|
|
173
|
+
code: s.toString(),
|
|
174
|
+
map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: 'boundary' }) : null
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
workerAssetUrlRE.lastIndex = 0;
|
|
178
|
+
if (workerAssetUrlRE.test(code)) {
|
|
179
|
+
const toRelativeRuntime = bridge_build.createToImportMetaURLBasedRelativeRuntime(outputOptions.format, resolvedConfig.isWorker);
|
|
180
|
+
s = new MagicString(code);
|
|
181
|
+
workerAssetUrlRE.lastIndex = 0;
|
|
182
|
+
// Replace "VITE_WORKER_ASSET__5aa0ddc0" using relative paths
|
|
183
|
+
const workerMap = bridge_worker.workerCache.get(resolvedConfig.mainConfig || resolvedConfig);
|
|
184
|
+
const { fileNameHash } = workerMap;
|
|
185
|
+
let match = workerAssetUrlRE.exec(code);
|
|
186
|
+
while (match) {
|
|
187
|
+
const [full, hash] = match;
|
|
188
|
+
const filename = fileNameHash.get(hash);
|
|
189
|
+
const replacement = bridge_build.toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', resolvedConfig, toRelativeRuntime);
|
|
190
|
+
const replacementString = typeof replacement === 'string'
|
|
191
|
+
? JSON.stringify(bridge_utils.encodeURIPath(replacement)).slice(1, -1)
|
|
192
|
+
: `"+${replacement.runtime}+"`;
|
|
193
|
+
s.update(match.index, match.index + full.length, replacementString);
|
|
194
|
+
match = workerAssetUrlRE.exec(code);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return result();
|
|
198
|
+
},
|
|
199
|
+
generateBundle(_, bundle) {
|
|
200
|
+
if (isWorker) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const workerMap = bridge_worker.workerCache.get(resolvedConfig);
|
|
204
|
+
for (const asset of workerMap.assets.values()) {
|
|
205
|
+
const duplicateAsset = bundle[asset.fileName];
|
|
206
|
+
if (duplicateAsset) {
|
|
207
|
+
const content = duplicateAsset.type === 'asset' ? duplicateAsset.source : duplicateAsset.code;
|
|
208
|
+
// don't emit if the file name and the content is same
|
|
209
|
+
if (bridge_worker.isSameContent(content, asset.source)) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
this.emitFile({
|
|
214
|
+
type: 'asset',
|
|
215
|
+
fileName: asset.fileName,
|
|
216
|
+
source: asset.source
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
workerMap.assets.clear();
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
exports.workerPlugin = workerPlugin;
|
package/dist/workerPlugin.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderline/alphatab-vite",
|
|
3
|
-
"version": "1.7.0-alpha.
|
|
3
|
+
"version": "1.7.0-alpha.1629",
|
|
4
4
|
"description": "A plugin for Vite to bundle alphaTab into your webapps.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"guitar",
|
|
@@ -22,9 +22,18 @@
|
|
|
22
22
|
"url": "git+https://github.com/coderline/alphaTab.git"
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"require": "./dist/alphaTab.vite.cjs",
|
|
28
|
+
"import": "./dist/alphaTab.vite.mjs",
|
|
29
|
+
"types": "./dist/alphaTab.vite.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./*": {
|
|
32
|
+
"require": "./dist/*.cjs",
|
|
33
|
+
"import": "./dist/*.mjs",
|
|
34
|
+
"types": "./dist/*.d.ts"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
28
37
|
"scripts": {
|
|
29
38
|
"clean": "rimraf dist",
|
|
30
39
|
"lint": "biome lint",
|