mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-15 02:54:07 +00:00
mpy/sagas: use "new" webpack asset URL
Jest added support for wasm imports which broke our tests. In the mean time, Webpack 5 added a new asset inclusion mechanism that can work around this and removes the need for our existing webpack workaround.
This commit is contained in:
committed by
David Lechner
parent
6ca0c49557
commit
3e50e58206
@@ -556,16 +556,6 @@ module.exports = function (webpackEnv) {
|
||||
'sass-loader'
|
||||
),
|
||||
},
|
||||
// Adds support for wasm that runs as an application.
|
||||
// https://github.com/webpack/webpack/issues/7352
|
||||
{
|
||||
test: /\.wasm$/,
|
||||
type: 'javascript/auto',
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
name: 'static/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||
// When you `import` an asset, you get its (virtual) filename.
|
||||
// In production, they would get copied to the `build` folder.
|
||||
|
||||
+18
-8
@@ -2,9 +2,7 @@
|
||||
// Copyright (c) 2020-2022 The Pybricks Authors
|
||||
|
||||
import { compile as mpyCrossCompileV5 } from '@pybricks/mpy-cross-v5';
|
||||
import wasmV5 from '@pybricks/mpy-cross-v5/build/mpy-cross.wasm';
|
||||
import { compile as mpyCrossCompileV6 } from '@pybricks/mpy-cross-v6';
|
||||
import wasmV6 from '@pybricks/mpy-cross-v6/build/mpy-cross-v6.wasm';
|
||||
import { call, getContext, put, select, takeEvery } from 'typed-redux-saga/macro';
|
||||
import { editorGetValue } from '../editor/sagaLib';
|
||||
import { FileContents, FileStorageDb } from '../fileStorage';
|
||||
@@ -56,8 +54,12 @@ function* handleCompile(action: ReturnType<typeof compile>): Generator {
|
||||
'main.py',
|
||||
action.script,
|
||||
action.options,
|
||||
// HACK: testing user agent for jsdom is needed only for getting unit tests to work
|
||||
navigator.userAgent.includes('jsdom') ? undefined : wasmV5,
|
||||
process.env.NODE_ENV === 'test'
|
||||
? undefined
|
||||
: new URL(
|
||||
'@pybricks/mpy-cross-v5/build/mpy-cross.wasm',
|
||||
import.meta.url,
|
||||
).toString(),
|
||||
),
|
||||
);
|
||||
if (result.status === 0 && result.mpy) {
|
||||
@@ -75,8 +77,12 @@ function* handleCompile(action: ReturnType<typeof compile>): Generator {
|
||||
'main.py',
|
||||
action.script,
|
||||
action.options,
|
||||
// HACK: testing user agent for jsdom is needed only for getting unit tests to work
|
||||
navigator.userAgent.includes('jsdom') ? undefined : wasmV6,
|
||||
process.env.NODE_ENV === 'test'
|
||||
? undefined
|
||||
: new URL(
|
||||
'@pybricks/mpy-cross-v6/build/mpy-cross-v6.wasm',
|
||||
import.meta.url,
|
||||
).toString(),
|
||||
),
|
||||
);
|
||||
if (result.status === 0 && result.mpy) {
|
||||
@@ -182,8 +188,12 @@ function* handleCompileMulti6(): Generator {
|
||||
py.path,
|
||||
py.contents,
|
||||
undefined,
|
||||
// HACK: testing user agent for jsdom is needed only for getting unit tests to work
|
||||
navigator.userAgent.includes('jsdom') ? undefined : wasmV6,
|
||||
process.env.NODE_ENV === 'test'
|
||||
? undefined
|
||||
: new URL(
|
||||
'@pybricks/mpy-cross-v6/build/mpy-cross-v6.wasm',
|
||||
import.meta.url,
|
||||
).toString(),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Vendored
-5
@@ -78,11 +78,6 @@ declare module '*.json' {
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.wasm' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.zip' {
|
||||
const src: string;
|
||||
export default src;
|
||||
|
||||
Reference in New Issue
Block a user