@coderline/alphatab-vite 1.8.1 → 1.8.3

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.
Files changed (47) hide show
  1. package/dist/AlphaTabVitePluginOptions.cjs +34 -37
  2. package/dist/AlphaTabVitePluginOptions.mjs +34 -35
  3. package/dist/alphaTab.vite.cjs +37 -44
  4. package/dist/alphaTab.vite.mjs +36 -36
  5. package/dist/alphaTabVitePlugin.cjs +50 -54
  6. package/dist/alphaTabVitePlugin.mjs +49 -50
  7. package/dist/bridge/asset.cjs +50 -80
  8. package/dist/bridge/asset.mjs +47 -57
  9. package/dist/bridge/build.cjs +152 -214
  10. package/dist/bridge/build.mjs +149 -191
  11. package/dist/bridge/bundler.cjs +54 -0
  12. package/dist/bridge/bundler.mjs +52 -0
  13. package/dist/bridge/config.cjs +34 -37
  14. package/dist/bridge/config.mjs +34 -35
  15. package/dist/bridge/constants.cjs +73 -80
  16. package/dist/bridge/constants.mjs +72 -76
  17. package/dist/bridge/fsUtils.cjs +46 -55
  18. package/dist/bridge/fsUtils.mjs +43 -51
  19. package/dist/bridge/index.cjs +58 -68
  20. package/dist/bridge/index.mjs +42 -42
  21. package/dist/bridge/optimizer.cjs +112 -155
  22. package/dist/bridge/optimizer.mjs +108 -132
  23. package/dist/bridge/plugins.cjs +39 -45
  24. package/dist/bridge/plugins.mjs +38 -41
  25. package/dist/bridge/resolve.cjs +54 -66
  26. package/dist/bridge/resolve.mjs +53 -62
  27. package/dist/bridge/typeUtils.cjs +34 -37
  28. package/dist/bridge/typeUtils.mjs +34 -35
  29. package/dist/bridge/utils.cjs +87 -121
  30. package/dist/bridge/utils.mjs +84 -117
  31. package/dist/bridge/worker.cjs +179 -183
  32. package/dist/bridge/worker.mjs +175 -160
  33. package/dist/chunk.cjs +63 -0
  34. package/dist/copyAssetsPlugin.cjs +102 -163
  35. package/dist/copyAssetsPlugin.mjs +35 -141
  36. package/dist/copyAssetsPlugin2.mjs +108 -0
  37. package/dist/detectionGlobalPlugin.cjs +65 -68
  38. package/dist/detectionGlobalPlugin.mjs +62 -64
  39. package/dist/dist.cjs +6595 -0
  40. package/dist/dist.mjs +6589 -0
  41. package/dist/importMetaPlugin.cjs +147 -192
  42. package/dist/importMetaPlugin.mjs +143 -188
  43. package/dist/prompt-DewH0PjV.cjs +885 -0
  44. package/dist/prompt-DewH0PjV.mjs +882 -0
  45. package/dist/workerPlugin.cjs +145 -219
  46. package/dist/workerPlugin.mjs +141 -196
  47. package/package.json +17 -17
@@ -1,151 +1,118 @@
1
1
  /*!
2
- * alphaTab Vite Plugin v1.8.1 (, build 30)
3
- *
4
- * Copyright © 2026, 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 { createHash } from 'node:crypto';
39
-
40
- // index.ts for more details on contents and license of this file
41
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1302
2
+ * alphaTab Vite Plugin v1.8.3 (, build 32)
3
+ *
4
+ * Copyright © 2026, 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
+ import fs from "node:fs";
37
+ import { createHash } from "node:crypto";
38
+ //#region src/bridge/utils.ts
42
39
  /**
43
- * @internal
44
- */
40
+ * @internal
41
+ */
45
42
  function evalValue(rawValue) {
46
- const fn = new Function(`
43
+ return new Function(`
47
44
  var console, exports, global, module, process, require
48
45
  return (\n${rawValue}\n)
49
- `);
50
- return fn();
46
+ `)();
51
47
  }
