Skip to content

Commit

Permalink
refactor(tsup): update script options (#1370)
Browse files Browse the repository at this point in the history
# Overview

details:
#1338 (comment)

- Standardized tsup script options.
- Narrowed down the utils folder in react-query and codemods. (The
react-query project structure has been updated accordingly.)
- I verified that it works correctly locally using pnpm pack.

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
  • Loading branch information
gwansikk authored Nov 23, 2024
1 parent 800ba8f commit 390e82d
Show file tree
Hide file tree
Showing 21 changed files with 30 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .changeset/few-boats-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@suspensive/codemods": patch
"@suspensive/react-query": patch
---

refactor(tsup): update script options
9 changes: 4 additions & 5 deletions configs/tsup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export const options: Options = {
}

export const scriptOptions: Options = {
format: ['cjs'],
target: ['chrome51', 'firefox53', 'edge18', 'safari11', 'ios11', 'opera38', 'es6', 'node14'],
entry: ['src/scripts/*.{ts,tsx}', '!**/*.{spec,test,test-d,bench}.*'],
outDir: 'dist/scripts',
sourcemap: true,
format: 'cjs',
target: ['node18'],
entry: ['src/bin/*.{ts,tsx}', '!**/*.{spec,test,test-d,bench}.*'],
outDir: 'dist/bin',
}
1 change: 1 addition & 0 deletions packages/codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"devDependencies": {
"@suspensive/eslint-config": "workspace:*",
"@suspensive/tsconfig": "workspace:*",
"@suspensive/tsup": "workspace:*",
"@types/jscodeshift": "^0.12.0",
"@types/prompts": "^2.4.9"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/src/transforms/tanstack-query-import.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FileInfo } from 'jscodeshift'
import { createParserFromPath } from '../utils/createParserFromPath'
import { createParserFromPath } from './utils/createParserFromPath'

const IMPORT_TO_CHANGE = [
'useSuspenseQuery',
Expand Down
9 changes: 3 additions & 6 deletions packages/codemods/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { scriptOptions } from '@suspensive/tsup'
import { defineConfig } from 'tsup'

export default defineConfig([
{
format: 'cjs',
target: ['node18'],
entry: ['src/bin/*.{ts,tsx}', '!**/*.{spec,test,test-d,bench}.*'],
outDir: 'dist/bin',
...scriptOptions,
external: ['.bin/jscodeshift'],
},
{
format: 'cjs',
target: ['node18'],
...scriptOptions,
entry: ['src/transforms/*.{ts,tsx}', '!**/*.{spec,test,test-d,bench}.*'],
outDir: 'dist/transforms',
},
Expand Down
7 changes: 3 additions & 4 deletions packages/react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"module": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"suspensive-react-query": "dist/scripts/cli.cjs",
"srq": "dist/scripts/cli.cjs"
"suspensive-react-query": "dist/bin/cli.cjs",
"srq": "dist/bin/cli.cjs"
},
"files": [
"dist",
Expand All @@ -50,7 +50,7 @@
"ci:test": "vitest run --coverage --typecheck",
"ci:type": "tsc --noEmit",
"clean": "rimraf ./dist && rimraf ./coverage",
"postinstall": "node -e \"import('./dist/scripts/postinstall.cjs').catch(e => console.error(e))\"",
"postinstall": "node ./dist/bin/postinstall.cjs || echo 'please reinstall @suspensive/react-query'",
"prepack": "pnpm build",
"test:ui": "vitest --ui --coverage --typecheck"
},
Expand All @@ -66,7 +66,6 @@
"@suspensive/react": "workspace:*",
"@suspensive/tsconfig": "workspace:*",
"@suspensive/tsup": "workspace:*",
"@tanstack/react-query": "catalog:react-query4",
"@types/react": "catalog:react18",
"react": "catalog:react18"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import packageJson from '../../package.json'
import { getTanStackReactQueryPackageJson } from './utils/package'
import { getStatusTable } from './utils/table'

const cliPath = path.resolve(__dirname, '../../dist/scripts/cli.cjs')
const cliPath = path.resolve(__dirname, '../../dist/bin/cli.cjs')

describe('cli', () => {
it('should display the correct version when using the -v flag', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#!/usr/bin/env node
'use strict'

import { Command } from '@commander-js/extra-typings'
import { fixAction, statusAction, switchAction } from './utils/commands'
import { getPackageJson } from './utils/package'

const packageJson = getPackageJson()
const program = new Command()
const program = new Command(packageJson.name)

program
.name(packageJson.name)
.description(packageJson.description)
.version(packageJson.version, '-v, --version', 'Displays the currently installed version of @suspensive/react-query')

program
.command('status')
.description('Checks compatibility with the currently used version of @tanstack/react-query')
.action(() => statusAction())
.action(statusAction)

program
.command('switch')
Expand All @@ -34,6 +32,6 @@ program
.description(
"Automatically switch @suspensive/react-query's exports to use compatible Suspensive interfaces for @tanstack/react-query"
)
.action(() => fixAction())
.action(fixAction)

program.parse()
program.parse(process.argv)
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 7 additions & 4 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 390e82d

Please sign in to comment.