From f3c9859c18ee0b98be72f515deaa0ef45dbafcfe Mon Sep 17 00:00:00 2001 From: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com> Date: Sun, 19 Nov 2023 23:37:43 +1100 Subject: [PATCH] Stricter npm field validation (#484) * Add zod schemas for CI validation * Require npm field for components.json * Remove svelte-layout-resizable * Stricter Zod validation * Stricter repository field validation * Implement requested changes * Add back accidentally removed field * Move SvelteStore to templates.json * Update category and tags --- package.json | 1 + pnpm-lock.yaml | 8 ++++++++ src/lib/schemas.js | 11 +++-------- src/routes/components/components.json | 25 ++++++------------------- src/routes/templates/templates.json | 7 +++++++ 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 2e285d1..517892a 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "itemsjs": "^2.1.20", "lint-staged": "^13.2.3", "mdsvex": "^0.11.0", + "package-name-regex": "^3.0.0", "prettier": "^2.8.8", "prettier-plugin-svelte": "^2.10.1", "rehype-slug": "^5.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index de793bd..b4a225d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -53,6 +53,9 @@ devDependencies: mdsvex: specifier: ^0.11.0 version: 0.11.0(svelte@4.0.5) + package-name-regex: + specifier: ^3.0.0 + version: 3.0.0 prettier: specifier: ^2.8.8 version: 2.8.8 @@ -2065,6 +2068,11 @@ packages: aggregate-error: 3.1.0 dev: true + /package-name-regex@3.0.0: + resolution: {integrity: sha512-n4LexlsIvKpV8zfGWDxJIZDqDiZ9kN5JiXgx3K7oy8JbqRdrQvPG8BdJesqvGQMt/bPBG4U0gTf2w+pcNk6VWw==} + engines: {node: '>=14'} + dev: true + /parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} diff --git a/src/lib/schemas.js b/src/lib/schemas.js index 01c0d04..b990714 100644 --- a/src/lib/schemas.js +++ b/src/lib/schemas.js @@ -1,12 +1,10 @@ import { z } from 'zod'; +import packageNameRegex from 'package-name-regex'; export const componentsSchema = z.array( z.object({ title: z.string(), - npm: z - .string() - .regex(/(@[\w-]+\/)?[\w-]+/) - .optional(), + npm: z.string().regex(packageNameRegex), url: z.string().url().optional(), repository: z.string().url(), description: z.string(), @@ -46,10 +44,7 @@ export const templatesSchema = z.array( export const toolsSchema = z.array( z.object({ title: z.string(), - npm: z - .string() - .regex(/(@[\w-]+\/)?[\w-]+/) - .optional(), + npm: z.string().regex(packageNameRegex).optional(), url: z.string().url().optional(), repository: z.string().url(), description: z.string(), diff --git a/src/routes/components/components.json b/src/routes/components/components.json index 4a47ed3..241d180 100644 --- a/src/routes/components/components.json +++ b/src/routes/components/components.json @@ -12,7 +12,7 @@ "url": "https://svelte.dev/repl/d9616fce34c444d4bcac551cb5bdc0ee?version=3.55.1", "repository": "https://github.com/dmvvilela/svelte-scrollactive", "description": "This is a port of vue-scrollactive to Svelte, a lightweight and simple to use component that highlights menu items as you scroll the page, also scrolling to target section when clicked.", - "npm": "https://www.npmjs.com/package/svelte-scrollactive", + "npm": "svelte-scrollactive", "category": "User Interaction", "tags": [ "components and libraries", @@ -213,7 +213,8 @@ }, { "title": "SCR Svelte Client Router", - "repository": "https://arthurgermano.github.io/svelte-client-router/#/svelte-client-router", + "url": "https://arthurgermano.github.io/svelte-client-router/#/svelte-client-router", + "repository": "https://github.com/arthurgermano/svelte-client-router", "npm": "svelte-client-router", "description": "Svelte Client Router is everything you need and think when routing SPA's. This is The Svelte Router for SPA!", "tags": ["routers"], @@ -1002,13 +1003,6 @@ "title": "layercake", "repository": "https://github.com/mhkeller/layercake" }, - { - "category": "CSS and Layout", - "description": "resizable layout component for svelte", - "tags": ["components and libraries", "layout and structure"], - "title": "svelte-layout-resizable", - "repository": "https://github.com/milahu/svelte-layout-resizable" - }, { "category": "CSS and Layout", "description": "Arrange infinite card elements according to various layout types like masonry", @@ -1161,13 +1155,6 @@ "title": "storez", "repository": "https://github.com/plrenaudin/svelte-storez" }, - { - "category": "Stores", - "description": "Template for client side svelte store", - "tags": ["components and libraries", "stores and state"], - "title": "SvelteStore", - "repository": "https://github.com/gitbreaker222/SvelteStore" - }, { "category": "Integration", "description": "Use Svelte components with Vue and React", @@ -2168,7 +2155,7 @@ "title": "svelte-currency-input", "repository": "https://github.com/fmaclen/svelte-currency-input", "description": "A form input that converts numbers to localized currency formats as you type", - "npm": "svelte-currency-input", + "npm": "@canutin/svelte-currency-input", "category": "Forms & User Input", "tags": ["forms", "inputs and widgets", "internationalization", "typescript"] }, @@ -2265,7 +2252,7 @@ "title": "svelte-form-builder", "repository": "https://github.com/pragmatic-engineering/svelte-form-builder-community", "description": "A No-Code Form Builder Library", - "npm": "svelte-form-builder-community", + "npm": "@pragmatic-engineering/svelte-form-builder-community", "category": "Forms & User Input", "tags": ["forms", "components and libraries"] }, @@ -2415,7 +2402,7 @@ "title": "SvelteKit-Adapter-Versioned-Worker", "repository": "https://github.com/hedgehog125/SvelteKit-Adapter-Versioned-Worker", "description": "A SvelteKit adapter for generating service workers to make PWAs work offline", - "npm": "svelteKit-adapter-versioned-worker", + "npm": "sveltekit-adapter-versioned-worker", "category": "SvelteKit Adapters" }, { diff --git a/src/routes/templates/templates.json b/src/routes/templates/templates.json index d701de7..c6e0355 100644 --- a/src/routes/templates/templates.json +++ b/src/routes/templates/templates.json @@ -678,5 +678,12 @@ "description": "A Starter Kit with SurrealDB and SvelteKit, featuring Authentication and CRUD Operations + Realtime", "category": "SvelteKit", "tags": ["templates", "database", "integrations", "typescript", "ssr"] + }, + { + "title": "SvelteStore", + "repository": "https://github.com/gitbreaker222/SvelteStore", + "description": "Template for client side svelte store", + "category": "Svelte", + "tags": ["templates", "stores and state"] } ]