Skip to content

Commit

Permalink
fix: ibmtelemetry not run in prod (#1593)
Browse files Browse the repository at this point in the history
* fix: ibmtelemetry not run in prod

* fix: remove prepare
  • Loading branch information
davidnixon committed May 9, 2024
1 parent a02a189 commit 3ae3f22
Show file tree
Hide file tree
Showing 30 changed files with 353 additions and 24 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"types": "src/index.d.ts",
"web-types": "dist/web-types.json",
"scripts": {
"postinstall": "node prepare.js && node .storybook/postinstall.js && ibmtelemetry --config=telemetry.yml",
"prepack": "pinst --disable",
"postpack": "pinst --enable",
"postinstall": "node prepare.js && node .storybook/postinstall.js",
"pack_postinstall": "ibmtelemetry --config=telemetry.yml",
"prepack": "node packrat.js --disable",
"postpack": "node packrat.js --enable",
"build": "vue-cli-service build --target lib --name carbon-vue-3 ./src/index.js --no-clean",
"lint": "vue-cli-service lint",
"build-web-types": "vue-docgen-web-types --outFile dist/web-types.json",
Expand Down Expand Up @@ -42,6 +43,7 @@
"@babel/eslint-parser": "^7.17.0",
"@commitlint/cli": "^16.3.0",
"@commitlint/config-conventional": "^16.2.4",
"@npmcli/package-json": "^5.1.0",
"@testing-library/dom": "^8.19.0",
"@testing-library/user-event": "^14.4.3",
"@testing-library/vue": "^6.6.1",
Expand All @@ -66,7 +68,6 @@
"jest": "^27.5.1",
"lerna": "^6.5.1",
"lint-staged": "^12.5.0",
"pinst": "^3.0.0",
"postcss": "^8.4.19",
"postcss-loader": "^6.2.1",
"prettier": "^2.8.0",
Expand Down
58 changes: 58 additions & 0 deletions packrat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const PackageJson = require('@npmcli/package-json');

async function prepack() {
const pkgJson = await PackageJson.load('./');
pkgJson.content.scripts['dev_postinstall'] =
pkgJson.content.scripts['postinstall'];
pkgJson.content.scripts['postinstall'] =
pkgJson.content.scripts['pack_postinstall'];
pkgJson.content.scripts['pack_postinstall'] = 'echo removed by packrat.js';
await pkgJson.save();
// eslint-disable-next-line no-console
console.log('scripts:', {
postinstall: pkgJson.content.scripts['postinstall'],
dev_postinstall: pkgJson.content.scripts['dev_postinstall'],
});
}
async function postpack() {
const pkgJson = await PackageJson.load('./');
pkgJson.content.scripts['pack_postinstall'] =
pkgJson.content.scripts['postinstall'];
pkgJson.content.scripts['postinstall'] =
pkgJson.content.scripts['dev_postinstall'];
delete pkgJson.content.scripts['dev_postinstall'];
await pkgJson.save();
// eslint-disable-next-line no-console
console.log('scripts:', {
postinstall: pkgJson.content.scripts['postinstall'],
pack_postinstall: pkgJson.content.scripts['pack_postinstall'],
});
}

if (process.argv.length !== 3) {
console.error(
'The pinst package not working for us anymore. We need two different postinstall hooks.'
);
console.error(
'1. postinstall that runs git pre-commit hooks - this is dev only'
);
console.error('2. postinstall that runs production hooks like ibmtelemetry');
console.error('This script toggles between the 2');
console.error('usage: node packrat.js');
console.error('Options');
console.error('\t--enable Enable pack (production) postinstall hook');
console.error('\t\trename postinstall to dev_postinstall');
console.error('\t\trename pack_postinstall to postinstall');
console.error('\t--disable Disable pack (production) postinstall hook');
console.error('\t\trename postinstall to pack_postinstall');
console.error('\t\trename dev_postinstall to postinstall');
process.exit(1);
}

if (process.argv[2] === '--disable') {
// eslint-disable-next-line no-console
prepack().then(() => console.log('updated package.json'));
} else if (process.argv[2] === '--enable') {
// eslint-disable-next-line no-console
postpack().then(() => console.log('updated package.json'));
} else console.error('unknown argument', process.argv[2]);
Loading

0 comments on commit 3ae3f22

Please sign in to comment.