Skip to content

Commit 6c77878

Browse files
authored
fix: load relative subpath (#189)
* Build separate package/bundle for dynamic import * formatting issues * Update to node 22 for default build and node 18/20 for test * Put scripts last so it is easy to cat the file and run scripts * fix: Basic deploy working with slim and CS3D * fix: Load path * Try to fix build/test * fix: Webworker load and icc transform * Revert viewer test * Revert version updates * Downgrade minimatch for compatibility * fix: Add a better relative path directory
1 parent ca5696b commit 6c77878

File tree

16 files changed

+8135
-7986
lines changed

16 files changed

+8135
-7986
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v4
1111
- uses: actions/setup-node@v4
1212
with:
13-
node-version: "20.x"
13+
node-version: "22.x"
1414
registry-url: "https://registry.npmjs.org"
1515
- run: yarn install --frozen-lockfile
1616
- run: npm publish --access public

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ jobs:
1010
build:
1111
name: Build and run tests
1212
runs-on: ubuntu-latest
13+
1314
strategy:
1415
matrix:
15-
node-version: ["16.x", "20.x"]
16+
node-version: ["18.x", "24.x"]
1617

1718
steps:
1819
- uses: actions/checkout@v2

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ dist/
6969
.env.local
7070
.env.development.local
7171
.env.test.local
72-
.env.production.local
72+
.env.production.local
73+
*~
74+
*.swp
75+
bun.lock
76+
*workspace

babel.config.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
module.exports = {
22
presets: [
3-
['@babel/preset-env', {
4-
targets: {
5-
browsers: ['ie 11']
6-
}
7-
}]
3+
[
4+
"@babel/preset-env",
5+
{
6+
targets: {
7+
browsers: ["ie 11"],
8+
},
9+
},
10+
],
811
],
912
plugins: [
10-
['@babel/plugin-transform-runtime',
13+
"babel-plugin-transform-import-meta",
14+
[
15+
"@babel/plugin-transform-runtime",
1116
{
1217
regenerator: true,
13-
corejs: 3
14-
}
15-
]
16-
]
17-
}
18+
corejs: 3,
19+
},
20+
],
21+
],
22+
};

config/webpack/webpack-base.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,50 @@ module.exports = {
88
mode: 'development',
99
context,
1010
stats: {
11-
children: true
11+
children: true,
1212
},
1313
entry: {
14-
dicomMicroscopyViewer: './dicom-microscopy-viewer.js'
14+
dicomMicroscopyViewer: './dicom-microscopy-viewer.js',
15+
'dataLoader.worker': './webWorker/dataLoader.worker.js',
1516
},
1617
target: 'web',
1718
output: {
1819
library: {
1920
name: '[name]',
2021
type: 'umd',
21-
umdNamedDefine: true
22+
umdNamedDefine: true,
2223
},
2324
globalObject: 'this',
2425
path: outputPath,
25-
publicPath: 'auto'
26+
publicPath: 'auto',
2627
},
2728
devtool: 'source-map',
2829
resolve: {
2930
fallback: {
3031
fs: false,
31-
path: false
32-
}
32+
path: false,
33+
url: false,
34+
},
3335
},
3436
module: {
3537
noParse: [/(codec)/, /(dicomicc)/],
3638
rules: [
3739
{
3840
test: /\.css$/,
39-
use: 'css-loader'
41+
use: 'css-loader',
4042
},
4143
{
4244
test: /\.wasm/,
43-
type: 'asset/resource'
44-
},
45-
{
46-
test: /\.worker\.js$/,
47-
use: [
48-
{
49-
loader: 'worker-loader'
50-
}
51-
]
45+
type: 'asset/resource',
5246
},
5347
{
5448
test: /\.js$/,
5549
exclude: [/(node_modules)/, /(codecs)/, /(dicomicc)/],
5650
use: {
57-
loader: 'babel-loader'
58-
}
59-
}
60-
]
51+
loader: 'babel-loader',
52+
},
53+
},
54+
],
6155
},
62-
plugins: [new webpack.ProgressPlugin()]
63-
}
56+
plugins: [new webpack.ProgressPlugin()],
57+
};

