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

exclude node modules from user workspace resolution #687

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
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-user-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UserWorkspaceResource extends ResourceInterface {
const isAbsoluteWorkspaceFile = fs.existsSync(path.join(userWorkspace, bareUrl));
const workspaceUrl = isAbsoluteWorkspaceFile
? isAbsoluteWorkspaceFile || bareUrl === '/'
: this.resolveRelativeUrl(userWorkspace, bareUrl);
: url.indexOf('node_modules') < 0 && this.resolveRelativeUrl(userWorkspace, bareUrl);

return Promise.resolve(workspaceUrl);
}
Expand Down
36 changes: 36 additions & 0 deletions packages/cli/test/cases/develop.default/develop.default.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,42 @@ describe('Develop Greenwood With: ', function() {
});
});

// if things work correctly, this workspace file should never resolve for the equivalent node_modules file
// https://github.com/ProjectEvergreen/greenwood/pull/687
describe('Develop command specific workspace resolution when matching node_modules', function() {
let response = {};

before(async function() {
return new Promise((resolve, reject) => {
request.get(`${hostname}:${port}/lit-html.js`, (err, res, body) => {
if (err) {
reject();
}

response = res;
response.body = body;

resolve();
});
});
});

it('should return a 200 status', function(done) {
expect(response.statusCode).to.equal(200);
done();
});

it('should return the correct content type', function(done) {
expect(response.headers['content-type']).to.equal('text/javascript');
done();
});

it('should return the correct response body', function(done) {
expect(response.body).to.equal('console.debug(\'its just a prank bro!\');');
done();
});
});

// need some better 404 handling here (promise reject handling for assets and routes)
describe('Develop command with default 404 behavior', function() {
let response = {};
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/cases/develop.default/src/lit-html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.debug('its just a prank bro!');