Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1663: Remove prettier custom options r=curquiza a=flevi29

# Pull Request

## Related issue
Fixes meilisearch#1659

## What does this PR do?
- Removes unnecessary prettier options for reasons described in the linked issue
- Applies these changes to all files


Co-authored-by: F. Levi <[email protected]>
  • Loading branch information
meili-bors[bot] and flevi29 authored May 29, 2024
2 parents 6cd64e9 + 792860d commit 7b2054d
Show file tree
Hide file tree
Showing 64 changed files with 6,157 additions and 6,119 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ module.exports = {
},
},
],
}
};
5 changes: 1 addition & 4 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// https://prettier.io/docs/en/options.html

module.exports = {
singleQuote: true,
semi: false,
trailingComma: 'es5',
plugins: ['./node_modules/prettier-plugin-jsdoc/dist/index.js'],
// https://github.com/hosseinmd/prettier-plugin-jsdoc#tsdoc
tsdoc: true,
}
};
4 changes: 2 additions & 2 deletions jest-disable-built-in-fetch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function () {
// This is required for tests to work with "cross-fetch" on newer node versions,
// otherwise "cross-fetch" won't replace the builtin `fetch`
globalThis.fetch = undefined
}
globalThis.fetch = undefined;
};
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ const config = {
testPathIgnorePatterns: ['meilisearch-test-utils', 'env/'],
},
],
}
};

module.exports = config
module.exports = config;
52 changes: 26 additions & 26 deletions playgrounds/javascript/src/app.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { MeiliSearch } from '../../../src'
import { MeiliSearch } from '../../../src';

const config = {
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
}
};

const client = new MeiliSearch(config)
const indexUid = 'movies'
const client = new MeiliSearch(config);
const indexUid = 'movies';

const addDataset = async () => {
await client.deleteIndex(indexUid)
const { taskUid } = await client.createIndex(indexUid)
await client.index(indexUid).waitForTask(taskUid)
await client.deleteIndex(indexUid);
const { taskUid } = await client.createIndex(indexUid);
await client.index(indexUid).waitForTask(taskUid);

const documents = await client.index(indexUid).getDocuments()
const documents = await client.index(indexUid).getDocuments();

const dataset = [
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
Expand All @@ -26,35 +26,35 @@ const addDataset = async () => {
},
{ id: 5, title: 'Moana', genres: ['Fantasy', 'Action'] },
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
]
];
if (documents.results.length === 0) {
const { taskUid } = await client.index(indexUid).addDocuments(dataset)
await client.index(indexUid).waitForTask(taskUid)
const { taskUid } = await client.index(indexUid).addDocuments(dataset);
await client.index(indexUid).waitForTask(taskUid);
}
}
};

;(async () => {
(async () => {
try {
await addDataset()
const indexes = await client.getRawIndexes()
await addDataset();
const indexes = await client.getRawIndexes();
document.querySelector('.indexes').innerText = JSON.stringify(
indexes,
null,
1
)
1,
);
const resp = await client.index(indexUid).search('', {
attributesToHighlight: ['title'],
})
console.log({ resp })
console.log({ hit: resp.hits[0] })
});
console.log({ resp });
console.log({ hit: resp.hits[0] });
document.querySelector('.hits').innerText = JSON.stringify(
resp.hits.map((hit) => hit.title),
null,
1
)
document.querySelector('.errors_title').style.display = 'none'
1,
);
document.querySelector('.errors_title').style.display = 'none';
} catch (e) {
console.error(e)
document.querySelector('.errors').innerText = JSON.stringify(e, null, 1)
console.error(e);
document.querySelector('.errors').innerText = JSON.stringify(e, null, 1);
}
})()
})();
32 changes: 16 additions & 16 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const nodeResolve = require('@rollup/plugin-node-resolve')
const { resolve } = require('path')
const commonjs = require('@rollup/plugin-commonjs')
const json = require('@rollup/plugin-json')
const typescript = require('rollup-plugin-typescript2')
const pkg = require('./package.json')
const { terser } = require('rollup-plugin-terser')
const { babel } = require('@rollup/plugin-babel')
const nodeResolve = require('@rollup/plugin-node-resolve');
const { resolve } = require('path');
const commonjs = require('@rollup/plugin-commonjs');
const json = require('@rollup/plugin-json');
const typescript = require('rollup-plugin-typescript2');
const pkg = require('./package.json');
const { terser } = require('rollup-plugin-terser');
const { babel } = require('@rollup/plugin-babel');

