Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to jsr.io #319

Merged
merged 8 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .earthignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generate when development
node_modules/
dist/
junit/
junit/
docs/
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
git config user.email github-actions@github.com

# npm publish and push updated package.json
- name: Publish
- name: Publish to npm and jsr
run: |
npm run release -- --VERSION=$VERSION
git push origin master
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/release_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ jobs:
git config user.email github-actions@github.com

# npm publish and push updated package.json
- name: PrePublish
- name: prepublish to npm and jsr
run: |
npm run release:prepublish
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}

- name: Commit and push changes
run: |
git add package*.json
git commit -m "debug: npm run release:prepublish"
git push
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
junit/
junit/
docs/
13 changes: 11 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ prepublish:
RUN rm -rf dist
COPY +build/dist dist

# Bump package.json and jsr.json then commit the changes that mimic `npm version`
RUN npm version prerelease --no-git-tag-version && \
npm publish --provenance --tag=beta
npm run jsr:version && \
git add jsr.json package*.json && \
jq -r '.version' package.json | xargs -I {} git commit -m "{}"
RUN npm publish --provenance --tag=beta
RUN npm install && npx -y jsr publish

publish:
BUILD +integate-test
Expand All @@ -38,4 +43,8 @@ publish:
COPY +build/dist dist

RUN npm version $VERSION && \
npm publish --provenance
npm run jsr:version && \
git add jsr.json package*.json && \
jq -r '.version' package.json | xargs -I {} git commit -m "{}"
RUN npm publish --provenance
RUN npm install && npx -y jsr publish
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ts-junit2json
[![junit2json](https://badgen.net/npm/v/junit2json)](https://www.npmjs.com/package/junit2json)
[![JSR](https://jsr.io/badges/@kesin11/junit2json)](https://jsr.io/@kesin11/junit2json)
![CI](https://github.com/Kesin11/ts-junit2json/workflows/Node%20CI/badge.svg)

ts-juni2json provides a converter that convert JUnit XML format to JSON. Also provides TypeScript types definition.
Expand Down
12 changes: 12 additions & 0 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@kesin11/junit2json",
"version": "0.1.1",
"exports": "./src/index.ts",
"publish": {
"include": [
"LICENSE",
"README.md",
"src/**/*.ts"
]
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && tsconfig-to-dual-package",
"test": "jest",
"test:watch": "jest --watch",
"doc": "deno doc --unstable-byonm --unstable-sloppy-imports --html --name=junit2json src",
"doc:lint": "deno doc --unstable-byonm --unstable-sloppy-imports --lint src",
"integrate_test": "node --test integrate_tests/",
"release:prepublish": "earthly +prepublish",
"release": "earthly +publish"
"release": "earthly +publish",
"jsr:version": "jq -r '.version' package.json | xargs -I {} jq '.version = \"{}\"' jsr.json > temp.json && mv temp.json jsr.json"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import fs from 'fs'
import fs from 'node:fs'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import { parse } from './index.js'
Expand Down Expand Up @@ -38,4 +38,4 @@ const main = async () => {
const output = await parse(xmlString)
console.log(JSON.stringify(output, replacer, indent))
}
main()
main()
32 changes: 32 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parseStringPromise, processors } from 'xml2js'
import type { convertableToString, OptionsV2 } from 'xml2js'

/** It represents a `<testsuites>` tag. */
export type TestSuites = {
testsuite?: TestSuite[]
name?: string
Expand All @@ -11,6 +12,7 @@ export type TestSuites = {
disabled?: number
}

/** It represents a `<testcase>` tag. */
export type TestCase = {
name?: string
classname?: string
Expand All @@ -24,6 +26,7 @@ export type TestCase = {
"system-err"?: string[]
}

/** It represents a `<testsuite>` tag. */
export type TestSuite = {
testcase?: TestCase[]
name?: string
Expand All @@ -42,10 +45,39 @@ export type TestSuite = {
"system-err"?: string[]
}

/** It represents a `<properties>` tag. */
export type Property = { name?: string, value?: string }
/** It represents a `<skipped>` tag. */
export type Skipped = { message?: string }
/** It represents a `<failure> and <errors>` tag. */
export type Details = { message?: string, type?: string, inner?: string }

/**
* Parses the given JUnit XML string into a JavaScript object representation using xml2js library.
*
* @example Basic usage
* ```ts
* import { parse } from 'junit2json'
*
* const junitXmlString = "..."
* const output = await parse(xmlString)
* ```
*
* If you want to filter some tags like `<system-out>` or `<system-err>`, you can use `replacer` function argument in [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
*
* @example Filter some tags
* ```ts
* import { parse } from 'junit2json'
*
* const junitXmlString = "..."
* const output = await parse(xmlString)
* const replacer = (key: any, value: any) => {
* if (key === 'system-out' || key === 'system-err') return undefined
* return value
* }
* console.log(JSON.stringify(output, replacer, 2))
* ```
*/
export const parse = async (xmlString: convertableToString, xml2jsOptions?: OptionsV2): Promise<TestSuites|TestSuite|undefined|null> => {
const options = xml2jsOptions ?? {
attrValueProcessors: [processors.parseNumbers]
Expand Down
Loading