joshjohanning / joshjohanning.github.io

josh-ops.com | a devops blog
https://josh-ops.com
MIT License
8 stars 0 forks source link

GitHub Packages: Migrate npm Packages Between GitHub Instances | josh-ops #38

Open utterances-bot opened 3 months ago

utterances-bot commented 3 months ago

GitHub Packages: Migrate npm Packages Between GitHub Instances | josh-ops

Migrating npm packages stored in GitHub Packages from one instance to another

https://josh-ops.com/posts/github-packages-migrate-npm-packages/

dmtrshpv commented 3 months ago

Hey Josh,

the migration of npm packages from one github org to another one is just the scenario that I am currently fighting in my project. I came across your very nice project here (thanks for sharing it!) and instantly tried it out. The initial setup (GH cli, logins, etc) worked fine, but now I am facing one issue and thought that maybe you could have an idea what is going wrong? So after executing the .sh script with the four arguments I get the following:

npm ERR! code 1 npm ERR! path /Users/redactedPath/temp/my-package-0.1.0/package npm ERR! command failed npm ERR! command sh -c ts-node scripts/prepare.ts npm ERR! node:internal/modules/cjs/loader:1051 npm ERR! throw err; npm ERR! ^ npm ERR! npm ERR! Error: Cannot find module './prepare.ts' npm ERR! Require stack: npm ERR! - /Users/redactedPath/temp/my-package-0.1.0/package/scripts/imaginaryUncacheableRequireResolveScript npm ERR! at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15) npm ERR! at Function.resolve (node:internal/modules/helpers:136:19) npm ERR! at requireResolveNonCached (/Users/redactedPath/node_modules/ts-node/dist/bin.js:549:16) npm ERR! at getProjectSearchDir (/Users/redactedPath/node_modules/ts-node/dist/bin.js:519:40) npm ERR! at phase3 (/Users/redactedPath/node_modules/ts-node/dist/bin.js:267:27) npm ERR! at bootstrap (/Users/redactedPath/node_modules/ts-node/dist/bin.js:47:30) npm ERR! at main (/Users/redactedPath/node_modules/ts-node/dist/bin.js:33:12) npm ERR! at Object. (/Users/redactedPath/node_modules/ts-node/dist/bin.js:579:5) npm ERR! at Module._compile (node:internal/modules/cjs/loader:1241:14) npm ERR! at Module._extensions..js (node:internal/modules/cjs/loader:1295:10) { npm ERR! code: 'MODULE_NOT_FOUND', npm ERR! requireStack: [ npm ERR! '/Users/redactedPath/temp/my-package-0.1.0/package/scripts/imaginaryUncacheableRequireResolveScript' npm ERR! ] npm ERR! } npm ERR! npm ERR! Node.js v20.8.1

joshjohanning commented 3 months ago

Hmm interesting @dmtrshpv. Is it possible that there's a custom command or something that is running when we do the npm publish? That's really the only npm command I have in the script.

It's possible this package has a prepublish npm lifecycle script?

dmtrshpv commented 3 months ago

Hey @joshjohanning ,

As I wanted to exclude that it is because of the Mac I am working on, I just tried on a WSL env (there I have older npm and node versions installed) and I ended up with the same situation. More or less to get there I had to install additionally the "ts-node" npm package, therefore I just guess I am lacking some other package(s) that I can't figure out unfortunately.

BUT, after removing the "| sort -V" part from line 60, the script started with a different order and was running up until it met a package with this issue. So now I have to find out how to make it skip such packages and not crash.

BR

dmtrshpv commented 3 months ago

One more update -> after a bit of echo debugging I found that it really fails at the "npm publish" command so at line 83 after the "npm publish.." I added

|| echo "skipped package: $package_name-$version.tgz" >> /skippedPackages.txt

so that the script skips the failing packages and prints their name and version to a file. After that I will deal with these packages manually.

joshjohanning commented 3 months ago

More or less to get there I had to install additionally the "ts-node" npm package, therefore I just guess I am lacking some other package(s) that I can't figure out unfortunately.

Ahhh- that's fascinating. I just checked and I don't have ts-node on my machine where I ran the script, so good chance it is something to do with one of your packages indeed.

|| echo "skipped package: $package_name-$version.tgz" >> /skippedPackages.txt

Love your suggestion to add that line here to capture the failed packages and continue to attempt the rest. I pushed that upstream. Thank you!

dmtrshpv commented 3 months ago

Happy to be able to contribute a bit! Thanks again for sharing your script!