@way17/minimal-npm-demo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # minimal-npm-demo
2
+
3
+ 一个最小可运行、且需要先构建再发布的 npm 包示例。
4
+
5
+ ## 功能
6
+
7
+ - 源码使用 TypeScript,构建产物输出到 `dist/`
8
+ - 导出一个 `createHelloMessage(name)` 方法
9
+ - 自带测试
10
+ - 发布前会先执行构建
11
+
12
+ ## 项目结构
13
+
14
+ ```text
15
+ src/ # TypeScript 源码
16
+ dist/ # build 后生成的发布产物
17
+ test/ # 测试
18
+ ```
19
+
20
+ ## 本地开发
21
+
22
+ 先安装依赖:
23
+
24
+ ```bash
25
+ npm install
26
+ ```
27
+
28
+ 构建:
29
+
30
+ ```bash
31
+ npm run build
32
+ ```
33
+
34
+ 测试:
35
+
36
+ ```bash
37
+ npm test
38
+ ```
39
+
40
+ 检查发布内容:
41
+
42
+ ```bash
43
+ npm run pack:check
44
+ ```
45
+
46
+ ## 使用
47
+
48
+ ```js
49
+ const { createHelloMessage } = require("minimal-npm-demo");
50
+
51
+ console.log(createHelloMessage("Codex"));
52
+ // Hello, Codex!
53
+ ```
54
+
55
+ 这个包发布后,用户实际拿到的是 `dist/index.js`,不是 `src/index.ts`。
56
+
57
+ ## 开发命令
58
+
59
+ ```bash
60
+ npm install
61
+ npm run build
62
+ npm test
63
+ npm run pack:check
64
+ ```
65
+
66
+ ## 发布流程
67
+
68
+ 1. 修改 `package.json` 中的 `name` 为你自己的包名
69
+ 2. 更新 `version`
70
+ 3. 执行 `npm test`
71
+ 4. 登录 npm:`npm login`
72
+ 5. 发布:`npm publish`
73
+
74
+ 其中 `npm publish` 前会自动执行 `prepublishOnly`,`npm pack` / `npm publish` 前会自动执行 `prepack`,所以这个 demo 已经具备“发布前必须先构建”的流程。
@@ -0,0 +1 @@
1
+ export declare function createHelloMessage(name?: string): string;
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHelloMessage = createHelloMessage;
4
+ function createHelloMessage(name = "world") {
5
+ if (typeof name !== "string") {
6
+ throw new TypeError("name must be a string");
7
+ }
8
+ const normalizedName = name.trim();
9
+ return `Hello, ${normalizedName || "world"}!`;
10
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@way17/minimal-npm-demo",
3
+ "version": "0.1.0",
4
+ "description": "A minimal npm package demo that requires a build step before publish.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.json",
16
+ "test": "npm run build && node --test",
17
+ "check": "npm run build && npm test",
18
+ "prepack": "npm run build",
19
+ "prepublishOnly": "npm test",
20
+ "pack:check": "npm pack --dry-run"
21
+ },
22
+ "keywords": [
23
+ "npm",
24
+ "demo",
25
+ "package"
26
+ ],
27
+ "author": "",
28
+ "license": "MIT",
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.8.3"
34
+ }
35
+ }