Skip to content

Commit

Permalink
fix: relative entrypoint (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoulain authored Sep 5, 2022
1 parent 7ba9a6a commit 255dc62
Show file tree
Hide file tree
Showing 17 changed files with 412 additions and 287 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: 'current'
- name: Install dependencies
run: yarn install
- name: Check build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: 'current'
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: yarn install
Expand Down
10 changes: 9 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
preset: 'ts-jest',
preset: 'ts-jest/presets/default-esm',
setupFilesAfterEnv: ['./jest.setup.ts'],
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['/node_modules/', '/lib/'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
},
],
},
};

export default config;
32 changes: 20 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@
"lib",
"src"
],
"main": "lib/cjs/index",
"module": "lib/esm/index",
"type": "module",
"exports": {
".": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
}
},
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"repository": "api-platform/admin",
"homepage": "https://github.com/api-platform/admin",
"bugs": "https://github.com/api-platform/admin/issues",
"author": "Kévin Dunglas",
"license": "MIT",
"sideEffects": false,
"dependencies": {
"@api-platform/api-doc-parser": "^0.15.1",
"@api-platform/api-doc-parser": "^0.15.4",
"history": "^5.0.0",
"jsonld": "^5.2.0",
"jsonld": "^8.1.0",
"lodash.isplainobject": "^4.0.6",
"prop-types": "^15.6.2",
"react-admin": "^4.0.3",
Expand All @@ -29,7 +36,7 @@
"@testing-library/jest-dom": "^5.16.0",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^14.0.0",
"@types/jest": "^27.4.0",
"@types/jest": "^29.0.0",
"@types/jsonld": "^1.5.0",
"@types/lodash.isplainobject": "^4.0.0",
"@types/react-test-renderer": "^18.0.0",
Expand All @@ -41,19 +48,20 @@
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.0",
"eslint-plugin-markdown": "^2.1.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.12.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-tree-shaking": "^1.10.0",
"jest": "^28.0.0",
"jest-environment-jsdom": "^28.1.0",
"jest": "^29.0.0",
"jest-environment-jsdom": "^29.0.0",
"node-fetch": "^3.2.10",
"prettier": "^2.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-test-renderer": "^18.0.0",
"rimraf": "^3.0.0",
"ts-jest": "^28.0.0",
"ts-jest": "^29.0.0-next.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.0"
},
Expand All @@ -63,11 +71,11 @@
},
"scripts": {
"build": "rimraf ./lib && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
"eslint-check": "eslint-config-prettier .eslintrc.js",
"eslint-check": "eslint-config-prettier .eslintrc.cjs",
"fix": "eslint --ignore-pattern 'lib/*' --ext .ts,.tsx,.js,.md --fix .",
"lint": "eslint --ignore-pattern 'lib/*' --ext .ts,.tsx,.js,.md .",
"test": "jest src",
"test:watch": "jest --watch src",
"test": "NODE_OPTIONS=--experimental-vm-modules jest src",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch src",
"watch": "tsc --watch"
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions src/AdminGuesser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { createRenderer } from 'react-test-renderer/shallow';
import ReactTestRenderer from 'react-test-renderer/shallow';
import { AdminResourcesGuesser } from './AdminGuesser';
import ResourceGuesser from './ResourceGuesser';
import resources from './__fixtures__/resources';
Expand Down Expand Up @@ -29,7 +29,7 @@ const dataProvider: ApiPlatformAdminDataProvider = {
};

describe('<AdminGuesser />', () => {
const renderer = createRenderer();
const renderer = ReactTestRenderer.createRenderer();

test('renders loading', () => {
renderer.render(
Expand Down
4 changes: 2 additions & 2 deletions src/ResourceGuesser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { createRenderer } from 'react-test-renderer/shallow';
import ReactTestRenderer from 'react-test-renderer/shallow';
import ResourceGuesser from './ResourceGuesser';

describe('<ResourceGuesser />', () => {
const renderer = createRenderer();
const renderer = ReactTestRenderer.createRenderer();

test('renders with create', () => {
const CustomCreate = () => null;
Expand Down
18 changes: 9 additions & 9 deletions src/__snapshots__/AdminGuesser.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`<AdminGuesser /> renders loading 1`] = `
exports[`<AdminGuesser /> renders with custom resources 1`] = `
<Admin
dataProvider={
Object {
{
"create": [Function],
"delete": [Function],
"deleteMany": [Function],
Expand All @@ -26,15 +26,15 @@ exports[`<AdminGuesser /> renders with custom resources 1`] = `
}
}
i18nProvider={
Object {
{
"changeLocale": [Function],
"getLocale": [Function],
"translate": [Function],
}
}
loading={[Function]}
store={
Object {
{
"getItem": [Function],
"removeItem": [Function],
"reset": [Function],
Expand All @@ -54,7 +54,7 @@ exports[`<AdminGuesser /> renders with custom resources 1`] = `
exports[`<AdminGuesser /> renders without custom resources 1`] = `
<Admin
dataProvider={
Object {
{
"create": [Function],
"delete": [Function],
"deleteMany": [Function],
Expand All @@ -70,15 +70,15 @@ exports[`<AdminGuesser /> renders without custom resources 1`] = `
}
}
i18nProvider={
Object {
{
"changeLocale": [Function],
"getLocale": [Function],
"translate": [Function],
}
}
loading={[Function]}
store={
Object {
{
"getItem": [Function],
"removeItem": [Function],
"reset": [Function],
Expand All @@ -98,7 +98,7 @@ exports[`<AdminGuesser /> renders without custom resources 1`] = `
exports[`<AdminGuesser /> renders without data 1`] = `
<Admin
dataProvider={
Object {
{
"create": [Function],
"delete": [Function],
"deleteMany": [Function],
Expand All @@ -114,15 +114,15 @@ exports[`<AdminGuesser /> renders without data 1`] = `
}
}
i18nProvider={
Object {
{
"changeLocale": [Function],
"getLocale": [Function],
"translate": [Function],
}
}
loading={[Function]}
store={
Object {
{
"getItem": [Function],
"removeItem": [Function],
"reset": [Function],
Expand Down
6 changes: 4 additions & 2 deletions src/dataProvider/adminDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export default (
factoryParams: Required<ApiPlatformAdminDataProviderFactoryParams>,
) => {
const { entrypoint, docEntrypoint, apiDocumentationParser } = factoryParams;
const entrypointUrl = new URL(entrypoint, window.location.href);
const docEntrypointUrl = new URL(docEntrypoint, window.location.href);
const mercure: MercureOptions | null = factoryParams.mercure
? {
hub: null,
jwt: null,
topicUrl: entrypoint,
topicUrl: entrypointUrl,
...(factoryParams.mercure === true ? {} : factoryParams.mercure),
}
: null;
Expand All @@ -27,7 +29,7 @@ export default (
introspect: (_resource = '', _params = {}) =>
apiSchema
? Promise.resolve({ data: apiSchema })
: apiDocumentationParser(docEntrypoint)
: apiDocumentationParser(docEntrypointUrl.toString())
.then(({ api }: ApiDocumentationParserResponse) => {
if (api.resources && api.resources.length > 0) {
apiSchema = { ...api, resources: api.resources };
Expand Down
Loading

0 comments on commit 255dc62

Please sign in to comment.