Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(install): installed version is not the one specified by the user #38

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
78 changes: 78 additions & 0 deletions src/cmd/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,84 @@ describe.sequential("install deps", () => {
"d-0.0.1/package.oo.yaml",
]));
});

it("manually specifying the version should be the highest priority", async (ctx) => {
const p = fixture("install_deps_priority");

// Publish `remote_storage` to registry
{
const remoteStorage = path.join(p, "remote_storage");
await Promise.all([
publish(path.join(remoteStorage, "a-0.0.1"), ctx.registry.endpoint, "fake-token"),
publish(path.join(remoteStorage, "a-0.0.2"), ctx.registry.endpoint, "fake-token"),
publish(path.join(remoteStorage, "b-0.0.1"), ctx.registry.endpoint, "fake-token"),
publish(path.join(remoteStorage, "b-0.0.2"), ctx.registry.endpoint, "fake-token"),
]);
}

// Create distDir
const distDir = await tempDir();

// Copy `entry` to workdir
await copyDir(path.join(p, "entry"), ctx.workdir);

const result = await install({
deps: [
{
name: "a",
version: "0.0.2",
},
{
name: "b",
version: "0.0.1",
},
],
save: true,
token: "fake-token",
workdir: ctx.workdir,
distDir,
registry: ctx.registry.endpoint,
});

expect(new Set(result.primaryDepNames)).toEqual(new Set([
"a-0.0.2",
"b-0.0.1",
]));

expect(result.deps).toStrictEqual({
"a-0.0.2": {
name: "a",
version: "0.0.2",
isAlreadyExist: false,
target: expect.any(String),
meta: expect.any(Object),
},
"b-0.0.1": {
name: "b",
version: "0.0.1",
isAlreadyExist: false,
target: expect.any(String),
meta: expect.any(Object),
},
});

const deps = (await generatePackageJson(ctx.workdir, false)).dependencies;
expect(deps).toEqual({
a: "0.0.2",
b: "0.0.1",
});

const fileList = await fg.glob(`**/${ooPackageName}`, {
cwd: distDir,
onlyFiles: true,
absolute: false,
});

expect(new Set(fileList)).toEqual(new Set([
"a-0.0.2/package.oo.yaml",
"b-0.0.1/package.oo.yaml",
]));
});
});

describe.sequential("unknown type", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ export async function installPackage(options: InstallPackageOptions): Promise<In
});

Object.keys(dependencies).forEach((key) => {
// If there is a dependency, skip it
// Because it is manually specified by the user, it has the highest priority
if (options.deps.some(dep => dep.name === key)) {
return;
}

p.push((async (key) => {
const dep: Dep = {
name: key,
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/install_deps_priority/entry/package.oo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: entry
version: 0.0.1
dependencies:
a: 0.0.1
b: 0.0.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: a
version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: a
version: 0.0.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: b
version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: b
version: 0.0.2
Loading