Skip to content

Commit

Permalink
Merge pull request #69 from protibimbok/__dirname_fix
Browse files Browse the repository at this point in the history
Probable `__dirname` fix
  • Loading branch information
protibimbok authored Sep 27, 2024
2 parents acc77a3 + 8748d1f commit 39cbb50
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 232 deletions.
3 changes: 2 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/**/django_vite_plugin
/**/django_vite_plugin
/**/.vite
5 changes: 3 additions & 2 deletions example/custom_build/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "django-vite-plugin-custom-build-demo",
"private": true,
"version": "0.0.0",
"type": "module",
"type": "commonjs",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
Expand All @@ -12,5 +12,6 @@
"typescript": "^5.2.2",
"vite": "^5.2.0",
"django-vite-plugin": "file:../../../vite"
}
},
"packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"
}
46 changes: 23 additions & 23 deletions example/output/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"compilerOptions": {
"paths": {
"@/*": [
"./*"
],
"@s:home/*": [
"./home/static/home/*"
],
"@t:home/*": [
"./home/templates/home/*"
],
"@s:another_app/*": [
"./another_app/static/another_app/*"
],
"@t:another_app/*": [
"./another_app/templates/another_app/*"
]
}
},
"exclude": [
"node_modules"
]
{
"compilerOptions": {
"paths": {
"@/*": [
"./*"
],
"@s:home/*": [
"./home/static/home/*"
],
"@t:home/*": [
"./home/templates/home/*"
],
"@s:another_app/*": [
"./another_app/static/another_app/*"
],
"@t:another_app/*": [
"./another_app/templates/another_app/*"
]
}
},
"exclude": [
"node_modules"
]
}
47 changes: 24 additions & 23 deletions example/output/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"private": true,
"version": "0.0.1",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"type": "module",
"devDependencies": {
"@vitejs/plugin-vue": "^4.5.0",
"autoprefixer": "^10.4.16",
"glob": "^9.3.5",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"vite": "^5.0.2",
"vite-plugin-inspect": "^0.7.42",
"django-vite-plugin": "file:../../vite"
},
"dependencies": {
"sweetalert2": "^11.10.1",
"vue": "^3.3.9"
}
}
{
"private": true,
"version": "0.0.1",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"type": "module",
"devDependencies": {
"@vitejs/plugin-vue": "^4.5.0",
"autoprefixer": "^10.4.16",
"glob": "^9.3.5",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"vite": "^5.0.2",
"vite-plugin-inspect": "^0.7.42",
"django-vite-plugin": "file:../../vite"
},
"dependencies": {
"sweetalert2": "^11.10.1",
"vue": "^3.3.9"
},
"packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"
}
2 changes: 1 addition & 1 deletion vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "django-vite-plugin",
"version": "4.0.2",
"version": "4.0.3",
"description": "Django plugin for Vite.",
"type": "module",
"keywords": [
Expand Down
9 changes: 8 additions & 1 deletion vite/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import type {
} from './config.js'
import { AddressInfo } from 'net'

const BASE_DIR: string = path.dirname(
typeof __dirname === 'undefined'
? // @ts-ignore
path.dirname(new URL(import.meta.url).pathname)
: __dirname,
)

export function execPythonNoErr(
args: string[],
config: PluginConfig,
Expand Down Expand Up @@ -58,7 +65,7 @@ export async function execPythonJSON(
export function pluginVersion(): string {
try {
return JSON.parse(
fs.readFileSync(path.join(__dirname, '../package.json')).toString(),
fs.readFileSync(path.join(BASE_DIR, '/package.json')).toString(),
)?.version
} catch {
return ''
Expand Down
Loading

0 comments on commit 39cbb50

Please sign in to comment.