Skip to content

Commit 0dbd5b0

Browse files
committed
Use a dynamic import instead of weakRequire
1 parent 2d063e6 commit 0dbd5b0

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

src/jsonUtils/makeSvgLayer/makeSvgLayer.sketch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import convertSketchToJson from '../sketchJson/convertSketchToJson';
33

44
import { LayoutInfo } from '../../types';
55

6-
export default function makeSvgLayer(
6+
export default async function makeSvgLayer(
77
_layout: LayoutInfo,
88
name: string,
99
svg: string,
10-
): FileFormat.Group {
10+
): Promise<FileFormat.Group> {
1111
const svgString = NSString.stringWithString(svg);
1212
const svgData = svgString.dataUsingEncoding(NSUTF8StringEncoding);
1313
const svgImporter = MSSVGImporter.svgImporter();

src/jsonUtils/makeSvgLayer/makeSvgLayer.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { createUniformBorder } from '../borders';
66
import layerGroup from '../layerGroup';
77
import { makePathsFromCommands, makeLineCapStyle } from './graphics/path';
88
import { unionRects, scaleRect, makeBoundingRectFromCommands, resize } from './graphics/rect';
9-
import weakRequire from '../../utils/weakRequire';
109

1110
function makeLayerFromPathElement(pathElement, _parentFrame: FileFormat.Rect, scale: number) {
1211
const {
@@ -78,8 +77,13 @@ function makeLayerGroup(
7877
return group;
7978
}
8079

81-
export default function makeSvgLayer(layout: LayoutInfo, name: string, svg: string) {
82-
const svgModel = weakRequire(module, '@lona/svg-model');
80+
export default async function makeSvgLayer(
81+
layout: LayoutInfo,
82+
name: string,
83+
svg: string,
84+
): Promise<FileFormat.Group> {
85+
// Load the module only if it has been made available through another import.
86+
const svgModel = await import(/* webpackMode: "weak" */ '@lona/svg-model');
8387

8488
const {
8589
data: { params, children },

src/renderers/SvgRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class SvgRenderer extends ViewRenderer {
8080
children,
8181
});
8282

83-
const svgLayer = makeSvgLayer(layout, 'Shape', svgString);
83+
const svgLayer = await makeSvgLayer(layout, 'Shape', svgString);
8484

8585
layers.push(svgLayer);
8686

src/utils/weakRequire.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)