Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
node-version: [ 16.x, 18.x, 20.x ]
platform:
- os: ubuntu-20.04
- os: Ubuntu 22.04
shell: bash

runs-on: ${{ matrix.platform.os }}
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
matrix:
node-version: [ 16.x, 18.x, 20.x ]
platform:
- os: ubuntu-20.04
- os: Ubuntu 22.04
shell: bash
python-version: [ 3.9 ]

Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
arch: [amd64, arm64]

runs-on: ubuntu-20.04
runs-on: Ubuntu 22.04

defaults:
run:
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
name: linux-binding-release
path: |
${{ env.tarball }}
${{ env.tarball_shasum }}
${{ env.tarball_shasum }}


macos-binding-release:
Expand Down Expand Up @@ -165,15 +165,15 @@ jobs:
name: macos-binding-release
path: |
${{ env.tarball }}
${{ env.tarball_shasum }}
${{ env.tarball_shasum }}

binding-pkg-release:
strategy:
fail-fast: false
matrix:
arch: [amd64]

runs-on: ubuntu-20.04
runs-on: Ubuntu 22.04

defaults:
run:
Expand Down Expand Up @@ -225,15 +225,15 @@ jobs:
name: binding-pkg-release
path: |
${{ env.tarball }}
${{ env.tarball_shasum }}
${{ env.tarball_shasum }}

lib-release:
strategy:
fail-fast: false
matrix:
arch: [amd64]

runs-on: ubuntu-20.04
runs-on: Ubuntu 22.04

defaults:
run:
Expand Down Expand Up @@ -285,7 +285,7 @@ jobs:
name: lib-release
path: |
${{ env.tarball }}
${{ env.tarball_shasum }}
${{ env.tarball_shasum }}


release:
Expand All @@ -294,7 +294,7 @@ jobs:
matrix:
arch: [amd64]

runs-on: ubuntu-20.04
runs-on: Ubuntu 22.04
needs: [linux-binding-release, macos-binding-release, binding-pkg-release, lib-release]

defaults:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
platform:
- os: ubuntu-20.04
- os: Ubuntu 22.04
shell: bash

runs-on: ${{ matrix.platform.os }}
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/bin/rapid.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const argv = yargs
describe: 'Whether to generate package-lock.json file',
type: 'boolean',
default: true,
})
.option('single-mount', {
describe: 'Use single mount mode for monorepo projects',
type: 'boolean',
default: false,
});
},
handler: async argv => {
Expand All @@ -50,6 +55,7 @@ const argv = yargs
const productionMode = argv.production || argv.omit.includes('dev') || process.env.NODE_ENV === 'production';
const daemon = argv.daemon;
const noPackageLock = !argv['package-lock'];
const singleMount = argv['single-mount'];

const cwd = process.cwd();
const pkgRes = await util.readPkgJSON();
Expand All @@ -71,6 +77,7 @@ const argv = yargs
productionMode,
daemon,
noPackageLock,
singleMount,
});

