Unverified Commit 6839ef37 authored by Josh Story's avatar Josh Story Committed by GitHub

use `npm pack` instead of `yarn pack` (#52563)

`yarn pack` does not pack the same way that `npm pack` does. There is at least one bug with how files are treated where node_modules are ignored even inside folders defined by the files config. While this is not currently used in next.js an upcoming change will rely on it. The reason this change makes sense otherwise is we use npm to publish next and during a publish the pack from npm is used. For consistency we should use the same pack for our actions and other code that does repo setup such as `create-next-install` which is used for tests

The implementation is slightly more complicated than just replacing the pack command however. `npm pack` respects gitignore files whereas `yarn pack` does not (or at least not nested ones). For some packages the `"files"` property in package.json is set which overrides any gitignore rules however the `@next/swc` package uses a gitignore to prevent the committing of native binaries but does not use files and thus npm pack does not includes native binaries when yarn pack does. To address this the PR adds a temporary rename of the `next-swc/native/.gitignore` file which allows npm pack to mimic the yarn pack behavior. The reason I did not just add `"files"` is that this package actually publishes to many different package names on npm for each architecture and I was unsure about making changes to the package.json that would potentially affect this codepath.

In addition to those changes there are 2 `.gitignore` files that appear to be outdated and unnecessary. I removed them.
parent 9b932cc1
...@@ -142,13 +142,37 @@ module.exports = (actionInfo) => { ...@@ -142,13 +142,37 @@ module.exports = (actionInfo) => {
Array.from(pkgDatas.keys()).map(async (pkgName) => { Array.from(pkgDatas.keys()).map(async (pkgName) => {
const { pkgPath, packedPkgPath } = pkgDatas.get(pkgName) const { pkgPath, packedPkgPath } = pkgDatas.get(pkgName)
await execa('yarn', ['pack', '-f', packedPkgPath], { let cleanup = null
if (pkgName === '@next/swc') {
// next-swc uses a gitignore to prevent the committing of native builds but it doesn't
// use files in package.json because it publishes to individual packages based on architecture.
// When we used yarn to pack these packages the gitignore was ignored so the native builds were packed
// however npm does respect gitignore when packing so we need to remove it in this specific case
// to ensure the native builds are packed for use in gh actions and related scripts
await fs.rename(
path.join(pkgPath, 'native/.gitignore'),
path.join(pkgPath, 'disabled-native-gitignore')
)
cleanup = async () => {
await fs.rename(
path.join(pkgPath, 'disabled-native-gitignore'),
path.join(pkgPath, 'native/.gitignore')
)
}
}
const { stdout } = await execa('npm', ['pack'], {
cwd: pkgPath, cwd: pkgPath,
env: { env: {
...process.env, ...process.env,
COREPACK_ENABLE_STRICT: '0', COREPACK_ENABLE_STRICT: '0',
}, },
}) })
await fs.rename(path.resolve(pkgPath, stdout.trim()), packedPkgPath)
if (cleanup) {
await cleanup()
}
}) })
) )
return pkgPaths return pkgPaths
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment