Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: symlink local dep even when target dir does not exist #5253

Merged
merged 3 commits into from Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/orange-swans-relax.md
@@ -0,0 +1,6 @@
---
"@pnpm/symlink-dependency": patch
"pnpm": patch
---

Symlink a local dependency to `node_modules`, even if the target directory doesn't exist [#5219](https://github.com/pnpm/pnpm/issues/5219).
1 change: 1 addition & 0 deletions packages/symlink-dependency/jest.config.js
@@ -0,0 +1 @@
module.exports = require('../../jest.config.js')
8 changes: 5 additions & 3 deletions packages/symlink-dependency/package.json
Expand Up @@ -16,6 +16,7 @@
},
"devDependencies": {
"@pnpm/logger": "^4.0.0",
"@pnpm/prepare": "workspace:*",
"@pnpm/symlink-dependency": "workspace:*"
},
"directories": {
Expand All @@ -33,10 +34,11 @@
"repository": "https://github.com/pnpm/pnpm/blob/main/packages/symlink-dependency",
"scripts": {
"start": "tsc --watch",
"test": "pnpm run compile",
"lint": "eslint src/**/*.ts",
"test": "pnpm run compile && pnpm run _test",
"lint": "eslint src/**/*.ts test/**/*.ts",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix"
"compile": "tsc --build && pnpm run lint --fix",
"_test": "jest"
},
"dependencies": {
"@pnpm/core-loggers": "workspace:*",
Expand Down
Expand Up @@ -50,7 +50,10 @@ export default async function symlinkDirectRootDependency (
} catch (err: any) { // eslint-disable-line
if (err.code !== 'ENOENT') throw err
globalWarn(`Local dependency not found at ${dependencyLocation}`)
return
// Sometimes the linked in local package does not exist during installation
// and is created later via a build script.
// That is why we create the symlink even if the target directory does not exist.
dependencyRealLocation = dependencyLocation
}

const dest = path.join(destModulesDirReal, importAs)
Expand Down
@@ -0,0 +1,21 @@
import fs from 'fs'
import path from 'path'
import { tempDir } from '@pnpm/prepare'
import { symlinkDirectRootDependency } from '@pnpm/symlink-dependency'

test('symlink is created to directory that does not yet exist', async () => {
const tmp = tempDir(false)
const destModulesDir = path.join(tmp, 'node_modules')
const dependencyLocation = path.join(tmp, 'dep')
fs.mkdirSync(destModulesDir)
await symlinkDirectRootDependency(dependencyLocation, destModulesDir, 'dep', {
linkedPackage: {
name: 'dep',
version: '1.0.0',
},
prefix: '',
})
fs.mkdirSync(dependencyLocation)
fs.writeFileSync(path.join(dependencyLocation, 'index.js'), 'module.exports = {}')
expect(fs.existsSync(path.join(destModulesDir, 'dep/index.js'))).toBe(true)
})
3 changes: 3 additions & 0 deletions packages/symlink-dependency/tsconfig.json
Expand Up @@ -9,6 +9,9 @@
"../../typings/**/*.d.ts"
],
"references": [
{
"path": "../../privatePackages/prepare"
},
{
"path": "../core-loggers"
},
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.