Skip to content

Commit

Permalink
Add post install script to test if SPFx version 1.12 - 1.14
Browse files Browse the repository at this point in the history
Show's message that updates are needed & instructions are in the getting started guide
  • Loading branch information
juliemturner committed May 5, 2022
1 parent b5c06c6 commit 9946ef4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"serve": "tsc -p ./debug/serve/tsconfig.json && node ./build/server/debug/serve/plumbing/run.js",
"start": "npm run serve",
"test": "tsc -p ./test/tsconfig.json && mocha --verbose --logging",
"test-build": "tsc -p ./test/tsconfig.json"
"test-build": "tsc -p ./test/tsconfig.json",
"postinstall": "node tools/postinstall/script.cjs"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -86,4 +87,4 @@
"url": "https://github.com/pnp/pnpjs/issues"
},
"homepage": "https://github.com/pnp/pnpjs"
}
}
19 changes: 19 additions & 0 deletions tools/postinstall/script.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require("fs");
const projectRoot = process.env.INIT_CWD;
const packageLoc = `${projectRoot}\\package.json`;
const packageFile = fs.readFileSync(packageLoc, "utf8");
const packageJSON = JSON.parse(packageFile);
if (packageJSON.dependencies != null) {
const spfxVersion = packageJSON.dependencies["@microsoft/sp-core-library"];
if (spfxVersion != null) {
const spfxVersionFloat = parseFloat(spfxVersion);
if (spfxVersionFloat > 1.11 && spfxVersionFloat < 1.15) {
console.log("");
console.log("\x1b[43m%s\x1b[0m", " PnPjs WARNING ");
console.log("\x1b[33m%s\x1b[0m", " The version of SPFx you are using requires an update to work with PnPjs. Please make sure to follow the getting started instructions to make the appropriate changes. ➡ https://pnp.github.io/pnpjs/getting-started/#spfx-version-1121-later");
console.log("");
}
}
} else {
console.log("Package has no dependencies");
}

0 comments on commit 9946ef4

Please sign in to comment.