@coderline/alphatab-vite 1.7.0 → 1.8.0-alpha.1632
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.d.ts +30 -0
- package/dist/AlphaTabVitePluginOptions.mjs +36 -0
- package/dist/alphaTab.vite.cjs +45 -0
- package/dist/alphaTab.vite.d.ts +1 -33
- package/dist/alphaTab.vite.mjs +2 -2328
- package/dist/alphaTabVitePlugin.cjs +57 -0
- package/dist/alphaTabVitePlugin.d.ts +5 -0
- package/dist/alphaTabVitePlugin.mjs +53 -0
- package/dist/bridge/asset.cjs +87 -0
- package/dist/bridge/asset.mjs +63 -0
- package/dist/bridge/build.cjs +242 -0
- package/dist/bridge/build.mjs +217 -0
- package/dist/bridge/config.cjs +38 -0
- package/dist/bridge/config.mjs +36 -0
- package/dist/bridge/constants.cjs +88 -0
- package/dist/bridge/constants.mjs +82 -0
- package/dist/bridge/fsUtils.cjs +60 -0
- package/dist/bridge/fsUtils.mjs +56 -0
- package/dist/bridge/index.cjs +69 -0
- package/dist/bridge/index.mjs +43 -0
- package/dist/bridge/optimizer.cjs +172 -0
- package/dist/bridge/optimizer.mjs +148 -0
- package/dist/bridge/plugins.cjs +51 -0
- package/dist/bridge/plugins.mjs +47 -0
- package/dist/bridge/resolve.cjs +75 -0
- package/dist/bridge/resolve.mjs +71 -0
- package/dist/bridge/typeUtils.cjs +38 -0
- package/dist/bridge/typeUtils.d.ts +3 -0
- package/dist/bridge/typeUtils.mjs +36 -0
- package/dist/bridge/utils.cjs +164 -0
- package/dist/bridge/utils.mjs +151 -0
- package/dist/bridge/worker.cjs +207 -0
- package/dist/bridge/worker.d.ts +10 -0
- package/dist/bridge/worker.mjs +180 -0
- package/dist/copyAssetsPlugin.cjs +168 -0
- package/dist/copyAssetsPlugin.d.ts +5 -0
- package/dist/copyAssetsPlugin.mjs +143 -0
- package/dist/importMetaPlugin.cjs +201 -0
- package/dist/importMetaPlugin.d.ts +5 -0
- package/dist/importMetaPlugin.mjs +197 -0
- package/dist/workerPlugin.cjs +224 -0
- package/dist/workerPlugin.d.ts +5 -0
- package/dist/workerPlugin.mjs +201 -0
- package/package.json +32 -19
- package/dist/alphaTab.vite.js +0 -2388
- package/dist/alphaTab.vite.min.mjs +0 -36
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab Vite Plugin v1.8.0-alpha.1632 (develop, build 1632)
|
|
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 copyAssetsPlugin = require('./copyAssetsPlugin.cjs');
|
|
42
|
+
const importMetaPlugin = require('./importMetaPlugin.cjs');
|
|
43
|
+
const workerPlugin = require('./workerPlugin.cjs');
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
function alphaTab(options) {
|
|
49
|
+
const plugins = [];
|
|
50
|
+
options ??= {};
|
|
51
|
+
plugins.push(importMetaPlugin.importMetaUrlPlugin(options));
|
|
52
|
+
plugins.push(workerPlugin.workerPlugin(options));
|
|
53
|
+
plugins.push(copyAssetsPlugin.copyAssetsPlugin(options));
|
|
54
|
+
return plugins;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.alphaTab = alphaTab;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab Vite Plugin v1.8.0-alpha.1632 (develop, build 1632)
|
|
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 { copyAssetsPlugin } from './copyAssetsPlugin.mjs';
|
|
38
|
+
import { importMetaUrlPlugin } from './importMetaPlugin.mjs';
|
|
39
|
+
import { workerPlugin } from './workerPlugin.mjs';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
function alphaTab(options) {
|
|
45
|
+
const plugins = [];
|
|
46
|
+
options ??= {};
|
|
47
|
+
plugins.push(importMetaUrlPlugin(options));
|
|
48
|
+
plugins.push(workerPlugin(options));
|
|
49
|
+
plugins.push(copyAssetsPlugin(options));
|
|
50
|
+
return plugins;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { alphaTab };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab Vite Plugin v1.8.0-alpha.1632 (develop, build 1632)
|
|
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 bridge_utils = require('./utils.cjs');
|
|
43
|
+
|
|
44
|
+
function _interopNamespaceDefault(e) {
|
|
45
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
46
|
+
if (e) {
|
|
47
|
+
for (const k in e) {
|
|
48
|
+
if (k !== 'default') {
|
|
49
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
50
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: () => e[k]
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
n.default = e;
|
|
58
|
+
return Object.freeze(n);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
62
|
+
|
|
63
|
+
// index.ts for more details on contents and license of this file
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
const FS_PREFIX = '/@fs/';
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
async function fileToUrl(id, config) {
|
|
72
|
+
let rtn;
|
|
73
|
+
if (id.startsWith(bridge_utils.withTrailingSlash(config.root))) {
|
|
74
|
+
// in project root, infer short public path
|
|
75
|
+
rtn = `/${path__namespace.posix.relative(config.root, id)}`;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// outside of project root, use absolute fs path
|
|
79
|
+
// (this is special handled by the serve static middleware
|
|
80
|
+
rtn = path__namespace.posix.join(FS_PREFIX, id);
|
|
81
|
+
}
|
|
82
|
+
const base = bridge_utils.joinUrlSegments(config.server?.origin ?? '', config.base);
|
|
83
|
+
return bridge_utils.joinUrlSegments(base, bridge_utils.removeLeadingSlash(rtn));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
exports.FS_PREFIX = FS_PREFIX;
|
|
87
|
+
exports.fileToUrl = fileToUrl;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab Vite Plugin v1.8.0-alpha.1632 (develop, build 1632)
|
|
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 { withTrailingSlash, joinUrlSegments, removeLeadingSlash } from './utils.mjs';
|
|
39
|
+
|
|
40
|
+
// index.ts for more details on contents and license of this file
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
const FS_PREFIX = '/@fs/';
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
async function fileToUrl(id, config) {
|
|
49
|
+
let rtn;
|
|
50
|
+
if (id.startsWith(withTrailingSlash(config.root))) {
|
|
51
|
+
// in project root, infer short public path
|
|
52
|
+
rtn = `/${path.posix.relative(config.root, id)}`;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// outside of project root, use absolute fs path
|
|
56
|
+
// (this is special handled by the serve static middleware
|
|
57
|
+
rtn = path.posix.join(FS_PREFIX, id);
|
|
58
|
+
}
|
|
59
|
+
const base = joinUrlSegments(config.server?.origin ?? '', config.base);
|
|
60
|
+
return joinUrlSegments(base, removeLeadingSlash(rtn));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { FS_PREFIX, fileToUrl };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* alphaTab Vite Plugin v1.8.0-alpha.1632 (develop, build 1632)
|
|
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 bridge_constants = require('./constants.cjs');
|
|
43
|
+
const bridge_plugins = require('./plugins.cjs');
|
|
44
|
+
const bridge_utils = require('./utils.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
|
|
66
|
+
const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
|
|
67
|
+
const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
|
|
68
|
+
const backSlashRegEx = /\\/g;
|
|
69
|
+
function escapeId(id) {
|
|
70
|
+
if (!needsEscapeRegEx.test(id)) {
|
|
71
|
+
return id;
|
|
72
|
+
}
|
|
73
|
+
return id.replace(backSlashRegEx, '\\\\').replace(quoteNewlineRegEx, '\\$1');
|
|
74
|
+
}
|
|
75
|
+
const getResolveUrl = (path, URL = 'URL') => `new ${URL}(${path}).href`;
|
|
76
|
+
const getRelativeUrlFromDocument = (relativePath, umd = false) => getResolveUrl(`'${escapeId(bridge_utils.partialEncodeURIPath(relativePath))}', ${umd ? `typeof document === 'undefined' ? location.href : ` : ''}document.currentScript && document.currentScript.src || document.baseURI`);
|
|
77
|
+
const getFileUrlFromFullPath = (path) => `require('u' + 'rl').pathToFileURL(${path}).href`;
|
|
78
|
+
const getFileUrlFromRelativePath = (path) => getFileUrlFromFullPath(`__dirname + '/${escapeId(path)}'`);
|
|
79
|
+
const relativeUrlMechanisms = {
|
|
80
|
+
amd: relativePath => {
|
|
81
|
+
if (relativePath[0] !== '.') {
|
|
82
|
+
relativePath = `./${relativePath}`;
|
|
83
|
+
}
|
|
84
|
+
return getResolveUrl(`require.toUrl('${escapeId(relativePath)}'), document.baseURI`);
|
|
85
|
+
},
|
|
86
|
+
cjs: relativePath => `(typeof document === 'undefined' ? ${getFileUrlFromRelativePath(relativePath)} : ${getRelativeUrlFromDocument(relativePath)})`,
|
|
87
|
+
es: relativePath => getResolveUrl(`'${escapeId(bridge_utils.partialEncodeURIPath(relativePath))}', import.meta.url`),
|
|
88
|
+
iife: relativePath => getRelativeUrlFromDocument(relativePath),
|
|
89
|
+
// NOTE: make sure rollup generate `module` params
|
|
90
|
+
system: relativePath => getResolveUrl(`'${escapeId(bridge_utils.partialEncodeURIPath(relativePath))}', module.meta.url`),
|
|
91
|
+
umd: relativePath => `(typeof document === 'undefined' && typeof location === 'undefined' ? ${getFileUrlFromRelativePath(relativePath)} : ${getRelativeUrlFromDocument(relativePath, true)})`
|
|
92
|
+
};
|
|
93
|
+
const customRelativeUrlMechanisms = {
|
|
94
|
+
...relativeUrlMechanisms,
|
|
95
|
+
'worker-iife': relativePath => getResolveUrl(`'${escapeId(bridge_utils.partialEncodeURIPath(relativePath))}', self.location.href`)
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
function createToImportMetaURLBasedRelativeRuntime(format, isWorker) {
|
|
101
|
+
const formatLong = isWorker && format === 'iife' ? 'worker-iife' : format;
|
|
102
|
+
const toRelativePath = customRelativeUrlMechanisms[formatLong];
|
|
103
|
+
return (filename, importer) => ({
|
|
104
|
+
runtime: toRelativePath(path__namespace.posix.relative(path__namespace.dirname(importer), filename))
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
function toOutputFilePathInJS(filename, type, hostId, hostType, config, toRelative) {
|
|
111
|
+
const { renderBuiltUrl } = config.experimental;
|
|
112
|
+
let relative = config.base === '' || config.base === './';
|
|
113
|
+
if (renderBuiltUrl) {
|
|
114
|
+
const result = renderBuiltUrl(filename, {
|
|
115
|
+
hostId,
|
|
116
|
+
hostType,
|
|
117
|
+
type,
|
|
118
|
+
ssr: !!config.build.ssr
|
|
119
|
+
});
|
|
120
|
+
if (typeof result === 'object') {
|
|
121
|
+
if (result.runtime) {
|
|
122
|
+
return { runtime: result.runtime };
|
|
123
|
+
}
|
|
124
|
+
if (typeof result.relative === 'boolean') {
|
|
125
|
+
relative = result.relative;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (result) {
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (relative && !config.build.ssr) {
|
|
133
|
+
return toRelative(filename, hostId);
|
|
134
|
+
}
|
|
135
|
+
return bridge_utils.joinUrlSegments(config.base, filename);
|
|
136
|
+
}
|
|
137
|
+
// https://github.com/vitejs/vite/blob/v6.1.1/packages/vite/src/node/build.ts#L1131
|
|
138
|
+
/**
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
function injectEnvironmentToHooks(environment, plugin) {
|
|
142
|
+
const { resolveId, load, transform } = plugin;
|
|
143
|
+
const clone = { ...plugin };
|
|
144
|
+
for (const hook of Object.keys(clone)) {
|
|
145
|
+
switch (hook) {
|
|
146
|
+
case 'resolveId':
|
|
147
|
+
clone[hook] = wrapEnvironmentResolveId(environment, resolveId);
|
|
148
|
+
break;
|
|
149
|
+
case 'load':
|
|
150
|
+
clone[hook] = wrapEnvironmentLoad(environment, load);
|
|
151
|
+
break;
|
|
152
|
+
case 'transform':
|
|
153
|
+
clone[hook] = wrapEnvironmentTransform(environment, transform);
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
if (bridge_constants.ROLLUP_HOOKS.includes(hook)) {
|
|
157
|
+
clone[hook] = wrapEnvironmentHook(environment, clone[hook]);
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return clone;
|
|
163
|
+
}
|
|
164
|
+
function wrapEnvironmentResolveId(environment, hook) {
|
|
165
|
+
if (!hook) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const fn = bridge_plugins.getHookHandler(hook);
|
|
169
|
+
const handler = function (id, importer, options) {
|
|
170
|
+
return fn.call(injectEnvironmentInContext(this, environment), id, importer, injectSsrFlag(options, environment));
|
|
171
|
+
};
|
|
172
|
+
if ('handler' in hook) {
|
|
173
|
+
return {
|
|
174
|
+
...hook,
|
|
175
|
+
handler
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return handler;
|
|
179
|
+
}
|
|
180
|
+
function wrapEnvironmentLoad(environment, hook) {
|
|
181
|
+
if (!hook) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const fn = bridge_plugins.getHookHandler(hook);
|
|
185
|
+
const handler = function (id, ...args) {
|
|
186
|
+
return fn.call(injectEnvironmentInContext(this, environment), id, injectSsrFlag(args[0], environment));
|
|
187
|
+
};
|
|
188
|
+
if ('handler' in hook) {
|
|
189
|
+
return {
|
|
190
|
+
...hook,
|
|
191
|
+
handler
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return handler;
|
|
195
|
+
}
|
|
196
|
+
function wrapEnvironmentTransform(environment, hook) {
|
|
197
|
+
if (!hook) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const fn = bridge_plugins.getHookHandler(hook);
|
|
201
|
+
const handler = function (code, importer, ...args) {
|
|
202
|
+
return fn.call(injectEnvironmentInContext(this, environment), code, importer, injectSsrFlag(args[0], environment));
|
|
203
|
+
};
|
|
204
|
+
if ('handler' in hook) {
|
|
205
|
+
return {
|
|
206
|
+
...hook,
|
|
207
|
+
handler
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return handler;
|
|
211
|
+
}
|
|
212
|
+
function wrapEnvironmentHook(environment, hook) {
|
|
213
|
+
if (!hook) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const fn = bridge_plugins.getHookHandler(hook);
|
|
217
|
+
if (typeof fn !== 'function') {
|
|
218
|
+
return hook;
|
|
219
|
+
}
|
|
220
|
+
const handler = function (...args) {
|
|
221
|
+
return fn.call(injectEnvironmentInContext(this, environment), ...args);
|
|
222
|
+
};
|
|
223
|
+
if ('handler' in hook) {
|
|
224
|
+
return {
|
|
225
|
+
...hook,
|
|
226
|
+
handler
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return handler;
|
|
230
|
+
}
|
|
231
|
+
function injectEnvironmentInContext(context, environment) {
|
|
232
|
+
context.environment ??= environment;
|
|
233
|
+
return context;
|
|
234
|
+
}
|
|
235
|
+
function injectSsrFlag(options, environment) {
|
|
236
|
+
const ssr = environment ? environment.config.consumer === 'server' : true;
|
|
237
|
+
return { ...(options ?? {}), ssr };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
exports.createToImportMetaURLBasedRelativeRuntime = createToImportMetaURLBasedRelativeRuntime;
|
|
241
|
+
exports.injectEnvironmentToHooks = injectEnvironmentToHooks;
|
|
242
|
+
exports.toOutputFilePathInJS = toOutputFilePathInJS;
|