From cbc5c074a949f96c5382007b64fc62482a5f5938 Mon Sep 17 00:00:00 2001 From: userquin Date: Fri, 20 Dec 2024 01:58:34 +0100 Subject: [PATCH] fix: types --- package.json | 5 +-- pnpm-lock.yaml | 3 ++ scripts/postbuild.mjs | 34 +++++++++++++++++++ src/core/abstractions/AnimatedSprite/Atlas.ts | 4 +-- .../abstractions/AnimatedSprite/component.vue | 4 +-- .../abstractions/CubeCamera/component.vue | 4 +-- src/core/abstractions/Image/ImageMaterial.vue | 2 +- .../abstractions/Image/ImageMaterialImpl.ts | 2 +- src/core/abstractions/Lensflare/component.vue | 4 +-- src/core/abstractions/Lensflare/constants.ts | 2 +- src/core/abstractions/Lensflare/index.ts | 6 ++-- .../Outline/OutlineMaterialImpl.ts | 2 +- src/core/abstractions/Outline/component.vue | 2 +- src/core/abstractions/ScreenSizer.vue | 2 +- src/core/abstractions/index.ts | 12 +++---- src/core/abstractions/useFBO/component.vue | 4 +-- .../useSurfaceSampler/component.vue | 4 +-- src/core/controls/CameraControls.vue | 2 +- src/core/controls/KeyboardControls.vue | 2 +- src/core/index.ts | 14 ++++---- src/core/loaders/index.ts | 8 ++--- src/core/loaders/useFBX/component.vue | 2 +- src/core/loaders/useGLTF/component.vue | 2 +- src/core/loaders/useProgress.ts | 2 +- src/core/loaders/useVideoTexture.ts | 2 +- .../materials/holographicMaterial/index.vue | 2 +- .../materials/meshDiscardMaterial/index.vue | 2 +- .../materials/meshGlassMaterial/index.vue | 2 +- .../meshReflectionMaterial/BlurPass.ts | 2 +- .../ConvolutionMaterial.ts | 2 +- .../meshReflectionMaterial/index.vue | 4 +-- .../materials/meshWobbleMaterial/index.vue | 2 +- src/core/misc/index.ts | 8 ++--- src/core/staging/Grid.vue | 4 +-- src/core/staging/Sparkles/ShaderData.ts | 4 +-- .../staging/Sparkles/ShaderDataBuilder.ts | 4 +-- src/core/staging/Sparkles/component.vue | 8 ++--- src/core/staging/useEnvironment/component.vue | 6 ++-- src/core/staging/useEnvironment/index.ts | 4 +-- src/index.ts | 4 +-- 40 files changed, 113 insertions(+), 75 deletions(-) create mode 100644 scripts/postbuild.mjs diff --git a/package.json b/package.json index 0d335cd6e..9166818b0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/trescientos.js" + "default": "./dist/trescientos.js" }, "./core": { "types": "./dist/core/index.d.ts" @@ -47,7 +47,7 @@ "scripts": { "dev": "cd playground/vue && pnpm dev", "dev:nuxt": "cd playground/nuxt && pnpm dev", - "build": "vite build", + "build": "vite build && node ./scripts/postbuild.mjs", "release": "release-it", "lint": "eslint .", "lint:fix": "eslint . --fix", @@ -86,6 +86,7 @@ "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-visualizer": "^5.12.0", "three": "^0.171.0", + "tinyglobby": "^0.2.10", "typescript": "^5.7.2", "unocss": "^0.65.1", "vite": "^6.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8d20a8ebd..f49c80b91 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,6 +81,9 @@ importers: three: specifier: ^0.171.0 version: 0.171.0 + tinyglobby: + specifier: ^0.2.10 + version: 0.2.10 typescript: specifier: ^5.7.2 version: 5.7.2 diff --git a/scripts/postbuild.mjs b/scripts/postbuild.mjs new file mode 100644 index 000000000..43efb8a7c --- /dev/null +++ b/scripts/postbuild.mjs @@ -0,0 +1,34 @@ +import { readFile, writeFile } from 'node:fs/promises' +import { glob } from 'tinyglobby' + +/** + * Adds `.js` when importing the ./src/index.js in the dts + * + * @return {Promise} + */ +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 node16 issue: https://www.typescriptlang.org/tsconfig/#allowArbitraryExtensions + * - 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 + * + * @return {Promise} + */ +async function patchVueDts() { + const files = await glob('dist/**/*.vue.d.ts') + for (const file of files) { + // console.log(file) + await writeFile(file.replace('.vue.d.ts', '.d.vue.ts'), await readFile(file, 'utf-8'), 'utf-8') + } +} + +async function fixNode16() { + await patchVueDts() +} + +fixNode16() diff --git a/src/core/abstractions/AnimatedSprite/Atlas.ts b/src/core/abstractions/AnimatedSprite/Atlas.ts index 0cd501f6e..5a37f218e 100644 --- a/src/core/abstractions/AnimatedSprite/Atlas.ts +++ b/src/core/abstractions/AnimatedSprite/Atlas.ts @@ -1,8 +1,8 @@ import { useLoader, useLogger } from '@tresjs/core' import { type Texture, TextureLoader } from 'three' import type { LoaderProto } from '@tresjs/core' -import { expand } from './AtlasAnimationDefinitionParser' -import { getNumbersFromEnd, stripUnderscoresNumbersFromEnd } from './StringOps' +import { expand } from './AtlasAnimationDefinitionParser.js' +import { getNumbersFromEnd, stripUnderscoresNumbersFromEnd } from './StringOps.js' export async function getTextureAndAtlasAsync( imagePathOrImageData: string, diff --git a/src/core/abstractions/AnimatedSprite/component.vue b/src/core/abstractions/AnimatedSprite/component.vue index 793186154..4bb7ef64d 100644 --- a/src/core/abstractions/AnimatedSprite/component.vue +++ b/src/core/abstractions/AnimatedSprite/component.vue @@ -4,8 +4,8 @@ import { DoubleSide } from 'three' import { onUnmounted, ref, shallowRef, watch } from 'vue' import type { TresVector2 } from '@tresjs/core' import type { Texture } from 'three' -import { getAtlasFrames, getNullAtlasFrame, getTextureAndAtlasAsync, setAtlasDefinitions } from './Atlas' -import type { Atlas, Atlasish } from './Atlas' +import { getAtlasFrames, getNullAtlasFrame, getTextureAndAtlasAsync, setAtlasDefinitions } from './Atlas.js' +import type { Atlas, Atlasish } from './Atlas.js' export interface AnimatedSpriteProps { /** URL of the image texture or an image dataURL. This prop is not reactive. */ diff --git a/src/core/abstractions/CubeCamera/component.vue b/src/core/abstractions/CubeCamera/component.vue index 18d7042fb..00a4aff51 100644 --- a/src/core/abstractions/CubeCamera/component.vue +++ b/src/core/abstractions/CubeCamera/component.vue @@ -1,8 +1,8 @@