Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: refactor to avoid name collisions #152

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,25 @@
"exports": {
"./three": {
"types": "./dist/three.d.ts",
"import": "./dist/three.js"
"default": "./dist/three.js"
},
"./pmndrs": {
"types": "./dist/pmndrs.d.ts",
"import": "./dist/pmndrs.js"
"default": "./dist/pmndrs.js"
},
"./*": "./*"
},
"typesVersions": {
"*": {
"three": [
"./dist/three.d.ts"
],
"pmndrs": [
"./dist/pmndrs.d.ts"
]
}
},
"files": [
"*.d.ts",
"dist"
],
"publishConfig": {
Expand All @@ -44,7 +53,7 @@
"scripts": {
"dev": "cd playground && npm run dev",
"playground": "cd playground && npm run dev",
"build": "vite build",
"build": "vite build && node ./scripts/postbuild.mjs",
"preview": "vite preview",
"release": "release-it",
"lint": "eslint .",
Expand Down
10 changes: 10 additions & 0 deletions playground-nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ export default defineNuxtConfig({
modules: [
'@tresjs/nuxt',
],
typescript: {
tsConfig: {
compilerOptions: {
paths: {
'@tresjs/post-processing/pmndrs': ['../../src/core/pmndrs'],
'@tresjs/post-processing/three': ['../../src/core/three'],
},
},
},
},
vite: {
resolve: {
alias: {
Expand Down
2 changes: 1 addition & 1 deletion playground-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@tresjs/cientos": "^4.0.3",
"@tresjs/nuxt": "^3.0.7",
"@tresjs/post-processing": "^0.7.1",
"@tresjs/post-processing": "workspace:*",
"@types/three": "^0.169.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions playground-nuxt/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { EffectComposer, Glitch } from '@tresjs/post-processing/pmndrs'
import { EffectComposerPmndrs, GlitchPmndrs } from '@tresjs/post-processing/pmndrs'
import { BasicShadowMap, NoToneMapping, SRGBColorSpace } from 'three'

const gl = {
Expand All @@ -26,9 +26,9 @@ const gl = {
<TresGridHelper />
<TresAmbientLight :intensity="1" />
<Suspense>
<EffectComposer>
<Glitch />
</EffectComposer>
<EffectComposerPmndrs>
<GlitchPmndrs />
</EffectComposerPmndrs>
</Suspense>
</TresCanvas>
</template>
8 changes: 4 additions & 4 deletions playground/src/components/OutlineDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Intersection, Object3D } from 'three'
import { OrbitControls, useTweakPane } from '@tresjs/cientos'
import { TresCanvas } from '@tresjs/core'
import { EffectComposer, Outline } from '@tresjs/post-processing/pmndrs'
import { EffectComposerPmndrs, OutlinePmndrs } from '@tresjs/post-processing/pmndrs'
import { BasicShadowMap, NoToneMapping } from 'three'
import { reactive, ref } from 'vue'

Expand Down Expand Up @@ -61,12 +61,12 @@ pane.addInput(outlineParameters, 'visibleEdgeColor')
<TresGridHelper />
<TresAmbientLight :intensity="1" />
<Suspense>
<EffectComposer>
<Outline
<EffectComposerPmndrs>
<OutlinePmndrs
:outlined-objects="outlinedObjects"
v-bind="outlineParameters"
/>
</EffectComposer>
</EffectComposerPmndrs>
</Suspense>
</TresCanvas>
</template>
8 changes: 4 additions & 4 deletions playground/src/components/TheExperience.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { EffectComposer, Glitch } from '@tresjs/post-processing/pmndrs'
import { EffectComposerPmndrs, GlitchPmndrs } from '@tresjs/post-processing/pmndrs'
import { BasicShadowMap, NoToneMapping, SRGBColorSpace } from 'three'

const gl = {
Expand Down Expand Up @@ -30,9 +30,9 @@ const gl = {
<TresGridHelper />
<TresAmbientLight :intensity="1" />
<Suspense>
<EffectComposer>
<Glitch />
</EffectComposer>
<EffectComposerPmndrs>
<GlitchPmndrs />
</EffectComposerPmndrs>
</Suspense>
</TresCanvas>
</template>
3 changes: 2 additions & 1 deletion playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"module": "ESNext",
"moduleResolution": "bundler",
"paths": {
"@tresjs/post-processing": ["../dist/"]
"@tresjs/post-processing/pmndrs": ["../dist/pmndrs"],
"@tresjs/post-processing/three": ["../dist/three"],
},
"resolveJsonModule": true,
"strict": true,
Expand Down
50 changes: 17 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions scripts/postbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { readFile, writeFile, readdir } from 'node:fs/promises'

/**
* 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
*
* @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')
}
}
}

/**
* Adds `.js` when importing the core/xxx/index.js in the dts
*
* @param pmndrsDts {Boolean}
* @return {Promise<void>}
*/
async function patchRootDts(pmndrsDts) {
const dts = `dist/${pmndrsDts ? 'pmndrs' : 'three'}.d.ts`
const replacement = `./core/${pmndrsDts ? 'pmndrs' : 'three'}/index`
const content = await readFile(dts, 'utf8')
await writeFile(dts, content.replace(replacement, `${replacement}.js`))
}

async function fixNode16() {
await Promise.all([
patchRootDts(true),
patchRootDts(false),
patchVueDts('dist/core/pmndrs'),
patchVueDts('dist/core/three'),
])
}

fixNode16()
Loading
Loading