Skip to content
Closed
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: 2 additions & 2 deletions packages/analyzer/src/javascript/resolve-specifier-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const isPathSpecifier = (s: string) => /^\.{0,2}\//.test(s);
* this parameter causes relative paths to be returns for this style.
*/
export const resolve =
(specifier: string, documentPath: string, componentInfo?: {
(specifier: string, documentPath: string, moduleDirectory = 'node_modules', componentInfo?: {
packageName: string,
rootDir: string,
componentDir: string
Expand All @@ -48,7 +48,7 @@ export const resolve =

const dependencyFilepath = nodeResolve.sync(specifier, {
basedir: dirname(importerFilepath),

moduleDirectory,
// It's invalid to load a .json or .node file as a module on the web,
// but this is what Node's resolution algorithm does
// (https://nodejs.org/api/modules.html#modules_all_together), so we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,49 @@ suite('resolve', () => {
'./node_modules/@scope/scoped/scoped.js');
});

test('non-component root to bower_components', async () => {
assert.equal(
resolve('bower_dep', rootMain, 'bower_components'), './bower_components/bower_dep/bower_dep.js');
});

test('shallow dep to scoped dep', async () => {
assert.equal(
resolve('@scope/scoped', shallowDepMain, shallowRootComponentInfo),
resolve('@scope/scoped', shallowDepMain, 'node_modules', shallowRootComponentInfo),
'../@scope/scoped/scoped.js');
});

test('scoped dep to shallow dep', async () => {
assert.equal(
resolve('shallow', scopedDepMain, shallowRootComponentInfo),
resolve('shallow', scopedDepMain, 'node_modules', shallowRootComponentInfo),
'../../shallow/shallow.js');
});

test('component-root to path', async () => {
assert.equal(
resolve('./root.js', rootMain, shallowRootComponentInfo), './root.js');
resolve('./root.js', rootMain, 'node_modules', shallowRootComponentInfo), './root.js');
});

test('component-root to shallow dep', async () => {
assert.equal(
resolve('shallow', rootMain, shallowRootComponentInfo),
resolve('shallow', rootMain, 'node_modules', shallowRootComponentInfo),
'../shallow/shallow.js');
});

test('component-root to scoped dep', async () => {
assert.equal(
resolve('@scope/scoped', rootMain, shallowRootComponentInfo),
resolve('@scope/scoped', rootMain, 'node_modules', shallowRootComponentInfo),
'../@scope/scoped/scoped.js');
});

test('scoped-component-root to shallow dep', async () => {
assert.equal(
resolve('shallow', rootMain, scopedRootComponentInfo),
resolve('shallow', rootMain, 'node_modules', scopedRootComponentInfo),
'../../shallow/shallow.js');
});

test('scoped-component-root to scoped dep', async () => {
assert.equal(
resolve('@scope/scoped', rootMain, scopedRootComponentInfo),
resolve('@scope/scoped', rootMain, 'node_modules', scopedRootComponentInfo),
'../scoped/scoped.js');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "bower_dep",
"version": "1.0.0",
"main": "bower_dep.js"
}
7 changes: 6 additions & 1 deletion packages/build/src/babel-plugin-bare-specifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ const maybeResolve = (
rootDir: rootDir!,
};
}
return resolve(specifier, filePath, componentInfo);

let moduleDirectory = 'node_modules';
if (componentDir) {
moduleDirectory = componentDir.substring(componentDir.lastIndexOf('/'), componentDir.length);
}
return resolve(specifier, filePath, moduleDirectory, componentInfo);
} catch (e) {
// `require` and `meta` are fake imports that our other build tooling
// injects, so we should not warn for them.
Expand Down
2 changes: 1 addition & 1 deletion packages/wct-browser-legacy/browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/wct-browser-legacy/browser.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/web-component-tester/browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/web-component-tester/browser.js.map

Large diffs are not rendered by default.