Skip to content

Commit b113937

Browse files
authored
[turbopack] Replace uses of globby in scripts with glob (#68493)
Replace uses of `globby` (which is not in the `package.json`) with `glob` (which is in the `package.json`). These scripts were part of the nextpack repository (RIP), and @wbinnssmith copied them over in #68471 Tested by running `pnpm pack-next`, inspecting the `tarballs` directory, installing the tarballs into shadcn-ui, and building with turbopack. `globby` and `glob` share the same API, but Next.js pulls in a pretty old version of `glob`, so some of the newer APIs don't exist, and it doesn't natively use promises: https://github.com/isaacs/node-glob/tree/v7.1.6 We could upgrade `glob` without too much pain... It's only used for `devDependencies`.
1 parent db70330 commit b113937

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

scripts/pack-next.cjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
booleanArg,
55
exec,
66
execAsyncWithOutput,
7+
glob,
78
packageFiles,
89
} = require('./pack-util.cjs')
910
const fs = require('fs')
@@ -17,8 +18,6 @@ const NEXT_PACKAGES = `${CWD}/packages`
1718
const noBuild = booleanArg(args, '--no-build')
1819

1920
;(async () => {
20-
const { globby } = await import('globby')
21-
2221
// the debuginfo on macos is much smaller, so we don't typically need to strip
2322
const DEFAULT_PACK_NEXT_COMPRESS =
2423
process.platform === 'darwin' ? 'none' : 'strip'
@@ -47,7 +46,10 @@ const noBuild = booleanArg(args, '--no-build')
4746
const NEXT_BA_TARBALL = `${TARBALLS}/next-bundle-analyzer.tar`
4847

4948
async function nextSwcBinaries() {
50-
return await globby([`${NEXT_PACKAGES}/next-swc/native/*.node`])
49+
return await glob('next-swc/native/*.node', {
50+
cwd: NEXT_PACKAGES,
51+
absolute: true,
52+
})
5153
}
5254

5355
// We use neither:

scripts/pack-util.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const { execSync, execFileSync, spawn } = require('child_process')
22
const { existsSync } = require('fs')
3+
const globOrig = require('glob')
34
const { join } = require('path')
5+
const { promisify } = require('util')
6+
7+
const glob = promisify(globOrig)
8+
exports.glob = glob
49

510
function exec(title, command, opts) {
611
if (Array.isArray(command)) {
@@ -86,7 +91,6 @@ exports.booleanArg = booleanArg
8691
const DEFAULT_GLOBS = ['**', '!target', '!node_modules', '!crates', '!.turbo']
8792
const FORCED_GLOBS = ['package.json', 'README*', 'LICENSE*', 'LICENCE*']
8893
async function packageFiles(path) {
89-
const { globby } = await import('globby')
9094
const { files = DEFAULT_GLOBS, main, bin } = require(`${path}/package.json`)
9195

9296
const allFiles = files.concat(
@@ -99,7 +103,7 @@ async function packageFiles(path) {
99103
.filter((f) => !isGlob(f) && existsSync(join(path, f)))
100104
.map((f) => f.replace(/^\.\//, ''))
101105
const globFiles = allFiles.filter(isGlob)
102-
const globbedFiles = await globby(globFiles, { cwd: path })
106+
const globbedFiles = await glob(`+(${globFiles.join('|')})`, { cwd: path })
103107
const packageFiles = [...globbedFiles, ...simpleFiles].sort()
104108
const set = new Set()
105109
return packageFiles.filter((f) => {

0 commit comments

Comments
 (0)