Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:evex-dev/scratch-gui-vite into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
nakasyou committed Dec 10, 2024
2 parents 146c0f0 + cf49b89 commit e9fda3c
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 64 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/eruda"></script>
<script>eruda.init();</script>
<!--<script src="https://cdn.jsdelivr.net/npm/eruda"></script>
<script>eruda.init();</script>-->
</head>
<body>
<script src="/playground/main.jsx" type="module"></script>
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@
}
},
"patchedDependencies": {
"@scratch/paper@0.11.0": "patches/@scratch%2Fpaper@0.11.0.patch",
"scratch-paint@3.0.20": "patches/scratch-paint@3.0.20.patch",
"parse-color@1.0.0": "patches/parse-color@1.0.0.patch"
"scratch-paint@3.0.20": "patches/scratch-paint@3.0.20.patch"
}
}
10 changes: 0 additions & 10 deletions patches/@scratch%2Fpaper@0.11.0.patch

This file was deleted.

13 changes: 0 additions & 13 deletions patches/parse-color@1.0.0.patch

This file was deleted.

57 changes: 57 additions & 0 deletions plugins/cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Plugin } from 'vite'
import * as esbuild from 'esbuild'
import * as path from 'node:path'

const CJS_PATCHES = [
'@scratch/paper',
'parse-color',
'react-popover'
]

const cached = new Map<string, string>()
const getBuild = async (id: string) => {
if (cached.has(id)) {
return cached.get(id)
}
const result = await esbuild.build({
entryPoints: [id],
format: 'esm',
platform: 'browser',
target: 'esnext',
bundle: true,
write: false,
logLevel: 'error',
})
const code = result.outputFiles?.[0].text
if (!code) {
throw result.errors[0]
}
cached.set(id, code)
return code
}

export const cjsPlugin = (): Plugin => {
return {
name: 'vite-plugin-cjs',
async load(id, options) {
let isPatch = false
for (const patch of CJS_PATCHES) {
if (id.includes(`node_modules/${patch}`)) {
isPatch = true
break
}
}
if (!isPatch) {
return
}
const code = await getBuild(id)
if (!code) {
return
}
console.log('patched', id)
return {
code
}
},
}
}
9 changes: 4 additions & 5 deletions src/components/gui/gui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import tabStyles from 'react-tabs/style/react-tabs.css?module';
import VM from 'scratch-vm';
import Renderer from 'scratch-render';

//import Blocks from '../../containers/blocks.jsx';
import CostumeTab from '../../containers/costume-tab.jsx';/*
import Blocks from '../../containers/blocks.jsx';
import CostumeTab from '../../containers/costume-tab.jsx';
import TargetPane from '../../containers/target-pane.jsx';
import SoundTab from '../../containers/sound-tab.jsx';
import StageWrapper from '../../containers/stage-wrapper.jsx';
Expand All @@ -20,17 +20,16 @@ import Box from '../box/box.jsx';
import MenuBar from '../menu-bar/menu-bar.jsx';
import CostumeLibrary from '../../containers/costume-library.jsx';
import BackdropLibrary from '../../containers/backdrop-library.jsx';
import Watermark from '../../containers/watermark.jsx';*/
import Watermark from '../../containers/watermark.jsx';

/*
import Backpack from '../../containers/backpack.jsx';
import WebGlModal from '../../containers/webgl-modal.jsx';
import TipsLibrary from '../../containers/tips-library.jsx';
import Cards from '../../containers/cards.jsx';
import Alerts from '../../containers/alerts.jsx';
import DragLayer from '../../containers/drag-layer.jsx';
import ConnectionModal from '../../containers/connection-modal.jsx';
import TelemetryModal from '../telemetry-modal/telemetry-modal.jsx';*/
import TelemetryModal from '../telemetry-modal/telemetry-modal.jsx';

import layout, {STAGE_SIZE_MODES} from '../../lib/layout-constants';
import {resolveStageSize} from '../../lib/screen-utils';
Expand Down
2 changes: 1 addition & 1 deletion src/containers/paint-editor-wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import bindAll from 'lodash.bindall';
import VM from 'scratch-vm';
//import PaintEditor from 'scratch-paint';
import PaintEditor from 'scratch-paint';
import {inlineSvgFonts} from 'scratch-svg-renderer';

import {connect} from 'react-redux';
Expand Down
4 changes: 2 additions & 2 deletions src/lib/app-state-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {detectLocale} from './detect-locale';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

import guiRedux from '../reducers/gui.js';
import ScratchPaint from 'scratch-paint';
import * as guiRedux from '../reducers/gui.js';
import * as ScratchPaint from 'scratch-paint';

/*
* Higher Order Component to provide redux state. If an `intl` prop is provided
Expand Down
30 changes: 2 additions & 28 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'node:path'
import * as fs from 'node:fs/promises'
import * as url from 'node:url'
import { existsSync } from 'node:fs'
import { build } from 'esbuild'
import { cjsPlugin } from './plugins/cjs.ts'

const scratchGuiPlugin = (): Plugin => {
let resolvedConfig!: ResolvedConfig
Expand Down Expand Up @@ -122,36 +122,10 @@ const allModuleCSSPlugin = (): Plugin => {
}
}

const CJS_PATCHES = [
'css-vendor',
'@scratch/paper',
'color-convert'
]
const cjs = (): Plugin => {
return {
name: 'vite-plugin-cjs',
async load(id, options) {
for (const patch of CJS_PATCHES) {
if (id.includes(`node_modules/${patch}`)) {
const built = await build({
entryPoints: [id.replace(/\?.*/, '')],
write: false,
bundle: true,
format: 'esm'
})
return {
code: built.outputFiles[0].text
}
}
}
},
}
}

export default defineConfig({
plugins: [
cjs(),
allModuleCSSPlugin(),
cjsPlugin(),
reactVirtualized(),
scratchGuiPlugin()
],
Expand Down

0 comments on commit e9fda3c

Please sign in to comment.