@aelionsdk/vite-plugin 0.1.0-beta.1
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/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +141 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FoyonaCZY and AelionSDK contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# `@aelionsdk/vite-plugin`
|
|
2
|
+
|
|
3
|
+
Official Vite integration for AelionSDK's module Worker and AudioWorklet entry files.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @aelionsdk/sdk@next
|
|
9
|
+
pnpm add -D @aelionsdk/vite-plugin@next vite
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
// vite.config.ts
|
|
14
|
+
import { aelion } from '@aelionsdk/vite-plugin';
|
|
15
|
+
import { defineConfig } from 'vite';
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
plugins: [aelion()],
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
No asset paths or workspace aliases are required. During `vite build`, the plugin emits the
|
|
23
|
+
published `@aelionsdk/renderer-worker` WebGL2 Worker, the `@aelionsdk/export` mux Worker, and both
|
|
24
|
+
published `@aelionsdk/audio` AudioWorklet entry chunks, then rewrites the SDK package URLs to the
|
|
25
|
+
generated hashed files. During `vite dev`, it exposes equivalent virtual module URLs through
|
|
26
|
+
Vite's module server.
|
|
27
|
+
|
|
28
|
+
The optional flags are only for applications that never load the corresponding runtime:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
aelion({ audioWorklets: true, exportWorker: true, rendererWorker: true });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
All flags default to `true`. A disabled asset group must not be used by application code.
|
|
35
|
+
|
|
36
|
+
Production pages should use HTTPS. For the SharedArrayBuffer audio path, also return `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`. CSP must allow same-origin `worker-src` and `script-src`.
|
|
37
|
+
|
|
38
|
+
This package is part of [AelionSDK](https://github.com/FoyonaCZY/AelionSDK). The `0.1.0-beta.1` API may change before the first stable release.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/** Options for the official Aelion Vite integration. */
|
|
3
|
+
export interface AelionVitePluginOptions {
|
|
4
|
+
/** Emit and serve both `@aelionsdk/audio` AudioWorklet entries. Defaults to true. */
|
|
5
|
+
audioWorklets?: boolean;
|
|
6
|
+
/** Emit and serve the `@aelionsdk/renderer-worker` module Worker. Defaults to true. */
|
|
7
|
+
rendererWorker?: boolean;
|
|
8
|
+
/** Emit and serve the `@aelionsdk/export` mux Worker. Defaults to true. */
|
|
9
|
+
exportWorker?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Adds the published Aelion Worker/AudioWorklet entry graphs to Vite builds and
|
|
13
|
+
* exposes the same module entries through the Vite development server.
|
|
14
|
+
*/
|
|
15
|
+
export declare function aelion(options?: AelionVitePluginOptions): Plugin;
|
|
16
|
+
export default aelion;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAiBnC,wDAAwD;AACxD,MAAM,WAAW,uBAAuB;IACtC,qFAAqF;IACrF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,uFAAuF;IACvF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AA6CD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,uBAA4B,GAAG,MAAM,CAmGpE;AAED,eAAe,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
const virtualPrefix = '\0@aelionsdk/vite-plugin:runtime-asset:';
|
|
5
|
+
const publicPrefix = '/@aelionsdk/vite-plugin/runtime-assets';
|
|
6
|
+
function normalizedModuleId(id) {
|
|
7
|
+
return id.split('?', 1)[0]?.replaceAll('\\', '/') ?? id.replaceAll('\\', '/');
|
|
8
|
+
}
|
|
9
|
+
function packageDistDirectory(packageName) {
|
|
10
|
+
return dirname(fileURLToPath(import.meta.resolve(packageName)));
|
|
11
|
+
}
|
|
12
|
+
function isPackageDistModule(id, asset) {
|
|
13
|
+
const normalizedId = normalizedModuleId(id);
|
|
14
|
+
const normalizedDirectory = asset.packageDistDirectory.replaceAll('\\', '/');
|
|
15
|
+
return (normalizedId.startsWith(`${normalizedDirectory}/`) ||
|
|
16
|
+
normalizedId.includes(`/node_modules/${asset.packageName}/dist/`));
|
|
17
|
+
}
|
|
18
|
+
function createRuntimeAsset(packageName, packageDist, fileName) {
|
|
19
|
+
const namespace = packageName === '@aelionsdk/audio'
|
|
20
|
+
? 'audio'
|
|
21
|
+
: packageName === '@aelionsdk/export'
|
|
22
|
+
? 'export'
|
|
23
|
+
: 'renderer-worker';
|
|
24
|
+
const key = `${namespace}/${fileName}`;
|
|
25
|
+
return {
|
|
26
|
+
entryFile: resolve(packageDist, fileName),
|
|
27
|
+
key,
|
|
28
|
+
packageName,
|
|
29
|
+
packageDistDirectory: packageDist,
|
|
30
|
+
publicUrl: `${publicPrefix}/${key}`,
|
|
31
|
+
referencePattern: new RegExp(String.raw `new URL\(\s*(['"])\.\/${fileName.replaceAll('.', String.raw `\.`)}\1\s*,\s*import\.meta\.url\s*\)`, 'gu'),
|
|
32
|
+
virtualId: `${virtualPrefix}${key}`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Adds the published Aelion Worker/AudioWorklet entry graphs to Vite builds and
|
|
37
|
+
* exposes the same module entries through the Vite development server.
|
|
38
|
+
*/
|
|
39
|
+
export function aelion(options = {}) {
|
|
40
|
+
const includeAudioWorklets = options.audioWorklets ?? true;
|
|
41
|
+
const includeRendererWorker = options.rendererWorker ?? true;
|
|
42
|
+
const includeExportWorker = options.exportWorker ?? true;
|
|
43
|
+
const audioDist = includeAudioWorklets ? packageDistDirectory('@aelionsdk/audio') : undefined;
|
|
44
|
+
const rendererDist = includeRendererWorker
|
|
45
|
+
? packageDistDirectory('@aelionsdk/renderer-worker')
|
|
46
|
+
: undefined;
|
|
47
|
+
const exportDist = includeExportWorker ? packageDistDirectory('@aelionsdk/export') : undefined;
|
|
48
|
+
const assets = [
|
|
49
|
+
...(audioDist === undefined
|
|
50
|
+
? []
|
|
51
|
+
: [
|
|
52
|
+
createRuntimeAsset('@aelionsdk/audio', audioDist, 'pcm-player.worklet.js'),
|
|
53
|
+
createRuntimeAsset('@aelionsdk/audio', audioDist, 'pcm-message-player.worklet.js'),
|
|
54
|
+
]),
|
|
55
|
+
...(rendererDist === undefined
|
|
56
|
+
? []
|
|
57
|
+
: [createRuntimeAsset('@aelionsdk/renderer-worker', rendererDist, 'webgl2-worker.js')]),
|
|
58
|
+
...(exportDist === undefined
|
|
59
|
+
? []
|
|
60
|
+
: [createRuntimeAsset('@aelionsdk/export', exportDist, 'mux-export-worker.js')]),
|
|
61
|
+
];
|
|
62
|
+
const assetByVirtualId = new Map(assets.map(asset => [asset.virtualId, asset]));
|
|
63
|
+
const assetByPublicUrl = new Map(assets.map(asset => [asset.publicUrl, asset]));
|
|
64
|
+
const emittedReferences = new Map();
|
|
65
|
+
let command;
|
|
66
|
+
return {
|
|
67
|
+
name: '@aelionsdk/vite-plugin',
|
|
68
|
+
enforce: 'pre',
|
|
69
|
+
config() {
|
|
70
|
+
const excluded = [
|
|
71
|
+
...(includeAudioWorklets ? ['@aelionsdk/audio', '@aelionsdk/sdk'] : []),
|
|
72
|
+
...(includeRendererWorker ? ['@aelionsdk/renderer-worker', '@aelionsdk/sdk'] : []),
|
|
73
|
+
...(includeExportWorker ? ['@aelionsdk/export', '@aelionsdk/sdk'] : []),
|
|
74
|
+
];
|
|
75
|
+
return {
|
|
76
|
+
optimizeDeps: {
|
|
77
|
+
exclude: [...new Set(excluded)],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
configResolved(config) {
|
|
82
|
+
command = config.command;
|
|
83
|
+
},
|
|
84
|
+
buildStart() {
|
|
85
|
+
if (command !== 'build')
|
|
86
|
+
return;
|
|
87
|
+
for (const asset of assets) {
|
|
88
|
+
emittedReferences.set(asset.key, this.emitFile({
|
|
89
|
+
type: 'chunk',
|
|
90
|
+
id: asset.virtualId,
|
|
91
|
+
name: `aelion-${asset.key.replaceAll('/', '-')}`,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
resolveId(source, importer) {
|
|
96
|
+
if (assetByVirtualId.has(source))
|
|
97
|
+
return source;
|
|
98
|
+
const publicAsset = assetByPublicUrl.get(source.split('?', 1)[0] ?? source);
|
|
99
|
+
if (publicAsset !== undefined)
|
|
100
|
+
return publicAsset.virtualId;
|
|
101
|
+
if (importer?.startsWith(virtualPrefix) === true && source.startsWith('.')) {
|
|
102
|
+
const importerAsset = assetByVirtualId.get(importer);
|
|
103
|
+
if (importerAsset !== undefined) {
|
|
104
|
+
return resolve(dirname(importerAsset.entryFile), source);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
},
|
|
109
|
+
async load(id) {
|
|
110
|
+
const asset = assetByVirtualId.get(id);
|
|
111
|
+
return asset === undefined ? undefined : readFile(asset.entryFile, 'utf8');
|
|
112
|
+
},
|
|
113
|
+
transform(source, id) {
|
|
114
|
+
let transformed = source;
|
|
115
|
+
let changed = false;
|
|
116
|
+
for (const asset of assets) {
|
|
117
|
+
if (!isPackageDistModule(id, asset))
|
|
118
|
+
continue;
|
|
119
|
+
asset.referencePattern.lastIndex = 0;
|
|
120
|
+
if (!asset.referencePattern.test(transformed))
|
|
121
|
+
continue;
|
|
122
|
+
asset.referencePattern.lastIndex = 0;
|
|
123
|
+
let replacement;
|
|
124
|
+
if (command === 'serve') {
|
|
125
|
+
replacement = `new URL(${JSON.stringify(asset.publicUrl)}, import.meta.url)`;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const referenceId = emittedReferences.get(asset.key);
|
|
129
|
+
if (referenceId === undefined) {
|
|
130
|
+
this.error(`Aelion runtime asset ${asset.key} was not emitted before transform`);
|
|
131
|
+
}
|
|
132
|
+
replacement = `new URL(import.meta.ROLLUP_FILE_URL_${referenceId}, import.meta.url)`;
|
|
133
|
+
}
|
|
134
|
+
transformed = transformed.replace(asset.referencePattern, replacement);
|
|
135
|
+
changed = true;
|
|
136
|
+
}
|
|
137
|
+
return changed ? { code: transformed, map: null } : undefined;
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export default aelion;
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aelionsdk/vite-plugin",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "Official Vite integration for AelionSDK Worker and AudioWorklet assets",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/FoyonaCZY/AelionSDK.git",
|
|
9
|
+
"directory": "packages/vite-plugin"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/FoyonaCZY/AelionSDK#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/FoyonaCZY/AelionSDK/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"aelion",
|
|
17
|
+
"vite",
|
|
18
|
+
"video",
|
|
19
|
+
"worker",
|
|
20
|
+
"audioworklet"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"!dist/.tsbuildinfo"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20.19"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"provenance": true
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@aelionsdk/audio": "0.1.0-beta.1",
|
|
43
|
+
"@aelionsdk/export": "0.1.0-beta.1",
|
|
44
|
+
"@aelionsdk/renderer-worker": "0.1.0-beta.1"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"vite": "^7.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -b",
|
|
51
|
+
"test": "corepack pnpm run build && node test/vite-plugin.test-runner.mjs",
|
|
52
|
+
"typecheck": "tsc -b --pretty false"
|
|
53
|
+
}
|
|
54
|
+
}
|