Skip to content

Commit

Permalink
chore(pd): make esbuild find js-yaml correctly (#7598)
Browse files Browse the repository at this point in the history
* chore(pd): make esbuild find `js-yaml` correctly

For some reason, esbuild uses the upstream version of `js-yaml` rather
than the @zkochan fork. This throws a little plugin into esbuild's
resolution to resolve `js-yaml` using Node's resolvers instead, which
seems to find the correct version.

There may be a better way to do this, especially considering esbuild
does fine in the normal build of pnpm as far as I can tell... though
that may be because `tsc` does the first pass.
  • Loading branch information
stevenpetryk committed Jan 31, 2024
1 parent 977060f commit 4511aaf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pnpm/dev/pd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require('fs')
const esbuild = require('esbuild')
const pathLib = require('path')
const { createRequire } = require('module')
const { findWorkspacePackagesNoCheck } = require('@pnpm/workspace.find-packages')
const { findWorkspaceDir } = require('@pnpm/find-workspace-dir')

Expand Down Expand Up @@ -33,6 +34,18 @@ const pnpmPackageJson = JSON.parse(fs.readFileSync(pathLib.join(__dirname, 'pack
path: newPath
}
})

build.onResolve({filter: /js-yaml/}, ({ path, resolveDir, ...rest }) => {
if (path === 'js-yaml' && resolveDir.includes('lockfile/lockfile-file')) {
// Force esbuild to use the resolved js-yaml from within lockfile-file,
// since it seems to pick the wrong one otherwise.
const lockfileFileProject = pathLib.resolve(__dirname, '../../lockfile/lockfile-file/index.js')
const resolvedJsYaml = createRequire(lockfileFileProject).resolve('js-yaml')
return {
path: resolvedJsYaml
}
}
})
}
}

Expand Down

0 comments on commit 4511aaf

Please sign in to comment.