11/// <reference types="vitest" />
22import * as path from 'node:path' ;
3+ import * as fs from 'node:fs' ;
34import { createRequire } from 'node:module' ;
45import { Plugin , defineConfig , normalizePath } from 'vite' ;
56import vue from '@vitejs/plugin-vue' ;
@@ -10,35 +11,8 @@ import { visualizer } from 'rollup-plugin-visualizer';
1011import { sentryVitePlugin } from '@sentry/vite-plugin' ;
1112import replace from '@rollup/plugin-replace' ;
1213
13- import pkgLock from './package-lock.json' ;
1414import { config } from './wdio.shared.conf' ;
1515
16- function getPackageInfo ( lockInfo : typeof pkgLock ) {
17- if ( lockInfo . lockfileVersion === 2 ) {
18- return {
19- versions : {
20- volview : lockInfo . version ,
21- 'vtk.js' : lockInfo . dependencies [ '@kitware/vtk.js' ] . version ,
22- 'itk-wasm' : lockInfo . dependencies [ 'itk-wasm' ] . version ,
23- } ,
24- } ;
25- }
26-
27- if ( lockInfo . lockfileVersion === 3 ) {
28- return {
29- versions : {
30- volview : lockInfo . version ,
31- 'vtk.js' : lockInfo . packages [ 'node_modules/@kitware/vtk.js' ] . version ,
32- 'itk-wasm' : lockInfo . packages [ 'node_modules/itk-wasm' ] . version ,
33- } ,
34- } ;
35- }
36-
37- throw new Error (
38- 'VolView build: your package-lock.json version is not 2 or 3. Cannot extract dependency versions.'
39- ) ;
40- }
41-
4216function resolveNodeModulePath ( moduleName : string ) {
4317 const require = createRequire ( import . meta. url ) ;
4418 let modulePath = normalizePath ( require . resolve ( moduleName ) ) ;
@@ -55,13 +29,32 @@ function resolvePath(...args: string[]) {
5529 return normalizePath ( path . resolve ( ...args ) ) ;
5630}
5731
32+ function getPackageInfo ( ) {
33+ const mainPkgPath = path . resolve ( __dirname , 'package.json' ) ;
34+ const mainPkg = JSON . parse ( fs . readFileSync ( mainPkgPath , 'utf-8' ) ) ;
35+
36+ const vtkJsPath = path . join ( resolveNodeModulePath ( '@kitware/vtk.js' ) , 'package.json' ) ;
37+ const vtkJsPkg = JSON . parse ( fs . readFileSync ( vtkJsPath , 'utf-8' ) ) ;
38+
39+ const itkWasmPath = path . join ( resolveNodeModulePath ( 'itk-wasm' ) , 'package.json' ) ;
40+ const itkWasmPkg = JSON . parse ( fs . readFileSync ( itkWasmPath , 'utf-8' ) ) ;
41+
42+ return {
43+ versions : {
44+ volview : mainPkg . version ,
45+ 'vtk.js' : vtkJsPkg . version ,
46+ 'itk-wasm' : itkWasmPkg . version ,
47+ } ,
48+ } ;
49+ }
50+
5851const rootDir = resolvePath ( __dirname ) ;
5952const distDir = resolvePath ( rootDir , 'dist' ) ;
6053
6154const { ANALYZE_BUNDLE , SENTRY_AUTH_TOKEN , SENTRY_ORG , SENTRY_PROJECT } =
6255 process . env ;
6356
64- const pkgInfo = getPackageInfo ( pkgLock ) ;
57+ const pkgInfo = getPackageInfo ( ) ;
6558
6659function configureSentryPlugin ( ) {
6760 return SENTRY_AUTH_TOKEN && SENTRY_ORG && SENTRY_PROJECT
0 commit comments