From f2c32dad3254e2f7325da7ff70f7f21439445bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Sat, 27 Jul 2024 05:54:00 +0800 Subject: [PATCH 1/2] feat: add more fields into package.json --- src/types/packagejson.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/types/packagejson.ts b/src/types/packagejson.ts index 042dee8..59fd899 100644 --- a/src/types/packagejson.ts +++ b/src/types/packagejson.ts @@ -114,6 +114,10 @@ export interface PackageJson { * If your module is meant to be used client-side the browser field should be used instead of the main field. This is helpful to hint users that it might rely on primitives that aren’t available in Node.js modules. (e.g. window) */ browser?: string | Record; + /** + * The `unpkg` field is used to specify the URL to a UMD module for your package. This is used by default in the unpkg.com CDN service. + */ + unpkg?: string; /** * A map of command name to local file name. On install, npm will symlink that file into `prefix/bin` for global installs, or `./node_modules/.bin/` for local installs. */ @@ -182,5 +186,31 @@ export interface PackageJson { * The optional engines field is used to specify the versions of npm and node that your stuff works on. */ workspaces?: string[]; + typesVersions?: Record>; + os?: string[]; + cpu?: string[]; + publishConfig?: { + registry: string; + tag: string; + access: "public" | "restricted"; + + // pnpm + executableFiles?: string[]; + directory?: string; + linkDirectory?: boolean; + } & Pick< + PackageJson, + | "bin" + | "main" + | "exports" + | "types" + | "typings" + | "module" + | "browser" + | "unpkg" + | "typesVersions" + | "os" + | "cpu" + >; [key: string]: any; } From 721068a058021fba4eb48f77f353b34b4c334198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Mon, 29 Jul 2024 17:24:23 +0800 Subject: [PATCH 2/2] add jsdoc --- src/types/packagejson.ts | 95 +++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/src/types/packagejson.ts b/src/types/packagejson.ts index 59fd899..90bb054 100644 --- a/src/types/packagejson.ts +++ b/src/types/packagejson.ts @@ -33,15 +33,13 @@ export type PackageJsonExports = export interface PackageJson { /** - * The name is what your thing is called. - * Some rules: - - - The name must be less than or equal to 214 characters. This includes the scope for scoped packages. - - The name can’t start with a dot or an underscore. - - New packages must not have uppercase letters in the name. - - The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can’t contain any non-URL-safe characters. - - */ + * The name is what your thing is called. + * Some rules: + * - The name must be less than or equal to 214 characters. This includes the scope for scoped packages. + * - The name can’t start with a dot or an underscore. + * - New packages must not have uppercase letters in the name. + * - The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can’t contain any non-URL-safe characters. + */ name?: string; /** * Version must be parseable by `node-semver`, which is bundled with npm as a dependency. (`npm install semver` to use it yourself.) @@ -183,20 +181,93 @@ export interface PackageJson { */ imports?: Record>; /** - * The optional engines field is used to specify the versions of npm and node that your stuff works on. + * The field is used to define a set of sub-packages (or workspaces) within a monorepo. + * + * This field is an array of glob patterns or an object with specific configurations for managing + * multiple packages in a single repository. */ workspaces?: string[]; + /** + * The field is is used to specify different TypeScript declaration files for + * different versions of TypeScript, allowing for version-specific type definitions. + */ typesVersions?: Record>; + /** + * You can specify which operating systems your module will run on: + * ```json + * { + * "os": ["darwin", "linux"] + * } + * ``` + * You can also block instead of allowing operating systems, just prepend the blocked os with a '!': + * ```json + * { + * "os": ["!win32"] + * } + * ``` + * The host operating system is determined by `process.platform` + * It is allowed to both block and allow an item, although there isn't any good reason to do this. + */ os?: string[]; + /** + * If your code only runs on certain cpu architectures, you can specify which ones. + * ```json + * { + * "cpu": ["x64", "ia32"] + * } + * ``` + * Like the `os` option, you can also block architectures: + * ```json + * { + * "cpu": ["!arm", "!mips"] + * } + * ``` + * The host architecture is determined by `process.arch` + */ cpu?: string[]; + /** + * This is a set of config values that will be used at publish-time. + */ publishConfig?: { + /** + * The registry that will be used if the package is published. + */ registry: string; + /** + * The tag that will be used if the package is published. + */ tag: string; + /** + * The access level that will be used if the package is published. + */ access: "public" | "restricted"; - - // pnpm + /** + * **pnpm-only** + * + * By default, for portability reasons, no files except those listed in + * the bin field will be marked as executable in the resulting package + * archive. The executableFiles field lets you declare additional fields + * that must have the executable flag (+x) set even if + * they aren't directly accessible through the bin field. + */ executableFiles?: string[]; + /** + * **pnpm-only** + * + * You also can use the field `publishConfig.directory` to customize + * the published subdirectory relative to the current `package.json`. + * + * It is expected to have a modified version of the current package in + * the specified directory (usually using third party build tools). + */ directory?: string; + /** + * **pnpm-only** + * + * When set to `true`, the project will be symlinked from the + * `publishConfig.directory` location during local development. + * @default true + */ linkDirectory?: boolean; } & Pick< PackageJson,