@@ -16,12 +16,15 @@ const colors = {
1616const projectRoot = path . resolve ( __dirname , ".." ) ;
1717const packageDir = path . join (
1818 projectRoot ,
19- "packages/react-native-nitro-storage"
19+ "packages/react-native-nitro-storage" ,
2020) ;
2121const packageJsonPath = path . join ( packageDir , "package.json" ) ;
2222const packageFilter = "react-native-nitro-storage" ;
23- const isCI =
24- process . env . CI === "true" || process . env . GITHUB_ACTIONS === "true" ;
23+ const packageDocsSyncScript = path . join (
24+ packageDir ,
25+ "scripts/sync-package-docs.js" ,
26+ ) ;
27+ const isCI = process . env . CI === "true" || process . env . GITHUB_ACTIONS === "true" ;
2528
2629function log ( message , color = "green" ) {
2730 console . log ( colors [ color ] ( message ) ) ;
@@ -54,6 +57,25 @@ function execCommandWithOutput(command, options = {}) {
5457 }
5558}
5659
60+ function shellQuote ( value ) {
61+ return JSON . stringify ( String ( value ) ) ;
62+ }
63+
64+ function validateNpmTag ( tag ) {
65+ if ( ! / ^ [ a - z 0 - 9 ] [ a - z 0 - 9 . _ - ] * $ / i. test ( tag ) ) {
66+ log ( `Invalid npm dist tag: ${ tag } ` , "red" ) ;
67+ process . exit ( 1 ) ;
68+ }
69+
70+ if ( / ^ v ? \d + \. \d + \. \d + / . test ( tag ) ) {
71+ log (
72+ `Invalid npm dist tag "${ tag } ": use a release channel like latest or next.` ,
73+ "red" ,
74+ ) ;
75+ process . exit ( 1 ) ;
76+ }
77+ }
78+
5779function isInteractive ( ) {
5880 return process . stdin . isTTY && process . stdout . isTTY && ! isCI ;
5981}
@@ -102,6 +124,16 @@ function checkNpmAuth() {
102124 return whoami !== null && whoami !== "" ;
103125}
104126
127+ function cleanupPackageDocs ( ) {
128+ if ( ! fs . existsSync ( packageDocsSyncScript ) ) {
129+ return ;
130+ }
131+
132+ execCommand ( `node ${ shellQuote ( packageDocsSyncScript ) } cleanup` , {
133+ cwd : packageDir ,
134+ } ) ;
135+ }
136+
105137function formatGitStatus ( statusLines ) {
106138 const preview = statusLines . slice ( 0 , 10 ) . join ( "\n" ) ;
107139 const remainder =
@@ -177,12 +209,15 @@ async function main() {
177209 const skipPackPreview = args . includes ( "--skip-pack-preview" ) ;
178210 const tag =
179211 args . find ( ( arg ) => arg . startsWith ( "--tag=" ) ) ?. split ( "=" ) [ 1 ] || "latest" ;
212+ validateNpmTag ( tag ) ;
180213
181214 console . log ( "" ) ;
182215 log ( "📦 Publishing react-native-nitro-storage" , "bold" ) ;
183216 console . log ( "" ) ;
184217
185218 const version = getPackageVersion ( ) ;
219+ cleanupPackageDocs ( ) ;
220+
186221 log ( `Version: ${ version } ` , "cyan" ) ;
187222 log ( `Tag: ${ tag } ` , "cyan" ) ;
188223 if ( isDryRun ) {
@@ -220,35 +255,33 @@ async function main() {
220255 console . log ( "" ) ;
221256 }
222257
223- runCheck (
224- "🧹 Running lint..." ,
225- `bun run lint -- --filter=${ packageFilter } ` ,
226- { cwd : projectRoot }
227- ) ;
258+ runCheck ( "🧹 Running lint..." , `bun run lint -- --filter=${ packageFilter } ` , {
259+ cwd : projectRoot ,
260+ } ) ;
228261 runCheck (
229262 "🎨 Running format check..." ,
230263 `bun run format:check -- --filter=${ packageFilter } ` ,
231- { cwd : projectRoot }
264+ { cwd : projectRoot } ,
232265 ) ;
233266 runCheck (
234267 "📝 Running typecheck..." ,
235268 `bun run typecheck -- --filter=${ packageFilter } ` ,
236- { cwd : projectRoot }
269+ { cwd : projectRoot } ,
237270 ) ;
238271 runCheck (
239272 "🔎 Running type-surface checks..." ,
240273 `bun run test:types -- --filter=${ packageFilter } ` ,
241- { cwd : projectRoot }
274+ { cwd : projectRoot } ,
242275 ) ;
243276 runCheck (
244277 "🧪 Running unit tests..." ,
245278 `bun run test -- --filter=${ packageFilter } ` ,
246- { cwd : projectRoot }
279+ { cwd : projectRoot } ,
247280 ) ;
248281 runCheck (
249282 "🧪 Running C++ tests..." ,
250283 `bun run test:cpp -- --filter=${ packageFilter } ` ,
251- { cwd : projectRoot }
284+ { cwd : projectRoot } ,
252285 ) ;
253286 runCheck (
254287 "🏗️ Preparing package artifacts..." ,
@@ -261,7 +294,7 @@ async function main() {
261294 "bun run test:cpp" ,
262295 "bun run check:pack" ,
263296 ] . join ( " && " ) ,
264- { cwd : packageDir }
297+ { cwd : packageDir } ,
265298 ) ;
266299
267300 if ( ! skipPackPreview ) {
@@ -275,10 +308,10 @@ async function main() {
275308 if ( packSummary ) {
276309 const packageSize = packSummary . packageSize ?? packSummary . size ;
277310 console . log (
278- ` • tarball: ${ packSummary . filename } (${ formatBytes ( packageSize ) } )`
311+ ` • tarball: ${ packSummary . filename } (${ formatBytes ( packageSize ) } )` ,
279312 ) ;
280313 console . log (
281- ` • unpacked: ${ formatBytes ( packSummary . unpackedSize ) } , files: ${ packSummary . files ?. length ?? "?" } `
314+ ` • unpacked: ${ formatBytes ( packSummary . unpackedSize ) } , files: ${ packSummary . files ?. length ?? "?" } ` ,
282315 ) ;
283316 }
284317 console . log ( "" ) ;
@@ -295,22 +328,33 @@ async function main() {
295328 }
296329
297330 if ( isDryRun ) {
298- log ( "🏃 Dry run complete! Package is ready to publish." , "green" ) ;
331+ log ( "🏃 Running npm publish dry-run..." , "cyan" ) ;
332+ const dryPublishCommand = `npm publish --dry-run --tag ${ shellQuote ( tag ) } --access public` ;
333+ if ( ! execCommand ( dryPublishCommand , { cwd : packageDir } ) ) {
334+ log ( "✗ npm publish dry-run failed" , "red" ) ;
335+ cleanupPackageDocs ( ) ;
336+ process . exit ( 1 ) ;
337+ }
338+ cleanupPackageDocs ( ) ;
339+ console . log ( "" ) ;
340+ log ( "✅ Dry run complete. Package is ready to publish." , "green" ) ;
299341 log (
300342 `Run without --dry-run${ yes ? "" : " --yes" } to publish version ${ version } ` ,
301- "cyan"
343+ "cyan" ,
302344 ) ;
303345 } else {
304346 log ( "🚀 Publishing to npm..." , "cyan" ) ;
305- const publishCommand = `npm publish --tag ${ tag } --access public${ isCI ? " --provenance" : "" } ` ;
347+ const publishCommand = `npm publish --tag ${ shellQuote ( tag ) } --access public${ isCI ? " --provenance" : "" } ` ;
306348 if ( ! execCommand ( publishCommand , { cwd : packageDir } ) ) {
307349 log ( "✗ Publish failed" , "red" ) ;
350+ cleanupPackageDocs ( ) ;
308351 process . exit ( 1 ) ;
309352 }
353+ cleanupPackageDocs ( ) ;
310354 console . log ( "" ) ;
311355 log (
312356 `✅ Successfully published react-native-nitro-storage@${ version } ` ,
313- "green"
357+ "green" ,
314358 ) ;
315359 log ( ` https://www.npmjs.com/package/react-native-nitro-storage` , "cyan" ) ;
316360 }
0 commit comments