Skip to content

fix: generate both cjs and esm builds for swr plugin #892

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

Merged
merged 2 commits into from
Dec 14, 2023
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
18 changes: 16 additions & 2 deletions packages/plugins/swr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"scripts": {
"clean": "rimraf dist",
"build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && copyfiles ./package.json ./README.md ./LICENSE dist && pnpm pack dist --pack-destination '../../../../.build'",
"watch": "tsc --watch",
"build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && tsup-node --config ./tsup.config.ts && copyfiles ./package.json ./README.md ./LICENSE dist && pnpm pack dist --pack-destination '../../../../.build'",
"watch": "concurrently \"tsc --watch\" \"tsup-node --config ./tsup.config.ts --watch\"",
"lint": "eslint src --ext ts",
"test": "ZENSTACK_TEST=1 jest",
"prepublishOnly": "pnpm build"
Expand All @@ -23,6 +23,20 @@
"keywords": [],
"author": "ZenStack Team",
"license": "MIT",
"exports": {
".": {
"default": "./index.js"
},
"./package.json": {
"default": "./package.json"
},
"./runtime": {
"types": "./runtime/index.d.ts",
"import": "./runtime/index.mjs",
"require": "./runtime/index.js",
"default": "./runtime/index.js"
}
},
"dependencies": {
"@prisma/generator-helper": "^5.0.0",
"@zenstackhq/runtime": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/swr/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"outDir": "dist",
"jsx": "react"
},
"include": ["src/**/*.ts"]
"include": ["src/**/*.ts"],
"exclude": ["src/runtime"]
}
11 changes: 11 additions & 0 deletions packages/plugins/swr/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/runtime/index.ts'],
outDir: 'dist/runtime',
splitting: false,
sourcemap: true,
clean: true,
dts: true,
format: ['cjs', 'esm'],
});
1 change: 0 additions & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"author": "",
"license": "MIT",
"dependencies": {
"@zenstackhq/openapi": "workspace:*",
"@zenstackhq/runtime": "workspace:*",
"change-case": "^4.1.2",
"lower-case-first": "^2.0.2",
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

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

12 changes: 12 additions & 0 deletions tests/integration/tests/frameworks/nextjs/generation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ describe('SWR Hooks Generation Tests', () => {
process.chdir(origDir);
});

// deps
const ver = require('../../../../../package.json').version;
const depPkgs = [
`${path.join(__dirname, '../../../../../.build/zenstackhq-language-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../../.build/zenstackhq-sdk-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../../.build/zenstackhq-runtime-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../../.build/zenstackhq-swr-' + ver + '.tgz')}`,
];
const deps = depPkgs.join(' ');

it('sqlite', async () => {
const testDir = path.join(__dirname, './test-run/sqlite');
if (fs.existsSync(testDir)) {
Expand All @@ -25,6 +35,7 @@ describe('SWR Hooks Generation Tests', () => {
process.chdir(testDir);
const nodePath = path.join(testDir, 'node_modules');
run('npm install');
run('npm install ' + deps);
run('npx zenstack generate --schema ./sqlite.zmodel', { NODE_PATH: nodePath });
run('npm run build', { NODE_PATH: nodePath });
});
Expand All @@ -40,6 +51,7 @@ describe('SWR Hooks Generation Tests', () => {
process.chdir(testDir);
const nodePath = path.join(testDir, 'node_modules');
run('npm install');
run('npm install ' + deps);
run('npx zenstack generate --schema ./postgres.zmodel', { NODE_PATH: nodePath });
run('npm run build', { NODE_PATH: nodePath });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"@types/node": "18.11.18",
"@types/react": "18.0.27",
"@types/react-dom": "18.0.10",
"@zenstackhq/runtime": "../../../../../../../packages/runtime/dist",
"@zenstackhq/swr": "../../../../../../../packages/plugins/swr/dist",
"next": "13.1.4",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/tests/frameworks/trpc/generation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ describe('tRPC Routers Generation Tests', () => {
process.chdir(origDir);
});

// deps
const ver = require('../../../../../package.json').version;
const depPkgs = [
`${path.join(__dirname, '../../../../../.build/zenstackhq-language-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../../.build/zenstackhq-sdk-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../../.build/zenstackhq-runtime-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../../.build/zenstackhq-trpc-' + ver + '.tgz')}`,
];
const deps = depPkgs.join(' ');

it('basic', async () => {
const testDir = path.join(__dirname, './test-run/basic');
if (fs.existsSync(testDir)) {
Expand All @@ -24,6 +34,7 @@ describe('tRPC Routers Generation Tests', () => {

process.chdir(testDir);
run('npm install');
run('npm install ' + deps);
run('npx zenstack generate --no-dependency-check --schema ./todo.zmodel', { NODE_PATH: 'node_modules' });
run('npm run build', { NODE_PATH: 'node_modules' });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
"react-dom": "18.2.0",
"superjson": "^1.12.2",
"typescript": "4.9.4",
"zod": "^3.22.4",
"@zenstackhq/runtime": "../../../../../../../packages/runtime/dist"
"zod": "^3.22.4"
},
"devDependencies": {
"prisma": "^4.8.0",
"zenstack": "../../../../../../../packages/schema/dist",
"@zenstackhq/trpc": "../../../../../../../packages/plugins/trpc/dist"
"prisma": "^4.8.0"
}
}