diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f48df79f..0ab5e0a0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,18 +65,15 @@ jobs: - name: Install dependencies run: pnpm install - - - name: Build plugins - run: pnpm run build:plugin - name: Make Linux (x64) - run: npm run make:linux-x64 + run: pnpm run make:linux-x64 env: CI: true CI_PULL_REQUEST: ${{ github.event_name == 'pull_request' }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Make Linux (arm64) - run: npm run make:linux-arm + run: pnpm run make:linux-arm env: CI: true CI_PULL_REQUEST: ${{ github.event_name == 'pull_request' }} @@ -142,11 +139,8 @@ jobs: - name: Install dependencies run: pnpm install - - name: Build plugins - run: pnpm run build:plugin - - name: Make macOS (x64) - run: npm run make:mac-x64 + run: pnpm run make:mac-x64 env: APPLE_ID: ${{ secrets.APPLE_ID }} APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }} @@ -154,7 +148,7 @@ jobs: CI_PULL_REQUEST: ${{ github.event_name == 'pull_request' }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Make macOS (arm64) - run: npm run make:mac-arm + run: pnpm run make:mac-arm env: APPLE_ID: ${{ secrets.APPLE_ID }} APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }} @@ -223,12 +217,9 @@ jobs: - name: Add msi to path run: echo "${env:wix}bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - - name: Build plugins - run: pnpm run build:plugin # Enable x32 if someone still need it # - name: Make Windows (ia32) - # run: npm run make:win-ia32 + # run: pnpm run make:win-ia32 # env: # CSC_LINK: ${{ secrets.WIN_CERT }} # CSC_KEY_PASSWORD: ${{ secrets.WIN_CERT_PASS }} @@ -240,7 +231,7 @@ jobs: # Get-ChildItem out/make/wix/ia32 # Rename-Item -Path "out/make/wix/ia32/TidGi.msi" -NewName "Install-TidGi-Windows-ia32.msi" - name: Make Windows (x64) - run: npm run make:win-x64 + run: pnpm run make:win-x64 env: CSC_LINK: ${{ secrets.WIN_CERT }} CSC_KEY_PASSWORD: ${{ secrets.WIN_CERT_PASS }} @@ -252,7 +243,7 @@ jobs: Get-ChildItem out/make/wix/x64 Rename-Item -Path "out/make/wix/x64/TidGi.msi" -NewName "Install-TidGi-Windows-x64.msi" - name: Make Windows (arm64) - run: npm run make:win-arm + run: pnpm run make:win-arm env: CSC_LINK: ${{ secrets.WIN_CERT }} CSC_KEY_PASSWORD: ${{ secrets.WIN_CERT_PASS }} diff --git a/package.json b/package.json index 15e03fe1..5dcae83f 100644 --- a/package.json +++ b/package.json @@ -5,22 +5,22 @@ "version": "0.8.1-prerelease1", "license": "MPL 2.0", "scripts": { - "start": "npm run clean && npm run start:without-clean", - "start:without-clean": "npm run build:plugin && cross-env NODE_ENV=development electron-forge start", - "start:without-clean:debug-worker": "npm run build:plugin && cross-env NODE_ENV=development DEBUG_WORKER=true electron-forge start", - "start:without-clean:debug-main": "npm run build:plugin && cross-env NODE_ENV=development DEBUG_MAIN=true electron-forge start", + "start": "pnpm run clean && pnpm run start:without-clean", + "start:without-clean": "pnpm run build:plugin && cross-env NODE_ENV=development electron-forge start", + "start:without-clean:debug-worker": "pnpm run build:plugin && cross-env NODE_ENV=development DEBUG_WORKER=true electron-forge start", + "start:without-clean:debug-main": "pnpm run build:plugin && cross-env NODE_ENV=development DEBUG_MAIN=true electron-forge start", "build:plugin": "zx scripts/compilePlugins.mjs", - "test": "npm run clean && cross-env NODE_ENV=test npm run package && npm run test:without-package", + "test": "pnpm run clean && cross-env NODE_ENV=test pnpm run package && pnpm run test:without-package", "test:without-package": "mkdir -p logs && cross-env NODE_ENV=test cucumber-js", - "package": "npm run init:git-submodule && electron-forge package", - "make:mac-x64": "npm run init:git-submodule && cross-env NODE_ENV=production electron-forge make --platform=darwin --arch=x64", - "make:mac-arm": "npm run init:git-submodule && cross-env NODE_ENV=production electron-forge make --platform=darwin --arch=arm64", - "make:win-x64": "npm run init:git-submodule && cross-env NODE_ENV=production electron-forge make --platform=win32 --arch=x64", - "make:win-ia32": "npm run init:git-submodule && cross-env NODE_ENV=production electron-forge make --platform=win32 --arch=ia32", - "make:win-arm": "npm run init:git-submodule && cross-env NODE_ENV=production electron-forge make --platform=win32 --arch=arm64", - "make:linux-x64": "npm run init:git-submodule && cross-env NODE_ENV=production electron-forge make --platform=linux --arch=x64", - "make:linux-arm": "npm run init:git-submodule && cross-env NODE_ENV=production electron-forge make --platform=linux --arch=arm64", - "clean": "rimraf ./out ./settings-dev ./node_modules/@tiddlygit/tiddlywiki/plugins/linonetwo ./cache-database-dev ./logs ./.webpack ./node_modules/.cache && cross-env NODE_ENV=development npx ts-node scripts/developmentMkdir.ts && npm run init:git-submodule", + "package": "pnpm run init:git-submodule && pnpm run build:plugin && electron-forge package", + "make:mac-x64": "pnpm run init:git-submodule && pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make --platform=darwin --arch=x64", + "make:mac-arm": "pnpm run init:git-submodule && pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make --platform=darwin --arch=arm64", + "make:win-x64": "pnpm run init:git-submodule && pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make --platform=win32 --arch=x64", + "make:win-ia32": "pnpm run init:git-submodule && pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make --platform=win32 --arch=ia32", + "make:win-arm": "pnpm run init:git-submodule && pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make --platform=win32 --arch=arm64", + "make:linux-x64": "pnpm run init:git-submodule && pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make --platform=linux --arch=x64", + "make:linux-arm": "pnpm run init:git-submodule && pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make --platform=linux --arch=arm64", + "clean": "rimraf ./out ./settings-dev ./node_modules/@tiddlygit/tiddlywiki/plugins/linonetwo ./cache-database-dev ./logs ./.webpack ./node_modules/.cache && cross-env NODE_ENV=development npx ts-node scripts/developmentMkdir.ts && pnpm run init:git-submodule", "init:git-submodule": "git submodule update --recursive && git submodule update --remote", "lint": "eslint ./src --ext js,ts,tsx,json", "lint:fix": "eslint ./src --ext js,ts,tsx,json --fix", diff --git a/scripts/afterPack.js b/scripts/afterPack.js index cce71afe..9590a61a 100644 --- a/scripts/afterPack.js +++ b/scripts/afterPack.js @@ -35,35 +35,43 @@ exports.default = async (buildPath, electronVersion, platform, arch, callback) = await Promise.all(pathsToRemove.map((dir) => fs.remove(dir))); } /** copy npm packages with node-worker dependencies with binary or __filename usages, which can't be prepare properly by webpack */ + const tasks = []; if (['production', 'test'].includes(process.env.NODE_ENV)) { console.log('Copying tiddlywiki dependency to dist'); - await fs.copy(path.join(projectRoot, 'node_modules', '@tiddlygit', 'tiddlywiki'), path.join(cwd, 'node_modules', '@tiddlygit', 'tiddlywiki'), { dereference: true }); + tasks.push(fs.copy(path.join(projectRoot, 'node_modules', '@tiddlygit', 'tiddlywiki'), path.join(cwd, 'node_modules', '@tiddlygit', 'tiddlywiki'), { dereference: true })); // it has things like `git/bin/libexec/git-core/git-add` link to `git/bin/libexec/git-core/git`, to reduce size, so can't use `dereference: true` here. - await fs.copy(path.join(projectRoot, 'node_modules', '.pnpm', 'dugite@2.5.0', 'node_modules', 'dugite'), path.join(cwd, 'node_modules', 'dugite'), { dereference: false }); - // we only need its `main` binary - await fs.mkdirp(path.join(cwd, 'node_modules', 'app-path')); - await fs.copy(path.join(projectRoot, 'node_modules', 'app-path', 'main'), path.join(cwd, 'node_modules', 'app-path', 'main'), { dereference: true }); - await fs.copy(path.resolve(projectRoot, 'node_modules/better-sqlite3/build/Release/better_sqlite3.node'), path.resolve(cwd, 'node_modules/better-sqlite3/build/Release/better_sqlite3.node'), { dereference: true }); + tasks.push(fs.copy(path.join(projectRoot, 'node_modules', '.pnpm', 'dugite@2.5.1', 'node_modules', 'dugite'), path.join(cwd, 'node_modules', 'dugite'), { dereference: false })); + // we only need its `main` binary, no need its dependency and code, because we already copy it to src/services/native/externalApp + tasks.push(fs.mkdirp(path.join(cwd, 'node_modules', 'app-path')).then(async () => { + await fs.copy(path.join(projectRoot, 'node_modules', 'app-path', 'main'), path.join(cwd, 'node_modules', 'app-path', 'main'), { dereference: true }) + })); + tasks.push(fs.copy(path.resolve(projectRoot, 'node_modules/better-sqlite3/build/Release/better_sqlite3.node'), path.resolve(cwd, 'node_modules/better-sqlite3/build/Release/better_sqlite3.node'), { dereference: true })); + tasks.push(fs.copy(path.join(projectRoot, 'node_modules', 'zx'), path.join(cwd, 'node_modules', 'zx'), { dereference: true }).then(async () => { + // not using pnpm, because after using it, it always causing problem here, causing `Error: spawn /bin/sh ENOENT` in github actions + // it can probably being "working directory didn't exist" in https://github.com/nodejs/node/issues/9644#issuecomment-282060923 + // await exec(`pnpm i --shamefully-hoist --prod --ignore-scripts`, { cwd: path.join(cwd, 'node_modules', 'zx'), shell }); + await exec(`npm i --legacy-building`, { cwd: path.join(cwd, 'node_modules', 'zx'), shell }); + await exec(`npm i --legacy-building`, { cwd: path.join(cwd, 'node_modules', 'zx', 'node_modules', 'globby'), shell }); + await exec(`npm i --legacy-building --ignore-scripts`, { cwd: path.join(cwd, 'node_modules', 'zx', 'node_modules', 'node-fetch'), shell }); + })); const sqliteVssPackages = ['sqlite-vss-linux-x64', 'sqlite-vss-darwin-x64', 'sqlite-vss-darwin-arm64'] for (const sqliteVssPackage of sqliteVssPackages) { - try { - await fs.copy(path.resolve(projectRoot, `node_modules/${sqliteVssPackage}`), path.resolve(cwd, `node_modules/${sqliteVssPackage}`), { dereference: true }); - } catch {} + // some binary may not exist in other platforms, so allow failing here. + tasks.push(fs.copy(path.resolve(projectRoot, `node_modules/${sqliteVssPackage}`), path.resolve(cwd, `node_modules/${sqliteVssPackage}`), { dereference: true }).catch(() => {})); } - // await exec(`npm i --legacy-building`, { cwd: path.join(cwd, 'node_modules', 'app-path') }); - // await exec(`npm i --legacy-building`, { cwd: path.join(cwd, 'node_modules', 'app-path', 'node_modules', 'cross-spawn') }); - // await exec(`npm i --legacy-building`, { cwd: path.join(cwd, 'node_modules', 'app-path', 'node_modules', 'get-stream') }); - await fs.copy(path.join(projectRoot, 'node_modules', 'zx'), path.join(cwd, 'node_modules', 'zx'), { dereference: true }); - // not using pnpm, because after using it, it always causing problem here, causing `Error: spawn /bin/sh ENOENT` in github actions - // it can probably being "working directory didn't exist" in https://github.com/nodejs/node/issues/9644#issuecomment-282060923 - await exec(`npm i --legacy-building`, { cwd: path.join(cwd, 'node_modules', 'zx'), shell }); - await exec(`npm i --legacy-building`, { cwd: path.join(cwd, 'node_modules', 'zx', 'node_modules', 'globby'), shell }); - await exec(`npm i --legacy-building --ignore-scripts`, { cwd: path.join(cwd, 'node_modules', 'zx', 'node_modules', 'node-fetch'), shell }); - } - /** sign it for mac m1 https://www.zhihu.com/question/431722091/answer/1592339574 */ - if (platform === 'darwin') { - await exec(`xattr -rd com.apple.quarantine ${appPath}`, { cwd: appParentPath, shell }); } + /** sign it for mac m1 https://www.zhihu.com/question/431722091/answer/1592339574 (only work if user run this.) + * And have error + * ``` + * An unhandled rejection has occurred inside Forge: + Error: Command failed: xattr -rd com.apple.quarantine /var/folders/t3/0jyr287x3rd2m0b6ml8w4f2c0000gn/T/electron-packager/darwin-x64/TidGi-darwin-x64-8UwtyU/Electron.app + xattr: No such file: /var/folders/t3/0jyr287x3rd2m0b6ml8w4f2c0000gn/T/electron-packager/darwin-x64/TidGi-darwin-x64-8UwtyU/Electron.app/Contents/Resources/node_modules/dugite + ``` + */ + // if (platform === 'darwin') { + // await exec(`xattr -rd com.apple.quarantine ${appPath}`, { cwd: appParentPath, shell }); + // } + await Promise.all(tasks); /** complete this hook */ callback(); };