Skip to content

build(package-manager): migrate from Yarn to PNPM #149

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 19 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@ jobs:
ci:
name: Continuous integration
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 'current'
node-version: 22
cache: "pnpm"

- name: Install dependencies
run: yarn install
- name: Check build
run: yarn build
- name: Check coding standards
run: yarn lint
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build

- name: Lint
run: pnpm lint

- name: Run tests
run: yarn test
run: pnpm test
31 changes: 21 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch: ~
push:
tags:
- 'v*'
- "v*"

jobs:
release:
Expand All @@ -13,20 +13,31 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 'current'
registry-url: https://registry.npmjs.org
node-version: 22
cache: "pnpm"

- name: Install dependencies
run: yarn install
- name: Check build
run: yarn build
- name: Check coding standards
run: yarn lint
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build

- name: Lint
run: pnpm lint

- name: Run tests
run: yarn test
run: pnpm test

- name: Publish to npm
run: npm publish
run: pnpm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/lib/
/node_modules/
/yarn-error.log
53 changes: 35 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,74 @@ Using [NPM](https://www.npmjs.com/):

npm install @api-platform/api-doc-parser

Using [Pnpm](https://pnpm.io/):

pnpm add @api-platform/api-doc-parser

If you plan to use the library with Node, you also need a polyfill for the `fetch` function:

yarn add isomorphic-fetch

## Usage

**Hydra**

```javascript
import { parseHydraDocumentation } from '@api-platform/api-doc-parser';
import { parseHydraDocumentation } from "@api-platform/api-doc-parser";

parseHydraDocumentation('https://demo.api-platform.com').then(({api}) => console.log(api));
parseHydraDocumentation("https://demo.api-platform.com").then(({ api }) =>
console.log(api),
);
```

**OpenAPI v2 (formerly known as Swagger)**

```javascript
import { parseSwaggerDocumentation } from '@api-platform/api-doc-parser';
import { parseSwaggerDocumentation } from "@api-platform/api-doc-parser";

parseSwaggerDocumentation('https://demo.api-platform.com/docs.json').then(({api}) => console.log(api));
parseSwaggerDocumentation("https://demo.api-platform.com/docs.json").then(
({ api }) => console.log(api),
);
```

**OpenAPI v3**

```javascript
import { parseOpenApi3Documentation } from '@api-platform/api-doc-parser';
import { parseOpenApi3Documentation } from "@api-platform/api-doc-parser";

parseOpenApi3Documentation('https://demo.api-platform.com/docs.json?spec_version=3').then(({api}) => console.log(api));
parseOpenApi3Documentation(
"https://demo.api-platform.com/docs.json?spec_version=3",
).then(({ api }) => console.log(api));
```

**GraphQL**

```javascript
import { parseGraphQl } from '@api-platform/api-doc-parser';
import { parseGraphQl } from "@api-platform/api-doc-parser";

parseGraphQl('https://demo.api-platform.com/graphql').then(({api}) => console.log(api));
parseGraphQl("https://demo.api-platform.com/graphql").then(({ api }) =>
console.log(api),
);
```

## OpenAPI Support

In order to support OpenAPI, the library makes some assumptions about how the documentation relates to a corresponding ressource:

- The path to get (`GET`) or edit (`PUT`) one resource looks like `/books/{id}` (regular expression used: `^[^{}]+/{[^{}]+}/?$`).
Note that `books` may be a singular noun (`book`).
If there is no path like this, the library skips the resource.
Note that `books` may be a singular noun (`book`).
If there is no path like this, the library skips the resource.
- The corresponding path schema is retrieved for `get` either in the [`response` / `200` / `content` / `application/json`] path section or in the `components` section of the documentation.
If retrieved from the `components` section, the component name needs to look like `Book` (singular noun).
For `put`, the schema is only retrieved in the [`requestBody` / `content` / `application/json`] path section.
If no schema is found, the resource is skipped.
If retrieved from the `components` section, the component name needs to look like `Book` (singular noun).
For `put`, the schema is only retrieved in the [`requestBody` / `content` / `application/json`] path section.
If no schema is found, the resource is skipped.
- If there are two schemas (one for `get` and one for `put`), resource fields are merged.
- The library looks for a creation (`POST`) and list (`GET`) path. They need to look like `/books` (plural noun).
- The deletion (`DELETE`) path needs to be inside the get / edit path.
- In order to reference the resources between themselves (embeddeds or relations), the library guesses embeddeds or references from property names.
For instance if a book schema has a `reviews` property, the library tries to find a `Review` resource.
If there is, a relation or an embedded between `Book` and `Review` resources is made for the `reviews` field.
The property name can also be like `review_id`, `reviewId`, `review_ids` or `reviewIds` for references.
For instance if a book schema has a `reviews` property, the library tries to find a `Review` resource.
If there is, a relation or an embedded between `Book` and `Review` resources is made for the `reviews` field.
The property name can also be like `review_id`, `reviewId`, `review_ids` or `reviewIds` for references.
- Parameters are only retrieved in the list path.

## Support for other formats (JSON:API...)
Expand All @@ -81,8 +98,8 @@ to include it in the library.

## Run tests

yarn test
yarn lint
pnpm test
pnpm lint

## Credits

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@eslint/compat": "^1.2.5",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.19.0",
"@jest/types": "29.0.0",
"@types/inflection": "^1.13.0",
"@types/jest": "^29.0.0",
"@types/jsonld": "^1.5.0",
Expand Down Expand Up @@ -51,7 +52,7 @@
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"lint": "eslint src",
"fix": "yarn lint --fix",
"fix": "pnpm lint --fix",
"eslint-check": "eslint-config-prettier src/index.ts",
"build": "rm -rf lib/* && tsc",
"watch": "tsc --watch"
Expand All @@ -60,5 +61,5 @@
"publishConfig": {
"access": "public"
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
"packageManager": "[email protected]+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
}
Loading