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

Update karma.conf.js #348

Closed
wants to merge 18 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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"rules": {
"tsdoc/syntax": "warn",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-function": "off",
"no-console": [
"warn",
{
Expand Down
10 changes: 5 additions & 5 deletions .webpack/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ module.exports = (env, argv, { DIST_DIR }) => {
resolve: {
modules: [path.resolve(PROJECT_ROOT, './node_modules'), SRC_PATH],
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias: {
'cornerstone-wado-image-loader':
'cornerstone-wado-image-loader/dist/dynamic-import/cornerstoneWADOImageLoader.min.js',
},
// alias: {
// '@cornerstonejs/dicom-image-loader':
// '@cornerstonejs/dicom-image-loader/dist/dynamic-import/cornerstoneWADOImageLoader.min.js',
// },
fallback: {
fs: false,
path: require.resolve('path-browserify'),
Expand All @@ -70,7 +70,7 @@ module.exports = (env, argv, { DIST_DIR }) => {
// Show build progress
new webpack.ProgressPlugin(),
// Clear dist between builds
new CleanWebpackPlugin()
new CleanWebpackPlugin(),
],
};

Expand Down
3 changes: 2 additions & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"bundledPackages": [
"@cornerstonejs/core",
"@cornerstonejs/tools",
"@cornerstonejs/streaming-image-volume-loader"
"@cornerstonejs/streaming-image-volume-loader",
"@cornerstonejs/dicom-image-loader"
],

/**
Expand Down
2 changes: 1 addition & 1 deletion common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2356,4 +2356,4 @@ function worldToImageCoords(imageId: string, worldCoords: Point3): Point2 | unde

// (No @packageDocumentation comment for this package)

```
```
109 changes: 105 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
// @ts-check
const { tmpdir } = require('os');
const { join } = require('path');
const path = require('path');

process.env.CHROME_BIN = require('puppeteer').executablePath();

/**
* Required for packages/dicom-image-loader Manually set a temporary output
* directory for webpack so that Karma can serve all the required files for
* dicom-image-loader, such as wasm files and web-workers. See
* https://github.com/ryanclark/karma-webpack/issues/498
*/
const output = {
path: join(tmpdir(), '_karma_webpack_') + Math.floor(Math.random() * 1000000),
};

/**
*
* @param { import("karma").Config } config - karma config
*/
module.exports = function (config) {
config.set({
reporters: ['junit', 'coverage', 'spec'],
Expand Down Expand Up @@ -45,12 +62,12 @@ module.exports = function (config) {
frameworks: ['jasmine', 'webpack'],
customHeaders: [
{
match: '.*.html',
match: '.*html|js|wasm$',
name: 'Cross-Origin-Opener-Policy',
value: 'same-origin',
},
{
match: '.*.html',
match: '.*html|js|wasm$',
name: 'Cross-Origin-Embedder-Policy',
value: 'require-corp',
},
Expand All @@ -59,11 +76,41 @@ module.exports = function (config) {
'packages/streaming-image-volume-loader/test/**/*_test.js',
'packages/core/test/**/*_test.js',
'packages/tools/test/**/*_test.js',
'packages/dicom-image-loader/test/**/*_test.ts',
/**
* Required for packages/dicom-image-loader
* Serve all the webpack files from the output path so that karma can load
* wasm and web workers required for dicom-image-loader
*/
{
pattern: `${output.path}/**/*`,
watched: false,
included: false,
},
/**
* Required for packages/dicom-image-loader
* Serve all the testImages for the dicom-image-loader tests
*/
{
pattern: 'packages/dicom-image-loader/testImages/*.dcm',
watched: false,
included: false,
served: true,
nocache: false,
},
],
/**
* Required for packages/dicom-image-loader configure /testImages path as a
* proxy for all the dicom-image-loader test images
*/
proxies: {
'/testImages/': '/base/packages/dicom-image-loader/testImages',
},
preprocessors: {
'packages/streaming-image-volume-loader/test/**/*_test.js': ['webpack'],
'packages/core/test/**/*_test.js': ['webpack'],
'packages/tools/test/**/*_test.js': ['webpack'],
'packages/dicom-image-loader/test/**/*_test.js': ['webpack'],
},
coverageIstanbulReporter: {
reports: ['html', 'text-summary', 'lcovonly'],
Expand All @@ -80,11 +127,25 @@ module.exports = function (config) {
webpack: {
devtool: 'eval-source-map',
mode: 'development',
/**
* Required for dicom-image-loader
*
* The webpack output directory is manually specified so that all
* generated assets, such as wasm, workers etc.. can be found when running
* in Karma
*/
output,
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
/**
* exclude codecs for dicom-image-loader so that
* packages/dicom-image-loader/codecs/* are not processed and
* imported as is. See
* packages/dicom-image-loader/.webpack/webpack-base.js
*/
exclude: /(node_modules)|(codecs)/,
use: ['babel-loader'],
},
{
Expand All @@ -95,9 +156,46 @@ module.exports = function (config) {
},
],
},
/**
* Start webpack rules for packages/dicom-image-loader
* see packages/dicom-image-loader/.webpack/webpack-base.js
*/
{
test: /\.wasm/,
type: 'asset/resource',
},
{
test: /\.worker\.(mjs|js|ts)$/,
use: [
{
loader: 'worker-loader',
},
],
},
{
test: path.join(
path.resolve(__dirname, 'packages/dicom-image-loader'),
'codecs',
'jpeg.js'
),
loader: 'exports-loader',
options: {
type: 'commonjs',
exports: 'JpegImage',
},
},
/**
* End webpack rules for packages/dicom-image-loader
*/
{
test: /\.ts$/,
exclude: [path.resolve(__dirname, 'test')],
exclude: [
path.resolve(__dirname, 'test'),
/**
* Exclude dicom-image-loader due to a parsing error that I
* suspect is related to wasm modules
*/ path.resolve(__dirname, 'packages/dicom-image-loader'),
],
enforce: 'post',
use: {
loader: 'istanbul-instrumenter-loader',
Expand All @@ -118,6 +216,9 @@ module.exports = function (config) {
'@cornerstonejs/streaming-image-volume-loader': path.resolve(
'packages/streaming-image-volume-loader/src/index'
),
'@cornerstonejs/dicom-image-loader': path.resolve(
'packages/dicom-image-loader/src/imageLoader/index'
),
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"packages": [
"packages/core",
"packages/tools",
"packages/streaming-image-volume-loader"
"packages/streaming-image-volume-loader",
"packages/dicom-image-loader"
],
"npmClient": "yarn",
"useWorkspaces": true,
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"@cornerstonejs/calculate-suv": "1.0.2",
"@microsoft/api-extractor": "7.19.5",
"@types/node": "^14.18.9",
"@types/jasmine": "^4.3.1",
"@types/karma": "^6.3.3",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
"@typescript-eslint/eslint-plugin": "^4.33.0",
Expand All @@ -62,11 +64,13 @@
"cssnano": "^4.1.11",
"eslint": "7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "6.x",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-tsdoc": "^0.2.14",
"eslint-webpack-plugin": "^2.6.0",
"exports-loader": "^3.0.0",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"husky": "^4.3.8",
Expand Down
30 changes: 29 additions & 1 deletion packages/core/.webpack/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
const { merge } = require('webpack-merge');
const path = require('path');
const webpackCommon = require('./../../../.webpack/webpack.common.js');
const SRC_DIR = path.join(__dirname, '../src');
const DIST_DIR = path.join(__dirname, '../dist');

module.exports = (env, argv) => {
return webpackCommon(env, argv, { SRC_DIR, DIST_DIR });
const commonConfig = webpackCommon(env, argv, { SRC_DIR, DIST_DIR });

return merge(commonConfig, {
devtool: 'source-map',
entry: {
lib: path.join(__dirname, '../src/index.ts'),
},
output: {
path: path.join(__dirname, '../dist/umd'),
library: 'cornerstone3D',
libraryTarget: 'umd',
filename: 'index.js',
},
stats: {
colors: true,
hash: true,
timings: true,
assets: true,
chunks: false,
chunkModules: false,
modules: false,
children: false,
warnings: true,
},
optimization: {
minimize: false,
},
});
};
2 changes: 1 addition & 1 deletion packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,4 +929,4 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline

## 0.1.1 (2022-03-24)

**Note:** Version bump only for package @cornerstonejs/core
**Note:** Version bump only for package @cornerstonejs/core
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cornerstonejs/core",
"version": "0.23.0",
"version": "0.22.3",
"description": "",
"main": "dist/umd/index.js",
"types": "dist/esm/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,5 +762,6 @@ class Cache implements ICache {
*
*/
const cache = new Cache();
window.cache = cache;
export default cache;
export { Cache }; // for documentation
2 changes: 1 addition & 1 deletion packages/core/src/enums/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ enum Events {
IMAGE_SPACING_CALIBRATED = 'CORNERSTONE_IMAGE_SPACING_CALIBRATED',
/**
* Triggers on the eventTarget when there is a progress in the image load process. Note: this event
* is being used in the Cornerstone-WADO-Image-Loader repository. See {@link https://github.com/cornerstonejs/cornerstoneWADOImageLoader/blob/master/src/imageLoader/internal/xhrRequest.js | here}
* is being used in the dicom-image-loader repository. See {@link https://github.com/cornerstonejs/cornerstoneWADOImageLoader/blob/master/src/imageLoader/internal/xhrRequest.js | here}
*
* Make use of {@link EventTypes.ImageLoadProgress | ImageLoadProgress Event Type } for typing your event listeners for IMAGE_LOAD_PROGRESS event,
* and see what event detail is included in {@link EventTypes.ImageLoadProgressEventDetail | ImageLoadProgress Event Detail }
Expand Down
1 change: 1 addition & 0 deletions packages/dicom-image-loader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
19 changes: 19 additions & 0 deletions packages/dicom-image-loader/.webpack/merge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const _ = require('lodash');

// Merge two objects
// Instead of merging array objects index by index (n-th source
// item with n-th object item) it concatenates both arrays
module.exports = function (object, source) {
const clone = _.cloneDeep(object);
const merged = _.mergeWith(
clone,
source,
function (objValue, srcValue, key, object, source, stack) {
if (objValue && srcValue && _.isArray(objValue) && _.isArray(srcValue)) {
return _.concat(objValue, srcValue);
}
}
);

return merged;
};
Loading