Skip to content

Commit

Permalink
chore: use bundt for building worktop packages (#152)
Browse files Browse the repository at this point in the history
* chore(worktop): rename `src/router.ts` -> `src/index.ts`

* chore(bin): use `tsm` for test TS transform

* chore: use `bundt` for package builders

* chore: add jsdoc for bin types

* chore: use `build.mjs` instead

* chore(bin): use `tsm` for build script
  • Loading branch information
lukeed committed Mar 28, 2022
1 parent f9f6f10 commit 42b8dc5
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 296 deletions.
35 changes: 35 additions & 0 deletions bin/build.ts
@@ -0,0 +1,35 @@
import { resolve } from 'path';
import * as bundt from 'bundt';

const root = resolve('packages');
const minify = !process.argv.includes('--dev');

let result: bundt.Output = {};

async function run(mod: string) {
let dir = resolve(root, mod);
let stats = await bundt.build(dir, { minify });
Object.assign(result, stats);
}

try {
var timer = process.hrtime();
await Promise.all([
run('create-worktop'),
run('worktop.build'),
run('worktop'),
]);
timer = process.hrtime(timer);
} catch (err) {
let msg = (err as Error).stack || err;
console.error(msg);
process.exit(1);
}

console.log(
await bundt.report(result, {
cwd: root,
gzip: true,
delta: timer,
})
);
154 changes: 0 additions & 154 deletions bin/index.js

This file was deleted.

34 changes: 1 addition & 33 deletions bin/register.js
@@ -1,7 +1,5 @@
// @ts-check
const { transformSync } = require('esbuild');

const loadJS = require.extensions['.js'];
require('fetchy/polyfill');

// @ts-ignore - worktop/cfw.cache
globalThis.caches = { default: {} };
Expand All @@ -12,33 +10,3 @@ globalThis.crypto = require('crypto').webcrypto;
// worktop/base64
globalThis.btoa = (x) => Buffer.from(x, 'binary').toString('base64');
globalThis.atob = (x) => Buffer.from(x, 'base64').toString('binary');

require('fetchy/polyfill');

require.extensions['.ts'] = function (Module, filename) {
const pitch = Module._compile.bind(Module);

Module._compile = source => {
const { code, warnings } = transformSync(source, {
loader: 'ts',
format: 'cjs',
target: 'es2019',
sourcemap: 'inline',
sourcefile: filename,
minifyIdentifiers: true,
minifySyntax: true,
treeShaking: true,
charset: 'utf8',
});

warnings.forEach(msg => {
console.warn(`\nesbuild warning in ${filename}:`);
console.warn(msg.location);
console.warn(msg.text);
});

return pitch(code, filename);
};

loadJS(Module, filename);
}
103 changes: 0 additions & 103 deletions bin/utils.js

This file was deleted.

9 changes: 4 additions & 5 deletions package.json
Expand Up @@ -10,17 +10,16 @@
"node": ">=12"
},
"scripts": {
"build": "node bin",
"test": "uvu packages \".test.ts$\" -r ./bin/register",
"build": "tsm bin/build.ts",
"test": "uvu packages \".test.ts$\" -r tsm -r ./bin/register",
"types": "tsc --noEmit --skipLibCheck"
},
"devDependencies": {
"@types/node": "16.11.6",
"esbuild": "0.13.2",
"bundt": "2.0.0-next.1",
"fetchy": "next",
"is-uuid": "1.0.2",
"kleur": "4.1.4",
"rewrite-imports": "2.0.3",
"tsm": "2.2.1",
"typescript": "4.5.4",
"uvu": "0.5.2"
}
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -16,12 +16,13 @@
"checkJs": true,
"noEmit": true,
"paths": {
"worktop": ["./packages/worktop/src/router.d.ts"],
"worktop": ["./packages/worktop/src/index.d.ts"],
"worktop/*": ["./packages/worktop/src/*.d.ts"],
"worktop.build": ["./packages/worktop.build/index.d.ts"],
}
},
"include": [
"bin/*.ts",
"packages/combos.ts",
"packages/worktop/src",
"packages/worktop/types",
Expand Down

0 comments on commit 42b8dc5

Please sign in to comment.