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

Commit

Permalink
fix resolve-modules prefix with tilda to resolve according to the res…
Browse files Browse the repository at this point in the history
…olve-modules configuration and fallback to resolve from node_modules (#100)
  • Loading branch information
davidfirst authored May 31, 2019
1 parent 7c4c263 commit 1226b19
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

## [2.0.9] - 2019-05-31

- [#1665](https://github.com/teambit/bit/issues/1665) fix resolve-modules prefix with tilda

## [2.0.8] - 2019-05-27

- add support with `optionalChaining` and `nullishCoalescingOperator` plugins (by updating node-source-walk)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bit-javascript",
"version": "2.0.8",
"version": "2.0.9",
"scripts": {
"flow": "flow; test $? -eq 0 -o $? -eq 2",
"lint": "eslint src && flow check || true",
Expand Down
9 changes: 4 additions & 5 deletions src/dependency-builder/filing-cabinet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,16 @@ function jsLookup(options: Options) {
*/
function cssPreprocessorLookup(options: Options) {
const { filename, partial, directory, resolveConfig } = options;

if (resolveConfig && !isRelativeImport(partial)) {
const result = resolveNonRelativePath(partial, filename, directory, resolveConfig);
if (result) return result;
}
if (partial.startsWith('~') && !partial.startsWith('~/')) {
// webpack syntax for resolving a module from node_modules
debug('changing the resolver of css preprocessor to resolveWebpackPath as it has a ~ prefix');
const partialWithNoTilda = partial.replace('~', '');
return resolveWebpack(partialWithNoTilda, filename, directory, { extensions: styleExtensions, symlinks: false });
}
if (resolveConfig && !isRelativeImport(partial)) {
const result = resolveNonRelativePath(partial, filename, directory, resolveConfig);
if (result) return result;
}

// Less and Sass imports are very similar
return sassLookup(partial, filename, directory);
Expand Down
28 changes: 28 additions & 0 deletions src/dependency-builder/filing-cabinet/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,34 @@ describe('filing-cabinet', () => {
assert.equal(result, path.resolve(`${fixtures}/node_modules/bootstrap/index.scss`));
});
});
describe('.scss with a dependency prefix with a tilda and resolve config', () => {
describe('when the alias in resolve-config is resolved to an existing file', () => {
it('should resolve the dependency according to the resolve-config', () => {
const resolveConfig = { aliases: { '~bootstrap': path.normalize(fixtures) } };
const result = cabinet({
resolveConfig,
partial: '~bootstrap/foo2',
filename: `${fixtures}/foo.scss`,
directory: fixtures
});

assert.equal(result, path.resolve(`${fixtures}/foo2.scss`));
});
});
describe('when the alias in resolve-config does not match the partial', () => {
it('should fallback to the node-module resolution', () => {
const resolveConfig = { aliases: { '~non-exist': 'some-dir' } };
const result = cabinet({
resolveConfig,
partial: '~bootstrap/index',
filename: `${fixtures}/foo.scss`,
directory: fixtures
});

assert.equal(result, path.resolve(`${fixtures}/node_modules/bootstrap/index.scss`));
});
});
});

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

0 comments on commit 1226b19

Please sign in to comment.