mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
* build(deps): bump jest and @types/jest Bumps [jest](https://github.com/facebook/jest/tree/HEAD/packages/jest) and [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest). These dependencies needed to be updated together. Updates `jest` from 27.5.1 to 28.1.0 - [Release notes](https://github.com/facebook/jest/releases) - [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/facebook/jest/commits/v28.1.0/packages/jest) Updates `@types/jest` from 27.4.1 to 28.1.0 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) --- updated-dependencies: - dependency-name: jest dependency-type: direct:production update-type: version-update:semver-major - dependency-name: "@types/jest" dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix breaking changes in jest 28 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: David Lechner <david@pybricks.com>
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const camelcase = require('camelcase');
|
|
|
|
// This is a custom Jest transformer turning file imports into filenames.
|
|
// http://facebook.github.io/jest/docs/en/webpack.html
|
|
|
|
module.exports = {
|
|
process(src, filename) {
|
|
const assetFilename = JSON.stringify(path.basename(filename));
|
|
|
|
if (filename.match(/\.svg$/)) {
|
|
// Based on how SVGR generates a component name:
|
|
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
|
|
const pascalCaseFilename = camelcase(path.parse(filename).name, {
|
|
pascalCase: true,
|
|
});
|
|
const componentName = `Svg${pascalCaseFilename}`;
|
|
return {
|
|
code: `const React = require('react');
|
|
module.exports = {
|
|
__esModule: true,
|
|
default: ${assetFilename},
|
|
ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
|
|
return {
|
|
$$typeof: Symbol.for('react.element'),
|
|
type: 'svg',
|
|
ref: ref,
|
|
key: null,
|
|
props: Object.assign({}, props, {
|
|
children: ${assetFilename}
|
|
})
|
|
};
|
|
}),
|
|
};`,
|
|
}
|
|
}
|
|
|
|
return { code: `module.exports = ${assetFilename};` };
|
|
},
|
|
};
|