Comparing version 0.0.2 to 0.1.0
import '../vendors/wasm_exec.js'; | ||
export * from './print.js'; | ||
export * from './processor.js'; | ||
export * from './types.js'; |
import '../vendors/wasm_exec.js'; | ||
export * from './print.js'; | ||
export * from './processor.js'; | ||
export * from './types.js'; | ||
//# sourceMappingURL=browser.js.map |
import './shim.js'; | ||
import '../vendors/wasm_exec.js'; | ||
export declare const print: (text: string, { filepath, keepComments, stopAt, variant, useTabs, tabWidth, indent, binaryNextLine, switchCaseIndent, spaceRedirects, keepPadding, minify, functionNextLine, }?: Partial<import("./types.js").ShOptions>) => Promise<string>; | ||
export * from './print.js'; | ||
import type { File, ShOptions } from './types.js'; | ||
export declare const processor: { | ||
(text: string, options?: ShOptions | undefined): Promise<File>; | ||
(ast: File, options?: ShOptions | undefined): Promise<string>; | ||
}; | ||
export declare const parse: (text: string, options?: ShOptions | undefined) => Promise<File>; | ||
export declare const print: (ast: File, options?: ShOptions | undefined) => Promise<string>; | ||
export * from './processor.js'; | ||
export * from './types.js'; |
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { getPrinter } from './print.js'; | ||
import './shim.js'; | ||
import '../vendors/wasm_exec.js'; | ||
import { getProcessor } from './processor.js'; | ||
/* istanbul ignore next */ | ||
@@ -11,5 +11,7 @@ const _dirname = typeof __dirname === 'undefined' | ||
: __dirname; | ||
export const print = getPrinter(() => fs.promises.readFile(path.resolve(_dirname, '../main.wasm'))); | ||
export * from './print.js'; | ||
export const processor = getProcessor(() => fs.promises.readFile(path.resolve(_dirname, '../main.wasm'))); | ||
export const parse = (text, options) => processor(text, options); | ||
export const print = (ast, options) => processor(ast, options); | ||
export * from './processor.js'; | ||
export * from './types.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -8,15 +8,68 @@ export declare enum LangVariant { | ||
export interface ShOptions { | ||
filepath: string; | ||
useTabs: boolean; | ||
tabWidth: number; | ||
keepComments: boolean; | ||
stopAt: string; | ||
variant: LangVariant; | ||
indent: number; | ||
binaryNextLine: boolean; | ||
switchCaseIndent: boolean; | ||
spaceRedirects: boolean; | ||
keepPadding: boolean; | ||
minify: boolean; | ||
functionNextLine: boolean; | ||
filepath?: string; | ||
originalText?: string; | ||
useTabs?: boolean; | ||
tabWidth?: number; | ||
keepComments?: boolean; | ||
stopAt?: string; | ||
variant?: LangVariant; | ||
indent?: number; | ||
binaryNextLine?: boolean; | ||
switchCaseIndent?: boolean; | ||
spaceRedirects?: boolean; | ||
keepPadding?: boolean; | ||
minify?: boolean; | ||
functionNextLine?: boolean; | ||
} | ||
export interface Pos { | ||
Col: number; | ||
Line: number; | ||
Offset: number; | ||
} | ||
export interface Node { | ||
Pos: Pos; | ||
End: Pos; | ||
} | ||
export interface Comment extends Node { | ||
Text: string; | ||
} | ||
export interface Word extends Node { | ||
Parts: Node[]; | ||
Lit: string; | ||
} | ||
export interface Lit extends Node { | ||
ValuePos: Pos; | ||
ValueEnd: Pos; | ||
Value: string; | ||
} | ||
export interface Redirect extends Node { | ||
OpPos: Pos; | ||
Op: string; | ||
N: Lit | null; | ||
Word: Word; | ||
Hdoc: Word | null; | ||
} | ||
export interface Stmt extends Node { | ||
Comments: Comment[]; | ||
Cmd: Node | null; | ||
Position: Pos; | ||
Semicolon: Pos; | ||
Negated: boolean; | ||
Background: boolean; | ||
Coprocess: boolean; | ||
Redirs: Redirect[]; | ||
} | ||
export interface File extends Node { | ||
Name: string; | ||
Stmts: Stmt[]; | ||
} | ||
export interface IParseError { | ||
Filename: string; | ||
Incomplete: boolean; | ||
Text: string; | ||
Pos: Pos; | ||
} | ||
export interface ParseResult { | ||
Data: File | string | null; | ||
Error: IParseError | string | null; | ||
} |
{ | ||
"name": "sh-syntax", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"type": "module", | ||
@@ -10,3 +10,3 @@ "description": "A WASM shell parser and formatter with bash support, based on mvdan/sh", | ||
"engines": { | ||
"node": ">=v12.20" | ||
"node": ">=v14" | ||
}, | ||
@@ -30,3 +30,3 @@ "exports": { | ||
"devDependencies": { | ||
"@1stg/lib-config": "^5.3.0", | ||
"@1stg/lib-config": "^5.4.0", | ||
"@changesets/changelog-github": "^0.4.4", | ||
@@ -87,3 +87,3 @@ "@changesets/cli": "^2.22.0", | ||
}, | ||
"readme": "# sh-syntax\n\n[![GitHub Actions](https://github.com/rx-ts/sh-syntax/workflows/CI/badge.svg)](https://github.com/rx-ts/sh-syntax/actions/workflows/ci.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/rx-ts/sh-syntax.svg)](https://codecov.io/gh/rx-ts/sh-syntax)\n[![Codacy Grade](https://img.shields.io/codacy/grade/1d00ac27c99d4412bb70211e258706ab)](https://app.codacy.com/gh/rx-ts/sh-syntax)\n[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Frx-ts%2Fsh-syntax%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)\n[![npm](https://img.shields.io/npm/v/sh-syntax.svg)](https://www.npmjs.com/package/sh-syntax)\n[![GitHub Release](https://img.shields.io/github/release/rx-ts/sh-syntax)](https://github.com/rx-ts/sh-syntax/releases)\n\n[![David Peer](https://img.shields.io/david/peer/rx-ts/sh-syntax.svg)](https://david-dm.org/rx-ts/sh-syntax?type=peer)\n[![David](https://img.shields.io/david/rx-ts/sh-syntax.svg)](https://david-dm.org/rx-ts/sh-syntax)\n[![David Dev](https://img.shields.io/david/dev/rx-ts/sh-syntax.svg)](https://david-dm.org/rx-ts/sh-syntax?type=dev)\n\n[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/atlassian/changesets)\n\nA WASM shell parser and formatter with bash support, based on mvdan/sh\n\n## TOC <!-- omit in toc -->\n\n- [Usage](#usage)\n - [Install](#install)\n - [API](#api)\n- [Changelog](#changelog)\n- [License](#license)\n\n## Usage\n\n### Install\n\n```sh\n# yarn\nyarn add sh-syntax\n\n# npm\nnpm i sh-syntax\n```\n\n### API\n\n```js\n// node\nimport { print } from 'sh-syntax'\n\nawait print(\"echo 'Hello World!'\")\n```\n\n```js\n// browser\nimport { getPrinter } from 'sh-syntax'\n\nconst print = getPrinter(() =>\n fetch('path/to/main.wasm').then(res => res.arrayBuffer()),\n)\nawait print(\"echo 'Hello World!'\")\n```\n\n## Changelog\n\nDetailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).\n\n## License\n\n[MIT][] © [JounQin][]@[1stG.me][]\n\n[1stg.me]: https://www.1stg.me\n[jounqin]: https://GitHub.com/JounQin\n[mit]: http://opensource.org/licenses/MIT\n" | ||
"readme": "# sh-syntax\n\n[![GitHub Actions](https://github.com/rx-ts/sh-syntax/workflows/CI/badge.svg)](https://github.com/rx-ts/sh-syntax/actions/workflows/ci.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/rx-ts/sh-syntax.svg)](https://codecov.io/gh/rx-ts/sh-syntax)\n[![Codacy Grade](https://img.shields.io/codacy/grade/1d00ac27c99d4412bb70211e258706ab)](https://app.codacy.com/gh/rx-ts/sh-syntax)\n[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Frx-ts%2Fsh-syntax%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)\n[![npm](https://img.shields.io/npm/v/sh-syntax.svg)](https://www.npmjs.com/package/sh-syntax)\n[![GitHub Release](https://img.shields.io/github/release/rx-ts/sh-syntax)](https://github.com/rx-ts/sh-syntax/releases)\n\n[![David Peer](https://img.shields.io/david/peer/rx-ts/sh-syntax.svg)](https://david-dm.org/rx-ts/sh-syntax?type=peer)\n[![David](https://img.shields.io/david/rx-ts/sh-syntax.svg)](https://david-dm.org/rx-ts/sh-syntax)\n[![David Dev](https://img.shields.io/david/dev/rx-ts/sh-syntax.svg)](https://david-dm.org/rx-ts/sh-syntax?type=dev)\n\n[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/atlassian/changesets)\n\nA WASM shell parser and formatter with bash support, based on mvdan/sh\n\n## TOC <!-- omit in toc -->\n\n- [Usage](#usage)\n - [Install](#install)\n - [API](#api)\n- [Changelog](#changelog)\n- [License](#license)\n\n## Usage\n\n### Install\n\n```sh\n# yarn\nyarn add sh-syntax\n\n# npm\nnpm i sh-syntax\n```\n\n### API\n\n```js\n// node\nimport { parse, print } from 'sh-syntax'\n\nconst text = \"echo 'Hello World!'\"\nconst ast = await parse(text)\nconst newText = await print(ast, {\n // `originalText` is required for now, hope we will find better solution later\n originalText: text,\n})\n```\n\n```js\n// browser\nimport { getProcessor } from 'sh-syntax'\n\nconst processor = getProcessor(() =>\n fetch('path/to/main.wasm').then(res => res.arrayBuffer()),\n)\n\nconst parse = (text, options) => processor(text, options)\n\nconst print = (ast, options) => processor(ast, options)\n\n// just like node again\nconst text = \"echo 'Hello World!'\"\nconst ast = await parse(text)\nconst newText = await print(ast, { originalText: text })\n```\n\n## Changelog\n\nDetailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).\n\n## License\n\n[MIT][] © [JounQin][]@[1stG.me][]\n\n[1stg.me]: https://www.1stg.me\n[jounqin]: https://GitHub.com/JounQin\n[mit]: http://opensource.org/licenses/MIT\n" | ||
} |
@@ -46,5 +46,10 @@ # sh-syntax | ||
// node | ||
import { print } from 'sh-syntax' | ||
import { parse, print } from 'sh-syntax' | ||
await print("echo 'Hello World!'") | ||
const text = "echo 'Hello World!'" | ||
const ast = await parse(text) | ||
const newText = await print(ast, { | ||
// `originalText` is required for now, hope we will find better solution later | ||
originalText: text, | ||
}) | ||
``` | ||
@@ -54,8 +59,16 @@ | ||
// browser | ||
import { getPrinter } from 'sh-syntax' | ||
import { getProcessor } from 'sh-syntax' | ||
const print = getPrinter(() => | ||
const processor = getProcessor(() => | ||
fetch('path/to/main.wasm').then(res => res.arrayBuffer()), | ||
) | ||
await print("echo 'Hello World!'") | ||
const parse = (text, options) => processor(text, options) | ||
const print = (ast, options) => processor(ast, options) | ||
// just like node again | ||
const text = "echo 'Hello World!'" | ||
const ast = await parse(text) | ||
const newText = await print(ast, { originalText: text }) | ||
``` | ||
@@ -62,0 +75,0 @@ |
import _fs from 'fs' | ||
import type { IParseError, ParseResult } from 'sh-syntax' | ||
declare global { | ||
@@ -8,21 +10,3 @@ namespace globalThis { | ||
class Go { | ||
static __shProcessing: Record< | ||
number, | ||
| { | ||
error: | ||
| string | ||
| { | ||
filename: string | ||
incomplete: boolean | ||
text: string | ||
pos: { | ||
col: number | ||
line: number | ||
offset: number | ||
} | ||
message: string | ||
} | ||
} | ||
| { text: string } | ||
> | ||
static readonly __shProcessing: Record<string, ParseResult> | ||
@@ -29,0 +13,0 @@ _pendingEvent: { id: number } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2972961
1402
85