config/webpack/webpack-bundle.js

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,70 +11,61 @@ module.exports = {
1111
mode: 'production',
1212
context,
1313
stats: {
14-
children: true
14+
children: true,
1515
},
1616
entry: {
17-
dicomMicroscopyViewer: './dicom-microscopy-viewer.js'
17+
dicomMicroscopyViewer: './dicom-microscopy-viewer.js',
18+
'dataLoader.worker': './webWorker/dataLoader.worker.js',
1819
},
1920
target: 'web',
2021
output: {
2122
library: {
2223
name: 'dicomMicroscopyViewer',
2324
type: 'umd',
24-
umdNamedDefine: true
25+
umdNamedDefine: true,
2526
},
2627
globalObject: 'this',
2728
path: outputPath,
28-
filename: '[name].bundle.min.js'
29+
publicPath: 'auto',
30+
filename: '[name].bundle.min.js',
2931
},
3032
devtool: 'source-map',
3133
resolve: {
3234
fallback: {
3335
fs: false,
34-
path: false
35-
}
36+
path: false,
37+
url: false,
38+
},
3639
},
3740
module: {
3841
noParse: [/(codec)/, /(dicomicc)/],
3942
rules: [
4043
{
4144
test: /\.css$/,
42-
use: 'css-loader'
45+
use: 'css-loader',
4346
},
4447
{
4548
test: /\.wasm/,
46-
type: 'asset/inline'
47-
},
48-
{
49-
test: /\.worker\.js$/,
50-
use: [
51-
{
52-
loader: 'worker-loader',
53-
options: { inline: 'fallback' }
54-
},
55-
{
56-
loader: 'babel-loader'
57-
}
58-
]
49+
type: 'asset/inline',
5950
},
6051
{
6152
test: /\.js$/,
6253
exclude: [/(node_modules)/, /(codecs)/, /(dicomicc)/],
6354
use: {
64-
loader: 'babel-loader'
65-
}
66-
}
67-
]
55+
loader: 'babel-loader',
56+
},
57+
},
58+
],
6859
},
6960
plugins: [new webpack.ProgressPlugin()],
7061
experiments: {
71-
asyncWebAssembly: true
62+
asyncWebAssembly: true,
7263
},
7364
optimization: {
7465
minimizer: [
7566
new TerserPlugin({
76-
parallel: true
77-
})
78-
]
79-
}
80-
}
67+
parallel: true,
68+
}),
69+
],
70+
},
71+
};

config/webpack/webpack-dynamic-import.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,37 @@ const wasmRule = {
1010
test: /\.wasm/,
1111
type: 'asset/resource',
1212
generator: {
13-
filename: 'dicom-microscopy-viewer/[name][ext]'
14-
}
15-
}
13+
filename: '[name][ext]',
14+
},
15+
};
1616

1717
const prodConfig = {
1818
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
1919
stats: {
20-
children: true
20+
children: true,
2121
},
2222
output: {
2323
path: outputPath,
2424
libraryTarget: 'umd',
25-
globalObject: 'window',
25+
globalObject: 'self',
2626
filename: '[name].min.js',
27+
publicPath: 'auto',
28+
chunkFilename: '[name].worker.min.js'
2729
},
2830
module: {
29-
rules: [wasmRule]
31+
rules: [wasmRule],
3032
},
3133
optimization: {
3234
minimize: process.env.NODE_ENV === 'production',
3335
minimizer: [
3436
new TerserPlugin({
35-
parallel: true
36-
})
37-
]
38-
}
39-
}
37+
parallel: true,
38+
}),
39+
],
40+
},
41+
experiments: {
42+
asyncWebAssembly: true,
43+
},
44+
};
4045

