diff --git a/.gitignore b/.gitignore index 31219eb..3f1b29d 100644 --- a/.gitignore +++ b/.gitignore @@ -119,3 +119,5 @@ packages/downloader/test/nginx.conf packages/binding/index.d.ts .DS_Store package-lock.json +.vscode +.node diff --git a/.mocharc-integration.yml b/.mocharc-integration.yml index 067fde9..73a191d 100644 --- a/.mocharc-integration.yml +++ b/.mocharc-integration.yml @@ -10,3 +10,4 @@ require: - intelli-espower-loader full-trace: true exit: true +parallel: false diff --git a/.mocharc.yml b/.mocharc.yml index 4d58b1a..78e043a 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -10,3 +10,4 @@ require: - intelli-espower-loader full-trace: true exit: true +parallel: false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d0df4f3..9b765d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,125 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.5.0-alpha.15](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.13...v0.5.0-alpha.15) (2024-03-11) + + +### Bug Fixes + +* fix sudo ([f33f576](https://github.com/cnpm/rapid/commit/f33f57699c28b07d570239df3cba9fcea01b49cd)) + + + + + +# [0.5.0-alpha.13](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.11...v0.5.0-alpha.13) (2024-03-08) + + +### Features + +* update link to mount ([1d44dd4](https://github.com/cnpm/rapid/commit/1d44dd469e0a9512b909efea5731909d11e0b710)) + + + + + +# [0.5.0-alpha.11](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.10...v0.5.0-alpha.11) (2024-03-05) + + +### Bug Fixes + +* del log ([423e168](https://github.com/cnpm/rapid/commit/423e168b88e12c176cb41510b2beebb177a49ba0)) + + + + + +# [0.5.0-alpha.10](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.9...v0.5.0-alpha.10) (2024-03-05) + + +### Features + +* update mac already clean ([2c13f8c](https://github.com/cnpm/rapid/commit/2c13f8caa25119cb6b2acc39ca212598130b84e4)) + + + + + +# [0.5.0-alpha.9](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.8...v0.5.0-alpha.9) (2024-03-04) + + +### Bug Fixes + +* add kill deamon in register ([0057e47](https://github.com/cnpm/rapid/commit/0057e4774bf7469db1feafe65483317171cc62c4)) + + + + + +# [0.5.0-alpha.8](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.7...v0.5.0-alpha.8) (2024-03-04) + + +### Features + +* add update deamon ([0a4a753](https://github.com/cnpm/rapid/commit/0a4a753eb274d2eab5d178160778e0061f301a2d)) +* update test ([8505bd4](https://github.com/cnpm/rapid/commit/8505bd4c42b08304c367fcaa17d970ea5775bfeb)) + + + + + +# [0.5.0-alpha.7](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.7) (2024-02-28) + + +### Features + +* update fuse backen rs path ([405b66e](https://github.com/cnpm/rapid/commit/405b66e3a0672a656f6d0af4e929b75a9f7dcf08)) + + + + + +# [0.5.0-alpha.6](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.6) (2024-02-28) + + +### Features + +* add new version ([6ad510c](https://github.com/cnpm/rapid/commit/6ad510c65ebd28122a3740a74c2b47e823362d9c)) + + + + + +# [0.5.0-alpha.5](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.5) (2024-02-27) + + +### Features + +* add new version ([615e447](https://github.com/cnpm/rapid/commit/615e447c3eb652bf671ec9add48cad008e8de23a)) + + + + + +# [0.5.0-alpha.4](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.3...v0.5.0-alpha.4) (2024-02-27) + + +### Features + +* del unionfs ([7f0afbe](https://github.com/cnpm/rapid/commit/7f0afbe9cb6e2578aef52cd9aa6036f080a013b6)) + + + + + +# [0.5.0-alpha.3](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.2...v0.5.0-alpha.3) (2024-02-27) + +**Note:** Version bump only for package cnpm-rapid-monorepo + + + + + # [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01) diff --git a/bindings/binding-darwin-amd64/CHANGELOG.md b/bindings/binding-darwin-amd64/CHANGELOG.md index 4a6289f..128e195 100644 --- a/bindings/binding-darwin-amd64/CHANGELOG.md +++ b/bindings/binding-darwin-amd64/CHANGELOG.md @@ -3,6 +3,103 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.5.0-alpha.15](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.13...v0.5.0-alpha.15) (2024-03-11) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-x64 + + + + + +# [0.5.0-alpha.13](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.11...v0.5.0-alpha.13) (2024-03-08) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-x64 + + + + + +# [0.5.0-alpha.11](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.10...v0.5.0-alpha.11) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-x64 + + + + + +# [0.5.0-alpha.10](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.9...v0.5.0-alpha.10) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-x64 + + + + + +# [0.5.0-alpha.9](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.8...v0.5.0-alpha.9) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-x64 + + + + + +# [0.5.0-alpha.8](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.7...v0.5.0-alpha.8) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-x64 + + + + + +# [0.5.0-alpha.7](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.7) (2024-02-28) + + +### Features + +* update fuse backen rs path ([405b66e](https://github.com/cnpm/rapid/commit/405b66e3a0672a656f6d0af4e929b75a9f7dcf08)) + + + + + +# [0.5.0-alpha.6](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.6) (2024-02-28) + + +### Features + +* add new version ([6ad510c](https://github.com/cnpm/rapid/commit/6ad510c65ebd28122a3740a74c2b47e823362d9c)) + + + + + +# [0.5.0-alpha.5](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.5) (2024-02-27) + + +### Features + +* add new version ([615e447](https://github.com/cnpm/rapid/commit/615e447c3eb652bf671ec9add48cad008e8de23a)) + + + + + +# [0.5.0-alpha.4](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.3...v0.5.0-alpha.4) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-x64 + + + + + +# [0.5.0-alpha.3](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.2...v0.5.0-alpha.3) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-x64 + + + + + # [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01) **Note:** Version bump only for package @cnpmjs/binding-darwin-x64 diff --git a/bindings/binding-darwin-amd64/check.js b/bindings/binding-darwin-amd64/check.js index 4947a72..afcdbaa 100644 --- a/bindings/binding-darwin-amd64/check.js +++ b/bindings/binding-darwin-amd64/check.js @@ -8,7 +8,7 @@ const checkFiles = [ 'index.node', 'nydusd', 'nydusd-bootstrap', - 'unionfs', + 'rapid_deamon', ]; for (const file of checkFiles) { diff --git a/bindings/binding-darwin-amd64/package.json b/bindings/binding-darwin-amd64/package.json index 9c2922e..9db51f7 100644 --- a/bindings/binding-darwin-amd64/package.json +++ b/bindings/binding-darwin-amd64/package.json @@ -1,6 +1,6 @@ { "name": "@cnpmjs/binding-darwin-x64", - "version": "0.4.0", + "version": "0.5.0-alpha.15", "description": "downloader darwin x64 binding", "main": "index.node", "homepage": "https://github.com/cnpm/rapid", @@ -16,7 +16,7 @@ "index.node", "nydusd", "nydusd-bootstrap", - "unionfs" + "rapid_deamon" ], "scripts": { "pack": "npm pack", diff --git a/bindings/binding-darwin-arm64/CHANGELOG.md b/bindings/binding-darwin-arm64/CHANGELOG.md index 461a742..2e0ae83 100644 --- a/bindings/binding-darwin-arm64/CHANGELOG.md +++ b/bindings/binding-darwin-arm64/CHANGELOG.md @@ -3,6 +3,103 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.5.0-alpha.15](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.13...v0.5.0-alpha.15) (2024-03-11) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 + + + + + +# [0.5.0-alpha.13](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.11...v0.5.0-alpha.13) (2024-03-08) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 + + + + + +# [0.5.0-alpha.11](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.10...v0.5.0-alpha.11) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 + + + + + +# [0.5.0-alpha.10](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.9...v0.5.0-alpha.10) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 + + + + + +# [0.5.0-alpha.9](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.8...v0.5.0-alpha.9) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 + + + + + +# [0.5.0-alpha.8](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.7...v0.5.0-alpha.8) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 + + + + + +# [0.5.0-alpha.7](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.7) (2024-02-28) + + +### Features + +* update fuse backen rs path ([405b66e](https://github.com/cnpm/rapid/commit/405b66e3a0672a656f6d0af4e929b75a9f7dcf08)) + + + + + +# [0.5.0-alpha.6](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.6) (2024-02-28) + + +### Features + +* add new version ([6ad510c](https://github.com/cnpm/rapid/commit/6ad510c65ebd28122a3740a74c2b47e823362d9c)) + + + + + +# [0.5.0-alpha.5](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.5) (2024-02-27) + + +### Features + +* add new version ([615e447](https://github.com/cnpm/rapid/commit/615e447c3eb652bf671ec9add48cad008e8de23a)) + + + + + +# [0.5.0-alpha.4](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.3...v0.5.0-alpha.4) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 + + + + + +# [0.5.0-alpha.3](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.2...v0.5.0-alpha.3) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 + + + + + # [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01) **Note:** Version bump only for package @cnpmjs/binding-darwin-arm64 diff --git a/bindings/binding-darwin-arm64/check.js b/bindings/binding-darwin-arm64/check.js index ff8dbdc..39a935b 100644 --- a/bindings/binding-darwin-arm64/check.js +++ b/bindings/binding-darwin-arm64/check.js @@ -8,7 +8,7 @@ const checkFiles = [ 'index.node', // 'nydusd', // 'nydusd-bootstrap', - 'unionfs', + 'rapid_deamon', ]; for (const file of checkFiles) { diff --git a/bindings/binding-darwin-arm64/package.json b/bindings/binding-darwin-arm64/package.json index a2cdb01..743e15c 100644 --- a/bindings/binding-darwin-arm64/package.json +++ b/bindings/binding-darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@cnpmjs/binding-darwin-arm64", - "version": "0.4.0", + "version": "0.5.0-alpha.15", "description": "downloader darwin arm64 binding", "main": "index.node", "homepage": "https://github.com/cnpm/rapid", @@ -16,7 +16,7 @@ "index.node", "nydusd", "nydusd-bootstrap", - "unionfs" + "rapid_deamon" ], "scripts": { "pack": "npm pack", diff --git a/bindings/binding-linux-amd64/CHANGELOG.md b/bindings/binding-linux-amd64/CHANGELOG.md index e586d2e..9f58e00 100644 --- a/bindings/binding-linux-amd64/CHANGELOG.md +++ b/bindings/binding-linux-amd64/CHANGELOG.md @@ -3,6 +3,103 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.5.0-alpha.15](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.13...v0.5.0-alpha.15) (2024-03-11) + +**Note:** Version bump only for package @cnpmjs/binding-linux-x64 + + + + + +# [0.5.0-alpha.13](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.11...v0.5.0-alpha.13) (2024-03-08) + +**Note:** Version bump only for package @cnpmjs/binding-linux-x64 + + + + + +# [0.5.0-alpha.11](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.10...v0.5.0-alpha.11) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding-linux-x64 + + + + + +# [0.5.0-alpha.10](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.9...v0.5.0-alpha.10) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding-linux-x64 + + + + + +# [0.5.0-alpha.9](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.8...v0.5.0-alpha.9) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding-linux-x64 + + + + + +# [0.5.0-alpha.8](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.7...v0.5.0-alpha.8) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding-linux-x64 + + + + + +# [0.5.0-alpha.7](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.7) (2024-02-28) + + +### Features + +* update fuse backen rs path ([405b66e](https://github.com/cnpm/rapid/commit/405b66e3a0672a656f6d0af4e929b75a9f7dcf08)) + + + + + +# [0.5.0-alpha.6](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.6) (2024-02-28) + + +### Features + +* add new version ([6ad510c](https://github.com/cnpm/rapid/commit/6ad510c65ebd28122a3740a74c2b47e823362d9c)) + + + + + +# [0.5.0-alpha.5](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.5) (2024-02-27) + + +### Features + +* add new version ([615e447](https://github.com/cnpm/rapid/commit/615e447c3eb652bf671ec9add48cad008e8de23a)) + + + + + +# [0.5.0-alpha.4](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.3...v0.5.0-alpha.4) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding-linux-x64 + + + + + +# [0.5.0-alpha.3](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.2...v0.5.0-alpha.3) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding-linux-x64 + + + + + # [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01) **Note:** Version bump only for package @cnpmjs/binding-linux-x64 diff --git a/bindings/binding-linux-amd64/package.json b/bindings/binding-linux-amd64/package.json index 381bd2a..eff6d58 100644 --- a/bindings/binding-linux-amd64/package.json +++ b/bindings/binding-linux-amd64/package.json @@ -1,6 +1,6 @@ { "name": "@cnpmjs/binding-linux-x64", - "version": "0.4.0", + "version": "0.5.0-alpha.15", "description": "downloader linux x64 binding", "main": "index.node", "homepage": "https://github.com/cnpm/rapid", @@ -12,7 +12,8 @@ "files": [ "index.node", "nydusd", - "nydusd-bootstrap" + "nydusd-bootstrap", + "rapid_deamon" ], "engines": { "node": ">=12.0.0" diff --git a/bindings/binding-linux-arm64/CHANGELOG.md b/bindings/binding-linux-arm64/CHANGELOG.md index 7def2f3..336b30d 100644 --- a/bindings/binding-linux-arm64/CHANGELOG.md +++ b/bindings/binding-linux-arm64/CHANGELOG.md @@ -3,6 +3,103 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.5.0-alpha.15](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.13...v0.5.0-alpha.15) (2024-03-11) + +**Note:** Version bump only for package @cnpmjs/binding-linux-arm64 + + + + + +# [0.5.0-alpha.13](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.11...v0.5.0-alpha.13) (2024-03-08) + +**Note:** Version bump only for package @cnpmjs/binding-linux-arm64 + + + + + +# [0.5.0-alpha.11](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.10...v0.5.0-alpha.11) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding-linux-arm64 + + + + + +# [0.5.0-alpha.10](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.9...v0.5.0-alpha.10) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding-linux-arm64 + + + + + +# [0.5.0-alpha.9](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.8...v0.5.0-alpha.9) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding-linux-arm64 + + + + + +# [0.5.0-alpha.8](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.7...v0.5.0-alpha.8) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding-linux-arm64 + + + + + +# [0.5.0-alpha.7](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.7) (2024-02-28) + + +### Features + +* update fuse backen rs path ([405b66e](https://github.com/cnpm/rapid/commit/405b66e3a0672a656f6d0af4e929b75a9f7dcf08)) + + + + + +# [0.5.0-alpha.6](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.6) (2024-02-28) + + +### Features + +* add new version ([6ad510c](https://github.com/cnpm/rapid/commit/6ad510c65ebd28122a3740a74c2b47e823362d9c)) + + + + + +# [0.5.0-alpha.5](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.5) (2024-02-27) + + +### Features + +* add new version ([615e447](https://github.com/cnpm/rapid/commit/615e447c3eb652bf671ec9add48cad008e8de23a)) + + + + + +# [0.5.0-alpha.4](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.3...v0.5.0-alpha.4) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding-linux-arm64 + + + + + +# [0.5.0-alpha.3](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.2...v0.5.0-alpha.3) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding-linux-arm64 + + + + + # [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01) **Note:** Version bump only for package @cnpmjs/binding-linux-arm64 diff --git a/bindings/binding-linux-arm64/package.json b/bindings/binding-linux-arm64/package.json index e156198..9fad441 100644 --- a/bindings/binding-linux-arm64/package.json +++ b/bindings/binding-linux-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@cnpmjs/binding-linux-arm64", - "version": "0.4.0", + "version": "0.5.0-alpha.15", "description": "downloader linux arm64 binding", "main": "index.node", "homepage": "https://github.com/cnpm/rapid", @@ -15,7 +15,8 @@ "files": [ "index.node", "nydusd", - "nydusd-bootstrap" + "nydusd-bootstrap", + "rapid_deamon" ], "scripts": { "pack": "npm pack", diff --git a/integration/fixtures/not-exist-lock-file/package.json b/integration/fixtures/not-exist-lock-file/package.json new file mode 100644 index 0000000..2072244 --- /dev/null +++ b/integration/fixtures/not-exist-lock-file/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "canvas": "2.9.0" + } +} \ No newline at end of file diff --git a/integration/fixtures/utils/pids.js b/integration/fixtures/utils/pids.js deleted file mode 100644 index 4e41408..0000000 --- a/integration/fixtures/utils/pids.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; -const execa = require('execa'); - -class Pids { - constructor(nodeModulesDir) { - this.nodeModulesDir = nodeModulesDir; - } - - async getPsSnapshot() { - try { - const { stdout } = await execa.command('ps aux'); - return stdout; - } catch (error) { - throw new Error(`Failed to execute 'ps aux': ${error.message}`, { cause: error }); - } - } - - async getPids() { - const pids = []; - - try { - const snapshot = await this.getPsSnapshot(); - console.log(snapshot); - if (process.platform === 'darwin') { - const overlayPattern = new RegExp(`unionfs.*?${this.nodeModulesDir}`, 'i'); - const nfsPattern = new RegExp( - `/usr/local/bin/go-nfsv4.*?${this.nodeModulesDir}`, 'i' - ); - for (const line of snapshot.split('\n')) { - if (overlayPattern.test(line)) { - const fields = line.split(/\s+/); - console.log(fields); - if (fields.length >= 11) { - const pid = parseInt(fields[1], 10) || 0; - pids.push(pid); - } - } - - if (nfsPattern.test(line)) { - const fields = line.split(/\s+/); - console.log(fields); - if (fields.length >= 11) { - const pid = parseInt(fields[1], 10) || 0; - pids.push(pid); - } - } - } - } - - return pids; - } catch (error) { - throw new Error(`Failed to get PIDs: ${error.message}`, { cause: error }); - } - } -} - -exports.Pids = Pids; diff --git a/integration/index.2.test.js b/integration/index.2.test.js index bdd2346..3919781 100644 --- a/integration/index.2.test.js +++ b/integration/index.2.test.js @@ -3,6 +3,7 @@ const fs = require('node:fs/promises'); const path = require('node:path'); const assert = require('node:assert'); +const os = require('node:os'); const coffee = require('coffee'); const semver = require('semver'); const execa = require('execa'); @@ -20,7 +21,11 @@ describe('test/index.v2.test.js', () => { let cwd; afterEach(async () => { - await clean({ cwd }); + try { + await clean({ cwd, daemon: true }); + } catch (e) { + console.warn('clean error: ', e); + } if (process.platform === 'darwin') { try { await forceExitDaemon(); @@ -28,8 +33,13 @@ describe('test/index.v2.test.js', () => { console.warn('force exit daemon error: %s', err.message); } } else { - await exitDaemon(); + try { + await exitDaemon(); + } catch (err) { + console.warn('exit daemon error: %s', err.message); + } } + }); describe('update', () => { @@ -125,8 +135,10 @@ describe('test/index.v2.test.js', () => { .end(); await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/react-jsx-parser/package.json'))); - const { stdout } = await execa.command('mount', { stdio: 'pipe' }); - assert(stdout.indexOf(cwd) > 0); + if (os.type() === 'Darwin') { + const { stdout } = await execa.command('mount', { stdio: 'pipe' }); + assert(stdout.indexOf(cwd) > 0); + } assert(require(path.join(cwd, 'node_modules/react-jsx-parser/package.json')).version === '1.29.0'); }); @@ -205,7 +217,7 @@ describe('test/index.v2.test.js', () => { }); - describe('deamon', async () => { + describe.only('deamon', async () => { it('should work', async () => { cwd = path.join(__dirname, './fixtures/esbuild'); await coffee @@ -223,9 +235,8 @@ describe('test/index.v2.test.js', () => { assert.strictEqual(dirs.filter(dir => dir.includes('esbuild')).length, 2); await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/esbuild'))); assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14'); - const nodeModulesDir = path.join(cwd, 'node_modules'); - await execa.command(`umount -f ${nodeModulesDir}`); + await execa.command('killall -9 nydusd'); await setTimeoutPromise(20000); assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14'); }); @@ -248,9 +259,8 @@ describe('test/index.v2.test.js', () => { assert.strictEqual(dirs.filter(dir => dir.includes('esbuild')).length, 2); await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/esbuild'))); assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14'); - const nodeModulesDir = path.join(cwd, 'node_modules'); - await execa.command(`umount -f ${nodeModulesDir}`); + await execa.command('killall -9 nydusd'); await setTimeoutPromise(20000); await assert.rejects(fs.stat(path.join(cwd, 'node_modules', 'esbuild/package.json'))); diff --git a/integration/index.test.js b/integration/index.test.js index 8e220bd..70841ca 100644 --- a/integration/index.test.js +++ b/integration/index.test.js @@ -16,9 +16,13 @@ const { describe('test/index.test.js', () => { let fixture; afterEach(async () => { - await clean({ - cwd: fixture, - }); + try { + await clean({ + cwd: fixture, + }); + } catch (e) { + console.warn('clean error: ', e); + } if (process.platform === 'darwin') { await forceExitDaemon(); } else { diff --git a/integration/workspaces.test.js b/integration/workspaces.test.js index 8bb2fb1..c19ed41 100644 --- a/integration/workspaces.test.js +++ b/integration/workspaces.test.js @@ -17,10 +17,14 @@ describe('test/workspaces.test.js', () => { it('should install lodash successfully', async () => { cwd = path.join(__dirname, './fixtures/workspaces'); - await clean({ - cwd, - force: true, - }); + try { + await clean({ + cwd, + force: true, + }); + } catch (e) { + console.warn('clean error: ', e); + } await install({ nydusMode: 'FUSE', cwd, diff --git a/lerna.json b/lerna.json index c74ab95..017417f 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { - "version": "0.4.0", + "version": "0.5.0-alpha.15", "lerna": "7.1.4" } diff --git a/packages/binding/CHANGELOG.md b/packages/binding/CHANGELOG.md index bc66011..fd61058 100644 --- a/packages/binding/CHANGELOG.md +++ b/packages/binding/CHANGELOG.md @@ -3,6 +3,103 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.5.0-alpha.15](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.13...v0.5.0-alpha.15) (2024-03-11) + +**Note:** Version bump only for package @cnpmjs/binding + + + + + +# [0.5.0-alpha.13](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.11...v0.5.0-alpha.13) (2024-03-08) + +**Note:** Version bump only for package @cnpmjs/binding + + + + + +# [0.5.0-alpha.11](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.10...v0.5.0-alpha.11) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding + + + + + +# [0.5.0-alpha.10](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.9...v0.5.0-alpha.10) (2024-03-05) + +**Note:** Version bump only for package @cnpmjs/binding + + + + + +# [0.5.0-alpha.9](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.8...v0.5.0-alpha.9) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding + + + + + +# [0.5.0-alpha.8](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.7...v0.5.0-alpha.8) (2024-03-04) + +**Note:** Version bump only for package @cnpmjs/binding + + + + + +# [0.5.0-alpha.7](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.7) (2024-02-28) + + +### Features + +* update fuse backen rs path ([405b66e](https://github.com/cnpm/rapid/commit/405b66e3a0672a656f6d0af4e929b75a9f7dcf08)) + + + + + +# [0.5.0-alpha.6](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.6) (2024-02-28) + + +### Features + +* add new version ([6ad510c](https://github.com/cnpm/rapid/commit/6ad510c65ebd28122a3740a74c2b47e823362d9c)) + + + + + +# [0.5.0-alpha.5](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.5) (2024-02-27) + + +### Features + +* add new version ([615e447](https://github.com/cnpm/rapid/commit/615e447c3eb652bf671ec9add48cad008e8de23a)) + + + + + +# [0.5.0-alpha.4](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.3...v0.5.0-alpha.4) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding + + + + + +# [0.5.0-alpha.3](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.2...v0.5.0-alpha.3) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/binding + + + + + # [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01) diff --git a/packages/binding/package.json b/packages/binding/package.json index 2386369..a4f846e 100644 --- a/packages/binding/package.json +++ b/packages/binding/package.json @@ -1,6 +1,6 @@ { "name": "@cnpmjs/binding", - "version": "0.4.0", + "version": "0.5.0-alpha.15", "description": "downloader binding", "main": "index.js", "files": [ @@ -18,10 +18,10 @@ "pack": "npm pack" }, "optionalDependencies": { - "@cnpmjs/binding-darwin-arm64": "^0.4.0", - "@cnpmjs/binding-darwin-x64": "^0.4.0", - "@cnpmjs/binding-linux-arm64": "^0.4.0", - "@cnpmjs/binding-linux-x64": "^0.4.0" + "@cnpmjs/binding-darwin-arm64": "^0.5.0-alpha.15", + "@cnpmjs/binding-darwin-x64": "^0.5.0-alpha.15", + "@cnpmjs/binding-linux-arm64": "^0.5.0-alpha.15", + "@cnpmjs/binding-linux-x64": "^0.5.0-alpha.15" }, "devDependencies": { "@napi-rs/cli": "^2.4.2" diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 27d284b..76da2d9 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -3,6 +3,122 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.5.0-alpha.15](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.13...v0.5.0-alpha.15) (2024-03-11) + + +### Bug Fixes + +* fix sudo ([f33f576](https://github.com/cnpm/rapid/commit/f33f57699c28b07d570239df3cba9fcea01b49cd)) + + + + + +# [0.5.0-alpha.13](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.11...v0.5.0-alpha.13) (2024-03-08) + + +### Features + +* update link to mount ([1d44dd4](https://github.com/cnpm/rapid/commit/1d44dd469e0a9512b909efea5731909d11e0b710)) + + + + + +# [0.5.0-alpha.11](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.10...v0.5.0-alpha.11) (2024-03-05) + + +### Bug Fixes + +* del log ([423e168](https://github.com/cnpm/rapid/commit/423e168b88e12c176cb41510b2beebb177a49ba0)) + + + + + +# [0.5.0-alpha.10](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.9...v0.5.0-alpha.10) (2024-03-05) + + +### Features + +* update mac already clean ([2c13f8c](https://github.com/cnpm/rapid/commit/2c13f8caa25119cb6b2acc39ca212598130b84e4)) + + + + + +# [0.5.0-alpha.9](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.8...v0.5.0-alpha.9) (2024-03-04) + + +### Bug Fixes + +* add kill deamon in register ([0057e47](https://github.com/cnpm/rapid/commit/0057e4774bf7469db1feafe65483317171cc62c4)) + + + + + +# [0.5.0-alpha.8](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.7...v0.5.0-alpha.8) (2024-03-04) + + +### Features + +* add update deamon ([0a4a753](https://github.com/cnpm/rapid/commit/0a4a753eb274d2eab5d178160778e0061f301a2d)) +* update test ([8505bd4](https://github.com/cnpm/rapid/commit/8505bd4c42b08304c367fcaa17d970ea5775bfeb)) + + + + + +# [0.5.0-alpha.7](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.7) (2024-02-28) + + +### Features + +* update fuse backen rs path ([405b66e](https://github.com/cnpm/rapid/commit/405b66e3a0672a656f6d0af4e929b75a9f7dcf08)) + + + + + +# [0.5.0-alpha.6](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.6) (2024-02-28) + + +### Features + +* add new version ([6ad510c](https://github.com/cnpm/rapid/commit/6ad510c65ebd28122a3740a74c2b47e823362d9c)) + + + + + +# [0.5.0-alpha.5](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.1...v0.5.0-alpha.5) (2024-02-27) + + +### Features + +* add new version ([615e447](https://github.com/cnpm/rapid/commit/615e447c3eb652bf671ec9add48cad008e8de23a)) + + + + + +# [0.5.0-alpha.4](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.3...v0.5.0-alpha.4) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/rapid + + + + + +# [0.5.0-alpha.3](https://github.com/cnpm/rapid/compare/v0.5.0-alpha.2...v0.5.0-alpha.3) (2024-02-27) + +**Note:** Version bump only for package @cnpmjs/rapid + + + + + # [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01) diff --git a/packages/cli/bin/rapid.js b/packages/cli/bin/rapid.js index 0fedcf2..2a3d3b7 100755 --- a/packages/cli/bin/rapid.js +++ b/packages/cli/bin/rapid.js @@ -82,6 +82,34 @@ const argv = yargs process.exit(0); }, }) + .command({ + command: 'add [packages..]', + describe: 'add packages', + handler: async () => { + const cwd = process.cwd(); + const args = process.argv.slice(3); + args.unshift('install'); + await util.runNPM(args, { + env: process.env, + cwd, + stdio: 'inherit', + }); + }, + }) + .command({ + command: 'uninstall [packages..]', + describe: 'uninstall packages', + handler: async () => { + const cwd = process.cwd(); + const args = process.argv.slice(3); + args.unshift('uninstall'); + await util.runNPM(args, { + env: process.env, + cwd, + stdio: 'inherit', + }); + }, + }) .command({ command: 'clean [path]', aliases: [ 'c', 'unmount', 'uninstall' ], diff --git a/packages/cli/lib/deamon.js b/packages/cli/lib/deamon.js index 29dfb30..62b7b5e 100644 --- a/packages/cli/lib/deamon.js +++ b/packages/cli/lib/deamon.js @@ -64,7 +64,7 @@ const delProject = async projectName => { } try { - await fs.rm(`${configPath}`); + await fs.rm(`${configPath}`, { force: true }); } catch (error) { debug('rm json error: ', error); return false; @@ -140,6 +140,22 @@ const killDeamon = async () => { }; const registerDeamon = async () => { + try { + await execa.command('killall -9 rapid_deamon'); + + await execa.command(`umount -f ${nydusdMnt}`); + + await execa.command('killall -9 nydusd'); + } catch (error) { + debug('umount deamon error: ', error); + } + + await fs.rm(deamonDir, { recursive: true, force: true }); + + await fs.mkdir(deamonDir, { recursive: true }); + + await fs.copyFile(path.join(__dirname, '../package.json'), path.join(deamonDir, 'package.json')); + const nydusConfigPath = path.join(deamonDir, 'nydus_config.json'); await fs.writeFile(nydusConfigPath, JSON.stringify({ @@ -191,16 +207,23 @@ root: }; const initDeamon = async () => { - const isRunning = await checkDeamonAlive(); - if (isRunning) { - console.info('[rapid] rapid daemon is running already.'); - return; - } - await fs.mkdir(deamonDir, { recursive: true }); + try { + const rapidVersion = require(path.join(__dirname, '../package.json')).deamonVersion; + const deamonVersion = require(path.join(deamonDir, './package.json')).deamonVersion; - await fs.mkdir(nydusdMnt, { recursive: true }); + if (rapidVersion !== deamonVersion) { + const err = '[rapid] rapid and deamon version not match'; + console.info(err); + throw Error(err); + } + const isRunning = await checkDeamonAlive(); + if (isRunning) { + console.info('[rapid] rapid daemon is running already.'); + return; + } + await fs.mkdir(deamonDir, { recursive: true }); - try { + await fs.mkdir(nydusdMnt, { recursive: true }); await fs.stat(destinationFilePath); } catch (e) { await registerDeamon(); diff --git a/packages/cli/lib/index.js b/packages/cli/lib/index.js index 7486f0c..09e13e8 100644 --- a/packages/cli/lib/index.js +++ b/packages/cli/lib/index.js @@ -1,6 +1,7 @@ 'use strict'; const fs = require('node:fs/promises'); +const os = require('node:os'); const assert = require('node:assert'); const path = require('node:path'); const downloadDependency = require('./download_dependency'); @@ -10,6 +11,7 @@ const { tarBucketsDir, NYDUS_TYPE, } = require('./constants'); +const { addProject } = require('./deamon'); const util = require('./util'); const nydusd = require('./nydusd'); const nydusdApi = require('./nydusd/nydusd_api'); @@ -38,7 +40,7 @@ exports.install = async options => { console.time(`[rapid] ${nodeModulesDir} already mounted, try to clean`); await exports.clean({ nydusMode: options.nydusMode, - cwd: mountedInfo.mountPoint, + cwd: options.cwd, pkg: options.pkg, force: true, daemon: options.daemon, @@ -63,24 +65,28 @@ exports.install = async options => { await downloadDependency.download(options); assert(Object.keys(packageLock).length, '[rapid] depsJSON invalid.'); - await nydusd.startNydusFs(options.nydusMode, options.cwd, options.pkg, options.daemon); - + const deamonConfig = await nydusd.startNydusFs(options.nydusMode, options.cwd, options.pkg, options.daemon); await util.ensureAccess(options.cwd, packageLock); - // 存放原始依赖树,用于 npm 二次更新依赖 await util.storePackageLock(options.cwd, packageLock); console.time('[rapid] run lifecycle scripts'); await options.scripts.runLifecycleScripts(mirrorConfig); + + if (options.daemon) { + await addProject(deamonConfig); + } console.timeEnd('[rapid] run lifecycle scripts'); }; exports.clean = async function clean({ nydusMode = NYDUS_TYPE.FUSE, cwd, force, pkg, daemon }) { const listInfo = await util.listMountInfo(); - if (!listInfo.length) { - console.log('[rapid] no mount info found.'); - return; + if (os.type() === 'Linux') { + if (!listInfo.length) { + console.log('[rapid] no mount info found.'); + return; + } } if (cwd.endsWith('node_modules') || cwd.endsWith('node_modules/')) { diff --git a/packages/cli/lib/nydusd/fuse_mode.js b/packages/cli/lib/nydusd/fuse_mode.js index 4b5c577..06e656c 100644 --- a/packages/cli/lib/nydusd/fuse_mode.js +++ b/packages/cli/lib/nydusd/fuse_mode.js @@ -10,17 +10,18 @@ const { unionfs, BOOTSTRAP_BIN, socketPath, + // nydusdMnt, } = require('../constants'); const { wrapSudo, getWorkdir, getAllPkgPaths, wrapRetry, - listMountInfo, + // listMountInfo, } = require('../util'); const nydusdApi = require('./nydusd_api'); const { Bar } = require('../logger'); -const { addProject, delProject, initDeamon } = require('../deamon'); +const { delProject, initDeamon } = require('../deamon'); const getProjectName = cwd => { const folderName = path.basename(cwd); @@ -45,15 +46,20 @@ async function startNydusFs(cwd, pkg, daemon) { console.log('[rapid] generate bootstrap'); await generateBootstrapFile(cwd, pkg, deamonConfig); + if (os.type() === 'Darwin') { + console.log('[rapid] init overlay, it may take a few seconds'); + await macosOverlayInit(cwd, pkg, deamonConfig); + } + console.log('[rapid] mount nydusd'); await mountNydus(cwd, pkg, deamonConfig); - console.log('[rapid] mount overlay, it may take a few seconds'); - await mountOverlay(cwd, pkg, deamonConfig); - - if (daemon) { - await addProject(deamonConfig); + if (os.type() === 'Linux') { + console.log('[rapid] mount overlay, it may take a few seconds'); + await mountOverlay(cwd, pkg, deamonConfig); } + + return deamonConfig; } async function generateBootstrapFile(cwd, pkg, config) { @@ -88,20 +94,61 @@ async function mountNydus(cwd, pkg, config) { // 需要串行 mount,并发创建时 nydusd 会出现问题 for (const pkgPath of allPkgs) { - const { dirname, bootstrap } = await getWorkdir(cwd, pkgPath); - await nydusdApi.mount(`/${dirname}`, cwd, bootstrap); + const { dirname, bootstrap, nodeModulesDir } = await getWorkdir(cwd, pkgPath); + + const nydusdConfig = await nydusdApi.mount(`/${dirname}`, cwd, bootstrap); mounts.push({ - mountpoint: `/${dirname}`, + mountpoint: `${dirname}`, socketPath, bootstrap, - nydusdConfig: JSON.parse(nydusdApi.nydusdConfig), + nydusdConfig: JSON.parse(nydusdConfig), + nodeModulesDir, }); + if (os.type() === 'Darwin') { + await fs.mkdir(nodeModulesDir, { recursive: true }); + await execa.command(`mount -o port=52100,mountport=52100,vers=4,namedattr,rwsize=262144,nobrowse -t nfs fuse-t:/rafs-/${dirname} ${nodeModulesDir}`); + } bar.update(dirname); } bar.stop(); config.nydusdApiMount = mounts; } +async function macosOverlayInit(cwd, pkg, config) { + const allPkgs = await getAllPkgPaths(cwd, pkg); + const bar = new Bar({ + type: 'overlay', + total: allPkgs.length, + }); + const overlays = []; + await Promise.all(allPkgs.map(async pkgPath => { + const { + upper, + workdir, + mnt, + overlay, + nodeModulesDir, + } = await getWorkdir(cwd, pkgPath); + await fs.mkdir(overlay, { recursive: true }); + await fs.mkdir(upper, { recursive: true }); + await fs.mkdir(workdir, { recursive: true }); + await fs.chmod(upper, 0o777); + await fs.chmod(workdir, 0o777); + const overlayConfig = { + unionfs, + upper, + mnt, + nodeModulesDir, + overlay, + workdir, + }; + bar.update(nodeModulesDir); + overlays.push(overlayConfig); + })); + bar.stop(); + config.overlays = overlays; +} + async function mountOverlay(cwd, pkg, config) { const allPkgs = await getAllPkgPaths(cwd, pkg); const bar = new Bar({ @@ -116,37 +163,21 @@ async function mountOverlay(cwd, pkg, config) { mnt, overlay, nodeModulesDir, - volumeName, + // volumeName, tmpDmg, } = await getWorkdir(cwd, pkgPath); await fs.mkdir(nodeModulesDir, { recursive: true }); await fs.mkdir(overlay, { recursive: true }); await fs.mkdir(mnt, { recursive: true }); - if (os.type() === 'Linux') { - await wrapRetry({ - cmd: async () => - await execa.command(wrapSudo(`mount -t tmpfs tmpfs ${overlay}`)), - title: 'mount tnpmfs', - }); - } else if (os.type() === 'Darwin') { - // hdiutil create -size 512m -fs "APFS" -volname "NewAPFSDisk" -type SPARSE -layout NONE -imagekey diskimage-class=CRawDiskImage loopfile.dmg - await fs.rm(tmpDmg, { force: true }); - await wrapRetry({ - cmd: async () => - await execa.command( - `hdiutil create -size 512m -fs APFS -volname ${volumeName} -type SPARSE -layout NONE -imagekey diskimage-class=CRawDiskImage ${tmpDmg}` - ), - title: 'hdiutil create', - }); - await wrapRetry({ - cmd: async () => await execa.command(`hdiutil attach -nobrowse -mountpoint ${overlay} ${tmpDmg}`), - title: 'hdiutil attach', - }); - } + await wrapRetry({ + cmd: async () => + await execa.command(wrapSudo(`mount -t tmpfs tmpfs ${overlay}`)), + title: 'mount tnpmfs', + }); await fs.mkdir(upper, { recursive: true }); await fs.mkdir(workdir, { recursive: true }); let overlayConfig = {}; - let shScript = wrapSudo(`mount \ + const shScript = wrapSudo(`mount \ -t overlay overlay \ -o lowerdir=${mnt},upperdir=${upper},workdir=${workdir} \ ${nodeModulesDir}`); @@ -159,21 +190,6 @@ ${nodeModulesDir}`); overlay, }; - if (os.type() === 'Darwin') { - shScript = `${unionfs} \ --o cow,max_files=32768 \ --o allow_other,use_ino,suid,dev,nobrowse \ -${upper}=RW:${mnt}=RO \ -${nodeModulesDir}`; - overlayConfig = { - unionfs, - upper, - mnt, - nodeModulesDir, - tmpDmg, - overlay, - }; - } // console.log('[rapid] mountOverlay: `%s`', shScript); await execa.command(shScript); bar.update(nodeModulesDir); @@ -196,47 +212,10 @@ async function endNydusFs(cwd, pkg, force = true, daemon) { ); if (os.type() === 'Darwin') { await wrapRetry({ - cmd: async () => { - const currentMountInfo = await listMountInfo(); - const mounted = currentMountInfo.find( - item => item.mountPoint === nodeModulesDir - ); - if (!mounted) { - console.log(`[rapid] ${nodeModulesDir} is unmounted, skip`); - return; - } - await execa.command(`umount ${nodeModulesDir}`); - }, + cmd: () => execa.command(`${umountCmd} ${nodeModulesDir}`), title: 'umount node_modules', - fallback: force - ? async () => { - // force 模式再次尝试 - await execa.command(`umount -f ${nodeModulesDir}`); - } - : undefined, - }); - - await wrapRetry({ - cmd: async () => { - const listInfo = await execa.command( - `hdiutil info | grep ${overlay} || echo ""`, - { - shell: true, - } - ); - if (!listInfo.stdout) { - return; - } - await execa.command(`hdiutil detach ${overlay}`); - }, - title: 'hdiutil detach', - fallback: force - ? async () => { - console.log(`[rapid] use fallback umount -f ${overlay}`); - await execa.command(`umount -f ${overlay}`); - } - : undefined, }); + await fs.rm(nodeModulesDir, { recursive: true, force: true }); } else { await wrapRetry({ cmd: () => execa.command(wrapSudo(`${umountCmd} ${nodeModulesDir}`)), diff --git a/packages/cli/lib/nydusd/index.js b/packages/cli/lib/nydusd/index.js index 914c628..dee3800 100644 --- a/packages/cli/lib/nydusd/index.js +++ b/packages/cli/lib/nydusd/index.js @@ -34,7 +34,7 @@ exports.unregisterMode = function(mode) { exports.startNydusFs = async function(mode, cwd, pkg, daemon) { const impl = fsImplMap[mode]; assert(impl, `can not find fs impl for mode: ${mode}`); - await impl.start(cwd, pkg, daemon); + return await impl.start(cwd, pkg, daemon); }; exports.endNydusFs = async function(mode, cwd, pkg, force, daemon) { diff --git a/packages/cli/lib/nydusd/nydusd_api.js b/packages/cli/lib/nydusd/nydusd_api.js index 7b3adb4..a95e530 100644 --- a/packages/cli/lib/nydusd/nydusd_api.js +++ b/packages/cli/lib/nydusd/nydusd_api.js @@ -1,6 +1,7 @@ 'use strict'; const debug = require('node:util').debuglog('rapid:nydusd_api'); +const os = require('node:os'); const fs = require('node:fs/promises'); const urllib = require('urllib'); const execa = require('execa'); @@ -71,6 +72,8 @@ async function initDaemon(nydusdBin = '') { '--mountpoint', nydusdMnt, '--apisock', socketPath, '--log-file', nydusdLogFile, + '--log-level', 'error', + '--writable', ]; subprocess = execa('sudo', args, { detached: true, @@ -83,6 +86,8 @@ async function initDaemon(nydusdBin = '') { '--mountpoint', nydusdMnt, '--apisock', socketPath, '--log-file', nydusdLogFile, + '--log-level', 'error', + '--writable', ]; subprocess = execa(nydusdBin, args, { detached: true, @@ -140,12 +145,12 @@ async function checkDaemon() { // 优雅退出 nydusd daemon async function exitDaemon() { try { - await killDeamon(); await urllib.request(`${daemonUrl}/exit`, { method: 'PUT', socketPath, dataType: 'json', }); + await killDeamon(); } catch (e) { // ignore, nydusd quits with error, but it's ok e.message = 'exit nydusd faield: ' + e.message; @@ -165,31 +170,50 @@ async function forceExitDaemon() { e.message = 'umount nydusd mnt failed: ' + e.message; console.warn(e); } - - try { - await killDeamon(); - await execa.command('killall -9 nydusd'); - } catch (e) { - // ignore, nydusd quits with error, but it's ok - e.message = 'exit nydusd failed: ' + e.message; - console.warn(e); - } } async function mount(mountpoint, cwd, bootstrap = '') { const workDir = await getWorkdir(cwd); + const config = JSON.stringify({ + rafs: { + device: { + backend: { + type: 'localfs', + config: { + dir: tarBucketsDir, + readahead: true, + }, + }, + }, + mode: 'direct', + digest_validate: false, // skip entry shasum check + iostats_files: false, // skip profile file generation + }, + ...(os.type() === 'Linux' ? {} : { + overlay: { + upper_dir: workDir.upper, + work_dir: workDir.workdir, + }, + }), + }); const result = await urllib.request(`${mountUrl}?mountpoint=${mountpoint}`, { method: 'POST', socketPath, data: { source: bootstrap || workDir.bootstrap, fs_type: 'rafs', - config: nydusdConfig, + config, }, contentType: 'json', dataType: 'json', }); debug('mount result: %j', result); + + if (os.type() === 'Darwin') { + await new Promise(resolve => setTimeout(resolve, 1000)); + } + + return config; } // 重新配置挂载点 diff --git a/packages/cli/lib/util.js b/packages/cli/lib/util.js index 480a0f0..0e350da 100644 --- a/packages/cli/lib/util.js +++ b/packages/cli/lib/util.js @@ -19,6 +19,7 @@ const { FuseDeviceError, } = require('./error'); const execa = require('execa'); +const first = require('ee-first'); const normalize = require('npm-normalize-package-bin'); const { tarBucketsDir, @@ -604,7 +605,7 @@ exports.generatePackageLock = async cwd => { let isExist = true; try { const lockPath = path.join(cwd || exports.findLocalPrefix(), './package-lock.json'); - await await fs.stat(lockPath); + await fs.stat(lockPath); } catch { isExist = false; } @@ -673,13 +674,49 @@ exports.listMountInfo = async function listMountInfo() { async function storePackageLock(cwd, packageLock) { const lockPath = path.join(cwd, 'node_modules', '.package-lock.json'); - await fs.mkdir(path.dirname(lockPath), { recursive: true }); await fs.writeFile( lockPath, JSON.stringify(packageLock, null, 2) ); } + +const awaitFirst = (emitter, events) => { + if (Array.isArray(emitter)) { + events = emitter; + emitter = this; + } + return new Promise((resolve, reject) => { + first([ + [ emitter ].concat(events), + ], (err, ee, event, args) => { + if (err) { + reject(err); + } else { + resolve({ event, args }); + } + }); + }); +}; + +const runNPM = async (args, options) => { + const npm = execa('npm', args, options); + + const eventRes = await awaitFirst(npm, [ 'exit', 'error' ]); + let [ code, signal ] = eventRes.args; + + if (process.env.ENV_TYPE || code) { + console.warn('[tnpm] subprocess:%s exit code: %s, signal: %s', args.join(' '), code, signal); + if (signal && !code) { + code = 1; + } + } + + + process.exit(code); +}; + +exports.runNPM = runNPM; exports.getWorkdir = getWorkdir; exports.validDep = validDep; exports.getDisplayName = getDisplayName; diff --git a/packages/cli/package.json b/packages/cli/package.json index c6edb57..c96ff4b 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@cnpmjs/rapid", - "version": "0.4.0", + "version": "0.5.0-alpha.15", "description": "The rapid npm installed cli built with Nydus", "main": "lib/index.js", "bin": { @@ -11,7 +11,7 @@ "lib" ], "dependencies": { - "@cnpmjs/binding": "^0.4.0", + "@cnpmjs/binding": "^0.5.0-alpha.15", "@npmcli/arborist": "^6.1.5", "@npmcli/map-workspaces": "^3.0.0", "auto-launch": "^5.0.6", @@ -20,6 +20,7 @@ "boxen": "^5.1.2", "chalk": "^4.0.0", "cli-progress": "^3.12.0", + "ee-first": "^1.1.1", "execa": "^5.1.1", "inquirer": "^8.2.6", "ms": "^0.7.1", @@ -49,5 +50,6 @@ "rapid", "npm" ], - "author": "gemwuu (https://github.com/gemwuu)" + "author": "gemwuu (https://github.com/gemwuu)", + "deamonVersion": "0.0.2" } diff --git a/packages/cli/test/package_lock.test.js b/packages/cli/test/package_lock.test.js index b3d5c79..158d6fb 100644 --- a/packages/cli/test/package_lock.test.js +++ b/packages/cli/test/package_lock.test.js @@ -5,8 +5,7 @@ const path = require('node:path'); const fs = require('node:fs/promises'); const mm = require('mm'); const PackageLock = require('../lib/package_lock').PackageLock; -const { install } = require('../lib'); -const httpclient = require('../lib/httpclient'); +const { generatePackageLock } = require('../lib/util'); const nydusd = require('../lib/nydusd'); const downloadDependency = require('../lib/download_dependency'); @@ -68,15 +67,10 @@ describe('test/package_lock.test.js', () => { mm.restore(); }); - it('should run all project installation scripts', async () => { + it('should generate package-lock.json', async () => { fixture = path.join(__dirname, './fixtures/not-exist-lock-file'); - const pkg = require(path.join(fixture, 'package.json')); - await install({ - httpclient, - pkg, - cwd: fixture, - console: global.console, - }); + + await generatePackageLock(fixture); await fs.stat(path.join(fixture, 'package-lock.json')); }); }); diff --git a/packages/cli/test/scripts.test.js b/packages/cli/test/scripts.test.js index d426021..201b9c4 100644 --- a/packages/cli/test/scripts.test.js +++ b/packages/cli/test/scripts.test.js @@ -163,6 +163,8 @@ describe('test/scripts.test.js', () => { mm(process.env, NYDUS_CSI_ROOT_ENV, 'true'); mm(process, 'cwd', () => fixtures); mm(nydusd, 'startNydusFs', async () => { }); + mm(util, 'ensureAccess', async () => { }); + mm(util, 'storePackageLock', async () => { }); mm(downloadDependency, 'download', async () => { return { depsTree: [ 1 ], diff --git a/packages/deamon/src/config.rs b/packages/deamon/src/config.rs index ed2bb74..60513c0 100644 --- a/packages/deamon/src/config.rs +++ b/packages/deamon/src/config.rs @@ -6,9 +6,10 @@ use log::{error, info}; use regex::Regex; use serde::{Deserialize, Serialize}; use serde_json::Error; +use std::os::unix::fs::PermissionsExt; use std::{path::PathBuf, process::Command}; -use crate::utils::{get_ps_snapshot, start_command}; +use crate::utils::{create_dir_if_not_exists, del_dir_if_exists, get_ps_snapshot, start_command}; // { // projectName: "", @@ -48,11 +49,26 @@ pub struct NydusdApiMount { socket_path: String, bootstrap: String, nydusd_config: NydusdConfig, + node_modules_dir: String, } #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub struct NydusdConfig { + rafs: NydusdRafsConfig, + overlay: Option, +} + +#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)] +#[serde(rename_all = "snake_case")] +pub struct NydusdOverlayConfig { + upper_dir: String, + work_dir: String, +} + +#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)] +#[serde(rename_all = "snake_case")] +pub struct NydusdRafsConfig { device: DeviceConfig, mode: String, digest_validate: bool, @@ -98,10 +114,57 @@ impl NydusdApiMount { Ok(serde_json::to_string(&reset_struce)?) } + + fn link_node_modules(&self) -> Result<()> { + let str = format!(r#"umount -f {}"#, self.node_modules_dir); + + if let Err(e) = start_command(&str) { + error!("Error executing umount: {:?}", e); + } + + create_dir_if_not_exists(self.node_modules_dir.clone())?; + + let str = format!( + r#"mount -o port=52100,mountport=52100,vers=4,namedattr,rwsize=262144,nobrowse -t nfs fuse-t:/rafs-/{} {}"#, + self.mountpoint, self.node_modules_dir + ); + + match start_command(&str) { + Ok(output) => { + if output.status.success() { + info!( + "link_node_modules success base {} target {}", + self.mountpoint, self.node_modules_dir + ); + return Ok(()); + } else { + return Err(anyhow!( + "Error executing link_node_modules, status: {:?}, stdout: {:?}, stderr: {:?}, base {}, target {}", + output.status, + std::str::from_utf8(&output.stdout)?, + std::str::from_utf8(&output.stderr)?, + self.mountpoint, + self.node_modules_dir, + )); + } + } + Err(e) => { + return Err(anyhow!( + "Error executing link_node_modules: {:?}, base {}, target {}", + e, + self.mountpoint, + self.node_modules_dir + )) + } + } + } + pub async fn restart(&self) -> Result<()> { + del_dir_if_exists(self.node_modules_dir.clone())?; + let url = Uri::new( &self.socket_path, - &format!("/api/v1/mount?mountpoint={}", self.mountpoint), + &format!("/api/v1/mount?mountpoint=/{}", self.mountpoint), ); let client = Client::unix(); @@ -116,6 +179,8 @@ impl NydusdApiMount { let response = client.request(request).await?; if (response.status() == StatusCode::OK) || (response.status() == StatusCode::NO_CONTENT) { + #[cfg(target_os = "macos")] + self.link_node_modules()?; return Ok(()); } @@ -123,6 +188,8 @@ impl NydusdApiMount { let body = String::from_utf8_lossy(&binding).to_string(); if body.contains("object or filesystem already exists") { + #[cfg(target_os = "macos")] + self.link_node_modules()?; return Ok(()); } @@ -138,11 +205,10 @@ impl NydusdApiMount { #[serde(rename_all = "camelCase")] pub struct Overlay { unionfs: Option, - workdir: Option, + workdir: String, upper: String, mnt: String, node_modules_dir: String, - tmp_dmg: String, overlay: String, } @@ -240,19 +306,9 @@ impl Overlay { } } - let workdir = match &self.workdir { - Some(s) => s, - None => { - return Err(anyhow!( - "workdir is empty, node_modules_dir is {}", - self.node_modules_dir - )) - } - }; - let mount_str = format!( r#"mount -t overlay overlay -o lowerdir={},upperdir={},workdir={} {}"#, - self.mnt, self.upper, workdir, self.node_modules_dir + self.mnt, self.upper, &self.workdir, self.node_modules_dir ); match start_command(&mount_str) { Ok(output) => { @@ -283,79 +339,18 @@ impl Overlay { } #[cfg(target_os = "macos")] - pub fn restart(&self) -> Result> { - let tmp_str = format!( - r#"hdiutil attach -nobrowse -mountpoint {} {}"#, - self.overlay, self.tmp_dmg - ); - - match start_command(&tmp_str) { - Ok(output) => { - if output.status.success() { - info!( - "Overlay restart executed successfully, mountpoint: {:?}, tmp_str: {:?}", - self.node_modules_dir, tmp_str - ); - } else { - return Err(anyhow!( - "Error executing Overlay restart: {:?}, mountpoint: {:?}, tmp_str: {:?}", - output.status, - self.node_modules_dir, - tmp_str - )); - } - } - Err(e) => { - return Err(anyhow!( - "Error executing Overlay restart command: {:?}, mountpoint: {:?}, tmp_str: {:?}", - e, - self.node_modules_dir, - tmp_str - )); - } - } - - let unionfs = match &self.unionfs { - Some(s) => s, - None => { - return Err(anyhow!( - "unionfs is empty, node_modules_dir is {}", - self.node_modules_dir - )) - } - }; - - let mount_str = format!( - r#"{} -o cow,max_files=32768 -o allow_other,use_ino,suid,dev,nobrowse {}=RW:{}=RO {}"#, - unionfs, self.upper, self.mnt, self.node_modules_dir - ); - - match start_command(&mount_str) { - Ok(output) => { - if output.status.success() { - info!( - "Overlay restart executed successfully, mountpoint: {:?}", - self.node_modules_dir - ); - } else { - return Err(anyhow!( - "Error executing Overlay restart: {:?}, mountpoint: {:?}", - output.status, - self.node_modules_dir - )); - } - } - Err(e) => { - return Err(anyhow!( - "Error executing Overlay restart command: {:?}, mountpoint: {:?}", - e, - self.node_modules_dir - )); - } - } + pub fn restart(&self) -> Result<()> { + create_dir_if_not_exists(self.overlay.clone())?; + create_dir_if_not_exists(self.upper.clone())?; + create_dir_if_not_exists(self.workdir.clone())?; + std::fs::metadata(&self.upper)? + .permissions() + .set_mode(0o777); + std::fs::metadata(&self.workdir)? + .permissions() + .set_mode(0o777); - let res = self.get_pids()?; - Ok(res) + Ok(()) } } @@ -429,6 +424,13 @@ impl ProjectConfig { return &self.project_path; } + pub fn get_node_modules_paths(&self) -> Vec { + self.nydusd_api_mount + .iter() + .map(|c| c.node_modules_dir.clone()) + .collect() + } + pub fn get_pids(&self) -> Result> { let mut pids = vec![]; @@ -440,6 +442,7 @@ impl ProjectConfig { return Ok(pids); } + #[cfg(target_os = "linux")] pub async fn restart(&self) -> Result> { for bootstrap in self.bootstraps.iter() { bootstrap.restart()?; @@ -457,6 +460,25 @@ impl ProjectConfig { Ok(pids) } + + #[cfg(target_os = "macos")] + pub async fn restart(&self) -> Result> { + use std::vec; + + for bootstrap in self.bootstraps.iter() { + bootstrap.restart()?; + } + + for overlay in self.overlays.iter() { + overlay.restart()?; + } + + for mount in self.nydusd_api_mount.iter() { + mount.restart().await?; + } + + Ok(vec![]) + } } pub async fn process_json_files_in_folder( @@ -558,6 +580,9 @@ impl NydusConfig { &self.socket_path, "--log-file", &self.nydusd_log_file, + "--log-level", + "error", + "--writable", ]); std::thread::spawn(move || { let _ = command.output(); diff --git a/packages/deamon/src/pid.rs b/packages/deamon/src/pid.rs index 5e73c08..3ee5110 100644 --- a/packages/deamon/src/pid.rs +++ b/packages/deamon/src/pid.rs @@ -1,4 +1,5 @@ use super::config::ProjectConfig; +use crate::utils::list_mount_info; use anyhow::{anyhow, Result}; use log::{debug, error, info}; use nix::sys::signal::{self, Signal}; @@ -150,12 +151,7 @@ async fn check_project(project: &mut ProjectInfo) -> Result<()> { &project.pids ); - #[cfg(target_os = "macos")] - if (&project.pids).len() == 0 { - project.restart().await?; - return Ok(()); - } - if !is_alive(&project.pids, project.config.get_project_path()).await { + if !is_alive(&project.pids, project.config.get_node_modules_paths()).await { info!("{:?} will be check", project.config.get_project_path()); if let Err(e) = project.kill_pids() { error!( @@ -170,8 +166,9 @@ async fn check_project(project: &mut ProjectInfo) -> Result<()> { Ok(()) } -async fn is_alive(pids: &Vec, directory_path: &str) -> bool { +async fn is_alive(pids: &Vec, directory_path: Vec) -> bool { let mut is_pid_alive = true; + #[cfg(target_os = "linux")] for pid in pids.iter() { debug!("directory_path: {:?}, pid: {:?}", directory_path, pid); let output = Command::new("kill").arg("-0").arg(pid.to_string()).output(); @@ -183,11 +180,23 @@ async fn is_alive(pids: &Vec, directory_path: &str) -> bool { } } + #[cfg(target_os = "macos")] + { + match list_mount_info() { + Ok(mounts) => { + is_pid_alive = directory_path.iter().all(|item| mounts.contains(item)); + } + Err(e) => { + error!("list_mount_info error: {:?}", e); + } + } + } + if !is_pid_alive { return false; } - - match timeout(Duration::from_secs(1), read_directory(directory_path)).await { + info!("directory_path: {:?}, pids: {:?}", directory_path, pids); + match timeout(Duration::from_secs(1), read_directorys(&directory_path)).await { Ok(result) => match result { Ok(_) => true, Err(e) => { @@ -202,13 +211,15 @@ async fn is_alive(pids: &Vec, directory_path: &str) -> bool { } } -async fn read_directory(path: &str) -> Result> { - let mut dir = read_dir(path).await?; - +async fn read_directorys(paths: &Vec) -> Result> { let mut entries = vec![]; - while let Some(entry) = dir.next_entry().await? { - entries.push(entry); + for path in paths { + let mut dir = read_dir(path).await?; + + while let Some(entry) = dir.next_entry().await? { + entries.push(entry); + } } Ok(entries) diff --git a/packages/deamon/src/utils.rs b/packages/deamon/src/utils.rs index 6cb4016..35f6190 100644 --- a/packages/deamon/src/utils.rs +++ b/packages/deamon/src/utils.rs @@ -5,6 +5,22 @@ use std::fs::File; use std::io; use std::process::{Command, Output}; +pub fn del_dir_if_exists(folder_path: String) -> Result<()> { + let path = std::path::Path::new(&folder_path); + if path.exists() { + std::fs::remove_dir_all(folder_path.clone())?; + } + Ok(()) +} + +pub fn create_dir_if_not_exists(folder_path: String) -> Result<()> { + let path = std::path::Path::new(&folder_path); + if !path.exists() { + std::fs::create_dir_all(folder_path.clone())?; + } + Ok(()) +} + pub fn get_ps_snapshot() -> Result { let ps_output = Command::new("ps").arg("aux").output()?; @@ -62,6 +78,36 @@ pub fn check_and_create_file(file_path: &str) -> io::Result { } } +pub fn list_mount_info() -> Result> { + let output = Command::new("mount").output()?; + + let stdout = String::from_utf8_lossy(&output.stdout); + let mount_lines: Vec<&str> = stdout.split('\n').collect(); + + let filtered_mounts: Vec = mount_lines + .iter() + .filter(|&&line| { + line.contains("node_modules") + && (line.starts_with("fuse-t:/") || line.starts_with("overlay")) + }) + .map(|&line| { + let parts: Vec<&str> = line.split_whitespace().collect(); + let device = parts[0].to_string(); + let mount_point = parts[2].to_string(); + // MountInfo { + // device, + // mount_point, + // } + mount_point + }) + .collect(); + + let mut sorted_mounts = filtered_mounts; + sorted_mounts.sort_by(|a, b| a.cmp(&b)); + + Ok(sorted_mounts) +} + #[cfg(test)] mod test { use super::*; diff --git a/scripts/download_nydusd.sh b/scripts/download_nydusd.sh index 10af4fc..5c7e6bb 100755 --- a/scripts/download_nydusd.sh +++ b/scripts/download_nydusd.sh @@ -3,7 +3,7 @@ set -eux # Define versions -NYDUS_VERSION=v2.0.0-cnpm.3 +NYDUS_VERSION=v2.0.0-cnpm.alpha.2 os="${BUILD_OS:-darwin}" arch="${BUILD_ARCH:-$(uname -m)}" @@ -43,18 +43,5 @@ download_nydusd() { rm nydus.tgz } -# Function to download and extract unionfs -download_union_fs() { - version=$1 - os=$2 - arch=$3 - if [[ "${os}" == "darwin" ]]; then - download "https://github.com/cnpm/unionfs-fuse/releases/download/${version}/unionfs-refs-tags-${version}-${os}-${arch}.tgz" unionfs.tgz - tar -xzf unionfs.tgz -C "$(pwd)/bindings/binding-${os}-${arch}" --strip-components 1 unionfs/unionfs - rm unionfs.tgz - fi -} - # Download and extract nydusd and unionfs download_nydusd ${NYDUS_VERSION} ${os} ${arch} -download_union_fs ${UNION_FS_VERSION} ${os} ${arch}