Debian Codegraph @

node/PUBLISHING.md

raw symbols SCIP
1 # Publishing Guide
2
3 This document describes how to prepare and publish the OpenCC Node.js package
4 family.
5
6 The current npm layout is split by platform:
7
8 - `opencc` contains the JavaScript API, CLI, TypeScript declarations, source
9 fallback, and runtime dictionary/config assets.
10 - `@opencc/opencc-<platform>-<arch>` contains exactly one native
11 `opencc.node` binary for one platform.
12
13 The split-package layout is experimental. It keeps the main npm package smaller
14 while preserving source-build fallback for platforms without a scoped binary
15 package.
16
17 ## Package names
18
19 The main package declares these scoped packages as optional dependencies:
20
21 ```text
22 opencc
23 @opencc/opencc-darwin-arm64
24 @opencc/opencc-linux-arm64
25 @opencc/opencc-linux-x64
26 @opencc/opencc-win32-x64
27 ```
28
29 The main package can either point at newly built scoped binary package versions
30 or reuse already published compatible binary package versions. For a full native
31 binary refresh, publish all scoped packages at the same version as `opencc`.
32
33 ## Prerequisites
34
35 - npm account access to publish `opencc`.
36 - npm organization access to publish public packages under `@opencc`.
37 - Node.js, npm, Python, and a native C++ build toolchain for the target
38 platform.
39 - GitHub Actions or another set of machines covering each supported target
40 platform.
41
42 At the moment, maintainers are assumed to run the full multi-platform release
43 process through GitHub Actions. A local machine can still build and publish the
44 scoped package for its own platform.
45
46 ## Build
47
48 From the repository root, build the scoped binary for the current platform with
49 Bazel:
50
51 ```sh
52 npm install --omit=optional --ignore-scripts
53 ./scripts/build-node-prebuild-bazel.sh "$(node -p 'process.platform + "-" + process.arch')"
54 ```
55
56 This creates:
57
58 ```text
59 prebuilds/assets/*.json
60 prebuilds/assets/*.ocd2
61 prebuilds/<current-platform>-<current-arch>/opencc.node
62 ```
63
64 The release workflow runs the Bazel build script separately on the runner for
65 each scoped binary target. The main `opencc` package still keeps `binding.gyp`
66 and source files so installs on platforms without a scoped binary package can
67 fall back to `node-gyp-build`. This fallback is planned for removal in a
68 future release, after which all Node builds will use Bazel exclusively.
69
70 ## Prepare scoped binary packages
71
72 After the `prebuilds/` tree exists, generate publishable scoped package
73 directories:
74
75 ```sh
76 npm run prepare:scoped-packages
77 ```
78
79 This writes packages under:
80
81 ```text
82 dist/scoped-packages/@opencc/opencc-darwin-arm64
83 dist/scoped-packages/@opencc/opencc-linux-arm64
84 dist/scoped-packages/@opencc/opencc-linux-x64
85 dist/scoped-packages/@opencc/opencc-win32-x64
86 ```
87
88 Each generated package contains only:
89
90 ```text
91 index.js
92 package.json
93 README.md
94 prebuilds/<platform>-<arch>/opencc.node
95 ```
96
97 ## Verify package contents
98
99 Dry-run the main package:
100
101 ```sh
102 npm pack --dry-run
103 ```
104
105 The main package tarball should contain `node/`, `src/`, `data/`, source build
106 files, and `prebuilds/assets/`, but not `prebuilds/<platform>/opencc.node`.
107
108 Dry-run each scoped package:
109
110 ```sh
111 npm pack --dry-run dist/scoped-packages/@opencc/opencc-darwin-arm64
112 npm pack --dry-run dist/scoped-packages/@opencc/opencc-linux-arm64
113 npm pack --dry-run dist/scoped-packages/@opencc/opencc-linux-x64
114 npm pack --dry-run dist/scoped-packages/@opencc/opencc-win32-x64
115 ```
116
117 Each scoped tarball should contain one `opencc.node` binary for its own
118 platform plus a short package-specific README.
119
120 ## Publish order
121
122 Publish the scoped binary packages first. The main package depends on them via
123 `optionalDependencies`, so they should already exist by the time users install
124 the main package.
125
126 For a prerelease version such as `1.3.2-next1`, use the `next` dist-tag:
127
128 ```sh
129 npm publish dist/scoped-packages/@opencc/opencc-darwin-arm64 --access public --tag next
130 npm publish dist/scoped-packages/@opencc/opencc-linux-arm64 --access public --tag next
131 npm publish dist/scoped-packages/@opencc/opencc-linux-x64 --access public --tag next
132 npm publish dist/scoped-packages/@opencc/opencc-win32-x64 --access public --tag next
133 npm publish --tag next
134 ```
135
136 For a stable release, use `latest` or omit `--tag`:
137
138 ```sh
139 npm publish dist/scoped-packages/@opencc/opencc-darwin-arm64 --access public
140 npm publish dist/scoped-packages/@opencc/opencc-linux-arm64 --access public
141 npm publish dist/scoped-packages/@opencc/opencc-linux-x64 --access public
142 npm publish dist/scoped-packages/@opencc/opencc-win32-x64 --access public
143 npm publish
144 ```
145
146 `--access public` is required for the first publish of scoped public packages.
147 It is harmless to keep using it for later publishes.
148
149 The final `npm publish` command runs `prepublishOnly`, which verifies that the
150 scoped binary package versions declared in `optionalDependencies` have already
151 been published.
152
153 ## Install-test after publishing
154
155 Use a temporary directory and install from npm:
156
157 ```sh
158 mkdir /tmp/opencc-install-test
159 cd /tmp/opencc-install-test
160 npm init -y
161 npm install [email protected] --tag next
162 node -e "const OpenCC = require('opencc'); const cc = new OpenCC('s2twp'); console.log(cc.convertSync('鼠标里面的硅二极管坏了'));"
163 ```
164
165 The install should pull exactly one matching `@opencc/opencc-<platform>-<arch>`
166 optional package for the current machine. If no scoped binary package is
167 available, the install script falls back to `node-gyp-build`.
168
169 ## Future CI shape
170
171 The intended CI release flow is:
172
173 1. Build each scoped binary package on its matching platform or runner.
174 2. Upload scoped package artifacts.
175 3. Publish all scoped binary packages with the chosen version and dist-tag.
176 4. Publish the main `opencc` package after the scoped packages exist.
177
178 Until that CI flow exists, the local flow above is the source of truth.