From 05291a8a3644a86d403bad9102d2da92ac763dae Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Mon, 10 Jul 2023 14:19:59 +0800 Subject: [PATCH] chore: restrict node version (#3120) --- .npmrc | 1 + .yarn/plugins/@yarnpkg/plugin-after-install.cjs | 9 +++++++++ .yarnrc.yml | 4 ++++ package.json | 5 ++++- scripts/check-version.mjs | 13 +++++++++++++ yarn.lock | 12 ++++++++++++ 6 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .yarn/plugins/@yarnpkg/plugin-after-install.cjs create mode 100644 scripts/check-version.mjs diff --git a/.npmrc b/.npmrc index ac5f060b27..548137ea14 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,3 @@ shell-emulator=true electron_mirror="https://cdn.npmmirror.com/binaries/electron/" +engine-strict=true diff --git a/.yarn/plugins/@yarnpkg/plugin-after-install.cjs b/.yarn/plugins/@yarnpkg/plugin-after-install.cjs new file mode 100644 index 0000000000..070ea99cb5 --- /dev/null +++ b/.yarn/plugins/@yarnpkg/plugin-after-install.cjs @@ -0,0 +1,9 @@ +/* eslint-disable */ +//prettier-ignore +module.exports = { +name: "@yarnpkg/plugin-after-install", +factory: function (require) { +var plugin=(()=>{var g=Object.create,r=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var I=t=>r(t,"__esModule",{value:!0});var i=t=>{if(typeof require!="undefined")return require(t);throw new Error('Dynamic require of "'+t+'" is not supported')};var h=(t,o)=>{for(var e in o)r(t,e,{get:o[e],enumerable:!0})},w=(t,o,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of C(o))!y.call(t,n)&&n!=="default"&&r(t,n,{get:()=>o[n],enumerable:!(e=x(o,n))||e.enumerable});return t},a=t=>w(I(r(t!=null?g(k(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var j={};h(j,{default:()=>b});var c=a(i("@yarnpkg/core")),m={afterInstall:{description:"Hook that will always run after install",type:c.SettingsType.STRING,default:""}};var u=a(i("clipanion")),d=a(i("@yarnpkg/core"));var p=a(i("@yarnpkg/shell")),l=async(t,o)=>{var f;let e=t.get("afterInstall"),n=!!((f=t.projectCwd)==null?void 0:f.endsWith(`dlx-${process.pid}`));return e&&!n?(o&&console.log("Running `afterInstall` hook..."),(0,p.execute)(e,[],{cwd:t.projectCwd||void 0})):0};var s=class extends u.Command{async execute(){let o=await d.Configuration.find(this.context.cwd,this.context.plugins);return l(o,!1)}};s.paths=[["after-install"]];var P={configuration:m,commands:[s],hooks:{afterAllInstalled:async t=>{if(await l(t.configuration,!0))throw new Error("The `afterInstall` hook failed, see output above.")}}},b=P;return j;})(); +return plugin; +} +}; diff --git a/.yarnrc.yml b/.yarnrc.yml index 6a581ec964..83ec083735 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -15,5 +15,9 @@ plugins: spec: '@yarnpkg/plugin-version' - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs spec: '@yarnpkg/plugin-workspace-tools' + - path: .yarn/plugins/@yarnpkg/plugin-after-install.cjs + spec: 'https://raw.githubusercontent.com/mhassan1/yarn-plugin-after-install/v0.3.1/bundles/@yarnpkg/plugin-after-install.js' yarnPath: .yarn/releases/yarn-3.6.0.cjs + +afterInstall: node ./scripts/check-version.mjs && yarn i18n-codegen gen && yarn husky install diff --git a/package.json b/package.json index 3947ec03a2..8bdfe36bf9 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,9 @@ "tests/kit", "tests/affine-legacy/*" ], + "engines": { + "node": ">=18.16.1 <19.0.0" + }, "scripts": { "dev": "dev-web", "dev:electron": "yarn workspace @affine/electron dev:app", @@ -37,7 +40,6 @@ "test": "ENABLE_PRELOADING=false vitest --run", "test:ui": "ENABLE_PRELOADING=false vitest --ui", "test:coverage": "ENABLE_PRELOADING=false vitest run --coverage", - "postinstall": "i18n-codegen gen && husky install", "notify": "node scripts/notify.mjs", "circular": "madge --circular --ts-config ./tsconfig.json ./apps/web/src/pages/**/*.tsx", "typecheck": "tsc -b tsconfig.json --diagnostics" @@ -97,6 +99,7 @@ "nx-cloud": "latest", "nyc": "^15.1.0", "prettier": "^3.0.0", + "semver": "^7.5.4", "serve": "^14.2.0", "ts-node": "^10.9.1", "typescript": "^5.1.6", diff --git a/scripts/check-version.mjs b/scripts/check-version.mjs new file mode 100644 index 0000000000..5f258aa7fb --- /dev/null +++ b/scripts/check-version.mjs @@ -0,0 +1,13 @@ +import semver from 'semver'; + +import packageJson from '../package.json' assert { type: 'json' }; + +const { engines } = packageJson; + +const version = engines.node; +if (!semver.satisfies(process.version, version)) { + console.log( + `Required node version ${version} not satisfied with current version ${process.version}.` + ); + process.exit(1); +} diff --git a/yarn.lock b/yarn.lock index f22f64401b..11320faada 100644 --- a/yarn.lock +++ b/yarn.lock @@ -368,6 +368,7 @@ __metadata: nx-cloud: latest nyc: ^15.1.0 prettier: ^3.0.0 + semver: ^7.5.4 serve: ^14.2.0 ts-node: ^10.9.1 typescript: ^5.1.6 @@ -27705,6 +27706,17 @@ __metadata: languageName: node linkType: hard +"semver@npm:^7.5.4": + version: 7.5.4 + resolution: "semver@npm:7.5.4" + dependencies: + lru-cache: ^6.0.0 + bin: + semver: bin/semver.js + checksum: 12d8ad952fa353b0995bf180cdac205a4068b759a140e5d3c608317098b3575ac2f1e09182206bf2eb26120e1c0ed8fb92c48c592f6099680de56bb071423ca3 + languageName: node + linkType: hard + "semver@npm:~7.0.0": version: 7.0.0 resolution: "semver@npm:7.0.0"