Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat(plugin-infra): add package.json schema (#3456)

Alex Yangf79733e5df9e
diff --git a/packages/cli/src/bin/dev-plugin.ts b/packages/cli/src/bin/dev-plugin.ts
index ebb7d92736..d714b1b1b4 100644
--- a/packages/cli/src/bin/dev-plugin.ts
+++ b/packages/cli/src/bin/dev-plugin.ts
@@ -3,10 +3,14 @@ import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { parseArgs } from 'node:util';
+import {
+ packageJsonInputSchema,
+ packageJsonOutputSchema,
+} from '@toeverything/plugin-infra/type';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import react from '@vitejs/plugin-react-swc';
import { build } from 'vite';
-import { z } from 'zod';
+import type { z } from 'zod';
import { projectRoot } from '../config/index.js';
@@ -34,17 +38,6 @@ if (typeof plugin !== 'string') {
const isWatch = result.values.watch;
ok(typeof isWatch === 'boolean');
-const packageJsonSchema = z.object({
- name: z.string(),
- affinePlugin: z.object({
- release: z.boolean(),
- entry: z.object({
- core: z.string(),
- server: z.string().optional(),
- }),
- }),
-});
-
const external = [
// built-in packages
/^@affine/,
@@ -71,7 +64,7 @@ const getPluginDir = (plugin: string) => path.resolve(allPluginDir, plugin);
const pluginDir = getPluginDir(plugin);
const packageJsonFile = path.resolve(pluginDir, 'package.json');
-const json: z.infer<typeof packageJsonSchema> = await readFile(
+const json: z.infer<typeof packageJsonInputSchema> = await readFile(
packageJsonFile,
{
encoding: 'utf-8',
@@ -79,7 +72,7 @@ const json: z.infer<typeof packageJsonSchema> = await readFile(
)
.then(text => JSON.parse(text))
.then(async json => {
- const { success } = await packageJsonSchema.safeParseAsync(json);
+ const { success } = await packageJsonInputSchema.safeParseAsync(json);
if (success) {
return json;
} else {
@@ -163,6 +156,8 @@ await build({
async generateBundle() {
const packageJson = {
name: json.name,
+ version: json.version,
+ description: json.description,
affinePlugin: {
release: json.affinePlugin.release,
entry: {
@@ -171,6 +166,7 @@ await build({
assets: [...metadata.assets],
},
};
+ packageJsonOutputSchema.parse(packageJson);
this.emitFile({
type: 'asset',
fileName: 'package.json',
diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json
index 28a168b32d..718b013154 100644
--- a/packages/cli/tsconfig.json
+++ b/packages/cli/tsconfig.json
@@ -3,8 +3,13 @@
"compilerOptions": {
"composite": true,
"module": "ESNext",
- "moduleResolution": "Node16",
+ "moduleResolution": "Node",
"outDir": "lib"
},
- "include": ["src/bin", "src"]
+ "include": ["src"],
+ "references": [
+ {
+ "path": "../plugin-infra"
+ }
+ ]
}
diff --git a/packages/plugin-infra/package.json b/packages/plugin-infra/package.json
index a18fbff516..9073d72ee7 100644
--- a/packages/plugin-infra/package.json
+++ b/packages/plugin-infra/package.json
@@ -10,27 +10,27 @@
],
"exports": {
"./entry": {
- "type": "./dist/entry.d.ts",
+ "type": "./dist/src/entry.d.ts",
"import": "./dist/entry.js",
"require": "./dist/entry.cjs"
},
"./atom": {
- "type": "./dist/atom.d.ts",
+ "type": "./dist/src/atom.d.ts",
"import": "./dist/atom.js",
"require": "./dist/atom.cjs"
},
"./type": {
- "type": "./dist/type.d.ts",
+ "type": "./dist/src/type.d.ts",
"import": "./dist/type.js",
"require": "./dist/type.cjs"
},
"./__internal__/workspace": {
- "type": "./dist/__internal__/workspace.d.ts",
+ "type": "./dist/src/__internal__/workspace.d.ts",
"import": "./dist/__internal__/workspace.js",
"require": "./dist/__internal__/workspace.cjs"
},
"./__internal__/react": {
- "type": "./dist/__internal__/react.d.ts",
+ "type": "./dist/src/__internal__/react.d.ts",
"import": "./dist/__internal__/react.js",
"require": "./dist/__internal__/react.cjs"
}
@@ -38,7 +38,8 @@
"dependencies": {
"@blocksuite/global": "0.0.0-20230729011742-613f3782-nightly",
"@blocksuite/store": "0.0.0-20230729011742-613f3782-nightly",
- "jotai": "^2.2.2"
+ "jotai": "^2.2.2",
+ "zod": "^3.21.4"
},
"devDependencies": {
"@blocksuite/blocks": "0.0.0-20230729011742-613f3782-nightly",
diff --git a/packages/plugin-infra/src/__internal__/react.ts b/packages/plugin-infra/src/__internal__/react.ts
index fa926723a3..f46c5e8d2c 100644
--- a/packages/plugin-infra/src/__internal__/react.ts
+++ b/packages/plugin-infra/src/__internal__/react.ts
@@ -6,7 +6,7 @@ import { useEffect } from 'react';
import {
getActiveBlockSuiteWorkspaceAtom,
workspacePassiveEffectWeakMap,
-} from './workspace';
+} from './workspace.js';
export function useStaticBlockSuiteWorkspace(id: string): Workspace {
return useAtomValue(getActiveBlockSuiteWorkspaceAtom(id));
diff --git a/packages/plugin-infra/src/__tests__/use-block-suite-workspace.spec.ts b/packages/plugin-infra/src/__tests__/use-block-suite-workspace.spec.ts
index 87aa31c4c0..1b054433b9 100644
--- a/packages/plugin-infra/src/__tests__/use-block-suite-workspace.spec.ts
+++ b/packages/plugin-infra/src/__tests__/use-block-suite-workspace.spec.ts
@@ -9,11 +9,11 @@ import { expect, test, vi } from 'vitest';
import {
usePassiveWorkspaceEffect,
useStaticBlockSuiteWorkspace,
-} from '../__internal__/react';
+} from '../__internal__/react.js';
import {
getActiveBlockSuiteWorkspaceAtom,
INTERNAL_BLOCKSUITE_HASH_MAP,
-} from '../__internal__/workspace';
+} from '../__internal__/workspace.js';
test('useStaticBlockSuiteWorkspace', async () => {
const sync = vi.fn();
diff --git a/packages/plugin-infra/src/atom.ts b/packages/plugin-infra/src/atom.ts
index bda15b9ff5..41c86b81fb 100644
--- a/packages/plugin-infra/src/atom.ts
+++ b/packages/plugin-infra/src/atom.ts
@@ -2,9 +2,9 @@ import { assertExists } from '@blocksuite/global/utils';
import type { Page, Workspace } from '@blocksuite/store';
import { atom, createStore } from 'jotai/vanilla';
-import { getWorkspace, waitForWorkspace } from './__internal__/workspace';
-import type { CallbackMap } from './entry';
-import type { ExpectedLayout } from './type';
+import { getWorkspace, waitForWorkspace } from './__internal__/workspace.js';
+import type { CallbackMap } from './entry.js';
+import type { ExpectedLayout } from './type.js';
// global store
export const rootStore = createStore();
diff --git a/packages/plugin-infra/src/type.ts b/packages/plugin-infra/src/type.ts
index 5f7b4dbd22..e0cc82424c 100644
--- a/packages/plugin-infra/src/type.ts
+++ b/packages/plugin-infra/src/type.ts
@@ -1,4 +1,31 @@
import type { WritableAtom } from 'jotai';
+import { z } from 'zod';
+
+export const packageJsonInputSchema = z.object({
+ name: z.string(),
+ version: z.string(),
+ description: z.string(),
+ affinePlugin: z.object({
+ release: z.boolean(),
+ entry: z.object({
+ core: z.string(),
+ server: z.string().optional(),
+ }),
+ }),
+});
+
+export const packageJsonOutputSchema = z.object({
+ name: z.string(),
+ version: z.string(),
+ description: z.string(),
+ affinePlugin: z.object({
+ release: z.boolean(),
+ entry: z.object({
+ core: z.string(),
+ }),
+ assets: z.array(z.string()),
+ }),
+});
export type LayoutDirection = 'horizontal' | 'vertical';
export type LayoutNode = LayoutParentNode | string;
diff --git a/packages/plugin-infra/tsconfig.json b/packages/plugin-infra/tsconfig.json
index e9197b23ff..fc88b250ac 100644
--- a/packages/plugin-infra/tsconfig.json
+++ b/packages/plugin-infra/tsconfig.json
@@ -4,7 +4,8 @@
"compilerOptions": {
"composite": true,
"noEmit": false,
- "outDir": "lib"
+ "outDir": "lib",
+ "moduleResolution": "node16"
},
"references": [
{
diff --git a/packages/plugin-infra/vite.config.ts b/packages/plugin-infra/vite.config.ts
index f088ee3ae1..61241dc203 100644
--- a/packages/plugin-infra/vite.config.ts
+++ b/packages/plugin-infra/vite.config.ts
@@ -22,12 +22,8 @@ export default defineConfig({
},
},
rollupOptions: {
- external: ['react', /^jotai/, /^@blocksuite/],
+ external: ['react', /^jotai/, /^@blocksuite/, 'zod'],
},
},
- plugins: [
- dts({
- insertTypesEntry: true,
- }),
- ],
+ plugins: [dts()],
});
diff --git a/plugins/bookmark/package.json b/plugins/bookmark/package.json
index eec88315cd..5d61fd3143 100644
--- a/plugins/bookmark/package.json
+++ b/plugins/bookmark/package.json
@@ -1,6 +1,7 @@
{
"name": "@affine/bookmark-plugin",
"version": "0.8.0-canary.0",
+ "description": "Bookmark Plugin",
"affinePlugin": {
"release": true,
"entry": {
diff --git a/plugins/copilot/package.json b/plugins/copilot/package.json
index 52f544e1dc..09e0bf62c7 100644
--- a/plugins/copilot/package.json
+++ b/plugins/copilot/package.json
@@ -1,6 +1,7 @@
{
"name": "@affine/copilot-plugin",
"private": true,
+ "description": "Copilot plugin",
"affinePlugin": {
"release": false,
"entry": {
diff --git a/plugins/hello-world/package.json b/plugins/hello-world/package.json
index 72d6730476..f6afca5e95 100644
--- a/plugins/hello-world/package.json
+++ b/plugins/hello-world/package.json
@@ -1,6 +1,7 @@
{
"name": "@affine/hello-world-plugin",
"private": true,
+ "description": "Hello world plugin",
"version": "0.8.0-canary.0",
"affinePlugin": {
"release": false,
diff --git a/yarn.lock b/yarn.lock
index f000b7ccb7..dd78429798 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -10810,6 +10810,7 @@ __metadata:
jotai: ^2.2.2
vite: ^4.4.7
vite-plugin-dts: 3.3.1
+ zod: ^3.21.4
peerDependencies:
"@blocksuite/blocks": "*"
"@blocksuite/editor": "*"