Skip to content

Commit

Permalink
chore: convert to esm (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Feb 18, 2024
1 parent db88a15 commit ec5609b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { readGitignoreFiles } = require('eslint-gitignore');
module.exports = defineConfig({
ignorePatterns: [
...readGitignoreFiles(),
'.eslintrc.js', // Skip self linting
'.eslintrc.cjs', // Skip self linting
],
root: true,
env: {
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ jobs:
env:
CYPRESS_INSTALL_BINARY: 0

- name: Build types
run: pnpm run build:types

- name: Check scripts
run: pnpm run ts-check

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/commentCodeGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import type { context as ctx, GitHub } from '@actions/github/lib/utils';
* @param context An object containing the context of the workflow run
* @param isSuccess A boolean indicating whether the workflow was successful
*/
module.exports = async (
export async function script(
github: InstanceType<typeof GitHub>,
context: typeof ctx,
isSuccess: boolean
) => {
): Promise<void> {
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down Expand Up @@ -45,4 +45,4 @@ module.exports = async (
body,
});
}
};
}
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ jobs:
continue-on-error: true

- name: Transpile ts
run: pnpm exec tsc .github/workflows/commentCodeGeneration.ts --outDir .github/workflows
run: pnpm tsup-node .github/workflows/commentCodeGeneration.ts --format cjs --clean false --out-dir .github/workflows

- name: Comment
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const script = require('${{ github.workspace }}/.github/workflows/commentCodeGeneration.js')
const { script } = require('${{ github.workspace }}/.github/workflows/commentCodeGeneration.cjs')
await script(github, context, ${{ steps.generate.outcome == 'success' && steps.diff.outcome == 'success' }})
- name: Status
Expand Down
5 changes: 3 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-check

/**
* @type {import('prettier').Options}
* @type {import('prettier').Config}
*/
module.exports = {
export default {
plugins: ['prettier-plugin-organize-imports'],
singleQuote: true,
trailingComma: 'es5',
Expand All @@ -20,6 +20,7 @@ module.exports = {
{
files: '*.md',
options: {
// @ts-expect-error: known property
organizeImportsSkipDestructiveCodeActions: true,
},
},
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
],
"bugs": "https://github.com/faker-js/faker/issues",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "index.d.ts",
"typesVersions": {
">=4.0": {
Expand All @@ -41,13 +42,15 @@
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
},
"./locale/*": {
"types": "./dist/types/locale/*.d.ts",
"require": "./dist/locale/*.js",
"import": "./dist/locale/*.mjs"
"import": "./dist/locale/*.js",
"require": "./dist/locale/*.cjs",
"default": "./dist/locale/*.js"
},
"./package.json": "./package.json"
},
Expand Down
5 changes: 2 additions & 3 deletions test/faker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ describe('faker', () => {
);
});

it('should not log anything on startup', () => {
it('should not log anything on startup', async () => {
const spies: MockInstance[] = keys(console)
.filter((key) => typeof console[key] === 'function')
.map((methodName) =>
vi.spyOn(console, methodName as keyof typeof console)
);

// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module -- Using import() requires types being build but the CI / TS-Check runs without them.
require('..').faker;
(await import('..')).default;

new Faker({ locale: { metadata: { title: '' } } });

Expand Down
2 changes: 1 addition & 1 deletion test/locale-imports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { keys } from '../src/internal/keys';
describe.each(keys(allLocales))('locale imports', (locale) => {
it(`should be possible to directly require('@faker-js/faker/locale/${locale}')`, () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
const { faker } = require(`../dist/locale/${locale}`) as {
const { faker } = require(`../dist/locale/${locale}.cjs`) as {
faker: Faker;
};

Expand Down

0 comments on commit ec5609b

Please sign in to comment.