Skip to content

Commit

Permalink
chore: initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
knightedcodemonkey committed Jun 1, 2024
0 parents commit 641358c
Show file tree
Hide file tree
Showing 15 changed files with 4,014 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
name: CI
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Node
uses: actions/[email protected]
with:
node-version: '20.11.0'
- name: Install Dependencies
run: npm ci
- name: Save error log
uses: actions/[email protected]
if: ${{ failure() }}
with:
name: npm-debug-log-${{ hashFiles('package-lock.json') }}
path: npm-debug.log
- name: Lint
run: npm run lint
- name: Test
run: npm test
- name: Report Coverage
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Pack
run: npm pack
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish

on:
release:
types: [published]

jobs:
publish:
if: contains('["knightedcodemonkey"]', github.actor)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Node
uses: actions/[email protected]
with:
node-version: '20.11.0'
- name: Install Dependencies
run: npm ci
- name: Save error log
uses: actions/[email protected]
if: ${{ failure() }}
with:
name: npm-debug-log-${{ hashFiles('package-lock.json') }}
path: npm-debug.log
- name: Lint
run: npm run lint
- name: Test
run: npm test
- name: Pack
run: npm pack
- name: Push to NPM registry
uses: JS-DevTools/[email protected]
with:
token: ${{ secrets.NPM_AUTH_TOKEN }}
access: public
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
coverage
dist
*.tgz
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 KCM

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# [`@knighted/reparse`](https://www.npmjs.com/package/@knighted/reparse)

![CI](https://github.com/knightedcodemonkey/reparse/actions/workflows/ci.yml/badge.svg)
[![codecov](https://codecov.io/gh/knightedcodemonkey/reparse/graph/badge.svg?token=YCGi65lsmO)](https://codecov.io/gh/knightedcodemonkey/reparse)
[![NPM version](https://img.shields.io/npm/v/@knighted/reparse.svg)](https://www.npmjs.com/package/@knighted/reparse)

Multiple SWC parsings of the same file with correct spans.

Provides a workaround for [swc/1366](https://github.com/swc-project/swc/issues/1366).

## Requirements

- Node >= 20.11.0

## Example

```js
import assert from 'node:assert/strict'
import { reparse } from '@knighted/reparse'

const ast1 = await reparse('const foo = "bar"')
const ast2 = await reparse('const foo = "bar"')

assert.equal(ast1.span.start, ast2.span.start)
assert.equal(ast1.span.end, ast2.span.end)
```

You can also pass a file to `reparseFile`.

## Notes

This package makes use of [`child_process.fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options) for each invokation of `reparse()`. Thus it makes use of a promise to resolve the response from the forked child process which does the parsing, so the functions provided from `@knighted/reparse` are both async.

If you are consuming this package from CommonJS you need to wrap calls to `reparse` and `reparseFile` in an `async` function since top level await is not available.

```js
const { reparse } = require('@knighted/reparse')
const doReparse = async () => {
const ast = await reparse('const foo = "bar"')
}

doReparse()
```
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: 80.0
threshold: 0.5
patch:
default:
target: 80.0
threshold: 5.0
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import nodePlugin from 'eslint-plugin-n'

export default tseslint.config(
eslint.configs.recommended,
nodePlugin.configs['flat/recommended'],
...tseslint.configs.recommended,
{
rules: {
'no-console': 'error',
},
},
)
Loading

0 comments on commit 641358c

Please sign in to comment.