mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat(plugin-infra): add package.json schema (#3456)
This commit is contained in:
@@ -3,10 +3,14 @@ import { readFile } from 'node:fs/promises';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { parseArgs } from 'node:util';
|
import { parseArgs } from 'node:util';
|
||||||
|
|
||||||
|
import {
|
||||||
|
packageJsonInputSchema,
|
||||||
|
packageJsonOutputSchema,
|
||||||
|
} from '@toeverything/plugin-infra/type';
|
||||||
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
|
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
|
||||||
import react from '@vitejs/plugin-react-swc';
|
import react from '@vitejs/plugin-react-swc';
|
||||||
import { build } from 'vite';
|
import { build } from 'vite';
|
||||||
import { z } from 'zod';
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { projectRoot } from '../config/index.js';
|
import { projectRoot } from '../config/index.js';
|
||||||
|
|
||||||
@@ -34,17 +38,6 @@ if (typeof plugin !== 'string') {
|
|||||||
const isWatch = result.values.watch;
|
const isWatch = result.values.watch;
|
||||||
ok(typeof isWatch === 'boolean');
|
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 = [
|
const external = [
|
||||||
// built-in packages
|
// built-in packages
|
||||||
/^@affine/,
|
/^@affine/,
|
||||||
@@ -71,7 +64,7 @@ const getPluginDir = (plugin: string) => path.resolve(allPluginDir, plugin);
|
|||||||
const pluginDir = getPluginDir(plugin);
|
const pluginDir = getPluginDir(plugin);
|
||||||
const packageJsonFile = path.resolve(pluginDir, 'package.json');
|
const packageJsonFile = path.resolve(pluginDir, 'package.json');
|
||||||
|
|
||||||
const json: z.infer<typeof packageJsonSchema> = await readFile(
|
const json: z.infer<typeof packageJsonInputSchema> = await readFile(
|
||||||
packageJsonFile,
|
packageJsonFile,
|
||||||
{
|
{
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
@@ -79,7 +72,7 @@ const json: z.infer<typeof packageJsonSchema> = await readFile(
|
|||||||
)
|
)
|
||||||
.then(text => JSON.parse(text))
|
.then(text => JSON.parse(text))
|
||||||
.then(async json => {
|
.then(async json => {
|
||||||
const { success } = await packageJsonSchema.safeParseAsync(json);
|
const { success } = await packageJsonInputSchema.safeParseAsync(json);
|
||||||
if (success) {
|
if (success) {
|
||||||
return json;
|
return json;
|
||||||
} else {
|
} else {
|
||||||
@@ -163,6 +156,8 @@ await build({
|
|||||||
async generateBundle() {
|
async generateBundle() {
|
||||||
const packageJson = {
|
const packageJson = {
|
||||||
name: json.name,
|
name: json.name,
|
||||||
|
version: json.version,
|
||||||
|
description: json.description,
|
||||||
affinePlugin: {
|
affinePlugin: {
|
||||||
release: json.affinePlugin.release,
|
release: json.affinePlugin.release,
|
||||||
entry: {
|
entry: {
|
||||||
@@ -171,6 +166,7 @@ await build({
|
|||||||
assets: [...metadata.assets],
|
assets: [...metadata.assets],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
packageJsonOutputSchema.parse(packageJson);
|
||||||
this.emitFile({
|
this.emitFile({
|
||||||
type: 'asset',
|
type: 'asset',
|
||||||
fileName: 'package.json',
|
fileName: 'package.json',
|
||||||
|
|||||||
@@ -3,8 +3,13 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "Node16",
|
"moduleResolution": "Node",
|
||||||
"outDir": "lib"
|
"outDir": "lib"
|
||||||
},
|
},
|
||||||
"include": ["src/bin", "src"]
|
"include": ["src"],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "../plugin-infra"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,27 +10,27 @@
|
|||||||
],
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
"./entry": {
|
"./entry": {
|
||||||
"type": "./dist/entry.d.ts",
|
"type": "./dist/src/entry.d.ts",
|
||||||
"import": "./dist/entry.js",
|
"import": "./dist/entry.js",
|
||||||
"require": "./dist/entry.cjs"
|
"require": "./dist/entry.cjs"
|
||||||
},
|
},
|
||||||
"./atom": {
|
"./atom": {
|
||||||
"type": "./dist/atom.d.ts",
|
"type": "./dist/src/atom.d.ts",
|
||||||
"import": "./dist/atom.js",
|
"import": "./dist/atom.js",
|
||||||
"require": "./dist/atom.cjs"
|
"require": "./dist/atom.cjs"
|
||||||
},
|
},
|
||||||
"./type": {
|
"./type": {
|
||||||
"type": "./dist/type.d.ts",
|
"type": "./dist/src/type.d.ts",
|
||||||
"import": "./dist/type.js",
|
"import": "./dist/type.js",
|
||||||
"require": "./dist/type.cjs"
|
"require": "./dist/type.cjs"
|
||||||
},
|
},
|
||||||
"./__internal__/workspace": {
|
"./__internal__/workspace": {
|
||||||
"type": "./dist/__internal__/workspace.d.ts",
|
"type": "./dist/src/__internal__/workspace.d.ts",
|
||||||
"import": "./dist/__internal__/workspace.js",
|
"import": "./dist/__internal__/workspace.js",
|
||||||
"require": "./dist/__internal__/workspace.cjs"
|
"require": "./dist/__internal__/workspace.cjs"
|
||||||
},
|
},
|
||||||
"./__internal__/react": {
|
"./__internal__/react": {
|
||||||
"type": "./dist/__internal__/react.d.ts",
|
"type": "./dist/src/__internal__/react.d.ts",
|
||||||
"import": "./dist/__internal__/react.js",
|
"import": "./dist/__internal__/react.js",
|
||||||
"require": "./dist/__internal__/react.cjs"
|
"require": "./dist/__internal__/react.cjs"
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@blocksuite/global": "0.0.0-20230729011742-613f3782-nightly",
|
"@blocksuite/global": "0.0.0-20230729011742-613f3782-nightly",
|
||||||
"@blocksuite/store": "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": {
|
"devDependencies": {
|
||||||
"@blocksuite/blocks": "0.0.0-20230729011742-613f3782-nightly",
|
"@blocksuite/blocks": "0.0.0-20230729011742-613f3782-nightly",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { useEffect } from 'react';
|
|||||||
import {
|
import {
|
||||||
getActiveBlockSuiteWorkspaceAtom,
|
getActiveBlockSuiteWorkspaceAtom,
|
||||||
workspacePassiveEffectWeakMap,
|
workspacePassiveEffectWeakMap,
|
||||||
} from './workspace';
|
} from './workspace.js';
|
||||||
|
|
||||||
export function useStaticBlockSuiteWorkspace(id: string): Workspace {
|
export function useStaticBlockSuiteWorkspace(id: string): Workspace {
|
||||||
return useAtomValue(getActiveBlockSuiteWorkspaceAtom(id));
|
return useAtomValue(getActiveBlockSuiteWorkspaceAtom(id));
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import { expect, test, vi } from 'vitest';
|
|||||||
import {
|
import {
|
||||||
usePassiveWorkspaceEffect,
|
usePassiveWorkspaceEffect,
|
||||||
useStaticBlockSuiteWorkspace,
|
useStaticBlockSuiteWorkspace,
|
||||||
} from '../__internal__/react';
|
} from '../__internal__/react.js';
|
||||||
import {
|
import {
|
||||||
getActiveBlockSuiteWorkspaceAtom,
|
getActiveBlockSuiteWorkspaceAtom,
|
||||||
INTERNAL_BLOCKSUITE_HASH_MAP,
|
INTERNAL_BLOCKSUITE_HASH_MAP,
|
||||||
} from '../__internal__/workspace';
|
} from '../__internal__/workspace.js';
|
||||||
|
|
||||||
test('useStaticBlockSuiteWorkspace', async () => {
|
test('useStaticBlockSuiteWorkspace', async () => {
|
||||||
const sync = vi.fn();
|
const sync = vi.fn();
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import { assertExists } from '@blocksuite/global/utils';
|
|||||||
import type { Page, Workspace } from '@blocksuite/store';
|
import type { Page, Workspace } from '@blocksuite/store';
|
||||||
import { atom, createStore } from 'jotai/vanilla';
|
import { atom, createStore } from 'jotai/vanilla';
|
||||||
|
|
||||||
import { getWorkspace, waitForWorkspace } from './__internal__/workspace';
|
import { getWorkspace, waitForWorkspace } from './__internal__/workspace.js';
|
||||||
import type { CallbackMap } from './entry';
|
import type { CallbackMap } from './entry.js';
|
||||||
import type { ExpectedLayout } from './type';
|
import type { ExpectedLayout } from './type.js';
|
||||||
|
|
||||||
// global store
|
// global store
|
||||||
export const rootStore = createStore();
|
export const rootStore = createStore();
|
||||||
|
|||||||
@@ -1,4 +1,31 @@
|
|||||||
import type { WritableAtom } from 'jotai';
|
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 LayoutDirection = 'horizontal' | 'vertical';
|
||||||
export type LayoutNode = LayoutParentNode | string;
|
export type LayoutNode = LayoutParentNode | string;
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
"noEmit": false,
|
"noEmit": false,
|
||||||
"outDir": "lib"
|
"outDir": "lib",
|
||||||
|
"moduleResolution": "node16"
|
||||||
},
|
},
|
||||||
"references": [
|
"references": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,12 +22,8 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['react', /^jotai/, /^@blocksuite/],
|
external: ['react', /^jotai/, /^@blocksuite/, 'zod'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [dts()],
|
||||||
dts({
|
|
||||||
insertTypesEntry: true,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@affine/bookmark-plugin",
|
"name": "@affine/bookmark-plugin",
|
||||||
"version": "0.8.0-canary.0",
|
"version": "0.8.0-canary.0",
|
||||||
|
"description": "Bookmark Plugin",
|
||||||
"affinePlugin": {
|
"affinePlugin": {
|
||||||
"release": true,
|
"release": true,
|
||||||
"entry": {
|
"entry": {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@affine/copilot-plugin",
|
"name": "@affine/copilot-plugin",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"description": "Copilot plugin",
|
||||||
"affinePlugin": {
|
"affinePlugin": {
|
||||||
"release": false,
|
"release": false,
|
||||||
"entry": {
|
"entry": {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@affine/hello-world-plugin",
|
"name": "@affine/hello-world-plugin",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"description": "Hello world plugin",
|
||||||
"version": "0.8.0-canary.0",
|
"version": "0.8.0-canary.0",
|
||||||
"affinePlugin": {
|
"affinePlugin": {
|
||||||
"release": false,
|
"release": false,
|
||||||
|
|||||||
@@ -10810,6 +10810,7 @@ __metadata:
|
|||||||
jotai: ^2.2.2
|
jotai: ^2.2.2
|
||||||
vite: ^4.4.7
|
vite: ^4.4.7
|
||||||
vite-plugin-dts: 3.3.1
|
vite-plugin-dts: 3.3.1
|
||||||
|
zod: ^3.21.4
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
"@blocksuite/blocks": "*"
|
"@blocksuite/blocks": "*"
|
||||||
"@blocksuite/editor": "*"
|
"@blocksuite/editor": "*"
|
||||||
|
|||||||
Reference in New Issue
Block a user