Skip to content

Commit

Permalink
Replace parcel with tsup. Better types, better tsconfig. Move to ESM. (
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh authored Nov 4, 2024
1 parent bb03e8f commit ac52b6b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 57 deletions.
1 change: 1 addition & 0 deletions packages/providers/news/6468.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace `parcel` with `tsup`. Better types, better tsconfig. Move to ESM. @sneridagh
30 changes: 11 additions & 19 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@
"publishConfig": {
"access": "public"
},
"source": "./src/index.ts",
"main": "./dist/main.js",
"module": "./dist/module.mjs",
"types": "./dist/index.d.ts",
"type": "module",
"main": "./dist/index.js",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/module.mjs",
"require": "./dist/main.js"
},
"./src/*": "./src/*"
"import": "./dist/index.js",
"default": "./dist/index.cjs"
}
},
"scripts": {
"watch": "parcel watch",
"build": "parcel build",
"build:force": "rm -rf dist && parcel build --no-cache",
"build": "tsup",
"build:force": "tsup",
"check:exports": "attw --pack .",
"test": "vitest",
"dry-release": "release-it --dry-run",
"release": "release-it",
Expand All @@ -67,18 +64,13 @@
"react-aria-components": "^1.4.0"
},
"devDependencies": {
"@parcel/config-default": "^2.12.0",
"@parcel/core": "^2.12.0",
"@parcel/packager-ts": "^2.12.0",
"@parcel/transformer-js": "^2.12.0",
"@parcel/transformer-react-refresh-wrap": "^2.12.0",
"@parcel/transformer-typescript-types": "^2.12.0",
"@arethetypeswrong/cli": "^0.16.4",
"@plone/types": "workspace:*",
"@types/react": "^18",
"@types/react-dom": "^18",
"parcel": "^2.12.0",
"release-it": "17.1.1",
"tsconfig": "workspace:*",
"tsup": "^8.3.5",
"typescript": "^5.6.3",
"vitest": "^2.1.3"
}
Expand Down
9 changes: 7 additions & 2 deletions packages/providers/src/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import React, { createContext, ReactNode, useContext, useMemo } from 'react';
import React, {
createContext,
type ReactNode,
useContext,
useMemo,
} from 'react';
import { RouterProvider } from 'react-aria-components';
import { flattenToAppURL as defaultFlattenToAppURL } from './utils';

Expand All @@ -17,7 +22,7 @@ interface AppRouter {
useLocation: () => Location | undefined;
useParams: (opts?: any) => Record<string, string>;
navigate: (path: string) => void;
useHref: (to: string, options?: any) => string;
useHref?: (to: string, options?: any) => string;
flattenToAppURL: (path: string | undefined) => string | undefined;
}

Expand Down
17 changes: 10 additions & 7 deletions packages/providers/src/PloneProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import React, { createContext, ReactNode, useContext, useMemo } from 'react';
import React, {
createContext,
type ReactNode,
useContext,
useMemo,
} from 'react';
import { QueryClient } from '@tanstack/react-query';
import { AppRouterProvider, Location } from './AppRouter';
import { AppRouterProvider, type Location } from './AppRouter';
import { PloneClientProvider } from './PloneClient';
import PloneClient from '@plone/client';
import { flattenToAppURL as defaultFlattenToAppURL } from './utils';

interface PloneProvider {
ploneClient: InstanceType<typeof PloneClient>;
queryClient: QueryClient;
ploneClient?: InstanceType<typeof PloneClient>;
queryClient?: QueryClient;
useLocation: () => Location | undefined;
useParams: (opts?: any) => Record<string, string>;
navigate: (path: string) => void;
useHref: (to: string, options?: any) => string;
useHref?: (to: string, options?: any) => string;
flattenToAppURL: (path: string | undefined) => string | undefined;
}

const PloneProviderContext = createContext<PloneProvider>({
ploneClient: null,
queryClient: null,
useLocation: () => ({
href: '',
pathname: '',
Expand Down
25 changes: 23 additions & 2 deletions packages/providers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
{
"extends": "tsconfig/react-library.json",
"include": ["src", "src/**/*.js"],
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"verbatimModuleSyntax": true,

"strict": true,
"noImplicitOverride": true,

"lib": ["es2022", "dom", "dom.iterable"],
"module": "preserve",
"noEmit": true,

"jsx": "react-jsx",

"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src"],
"exclude": [
"node_modules",
"build",
Expand Down
9 changes: 9 additions & 0 deletions packages/providers/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entryPoints: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
outDir: 'dist',
clean: true,
});
45 changes: 18 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac52b6b

Please sign in to comment.