@needle-tools/engine 5.1.0-canary.db0c38f → 5.1.0-canary.e7c2511
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/.needle/generated/needle-bindings.gen.d.ts +5 -0
- package/CHANGELOG.md +52 -0
- package/components.needle.json +1 -1
- package/dist/{needle-engine.bundle-B29kieh0.js → needle-engine.bundle-D-eWNCu1.js} +12287 -11802
- package/dist/needle-engine.bundle-D3ZUII8o.min.js +1733 -0
- package/dist/needle-engine.bundle-_rOpvUGL.umd.cjs +1733 -0
- package/dist/needle-engine.d.ts +833 -231
- package/dist/needle-engine.js +584 -582
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/api.d.ts +6 -1
- package/lib/engine/api.js +4 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/codegen/register_types.js +2 -10
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/debug/debug_spatial_console.d.ts +2 -0
- package/lib/engine/debug/debug_spatial_console.js +10 -7
- package/lib/engine/debug/debug_spatial_console.js.map +1 -1
- package/lib/engine/engine_addressables.d.ts +2 -0
- package/lib/engine/engine_addressables.js +6 -3
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_audio.d.ts +68 -0
- package/lib/engine/engine_audio.js +172 -0
- package/lib/engine/engine_audio.js.map +1 -1
- package/lib/engine/engine_components.js +1 -1
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_context.d.ts +21 -20
- package/lib/engine/engine_context.js +27 -16
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_disposable.d.ts +171 -0
- package/lib/engine/engine_disposable.js +136 -0
- package/lib/engine/engine_disposable.js.map +1 -0
- package/lib/engine/engine_gameobject.d.ts +1 -10
- package/lib/engine/engine_gameobject.js +22 -120
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +7 -69
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_init.js +16 -1
- package/lib/engine/engine_init.js.map +1 -1
- package/lib/engine/engine_input.d.ts +1 -1
- package/lib/engine/engine_input.js +1 -1
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_instantiate_resolve.d.ts +42 -0
- package/lib/engine/engine_instantiate_resolve.js +372 -0
- package/lib/engine/engine_instantiate_resolve.js.map +1 -0
- package/lib/engine/engine_license.d.ts +2 -0
- package/lib/engine/engine_license.js +14 -6
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_lifecycle_functions_internal.js +5 -0
- package/lib/engine/engine_lifecycle_functions_internal.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.js +5 -2
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_networking.js +3 -1
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking_blob.js +1 -1
- package/lib/engine/engine_networking_blob.js.map +1 -1
- package/lib/engine/engine_physics_rapier.d.ts +11 -3
- package/lib/engine/engine_physics_rapier.js +88 -25
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine/engine_pmrem.js +2 -2
- package/lib/engine/engine_pmrem.js.map +1 -1
- package/lib/engine/engine_scenedata.d.ts +13 -17
- package/lib/engine/engine_scenedata.js +58 -31
- package/lib/engine/engine_scenedata.js.map +1 -1
- package/lib/engine/engine_serialization_builtin_serializer.d.ts +10 -16
- package/lib/engine/engine_serialization_builtin_serializer.js +56 -46
- package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
- package/lib/engine/engine_serialization_core.d.ts +1 -0
- package/lib/engine/engine_serialization_core.js +7 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_ssr.d.ts +2 -0
- package/lib/engine/engine_ssr.js +20 -0
- package/lib/engine/engine_ssr.js.map +1 -1
- package/lib/engine/engine_types.d.ts +19 -9
- package/lib/engine/engine_types.js +1 -1
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_util_decorator.js +7 -2
- package/lib/engine/engine_util_decorator.js.map +1 -1
- package/lib/engine/engine_utils.d.ts +1 -1
- package/lib/engine/engine_utils.js +19 -5
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
- package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js.map +1 -1
- package/lib/engine/webcomponents/jsx.d.ts +51 -0
- package/lib/engine/webcomponents/logo-element.js.map +1 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +3 -4
- package/lib/engine/webcomponents/needle menu/needle-menu.js +1 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
- package/lib/engine/webcomponents/needle-button.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.d.ts +10 -4
- package/lib/engine/webcomponents/needle-engine.js +1 -1
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine/xr/NeedleXRSession.d.ts +3 -2
- package/lib/engine/xr/NeedleXRSession.js +50 -14
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine/xr/events.d.ts +1 -1
- package/lib/engine/xr/events.js.map +1 -1
- package/lib/engine-components/Animation.js +17 -16
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/Animator.d.ts +6 -0
- package/lib/engine-components/Animator.js +17 -12
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.builder.d.ts +113 -0
- package/lib/engine-components/AnimatorController.builder.js +195 -0
- package/lib/engine-components/AnimatorController.builder.js.map +1 -0
- package/lib/engine-components/AnimatorController.d.ts +4 -119
- package/lib/engine-components/AnimatorController.js +35 -233
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioSource.d.ts +19 -3
- package/lib/engine-components/AudioSource.js +121 -68
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +18 -9
- package/lib/engine-components/Collider.js +61 -14
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +58 -6
- package/lib/engine-components/Component.js +77 -0
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +7 -0
- package/lib/engine-components/DragControls.js +19 -7
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/EventList.d.ts +31 -9
- package/lib/engine-components/EventList.js +37 -76
- package/lib/engine-components/EventList.js.map +1 -1
- package/lib/engine-components/Joints.d.ts +4 -2
- package/lib/engine-components/Joints.js +19 -3
- package/lib/engine-components/Joints.js.map +1 -1
- package/lib/engine-components/Light.d.ts +6 -8
- package/lib/engine-components/Light.js +48 -27
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/Networking.d.ts +1 -1
- package/lib/engine-components/Networking.js +1 -1
- package/lib/engine-components/OrbitControls.js +16 -11
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +2 -0
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +12 -4
- package/lib/engine-components/RigidBody.js +18 -4
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SeeThrough.js +2 -2
- package/lib/engine-components/SeeThrough.js.map +1 -1
- package/lib/engine-components/api.d.ts +1 -1
- package/lib/engine-components/api.js +1 -1
- package/lib/engine-components/api.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +3 -9
- package/lib/engine-components/codegen/components.js +3 -9
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +1 -1
- package/lib/engine-components/postprocessing/VolumeParameter.d.ts +2 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js +4 -1
- package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -1
- package/lib/engine-components/timeline/PlayableDirector.d.ts +16 -6
- package/lib/engine-components/timeline/PlayableDirector.js +63 -61
- package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
- package/lib/engine-components/timeline/SignalAsset.d.ts +3 -1
- package/lib/engine-components/timeline/SignalAsset.js +1 -0
- package/lib/engine-components/timeline/SignalAsset.js.map +1 -1
- package/lib/engine-components/timeline/TimelineBuilder.d.ts +247 -0
- package/lib/engine-components/timeline/TimelineBuilder.js +400 -0
- package/lib/engine-components/timeline/TimelineBuilder.js.map +1 -0
- package/lib/engine-components/timeline/TimelineModels.d.ts +2 -1
- package/lib/engine-components/timeline/TimelineModels.js +3 -0
- package/lib/engine-components/timeline/TimelineModels.js.map +1 -1
- package/lib/engine-components/timeline/TimelineTracks.d.ts +23 -0
- package/lib/engine-components/timeline/TimelineTracks.js +71 -13
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/timeline/index.d.ts +2 -1
- package/lib/engine-components/timeline/index.js +2 -0
- package/lib/engine-components/timeline/index.js.map +1 -1
- package/lib/engine-components/ui/Canvas.d.ts +1 -1
- package/lib/engine-components/ui/Canvas.js +2 -8
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/engine-components/ui/Text.d.ts +1 -0
- package/lib/engine-components/ui/Text.js +10 -7
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components/web/CursorFollow.js +21 -12
- package/lib/engine-components/web/CursorFollow.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.js +4 -0
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/lib/needle-engine.d.ts +2 -0
- package/lib/needle-engine.js +2 -0
- package/lib/needle-engine.js.map +1 -1
- package/package.json +4 -84
- package/plugins/common/worker.js +9 -4
- package/plugins/dts-generator/dts.codegen.js +255 -50
- package/plugins/dts-generator/dts.scan.js +37 -9
- package/plugins/dts-generator/dts.writer.js +1 -1
- package/plugins/dts-generator/glb.discovery.js +140 -23
- package/plugins/dts-generator/glb.extractor.js +48 -8
- package/plugins/dts-generator/glb.reader.js +80 -27
- package/plugins/dts-generator/index.js +1 -1
- package/plugins/types/needle-bindings.d.ts +25 -14
- package/plugins/types/userconfig.d.ts +12 -0
- package/plugins/vite/asap.js +18 -9
- package/plugins/vite/dependencies.js +29 -0
- package/plugins/vite/dependency-watcher.d.ts +2 -2
- package/plugins/vite/dependency-watcher.js +5 -6
- package/plugins/vite/drop.d.ts +2 -2
- package/plugins/vite/drop.js +3 -4
- package/plugins/vite/dts-generator.d.ts +2 -2
- package/plugins/vite/dts-generator.js +43 -9
- package/plugins/vite/editor-connection.js +3 -3
- package/plugins/vite/index.d.ts +9 -3
- package/plugins/vite/index.js +23 -10
- package/plugins/vite/local-files-core.js +3 -3
- package/plugins/vite/local-files-utils.d.ts +3 -1
- package/plugins/vite/local-files-utils.js +29 -5
- package/plugins/vite/meta.js +4 -2
- package/plugins/vite/poster.d.ts +2 -2
- package/plugins/vite/poster.js +3 -5
- package/plugins/vite/reload.d.ts +2 -2
- package/plugins/vite/reload.js +23 -23
- package/plugins/vite/server.js +2 -1
- package/src/engine/api.ts +8 -1
- package/src/engine/codegen/register_types.ts +2 -10
- package/src/engine/debug/debug_spatial_console.ts +10 -7
- package/src/engine/engine_addressables.ts +6 -3
- package/src/engine/engine_audio.ts +184 -0
- package/src/engine/engine_components.ts +1 -1
- package/src/engine/engine_context.ts +36 -22
- package/src/engine/engine_disposable.ts +213 -0
- package/src/engine/engine_gameobject.ts +54 -159
- package/src/engine/engine_gltf_builtin_components.ts +7 -76
- package/src/engine/engine_init.ts +15 -1
- package/src/engine/engine_input.ts +1 -1
- package/src/engine/engine_instantiate_resolve.ts +407 -0
- package/src/engine/engine_license.ts +12 -10
- package/src/engine/engine_lifecycle_functions_internal.ts +7 -0
- package/src/engine/engine_mainloop_utils.ts +5 -2
- package/src/engine/engine_networking.ts +3 -1
- package/src/engine/engine_networking_blob.ts +1 -1
- package/src/engine/engine_physics_rapier.ts +82 -27
- package/src/engine/engine_pmrem.ts +3 -3
- package/src/engine/engine_scenedata.ts +56 -30
- package/src/engine/engine_serialization_builtin_serializer.ts +64 -52
- package/src/engine/engine_serialization_core.ts +9 -0
- package/src/engine/engine_ssr.ts +29 -3
- package/src/engine/engine_types.ts +24 -13
- package/src/engine/engine_util_decorator.ts +7 -2
- package/src/engine/engine_utils.ts +16 -5
- package/src/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
- package/src/engine/webcomponents/jsx.d.ts +51 -0
- package/src/engine/webcomponents/logo-element.ts +1 -0
- package/src/engine/webcomponents/needle menu/needle-menu.ts +3 -2
- package/src/engine/webcomponents/needle-button.ts +1 -0
- package/src/engine/webcomponents/needle-engine.ts +11 -4
- package/src/engine/xr/NeedleXRSession.ts +48 -13
- package/src/engine/xr/events.ts +1 -1
- package/src/engine-components/Animation.ts +19 -16
- package/src/engine-components/Animator.ts +18 -11
- package/src/engine-components/AnimatorController.builder.ts +261 -0
- package/src/engine-components/AnimatorController.ts +23 -292
- package/src/engine-components/AudioSource.ts +130 -79
- package/src/engine-components/Collider.ts +66 -18
- package/src/engine-components/Component.ts +79 -9
- package/src/engine-components/DragControls.ts +18 -11
- package/src/engine-components/EventList.ts +45 -83
- package/src/engine-components/Joints.ts +20 -4
- package/src/engine-components/Light.ts +49 -27
- package/src/engine-components/Networking.ts +1 -1
- package/src/engine-components/OrbitControls.ts +18 -9
- package/src/engine-components/ReflectionProbe.ts +2 -0
- package/src/engine-components/RigidBody.ts +18 -4
- package/src/engine-components/SeeThrough.ts +2 -2
- package/src/engine-components/api.ts +1 -1
- package/src/engine-components/codegen/components.ts +3 -9
- package/src/engine-components/postprocessing/VolumeParameter.ts +4 -1
- package/src/engine-components/timeline/PlayableDirector.ts +61 -64
- package/src/engine-components/timeline/SignalAsset.ts +4 -1
- package/src/engine-components/timeline/TimelineBuilder.ts +565 -0
- package/src/engine-components/timeline/TimelineModels.ts +5 -1
- package/src/engine-components/timeline/TimelineTracks.ts +74 -13
- package/src/engine-components/timeline/index.ts +2 -1
- package/src/engine-components/ui/Canvas.ts +2 -8
- package/src/engine-components/ui/Text.ts +12 -8
- package/src/engine-components/web/CursorFollow.ts +21 -13
- package/src/engine-components/webxr/WebXRImageTracking.ts +2 -0
- package/src/needle-engine.ts +3 -0
- package/dist/needle-engine.bundle-Dq0Ly8fW.umd.cjs +0 -1732
- package/dist/needle-engine.bundle-YnpzzOPL.min.js +0 -1732
- package/lib/engine-components/AvatarLoader.d.ts +0 -80
- package/lib/engine-components/AvatarLoader.js +0 -232
- package/lib/engine-components/AvatarLoader.js.map +0 -1
- package/lib/engine-components/avatar/AvatarBlink_Simple.d.ts +0 -11
- package/lib/engine-components/avatar/AvatarBlink_Simple.js +0 -77
- package/lib/engine-components/avatar/AvatarBlink_Simple.js.map +0 -1
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.d.ts +0 -14
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js +0 -69
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js.map +0 -1
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.d.ts +0 -29
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.js +0 -122
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.js.map +0 -1
- package/lib/engine-components/avatar/Avatar_MouthShapes.d.ts +0 -15
- package/lib/engine-components/avatar/Avatar_MouthShapes.js +0 -80
- package/lib/engine-components/avatar/Avatar_MouthShapes.js.map +0 -1
- package/lib/engine-components/avatar/Avatar_MustacheShake.d.ts +0 -9
- package/lib/engine-components/avatar/Avatar_MustacheShake.js +0 -30
- package/lib/engine-components/avatar/Avatar_MustacheShake.js.map +0 -1
- package/src/engine-components/AvatarLoader.ts +0 -264
- package/src/engine-components/avatar/AvatarBlink_Simple.ts +0 -70
- package/src/engine-components/avatar/AvatarEyeLook_Rotation.ts +0 -64
- package/src/engine-components/avatar/Avatar_Brain_LookAt.ts +0 -140
- package/src/engine-components/avatar/Avatar_MouthShapes.ts +0 -84
- package/src/engine-components/avatar/Avatar_MustacheShake.ts +0 -32
package/plugins/vite/asap.js
CHANGED
|
@@ -22,7 +22,7 @@ export async function needleAsap(command, config, userSettings) {
|
|
|
22
22
|
|
|
23
23
|
fixMainTs();
|
|
24
24
|
|
|
25
|
-
if (command
|
|
25
|
+
if (command === "serve") {
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -50,7 +50,7 @@ export async function needleAsap(command, config, userSettings) {
|
|
|
50
50
|
const tags = [];
|
|
51
51
|
|
|
52
52
|
try {
|
|
53
|
-
generateGltfPreloadLinks(config, html, tags);
|
|
53
|
+
generateGltfPreloadLinks(config, html, tags, viteConfig?.base);
|
|
54
54
|
}
|
|
55
55
|
catch (err) {
|
|
56
56
|
console.error("Error generating gltf preload links", err);
|
|
@@ -173,18 +173,21 @@ function fixMainTs() {
|
|
|
173
173
|
* @param {import('vite').ResolvedConfig} _config
|
|
174
174
|
* @param {import('vite').HtmlTagDescriptor[]} tags
|
|
175
175
|
*/
|
|
176
|
-
function generateScriptPreloadLinks(
|
|
176
|
+
function generateScriptPreloadLinks(config, tags) {
|
|
177
177
|
try {
|
|
178
|
+
const base = config.base || '/';
|
|
178
179
|
const chunks = preloadScriptPaths;
|
|
179
180
|
// console.log("ASAP", chunks)
|
|
180
181
|
if (chunks.length > 0) {
|
|
181
182
|
for (const chunk of chunks) {
|
|
183
|
+
// Apply base path so preload hrefs resolve correctly under SPA routing
|
|
184
|
+
const href = chunk.startsWith('./') ? base + chunk.slice(2) : chunk;
|
|
182
185
|
tags.push({
|
|
183
186
|
tag: 'link',
|
|
184
187
|
attrs: {
|
|
185
188
|
rel: "modulepreload",
|
|
186
189
|
as: "script",
|
|
187
|
-
href:
|
|
190
|
+
href: href,
|
|
188
191
|
}
|
|
189
192
|
});
|
|
190
193
|
}
|
|
@@ -203,15 +206,16 @@ const codegenRegex = /\"(?<gltf>.+(.glb|.gltf)(\?.*)?)\"/gm;
|
|
|
203
206
|
/**
|
|
204
207
|
* @param {import('../types').needleConfig} config
|
|
205
208
|
* @param {string} html
|
|
206
|
-
* @param {import('vite').HtmlTagDescriptor[]} tags
|
|
209
|
+
* @param {import('vite').HtmlTagDescriptor[]} tags
|
|
210
|
+
* @param {string} [base]
|
|
207
211
|
**/
|
|
208
|
-
function generateGltfPreloadLinks(config, html, tags) {
|
|
212
|
+
function generateGltfPreloadLinks(config, html, tags, base) {
|
|
209
213
|
|
|
210
214
|
// TODO: try to get the <needle-engine src> element src attribute and preload that
|
|
211
215
|
const needleEngineMatches = tryParseNeedleEngineSrcAttributeFromHtml(html);
|
|
212
216
|
if (needleEngineMatches?.length) {
|
|
213
217
|
for (const item of needleEngineMatches) {
|
|
214
|
-
insertPreloadLink(tags, item, "model/gltf+json");
|
|
218
|
+
insertPreloadLink(tags, item, "model/gltf+json", base);
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
|
|
@@ -246,7 +250,7 @@ function generateGltfPreloadLinks(config, html, tags) {
|
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
252
|
needleLog("needle:asap", `Insert glTF preload link: ${value}`);
|
|
249
|
-
insertPreloadLink(tags, value, "model/gltf+json");
|
|
253
|
+
insertPreloadLink(tags, value, "model/gltf+json", base);
|
|
250
254
|
}
|
|
251
255
|
}
|
|
252
256
|
}
|
|
@@ -258,9 +262,14 @@ function generateGltfPreloadLinks(config, html, tags) {
|
|
|
258
262
|
* @param {import('vite').HtmlTagDescriptor[]} tags
|
|
259
263
|
* @param {string} href
|
|
260
264
|
* @param {string} type
|
|
265
|
+
* @param {string} [base]
|
|
261
266
|
*/
|
|
262
|
-
function insertPreloadLink(tags, href, type) {
|
|
267
|
+
function insertPreloadLink(tags, href, type, base) {
|
|
263
268
|
if (!href) return;
|
|
269
|
+
// Apply base path so preload hrefs resolve correctly under SPA routing
|
|
270
|
+
if (base && !href.startsWith('http') && !href.startsWith('/')) {
|
|
271
|
+
href = base + (href.startsWith('./') ? href.slice(2) : href);
|
|
272
|
+
}
|
|
264
273
|
tags.push({
|
|
265
274
|
tag: 'link',
|
|
266
275
|
attrs: {
|
|
@@ -61,6 +61,35 @@ export function needleDependencies(command, config, userSettings) {
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
},
|
|
64
|
+
// Vite 8's optimizer rebases `new URL(specifier, import.meta.url)` paths
|
|
65
|
+
// inside pre-bundled dependencies (PR #21434), but only handles truly relative
|
|
66
|
+
// paths (./ ../). Bare-specifier paths like `three-mesh-bvh/src/workers/...`
|
|
67
|
+
// are treated as relative to the *source file* that contained the `new URL()`
|
|
68
|
+
// call, producing a wrong URL such as:
|
|
69
|
+
// /node_modules/@needle-tools/engine/.../three-mesh-bvh/src/workers/generateMeshBVH.worker.js
|
|
70
|
+
// This middleware rewrites those broken URLs so the dev server finds the file at
|
|
71
|
+
// its real location in node_modules.
|
|
72
|
+
{
|
|
73
|
+
name: 'needle:worker-url-rewrite',
|
|
74
|
+
configureServer(server) {
|
|
75
|
+
const rewritePackages = ['three-mesh-bvh'];
|
|
76
|
+
server.middlewares.use((req, _res, next) => {
|
|
77
|
+
if (req.url) {
|
|
78
|
+
for (const pkg of rewritePackages) {
|
|
79
|
+
const marker = `/${pkg}/`;
|
|
80
|
+
if (req.url.includes(marker) && !req.url.startsWith(`/node_modules/${pkg}/`)) {
|
|
81
|
+
const idx = req.url.indexOf(marker);
|
|
82
|
+
const rewritten = '/node_modules' + req.url.slice(idx);
|
|
83
|
+
needleLog('needle-dependencies', `Rewriting worker URL → ${rewritten}`);
|
|
84
|
+
req.url = rewritten;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
next();
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
},
|
|
64
93
|
]
|
|
65
94
|
}
|
|
66
95
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {"build" | "serve"}
|
|
2
|
+
* @param {"build" | "serve" | undefined} _command
|
|
3
3
|
* @param {unknown} _config
|
|
4
4
|
* @param {import('../types').userSettings} userSettings
|
|
5
5
|
* @returns {import('vite').Plugin | null}
|
|
6
6
|
*/
|
|
7
|
-
export function needleDependencyWatcher(
|
|
7
|
+
export function needleDependencyWatcher(_command: "build" | "serve" | undefined, _config: unknown, userSettings: import("../types").userSettings): import("vite").Plugin | null;
|
|
8
8
|
export type PackageJson = {
|
|
9
9
|
dependencies?: Record<string, string>;
|
|
10
10
|
devDependencies?: Record<string, string>;
|
|
@@ -12,14 +12,12 @@ function log(...msg) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @param {"build" | "serve"}
|
|
15
|
+
* @param {"build" | "serve" | undefined} _command
|
|
16
16
|
* @param {unknown} _config
|
|
17
17
|
* @param {import('../types').userSettings} userSettings
|
|
18
18
|
* @returns {import('vite').Plugin | null}
|
|
19
19
|
*/
|
|
20
|
-
export function needleDependencyWatcher(
|
|
21
|
-
if (command === "build") return null;
|
|
22
|
-
|
|
20
|
+
export function needleDependencyWatcher(_command, _config, userSettings) {
|
|
23
21
|
if (userSettings?.noDependencyWatcher === true) return null;
|
|
24
22
|
|
|
25
23
|
const dir = process.cwd();
|
|
@@ -28,6 +26,7 @@ export function needleDependencyWatcher(command, _config, userSettings) {
|
|
|
28
26
|
|
|
29
27
|
return /** @type {import('vite').Plugin} */ ({
|
|
30
28
|
name: 'needle-dependency-watcher',
|
|
29
|
+
apply: 'serve',
|
|
31
30
|
/** @param {import('vite').ViteDevServer} server */
|
|
32
31
|
configureServer(server) {
|
|
33
32
|
manageClients(server);
|
|
@@ -99,7 +98,7 @@ function watchPackageJson(server, projectDir, packageJsonPath, cachePath) {
|
|
|
99
98
|
|
|
100
99
|
setTimeout(() => {
|
|
101
100
|
requireInstall = testIfInstallIsRequired(projectDir, packageJson);
|
|
102
|
-
}, 1000);
|
|
101
|
+
}, 1000).unref();
|
|
103
102
|
|
|
104
103
|
setInterval(() => {
|
|
105
104
|
if (!packageJson || lastEditTime === undefined) return;
|
|
@@ -150,7 +149,7 @@ function watchPackageJson(server, projectDir, packageJsonPath, cachePath) {
|
|
|
150
149
|
restart(server, projectDir, cachePath);
|
|
151
150
|
}
|
|
152
151
|
}
|
|
153
|
-
}, 2000);
|
|
152
|
+
}, 2000).unref();
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
/** @param {string} projectDir @param {PackageJson | undefined} packageJson @returns {boolean} */
|
package/plugins/vite/drop.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Experimental, allow dropping files from Unity into the running scene.
|
|
2
|
-
* @param {"build" | "serve"}
|
|
2
|
+
* @param {"build" | "serve" | undefined} _command
|
|
3
3
|
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
4
4
|
* @param {import('../types/userconfig.js').userSettings} userSettings
|
|
5
5
|
* @returns {import('vite').Plugin | null | undefined}
|
|
6
6
|
*/
|
|
7
|
-
export function needleDrop(
|
|
7
|
+
export function needleDrop(_command: "build" | "serve" | undefined, config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types/userconfig.js").userSettings): import("vite").Plugin | null | undefined;
|
package/plugins/vite/drop.js
CHANGED
|
@@ -7,18 +7,17 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
7
7
|
const __dirname = path.dirname(__filename);
|
|
8
8
|
|
|
9
9
|
/** Experimental, allow dropping files from Unity into the running scene.
|
|
10
|
-
* @param {"build" | "serve"}
|
|
10
|
+
* @param {"build" | "serve" | undefined} _command
|
|
11
11
|
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
12
12
|
* @param {import('../types/userconfig.js').userSettings} userSettings
|
|
13
13
|
* @returns {import('vite').Plugin | null | undefined}
|
|
14
14
|
*/
|
|
15
|
-
export function needleDrop(
|
|
16
|
-
if (command === "build") return;
|
|
17
|
-
|
|
15
|
+
export function needleDrop(_command, config, userSettings) {
|
|
18
16
|
if(userSettings.useDrop !== true) return null;
|
|
19
17
|
|
|
20
18
|
return {
|
|
21
19
|
name: "needle:drop",
|
|
20
|
+
apply: 'serve',
|
|
22
21
|
config(/** @type {{ server?: { hmr?: { port?: number } } }} */ viteConfig) {
|
|
23
22
|
if(userSettings)
|
|
24
23
|
if (!viteConfig.server) viteConfig.server = {};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* @param {"build" | "serve"} _command Vite command (unused — runs in both modes)
|
|
3
3
|
* @param {import('../types/needleConfig').needleMeta | null | undefined} _config
|
|
4
4
|
* @param {import('../types').userSettings} [_userSettings]
|
|
5
|
-
* @returns {import('vite').Plugin}
|
|
5
|
+
* @returns {import('vite').Plugin | null}
|
|
6
6
|
*/
|
|
7
|
-
export function needleDtsGenerator(_command: "build" | "serve", _config: import("../types/needleConfig").needleMeta | null | undefined, _userSettings?: import("../types").userSettings): import("vite").Plugin;
|
|
7
|
+
export function needleDtsGenerator(_command: "build" | "serve", _config: import("../types/needleConfig").needleMeta | null | undefined, _userSettings?: import("../types").userSettings): import("vite").Plugin | null;
|
|
@@ -16,12 +16,24 @@
|
|
|
16
16
|
* needleDtsGenerator(command, needleConfig, userSettings)
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { join, resolve } from 'path';
|
|
20
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
19
|
+
import { join, resolve, dirname } from 'path';
|
|
20
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, realpathSync } from 'fs';
|
|
21
21
|
import { tryLoadProjectConfig } from './config.js';
|
|
22
22
|
import { generateBindingsDts } from '../dts-generator/index.js';
|
|
23
23
|
import { needleLog } from './logging.js';
|
|
24
24
|
|
|
25
|
+
// Two dirs up from plugins/vite/ → package root.
|
|
26
|
+
// Use fileURLToPath so %7E and other URL-encoded characters in the path are decoded correctly.
|
|
27
|
+
// realpathSync follows symlinks so the path is stable even in npm link / monorepo setups.
|
|
28
|
+
import { fileURLToPath } from 'url';
|
|
29
|
+
let _packageRoot = /** @type {string | null} */ (null);
|
|
30
|
+
try {
|
|
31
|
+
_packageRoot = realpathSync(join(dirname(fileURLToPath(import.meta.url)), '..', '..'));
|
|
32
|
+
} catch (_e) {
|
|
33
|
+
// If we can't resolve the package root (e.g. unusual install layout), the plugin
|
|
34
|
+
// will silently skip generation rather than crashing the dev server.
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
/**
|
|
26
38
|
* Ensure `.vscode/settings.json` references the generated `needle-html-data.json`
|
|
27
39
|
* so VS Code provides `data-bind-needle` completions in HTML files automatically.
|
|
@@ -60,9 +72,14 @@ function ensureVscodeHtmlCustomData(projectRoot, htmlDataPath) {
|
|
|
60
72
|
* @param {"build" | "serve"} _command Vite command (unused — runs in both modes)
|
|
61
73
|
* @param {import('../types/needleConfig').needleMeta | null | undefined} _config
|
|
62
74
|
* @param {import('../types').userSettings} [_userSettings]
|
|
63
|
-
* @returns {import('vite').Plugin}
|
|
75
|
+
* @returns {import('vite').Plugin | null}
|
|
64
76
|
*/
|
|
65
77
|
export function needleDtsGenerator(_command, _config, _userSettings) {
|
|
78
|
+
|
|
79
|
+
if(_userSettings?.dts?.enabled === false) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
66
83
|
let projectRoot = process.cwd();
|
|
67
84
|
|
|
68
85
|
function resolveCodegenDir() {
|
|
@@ -73,7 +90,11 @@ export function needleDtsGenerator(_command, _config, _userSettings) {
|
|
|
73
90
|
}
|
|
74
91
|
|
|
75
92
|
function resolveOutputPath() {
|
|
76
|
-
|
|
93
|
+
// Write to a .needle dotfolder at the package root.
|
|
94
|
+
// Not in the `files` allowlist → never npm-published.
|
|
95
|
+
// ../../.needle/ from plugins/types/ resolves correctly for both
|
|
96
|
+
// symlinked (js/package~/) and published (node_modules/@needle-tools/engine/) layouts.
|
|
97
|
+
return join(/** @type {string} */ (_packageRoot), ".needle", "generated", "needle-bindings.gen.d.ts");
|
|
77
98
|
}
|
|
78
99
|
|
|
79
100
|
function resolveAssetsDir() {
|
|
@@ -86,14 +107,24 @@ export function needleDtsGenerator(_command, _config, _userSettings) {
|
|
|
86
107
|
/** @type {import('vite').ViteDevServer | undefined} */
|
|
87
108
|
let devServer;
|
|
88
109
|
|
|
89
|
-
|
|
110
|
+
/** @type {Promise<void> | null} */
|
|
111
|
+
let _runInFlight = null;
|
|
112
|
+
|
|
113
|
+
function run() {
|
|
114
|
+
if (_runInFlight) return _runInFlight;
|
|
115
|
+
_runInFlight = _doRun().finally(() => { _runInFlight = null; });
|
|
116
|
+
return _runInFlight;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function _doRun() {
|
|
90
120
|
try {
|
|
121
|
+
if (!_packageRoot) return;
|
|
91
122
|
const assetsDir = resolveAssetsDir();
|
|
92
123
|
const outputPath = resolveOutputPath();
|
|
93
124
|
const codegenDir = resolveCodegenDir();
|
|
94
125
|
const count = await generateBindingsDts({ assetsDir, outputPath, projectRoot, codegenDir });
|
|
95
|
-
//
|
|
96
|
-
const htmlDataPath = join(
|
|
126
|
+
// HTML custom data sits next to the generated dts in .needle/generated/
|
|
127
|
+
const htmlDataPath = join(/** @type {string} */ (_packageRoot), ".needle", "generated", "needle-html-data.json");
|
|
97
128
|
ensureVscodeHtmlCustomData(projectRoot, htmlDataPath);
|
|
98
129
|
if (count !== false) {
|
|
99
130
|
needleLog("needle:dts-generator", `${count} binding(s) → ${outputPath.replace(process.cwd(), ".")}`);
|
|
@@ -102,7 +133,7 @@ export function needleDtsGenerator(_command, _config, _userSettings) {
|
|
|
102
133
|
hot.send({ type: "full-reload", path: "*" });
|
|
103
134
|
}
|
|
104
135
|
} else {
|
|
105
|
-
needleLog("needle:dts-generator", `up-to-date`);
|
|
136
|
+
needleLog("needle:dts-generator", `up-to-date → ${outputPath.replace(process.cwd(), ".")}`);
|
|
106
137
|
}
|
|
107
138
|
} catch (err) {
|
|
108
139
|
needleLog("needle:dts-generator", "Failed: " + (/** @type {any} */ (err)?.message ?? err));
|
|
@@ -118,7 +149,10 @@ export function needleDtsGenerator(_command, _config, _userSettings) {
|
|
|
118
149
|
},
|
|
119
150
|
|
|
120
151
|
buildStart() {
|
|
121
|
-
|
|
152
|
+
// In serve mode, the configureServer post-hook runs instead.
|
|
153
|
+
// Only run here for actual builds (no devServer).
|
|
154
|
+
if (!devServer) return run();
|
|
155
|
+
return undefined;
|
|
122
156
|
},
|
|
123
157
|
|
|
124
158
|
/** @param {import('vite').ViteDevServer} server */
|
|
@@ -27,7 +27,7 @@ export async function editorConnection(command, config, userSettings, pluginsArr
|
|
|
27
27
|
if (typeof config.generator === "string" && !config.generator.includes("Unity")) return;
|
|
28
28
|
|
|
29
29
|
if (!config) {
|
|
30
|
-
setTimeout(() => needleLog("needle-editor-sync", "Needle Editor Sync can not be installed automatically to vite: missing config", "warn"), 1000);
|
|
30
|
+
setTimeout(() => needleLog("needle-editor-sync", "Needle Editor Sync can not be installed automatically to vite: missing config", "warn"), 1000).unref();
|
|
31
31
|
return createPlugin(false);
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -42,14 +42,14 @@ export async function editorConnection(command, config, userSettings, pluginsArr
|
|
|
42
42
|
// }
|
|
43
43
|
// }
|
|
44
44
|
if (needleEditorSettings && needleEditorSettings.enabled === false) {
|
|
45
|
-
setTimeout(() => needleLog("needle-editor-sync", "Needle Editor Sync is not enabled. Add a 'Needle Editor Sync' component to your scene to enable", "warn"), 1000);
|
|
45
|
+
setTimeout(() => needleLog("needle-editor-sync", "Needle Editor Sync is not enabled. Add a 'Needle Editor Sync' component to your scene to enable", "warn"), 1000).unref();
|
|
46
46
|
return createPlugin(false);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// Check if the editor package is installed
|
|
50
50
|
let path = root + `/node_modules/${editorSyncPackageName}/plugins/index.js`;
|
|
51
51
|
if (existsSync(path) === false) {
|
|
52
|
-
setTimeout(() => needleLog("needle-editor-sync", `${editorSyncPackageName} is not installed: Add the "Needle Editor Sync" component to your scene if you want to send changes directly from the Unity Editor to web app`, "warn"), 1000);
|
|
52
|
+
setTimeout(() => needleLog("needle-editor-sync", `${editorSyncPackageName} is not installed: Add the "Needle Editor Sync" component to your scene if you want to send changes directly from the Unity Editor to web app`, "warn"), 1000).unref();
|
|
53
53
|
return createPlugin(false);
|
|
54
54
|
}
|
|
55
55
|
|
package/plugins/vite/index.d.ts
CHANGED
|
@@ -19,12 +19,18 @@
|
|
|
19
19
|
* ],
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* When used without arguments (e.g. in a SvelteKit `defineConfig({})` plain object),
|
|
23
|
+
* the command is resolved automatically from Vite's `configResolved` hook.
|
|
24
|
+
* ```js
|
|
25
|
+
* // SvelteKit — no command needed:
|
|
26
|
+
* export default defineConfig({ plugins: [sveltekit(), needlePlugins()] });
|
|
27
|
+
* ```
|
|
28
|
+
* @param {"build" | "serve" | undefined} [command]
|
|
29
|
+
* @param {import('../types/needleConfig').needleMeta | null | undefined} [config]
|
|
24
30
|
* @param {import('../types/index.js').userSettings} [userSettings]
|
|
25
31
|
* @returns {Promise<import('vite').Plugin[]>}
|
|
26
32
|
*/
|
|
27
|
-
export function needlePlugins(command
|
|
33
|
+
export function needlePlugins(command?: "build" | "serve" | undefined, config?: import("../types/needleConfig").needleMeta | null | undefined, userSettings?: import("../types/index.js").userSettings): Promise<import("vite").Plugin[]>;
|
|
28
34
|
export { needleAI } from "./ai.js";
|
|
29
35
|
export { needleDtsGenerator } from "./dts-generator.js";
|
|
30
36
|
export { needleAsap } from "./asap.js";
|
package/plugins/vite/index.js
CHANGED
|
@@ -116,12 +116,18 @@ const defaultUserSettings = {
|
|
|
116
116
|
* ],
|
|
117
117
|
* }
|
|
118
118
|
* ```
|
|
119
|
-
*
|
|
120
|
-
*
|
|
119
|
+
* When used without arguments (e.g. in a SvelteKit `defineConfig({})` plain object),
|
|
120
|
+
* the command is resolved automatically from Vite's `configResolved` hook.
|
|
121
|
+
* ```js
|
|
122
|
+
* // SvelteKit — no command needed:
|
|
123
|
+
* export default defineConfig({ plugins: [sveltekit(), needlePlugins()] });
|
|
124
|
+
* ```
|
|
125
|
+
* @param {"build" | "serve" | undefined} [command]
|
|
126
|
+
* @param {import('../types/needleConfig').needleMeta | null | undefined} [config]
|
|
121
127
|
* @param {import('../types/index.js').userSettings} [userSettings]
|
|
122
128
|
* @returns {Promise<import('vite').Plugin[]>}
|
|
123
129
|
*/
|
|
124
|
-
export async function needlePlugins(command, config = undefined, userSettings = {}) {
|
|
130
|
+
export async function needlePlugins(command = undefined, config = undefined, userSettings = {}) {
|
|
125
131
|
|
|
126
132
|
if (!config) config = {}
|
|
127
133
|
|
|
@@ -168,14 +174,21 @@ export async function needlePlugins(command, config = undefined, userSettings =
|
|
|
168
174
|
array.push(await editorConnection(command, config, userSettings, array));
|
|
169
175
|
array.push(needleDependencyWatcher(command, config, userSettings));
|
|
170
176
|
|
|
171
|
-
// Ensure the process exits on SIGINT (Ctrl+C) since plugin timers/sockets can keep the event loop alive
|
|
172
|
-
|
|
177
|
+
// Ensure the process exits on SIGINT (Ctrl+C) since plugin timers/sockets can keep the event loop alive.
|
|
178
|
+
// If command is unknown at call time (e.g. SvelteKit plain defineConfig), defer to configResolved.
|
|
179
|
+
const registerSigint = () => {
|
|
173
180
|
process.on('SIGINT', () => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
setTimeout(() => { console.debug('\nGoodbye!'); process.exit(); }, 1000);
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
if (command === "serve") {
|
|
185
|
+
registerSigint();
|
|
186
|
+
} else if (command === undefined) {
|
|
187
|
+
array.push({
|
|
188
|
+
name: "needle:sigint",
|
|
189
|
+
configResolved(config) {
|
|
190
|
+
if (config.command === "serve") registerSigint();
|
|
191
|
+
}
|
|
179
192
|
});
|
|
180
193
|
}
|
|
181
194
|
|
|
@@ -291,7 +291,7 @@ export function needleMakeFilesLocal(command, _config, userSettings) {
|
|
|
291
291
|
failedDownloads,
|
|
292
292
|
localizationStats,
|
|
293
293
|
}, activeHandlers);
|
|
294
|
-
src = fixRelativeNewURL(src);
|
|
294
|
+
src = fixRelativeNewURL(src, viteConfig?.base);
|
|
295
295
|
}
|
|
296
296
|
catch (err) {
|
|
297
297
|
needleLog("needle:local-files", "Error in transform: " + getErrMessage(err), "error");
|
|
@@ -303,7 +303,7 @@ export function needleMakeFilesLocal(command, _config, userSettings) {
|
|
|
303
303
|
},
|
|
304
304
|
renderChunk(code, chunk) {
|
|
305
305
|
if (!chunk.fileName?.endsWith(".js")) return null;
|
|
306
|
-
const fixed = fixRelativeNewURL(code);
|
|
306
|
+
const fixed = fixRelativeNewURL(code, viteConfig?.base);
|
|
307
307
|
if (fixed === code) return null;
|
|
308
308
|
return {
|
|
309
309
|
code: fixed,
|
|
@@ -314,7 +314,7 @@ export function needleMakeFilesLocal(command, _config, userSettings) {
|
|
|
314
314
|
for (const output of Object.values(bundle)) {
|
|
315
315
|
if (output.type !== "chunk") continue;
|
|
316
316
|
if (!output.fileName?.endsWith(".js")) continue;
|
|
317
|
-
const fixed = fixRelativeNewURL(output.code);
|
|
317
|
+
const fixed = fixRelativeNewURL(output.code, viteConfig?.base);
|
|
318
318
|
if (fixed !== output.code) output.code = fixed;
|
|
319
319
|
}
|
|
320
320
|
},
|
|
@@ -24,9 +24,11 @@ export function normalizeWebPath(path: string): string;
|
|
|
24
24
|
export function ensureTrailingSlash(path: string): string;
|
|
25
25
|
/**
|
|
26
26
|
* @param {string} src
|
|
27
|
+
* @param {string} [base] - Vite base path (e.g. "/" or "/app/"). When provided,
|
|
28
|
+
* ext/ paths are made absolute so they resolve correctly under SPA routing.
|
|
27
29
|
* @returns {string}
|
|
28
30
|
*/
|
|
29
|
-
export function fixRelativeNewURL(src: string): string;
|
|
31
|
+
export function fixRelativeNewURL(src: string, base?: string): string;
|
|
30
32
|
/**
|
|
31
33
|
* @param {string} src
|
|
32
34
|
* @returns {string}
|
|
@@ -113,25 +113,49 @@ export function ensureTrailingSlash(path) {
|
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* @param {string} src
|
|
116
|
+
* @param {string} [base] - Vite base path (e.g. "/" or "/app/"). When provided,
|
|
117
|
+
* ext/ paths are made absolute so they resolve correctly under SPA routing.
|
|
116
118
|
* @returns {string}
|
|
117
119
|
*/
|
|
118
|
-
export function fixRelativeNewURL(src) {
|
|
120
|
+
export function fixRelativeNewURL(src, base) {
|
|
121
|
+
/** @param {string} path */
|
|
122
|
+
function makeAbsolute(path) {
|
|
123
|
+
// Strip any leading ./ ../ or / prefix to get the clean ext/... path
|
|
124
|
+
const clean = path.replace(/^(?:\.\.?\/)+/, '').replace(/^\//, '');
|
|
125
|
+
if (base) return base.replace(/\/+$/, '') + '/' + clean;
|
|
126
|
+
return clean;
|
|
127
|
+
}
|
|
128
|
+
|
|
119
129
|
src = src.replace(
|
|
120
130
|
/(?<==\s*)(["'])((?:(?:\.{1,2}\/)|\/)?ext\/[^"']*\/)\1/g,
|
|
121
131
|
(/** @type {string} */ _match, /** @type {string} */ quote, /** @type {string} */ path) => {
|
|
122
|
-
const
|
|
123
|
-
return `new URL(${quote}${
|
|
132
|
+
const resolved = makeAbsolute(path);
|
|
133
|
+
return `new URL(${quote}${resolved}${quote}, self.location?.href || ${quote}${quote}).href`;
|
|
124
134
|
}
|
|
125
135
|
);
|
|
126
136
|
|
|
127
137
|
src = src.replace(
|
|
128
138
|
/new\s+URL\s*\(\s*(["'`])((?:(?:\.{1,2}\/)|\/)?ext\/[^"'`]+)\1\s*\)/g,
|
|
129
139
|
(/** @type {string} */ _match, /** @type {string} */ quote, /** @type {string} */ path) => {
|
|
130
|
-
const
|
|
131
|
-
return `new URL(${quote}${
|
|
140
|
+
const resolved = makeAbsolute(path);
|
|
141
|
+
return `new URL(${quote}${resolved}${quote}, self.location?.href)`;
|
|
132
142
|
}
|
|
133
143
|
);
|
|
134
144
|
|
|
145
|
+
// Make remaining ext/ string literals absolute (e.g. font paths passed as
|
|
146
|
+
// function arguments like addVariant("normal","normal","ext/fonts/...")).
|
|
147
|
+
// The regexes above already consumed paths inside new URL() calls and
|
|
148
|
+
// assignment-based patterns, so this only catches leftover bare strings.
|
|
149
|
+
if (base) {
|
|
150
|
+
src = src.replace(
|
|
151
|
+
/(["'`])((?:\.{1,2}\/)?ext\/[^"'`]+)\1/g,
|
|
152
|
+
(/** @type {string} */ _match, /** @type {string} */ quote, /** @type {string} */ path) => {
|
|
153
|
+
const resolved = makeAbsolute(path);
|
|
154
|
+
return `${quote}${resolved}${quote}`;
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
135
159
|
return src;
|
|
136
160
|
}
|
|
137
161
|
|
package/plugins/vite/meta.js
CHANGED
|
@@ -13,8 +13,7 @@ import { needleGreenBold, needleLog } from './logging.js';
|
|
|
13
13
|
*/
|
|
14
14
|
export function needleMeta(command, config, userSettings) {
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
const isBuild = command === 'build';
|
|
16
|
+
let isBuild = command === 'build';
|
|
18
17
|
|
|
19
18
|
async function updateConfig() {
|
|
20
19
|
config = await loadConfig();
|
|
@@ -25,6 +24,9 @@ export function needleMeta(command, config, userSettings) {
|
|
|
25
24
|
return {
|
|
26
25
|
// replace meta tags
|
|
27
26
|
name: 'needle:meta',
|
|
27
|
+
configResolved(resolvedConfig) {
|
|
28
|
+
isBuild = resolvedConfig.command === 'build';
|
|
29
|
+
},
|
|
28
30
|
transformIndexHtml: {
|
|
29
31
|
order: 'pre',
|
|
30
32
|
handler(/** @type {string} */ html, /** @type {unknown} */ _ctx) {
|
package/plugins/vite/poster.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export function getPosterPath(): string;
|
|
2
2
|
/**
|
|
3
|
-
* @param {"build" | "serve"}
|
|
3
|
+
* @param {"build" | "serve" | undefined} _command
|
|
4
4
|
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
5
5
|
* @param {import('../types').userSettings} userSettings
|
|
6
6
|
* @returns {import('vite').Plugin | undefined}
|
|
7
7
|
*/
|
|
8
|
-
export function needlePoster(
|
|
8
|
+
export function needlePoster(_command: "build" | "serve" | undefined, config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
|
package/plugins/vite/poster.js
CHANGED
|
@@ -10,19 +10,17 @@ export function getPosterPath() {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @param {"build" | "serve"}
|
|
13
|
+
* @param {"build" | "serve" | undefined} _command
|
|
14
14
|
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
15
15
|
* @param {import('../types').userSettings} userSettings
|
|
16
16
|
* @returns {import('vite').Plugin | undefined}
|
|
17
17
|
*/
|
|
18
|
-
export function needlePoster(
|
|
19
|
-
// only relevant for local development
|
|
20
|
-
if (command === 'build') return [];
|
|
21
|
-
|
|
18
|
+
export function needlePoster(_command, config, userSettings) {
|
|
22
19
|
if (userSettings.noPoster) return;
|
|
23
20
|
|
|
24
21
|
return {
|
|
25
22
|
name: 'needle:poster',
|
|
23
|
+
apply: 'serve',
|
|
26
24
|
configureServer(server) {
|
|
27
25
|
const hot = server.hot ?? server.ws;
|
|
28
26
|
hot.on('needle:screenshot', async (data, client) => {
|
package/plugins/vite/reload.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {"build" | "serve"}
|
|
2
|
+
* @param {"build" | "serve" | undefined} _command
|
|
3
3
|
* @param {import('../types/needleConfig').needleMeta | null} config
|
|
4
4
|
* @param {import('../types').userSettings} userSettings
|
|
5
5
|
* @returns {import('vite').Plugin | undefined}
|
|
6
6
|
*/
|
|
7
|
-
export function needleReload(
|
|
7
|
+
export function needleReload(_command: "build" | "serve" | undefined, config: import("../types/needleConfig").needleMeta | null, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
|