diff --git a/LICENSE b/LICENSE index 0ae5983..c4a5e8e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Webpod +Copyright (c) 2024 Webpod Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e399e63..fe4fc59 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ – eat all kinds of materials. -

🔬🧫

+## 🔬🧫 > This subproject is a kind of experiment, addressed to the [google/zx/issues/589](https://github.com/google/zx/issues/589). Just a testing ground for verifying ideas and approaches aimed at improve the [zx](https://github.com/google/zx) architecture. diff --git a/package.json b/package.json index 7819bdd..0f87840 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,18 @@ "require": "./target/cjs/spawn.cjs", "import": "./target/esm/spawn.mjs", "default": "./target/esm/spawn.mjs" + }, + "./zurk": { + "types": "./target/dts/zurk.d.ts", + "require": "./target/cjs/zurk.cjs", + "import": "./target/esm/zurk.mjs", + "default": "./target/esm/zurk.mjs" + }, + "./util": { + "types": "./target/dts/util.d.ts", + "require": "./target/cjs/util.cjs", + "import": "./target/esm/util.mjs", + "default": "./target/esm/util.mjs" } }, "module": "target/esm/index.mjs", @@ -28,7 +40,7 @@ ], "scripts": { "build": "concurrently 'npm:build:*'", - "build:js": "node ./src/scripts/build.mjs --entry='./src/main/ts/index.ts:./src/main/ts/spawn.ts'", + "build:js": "node ./src/scripts/build.mjs --entry='./src/main/ts/index.ts:./src/main/ts/util.ts:./src/main/ts/spawn.ts:./src/main/ts/zurk.ts'", "build:dts": "tsc --emitDeclarationOnly --outDir target/dts", "build:docs": "typedoc --options src/main/typedoc", "build:stamp": "npx buildstamp", @@ -49,12 +61,12 @@ "homepage": "https://github.com/webpod/zurk#readme", "dependencies": {}, "devDependencies": { - "@types/node": "^20.11.27", + "@types/node": "^20.11.28", "c8": "^9.1.0", "concurrently": "^8.2.2", "esbuild": "^0.20.2", "esbuild-node-externals": "^1.13.0", - "esbuild-plugin-entry-chunks": "^0.1.8", + "esbuild-plugin-entry-chunks": "^0.1.11", "eslint": "^8.57.0", "eslint-config-qiwi": "^2.1.3", "fast-glob": "^3.3.2", diff --git a/src/main/ts/util.ts b/src/main/ts/util.ts index 7afe7f0..17c3a20 100644 --- a/src/main/ts/util.ts +++ b/src/main/ts/util.ts @@ -1,3 +1,5 @@ +import { Stream } from 'node:stream' + export const noop = () => { /* noop */ } export type PromiseResolve = (value: T | PromiseLike) => void @@ -70,3 +72,13 @@ export const substitute: TSubstitute = (arg: any) => (typeof arg?.stdout === 'string') ? arg.stdout.replace(/\n$/, '') : `${arg}` + +export const parseInput = (input: any): string | Buffer | Stream | null => { + if (typeof input === 'string' || input instanceof Buffer || input instanceof Stream) return input + + if (typeof input?.stdout === 'string') return input.stdout + + if (input?.ctx) return parseInput(input.ctx.stdout) + + return null +} diff --git a/src/main/ts/x.ts b/src/main/ts/x.ts index 18e7f92..20a8536 100644 --- a/src/main/ts/x.ts +++ b/src/main/ts/x.ts @@ -16,7 +16,8 @@ import { isStringLiteral, assign, quote, - buildCmd + buildCmd, + parseInput } from './util.js' import { pipeMixin } from './mixin/pipe.js' import { killMixin } from './mixin/kill.js' @@ -126,10 +127,3 @@ export const applyMixins = ($: TShell, result: TZurk | TZurkPromise | TShellOpti return m($, r as any, ctx) }, result) } - -export const parseInput = (input: TShellOptions['input']): TShellCtx['input'] => { - if (typeof (input as TShellResponseSync)?.stdout === 'string') return (input as TShellResponseSync).stdout - if ((input as TShellResponse)?.ctx) return (input as TShellResponse).ctx.stdout - - return input as TShellCtx['input'] -} diff --git a/src/main/ts/zurk.ts b/src/main/ts/zurk.ts index f98c6c6..8d471a6 100644 --- a/src/main/ts/zurk.ts +++ b/src/main/ts/zurk.ts @@ -2,11 +2,16 @@ import util from 'node:util' import { invoke, normalizeCtx, - TSpawnCtxNormalized, - TSpawnResult, - TSpawnListeners, + type TSpawnCtxNormalized, + type TSpawnResult, + type TSpawnListeners, } from './spawn.js' -import { isPromiseLike, makeDeferred, type Promisified, type TVoidCallback } from './util.js' +import { + isPromiseLike, + makeDeferred, + type Promisified, + type TVoidCallback +} from './util.js' export const ZURK = Symbol('Zurk') diff --git a/src/test/js/index.test.cjs b/src/test/js/index.test.cjs index 6f18ef5..e8487ad 100644 --- a/src/test/js/index.test.cjs +++ b/src/test/js/index.test.cjs @@ -1,9 +1,13 @@ const assert = require('node:assert') const { describe, it } = require('node:test') const { $ } = require('zurk') +const { buildCmd } = require('zurk/util') describe('cjs entry', () => { it('$ is callable', () => { assert.equal(typeof $, 'function') }) + it('buildCmd is callable', () => { + assert.equal(typeof buildCmd, 'function') + }) }) diff --git a/src/test/js/index.test.mjs b/src/test/js/index.test.mjs index 0e3cfe0..c403076 100644 --- a/src/test/js/index.test.mjs +++ b/src/test/js/index.test.mjs @@ -1,9 +1,13 @@ import assert from 'node:assert' import { describe, it } from 'node:test' import { $ } from 'zurk' +import { buildCmd } from 'zurk/util' describe('mjs entry', () => { it('$ is callable', () => { assert.equal(typeof $, 'function') }) + it('buildCmd is callable', () => { + assert.equal(typeof buildCmd, 'function') + }) }) diff --git a/src/test/ts/index.test.ts b/src/test/ts/index.test.ts index 1df36ae..54541f4 100644 --- a/src/test/ts/index.test.ts +++ b/src/test/ts/index.test.ts @@ -1,6 +1,6 @@ import * as assert from 'node:assert' import { describe, it } from 'node:test' -import { invoke, zurk, $, buildCmd, exec } from '../../main/ts' +import { invoke, zurk, $, buildCmd, exec } from '../../main/ts/index.js' describe('index', () => { it('has proper exports', () => { diff --git a/src/test/ts/x.test.ts b/src/test/ts/x.test.ts index 2d00260..812190a 100644 --- a/src/test/ts/x.test.ts +++ b/src/test/ts/x.test.ts @@ -3,8 +3,8 @@ import * as fs from 'node:fs' import * as path from 'node:path' import * as os from 'node:os' import { describe, it } from 'node:test' -import { $ } from '../../main/ts/x.js' import { Stream } from 'node:stream' +import { $ } from '../../main/ts/x.js' const __dirname = new URL('.', import.meta.url).pathname const fixtures = path.resolve(__dirname, '../fixtures') diff --git a/yarn.lock b/yarn.lock index 1045292..442daf2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -296,10 +296,10 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== -"@types/node@^20.11.27": - version "20.11.27" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.27.tgz#debe5cfc8a507dd60fe2a3b4875b1604f215c2ac" - integrity sha512-qyUZfMnCg1KEz57r7pzFtSGt49f6RPkPBis3Vo4PbS7roQEDn22hiHzl/Lo1q4i4hDEgBJmBF/NTNg2XR0HbFg== +"@types/node@^20.11.28": + version "20.11.28" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.28.tgz#4fd5b2daff2e580c12316e457473d68f15ee6f66" + integrity sha512-M/GPWVS2wLkSkNHVeLkrF2fD5Lx5UC4PxA0uZcKc6QqbIQUJyW1jVjueJYi1z8n0I5PxYrtpnPnWglE+y9A0KA== dependencies: undici-types "~5.26.4" @@ -883,10 +883,10 @@ esbuild-node-externals@^1.13.0: find-up "^5.0.0" tslib "^2.4.1" -esbuild-plugin-entry-chunks@^0.1.8: - version "0.1.8" - resolved "https://registry.yarnpkg.com/esbuild-plugin-entry-chunks/-/esbuild-plugin-entry-chunks-0.1.8.tgz#66600276510c1b5a042b14cded95e9d9b74dfcb6" - integrity sha512-iKX18Uj8WTiRygwOGNa4S66pvNeexcvH1ohs/P5wV0fVGCRRzHzCiyI1/HShCVkC8HOnxvGWiG006PmsBHmS9Q== +esbuild-plugin-entry-chunks@^0.1.11: + version "0.1.11" + resolved "https://registry.yarnpkg.com/esbuild-plugin-entry-chunks/-/esbuild-plugin-entry-chunks-0.1.11.tgz#6397a0a6f50b6f319df01b56a6ea326bd3eb3dd2" + integrity sha512-lSFwPa7YYdp0iSg3ukKKlHrJ735WpsqlkfsYzUHXYhFYRHPuYaf5qkNyWulyDL7ycPlguCo/Q4ALCsi1mu6waA== dependencies: depseek "0.4.0"