function getOutputFileName(fileName, isProd = false) {
return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName
return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName;
}

const env = process.env.NODE_ENV || 'development'
const ROOT = resolve(__dirname, '.')
const env = process.env.NODE_ENV || 'development';
const ROOT = resolve(__dirname, '.');

const PLUGINS = [
typescript({
Expand All @@ -23,7 +23,7 @@ const PLUGINS = [
exclude: ['tests', 'examples', '*.js', 'scripts'],
},
}),
]
];

module.exports = [
// browser-friendly UMD build
Expand All @@ -36,7 +36,7 @@ module.exports = [
file: getOutputFileName(
// will add .min. in filename if in production env
resolve(ROOT, pkg.jsdelivr),
env === 'production'
env === 'production',
),
format: 'umd',
sourcemap: env === 'production', // create sourcemap for error reporting in production mode
Expand Down Expand Up @@ -80,7 +80,7 @@ module.exports = [
{
file: getOutputFileName(
resolve(ROOT, pkg.module),
env === 'production'
env === 'production',
),
exports: 'named',
format: 'es',
Expand All @@ -101,11 +101,11 @@ module.exports = [
file: getOutputFileName(
// will add .min. in filename if in production env
resolve(ROOT, pkg.main),
env === 'production'
env === 'production',
),
exports: 'named',
format: 'cjs',
},
plugins: [...PLUGINS],
},
]
];
32 changes: 16 additions & 16 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/** This file only purpose is to execute any build related tasks */

const { resolve, normalize } = require('path')
const { readFileSync, writeFileSync } = require('fs')
const pkg = require('../package.json')
const { resolve, normalize } = require('path');
const { readFileSync, writeFileSync } = require('fs');
const pkg = require('../package.json');

const ROOT = resolve(__dirname, '..')
const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.typings))
const ROOT = resolve(__dirname, '..');
const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.typings));

main()
main();

function main() {
writeDtsHeader()
writeDtsHeader();
}

function writeDtsHeader() {
Expand All @@ -19,10 +19,10 @@ function writeDtsHeader() {
pkg.version,
pkg.author,
pkg.repository.url,
pkg.devDependencies.typescript
)
pkg.devDependencies.typescript,
);

prependFileSync(TYPES_ROOT_FILE, dtsHeader)
prependFileSync(TYPES_ROOT_FILE, dtsHeader);
}

