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 @@