This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix dependencies bundling for yarn workspaces
This improves the hack which gets rid of protagonist (i.e. C++ compilation of drafter, the API Blueprint parser). When we moved dredd-transactions to the monorepo, where dependencies are managed by yarn workspaces, the hack to get rid of protagonist stopped to work. The hack relies on 'bundledDependencies', but those stopped to work. 'npm pack' cannot find the dependencies to bundle if they're in the root 'node_modules' directory. 'yarn pack' doesn't work either, it has bugs and it doesn't support 'bundledDependencies' or the workspaces very well - see yarnpkg/yarn#6794 This change overcomes the limitation by improving the prepack.js script. It now iterates over the 'bundledDependencies' and symlinks them to the local 'node_modules' directory where 'npm pack' can pick them up. After packing is done, there's a new postpack.js script, which makes sure the symlinks get cleaned up. The resulting .tgz then contains the dependencies bundled - without protagonist.
- Loading branch information
1 parent
66d6a54
commit f341455
Showing
4 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dredd-transactions-*.tgz | ||
prepack-symlinks.log | ||
/test/fixtures/**/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env node | ||
// Cleans up after the prepack.js script | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const PACKAGE_DIR = path.resolve(path.dirname(__filename), '..'); | ||
const SYMLINKS_LOG = path.join(PACKAGE_DIR, 'prepack-symlinks.log'); | ||
|
||
|
||
if (fs.existsSync(SYMLINKS_LOG)) { | ||
fs.readFileSync(SYMLINKS_LOG, 'utf8') | ||
.split('\n') | ||
.filter(line => line.trim()) | ||
.map(dependencyName => path.join(PACKAGE_DIR, 'node_modules', dependencyName)) | ||
.filter(symlinkPath => fs.existsSync(symlinkPath)) | ||
.forEach(symlinkPath => fs.unlinkSync(symlinkPath)); | ||
|
||
fs.unlinkSync(SYMLINKS_LOG); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters