fix: change back to loading from literal ".zenstack" path otherwise Vercel breaks :( (#701)

This commit is contained in:
Yiming 2023-09-18 20:59:45 -07:00 committed by GitHub
parent cc6f286f2e
commit 2d41a9fcff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 35 additions and 25 deletions

View file

@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "",
"scripts": {
"build": "pnpm -r build",

View file

@ -1,6 +1,6 @@
{
"name": "@zenstackhq/language",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",

View file

@ -1,7 +1,7 @@
{
"name": "@zenstackhq/openapi",
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {

View file

@ -1,7 +1,7 @@
{
"name": "@zenstackhq/swr",
"displayName": "ZenStack plugin for generating SWR hooks",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "ZenStack plugin for generating SWR hooks",
"main": "index.js",
"repository": {

View file

@ -1,7 +1,7 @@
{
"name": "@zenstackhq/tanstack-query",
"displayName": "ZenStack plugin for generating tanstack-query hooks",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "ZenStack plugin for generating tanstack-query hooks",
"main": "index.js",
"exports": {

View file

@ -1,7 +1,7 @@
{
"name": "@zenstackhq/trpc",
"displayName": "ZenStack plugin for tRPC",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {

View file

@ -1,7 +1,7 @@
{
"name": "@zenstackhq/runtime",
"displayName": "ZenStack Runtime Library",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",

View file

@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import path from 'path';
import { DEFAULT_RUNTIME_LOAD_PATH } from './constants';
import { ModelMeta, PolicyDef, ZodSchemas } from './enhancements';
/**
@ -10,15 +9,18 @@ import { ModelMeta, PolicyDef, ZodSchemas } from './enhancements';
* will use default load path.
*/
export function getDefaultModelMeta(loadPath: string | undefined): ModelMeta {
const toLoad = loadPath ? path.resolve(loadPath, 'model-meta') : `${DEFAULT_RUNTIME_LOAD_PATH}/model-meta`;
try {
// normal load
return require(toLoad).default;
if (loadPath) {
const toLoad = path.resolve(loadPath, 'model-meta');
return require(toLoad).default;
} else {
return require('.zenstack/model-meta').default;
}
} catch {
if (process.env.ZENSTACK_TEST === '1' && !path.isAbsolute(toLoad)) {
if (process.env.ZENSTACK_TEST === '1' && !loadPath) {
try {
// special handling for running as tests, try resolving relative to CWD
return require(path.join(process.cwd(), 'node_modules', toLoad)).default;
return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'model-meta')).default;
} catch {
throw new Error('Model meta cannot be loaded. Please make sure "zenstack generate" has been run.');
}
@ -34,14 +36,18 @@ export function getDefaultModelMeta(loadPath: string | undefined): ModelMeta {
* will use default load path.
*/
export function getDefaultPolicy(loadPath: string | undefined): PolicyDef {
const toLoad = loadPath ? path.resolve(loadPath, 'policy') : `${DEFAULT_RUNTIME_LOAD_PATH}/policy`;
try {
return require(toLoad).default;
if (loadPath) {
const toLoad = path.resolve(loadPath, 'policy');
return require(toLoad).default;
} else {
return require('.zenstack/policy').default;
}
} catch {
if (process.env.ZENSTACK_TEST === '1' && !path.isAbsolute(toLoad)) {
if (process.env.ZENSTACK_TEST === '1' && !loadPath) {
try {
// special handling for running as tests, try resolving relative to CWD
return require(path.join(process.cwd(), 'node_modules', toLoad)).default;
return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'policy')).default;
} catch {
throw new Error(
'Policy definition cannot be loaded from default location. Please make sure "zenstack generate" has been run.'
@ -61,14 +67,18 @@ export function getDefaultPolicy(loadPath: string | undefined): PolicyDef {
* will use default load path.
*/
export function getDefaultZodSchemas(loadPath: string | undefined): ZodSchemas | undefined {
const toLoad = loadPath ? path.resolve(loadPath, 'zod') : `${DEFAULT_RUNTIME_LOAD_PATH}/zod`;
try {
return require(toLoad);
if (loadPath) {
const toLoad = path.resolve(loadPath, 'zod');
return require(toLoad);
} else {
return require('.zenstack/zod');
}
} catch {
if (process.env.ZENSTACK_TEST === '1' && !path.isAbsolute(toLoad)) {
if (process.env.ZENSTACK_TEST === '1' && !loadPath) {
try {
// special handling for running as tests, try resolving relative to CWD
return require(path.join(process.cwd(), 'node_modules', toLoad));
return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'zod'));
} catch {
return undefined;
}

View file

@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack Language Tools",
"description": "A toolkit for building secure CRUD apps with Next.js + Typescript",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"author": {
"name": "ZenStack Team"
},

View file

@ -1,6 +1,6 @@
{
"name": "@zenstackhq/sdk",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "ZenStack plugin development SDK",
"main": "index.js",
"scripts": {

View file

@ -1,6 +1,6 @@
{
"name": "@zenstackhq/server",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"displayName": "ZenStack Server-side Adapters",
"description": "ZenStack server-side adapters",
"homepage": "https://zenstack.dev",

View file

@ -1,6 +1,6 @@
{
"name": "@zenstackhq/testtools",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "ZenStack Test Tools",
"main": "index.js",
"publishConfig": {