Skip to content

Commit

Permalink
Update deps & remove mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed May 27, 2024
1 parent 527b8ff commit 4d13892
Show file tree
Hide file tree
Showing 8 changed files with 975 additions and 5,125 deletions.
File renamed without changes.
5 changes: 0 additions & 5 deletions .mocharc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

module.exports = {
export default {
semi: true,
trailingComma: "all",
singleQuote: true,
Expand Down
58 changes: 44 additions & 14 deletions esbuild.mjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
#!/usr/bin/env node

/* Copyright © 2023 Exact Realty Limited. All rights reserved.
/* Copyright © 2023 Exact Realty Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License") with LLVM
* exceptions; you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* http://llvm.org/foundation/relicensing/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/

import esbuild from 'esbuild';
import { readdir, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

const outdir = process.env['BUILD_TARGET_DIR'] || 'dist';

const buildOptionsBase = {
entryPoints: ['./src/index.ts'],
target: 'es2018',
outdir: 'dist',
outdir,
bundle: true,
minify: true,
entryNames: '[name]',
Expand All @@ -30,14 +34,40 @@ const buildOptionsBase = {

const formats = ['cjs', 'esm'];

await Promise.resolve(
await Promise.all(
formats.map((format) => {
return esbuild.build({
...buildOptionsBase,
format,
outExtension: {
'.js': format === 'esm' ? '.mjs' : '.js',
'.js': format === 'esm' ? '.mjs' : '.cjs',
},
});
}),
);

const cjsDeclarationFiles = async (directoryPath) => {
const entries = await readdir(directoryPath, {
withFileTypes: true,
recursive: true,
});

await Promise.all(
entries
.filter((entry) => {
return entry.isFile() && entry.name.endsWith('.d.ts');
})
.map(async (file) => {
const name = join(file.path, file.name);
const newName = name.slice(0, -2) + 'cts';

const contents = await readFile(name, { encoding: 'utf-8' });
await writeFile(
newName,
contents.replace(/(?<=\.)js(?=['"])/g, 'cjs'),
);
}),
);
};

await cjsDeclarationFiles(outdir);
Loading

0 comments on commit 4d13892

Please sign in to comment.