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: improve duplicate jest-metadata detection #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"files": [
".idea/icon.svg",
"README.md",
"scripts/postinstall.js",
"src",
"dist",
"*.js",
"*.d.ts",
"*.mjs",
"./*.js",
"./*.d.ts",
"./*.mjs",
"!**/__utils__",
"!**/__tests__",
"!**/*.test.*"
Expand Down Expand Up @@ -60,6 +61,7 @@
"scripts": {
"prepare": "husky install || true",
"prepack": "tsc",
"postinstall": "node scripts/postinstall.js",
"build": "tsc",
"build:e2e": "tsc && nyc instrument --in-place dist && npm pack && mv jest-metadata-*.tgz package.tar.gz",
"docs": "typedoc",
Expand Down
25 changes: 25 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

const fs = require('node:fs');
const path = require('node:path');
const process = require('node:process');

const instances = [];

for (let cwd = process.cwd(); cwd !== path.dirname(cwd); cwd = path.dirname(cwd)) {
const anotherInstance = path.join(cwd, 'node_modules', 'jest-metadata');
if (fs.existsSync(anotherInstance)) {
instances.push(anotherInstance);
}
}

if (instances.length > 1) {
process.exitCode = 1;

console.error('\x1b[31m%s\x1b[0m', [
'[jest-metadata] postinstall script failed!',
'More than one instance of jest-metadata has been installed:',
...instances.map((dir) => `- ${dir}`),
'Please flatten your package-lock.json or yarn.lock file to resolve this issue.',
].join('\n'));
}
Loading