4146
module.exports = merge(baseConfig, prodConfig)

jest.config.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
module.exports = {
22
verbose: true,
3-
testEnvironment: 'jsdom',
4-
roots: [
5-
'<rootDir>',
6-
'<rootDir>/src'
7-
],
8-
moduleDirectories: [
9-
'node_modules'
10-
],
11-
moduleFileExtensions: ['js', 'wasm', 'json'],
3+
testEnvironment: "jsdom",
4+
roots: ["<rootDir>", "<rootDir>/src"],
5+
moduleDirectories: ["node_modules"],
6+
moduleFileExtensions: ["js", "wasm", "json"],
7+
128
transform: {
13-
'^.+wasm.*\\.js$': '<rootDir>/src/__mocks__/emscriptenMock.js',
14-
'^.+\\.js$': 'babel-jest',
15-
'\\.(css|less|sass|scss)$': '<rootDir>/src/__mocks__/styleMock.js',
16-
'\\.(wasm)$': '<rootDir>/src/__mocks__/wasmMock.js'
9+
"^.+wasm.*\\.js$": "<rootDir>/src/__mocks__/emscriptenMock.js",
10+
"^.+\\.js$": "babel-jest",
11+
"\\.(css|less|sass|scss)$": "<rootDir>/src/__mocks__/styleMock.js",
12+
"\\.(wasm)$": "<rootDir>/src/__mocks__/wasmMock.js",
1713
},
1814
transformIgnorePatterns: [
19-
'node_modules/(?!(ol|@cornerstonejs|dicomicc|rbush|color-rgba|color-parse|color-name|color-space|quickselect|earcut)/)' // <- transform libraries
20-
],
21-
testMatch: [
22-
'<rootDir>/src/**/*.test.js'
23-
],
24-
testPathIgnorePatterns: [
25-
'<rootDir>/node_modules'
15+
"node_modules/(?!(ol|@cornerstonejs|dicomicc|rbush|color-rgba|color-parse|color-name|color-space|quickselect|earcut)/)", // <- transform libraries
2616
],
27-
setupFiles: ['jest-canvas-mock'],
17+
testMatch: ["<rootDir>/src/**/*.test.js"],
18+
testPathIgnorePatterns: ["<rootDir>/node_modules"],
19+
setupFiles: ["jest-canvas-mock"],
2820
moduleNameMapper: {
29-
'@cornerstonejs/codec-libjpeg-turbo-8bit/decodewasmjs': '@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode',
30-
'@cornerstonejs/codec-libjpeg-turbo-8bit/decodewasm': '@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode.wasm',
31-
'@cornerstonejs/codec-charls/decodewasmjs': '@cornerstonejs/codec-charls/dist/charlswasm_decode.js',
32-
'@cornerstonejs/codec-charls/decodewasm': '@cornerstonejs/codec-charls/dist/charlswasm_decode.wasm',
33-
'@cornerstonejs/codec-openjpeg/decodewasmjs': '@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode.js',
34-
'@cornerstonejs/codec-openjpeg/decodewasm': '@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode.wasm',
21+
"@cornerstonejs/codec-libjpeg-turbo-8bit/decodewasmjs":
22+
"@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode",
23+
"@cornerstonejs/codec-libjpeg-turbo-8bit/decodewasm":
24+
"@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode.wasm",
25+
"@cornerstonejs/codec-charls/decodewasmjs":
26+
"@cornerstonejs/codec-charls/dist/charlswasm_decode.js",
27+
"@cornerstonejs/codec-charls/decodewasm":
28+
"@cornerstonejs/codec-charls/dist/charlswasm_decode.wasm",
29+
"@cornerstonejs/codec-openjpeg/decodewasmjs":
30+
"@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode.js",
31+
"@cornerstonejs/codec-openjpeg/decodewasm":
32+
"@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode.wasm",
3533
},
36-
}
34+
};

0 commit comments

Comments
 (0)