/**
Expand All @@ -33,16 +33,16 @@ function writeDtsHeader() {
* @param {string} tsVersion
*/
function getDtsHeader(pkgName, version, author, repoUrl, tsVersion) {
const extractUserName = repoUrl.match(/\.com\/([\w-]+)\/\w+/i)
const githubUserUrl = extractUserName ? extractUserName[1] : 'Unknown'
const extractUserName = repoUrl.match(/\.com\/([\w-]+)\/\w+/i);
const githubUserUrl = extractUserName ? extractUserName[1] : 'Unknown';

return `
// Type definitions for ${pkgName} ${version}
// Project: ${repoUrl}
// Definitions by: ${author} <https://github.com/${githubUserUrl}>
// Definitions: ${repoUrl}
// TypeScript Version: ${tsVersion}
`.replace(/^\s+/gm, '')
`.replace(/^\s+/gm, '');
}

/**
Expand All @@ -52,10 +52,10 @@ function getDtsHeader(pkgName, version, author, repoUrl, tsVersion) {
function prependFileSync(path, data) {
const existingFileContent = readFileSync(path, {
encoding: 'utf8',
})
const newFileContent = [data, existingFileContent].join('\n')
});
const newFileContent = [data, existingFileContent].join('\n');
writeFileSync(path, newFileContent, {
flag: 'w+',
encoding: 'utf8',
})
});
}
62 changes: 31 additions & 31 deletions scripts/file-size.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
const { basename, normalize } = require('path')
const { readFile: readFileCb } = require('fs')
const { promisify } = require('util')
const readFile = promisify(readFileCb)
const { basename, normalize } = require('path');
const { readFile: readFileCb } = require('fs');
const { promisify } = require('util');
const readFile = promisify(readFileCb);

const kolor = require('kleur')
const prettyBytes = require('pretty-bytes')
const brotliSize = require('brotli-size')
const gzipSize = require('gzip-size')
const { log } = console
const pkg = require('../package.json')
const kolor = require('kleur');
const prettyBytes = require('pretty-bytes');
const brotliSize = require('brotli-size');
const gzipSize = require('gzip-size');
const { log } = console;
const pkg = require('../package.json');

main()
main();

async function main() {
const args = process.argv.splice(2)
const filePaths = [...args.map(normalize)]
const args = process.argv.splice(2);
const filePaths = [...args.map(normalize)];
const fileMetadata = await Promise.all(
filePaths.map(async (filePath) => {
return {
path: filePath,
blob: await readFile(filePath, { encoding: 'utf8' }),
}
})
)
};
}),
);

const output = await Promise.all(
fileMetadata.map((metadata) => getSizeInfo(metadata.blob, metadata.path))
)
fileMetadata.map((metadata) => getSizeInfo(metadata.blob, metadata.path)),
);

log(getFormatedOutput(pkg.name, output))
log(getFormatedOutput(pkg.name, output));
}

/**
* @param {string} pkgName
* @param {string[]} filesOutput
*/
function getFormatedOutput(pkgName, filesOutput) {
const MAGIC_INDENTATION = 3
const WHITE_SPACE = ' '.repeat(MAGIC_INDENTATION)
const MAGIC_INDENTATION = 3;
const WHITE_SPACE = ' '.repeat(MAGIC_INDENTATION);

return (
kolor.blue(`${pkgName} bundle sizes: 📦`) +
`\n${WHITE_SPACE}` +
readFile.name +
filesOutput.join(`\n${WHITE_SPACE}`)
)
);
}

/**
Expand All @@ -54,13 +54,13 @@ function getFormatedOutput(pkgName, filesOutput) {
* @param {boolean} raw
*/
function formatSize(size, filename, type, raw) {
const pretty = raw ? `${size} B` : prettyBytes(size)
const color = size < 5000 ? 'green' : size > 40000 ? 'red' : 'yellow'
const MAGIC_INDENTATION = type === 'br' ? 13 : 10
const pretty = raw ? `${size} B` : prettyBytes(size);
const color = size < 5000 ? 'green' : size > 40000 ? 'red' : 'yellow';
const MAGIC_INDENTATION = type === 'br' ? 13 : 10;

return `${' '.repeat(MAGIC_INDENTATION - pretty.length)}${kolor[color](
pretty
)}: ${kolor.white(basename(filename))}.${type}`
pretty,
)}: ${kolor.white(basename(filename))}.${type}`;
}

/**
Expand All @@ -69,8 +69,8 @@ function formatSize(size, filename, type, raw) {
* @param {boolean} [raw=false] Default is `false`
*/
async function getSizeInfo(code, filename, raw = false) {
const isRaw = raw || code.length < 5000
const gzip = formatSize(await gzipSize(code), filename, 'gz', isRaw)
const brotli = formatSize(await brotliSize.sync(code), filename, 'br', isRaw)
return gzip + '\n' + brotli
const isRaw = raw || code.length < 5000;
const gzip = formatSize(await gzipSize(code), filename, 'gz', isRaw);
const brotli = formatSize(await brotliSize.sync(code), filename, 'br', isRaw);
return gzip + '\n' + brotli;
}
12 changes: 6 additions & 6 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './types'
export * from './errors'
export * from './indexes'
import { MeiliSearch } from './clients/browser-client'
export * from './types';
export * from './errors';
export * from './indexes';
import { MeiliSearch } from './clients/browser-client';

export { MeiliSearch, MeiliSearch as Meilisearch }
export default MeiliSearch
export { MeiliSearch, MeiliSearch as Meilisearch };
export default MeiliSearch;
8 changes: 4 additions & 4 deletions src/clients/browser-client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Config } from '../types'
import { Client } from './client'
import { Config } from '../types';
import { Client } from './client';

class MeiliSearch extends Client {
constructor(config: Config) {
super(config)
super(config);
}
}

export { MeiliSearch }
export { MeiliSearch };
Loading

0 comments on commit 7b2054d

Please sign in to comment.