Skip to content

Commit

Permalink
WIP bun up
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasrw committed Sep 30, 2023
1 parent 9ea1019 commit 259fa4c
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 24 deletions.
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
"url": "git+https://github.com/mathiasrw/rexreplace.git"
},
"bin": {
"rr": "bin/rexreplace.cli.js",
"rexreplace": "dist/env/node.js"
"rr": "src/env/bun.ts",
"rexreplace_node": "bin/rexreplace.cli.js",
"rexreplace": "src/env/bun.ts"
},
"scripts": {
"test": "yarn build && yarn test-cli && yarn test-js",
"postbuild": "cp bin/rexreplace.cli.js bin/rexreplace.cli.min.js",
"version": "yarn build-minify",
"build": "yarn build-only",
"build-only": "swc src/ -d bin/ && bun build --target node bin/env/node.js --outfile bin/rexreplace.cli.js",
"build-minify": "bun build --target node bin/env/node.js --outfile bin/rexreplace.cli.min.js --minify",
"prebuild": "rm -fr bin && yarn format",
"build-only": "swc src/ -d dist/ && bun build --target node src/env/node.ts --outfile bin/rexreplace.cli.js ",
"build-minify": "bun build --target node src/env/node.ts --outfile bin/rexreplace.cli.min.js --minify",
"prebuild": "rm -fr bin # && yarn format",
"test-js": "echo todo: async mocha",
"test-minify": "yarn build-minify && yarn test-cli && yarn test-js",
"test-cli": "npm uninstall -g rexreplace && npm -g install ./ && yarn test-cli-only",
Expand Down Expand Up @@ -66,6 +67,7 @@
"rollup-plugin-preserve-shebang": "1.0.1",
"rollup-plugin-progress": "1.1.2",
"rollup-plugin-typescript3": "1.1.3",
"ts-node": "^10.9.1",
"typescript": "5.2.2",
"version-bump-prompt": "6.1.0",
"yarn": "1.22.19"
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import yargs from 'yargs';

import * as rexreplace from './engine.ts';

import {chat, debug, die, error, info, outputConfig, step} from './output';
import {chat, debug, die, error, info, outputConfig, step} from './output.ts';

const re = {
nl: /\r?\n/,
Expand Down
Empty file removed src/deno.d.ts
Empty file.
4 changes: 2 additions & 2 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const globs = require('globs');

const now = new Date();

import {chat, debug, die, error, info, outputConfig, step} from './output';
import {chat, debug, die, error, info, outputConfig, step} from './output.ts';

const re = {
euro: //g,
Expand Down Expand Up @@ -45,7 +45,7 @@ export function engine(_runtime: Runtime, conf: any = {engine: 'V8'}) {
conf.files = getFilePaths(conf);

if (!conf.files.length) {
if (conf.contentWasPiped) {
if (null !== conf.pipeData) {
return doReplacement('[pipe-data]', conf, conf.pipeData);
}

Expand Down
4 changes: 2 additions & 2 deletions src/env/bun.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export const runtime: Runtime = {

process.stdin.setEncoding(conf.encoding);

let pipeData = '';
let pipeData = null;
process.stdin.on('readable', () => {
let chunk = process.stdin.read();

if (null !== chunk) {
pipeData += chunk;
pipeData = chunk;
while ((chunk = process.stdin.read())) {
pipeData += chunk;
}
Expand Down
6 changes: 2 additions & 4 deletions src/env/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

/// <reference types="deno" />

import {readAll} from 'https://deno.land/std/io/mod.ts';

import yargs from 'https://deno.land/x/yargs/deno.ts';

import fs from 'fs-extra';

import {cli2conf, executeReplacement} from '../cli.js';
import {cli2conf, executeReplacement} from '../cli.ts';

const runtime: Runtime = {
fileReadSync: (path, encoding = 'utf8') => fs.readFileSync(path, {encoding}),
Expand Down Expand Up @@ -40,7 +38,7 @@ const runtime: Runtime = {
};

async function getPipeData() {
const stdinContent = await readAll(Deno.stdin);
const stdinContent = await Deno.readAll(Deno.stdin);
const text = new TextDecoder().decode(stdinContent);
return text;
}
Expand Down
4 changes: 2 additions & 2 deletions src/env/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export const runtime: Runtime = {

process.stdin.setEncoding(conf.encoding);

let pipeData = '';
let pipeData = null;
process.stdin.on('readable', () => {
let chunk = process.stdin.read();

if (null !== chunk) {
pipeData += chunk;
pipeData = chunk;
while ((chunk = process.stdin.read())) {
pipeData += chunk;
}
Expand Down
14 changes: 11 additions & 3 deletions test/cli/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#!/usr/bin/env bash

#rexreplace() {
# node dist/env/node.js "$@"
#npx node-ts src/env/node.ts "$@"
# npx ts-node src/env/node.ts "$@"
# bun src/env/bun.ts "$@"
#}

echo RexReplace v$(rexreplace -v)
where rexreplace
# where rexreplace

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

export STOP=1
source $DIR/aserta.sh

# # Command exit codes
Expand All @@ -31,8 +39,6 @@ reset() {
echo 'abc123' > your.file
echo -n > stdout.log
echo -n > stderr.log

rm stderr.log
}


Expand Down Expand Up @@ -588,11 +594,13 @@ assert_failure "rexreplace '*foo' 'bar' my.file"
# assert "rexreplace ??? ??? my.file -d" "foobar"
# reset

reset
rm my.file
rm your.file
rm stdout.log
rm stderr.log


assert_end "rexreplace"


Expand Down
13 changes: 10 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
"target": "ES6",
"lib": ["es6", "esnext"],
"types": ["node"],
"moduleResolution": "nodenext",
"module": "NodeNext"
"moduleResolution": "node",
"module": "commonjs",
"allowImportingTsExtensions": true,
"noEmit": true,
"esModuleInterop": true
},
"include": ["src/env/node.ts"]
"include": ["src/**/*.ts"],
"exclude": ["node_modules"],
"ts-node": {
"esm": true
}
}
93 changes: 91 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
dependencies:
regenerator-runtime "^0.14.0"

"@cspotcode/source-map-support@^0.8.0":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"
integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==
dependencies:
"@jridgewell/trace-mapping" "0.3.9"

"@gar/promisify@^1.0.1":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6"
Expand All @@ -23,7 +30,7 @@
"@jridgewell/sourcemap-codec" "^1.4.10"
"@jridgewell/trace-mapping" "^0.3.9"

"@jridgewell/resolve-uri@^3.1.0":
"@jridgewell/resolve-uri@^3.0.3", "@jridgewell/resolve-uri@^3.1.0":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz#c08679063f279615a3326583ba3a90d1d82cc721"
integrity sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==
Expand All @@ -46,6 +53,14 @@
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32"
integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==

"@jridgewell/trace-mapping@0.3.9":
version "0.3.9"
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9"
integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==
dependencies:
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@jridgewell/trace-mapping@^0.3.9":
version "0.3.19"
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz#f8a3249862f91be48d3127c3cfe992f79b4b8811"
Expand Down Expand Up @@ -336,6 +351,26 @@
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==

"@tsconfig/node10@^1.0.7":
version "1.0.9"
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2"
integrity sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==

"@tsconfig/node12@^1.0.7":
version "1.0.11"
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d"
integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==

"@tsconfig/node14@^1.0.0":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.3.tgz#e4386316284f00b98435bf40f72f75a09dabf6c1"
integrity sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==

"@tsconfig/node16@^1.0.2":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.4.tgz#0b92dcc0cc1c81f6f306a381f28e31b1a56536e9"
integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==

"@types/buble@^0.19.2":
version "0.19.2"
resolved "https://registry.yarnpkg.com/@types/buble/-/buble-0.19.2.tgz#a4289d20b175b3c206aaad80caabdabe3ecdfdd1"
Expand Down Expand Up @@ -414,12 +449,17 @@ acorn-jsx@^5.2.0:
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"
integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==

acorn-walk@^8.1.1:
version "8.2.0"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1"
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==

acorn@^6.4.1:
version "6.4.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.2.tgz#35866fd710528e92de10cf06016498e47e39e1e6"
integrity sha512-XtGIhXwF8YM8bJhGxG5kXgjkEuNGLTkoYqVE+KMR+aspr4KGYmKYg7yUe3KghyQ9yheNwLnjmzh/7+gfDBmHCQ==

acorn@^8.8.2:
acorn@^8.4.1, acorn@^8.8.2:
version "8.10.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5"
integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==
Expand Down Expand Up @@ -520,6 +560,11 @@ are-we-there-yet@~1.1.2:
delegates "^1.0.0"
readable-stream "^2.0.6"

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
Expand Down Expand Up @@ -948,6 +993,11 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

cross-spawn@^5.0.1:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -1045,6 +1095,11 @@ diff@5.0.0:
resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b"
integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==

diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

dir-glob@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
Expand Down Expand Up @@ -2000,6 +2055,11 @@ magic-string@^0.27.0:
dependencies:
"@jridgewell/sourcemap-codec" "^1.4.13"

make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

make-fetch-happen@^9.0.1:
version "9.1.0"
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz#53085a09e7971433e6765f7971bf63f4e05cb968"
Expand Down Expand Up @@ -3152,6 +3212,25 @@ trim-repeated@^2.0.0:
dependencies:
escape-string-regexp "^5.0.0"

ts-node@^10.9.1:
version "10.9.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b"
integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==
dependencies:
"@cspotcode/source-map-support" "^0.8.0"
"@tsconfig/node10" "^1.0.7"
"@tsconfig/node12" "^1.0.7"
"@tsconfig/node14" "^1.0.0"
"@tsconfig/node16" "^1.0.2"
acorn "^8.4.1"
acorn-walk "^8.1.1"
arg "^4.1.0"
create-require "^1.1.0"
diff "^4.0.1"
make-error "^1.1.1"
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
Expand Down Expand Up @@ -3282,6 +3361,11 @@ uuid@^3.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

v8-compile-cache-lib@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==

validate-npm-package-name@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz#5fa912d81eb7d0c74afc140de7317f0ca7df437e"
Expand Down Expand Up @@ -3439,6 +3523,11 @@ yarn@1.22.19:
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.19.tgz#4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
integrity sha512-/0V5q0WbslqnwP91tirOvldvYISzaqhClxzyUKXYxs07yUILIs5jx/k6CFe8bvKSkds5w+eiOqta39Wk3WxdcQ==

yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
Expand Down

0 comments on commit 259fa4c

Please sign in to comment.