Skip to content

Commit 1a51c3a

Browse files
takaokoujiclaude
andcommitted
feat: enhance fetch-worker path fixing with robust pattern matching
- Improved postbuild.mjs script with additional regex pattern for arrow functions - Fixed webpack externals configuration syntax - Resolved import path issues in ruby-to-blocks-converter - Enhanced pattern detection for worker-loader generated code This completes the GitHub Pages publicPath fix to ensure sprite/background selection functionality works correctly on subdirectory deployments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4be607e commit 1a51c3a

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

scripts/postbuild.mjs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,27 @@ const fixFetchWorkerPaths = (filePath, publicPath) => {
2626
}
2727

2828
const content = fs.readFileSync(filePath, 'utf8');
29-
29+
3030
// Replace relative "chunks/" paths with absolute paths including publicPath
3131
const fixedContent = content.replace(
3232
/return "chunks\/" \+ "fetch-worker"/g,
3333
`return "${publicPath}chunks/" + "fetch-worker"`
34+
).replace(
35+
/[=]>"chunks\/fetch-worker\./g,
36+
`=>"${publicPath}chunks/fetch-worker.`
3437
);
3538

36-
if (content !== fixedContent) {
39+
if (content === fixedContent) {
40+
console.info(`No fetch-worker paths found in ${path.relative(basePath, filePath)}`);
41+
} else {
3742
fs.writeFileSync(filePath, fixedContent);
3843
console.info(`Fixed fetch-worker paths in ${path.relative(basePath, filePath)}`);
39-
} else {
40-
console.info(`No fetch-worker paths found in ${path.relative(basePath, filePath)}`);
4144
}
4245
};
4346

44-
const postbuild = async () => {
47+
const postbuild = () => {
4548
const publicPath = process.env.PUBLIC_PATH;
46-
49+
4750
if (!publicPath) {
4851
console.info('PUBLIC_PATH not set - skipping fetch-worker path fixes');
4952
return;
@@ -63,13 +66,6 @@ const postbuild = async () => {
6366
}
6467
};
6568

66-
postbuild().then(
67-
() => {
68-
console.info('Post-build script complete');
69-
process.exit(0);
70-
},
71-
e => {
72-
console.error('Post-build script failed:', e);
73-
process.exit(1);
74-
}
75-
);
69+
postbuild();
70+
console.info('Post-build script complete');
71+
process.exit(0);

src/lib/ruby-to-blocks-converter/constants.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ const KeyOptions = [
4343
'9'
4444
];
4545

46+
/**
47+
* scratch-vm/src/engine/variable.jsからコピー
48+
* @const
49+
*/
50+
const Variable = {
51+
SCALAR_TYPE: '',
52+
LIST_TYPE: 'list',
53+
BROADCAST_MESSAGE_TYPE: 'broadcast_msg'
54+
};
55+
4656
export {
47-
KeyOptions
57+
KeyOptions,
58+
Variable
4859
};

src/lib/ruby-to-blocks-converter/event.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// eslint-disable-next-line import/no-unresolved
2-
import Variable from 'scratch-vm/src/engine/variable';
3-
import {KeyOptions} from './constants';
2+
import {KeyOptions, Variable} from './constants';
43

54
const GreaterThanMenu = [
65
'LOUDNESS',

src/lib/ruby-to-blocks-converter/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import log from '../log';
55
import Blockly from 'scratch-blocks';
66
import RubyParser from '../ruby-parser';
77
// eslint-disable-next-line import/no-unresolved
8-
import Variable from 'scratch-vm/src/engine/variable';
8+
import {Variable} from './constants';
99

1010
import Primitive from './primitive';
1111
import {RubyToBlocksConverterError} from './errors';
@@ -588,7 +588,7 @@ class RubyToBlocksConverter {
588588
SoundConverter,
589589
SensingConverter
590590
];
591-
591+
592592
for (let i = 0; i < legacyConverters.length; i++) {
593593
const converter = legacyConverters[i];
594594
if (Object.prototype.hasOwnProperty.call(converter, handlerName)) {

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ const distConfig = baseConfig.clone()
101101
},
102102
output: {
103103
path: path.resolve(__dirname, 'dist')
104-
}
104+
},
105+
externals: ['react', 'react-dom']
105106
})
106-
.addExternals(['react', 'react-dom'])
107107
.addPlugin(
108108
new CopyWebpackPlugin({
109109
patterns: [

0 commit comments

Comments
 (0)