@embroider/reverse-exports
Advanced tools
Comparing version 0.0.1-unstable.9606cac to 0.0.1-unstable.d68fbec
{ | ||
"name": "@embroider/reverse-exports", | ||
"version": "0.0.1-unstable.9606cac", | ||
"version": "0.0.1-unstable.d68fbec", | ||
"description": "", | ||
@@ -12,9 +12,5 @@ "main": "src/index.js", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/minimatch": "^3.0.4" | ||
}, | ||
"dependencies": { | ||
"minimatch": "^3.0.4", | ||
"resolve.exports": "^2.0.2" | ||
} | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._findPathRecursively = void 0; | ||
exports._prepareStringForRegex = exports._findPathRecursively = void 0; | ||
const path_1 = require("path"); | ||
const minimatch_1 = __importDefault(require("minimatch")); | ||
const resolve_exports_1 = require("resolve.exports"); | ||
@@ -73,7 +69,4 @@ /** | ||
const maybeKeyValuePair = _findPathRecursively(exportsObj, candidate => { | ||
// miminatch does not treat directories as full of content without glob | ||
if (candidate.endsWith('/')) { | ||
candidate += '**'; | ||
} | ||
return (0, minimatch_1.default)(relativePath, candidate); | ||
const regex = new RegExp(_prepareStringForRegex(candidate)); | ||
return regex.test(relativePath); | ||
}); | ||
@@ -95,2 +88,13 @@ if (!maybeKeyValuePair) { | ||
exports.default = reversePackageExports; | ||
function _prepareStringForRegex(input) { | ||
let result = input | ||
.split('*') | ||
.map(substr => substr.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')) | ||
.join('.*'); | ||
if (result.endsWith('/')) { | ||
result += '.*'; | ||
} | ||
return `^${result}$`; | ||
} | ||
exports._prepareStringForRegex = _prepareStringForRegex; | ||
//# sourceMappingURL=index.js.map |
import { posix } from 'path'; | ||
import minimatch from 'minimatch'; | ||
import { exports as resolveExports } from 'resolve.exports'; | ||
@@ -85,8 +84,5 @@ | ||
const maybeKeyValuePair = _findPathRecursively(exportsObj, candidate => { | ||
// miminatch does not treat directories as full of content without glob | ||
if (candidate.endsWith('/')) { | ||
candidate += '**'; | ||
} | ||
const regex = new RegExp(_prepareStringForRegex(candidate)); | ||
return minimatch(relativePath, candidate); | ||
return regex.test(relativePath); | ||
}); | ||
@@ -118,1 +114,14 @@ | ||
} | ||
export function _prepareStringForRegex(input: string): string { | ||
let result = input | ||
.split('*') | ||
.map(substr => substr.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')) | ||
.join('.*'); | ||
if (result.endsWith('/')) { | ||
result += '.*'; | ||
} | ||
return `^${result}$`; | ||
} |
@@ -1,2 +0,2 @@ | ||
import reversePackageExports, { _findPathRecursively } from '../src'; | ||
import reversePackageExports, { _findPathRecursively, _prepareStringForRegex } from '../src'; | ||
@@ -143,2 +143,20 @@ describe('reverse exports', function () { | ||
}); | ||
it('conditional exports: using a single asterisk as glob for nested path', function () { | ||
const packageJson = { | ||
name: 'my-v2-addon', | ||
exports: { | ||
'.': './dist/index.js', | ||
'./*': { | ||
types: './dist/*.d.ts', | ||
default: './dist/*.js', | ||
}, | ||
'./addon-main.js': './addon-main.js', | ||
}, | ||
}; | ||
expect(reversePackageExports(packageJson, './dist/_app_/components/welcome-page.js')).toBe( | ||
'my-v2-addon/_app_/components/welcome-page' | ||
); | ||
}); | ||
}); | ||
@@ -264,1 +282,14 @@ | ||
}); | ||
describe('_prepareStringForRegex', function () { | ||
[ | ||
{ input: './foo', expected: '^\\.\\/foo$' }, | ||
{ input: './foo.js', expected: '^\\.\\/foo\\.js$' }, | ||
{ input: './foo/*.js', expected: '^\\.\\/foo\\/.*\\.js$' }, | ||
{ input: './foo/', expected: '^\\.\\/foo\\/.*$' }, | ||
].forEach(({ input, expected }) => { | ||
it(input, function () { | ||
expect(_prepareStringForRegex(input)).toStrictEqual(expected); | ||
}); | ||
}); | ||
}); |
17778
1
0
460
- Removedminimatch@^3.0.4
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedminimatch@3.1.2(transitive)