Skip to content

Commit a1bad34

Browse files
committed
fix(alternative names): remove prismjs -> prismjs.js
also add the js without dot form to other keys
1 parent c37d6d6 commit a1bad34

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

src/__tests__/__snapshots__/formatPkg.test.js.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Object {
77
"atlaskitinput",
88
" atlaskit input",
99
"@atlaskit/input.js",
10+
"@atlaskit/inputjs",
1011
"@atlaskit/input",
1112
],
1213
},
@@ -202,6 +203,7 @@ Object {
202203
"atomicpackagetab",
203204
" atomic package tab",
204205
"@atomic-package/tab.js",
206+
"@atomic-package/tabjs",
205207
"@atomic-package/tab",
206208
],
207209
},
@@ -318,6 +320,7 @@ Object {
318320
"createinstantsearchapp",
319321
"create instantsearch app",
320322
"create-instantsearch-app.js",
323+
"create-instantsearch-appjs",
321324
"create-instantsearch-app",
322325
],
323326
},
@@ -438,6 +441,7 @@ Object {
438441
"alternativeNames": Array [
439442
"indexof",
440443
"indexof.js",
444+
"indexofjs",
441445
],
442446
},
443447
"bin": undefined,
@@ -521,7 +525,7 @@ Object {
521525
"_searchInternal": Object {
522526
"alternativeNames": Array [
523527
"prismjs",
524-
"prismjs.js",
528+
"prism",
525529
],
526530
},
527531
"bin": undefined,
@@ -719,6 +723,7 @@ Object {
719723
"longboy",
720724
"long boy",
721725
"long-boy.js",
726+
"long-boyjs",
722727
"long-boy",
723728
],
724729
},

src/__tests__/formatPkg.test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ it('keeps .bin intact', () => {
3030
);
3131
const formatted = formatPkg(createInstantSearchApp);
3232
expect(formatted.bin).toMatchInlineSnapshot(`
33-
Object {
34-
"create-instantsearch-app": "src/cli/index.js",
35-
}
36-
`);
33+
Object {
34+
"create-instantsearch-app": "src/cli/index.js",
35+
}
36+
`);
3737
});
3838

3939
it('truncates long readmes', () => {
@@ -390,6 +390,7 @@ describe('alternative names', () => {
390390
Array [
391391
"places",
392392
"places.js",
393+
"placesjs",
393394
]
394395
`);
395396
});
@@ -410,6 +411,20 @@ describe('alternative names', () => {
410411
`);
411412
});
412413

414+
test('name ending in js', () => {
415+
const original = {
416+
name: 'prismjs',
417+
lastPublisher: { name: 'unknown' },
418+
};
419+
expect(formatPkg(original)._searchInternal.alternativeNames)
420+
.toMatchInlineSnapshot(`
421+
Array [
422+
"prismjs",
423+
"prism",
424+
]
425+
`);
426+
});
427+
413428
test('scoped package', () => {
414429
const original = {
415430
name: '@algolia/places.js',
@@ -437,6 +452,7 @@ describe('alternative names', () => {
437452
"thisisadumbname",
438453
"this is a dumb name",
439454
"this-is_a-dumb-name.js",
455+
"this-is_a-dumb-namejs",
440456
"this-is_a-dumb-name",
441457
]
442458
`);

src/formatPkg.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,29 @@ function getTypes(pkg) {
425425
* @param {string} name
426426
*/
427427
function getAlternativeNames(name) {
428+
const alternativeNames = new Set();
429+
428430
const concatenatedName = name.replace(/[-/@_.]+/g, '');
431+
alternativeNames.add(concatenatedName);
432+
429433
const splitName = name.replace(/[-/@_.]+/g, ' ');
430-
const dotJSName = name.endsWith('.js')
431-
? name.substring(0, name.length - 3)
432-
: `${name}.js`;
433-
const normalName = name;
434+
alternativeNames.add(splitName);
435+
436+
const isDotJs = name.endsWith('.js');
437+
const isJsSuffix = name.match(/\.?js$/);
438+
439+
if (isDotJs) {
440+
alternativeNames.add(name.substring(0, name.length - 3));
441+
} else if (isJsSuffix) {
442+
alternativeNames.add(name.substring(0, name.length - 2));
443+
} else {
444+
alternativeNames.add(`${name}.js`);
445+
alternativeNames.add(`${name}js`);
446+
}
434447

435-
return Array.from(
436-
new Set([concatenatedName, splitName, dotJSName, normalName])
437-
);
448+
alternativeNames.add(name);
449+
450+
return Array.from(alternativeNames);
438451
}
439452

440453
export function getMains(pkg) {

0 commit comments

Comments
 (0)