52
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/shared/utils.ts#L31-L34
53
- const postfixRE = /[?#].*$/;
48
+ var postfixRE = /[?#].*$/;
54
49
  /**
55
- * @internal
56
- */
50
+ * @internal
51
+ */
57
52
  function cleanUrl(url) {
58
- return url.replace(postfixRE, '');
53
+ return url.replace(postfixRE, "");
59
54
  }
60
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L393
61
55
  /**
62
- * @internal
63
- */
56
+ * @internal
57
+ */
64
58
  function tryStatSync(file) {
65
- try {
66
- // The "throwIfNoEntry" is a performance optimization for cases where the file does not exist
67
- return fs.statSync(file, { throwIfNoEntry: false });
68
- }
69
- catch {
70
- // Ignore errors
71
- }
72
- return;
59
+ try {
60
+ return fs.statSync(file, { throwIfNoEntry: false });
61
+ } catch {}
73
62
  }
74
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1030
75
63
  /**
76
- * @internal
77
- */
64
+ * @internal
65
+ */
78
66
  function getHash(text, length = 8) {
79
- const h = createHash('sha256').update(text).digest('hex').substring(0, length);
80
- if (length <= 64) {
81
- return h;
82
- }
83
- return h.padEnd(length, '_');
67
+ const h = createHash("sha256").update(text).digest("hex").substring(0, length);
68
+ if (length <= 64) return h;
69
+ return h.padEnd(length, "_");
84
70
  }
85
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/shared/utils.ts#L40
86
71
  /**
87
- * @internal
88
- */
72
+ * @internal
73
+ */
89
74
  function withTrailingSlash(path) {
90
- if (path[path.length - 1] !== '/') {
91
- return `${path}/`;
92
- }
93
- return path;
75
+ if (path[path.length - 1] !== "/") return `${path}/`;
76
+ return path;
94
77
  }
95
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1268
96
78
  /**
97
- * @internal
98
- */
79
+ * @internal
80
+ */
99
81
  function joinUrlSegments(a, b) {
100
- if (!a || !b) {
101
- return a || b || '';
102
- }
103
- if (a[a.length - 1] === '/') {
104
- a = a.substring(0, a.length - 1);
105
- }
106
- if (b[0] !== '/') {
107
- b = `/${b}`;
108
- }
109
- return a + b;
82
+ if (!a || !b) return a || b || "";
83
+ if (a[a.length - 1] === "/") a = a.substring(0, a.length - 1);
84
+ if (b[0] !== "/") b = `/${b}`;
85
+ return a + b;
110
86
  }
111
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1281
112
87
  /**
113
- * @internal
114
- */
88
+ * @internal
89
+ */
115
90
  function removeLeadingSlash(str) {
116
- return str[0] === '/' ? str.slice(1) : str;
91
+ return str[0] === "/" ? str.slice(1) : str;
117
92
  }
118
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L319
119
93
  /**
120
- * @internal
121
- */
94
+ * @internal
95
+ */
122
96
  function injectQuery(builtUrl, query) {
123
- const queryIndex = builtUrl.indexOf('?');
124
- return builtUrl + (queryIndex === -1 ? '?' : '&') + query;
97
+ return builtUrl + (builtUrl.indexOf("?") === -1 ? "?" : "&") + query;
125
98
  }
126
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1435
127
99
  /**
128
- * @internal
129
- */
100
+ * @internal
101
+ */
130
102
  function partialEncodeURIPath(uri) {
131
- if (uri.startsWith('data:')) {
132
- return uri;
133
- }
134
- const filePath = cleanUrl(uri);
135
- const postfix = filePath !== uri ? uri.slice(filePath.length) : '';
136
- return filePath.replaceAll('%', '%25') + postfix;
103
+ if (uri.startsWith("data:")) return uri;
104
+ const filePath = cleanUrl(uri);
105
+ const postfix = filePath !== uri ? uri.slice(filePath.length) : "";
106
+ return filePath.replaceAll("%", "%25") + postfix;
137
107
  }
138
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1424
139
108
  /**
140
- * @internal
141
- */
109
+ * @internal
110
+ */
142
111
  function encodeURIPath(uri) {
143
- if (uri.startsWith('data:')) {
144
- return uri;
145
- }
146
- const filePath = cleanUrl(uri);
147
- const postfix = filePath !== uri ? uri.slice(filePath.length) : '';
148
- return encodeURI(filePath) + postfix;
112
+ if (uri.startsWith("data:")) return uri;
113
+ const filePath = cleanUrl(uri);
114
+ const postfix = filePath !== uri ? uri.slice(filePath.length) : "";
115
+ return encodeURI(filePath) + postfix;
149
116
  }
150
-
117
+ //#endregion
151
118
  export { cleanUrl, encodeURIPath, evalValue, getHash, injectQuery, joinUrlSegments, partialEncodeURIPath, removeLeadingSlash, tryStatSync, withTrailingSlash };
@@ -1,205 +1,201 @@
1
1
  /*!
2
- * alphaTab Vite Plugin v1.8.1 (, build 30)
3
- *
4
- * Copyright © 2026, 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 bridge_utils = require('./utils.cjs');
42
- const path = require('node:path');
43
- const vite = require('vite');
44
- const bridge_build = require('./build.cjs');
45
-
46
- function _interopNamespaceDefault(e) {
47
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
48
- if (e) {
49
- for (const k in e) {
50
- if (k !== 'default') {
51
- const d = Object.getOwnPropertyDescriptor(e, k);
52
- Object.defineProperty(n, k, d.get ? d : {
53
- enumerable: true,
54
- get: () => e[k]
55
- });
56
- }
57
- }
58
- }
59
- n.default = e;
60
- return Object.freeze(n);
61
- }
62
-
63
- const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
64
-
65
- // index.ts for more details on contents and license of this file
2
+ * alphaTab Vite Plugin v1.8.3 (, build 32)
3
+ *
4
+ * Copyright © 2026, 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
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
37
+ const require_chunk = require("../chunk.cjs");
38
+ const require_bridge_utils = require("./utils.cjs");
39
+ const require_bridge_build = require("./build.cjs");
40
+ const require_bridge_bundler = require("./bundler.cjs");
41
+ let node_path = require("node:path");
42
+ node_path = require_chunk.__toESM(node_path, 1);
43
+ let vite = require("vite");
44
+ //#region src/bridge/worker.ts
66
45
  /**
67
- * @internal
68
- */
69
- // biome-ignore lint/suspicious/noConstEnum: Exception where we use them
70
- exports.AlphaTabWorkerTypes = void 0;
71
- (function (AlphaTabWorkerTypes) {
72
- AlphaTabWorkerTypes["WorkerClassic"] = "worker_classic";
73
- AlphaTabWorkerTypes["WorkerModule"] = "worker_module";
74
- AlphaTabWorkerTypes["AudioWorklet"] = "audio_worklet";
75
- })(exports.AlphaTabWorkerTypes || (exports.AlphaTabWorkerTypes = {}));
46
+ * @internal
47
+ */
48
+ var AlphaTabWorkerTypes = /* @__PURE__ */ function(AlphaTabWorkerTypes) {
49
+ AlphaTabWorkerTypes["WorkerClassic"] = "worker_classic";
50
+ AlphaTabWorkerTypes["WorkerModule"] = "worker_module";
51
+ AlphaTabWorkerTypes["AudioWorklet"] = "audio_worklet";
52
+ return AlphaTabWorkerTypes;
53
+ }({});
76
54
  /**
77
- * @internal
78
- */
79
- const workerCache = new WeakMap();
55
+ * @internal
56
+ */
57
+ var workerCache = /* @__PURE__ */ new WeakMap();
80
58
  /**
81
- * @internal
82
- */
83
- const WORKER_FILE_ID = 'alphatab_worker';
59
+ * @internal
60
+ */
61
+ var WORKER_FILE_ID = "alphatab_worker";
84
62
  /**
85
- * @internal
86
- */
87
- const WORKER_ASSET_ID = '__ALPHATAB_WORKER_ASSET__';
88
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L47
63
+ * @internal
64
+ */
65
+ var WORKER_ASSET_ID = "__ALPHATAB_WORKER_ASSET__";
89
66
  function saveEmitWorkerAsset(config, asset) {
90
- const workerMap = workerCache.get(config.mainConfig || config);
91
- workerMap.assets.set(asset.fileName, asset);
67
+ workerCache.get(config.mainConfig || config).assets.set(asset.fileName, asset);
92
68
  }
93
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L161
94
69
  /**
95
- * @internal
96
- */
70
+ * @internal
71
+ */
97
72
  async function workerFileToUrl(config, id) {
98
- const workerMap = workerCache.get(config.mainConfig || config);
99
- let fileName = workerMap.bundle.get(id);
100
- if (!fileName) {
101
- const outputChunk = await bundleWorkerEntry(config, id);
102
- fileName = outputChunk.fileName;
103
- saveEmitWorkerAsset(config, {
104
- fileName,
105
- source: outputChunk.code
106
- });
107
- workerMap.bundle.set(id, fileName);
108
- }
109
- return encodeWorkerAssetFileName(fileName, workerMap);
73
+ const workerMap = workerCache.get(config.mainConfig || config);
74
+ let fileName = workerMap.bundle.get(id);
75
+ if (!fileName) {
76
+ const outputChunk = await bundleWorkerEntry(config, id);
77
+ fileName = outputChunk.fileName;
78
+ saveEmitWorkerAsset(config, {
79
+ fileName,
80
+ source: outputChunk.code
81
+ });
82
+ workerMap.bundle.set(id, fileName);
83
+ }
84
+ return encodeWorkerAssetFileName(fileName, workerMap);
110
85
  }
111
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L149
112
86
  function encodeWorkerAssetFileName(fileName, workerCache) {
113
- const { fileNameHash } = workerCache;
114
- const hash = bridge_utils.getHash(fileName);
115
- if (!fileNameHash.get(hash)) {
116
- fileNameHash.set(hash, fileName);
117
- }
118
- return `${WORKER_ASSET_ID}${hash}__`;
87
+ const { fileNameHash } = workerCache;
88
+ const hash = require_bridge_utils.getHash(fileName);
89
+ if (!fileNameHash.get(hash)) fileNameHash.set(hash, fileName);
90
+ return `${WORKER_ASSET_ID}${hash}__`;
119
91
  }
120
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L55
121
92
  async function bundleWorkerEntry(config, id) {
122
- const input = bridge_utils.cleanUrl(id);
123
- const bundleChain = config.bundleChain ?? [];
124
- const newBundleChain = [...bundleChain, input];
125
- if (bundleChain.includes(input)) {
126
- throw new Error(`Circular worker imports detected. Vite does not support it. Import chain: ${newBundleChain.join(' -> ')}`);
127
- }
128
- // bundle the file as entry to support imports
129
- const { rollup } = await import('rollup');
130
- const { plugins, rollupOptions, format } = config.worker;
131
- const workerConfig = await plugins(newBundleChain);
132
- const workerEnvironment = new vite.BuildEnvironment('client', workerConfig); // TODO: should this be 'worker'?
133
- await workerEnvironment.init();
134
- const bundle = await rollup({
135
- ...rollupOptions,
136
- input,
137
- plugins: workerEnvironment.plugins.map(p => bridge_build.injectEnvironmentToHooks(workerEnvironment, p)),
138
- preserveEntrySignatures: false
139
- });
140
- let chunk;
141
- try {
142
- const workerOutputConfig = config.worker.rollupOptions.output;
143
- const workerConfig = workerOutputConfig
144
- ? Array.isArray(workerOutputConfig)
145
- ? workerOutputConfig[0] || {}
146
- : workerOutputConfig
147
- : {};
148
- const { output: [outputChunk, ...outputChunks] } = await bundle.generate({
149
- entryFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].js'),
150
- chunkFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].js'),
151
- assetFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].[ext]'),
152
- ...workerConfig,
153
- format,
154
- sourcemap: config.build.sourcemap
155
- });
156
- chunk = outputChunk;
157
- for (const outputChunk of outputChunks) {
158
- if (outputChunk.type === 'asset') {
159
- saveEmitWorkerAsset(config, outputChunk);
160
- }
161
- else if (outputChunk.type === 'chunk') {
162
- saveEmitWorkerAsset(config, {
163
- fileName: outputChunk.fileName,
164
- source: outputChunk.code
165
- });
166
- }
167
- }
168
- }
169
- finally {
170
- await bundle.close();
171
- }
172
- return emitSourcemapForWorkerEntry(config, chunk);
93
+ const input = require_bridge_utils.cleanUrl(id);
94
+ const bundleChain = config.bundleChain ?? [];
95
+ const newBundleChain = [...bundleChain, input];
96
+ if (bundleChain.includes(input)) throw new Error(`Circular worker imports detected. Vite does not support it. Import chain: ${newBundleChain.join(" -> ")}`);
97
+ const { plugins, format } = config.worker;
98
+ const workerOptionsCarrier = config.worker;
99
+ const workerBundlerOptions = workerOptionsCarrier.rolldownOptions ?? workerOptionsCarrier.rollupOptions;
100
+ const workerEnvironment = new vite.BuildEnvironment("client", await plugins(newBundleChain));
101
+ await workerEnvironment.init();
102
+ const wrappedPlugins = workerEnvironment.plugins.map((p) => require_bridge_build.injectEnvironmentToHooks(workerEnvironment, p));
103
+ const workerOutputConfig = workerBundlerOptions.output;
104
+ const outputConfig = workerOutputConfig ? Array.isArray(workerOutputConfig) ? workerOutputConfig[0] || {} : workerOutputConfig : {};
105
+ const generateOptions = {
106
+ entryFileNames: node_path.posix.join(config.build.assetsDir, "[name]-[hash].js"),
107
+ chunkFileNames: node_path.posix.join(config.build.assetsDir, "[name]-[hash].js"),
108
+ assetFileNames: node_path.posix.join(config.build.assetsDir, "[name]-[hash].[ext]"),
109
+ ...outputConfig,
110
+ format,
111
+ sourcemap: config.build.sourcemap
112
+ };
113
+ let chunk;
114
+ if (require_bridge_bundler.detectBundler(config) === require_bridge_bundler.BundlerKind.Rolldown) chunk = await bundleWorkerEntryRolldown(config, input, workerBundlerOptions, wrappedPlugins, generateOptions, workerEnvironment);
115
+ else chunk = await bundleWorkerEntryRollup(config, input, workerBundlerOptions, wrappedPlugins, generateOptions);
116
+ return emitSourcemapForWorkerEntry(config, chunk);
117
+ }
118
+ async function bundleWorkerEntryRollup(config, input, bundlerOptions, plugins, generateOptions) {
119
+ const { rollup } = await import("rollup");
120
+ const bundle = await rollup({
121
+ ...bundlerOptions,
122
+ input,
123
+ plugins,
124
+ preserveEntrySignatures: false
125
+ });
126
+ try {
127
+ const { output } = await bundle.generate(generateOptions);
128
+ const [outputChunk, ...rest] = output;
129
+ for (const o of rest) if (o.type === "asset") saveEmitWorkerAsset(config, o);
130
+ else saveEmitWorkerAsset(config, {
131
+ fileName: o.fileName,
132
+ source: o.code
133
+ });
134
+ return outputChunk;
135
+ } finally {
136
+ await bundle.close();
137
+ }
138
+ }
139
+ async function bundleWorkerEntryRolldown(config, input, bundlerOptions, plugins, generateOptions, workerEnvironment) {
140
+ const { rolldown } = await Promise.resolve().then(() => require("../dist.cjs"));
141
+ const workerBuildTarget = workerEnvironment.config.build.target;
142
+ const bundle = await rolldown({
143
+ ...bundlerOptions,
144
+ input,
145
+ plugins,
146
+ transform: {
147
+ target: workerBuildTarget === false ? void 0 : workerBuildTarget,
148
+ ...bundlerOptions.transform,
149
+ define: {
150
+ ...bundlerOptions.transform?.define,
151
+ "process.env.NODE_ENV": "process.env.NODE_ENV"
152
+ }
153
+ },
154
+ moduleTypes: {
155
+ ".css": "js",
156
+ ...bundlerOptions.moduleTypes
157
+ },
158
+ preserveEntrySignatures: false,
159
+ experimental: {
160
+ ...bundlerOptions.experimental,
161
+ viteMode: true
162
+ }
163
+ });
164
+ try {
165
+ const { output } = await bundle.generate(generateOptions);
166
+ const [outputChunk, ...rest] = output;
167
+ for (const o of rest) if (o.type === "asset") saveEmitWorkerAsset(config, o);
168
+ else saveEmitWorkerAsset(config, {
169
+ fileName: o.fileName,
170
+ source: o.code
171
+ });
172
+ return outputChunk;
173
+ } finally {
174
+ await bundle.close();
175
+ }
173
176
  }
