diff --git a/build b/build index 415a2faa686e..47a058fd30d9 100755 --- a/build +++ b/build @@ -30,11 +30,6 @@ try { console.log('Installing dependencies...'); shell('npm install'); } -// for some reason, esbuild won't be requirable until a tick has passed -// see https://stackoverflow.com/questions/53270058/node-cant-find-certain-modules-after-synchronous-install -setImmediate(() => { - require('./tools/build-utils').transpile(force, decl); -}); // Make sure config.js exists. If not, copy it over synchronously from // config-example.js, since it's needed before we can start the server @@ -49,3 +44,11 @@ try { fs.readFileSync('config/config-example.js') ); } + +// for some reason, esbuild won't be requirable until a tick has passed +// see https://stackoverflow.com/questions/53270058/node-cant-find-certain-modules-after-synchronous-install +setImmediate(() => { + // npm package, don't rebuild + if (process.argv[2] === 'postinstall' && fs.existsSync('dist')) return; + require('./tools/build-utils').transpile(force, decl); +}); diff --git a/package.json b/package.json index 31c63cb5f088..cdec72108bd5 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "test": "mocha", "posttest": "npm run tsc", "full-test": "npm run lint && npm run tsc && mocha --timeout 8000 --forbid-only -g \".*\"", - "postinstall": "npm run build" + "postinstall": "npm run build postinstall" }, "bin": "./pokemon-showdown", "homepage": "http://pokemonshowdown.com",