fix(providence): windows compatibility

This commit is contained in:
Thijs Louisse 2021-11-23 09:35:39 +01:00
parent 306d57f57d
commit b90ed14234
4 changed files with 21 additions and 4 deletions

View file

@ -2,4 +2,5 @@
'providence-analytics': patch
---
correctly dedupe match-imports exportSpecifiers
- correctly dedupe match-imports exportSpecifiers
- windows compatibility

View file

@ -115,7 +115,12 @@ async function appendProjectDependencyPaths(rootPaths, matchPattern, modes = ['n
let matchFn;
if (matchPattern) {
if (matchPattern.startsWith('/') && matchPattern.endsWith('/')) {
matchFn = (_, d) => new RegExp(matchPattern.slice(1, -1)).test(d);
matchFn = (_, d) => {
const reString = matchPattern.slice(1, -1);
const result = new RegExp(reString).test(d);
LogService.debug(`[appendProjectDependencyPaths]: /${reString}/.test(${d} => ${result})`);
return result;
};
} else {
LogService.error(
`[appendProjectDependencyPaths] Please provide a matchPattern enclosed by '/'. Found: ${matchPattern}`,

View file

@ -13,6 +13,7 @@ const pathLib = require('path');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const { LogService } = require('../services/LogService.js');
const { memoizeAsync } = require('./memoize.js');
const { toPosixPath } = require('./to-posix-path.js');
const fakePluginContext = {
meta: {
@ -51,7 +52,7 @@ async function resolveImportPath(importee, importer, opts = {}) {
return null;
}
// @ts-ignore
return result.id;
return toPosixPath(result.id);
}
/**

View file

@ -484,8 +484,18 @@ describe('CLI helpers', () => {
});
it('allows a regex filter', async () => {
const result = await appendProjectDependencyPaths(['/mocked/path/example-project'], '/b$/');
const result = await appendProjectDependencyPaths(
['/mocked/path/example-project'],
'/^dependency-/',
);
expect(result).to.eql([
'/mocked/path/example-project/node_modules/dependency-a',
'/mocked/path/example-project/bower_components/dependency-b',
'/mocked/path/example-project',
]);
const result2 = await appendProjectDependencyPaths(['/mocked/path/example-project'], '/b$/');
expect(result2).to.eql([
'/mocked/path/example-project/bower_components/dependency-b',
'/mocked/path/example-project',
]);