Skip to content

Commit

Permalink
feat: support version check between @ice/app and @ice/runtime (alibab…
Browse files Browse the repository at this point in the history
…a#6151)

* feat: support version check between @ice/app and @ice/runtime

* fix: update lock
  • Loading branch information
ClarkXia authored Apr 14, 2023
1 parent 4763bc7 commit 9de09ee
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/friendly-lions-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ice/runtime': patch
'@ice/app': patch
---

feat: support version check between @ice/app and @ice/runtime
6 changes: 4 additions & 2 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
"!esm/**/*.map",
"templates",
"openChrome.applescript",
"*.d.ts"
"*.d.ts",
"scripts"
],
"engines": {
"node": ">=14.19.0",
"npm": ">=3.0.0"
},
"scripts": {
"watch": "tsc -w",
"build": "tsc"
"build": "tsc",
"postinstall": "node ./scripts/postinstall.mjs"
},
"author": "ice-admin",
"license": "MIT",
Expand Down
20 changes: 20 additions & 0 deletions packages/ice/scripts/postinstall.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createRequire } from 'module';
import fs from 'fs';
import semver from 'semver';

const require = createRequire(import.meta.url);
// Only change this when you release a version which break the usage of runtime generation.
// TODO modify valid version to 1.2.0 after version is updated, otherwise it will cause build error.
const RUNTIME_VALID_VERSION = '>=1.1.0';
try {
// @ice/runtime has defined package.json exports, so we can use require.resolve to get the package.json path.
const packageJsonPath = require.resolve('@ice/runtime/package.json');
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
if (!semver.satisfies(pkg.version, RUNTIME_VALID_VERSION)) {
console.log(`Detect @ice/runtime version is ${pkg.version}, Please update @ice/runtime to ${RUNTIME_VALID_VERSION}`);
// Break the process while @ice/runtime version is not valid.
process.exit(1);
}
} catch (e) {
// Ignore errors while @ice/runtime is not installed.
}
9 changes: 6 additions & 3 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"esm",
"!esm/**/*.map",
"templates",
"*.d.ts"
"*.d.ts",
"scripts"
],
"author": "ICE",
"license": "MIT",
Expand All @@ -30,7 +31,8 @@
"homepage": "https://v3.ice.work",
"scripts": {
"watch": "tsc -w",
"build": "tsc"
"build": "tsc",
"postinstall": "node ./scripts/postinstall.mjs"
},
"devDependencies": {
"@types/react": "^18.0.8",
Expand All @@ -48,7 +50,8 @@
"fs-extra": "^10.0.0",
"history": "^5.3.0",
"htmlparser2": "^8.0.1",
"react-router-dom": "6.10.0"
"react-router-dom": "6.10.0",
"semver": "^7.4.0"
},
"peerDependencies": {
"react": "^18.1.0",
Expand Down
21 changes: 21 additions & 0 deletions packages/runtime/scripts/postinstall.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createRequire } from 'module';
import fs from 'fs';
import path from 'path';
import semver from 'semver';

const require = createRequire(import.meta.url);
// Only change this when you release a version which break the usage of runtime generation.
// TODO modify valid version to 3.2.0 after version is updated, otherwise it will cause build error.
const ICE_VALID_VERSION = '>=3.1.6';
try {
const packagePath = require.resolve('@ice/app', { paths: [process.cwd()] });
const packageJsonPath = path.join(path.dirname(packagePath),'../package.json');
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
if (!semver.satisfies(pkg.version, ICE_VALID_VERSION)) {
console.log(`Detect @ice/app version is ${pkg.version}, Please update @ice/app to ${ICE_VALID_VERSION}`);
// Break the process while @ice/app version is not valid.
process.exit(1);
}
} catch (e) {
// Ignore errors while @ice/app is not installed.
}
41 changes: 25 additions & 16 deletions pnpm-lock.yaml

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

0 comments on commit 9de09ee

Please sign in to comment.