Alert.success('🚀 Success', [
Expand Down
21 changes: 15 additions & 6 deletions packages/cli/lib/download_dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,25 @@ async function download(options) {

console.log('[rapid] generate fs meta');


const npmFs = new NpmFs(blobManager, options);
const allPkgs = await util.getAllPkgPaths(options.cwd, options.pkg);
const allPkgs = await util.getAllPkgPaths(options.cwd, options.pkg, options.singleMount);

await Promise.all(allPkgs.map(async pkgPath => {
const { tarIndex } = await util.getWorkdir(options.cwd, pkgPath);
const fsMeta = await npmFs.getFsMeta(depsTree, pkgPath);
if (options.singleMount) {
// 单挂载模式下,为根包生成一个包含所有依赖的 fsMeta
const { tarIndex } = await util.getWorkdir(options.cwd, '');
const fsMeta = await npmFs.getFsMeta(depsTree, '');
await fs.mkdir(path.dirname(tarIndex), { recursive: true });
console.log('tarIndex %s', tarIndex);
await fs.writeFile(tarIndex, JSON.stringify(fsMeta), 'utf8');
}));
} else {
// 多挂载模式,为每个包生成独立的 fsMeta
await Promise.all(allPkgs.map(async pkgPath => {
const { tarIndex } = await util.getWorkdir(options.cwd, pkgPath);
const fsMeta = await npmFs.getFsMeta(depsTree, pkgPath);
await fs.mkdir(path.dirname(tarIndex), { recursive: true });
await fs.writeFile(tarIndex, JSON.stringify(fsMeta), 'utf8');
}));
}

// FIXME atomic write
await fs.writeFile(npmCacheConfigPath, JSON.stringify(tocMap), 'utf8');
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.install = async options => {

const currentMountInfo = await util.listMountInfo();

const allPkgs = await util.getAllPkgPaths(options.cwd, options.pkg);
const allPkgs = await util.getAllPkgPaths(options.cwd, options.pkg, options.singleMount);

for (const pkgPath of allPkgs) {
const { baseDir, tarIndex, nodeModulesDir } = await util.getWorkdir(options.cwd, pkgPath);
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/lib/npm_fs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class NpmFs {
* @param {string} [options.mode] -
* @param {number} [options.uid] -
* @param {number} [options.gid] -
* @param {boolean} [options.singleMount] -
*/
constructor(blobManager, options) {
this.blobManager = blobManager;
Expand All @@ -21,13 +22,18 @@ class NpmFs {
uid: process.getuid(),
gid: process.getgid(),
mode: NpmFsMode.NPM,
singleMount: false,
}, options);
}

get mode() {
return this.options.mode;
}

get singleMount() {
return this.options.singleMount;
}

async getFsMeta(pkgLockJson, pkgPath = '') {
this.bar = new Bar({
type: 'fs meta',
Expand Down
12 changes: 9 additions & 3 deletions packages/cli/lib/npm_fs/npm_fs_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class NpmFsMetaBuilder {
this.cwd = options.cwd;
this.entryListener = options.entryListener;
this.productionMode = options.productionMode;
this.singleMount = options.singleMount;
// 项目直接依赖的 bin
this.pkgBinSet = new Set();
}
Expand All @@ -36,10 +37,13 @@ class NpmFsMetaBuilder {
const name = Util.getAliasPackageNameFromPackagePath(pkgPath, packages);
const version = pkgItem.version;
// node_modules 目录需要处理所有的提升过的依赖
// 子目录需要处理自己的依赖
if ((packageLock.isRootPkg(currentPkgPath) && pkgPath.startsWith('node_modules/')) || (!packageLock.isRootPkg(currentPkgPath) && pkgPath.startsWith(currentPkgPath))) {
// singleMount 模式下,需要一起挂载
if (this.singleMount) {
this.createPackageMeta(name, version, pkgPath, currentPkgPath, packages['']);
} else if ((packageLock.isRootPkg(currentPkgPath) && pkgPath.startsWith('node_modules/')) || (!packageLock.isRootPkg(currentPkgPath) && pkgPath.startsWith(currentPkgPath))) {
this.createPackageMeta(name, version, pkgPath, currentPkgPath, packages['']);
}

}

const blobId = this.fsMeta.blobIds[0] || 'bucket_0.stgz';
Expand All @@ -61,7 +65,9 @@ class NpmFsMetaBuilder {
}

createPackageMeta(name, version, packagePath, currentPkgPath, pkgJSON) {
packagePath = path.relative(currentPkgPath, packagePath).substring(PREFIX_LENGTH);
if (!this.singleMount) {
packagePath = path.relative(currentPkgPath, packagePath).substring(PREFIX_LENGTH);
}
const pkgId = Util.generatePackageId(name, version);

const pkg = this.blobManager.getPackage(name, version);
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/lib/npm_fs/tnpm_fs_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TnpmFsBuilder {
this.gid = options.gid;
this.productionMode = options.productionMode;
this.mode = NpmFsMode.NPMINSTALL;
this.singleMount = options.singleMount;
// fork from: https://github.com/cnpm/npminstall/blob/master/lib/install.js#L157
this.latestVersions = new Map();
this.projectVersions = new Map();
Expand Down Expand Up @@ -146,7 +147,7 @@ class TnpmFsBuilder {
this.fsMeta.addEntry(blobId, Util.generateSymbolLink(name, linkPath, this.uid, this.gid, true));
}

createPackageMeta(name, version, pkgPath) {
createPackageMeta(name, version, pkgPath, currentPkgPath, projectPkg) {
pkgPath = pkgPath.substring(PREFIX_LENGTH);
const pkgId = Util.generatePackageId(name, version);
const displayName = Util.getDisplayName({ name, version }, this.mode);
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,11 @@ exports.ensureAccess = async function ensureAccess(cwd, packageLock) {
});
};

exports.getAllPkgPaths = async function getAllPkgPaths(cwd, pkg) {
exports.getAllPkgPaths = async function getAllPkgPaths(cwd, pkg, singleMount = false) {
if (singleMount) {
// 单挂载模式下只返回根包路径
return [''];
}
const workspaces = await exports.getWorkspaces(cwd, pkg);
const allPkgs = Object.values(workspaces);
// root pkg
Expand Down
Loading