From 209dc5202e94b2a8aa6f94fe0da6de32b6c50fcf Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Thu, 19 Dec 2024 00:20:31 +0800 Subject: [PATCH] fix: scheduler not find --- scripts/download-react.mjs | 10 ++++++---- src/{scheduler.js.meta => react-scheduler.js.meta} | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) rename src/{scheduler.js.meta => react-scheduler.js.meta} (65%) diff --git a/scripts/download-react.mjs b/scripts/download-react.mjs index a64291b..41e847c 100644 --- a/scripts/download-react.mjs +++ b/scripts/download-react.mjs @@ -7,6 +7,8 @@ const pluginTitle = `${author}/${name}`; // fix ReferenceError: process is not defined const fixProcessUndefined = (code) => code.replace('process.env.NODE_ENV', '"development"'); +// prevent collision of name, use a different name. See `src/react-scheduler.js.meta`. +const fixSchedulerNameCollision = (code) => code.replace('require("scheduler")', 'require("react-scheduler.js")'); const version = '19'; const reactPath = `node_modules/react/cjs`; @@ -18,8 +20,8 @@ const [reactDev, react, reactDomDev, reactDom, reactDomClientDev, reactClientDom fs.readFile(path.join(reactPath, `react.production.js`), 'utf-8'), fs.readFile(path.join(reactDomPath, `react-dom.development.js`), 'utf-8').then(fixProcessUndefined), fs.readFile(path.join(reactDomPath, `react-dom.production.js`), 'utf-8'), - fs.readFile(path.join(reactDomPath, `react-dom-client.development.js`), 'utf-8').then(fixProcessUndefined), - fs.readFile(path.join(reactDomPath, `react-dom-client.production.js`), 'utf-8'), + fs.readFile(path.join(reactDomPath, `react-dom-client.development.js`), 'utf-8').then(fixProcessUndefined).then(fixSchedulerNameCollision), + fs.readFile(path.join(reactDomPath, `react-dom-client.production.js`), 'utf-8').then(fixSchedulerNameCollision), fs.readFile(path.join(reactPath, `react-jsx-runtime.development.js`), 'utf-8').then(fixProcessUndefined), fs.readFile(path.join(reactPath, `react-jsx-runtime.production.js`), 'utf-8'), fs.readFile(path.join(schedulerPath, `scheduler.development.js`), 'utf-8').then(fixProcessUndefined), @@ -38,6 +40,6 @@ await Promise.all([ fs.writeFile(path.join(pluginPath, 'react-dom-client.js'), reactClientDom), fs.writeFile(path.join(devPluginPath, 'react-jsx-runtime.js'), reactJsxRuntimeDev), fs.writeFile(path.join(pluginPath, 'react-jsx-runtime.js'), reactJsxRuntime), - fs.writeFile(path.join(devPluginPath, 'scheduler.js'), schedulerDev), - fs.writeFile(path.join(pluginPath, 'scheduler.js'), scheduler), + fs.writeFile(path.join(devPluginPath, 'react-scheduler.js'), schedulerDev), + fs.writeFile(path.join(pluginPath, 'react-scheduler.js'), scheduler), ]); diff --git a/src/scheduler.js.meta b/src/react-scheduler.js.meta similarity index 65% rename from src/scheduler.js.meta rename to src/react-scheduler.js.meta index bc73083..184156e 100644 --- a/src/scheduler.js.meta +++ b/src/react-scheduler.js.meta @@ -1,3 +1,3 @@ -title: scheduler +title: react-scheduler.js type: application/javascript module-type: library