Skip to content
This repository was archived by the owner on Dec 4, 2022. It is now read-only.

Commit 1226b19

Browse files
authored
fix resolve-modules prefix with tilda to resolve according to the resolve-modules configuration and fallback to resolve from node_modules (#100)
1 parent 7c4c263 commit 1226b19

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [unreleased]
99

10+
## [2.0.9] - 2019-05-31
11+
12+
- [#1665](https://github.com/teambit/bit/issues/1665) fix resolve-modules prefix with tilda
13+
1014
## [2.0.8] - 2019-05-27
1115

1216
- add support with `optionalChaining` and `nullishCoalescingOperator` plugins (by updating node-source-walk)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bit-javascript",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"scripts": {
55
"flow": "flow; test $? -eq 0 -o $? -eq 2",
66
"lint": "eslint src && flow check || true",

src/dependency-builder/filing-cabinet/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,16 @@ function jsLookup(options: Options) {
223223
*/
224224
function cssPreprocessorLookup(options: Options) {
225225
const { filename, partial, directory, resolveConfig } = options;
226-
226+
if (resolveConfig && !isRelativeImport(partial)) {
227+
const result = resolveNonRelativePath(partial, filename, directory, resolveConfig);
228+
if (result) return result;
229+
}
227230
if (partial.startsWith('~') && !partial.startsWith('~/')) {
228231
// webpack syntax for resolving a module from node_modules
229232
debug('changing the resolver of css preprocessor to resolveWebpackPath as it has a ~ prefix');
230233
const partialWithNoTilda = partial.replace('~', '');
231234
return resolveWebpack(partialWithNoTilda, filename, directory, { extensions: styleExtensions, symlinks: false });
232235
}
233-
if (resolveConfig && !isRelativeImport(partial)) {
234-
const result = resolveNonRelativePath(partial, filename, directory, resolveConfig);
235-
if (result) return result;
236-
}
237236

238237
// Less and Sass imports are very similar
239238
return sassLookup(partial, filename, directory);

src/dependency-builder/filing-cabinet/index.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,34 @@ describe('filing-cabinet', () => {
558558
assert.equal(result, path.resolve(`${fixtures}/node_modules/bootstrap/index.scss`));
559559
});
560560
});
561+
describe('.scss with a dependency prefix with a tilda and resolve config', () => {
562+
describe('when the alias in resolve-config is resolved to an existing file', () => {
563+
it('should resolve the dependency according to the resolve-config', () => {
564+
const resolveConfig = { aliases: { '~bootstrap': path.normalize(fixtures) } };
565+
const result = cabinet({
566+
resolveConfig,
567+
partial: '~bootstrap/foo2',
568+
filename: `${fixtures}/foo.scss`,
569+
directory: fixtures
570+
});
571+
572+
assert.equal(result, path.resolve(`${fixtures}/foo2.scss`));
573+
});
574+
});
575+
describe('when the alias in resolve-config does not match the partial', () => {
576+
it('should fallback to the node-module resolution', () => {
577+
const resolveConfig = { aliases: { '~non-exist': 'some-dir' } };
578+
const result = cabinet({
579+
resolveConfig,
580+
partial: '~bootstrap/index',
581+
filename: `${fixtures}/foo.scss`,
582+
directory: fixtures
583+
});
584+
585+
assert.equal(result, path.resolve(`${fixtures}/node_modules/bootstrap/index.scss`));
586+
});
587+
});
588+
});
561589

562590
// @todo: fix.
563591
describe.skip('webpack', () => {

0 commit comments

Comments
 (0)