From 67a7a78999fe3ae36938b6f0e9fac73ec87965fb Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Fri, 6 Aug 2021 15:20:10 -0400 Subject: [PATCH 1/3] exclude node modules from user workspace resolution --- packages/cli/src/plugins/resource/plugin-user-workspace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/plugins/resource/plugin-user-workspace.js b/packages/cli/src/plugins/resource/plugin-user-workspace.js index c5a64c907..2a3d60251 100644 --- a/packages/cli/src/plugins/resource/plugin-user-workspace.js +++ b/packages/cli/src/plugins/resource/plugin-user-workspace.js @@ -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); } From a70305f6593ce26f39de5a76e67d60a5002780c1 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Fri, 6 Aug 2021 16:56:44 -0400 Subject: [PATCH 2/3] add a matching file from node modules to user workspace --- packages/cli/test/cases/develop.default/src/lit-html.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 packages/cli/test/cases/develop.default/src/lit-html.js diff --git a/packages/cli/test/cases/develop.default/src/lit-html.js b/packages/cli/test/cases/develop.default/src/lit-html.js new file mode 100644 index 000000000..5dec23c95 --- /dev/null +++ b/packages/cli/test/cases/develop.default/src/lit-html.js @@ -0,0 +1,3 @@ +// if things work correctly, this should never resolve +// https://github.com/ProjectEvergreen/greenwood/pull/687 +console.debug('its just a prank bro!'); \ No newline at end of file From 65ae5de914ce7b00092434a02a8f47dddf2cd877 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Fri, 6 Aug 2021 17:01:54 -0400 Subject: [PATCH 3/3] test for false positive --- .../develop.default/develop.default.spec.js | 36 +++++++++++++++++++ .../cases/develop.default/src/lit-html.js | 2 -- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/cli/test/cases/develop.default/develop.default.spec.js b/packages/cli/test/cases/develop.default/develop.default.spec.js index c9951b69c..f6ade8e85 100644 --- a/packages/cli/test/cases/develop.default/develop.default.spec.js +++ b/packages/cli/test/cases/develop.default/develop.default.spec.js @@ -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 = {}; diff --git a/packages/cli/test/cases/develop.default/src/lit-html.js b/packages/cli/test/cases/develop.default/src/lit-html.js index 5dec23c95..5deb23c2a 100644 --- a/packages/cli/test/cases/develop.default/src/lit-html.js +++ b/packages/cli/test/cases/develop.default/src/lit-html.js @@ -1,3 +1 @@ -// if things work correctly, this should never resolve -// https://github.com/ProjectEvergreen/greenwood/pull/687 console.debug('its just a prank bro!'); \ No newline at end of file