174
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L124
175
177
  function emitSourcemapForWorkerEntry(config, chunk) {
176
- const { map: sourcemap } = chunk;
177
- if (sourcemap) {
178
- if (config.build.sourcemap === 'hidden' || config.build.sourcemap === true) {
179
- const data = sourcemap.toString();
180
- const mapFileName = `${chunk.fileName}.map`;
181
- saveEmitWorkerAsset(config, {
182
- fileName: mapFileName,
183
- source: data
184
- });
185
- }
186
- }
187
- return chunk;
178
+ const sourcemap = chunk.map;
179
+ if (sourcemap) {
180
+ if (config.build.sourcemap === "hidden" || config.build.sourcemap === true) saveEmitWorkerAsset(config, {
181
+ fileName: `${chunk.fileName}.map`,
182
+ source: sourcemap.toString()
183
+ });
184
+ }
185
+ return chunk;
188
186
  }
189
- // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L458
190
187
  /**
191
- * @internal
192
- */
188
+ * @internal
189
+ */
193
190
  function isSameContent(a, b) {
194
- if (typeof a === 'string') {
195
- if (typeof b === 'string') {
196
- return a === b;
197
- }
198
- return Buffer.from(a).equals(b);
199
- }
200
- return Buffer.from(b).equals(a);
191
+ if (typeof a === "string") {
192
+ if (typeof b === "string") return a === b;
193
+ return Buffer.from(a).equals(b);
194
+ }
195
+ return Buffer.from(b).equals(a);
201
196
  }
202
-
197
+ //#endregion
198
+ exports.AlphaTabWorkerTypes = AlphaTabWorkerTypes;
203
199
  exports.WORKER_ASSET_ID = WORKER_ASSET_ID;
204
200
  exports.WORKER_FILE_ID = WORKER_FILE_ID;
205
201
  exports.isSameContent = isSameContent;