Skip to content

Commit

Permalink
fix: node16 types
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Dec 19, 2024
1 parent e16ea32 commit d245134
Show file tree
Hide file tree
Showing 32 changed files with 144 additions and 104 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"scripts": {
"dev": "cd playground/vue && npm run dev",
"dev:nuxt": "cd playground/nuxt && npm run dev",
"build": "vite build",
"build": "vite build && node ./scripts/postbuild.mjs",
"test": "vitest",
"test:ci": "vitest run",
"test:ui": "vitest --ui --coverage.enabled=true",
Expand Down
40 changes: 40 additions & 0 deletions scripts/postbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { readdir, readFile, writeFile } from 'node:fs/promises'

/**
* Adds `.js` when importing the ./src/index.js in the dts
*
* @return {Promise<void>}
*/
async function patchRootDts() {
const dts = 'dist/index.d.ts'
const content = await readFile(dts, 'utf8')
await writeFile(dts, content.replaceAll('./src/index\'', './src/index.js\''))
}

/**
* Fix node10 issue:
* - node10 and bundler will check for d.vue.ts and vue.d.ts file when importing a vue file in a dts
* - node16 will check only for d.vue.ts file, this function will just copy/paste the content of vue.d.ts to d.vue.ts
*
* @param path {String}
* @return {Promise<void>}
*/
async function patchVueDts(path) {
const files = await readdir(path, { recursive: false })
for (const file of files) {
if (file.endsWith('.vue.d.ts')) {
await writeFile(`${path}/${file.replace('.vue.d.ts', '.d.vue.ts')}`, await readFile(`${path}/${file}`, 'utf-8'), 'utf-8')
}
}
}

async function fixNode16() {
await Promise.all([
patchRootDts(),
patchVueDts('dist/src/components'),
patchVueDts('dist/src/composables/useLoader'),
patchVueDts('dist/src/composables/useTexture'),
])
}

fixNode16()
14 changes: 7 additions & 7 deletions src/components/TresCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
WebGLRendererParameters,
} from 'three'
import type { App, Ref } from 'vue'
import type { RendererPresetsType } from '../composables/useRenderer/const'
import type { TresCamera, TresObject, TresScene } from '../types/'
import type { RendererPresetsType } from '../composables/useRenderer/const.js'
import type { TresCamera, TresObject, TresScene } from '../types/index.js'
import { PerspectiveCamera, Scene } from 'three'
import * as THREE from 'three'
Expand All @@ -30,12 +30,12 @@ import {
type TresContext,
useLogger,
useTresContextProvider,
} from '../composables'
import { extend } from '../core/catalogue'
import { nodeOps } from '../core/nodeOps'
} from '../composables/index.js'
import { extend } from '../core/catalogue.js'
import { nodeOps } from '../core/nodeOps.js'
import { registerTresDevtools } from '../devtools'
import { disposeObject3D } from '../utils/'
import { registerTresDevtools } from '../devtools/index.js'
import { disposeObject3D } from '../utils/index.js'
export interface TresCanvasProps
extends Omit<WebGLRendererParameters, 'canvas'> {
Expand Down
24 changes: 12 additions & 12 deletions src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import UseLoader from './useLoader/component.vue'
import UseTexture from './useTexture/component.vue'

export * from './useCamera/'
export * from './useLoader'
export * from './useLogger'
export * from './useLoop'
export * from './useRaycaster'
export * from './useRenderer/'
export * from './useRenderLoop'
export * from './useSeek'
export * from './useTexture'
export * from './useTresContextProvider'
export * from './useTresEventManager'
export { onTresReady } from './useTresReady'
export * from './useCamera/index.js'
export * from './useLoader/index.js'
export * from './useLogger.js'
export * from './useLoop/index.js'
export * from './useRaycaster/index.js'
export * from './useRenderer/index.js'
export * from './useRenderLoop/index.js'
export * from './useSeek/index.js'
export * from './useTexture/index.js'
export * from './useTresContextProvider/index.js'
export * from './useTresEventManager/index.js'
export { onTresReady } from './useTresReady/index.js'
export { UseLoader, UseTexture }
6 changes: 3 additions & 3 deletions src/composables/useCamera/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { OrthographicCamera } from 'three'
import type { TresScene } from '../../types'
import type { TresContext } from '../useTresContextProvider'
import type { TresScene } from '../../types/index.js'
import type { TresContext } from '../useTresContextProvider/index.js'

import { Camera, PerspectiveCamera } from 'three'
import { computed, onUnmounted, ref, watchEffect } from 'vue'
import { camera as isCamera } from '../../utils/is'
import { camera as isCamera } from '../../utils/is.js'

export const useCamera = ({ sizes }: Pick<TresContext, 'sizes'> & { scene: TresScene }) => {
// the computed does not trigger, when for example the camera position changes
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useLoader/component.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { LoaderProto } from './index'
import type { LoaderProto } from './index.js'
import { reactive } from 'vue'
import { useLoader } from './index'
import { useLoader } from './index.js'
const props = defineProps<{
loader: LoaderProto<unknown>
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useLoader/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Loader, LoadingManager, Object3D } from 'three'
import type { TresObject } from '../../types'
import { useLogger } from '..'
import type { TresObject } from '../../types/index.js'
import { useLogger } from '../useLogger.js'

export interface TresLoader<T> extends Loader {
load: (
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useLoop/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LoopCallbackFn } from './../../core/loop'
import { useTresContext } from '../useTresContextProvider'
import type { LoopCallbackFn } from './../../core/loop.js'
import { useTresContext } from '../useTresContextProvider/index.js'

export function useLoop() {
const {
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useRaycaster/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { EventHook } from '@vueuse/core'
import type { DomEvent, TresCamera, TresEvent, TresInstance } from 'src/types'
import type { DomEvent, TresCamera, TresEvent, TresInstance } from 'src/types/index.js'
import type { Intersection, Object3D, Object3DEventMap } from 'three'
import type { ShallowRef } from 'vue'
import type { TresContext } from '../useTresContextProvider'
import type { TresContext } from '../useTresContextProvider/index.js'
import { createEventHook, useElementBounding, usePointer } from '@vueuse/core'

import { Vector2, Vector3 } from 'three'
Expand Down
6 changes: 3 additions & 3 deletions src/composables/useRenderer/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ColorSpace, Scene, ShadowMapType, ToneMapping, WebGLRendererParameters } from 'three'
import type { EmitEventFn, TresColor } from '../../types'
import type { EmitEventFn, TresColor } from '../../types/index.js'

import type { TresContext } from '../useTresContextProvider'
import type { TresContext } from '../useTresContextProvider/index.js'

import type { RendererPresetsType } from './const'
import type { RendererPresetsType } from './const.js'
import {
type MaybeRefOrGetter,
toValue,
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useSeek/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Object3D, Scene } from 'three'
import { useLogger } from '../useLogger'
import { useLogger } from '../useLogger.js'

/**
* Seek composable return type
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useTexture/component.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { PBRUseTextureMap } from './index'
import type { PBRUseTextureMap } from './index.js'
import { reactive } from 'vue'
import { useTexture } from './index'
import { useTexture } from './index.js'
const props = defineProps<PBRUseTextureMap>()
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useTexture/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LoadingManager, Texture } from 'three'
import { TextureLoader } from 'three'
import { isArray } from '../../utils'
import { isArray } from '../../utils/index.js'

export interface PBRMaterialOptions {
/**
Expand Down
24 changes: 12 additions & 12 deletions src/composables/useTresContextProvider/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { Camera, WebGLRenderer } from 'three'
import type { ComputedRef, DeepReadonly, MaybeRef, MaybeRefOrGetter, Ref, ShallowRef } from 'vue'
import type { RendererLoop } from '../../core/loop'
import type { EmitEventFn, TresControl, TresObject, TresScene } from '../../types'
import type { UseRendererOptions } from '../useRenderer'
import type { RendererLoop } from '../../core/loop.js'
import type { EmitEventFn, TresControl, TresObject, TresScene } from '../../types/index.js'
import type { UseRendererOptions } from '../useRenderer/index.js'
import { useFps, useMemory, useRafFn } from '@vueuse/core'
import { Raycaster } from 'three'
import { computed, inject, onUnmounted, provide, readonly, ref, shallowRef } from 'vue'
import { extend } from '../../core/catalogue'
import { createRenderLoop } from '../../core/loop'
import { calculateMemoryUsage } from '../../utils/perf'

import { useCamera } from '../useCamera'
import { useRenderer } from '../useRenderer'
import useSizes, { type SizesType } from '../useSizes'
import { type TresEventManager, useTresEventManager } from '../useTresEventManager'
import { useTresReady } from '../useTresReady'
import { extend } from '../../core/catalogue.js'
import { createRenderLoop } from '../../core/loop.js'
import { calculateMemoryUsage } from '../../utils/perf.js'

import { useCamera } from '../useCamera/index.js'
import { useRenderer } from '../useRenderer/index.js'
import useSizes, { type SizesType } from '../useSizes/index.js'
import { type TresEventManager, useTresEventManager } from '../useTresEventManager/index.js'
import { useTresReady } from '../useTresReady/index.js'

export interface InternalState {
priority: Ref<number>
Expand Down
10 changes: 5 additions & 5 deletions src/composables/useTresEventManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { EmitEventFn, EmitEventName, Intersection, TresEvent, TresInstance, TresObject } from 'src/types'
import type { EmitEventFn, EmitEventName, Intersection, TresEvent, TresInstance, TresObject } from '../../types/index.js'
import type { Object3D, Object3DEventMap, Scene } from 'three'
import type { TresContext } from '../useTresContextProvider'
import type { TresContext } from '../useTresContextProvider/index.js'
import { shallowRef } from 'vue'
import { hyphenate } from '../../utils'
import * as is from '../../utils/is'
import { useRaycaster } from '../useRaycaster'
import { hyphenate } from '../../utils/index.js'
import * as is from '../../utils/is.js'
import { useRaycaster } from '../useRaycaster/index.js'

export interface TresEventManager {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createReadyEventHook } from './index'
import { createReadyEventHook } from './index.js'

describe('createReadyEventHook', () => {
beforeEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/composables/useTresReady/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TresContext } from '../useTresContextProvider'
import { useTresContext } from '../useTresContextProvider'
import { createReadyEventHook } from './createReadyEventHook'
import type { TresContext } from '../useTresContextProvider/index.js'
import { useTresContext } from '../useTresContextProvider/index.js'
import { createReadyEventHook } from './createReadyEventHook/index.js'

const ctxToUseTresReady = new WeakMap<
TresContext,
Expand Down
2 changes: 1 addition & 1 deletion src/core/catalogue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Ref } from 'vue'
import type { TresCatalogue } from '../types'
import type { TresCatalogue } from '../types/index.js'
import { ref } from 'vue'

export const catalogue: Ref<TresCatalogue> = ref({})
Expand Down
4 changes: 2 additions & 2 deletions src/core/loop.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Fn } from '@vueuse/core'
import type { Camera, EventDispatcher, Raycaster, Scene, WebGLRenderer } from 'three'
import type { Ref } from 'vue'
import type { Callback } from '../utils/createPriorityEventHook'
import type { Callback } from '../utils/createPriorityEventHook.js'
import { Clock, MathUtils } from 'three'
import { ref, unref } from 'vue'
import { createPriorityEventHook } from '../utils/createPriorityEventHook'
import { createPriorityEventHook } from '../utils/createPriorityEventHook.js'

export type LoopStage = 'before' | 'render' | 'after'

Expand Down
14 changes: 7 additions & 7 deletions src/core/nodeOps.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { TresContext } from '../composables'
import type { DisposeType, LocalState, TresInstance, TresObject, TresObject3D, TresPrimitive, WithMathProps } from '../types'
import type { TresContext } from '../composables/index.js'
import type { DisposeType, LocalState, TresInstance, TresObject, TresObject3D, TresPrimitive, WithMathProps } from '../types/index.js'
import { BufferAttribute, Object3D } from 'three'
import { isRef, type RendererOptions } from 'vue'
import { useLogger } from '../composables'
import { attach, deepArrayEqual, doRemoveDeregister, doRemoveDetach, invalidateInstance, isHTMLTag, kebabToCamel, noop, prepareTresInstance, setPrimitiveObject, unboxTresPrimitive } from '../utils'
import * as is from '../utils/is'
import { createRetargetingProxy } from '../utils/primitive/createRetargetingProxy'
import { catalogue } from './catalogue'
import { useLogger } from '../composables/useLogger.js'
import { attach, deepArrayEqual, doRemoveDeregister, doRemoveDetach, invalidateInstance, isHTMLTag, kebabToCamel, noop, prepareTresInstance, setPrimitiveObject, unboxTresPrimitive } from '../utils/index.js'
import * as is from '../utils/is.js'
import { createRetargetingProxy } from '../utils/primitive/createRetargetingProxy.js'
import { catalogue } from './catalogue.js'

const { logError } = useLogger()

Expand Down
2 changes: 1 addition & 1 deletion src/devtools/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { registerTresDevtools } from './plugin'
export { registerTresDevtools } from './plugin.js'
12 changes: 6 additions & 6 deletions src/devtools/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type {
App as DevtoolsApp,
} from '@vue/devtools-api'
import type { TresContext } from '../composables'
import type { TresObject } from './../types'
import type { TresContext } from '../composables/index.js'
import type { TresObject } from '../types/index.js'
import {
setupDevtoolsPlugin,
} from '@vue/devtools-api'
import { Color, type Mesh } from 'three'
import { reactive } from 'vue'
import { createHighlightMesh, editSceneObject } from '../utils'
import * as is from '../utils/is'
import { bytesToKB, calculateMemoryUsage } from '../utils/perf'
import { toastMessage } from './utils'
import { createHighlightMesh, editSceneObject } from '../utils/index.js'
import * as is from '../utils/is.js'
import { bytesToKB, calculateMemoryUsage } from '../utils/perf.js'
import { toastMessage } from './utils.js'

export interface Tags {
label: string
Expand Down
6 changes: 3 additions & 3 deletions src/directives/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vDistanceTo } from './vDistanceTo'
import { vLightHelper } from './vLightHelper'
import { vLog } from './vLog'
import { vDistanceTo } from './vDistanceTo.js'
import { vLightHelper } from './vLightHelper.js'
import { vLog } from './vLog.js'

export { vDistanceTo, vLightHelper, vLog }
6 changes: 3 additions & 3 deletions src/directives/vDistanceTo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Ref } from 'vue'
import type { TresObject } from '../types'
import type { TresObject } from '../types/index.js'
import { ArrowHelper } from 'three'
import { useLogger } from '../composables'
import { extractBindingPosition } from '../utils'
import { useLogger } from '../composables/index.js'
import { extractBindingPosition } from '../utils/index.js'

const { logWarning } = useLogger()

Expand Down
4 changes: 2 additions & 2 deletions src/directives/vLightHelper.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type {
Light,
} from 'three'
import type { TresObject } from '../types'
import type { TresObject } from '../types/index.js'
import {
DirectionalLightHelper,
HemisphereLightHelper,
PointLightHelper,
SpotLightHelper,
} from 'three'
import { RectAreaLightHelper } from 'three-stdlib'
import { useLogger } from '../composables'
import { useLogger } from '../composables/index.js'

const { logWarning } = useLogger()

Expand Down
2 changes: 1 addition & 1 deletion src/directives/vLog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TresObject } from '../types'
import type { TresObject } from '../types/index.js'

export const vLog = {
mounted: (el: TresObject, binding: { arg: string }) => {
Expand Down
Loading

0 comments on commit d245134

Please sign in to comment.