From cbc8b2a6f5e1ebd367b8fd66eec775c2f5b3553b Mon Sep 17 00:00:00 2001 From: Bever1337 Date: Thu, 5 May 2022 16:50:53 -0400 Subject: [PATCH] feat(sync): Adds sync build step --- package.json | 4 +++- prebuild.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c5ed6b14..37c27cc8 100644 --- a/package.json +++ b/package.json @@ -56,9 +56,11 @@ "prerelease": "yarn verify", "prebuild": "rimraf dist && mkdir dist && node prebuild.js && cp src/itty-router.d.ts dist", "build": "yarn uglify", - "uglify": "yarn uglify:cjs && yarn uglify:esm", + "uglify": "yarn uglify:cjs && yarn uglify:cjs:sync && yarn uglify:esm && yarn uglify:esm:sync", "uglify:esm": "uglifyjs dist/itty-router.mjs -c -m --toplevel > dist/itty-router.min.mjs", + "uglify:esm:sync": "uglifyjs dist/itty-router-sync.mjs -c -m --toplevel > dist/itty-router-sync.min.mjs", "uglify:cjs": "uglifyjs src/itty-router.js -c -m --toplevel > dist/itty-router.min.js", + "uglify:cjs:sync": "uglifyjs dist/itty-router-sync.js -c -m --toplevel > dist/itty-router-sync.min.js", "build:esm": "esbuild src/itty-router.js --format=esm --outfile=./dist/itty-router.mjs", "postbuild": "node check-size.js", "release": "release --tag --push" diff --git a/prebuild.js b/prebuild.js index a9b64d87..284041dc 100644 --- a/prebuild.js +++ b/prebuild.js @@ -2,11 +2,21 @@ const { readFileSync, writeFileSync } = require('fs-extra') console.log('writing esm version.') const base = readFileSync('./src/itty-router.js', { encoding: 'utf-8' }) +writeFileSync('./dist/itty-router.mjs', base) +const baseSync = base + .replace('async handle', 'handle') + .replace('await handler', 'handler') +writeFileSync('./dist/itty-router-sync.js', baseSync) const esm = base .replace('function Router', 'export function Router') .replace('module.exports =', 'export default') .replace(/\s*\/\/[^\n]+/g, '') writeFileSync('./dist/itty-router.mjs', esm) +const esmSync = baseSync + .replace('function Router', 'export function Router') + .replace('module.exports =', 'export default') + .replace(/\s*\/\/[^\n]+/g, '') +writeFileSync('./dist/itty-router-sync.mjs', esmSync) const test = readFileSync('./src/itty-router.spec.js', { encoding: 'utf-8' }) const minifiedTest = test.replace('itty-router', 'itty-router.min.js')