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

[INTERNAL] Resource#clone: Omit project association #459

Merged
merged 1 commit into from
Dec 22, 2022
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
4 changes: 0 additions & 4 deletions lib/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,6 @@ class Resource {
options.buffer = this._buffer;
}

if (this.__project) {
options.project = this.__project;
}

return options;
}

Expand Down
17 changes: 14 additions & 3 deletions lib/adapters/Memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,22 @@ class Memory extends AbstractAdapter {
const matchedPaths = micromatch(resourcePaths, patterns, {
dot: true
});
return Promise.all(matchedPaths.map((virPath) => {
return resourceMap[virPath] && resourceMap[virPath].clone();
return await Promise.all(matchedPaths.map((virPath) => {
const resource = resourceMap[virPath];
if (resource) {
return this._cloneResource(resource);
}
}));
}

async _cloneResource(resource) {
const clonedResource = await resource.clone();
if (this._project) {
clonedResource.setProject(this._project);
}
return clonedResource;
}

/**
* Locate resources by glob.
*
Expand Down Expand Up @@ -109,7 +120,7 @@ class Memory extends AbstractAdapter {
if (!resource || (options.nodir && resource.getStatInfo().isDirectory())) {
return null;
} else {
return await resource.clone();
return await this._cloneResource(resource);
}
}

Expand Down
10 changes: 2 additions & 8 deletions test/lib/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,13 @@ test("Resource: clone resource with source", async (t) => {
t.deepEqual(clonedResource2.getSource(), resource.getSource());
});

test("Resource: clone resource with project", async (t) => {
test("Resource: clone resource with project removes project", async (t) => {
t.plan(2);

const myProject = {
name: "my project"
};

const resourceOptions = {
path: "my/path/to/resource",
project: myProject
};

const resource = new Resource({
path: "my/path/to/resource",
project: myProject
Expand All @@ -362,8 +357,7 @@ test("Resource: clone resource with project", async (t) => {
t.pass("Resource cloned");

const clonedResourceProject = await clonedResource.getProject();
t.is(clonedResourceProject, resourceOptions.project, "Cloned resource should have same " +
"project reference as the original resource");
t.falsy(clonedResourceProject, "Cloned resource should not have a project");
});

test("Resource: create resource with modified source", (t) => {
Expand Down