Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 51 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions packages/alphatab/src/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,15 @@ export class Environment {
try {
// @ts-expect-error
if (typeof __webpack_require__ === 'function') {
// check if webpack plugin was used
// @ts-expect-error
if (typeof __ALPHATAB_WEBPACK__ !== 'boolean') {
Logger.warning(
'WebPack',
`Detected bundling with WebPack but @coderline/alphatab-webpcak was not used! To ensure alphaTab works as expected use our bundler plugins. Learn more at https://www.alphatab.net/docs/getting-started/installation-webpack`
);
}

return true;
}
} catch {
Expand All @@ -712,6 +721,15 @@ export class Environment {
try {
// @ts-expect-error
if (typeof __BASE__ === 'string') {
// check if vite plugin was used
// @ts-expect-error
if (typeof __ALPHATAB_VITE__ !== 'boolean') {
Logger.warning(
'Vite',
`Detected bundling with Vite but @coderline/alphatab-vite was not used! To ensure alphaTab works as expected use our bundler plugins. Learn more at https://www.alphatab.net/docs/getting-started/installation-vite`
);
}

return true;
}
} catch {
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/alphaTabVitePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { detectionGlobalPlugin } from '@coderline/alphatab-vite/detectionGlobalPlugin';
import type { AlphaTabVitePluginOptions } from './AlphaTabVitePluginOptions';
import type { Plugin } from './bridge';
import { copyAssetsPlugin } from './copyAssetsPlugin';
Expand All @@ -12,6 +13,7 @@ export function alphaTab(options?: AlphaTabVitePluginOptions) {

options ??= {};

plugins.push(detectionGlobalPlugin());
plugins.push(importMetaUrlPlugin(options));
plugins.push(workerPlugin(options));
plugins.push(copyAssetsPlugin(options));
Expand Down
38 changes: 38 additions & 0 deletions packages/vite/src/detectionGlobalPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import MagicString from 'magic-string';
import type { Plugin, ResolvedConfig } from './bridge';

const marker = '__ALPHATAB_VITE__';

/**
* @public
*/
export function detectionGlobalPlugin(): Plugin {
let resolvedConfig: ResolvedConfig;
return {
name: 'vite-plugin-alphatab-global',

configResolved(config) {
resolvedConfig = config as ResolvedConfig;
},

shouldTransformCachedModule({ code }) {
return code.includes(marker);
},

async transform(code, id) {
if (!code.includes(marker)) {
return;
}

const s = new MagicString(code);
s.replaceAll(marker, JSON.stringify(true));
return {
code: s.toString(),
map:
resolvedConfig.command === 'build' && resolvedConfig.build.sourcemap
? s.generateMap({ hires: 'boundary', source: id })
: null
};
}
};
}
2 changes: 2 additions & 0 deletions packages/vite/test/Vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ describe('Vite', () => {
expect(text).to.include('assets/alphaTab.worklet-');
// without custom chunking the app will bundle alphatab directly
expect(text).to.include(".at-surface");
// ensure __ALPHATAB_VITE__ got replaced
expect(text).to.not.include("__ALPHATAB_VITE__");
appValidated = true;
} else if (file.name.startsWith('alphaTab.worker-')) {
expect(text).to.include('initializeWorker()');
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"test": "mocha"
},
"dependencies": {
"webpack": "^5.101.3"
"webpack": "^5.103.0"
},
"engines": {
"node": ">=20.19.0"
Expand Down
2 changes: 2 additions & 0 deletions packages/webpack/src/AlphaTabWebPackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { webPackWithAlphaTab, webpackTypes } from './Utils';
import { injectWebWorkerDependency } from './AlphaTabWebWorkerDependency';
import { injectWorkletRuntimeModule } from './AlphaTabWorkletStartRuntimeModule';
import { injectWorkletDependency } from './AlphaTabWorkletDependency';
import { configureDetectionGlobal } from '@coderline/alphatab-webpack/DetectionGlobal';

const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
Expand Down Expand Up @@ -219,6 +220,7 @@ export class AlphaTabWebPackPlugin {
cachedContextify
);
this._configureAssetCopy(this._webPackWithAlphaTab, pluginName, compiler, compilation);
configureDetectionGlobal(pluginName, normalModuleFactory);
});
}

Expand Down
Loading