From 402bed6eb6ccd3ca6f13595e1a05fe04be84c56c Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Fri, 4 Oct 2024 23:06:06 -0400 Subject: [PATCH] chore: `.mts` migration Signed-off-by: Lexus Drumgold --- .codecov.yml | 13 +- .dictionary.txt | 2 + .github/workflows/ci.yml | 41 +-- .lintstagedrc.json | 2 +- .vscode/settings.json | 17 +- .yarnrc.yml | 4 +- README.md | 78 ++--- .../{conditions.ts => conditions.mts} | 0 ...valid-json-url.ts => invalid-json-url.mts} | 0 __fixtures__/{parent.ts => parent.mts} | 2 +- __mocks__/.gitkeep | 0 .../{tsconfig-paths.ts => tsconfig-paths.mts} | 0 .../reporters/{notifier.ts => notifier.mts} | 0 __tests__/serializers/{cwd.ts => cwd.mts} | 0 __tests__/setup/{chai.ts => chai.mts} | 0 __tests__/setup/{faker.ts => faker.mts} | 0 .../{percent-encode.ts => percent-encode.mts} | 0 .../{to-package-url.ts => to-package-url.mts} | 0 build.config.ts => build.config.mts | 0 build/{build.ts => build.mts} | 10 +- build/{make.ts => make.mts} | 8 +- build/plugins/{clean.ts => clean.mts} | 0 build/plugins/dts.mts | 267 +++++++++++++++++ build/plugins/dts.ts | 276 ------------------ build/plugins/{write.ts => write.mts} | 0 eslint.base.config.mjs | 35 ++- package.json | 20 +- .../{index.e2e.spec.ts => index.e2e.spec.mts} | 0 src/{index.ts => index.mts} | 0 .../{aliases.spec-d.ts => aliases.spec-d.mts} | 0 ...ystem.spec-d.ts => file-system.spec-d.mts} | 0 ...ap.spec-d.ts => main-field-map.spec-d.mts} | 0 ...spec-d.ts => module-format-map.spec-d.mts} | 0 ...-d.ts => options-resolve-alias.spec-d.mts} | 0 ...d.ts => options-resolve-module.spec-d.mts} | 0 ...-map.spec-d.ts => protocol-map.spec-d.mts} | 0 .../{stats.spec-d.ts => stats.spec-d.mts} | 0 src/interfaces/{aliases.ts => aliases.mts} | 0 .../{file-system.ts => file-system.mts} | 0 src/interfaces/{index.ts => index.mts} | 0 .../{main-field-map.ts => main-field-map.mts} | 0 ...le-format-map.ts => module-format-map.mts} | 0 ...lve-alias.ts => options-resolve-alias.mts} | 0 ...e-module.ts => options-resolve-module.mts} | 0 .../{protocol-map.ts => protocol-map.mts} | 0 src/interfaces/{stats.ts => stats.mts} | 0 .../__snapshots__/invalid-package-target.snap | 2 +- ...pec.ts => check-invalid-segments.spec.mts} | 0 ...pec.ts => invalid-package-target.spec.mts} | 0 ...bpath.spec.ts => invalid-subpath.spec.mts} | 0 src/internal/{chars.ts => chars.mts} | 0 ...segments.ts => check-invalid-segments.mts} | 0 .../{fs.browser.ts => fs.browser.mts} | 0 ...e-target.ts => invalid-package-target.mts} | 0 ...invalid-subpath.ts => invalid-subpath.mts} | 0 src/lib/__snapshots__/resolve-alias.snap | 4 +- src/lib/__snapshots__/resolve-module.snap | 2 +- src/lib/__snapshots__/resolver.snap | 38 +-- ...rse-url.spec.ts => can-parse-url.spec.mts} | 0 .../__tests__/{cwd.spec.ts => cwd.spec.mts} | 0 ...ns.spec.ts => default-conditions.spec.mts} | 0 ...ns.spec.ts => default-extensions.spec.mts} | 0 ....spec.ts => extension-format-map.spec.mts} | 0 ...spec.ts => is-absolute-specifier.spec.mts} | 0 ...-index.spec.ts => is-array-index.spec.mts} | 0 ...ier.spec.ts => is-bare-specifier.spec.mts} | 0 ...irectory.spec.ts => is-directory.spec.mts} | 2 +- .../{is-file.spec.ts => is-file.spec.mts} | 2 +- ...th.spec.ts => is-imports-subpath.spec.mts} | 0 ...spec.ts => is-relative-specifier.spec.mts} | 0 ....spec.ts => lookup-package-scope.spec.mts} | 0 ...e.spec.ts => pattern-key-compare.spec.mts} | 0 ...n-match.spec.ts => pattern-match.spec.mts} | 0 ...son.spec.ts => read-package-json.spec.mts} | 2 +- ...e-alias.spec.ts => resolve-alias.spec.mts} | 4 +- ...module.spec.ts => resolve-module.spec.mts} | 2 +- .../{resolver.spec.ts => resolver.spec.mts} | 40 +-- ...spec.ts => to-relative-specifier.spec.mts} | 2 +- .../{can-parse-url.ts => can-parse-url.mts} | 0 src/lib/{cwd.ts => cwd.mts} | 0 ...t-conditions.ts => default-conditions.mts} | 0 ...t-extensions.ts => default-extensions.mts} | 0 ...main-fields.ts => default-main-fields.mts} | 0 ...format-map.ts => extension-format-map.mts} | 0 src/lib/{formats.ts => formats.mts} | 0 src/lib/{index.ts => index.mts} | 0 ...specifier.ts => is-absolute-specifier.mts} | 0 .../{is-array-index.ts => is-array-index.mts} | 0 ...are-specifier.ts => is-bare-specifier.mts} | 0 src/lib/{is-directory.ts => is-directory.mts} | 0 src/lib/{is-file.ts => is-file.mts} | 0 ...orts-subpath.ts => is-imports-subpath.mts} | 0 ...specifier.ts => is-relative-specifier.mts} | 0 ...kage-scope.ts => lookup-package-scope.mts} | 0 ...key-compare.ts => pattern-key-compare.mts} | 0 .../{pattern-match.ts => pattern-match.mts} | 0 ...-package-json.ts => read-package-json.mts} | 2 +- .../{resolve-alias.ts => resolve-alias.mts} | 0 .../{resolve-module.ts => resolve-module.mts} | 4 +- src/lib/{resolver.ts => resolver.mts} | 8 +- src/lib/{root.ts => root.mts} | 0 ...specifier.ts => to-relative-specifier.mts} | 0 ...-fn.spec-d.ts => change-ext-fn.spec-d.mts} | 0 ...-field.spec-d.ts => main-field.spec-d.mts} | 0 ...mat.spec-d.ts => module-format.spec-d.mts} | 0 ...dule-id.spec-d.ts => module-id.spec-d.mts} | 0 .../{numeric.spec-d.ts => numeric.spec-d.mts} | 0 ... => pattern-key-compare-result.spec-d.mts} | 0 ...tch.spec-d.ts => pattern-match.spec-d.mts} | 0 ...protocol.spec-d.ts => protocol.spec-d.mts} | 0 .../{change-ext-fn.ts => change-ext-fn.mts} | 0 src/types/{index.ts => index.mts} | 0 src/types/{main-field.ts => main-field.mts} | 0 .../{module-format.ts => module-format.mts} | 0 src/types/{module-id.ts => module-id.mts} | 0 src/types/{numeric.ts => numeric.mts} | 0 ...sult.ts => pattern-key-compare-result.mts} | 0 .../{pattern-match.ts => pattern-match.mts} | 0 src/types/{protocol.ts => protocol.mts} | 0 tsconfig.typecheck.json | 10 +- vitest-env.d.ts => vitest-env.d.mts | 0 vitest.config.ts => vitest.config.mts | 26 +- 122 files changed, 457 insertions(+), 468 deletions(-) rename __fixtures__/{conditions.ts => conditions.mts} (100%) rename __fixtures__/{invalid-json-url.ts => invalid-json-url.mts} (100%) rename __fixtures__/{parent.ts => parent.mts} (73%) delete mode 100644 __mocks__/.gitkeep rename __tests__/plugins/{tsconfig-paths.ts => tsconfig-paths.mts} (100%) rename __tests__/reporters/{notifier.ts => notifier.mts} (100%) rename __tests__/serializers/{cwd.ts => cwd.mts} (100%) rename __tests__/setup/{chai.ts => chai.mts} (100%) rename __tests__/setup/{faker.ts => faker.mts} (100%) rename __tests__/utils/{percent-encode.ts => percent-encode.mts} (100%) rename __tests__/utils/{to-package-url.ts => to-package-url.mts} (100%) rename build.config.ts => build.config.mts (100%) rename build/{build.ts => build.mts} (68%) rename build/{make.ts => make.mts} (98%) rename build/plugins/{clean.ts => clean.mts} (100%) create mode 100644 build/plugins/dts.mts delete mode 100644 build/plugins/dts.ts rename build/plugins/{write.ts => write.mts} (100%) rename src/__tests__/{index.e2e.spec.ts => index.e2e.spec.mts} (100%) rename src/{index.ts => index.mts} (100%) rename src/interfaces/__tests__/{aliases.spec-d.ts => aliases.spec-d.mts} (100%) rename src/interfaces/__tests__/{file-system.spec-d.ts => file-system.spec-d.mts} (100%) rename src/interfaces/__tests__/{main-field-map.spec-d.ts => main-field-map.spec-d.mts} (100%) rename src/interfaces/__tests__/{module-format-map.spec-d.ts => module-format-map.spec-d.mts} (100%) rename src/interfaces/__tests__/{options-resolve-alias.spec-d.ts => options-resolve-alias.spec-d.mts} (100%) rename src/interfaces/__tests__/{options-resolve-module.spec-d.ts => options-resolve-module.spec-d.mts} (100%) rename src/interfaces/__tests__/{protocol-map.spec-d.ts => protocol-map.spec-d.mts} (100%) rename src/interfaces/__tests__/{stats.spec-d.ts => stats.spec-d.mts} (100%) rename src/interfaces/{aliases.ts => aliases.mts} (100%) rename src/interfaces/{file-system.ts => file-system.mts} (100%) rename src/interfaces/{index.ts => index.mts} (100%) rename src/interfaces/{main-field-map.ts => main-field-map.mts} (100%) rename src/interfaces/{module-format-map.ts => module-format-map.mts} (100%) rename src/interfaces/{options-resolve-alias.ts => options-resolve-alias.mts} (100%) rename src/interfaces/{options-resolve-module.ts => options-resolve-module.mts} (100%) rename src/interfaces/{protocol-map.ts => protocol-map.mts} (100%) rename src/interfaces/{stats.ts => stats.mts} (100%) rename src/internal/__tests__/{check-invalid-segments.spec.ts => check-invalid-segments.spec.mts} (100%) rename src/internal/__tests__/{invalid-package-target.spec.ts => invalid-package-target.spec.mts} (100%) rename src/internal/__tests__/{invalid-subpath.spec.ts => invalid-subpath.spec.mts} (100%) rename src/internal/{chars.ts => chars.mts} (100%) rename src/internal/{check-invalid-segments.ts => check-invalid-segments.mts} (100%) rename src/internal/{fs.browser.ts => fs.browser.mts} (100%) rename src/internal/{invalid-package-target.ts => invalid-package-target.mts} (100%) rename src/internal/{invalid-subpath.ts => invalid-subpath.mts} (100%) rename src/lib/__tests__/{can-parse-url.spec.ts => can-parse-url.spec.mts} (100%) rename src/lib/__tests__/{cwd.spec.ts => cwd.spec.mts} (100%) rename src/lib/__tests__/{default-conditions.spec.ts => default-conditions.spec.mts} (100%) rename src/lib/__tests__/{default-extensions.spec.ts => default-extensions.spec.mts} (100%) rename src/lib/__tests__/{extension-format-map.spec.ts => extension-format-map.spec.mts} (100%) rename src/lib/__tests__/{is-absolute-specifier.spec.ts => is-absolute-specifier.spec.mts} (100%) rename src/lib/__tests__/{is-array-index.spec.ts => is-array-index.spec.mts} (100%) rename src/lib/__tests__/{is-bare-specifier.spec.ts => is-bare-specifier.spec.mts} (100%) rename src/lib/__tests__/{is-directory.spec.ts => is-directory.spec.mts} (94%) rename src/lib/__tests__/{is-file.spec.ts => is-file.spec.mts} (93%) rename src/lib/__tests__/{is-imports-subpath.spec.ts => is-imports-subpath.spec.mts} (100%) rename src/lib/__tests__/{is-relative-specifier.spec.ts => is-relative-specifier.spec.mts} (100%) rename src/lib/__tests__/{lookup-package-scope.spec.ts => lookup-package-scope.spec.mts} (100%) rename src/lib/__tests__/{pattern-key-compare.spec.ts => pattern-key-compare.spec.mts} (100%) rename src/lib/__tests__/{pattern-match.spec.ts => pattern-match.spec.mts} (100%) rename src/lib/__tests__/{read-package-json.spec.ts => read-package-json.spec.mts} (97%) rename src/lib/__tests__/{resolve-alias.spec.ts => resolve-alias.spec.mts} (92%) rename src/lib/__tests__/{resolve-module.spec.ts => resolve-module.spec.mts} (98%) rename src/lib/__tests__/{resolver.spec.ts => resolver.spec.mts} (94%) rename src/lib/__tests__/{to-relative-specifier.spec.ts => to-relative-specifier.spec.mts} (92%) rename src/lib/{can-parse-url.ts => can-parse-url.mts} (100%) rename src/lib/{cwd.ts => cwd.mts} (100%) rename src/lib/{default-conditions.ts => default-conditions.mts} (100%) rename src/lib/{default-extensions.ts => default-extensions.mts} (100%) rename src/lib/{default-main-fields.ts => default-main-fields.mts} (100%) rename src/lib/{extension-format-map.ts => extension-format-map.mts} (100%) rename src/lib/{formats.ts => formats.mts} (100%) rename src/lib/{index.ts => index.mts} (100%) rename src/lib/{is-absolute-specifier.ts => is-absolute-specifier.mts} (100%) rename src/lib/{is-array-index.ts => is-array-index.mts} (100%) rename src/lib/{is-bare-specifier.ts => is-bare-specifier.mts} (100%) rename src/lib/{is-directory.ts => is-directory.mts} (100%) rename src/lib/{is-file.ts => is-file.mts} (100%) rename src/lib/{is-imports-subpath.ts => is-imports-subpath.mts} (100%) rename src/lib/{is-relative-specifier.ts => is-relative-specifier.mts} (100%) rename src/lib/{lookup-package-scope.ts => lookup-package-scope.mts} (100%) rename src/lib/{pattern-key-compare.ts => pattern-key-compare.mts} (100%) rename src/lib/{pattern-match.ts => pattern-match.mts} (100%) rename src/lib/{read-package-json.ts => read-package-json.mts} (98%) rename src/lib/{resolve-alias.ts => resolve-alias.mts} (100%) rename src/lib/{resolve-module.ts => resolve-module.mts} (98%) rename src/lib/{resolver.ts => resolver.mts} (99%) rename src/lib/{root.ts => root.mts} (100%) rename src/lib/{to-relative-specifier.ts => to-relative-specifier.mts} (100%) rename src/types/__tests__/{change-ext-fn.spec-d.ts => change-ext-fn.spec-d.mts} (100%) rename src/types/__tests__/{main-field.spec-d.ts => main-field.spec-d.mts} (100%) rename src/types/__tests__/{module-format.spec-d.ts => module-format.spec-d.mts} (100%) rename src/types/__tests__/{module-id.spec-d.ts => module-id.spec-d.mts} (100%) rename src/types/__tests__/{numeric.spec-d.ts => numeric.spec-d.mts} (100%) rename src/types/__tests__/{pattern-key-compare-result.spec-d.ts => pattern-key-compare-result.spec-d.mts} (100%) rename src/types/__tests__/{pattern-match.spec-d.ts => pattern-match.spec-d.mts} (100%) rename src/types/__tests__/{protocol.spec-d.ts => protocol.spec-d.mts} (100%) rename src/types/{change-ext-fn.ts => change-ext-fn.mts} (100%) rename src/types/{index.ts => index.mts} (100%) rename src/types/{main-field.ts => main-field.mts} (100%) rename src/types/{module-format.ts => module-format.mts} (100%) rename src/types/{module-id.ts => module-id.mts} (100%) rename src/types/{numeric.ts => numeric.mts} (100%) rename src/types/{pattern-key-compare-result.ts => pattern-key-compare-result.mts} (100%) rename src/types/{pattern-match.ts => pattern-match.mts} (100%) rename src/types/{protocol.ts => protocol.mts} (100%) rename vitest-env.d.ts => vitest-env.d.mts (100%) rename vitest.config.ts => vitest.config.mts (88%) diff --git a/.codecov.yml b/.codecov.yml index d453b1b8..c9ac8f8e 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -27,11 +27,11 @@ component_management: - component_id: internal name: internal paths: - - src/internal/*.ts + - src/internal/*.mts - component_id: lib name: lib paths: - - src/lib/*.ts + - src/lib/*.mts coverage: precision: 2 @@ -89,14 +89,15 @@ github_checks: annotations: true ignore: + - '**/*.d.mts' - '**/__mocks__/**' - '**/__tests__/**' - - '**/index.ts' + - '**/index.mts' - '**/interfaces/**' - '**/types/**' - - '!src/index.ts' - - src/internal/*.browser.ts + - '!src/index.mts' + - src/internal/*.browser.mts profiling: critical_files_paths: - - src/lib/*.ts + - src/lib/*.mts diff --git a/.dictionary.txt b/.dictionary.txt index 3f9395fb..3e4f1192 100644 --- a/.dictionary.txt +++ b/.dictionary.txt @@ -19,10 +19,12 @@ hmarr iife jchen kaisugi +ksort lcov lintstagedrc mkbuild mlly +nocheck nvmrc pathe pjson diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a26fc11..04f61aef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,8 +58,10 @@ jobs: runs-on: ubuntu-latest outputs: cache-key: ${{ steps.cache-key.outputs.result }} - version: ${{ steps.version.outputs.result }} + test-files: ${{ steps.test-files.outputs.files_exists }} + typecheck-files: ${{ steps.typecheck-files.outputs.files_exists }} version-typescript: ${{ steps.version-typescript.outputs.result }} + version: ${{ steps.version.outputs.result }} steps: - id: debug name: Print environment variables and event payload @@ -97,6 +99,16 @@ jobs: - id: version-typescript name: Get TypeScript version run: echo "result=$(jq .devDependencies.typescript package.json -r)" >>$GITHUB_OUTPUT + - id: test-files + name: Check for test files + uses: andstor/file-existence-action@v3.0.0 + with: + files: '**/__tests__/*.spec.+(mts|tsx)' + - id: typecheck-files + name: Check for typecheck files + uses: andstor/file-existence-action@v3.0.0 + with: + files: '**/__tests__/*.spec-d.mts' commitlint: needs: preflight runs-on: ubuntu-latest @@ -248,6 +260,7 @@ jobs: - 5.5.4 - 5.4.5 - 5.0.4 + if: ${{ fromJson(needs.preflight.outputs.typecheck-files) }} steps: - id: checkout name: Checkout ${{ env.REF_NAME }} @@ -255,13 +268,7 @@ jobs: with: persist-credentials: false ref: ${{ env.REF }} - - id: test-files-check - name: Check for typecheck files - uses: andstor/file-existence-action@v3.0.0 - with: - files: '**/__tests__/*.spec-d.ts' - id: node - if: steps.test-files-check.outputs.files_exists == 'true' name: Setup Node.js uses: actions/setup-node@v4.0.4 with: @@ -269,22 +276,18 @@ jobs: cache-dependency-path: yarn.lock node-version-file: .nvmrc - id: cache - if: steps.test-files-check.outputs.files_exists == 'true' name: Restore dependencies cache uses: actions/cache@v4.1.0 with: key: ${{ needs.preflight.outputs.cache-key }} path: ${{ env.CACHE_PATH }} - id: typescript - if: steps.test-files-check.outputs.files_exists == 'true' name: Install typescript@${{ matrix.typescript-version }} run: yarn add -D typescript@${{ matrix.typescript-version }} - id: print-typescript-version - if: steps.test-files-check.outputs.files_exists == 'true' name: Print TypeScript version run: jq .devDependencies.typescript package.json -r - id: typecheck - if: steps.test-files-check.outputs.files_exists == 'true' name: Run typecheck run: yarn typecheck test: @@ -302,6 +305,7 @@ jobs: COVERAGE_SUMMARY: ./coverage/coverage-summary.json PCT: .total.branches.pct + .total.functions.pct + .total.lines.pct + .total.statements.pct VITEST_REPORT: ./.vitest-reports/test.blob.json + if: ${{ fromJson(needs.preflight.outputs.test-files) }} steps: - id: checkout name: Checkout ${{ env.REF_NAME }} @@ -309,13 +313,7 @@ jobs: with: persist-credentials: false ref: ${{ env.REF }} - - id: test-files-check - name: Check for test files - uses: andstor/file-existence-action@v3.0.0 - with: - files: '**/__tests__/*.spec.+(ts|tsx)' - id: node - if: steps.test-files-check.outputs.files_exists == 'true' name: Setup Node.js v${{ matrix.node-version }} uses: actions/setup-node@v4.0.4 with: @@ -324,27 +322,23 @@ jobs: check-latest: true node-version: ${{ matrix.node-version }} - id: cache - if: steps.test-files-check.outputs.files_exists == 'true' name: Restore dependencies cache uses: actions/cache@v4.1.0 with: key: ${{ needs.preflight.outputs.cache-key }} path: ${{ env.CACHE_PATH }} - id: test - if: steps.test-files-check.outputs.files_exists == 'true' name: Run tests run: | yarn test:cov --coverage.thresholds.100=false \ && echo "coverage=$(jq '${{ env.PCT }}' ${{ env.COVERAGE_SUMMARY }} -r)" >>$GITHUB_OUTPUT - id: report - if: steps.test-files-check.outputs.files_exists == 'true' name: Upload report uses: actions/upload-artifact@v4.4.0 with: name: ${{ format('vitest-report-{0}-{1}.json', github.event.repository.name, env.SHA) }} path: ${{ env.VITEST_REPORT }} - id: coverage-summary - if: steps.test-files-check.outputs.files_exists == 'true' name: Upload coverage summary uses: actions/upload-artifact@v4.4.0 with: @@ -352,7 +346,6 @@ jobs: ${{ format('coverage-summary-{0}-{1}.json', github.event.repository.name, env.SHA) }} path: ${{ env.COVERAGE_SUMMARY }} - id: codecov - if: steps.test-files-check.outputs.files_exists == 'true' name: Upload coverage report to Codecov uses: codecov/codecov-action@v4.6.0 env: @@ -373,9 +366,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - id: coverage-failure - if: | - steps.test-files-check.outputs.files_exists == 'true' - && ${{ toJson(steps.test.outputs.coverage) }} != 400 + if: ${{ toJson(steps.test.outputs.coverage) }} != 400 name: Coverage threshold failure (${{ steps.test.outputs.coverage }}) run: yarn test:cov:reports build: diff --git a/.lintstagedrc.json b/.lintstagedrc.json index abdeb846..1d2c0fc2 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -6,7 +6,7 @@ ], "**/*.{cts,mts,ts}": "yarn test --changed --typecheck --mode=typecheck", "**/yarn.lock": "yarn dedupe --check", - "src/**/*.ts": [ + "src/**/*.mts": [ "yarn test --changed --coverage", "yarn build", "bash -c tsc -p tsconfig.build.json" diff --git a/.vscode/settings.json b/.vscode/settings.json index d16bdc2c..c833eb0d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -231,11 +231,6 @@ "resolutions" ], "vsicons.associations.files": [ - { - "extensions": [".eslintrc.base.cjs"], - "format": "svg", - "icon": "eslint" - }, { "extensions": ["build.json", "typecheck.json"], "format": "svg", @@ -247,14 +242,9 @@ "icon": "vitest" }, { - "extensions": ["spec-d.ts"], + "extensions": ["spec-d.mts"], "format": "svg", "icon": "testts" - }, - { - "extensions": ["yarnrc.yml"], - "format": "svg", - "icon": "yarn" } ], "vsicons.associations.folders": [ @@ -273,11 +263,6 @@ "format": "svg", "icon": "private" }, - { - "extensions": ["namespaces"], - "format": "svg", - "icon": "module" - }, { "extensions": ["patches"], "format": "svg", diff --git a/.yarnrc.yml b/.yarnrc.yml index 1b978c99..c43c2376 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -7,8 +7,8 @@ changesetBaseRefs: changesetIgnorePatterns: - '!{docs,src/**,{CHANGELOG,LICENSE,README}.md,package.json}' - '**/*.snap' - - '**/*.spec.ts' - - '**/*.spec-d.ts' + - '**/*.spec.mts' + - '**/*.spec-d.mts' compressionLevel: mixed diff --git a/README.md b/README.md index 265c3e74..5a00210a 100644 --- a/README.md +++ b/README.md @@ -99,27 +99,27 @@ import { This package exports the following identifiers: -- [`canParseUrl`](./src/lib/can-parse-url.ts) -- [`cwd`](./src/lib/cwd.ts) -- [`defaultConditions`](./src/lib/default-conditions.ts) -- [`defaultExtensions`](./src/lib/default-extensions.ts) -- [`defaultMainFields`](./src/lib/default-main-fields.ts) -- [`extensionFormatMap`](./src/lib/extension-format-map.ts) -- [`formats`](./src/lib/formats.ts) -- [`isAbsoluteSpecifier`](./src/lib/is-absolute-specifier.ts) -- [`isArrayIndex`](./src/lib/is-array-index.ts) -- [`isBareSpecifier`](./src/lib/is-bare-specifier.ts) -- [`isDirectory`](./src/lib/is-directory.ts) -- [`isFile`](./src/lib/is-file.ts) -- [`isImportsSubpath`](./src/lib/is-imports-subpath.ts) -- [`isRelativeSpecifier`](./src/lib/is-relative-specifier.ts) -- [`lookupPackageScope`](./src/lib/lookup-package-scope.ts) -- [`patternKeyCompare`](./src/lib/pattern-key-compare.ts) -- [`patternMatch`](./src/lib/pattern-match.ts) -- [`readPackageJson`](./src/lib/read-package-json.ts) -- [`resolveAlias`](./src/lib/resolve-alias.ts) -- [`resolveModule`](./src/lib/resolve-module.ts) -- [`resolver`](./src/lib/resolver.ts) +- [`canParseUrl`](./src/lib/can-parse-url.mts) +- [`cwd`](./src/lib/cwd.mts) +- [`defaultConditions`](./src/lib/default-conditions.mts) +- [`defaultExtensions`](./src/lib/default-extensions.mts) +- [`defaultMainFields`](./src/lib/default-main-fields.mts) +- [`extensionFormatMap`](./src/lib/extension-format-map.mts) +- [`formats`](./src/lib/formats.mts) +- [`isAbsoluteSpecifier`](./src/lib/is-absolute-specifier.mts) +- [`isArrayIndex`](./src/lib/is-array-index.mts) +- [`isBareSpecifier`](./src/lib/is-bare-specifier.mts) +- [`isDirectory`](./src/lib/is-directory.mts) +- [`isFile`](./src/lib/is-file.mts) +- [`isImportsSubpath`](./src/lib/is-imports-subpath.mts) +- [`isRelativeSpecifier`](./src/lib/is-relative-specifier.mts) +- [`lookupPackageScope`](./src/lib/lookup-package-scope.mts) +- [`patternKeyCompare`](./src/lib/pattern-key-compare.mts) +- [`patternMatch`](./src/lib/pattern-match.mts) +- [`readPackageJson`](./src/lib/read-package-json.mts) +- [`resolveAlias`](./src/lib/resolve-alias.mts) +- [`resolveModule`](./src/lib/resolve-module.mts) +- [`resolver`](./src/lib/resolver.mts) - `legacyMainResolve` - `moduleResolve` - `packageExportsResolve` @@ -128,8 +128,8 @@ This package exports the following identifiers: - `packageResolve` - `packageSelfResolve` - `packageTargetResolve` -- [`root`](./src/lib/root.ts) -- [`toRelativeSpecifier`](./src/lib/to-relative-specifier.ts) +- [`root`](./src/lib/root.mts) +- [`toRelativeSpecifier`](./src/lib/to-relative-specifier.mts) There is no default export. @@ -139,25 +139,25 @@ This package is fully typed with [TypeScript][]. ### Interfaces -- [`Aliases`](src/interfaces/aliases.ts) -- [`FileSystem`](src/interfaces/file-system.ts) -- [`MainFieldMap`](src/interfaces/main-field-map.ts) -- [`ModuleFormatMap`](src/interfaces/module-format-map.ts) -- [`ResolveAliasOptions`](src/interfaces/options-resolve-alias.ts) -- [`ResolveModuleOptions`](src/interfaces/options-resolve-module.ts) -- [`ProtocolMap`](src/interfaces/protocol-map.ts) -- [`Stats`](src/interfaces/stats.ts) +- [`Aliases`](src/interfaces/aliases.mts) +- [`FileSystem`](src/interfaces/file-system.mts) +- [`MainFieldMap`](src/interfaces/main-field-map.mts) +- [`ModuleFormatMap`](src/interfaces/module-format-map.mts) +- [`ResolveAliasOptions`](src/interfaces/options-resolve-alias.mts) +- [`ResolveModuleOptions`](src/interfaces/options-resolve-module.mts) +- [`ProtocolMap`](src/interfaces/protocol-map.mts) +- [`Stats`](src/interfaces/stats.mts) ### Type Aliases -- [`ChangeExtFn`](src/types/change-ext-fn.ts) -- [`MainField`](src/types/main-field.ts) -- [`ModuleFormat`](src/types/module-format.ts) -- [`ModuleId`](src/types/module-id.ts) -- [`Numeric`](src/types/numeric.ts) -- [`PatternKeyCompareResult`](src/types/pattern-key-compare-result.ts) -- [`PatternMatch`](src/types/pattern-match.ts) -- [`Protocol`](src/types/protocol.ts) +- [`ChangeExtFn`](src/types/change-ext-fn.mts) +- [`MainField`](src/types/main-field.mts) +- [`ModuleFormat`](src/types/module-format.mts) +- [`ModuleId`](src/types/module-id.mts) +- [`Numeric`](src/types/numeric.mts) +- [`PatternKeyCompareResult`](src/types/pattern-key-compare-result.mts) +- [`PatternMatch`](src/types/pattern-match.mts) +- [`Protocol`](src/types/protocol.mts) ## Contribute diff --git a/__fixtures__/conditions.ts b/__fixtures__/conditions.mts similarity index 100% rename from __fixtures__/conditions.ts rename to __fixtures__/conditions.mts diff --git a/__fixtures__/invalid-json-url.ts b/__fixtures__/invalid-json-url.mts similarity index 100% rename from __fixtures__/invalid-json-url.ts rename to __fixtures__/invalid-json-url.mts diff --git a/__fixtures__/parent.ts b/__fixtures__/parent.mts similarity index 73% rename from __fixtures__/parent.ts rename to __fixtures__/parent.mts index 4906e38d..873f66f0 100644 --- a/__fixtures__/parent.ts +++ b/__fixtures__/parent.mts @@ -10,6 +10,6 @@ import pathe from '@flex-development/pathe' * * @const {URL} parent */ -const parent: URL = pathe.pathToFileURL('__fixtures__/parent.ts') +const parent: URL = pathe.pathToFileURL('__fixtures__/parent.mts') export default parent diff --git a/__mocks__/.gitkeep b/__mocks__/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/__tests__/plugins/tsconfig-paths.ts b/__tests__/plugins/tsconfig-paths.mts similarity index 100% rename from __tests__/plugins/tsconfig-paths.ts rename to __tests__/plugins/tsconfig-paths.mts diff --git a/__tests__/reporters/notifier.ts b/__tests__/reporters/notifier.mts similarity index 100% rename from __tests__/reporters/notifier.ts rename to __tests__/reporters/notifier.mts diff --git a/__tests__/serializers/cwd.ts b/__tests__/serializers/cwd.mts similarity index 100% rename from __tests__/serializers/cwd.ts rename to __tests__/serializers/cwd.mts diff --git a/__tests__/setup/chai.ts b/__tests__/setup/chai.mts similarity index 100% rename from __tests__/setup/chai.ts rename to __tests__/setup/chai.mts diff --git a/__tests__/setup/faker.ts b/__tests__/setup/faker.mts similarity index 100% rename from __tests__/setup/faker.ts rename to __tests__/setup/faker.mts diff --git a/__tests__/utils/percent-encode.ts b/__tests__/utils/percent-encode.mts similarity index 100% rename from __tests__/utils/percent-encode.ts rename to __tests__/utils/percent-encode.mts diff --git a/__tests__/utils/to-package-url.ts b/__tests__/utils/to-package-url.mts similarity index 100% rename from __tests__/utils/to-package-url.ts rename to __tests__/utils/to-package-url.mts diff --git a/build.config.ts b/build.config.mts similarity index 100% rename from build.config.ts rename to build.config.mts diff --git a/build/build.ts b/build/build.mts similarity index 68% rename from build/build.ts rename to build/build.mts index 924be8a3..9a01126d 100644 --- a/build/build.ts +++ b/build/build.mts @@ -11,15 +11,15 @@ await make({ { dts: 'only', entryPoints: [ - 'src/*.ts', - 'src/interfaces/*.ts', - 'src/lib/*.ts', - 'src/types/*.ts' + 'src/*.mts', + 'src/interfaces/*.mts', + 'src/lib/*.mts', + 'src/types/*.mts' ] }, { dts: false, - entryPoints: ['src/internal/*.ts', 'src/lib/*.ts', 'src/*.ts'] + entryPoints: ['src/internal/*.mts', 'src/lib/*.mts', 'src/*.mts'] } ], target: ['node18', tsconfig.compilerOptions.target], diff --git a/build/make.ts b/build/make.mts similarity index 98% rename from build/make.ts rename to build/make.mts index c8eed434..7a928d5f 100644 --- a/build/make.ts +++ b/build/make.mts @@ -164,9 +164,9 @@ async function make( const { entries, serve, watch, ...opts } = defaults(options, { absWorkingDir: '.', bundle: false, - logLevel: 'info', + logLevel: 'info' as LogLevel, outdir: 'dist', - serve: false, + serve: false as ServeOptions | boolean, watch: false, write: false }) @@ -277,7 +277,7 @@ async function make( footer, format, inject: [...new Set(inject)], - loader: >{ + loader: { '.cjs': format === 'cjs' && !bundle ? 'copy' : 'js', '.css': bundle ? 'css' : 'copy', '.cts': 'ts', @@ -305,7 +305,7 @@ async function make( '.woff': 'copy', '.woff2': 'copy', ...loader - }, + } as Record, logLimit, logOverride, mainFields: [...new Set(mainFields)], diff --git a/build/plugins/clean.ts b/build/plugins/clean.mts similarity index 100% rename from build/plugins/clean.ts rename to build/plugins/clean.mts diff --git a/build/plugins/dts.mts b/build/plugins/dts.mts new file mode 100644 index 00000000..737c29b7 --- /dev/null +++ b/build/plugins/dts.mts @@ -0,0 +1,267 @@ +/** + * @file Plugins - dts + * @module build/plugins/dts + */ + +import { + EXT_DTS_REGEX +} from '@flex-development/ext-regex' +import pathe from '@flex-development/pathe' +import * as tscu from '@flex-development/tsconfig-utils' +import { constant, ksort } from '@flex-development/tutils' +import { ok } from 'devlop' +import type { + BuildOptions, + BuildResult, + OnLoadArgs, + OnLoadOptions, + Plugin, + PluginBuild +} from 'esbuild' +import type { + CompilerHost, + CompilerOptions, + default as TypeScript +} from 'typescript' + +export default plugin + +/** + * Plugin configuration options. + */ +type Options = { + /** + * Remove declaration source files. + */ + only?: boolean | null | undefined +} + +/** + * Create a TypeScript declaration plugin. + * + * @param {Options | null | undefined} [options] + * Plugin configuration options + * @return {Plugin} + * TypeScript declaration plugin + */ +function plugin(options?: Options | null | undefined): Plugin { + return { name: 'mkbuild:dts', setup } + + /** + * Generate TypeScript declarations. + * + * @param {PluginBuild} build + * [esbuild plugin api](https://esbuild.github.io/plugins) + * @return {undefined} + */ + function setup(build: PluginBuild): undefined { + const { + absWorkingDir = pathe.cwd(), + bundle, + outExtension: { '.js': ext } = {} + } = build.initialOptions + + if (!bundle) { + /** + * Absolute paths to source files. + * + * @var {string[]} files + */ + let files: string[] = [] + + /** + * Load options. + * + * @const {OnLoadOptions} onLoadOptions + */ + const onLoadOptions: OnLoadOptions = { + filter: /\.[cm]?ts$/, + namespace: 'file' + } + + build.onLoad(onLoadOptions, (args: OnLoadArgs): undefined => { + return void files.push(args.path) + }) + + build.onEnd(async (result: BuildResult): Promise => { + files = files.filter(file => !EXT_DTS_REGEX.test(file)) + + if (files.length) { + ok(ext, 'expected `ext`') + ok(result.outputFiles, 'expected `result.outputFiles`') + + /** + * TypeScript module. + * + * @const {typeof TypeScript} ts + */ + const ts: typeof TypeScript = (await import('typescript')).default + + /** + * TypeScript compiler options. + * + * @const {CompilerOptions} compilerOptions + */ + const compilerOptions: CompilerOptions = loadCompilerOptions( + build.initialOptions + ) + + delete compilerOptions.out + + compilerOptions.declaration = true + compilerOptions.declarationMap = false + compilerOptions.emitDeclarationOnly = true + compilerOptions.noErrorTruncation = true + compilerOptions.noEmitOnError = false + + /** + * TypeScript compiler host. + * + * @const {CompilerHost} host + */ + const host: CompilerHost = ts.createCompilerHost(compilerOptions) + + /** + * Virtual file system for declaration files. + * + * @const {Map} vfs + */ + const vfs: Map = new Map() + + /** + * Write a declaration file to {@linkcode vfs}. + * + * @param {string} filename + * Name of file to write + * @param {string} contents + * Content to write + * @return {undefined} + */ + host.writeFile = function writeFile( + filename: string, + contents: string + ): undefined { + return void vfs.set(filename.replace(EXT_DTS_REGEX, ext), { + path: filename, + text: contents + }) + } + + // emit declarations to virtual file system + ts.createProgram(files, compilerOptions, host).emit() + + // add declaration output files + result.outputFiles = result.outputFiles.flatMap(output => { + if (vfs.has(output.path)) { + const { path, text } = vfs.get(output.path)! + + /** + * Declaration file output. + * + * @const {typeof output} dts + */ + const dts: typeof output = Object.defineProperties({ + contents: new TextEncoder().encode(text), + hash: '', + path, + text: '' + }, { text: { get: constant(text) } }) + + /** + * Relative path to output file. + * + * @const {string} outfile + */ + const outfile: string = output.path + .slice(absWorkingDir.length) + .replace(/^[/\\]/, '') + + // update metafile + if (result.metafile) { + /** + * Relative path to declaraion output file. + * + * @const {string} dtsOutfile + */ + const dtsOutfile: string = dts.path + .slice(absWorkingDir.length) + .replace(/^[/\\]/, '') + + result.metafile.outputs[dtsOutfile] = ksort({ + ...result.metafile.outputs[outfile]!, + bytes: Buffer.byteLength(dts.contents) + }) + } + + // filter output files + if (options?.only) { + result.metafile && delete result.metafile.outputs[outfile] + return [dts] + } + + return [output, dts] + } + + return [output] + }) + } + + return void result + }) + } + + return void build + } + + /** + * Load TypeScript compiler options. + * + * @param {BuildOptions} options + * [esbuild build api](https://esbuild.github.io/api/#build-api) options + * @return {CompilerOptions} + * Normalized compiler options + */ + function loadCompilerOptions(options: BuildOptions): CompilerOptions { + const { + absWorkingDir = pathe.cwd(), + outbase = '', + outdir = pathe.dot, + preserveSymlinks = false, + tsconfig = 'tsconfig.json', + tsconfigRaw + } = options + + /** + * TypeScript compiler options. + * + * @var {tscu.CompilerOptions | undefined} compilerOptions + */ + let compilerOptions: tscu.CompilerOptions | undefined + + if (tsconfigRaw) { + if (typeof tsconfigRaw === 'object' && tsconfigRaw.compilerOptions) { + compilerOptions = tsconfigRaw.compilerOptions as tscu.CompilerOptions + } + + if (typeof tsconfigRaw === 'string' && tsconfigRaw) { + compilerOptions = + (JSON.parse(tsconfigRaw) as tscu.TSConfig).compilerOptions + } + } + + if (!compilerOptions) { + compilerOptions = tscu.loadCompilerOptions(pathe.resolve( + absWorkingDir, + tsconfig + )) + } + + compilerOptions.baseUrl = absWorkingDir + compilerOptions.noEmit = false + compilerOptions.outDir = pathe.resolve(absWorkingDir, outdir) + compilerOptions.preserveSymlinks = preserveSymlinks + compilerOptions.rootDir = pathe.resolve(absWorkingDir, outbase) + + return tscu.normalizeCompilerOptions(compilerOptions) + } +} diff --git a/build/plugins/dts.ts b/build/plugins/dts.ts deleted file mode 100644 index 7082de3e..00000000 --- a/build/plugins/dts.ts +++ /dev/null @@ -1,276 +0,0 @@ -/** - * @file Plugins - dts - * @module build/plugins/dts - */ - -import { - EXT_DTS_REGEX, - EXT_JS_REGEX, - EXT_TS_REGEX -} from '@flex-development/ext-regex' -import pathe from '@flex-development/pathe' -import * as tscu from '@flex-development/tsconfig-utils' -import { defaults, shake } from '@flex-development/tutils' -import { ok } from 'devlop' -import type { BuildResult, Plugin, PluginBuild } from 'esbuild' -import type { - CompilerHost, - CompilerOptions, - default as TypeScript -} from 'typescript' - -export default plugin - -/** - * Plugin configuration options. - */ -type Options = { - /** - * Remove declaration source files. - */ - only?: boolean | null | undefined -} - -/** - * Create a TypeScript declaration plugin. - * - * @param {Options | null | undefined} [options] - * Plugin configuration options - * @return {Plugin} - * TypeScript declaration plugin - */ -function plugin(options?: Options | null | undefined): Plugin { - return { name: 'mkbuild:dts', setup } - - /** - * Generate TypeScript declarations. - * - * @param {PluginBuild} build - * [esbuild plugin api](https://esbuild.github.io/plugins) - * @param {BuildOptions} build.initialOptions - * [esbuild build api](https://esbuild.github.io/api/#build-api) options - * @param {PluginBuild['onEnd']} build.onEnd - * Build end callback - * @param {PluginBuild['onResolve']} build.onResolve - * Path resolution callback - * @return {void} - */ - async function setup(build: PluginBuild): Promise { - const { - absWorkingDir, - bundle, - color = true, - format, - outExtension: { '.js': ext = '.js' } = {}, - outbase = '', - outdir = '.', - preserveSymlinks, - tsconfig = 'tsconfig.json' - } = build.initialOptions - - if (!bundle) { - /** - * TypeScript module. - * - * @const {typeof TypeScript} ts - */ - const ts: typeof TypeScript = (await import('typescript')).default - - build.onEnd((result: BuildResult): undefined => { - ok(absWorkingDir, 'expected `absWorkingDir`') - ok(result.metafile, 'expected `result.metafile`') - ok(result.outputFiles, 'expected `result.outputFiles`') - - /** - * Absolute paths to source files. - * - * @const {string[]} files - */ - const files: string[] = Object - .keys(result.metafile.inputs) - .map(key => pathe.join(absWorkingDir, key)) - .filter(file => !EXT_DTS_REGEX.test(file)) - - if (files.length) { - /** - * Path to tsconfig file. - * - * @const {string} tsconfigPath - */ - const tsconfigPath: string = pathe.resolve(absWorkingDir, tsconfig) - - /** - * TypeScript compiler options. - * - * @var {CompilerOptions | tscu.CompilerOptions} compilerOptions - */ - let compilerOptions: CompilerOptions | tscu.CompilerOptions - - compilerOptions = tscu.loadCompilerOptions(tsconfigPath) - - delete compilerOptions.declarationDir - delete compilerOptions.out - delete compilerOptions.outFile - delete compilerOptions.rootDirs - delete compilerOptions.sourceMap - delete compilerOptions.sourceRoot - - compilerOptions.declaration = true - compilerOptions.declarationMap = false - compilerOptions.emitDeclarationOnly = true - compilerOptions.noEmit = false - compilerOptions.noErrorTruncation = true - compilerOptions.noEmitOnError = false - compilerOptions.outDir = pathe.resolve(absWorkingDir, outdir) - compilerOptions.rootDir = pathe.resolve(absWorkingDir, outbase) - - compilerOptions = tscu.normalizeCompilerOptions(compilerOptions) - - compilerOptions = defaults(compilerOptions, shake({ - allowJs: true, - allowUmdGlobalAccess: format === 'iife', - allowUnreachableCode: false, - baseUrl: absWorkingDir, - checkJs: false, - esModuleInterop: true, - forceConsistentCasingInFileNames: true, - isolatedModules: true, - module: ts.ModuleKind.ESNext, - moduleResolution: tscu.normalizeModuleResolution( - tscu.ModuleResolutionKind.NodeJs - ), - noImplicitAny: true, - noImplicitOverride: true, - noImplicitReturns: true, - preserveConstEnums: true, - preserveSymlinks, - pretty: color, - resolveJsonModule: true, - skipLibCheck: true, - target: ts.ScriptTarget.ESNext - })) - - /** - * TypeScript compiler host. - * - * @const {CompilerHost} host - */ - const host: CompilerHost = ts.createCompilerHost(compilerOptions) - - /** - * Virtual file system for declaration files. - * - * @const {Record} vfs - */ - const vfs: Record = {} - - // first letter before "js" or "ts" in output file extension - const [, cm = ''] = /\.(c|m)?[jt]sx?$/.exec(ext)! - - /** - * Write a declaration file to {@linkcode vfs}. - * - * @param {string} filename - * Name of file to write - * @param {string} contents - * Content to write - * @return {undefined} - */ - host.writeFile = function writeFile( - filename: string, - contents: string - ): undefined { - filename = filename.replace(EXT_DTS_REGEX, `.d.${cm}ts`) - return void (vfs[filename] = contents) - } - - // emit declarations to virtual file system - ts.createProgram(files, compilerOptions, host).emit() - - // insert declaration files - result.outputFiles = result.outputFiles.flatMap(output => { - /** - * Absolute path to declaration file for {@linkcode output}. - * - * @const {string} dtsPath - */ - const dtsPath: string = EXT_JS_REGEX.test(output.path) - ? output.path.replace(EXT_JS_REGEX, '.d.$1ts') - : EXT_TS_REGEX.test(output.path) && - !EXT_DTS_REGEX.test(output.path) - ? output.path.replace(EXT_TS_REGEX, '.d.$2ts') - : '' - - if (dtsPath in vfs) { - /** - * Relative path to declaration output file. - * - * @const {string} dtsOutfile - */ - const dtsOutfile: string = dtsPath - .slice(absWorkingDir.length) - .replace(/^[/\\]/, '') - - /** - * Relative path to output file. - * - * @const {string} outfile - */ - const outfile: string = output.path - .slice(absWorkingDir.length) - .replace(/^[/\\]/, '') - - /** - * Declaration output file text. - * - * @const {string} text - */ - const text: string = vfs[dtsPath]! - - /** - * Declaration output file contents. - * - * @const {Uint8Array} contents - */ - const contents: Uint8Array = new TextEncoder().encode(text) - - /** - * Declaration file output. - * - * @const {typeof output} dts - */ - const dts: typeof output = Object.defineProperties({ - contents, - hash: '', - path: dtsPath, - text: '' - }, { - text: { get: () => text } - }) - - // update metafile - result.metafile!.outputs[dtsOutfile] = { - ...result.metafile!.outputs[outfile]!, - bytes: Buffer.byteLength(contents) - } - - // filter output files - if (options?.only) { - delete result.metafile!.outputs[outfile] - return [dts] - } - - return [output, dts] - } - - return [output] - }) - } - - return void result - }) - } - - return void build - } -} diff --git a/build/plugins/write.ts b/build/plugins/write.mts similarity index 100% rename from build/plugins/write.ts rename to build/plugins/write.mts diff --git a/eslint.base.config.mjs b/eslint.base.config.mjs index 279f3c1a..0374621a 100644 --- a/eslint.base.config.mjs +++ b/eslint.base.config.mjs @@ -991,6 +991,17 @@ export default [ 'require-await': 0 } }, + { + files: ['**/*.+(cts|mts)'], + rules: { + '@typescript-eslint/consistent-type-assertions': [ + 2, + { + assertionStyle: 'as' + } + ] + } + }, { files: ['**/*.d.+(cts|mts|ts)'], rules: { @@ -1011,17 +1022,21 @@ export default [ } }, { - files: ['**/*.interface.ts', '**/interfaces/*.ts', '**/types/*.ts'], + files: [ + '**/*.interface.+(mts|ts)', + '**/interfaces/*.+(mts|ts)', + '**/types/*.+(mts|ts)' + ], rules: { '@typescript-eslint/no-invalid-void-type': 0 } }, { files: [ - '**/__mocks__/**/*.+(ts|tsx)', - '**/__tests__/*.spec.+(ts|tsx)', - '**/__tests__/*.spec-d.ts', - '__tests__/setup/*.ts' + '**/__mocks__/**/*.+(mts|ts|tsx)', + '**/__tests__/*.spec.+(mts|ts|tsx)', + '**/__tests__/*.spec-d.+(mts|ts)', + '__tests__/setup/*.+(mts|ts|tsx)' ], languageOptions: { globals: { @@ -1085,7 +1100,7 @@ export default [ } }, { - files: ['**/__tests__/*.spec-d.ts'], + files: ['**/__tests__/*.spec-d.+(mts|ts)'], languageOptions: { globals: { assertType: true, @@ -1099,13 +1114,17 @@ export default [ } }, { - files: ['**/*.abstract.ts'], + files: ['**/*.abstract.+(mts|ts)'], rules: { '@typescript-eslint/no-useless-constructor': 0 } }, { - files: ['**/enums/*.ts', '**/interfaces/*.ts', '**/types/*.ts'], + files: [ + '**/enums/*.+(mts|ts)', + '**/interfaces/*.+(mts|ts)', + '**/types/*.+(mts|ts)' + ], rules: { 'unicorn/no-keyword-prefix': 0 } diff --git a/package.json b/package.json index c1df375c..e61ad3f9 100644 --- a/package.json +++ b/package.json @@ -39,16 +39,16 @@ ], "exports": { ".": { - "mlly": "./src/index.ts", + "mlly": "./src/index.mts", "default": "./dist/index.mjs" }, "./package.json": "./package.json" }, "imports": { - "#build/*": "./build/*.ts", - "#fixtures/*": "./__fixtures__/*.ts", + "#build/*": "./build/*.mts", + "#fixtures/*": "./__fixtures__/*.mts", "#interfaces/*": { - "mlly": "./src/interfaces/*.ts", + "mlly": "./src/interfaces/*.mts", "default": "./dist/interfaces/*.d.mts" }, "#internal/fs": { @@ -57,30 +57,30 @@ "default": "./dist/internal/fs.d.mts" }, "browser": { - "mlly": "./src/internal/fs.browser.ts", + "mlly": "./src/internal/fs.browser.mts", "default": "./dist/internal/fs.browser.mjs" }, "node": "fs", "default": "fs" }, "#internal/*": { - "mlly": "./src/internal/*.ts", + "mlly": "./src/internal/*.mts", "default": "./dist/internal/*.mjs" }, "#lib/*": { - "mlly": "./src/lib/*.ts", + "mlly": "./src/lib/*.mts", "default": "./dist/lib/*.mjs" }, - "#tests/*": "./__tests__/*.ts", + "#tests/*": "./__tests__/*.mts", "#types/*": { - "mlly": "./src/types/*.ts", + "mlly": "./src/types/*.mts", "default": "./dist/types/*.d.mts" } }, "module": "./dist/index.mjs", "types": "./dist/index.d.mts", "scripts": { - "build": "yarn clean:build; node --conditions development --conditions mlly/build --conditions mlly --experimental-strip-types --experimental-transform-types ./build/build.ts", + "build": "yarn clean:build; node --conditions development --conditions mlly/build --conditions mlly --experimental-strip-types --experimental-transform-types ./build/build.mts", "check:ci": "yarn dedupe --check && yarn check:format && yarn check:lint && yarn check:spelling && yarn typecheck && yarn test:cov && yarn pack && yarn check:types:build && attw package.tgz && yarn clean:pack", "check:format": "dprint check --incremental=false", "check:lint": "eslint --exit-on-fatal-error --max-warnings 0 .", diff --git a/src/__tests__/index.e2e.spec.ts b/src/__tests__/index.e2e.spec.mts similarity index 100% rename from src/__tests__/index.e2e.spec.ts rename to src/__tests__/index.e2e.spec.mts diff --git a/src/index.ts b/src/index.mts similarity index 100% rename from src/index.ts rename to src/index.mts diff --git a/src/interfaces/__tests__/aliases.spec-d.ts b/src/interfaces/__tests__/aliases.spec-d.mts similarity index 100% rename from src/interfaces/__tests__/aliases.spec-d.ts rename to src/interfaces/__tests__/aliases.spec-d.mts diff --git a/src/interfaces/__tests__/file-system.spec-d.ts b/src/interfaces/__tests__/file-system.spec-d.mts similarity index 100% rename from src/interfaces/__tests__/file-system.spec-d.ts rename to src/interfaces/__tests__/file-system.spec-d.mts diff --git a/src/interfaces/__tests__/main-field-map.spec-d.ts b/src/interfaces/__tests__/main-field-map.spec-d.mts similarity index 100% rename from src/interfaces/__tests__/main-field-map.spec-d.ts rename to src/interfaces/__tests__/main-field-map.spec-d.mts diff --git a/src/interfaces/__tests__/module-format-map.spec-d.ts b/src/interfaces/__tests__/module-format-map.spec-d.mts similarity index 100% rename from src/interfaces/__tests__/module-format-map.spec-d.ts rename to src/interfaces/__tests__/module-format-map.spec-d.mts diff --git a/src/interfaces/__tests__/options-resolve-alias.spec-d.ts b/src/interfaces/__tests__/options-resolve-alias.spec-d.mts similarity index 100% rename from src/interfaces/__tests__/options-resolve-alias.spec-d.ts rename to src/interfaces/__tests__/options-resolve-alias.spec-d.mts diff --git a/src/interfaces/__tests__/options-resolve-module.spec-d.ts b/src/interfaces/__tests__/options-resolve-module.spec-d.mts similarity index 100% rename from src/interfaces/__tests__/options-resolve-module.spec-d.ts rename to src/interfaces/__tests__/options-resolve-module.spec-d.mts diff --git a/src/interfaces/__tests__/protocol-map.spec-d.ts b/src/interfaces/__tests__/protocol-map.spec-d.mts similarity index 100% rename from src/interfaces/__tests__/protocol-map.spec-d.ts rename to src/interfaces/__tests__/protocol-map.spec-d.mts diff --git a/src/interfaces/__tests__/stats.spec-d.ts b/src/interfaces/__tests__/stats.spec-d.mts similarity index 100% rename from src/interfaces/__tests__/stats.spec-d.ts rename to src/interfaces/__tests__/stats.spec-d.mts diff --git a/src/interfaces/aliases.ts b/src/interfaces/aliases.mts similarity index 100% rename from src/interfaces/aliases.ts rename to src/interfaces/aliases.mts diff --git a/src/interfaces/file-system.ts b/src/interfaces/file-system.mts similarity index 100% rename from src/interfaces/file-system.ts rename to src/interfaces/file-system.mts diff --git a/src/interfaces/index.ts b/src/interfaces/index.mts similarity index 100% rename from src/interfaces/index.ts rename to src/interfaces/index.mts diff --git a/src/interfaces/main-field-map.ts b/src/interfaces/main-field-map.mts similarity index 100% rename from src/interfaces/main-field-map.ts rename to src/interfaces/main-field-map.mts diff --git a/src/interfaces/module-format-map.ts b/src/interfaces/module-format-map.mts similarity index 100% rename from src/interfaces/module-format-map.ts rename to src/interfaces/module-format-map.mts diff --git a/src/interfaces/options-resolve-alias.ts b/src/interfaces/options-resolve-alias.mts similarity index 100% rename from src/interfaces/options-resolve-alias.ts rename to src/interfaces/options-resolve-alias.mts diff --git a/src/interfaces/options-resolve-module.ts b/src/interfaces/options-resolve-module.mts similarity index 100% rename from src/interfaces/options-resolve-module.ts rename to src/interfaces/options-resolve-module.mts diff --git a/src/interfaces/protocol-map.ts b/src/interfaces/protocol-map.mts similarity index 100% rename from src/interfaces/protocol-map.ts rename to src/interfaces/protocol-map.mts diff --git a/src/interfaces/stats.ts b/src/interfaces/stats.mts similarity index 100% rename from src/interfaces/stats.ts rename to src/interfaces/stats.mts diff --git a/src/internal/__snapshots__/invalid-package-target.snap b/src/internal/__snapshots__/invalid-package-target.snap index 9c09406d..3826b042 100644 --- a/src/internal/__snapshots__/invalid-package-target.snap +++ b/src/internal/__snapshots__/invalid-package-target.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`unit:internal/invalidPackageTarget > should return new \`ERR_INVALID_PACKAGE_TARGET\` (0) 1`] = `Invalid "imports" target "./__fixtures__/node_modules/*" defined for '#nm/*' in the package config \${process.cwd()}/package.json imported from \${process.cwd()}/src/internal/__tests__/invalid-package-target.spec.ts`; +exports[`unit:internal/invalidPackageTarget > should return new \`ERR_INVALID_PACKAGE_TARGET\` (0) 1`] = `Invalid "imports" target "./__fixtures__/node_modules/*" defined for '#nm/*' in the package config \${process.cwd()}/package.json imported from \${process.cwd()}/src/internal/__tests__/invalid-package-target.spec.mts`; exports[`unit:internal/invalidPackageTarget > should return new \`ERR_INVALID_PACKAGE_TARGET\` (1) 1`] = `Invalid "exports" main target "[null]" defined in the package config \${process.cwd()}/__fixtures__/node_modules/invalid-target-array/package.json; targets must start with "./"`; diff --git a/src/internal/__tests__/check-invalid-segments.spec.ts b/src/internal/__tests__/check-invalid-segments.spec.mts similarity index 100% rename from src/internal/__tests__/check-invalid-segments.spec.ts rename to src/internal/__tests__/check-invalid-segments.spec.mts diff --git a/src/internal/__tests__/invalid-package-target.spec.ts b/src/internal/__tests__/invalid-package-target.spec.mts similarity index 100% rename from src/internal/__tests__/invalid-package-target.spec.ts rename to src/internal/__tests__/invalid-package-target.spec.mts diff --git a/src/internal/__tests__/invalid-subpath.spec.ts b/src/internal/__tests__/invalid-subpath.spec.mts similarity index 100% rename from src/internal/__tests__/invalid-subpath.spec.ts rename to src/internal/__tests__/invalid-subpath.spec.mts diff --git a/src/internal/chars.ts b/src/internal/chars.mts similarity index 100% rename from src/internal/chars.ts rename to src/internal/chars.mts diff --git a/src/internal/check-invalid-segments.ts b/src/internal/check-invalid-segments.mts similarity index 100% rename from src/internal/check-invalid-segments.ts rename to src/internal/check-invalid-segments.mts diff --git a/src/internal/fs.browser.ts b/src/internal/fs.browser.mts similarity index 100% rename from src/internal/fs.browser.ts rename to src/internal/fs.browser.mts diff --git a/src/internal/invalid-package-target.ts b/src/internal/invalid-package-target.mts similarity index 100% rename from src/internal/invalid-package-target.ts rename to src/internal/invalid-package-target.mts diff --git a/src/internal/invalid-subpath.ts b/src/internal/invalid-subpath.mts similarity index 100% rename from src/internal/invalid-subpath.ts rename to src/internal/invalid-subpath.mts diff --git a/src/lib/__snapshots__/resolve-alias.snap b/src/lib/__snapshots__/resolve-alias.snap index 3076db9a..4a9b5748 100644 --- a/src/lib/__snapshots__/resolve-alias.snap +++ b/src/lib/__snapshots__/resolve-alias.snap @@ -2,8 +2,8 @@ exports[`unit:lib/resolveAlias > should return specifier of aliased module ("#lib") 1`] = `"./src/lib/index"`; -exports[`unit:lib/resolveAlias > should return specifier of aliased module ("#lib/resolve-alias") 1`] = `"../resolve-alias.ts"`; +exports[`unit:lib/resolveAlias > should return specifier of aliased module ("#lib/resolve-alias") 1`] = `"../resolve-alias.mts"`; -exports[`unit:lib/resolveAlias > should return specifier of aliased module ("#tests/reporters/notifier.ts") 1`] = `file://\${process.cwd()}/__tests__/reporters/notifier.ts`; +exports[`unit:lib/resolveAlias > should return specifier of aliased module ("#tests/reporters/notifier.mts") 1`] = `file://\${process.cwd()}/__tests__/reporters/notifier.mts`; exports[`unit:lib/resolveAlias > should return specifier of aliased module ("#tests/utils/to-package-url") 1`] = `"./__tests__/utils/to-package-url"`; diff --git a/src/lib/__snapshots__/resolve-module.snap b/src/lib/__snapshots__/resolve-module.snap index 00df3df5..57f548e0 100644 --- a/src/lib/__snapshots__/resolve-module.snap +++ b/src/lib/__snapshots__/resolve-module.snap @@ -2,7 +2,7 @@ exports[`unit:lib/resolveModule > should return resolved URL ("#internal/fs") 1`] = `"node:fs"`; -exports[`unit:lib/resolveModule > should return resolved URL ("../../../src") 1`] = `file://\${process.cwd()}/src/index.ts`; +exports[`unit:lib/resolveModule > should return resolved URL ("../../../src") 1`] = `file://\${process.cwd()}/src/index.mts`; exports[`unit:lib/resolveModule > should return resolved URL ("../../lib") 1`] = `file://\${process.cwd()}/src/lib/index.mjs`; diff --git a/src/lib/__snapshots__/resolver.snap b/src/lib/__snapshots__/resolver.snap index 30ed8468..ca7b2547 100644 --- a/src/lib/__snapshots__/resolver.snap +++ b/src/lib/__snapshots__/resolver.snap @@ -1,18 +1,18 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`unit:lib/resolver > legacyMainResolve > should throw if main entry point is not found 1`] = `Cannot find package '\${process.cwd()}/__fixtures__/node_modules/@flex-development/mlly/' imported from \${process.cwd()}/__fixtures__/parent.ts`; +exports[`unit:lib/resolver > legacyMainResolve > should throw if main entry point is not found 1`] = `Cannot find package '\${process.cwd()}/__fixtures__/node_modules/@flex-development/mlly/' imported from \${process.cwd()}/__fixtures__/parent.mts`; exports[`unit:lib/resolver > moduleResolve > should return resolved URL (0) 1`] = `"node:fs"`; -exports[`unit:lib/resolver > moduleResolve > should return resolved URL (1) 1`] = `file://\${process.cwd()}/src/internal/fs.browser.ts`; +exports[`unit:lib/resolver > moduleResolve > should return resolved URL (1) 1`] = `file://\${process.cwd()}/src/internal/fs.browser.mts`; exports[`unit:lib/resolver > moduleResolve > should return resolved URL (2) 1`] = `"node:path/posix"`; exports[`unit:lib/resolver > moduleResolve > should return resolved URL (3) 1`] = `file://\${process.cwd()}/__fixtures__/node_modules/subpath-imports/internal/path/windows.browser.mjs`; -exports[`unit:lib/resolver > moduleResolve > should return resolved URL (4) 1`] = `file://\${process.cwd()}/src/lib/resolver.ts`; +exports[`unit:lib/resolver > moduleResolve > should return resolved URL (4) 1`] = `file://\${process.cwd()}/src/lib/resolver.mts`; -exports[`unit:lib/resolver > moduleResolve > should return resolved URL (5) 1`] = `file://\${process.cwd()}/src/lib/resolver.ts`; +exports[`unit:lib/resolver > moduleResolve > should return resolved URL (5) 1`] = `file://\${process.cwd()}/src/lib/resolver.mts`; exports[`unit:lib/resolver > moduleResolve > should return resolved URL (6) 1`] = `file://\${process.cwd()}/node_modules/@flex-development/mkbuild/dist/index.mjs`; @@ -24,7 +24,7 @@ exports[`unit:lib/resolver > moduleResolve > should return resolved URL (9) 1`] exports[`unit:lib/resolver > moduleResolve > should return resolved URL (10) 1`] = `file://\${process.cwd()}/node_modules/vitest/dist/index.js`; -exports[`unit:lib/resolver > moduleResolve > should return resolved URL (11) 1`] = `file://\${process.cwd()}/src/lib/index.ts`; +exports[`unit:lib/resolver > moduleResolve > should return resolved URL (11) 1`] = `file://\${process.cwd()}/src/lib/index.mts`; exports[`unit:lib/resolver > moduleResolve > should return resolved URL (12) 1`] = `file://\${process.cwd()}/node_modules/@flex-development/errnode/dist/index.mjs`; @@ -40,38 +40,38 @@ exports[`unit:lib/resolver > moduleResolve > should return resolved URL (17) 1`] exports[`unit:lib/resolver > moduleResolve > should return resolved URL (18) 1`] = `file://\${process.cwd()}/package.json`; -exports[`unit:lib/resolver > moduleResolve > should return resolved URL (19) 1`] = `file://\${process.cwd()}/src/index.ts`; +exports[`unit:lib/resolver > moduleResolve > should return resolved URL (19) 1`] = `file://\${process.cwd()}/src/index.mts`; exports[`unit:lib/resolver > moduleResolve > should return resolved URL (20) 1`] = `file://\${process.cwd()}/__fixtures__/node_modules/subpath-exports/lib/a.js`; exports[`unit:lib/resolver > moduleResolve > should return resolved URL (21) 1`] = `file://\${process.cwd()}/__fixtures__/node_modules/subpath-exports/lib/a.js`; -exports[`unit:lib/resolver > moduleResolve > should throw if \`specifier\` contains encoded separators 1`] = `Invalid module '/lib%2futils.mjs' must not include encoded "/" or "\\" characters imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > moduleResolve > should throw if \`specifier\` contains encoded separators 1`] = `Invalid module '/lib%2futils.mjs' must not include encoded "/" or "\\" characters imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > moduleResolve > should throw if \`specifier\` resolves to a directory 1`] = `Directory import '\${process.cwd()}/src/' is not supported resolving ES modules imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > moduleResolve > should throw if \`specifier\` resolves to a directory 1`] = `Directory import '\${process.cwd()}/src/' is not supported resolving ES modules imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > moduleResolve > should throw if \`specifier\` resolves to missing file 1`] = `Cannot find module '\${process.cwd()}/src/index.mts' imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > moduleResolve > should throw if \`specifier\` resolves to missing file 1`] = `Cannot find module '\${process.cwd()}/src/index.ts' imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; exports[`unit:lib/resolver > moduleResolve > should throw if module referrer is invalid (0) 1`] = `"Failed to resolve module specifier "./relative" from "data:text/javascript,export default import.meta.resolve("./relative")": Invalid relative URL or base scheme is not hierarchical."`; exports[`unit:lib/resolver > moduleResolve > should throw if module referrer is invalid (1) 1`] = `"Failed to resolve module specifier "not-builtin" from "data:text/javascript,export default import.meta.resolve("not-builtin")": Invalid relative URL or base scheme is not hierarchical."`; -exports[`unit:lib/resolver > packageExportsResolve > should throw if \`exports\` object is invalid 1`] = `Invalid package config \${process.cwd()}/package.json while importing file://\${process.cwd()}/src/lib/__tests__/resolver.spec.ts. "exports" cannot contain some keys starting starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`; +exports[`unit:lib/resolver > packageExportsResolve > should throw if \`exports\` object is invalid 1`] = `Invalid package config \${process.cwd()}/package.json while importing file://\${process.cwd()}/src/lib/__tests__/resolver.spec.mts. "exports" cannot contain some keys starting starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`; -exports[`unit:lib/resolver > packageExportsResolve > should throw if package path is not exported 1`] = `Package subpath './utils' is not defined by 'exports' in \${process.cwd()}/package.json imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > packageExportsResolve > should throw if package path is not exported 1`] = `Package subpath './utils' is not defined by 'exports' in \${process.cwd()}/package.json imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > packageImportsResolve > should throw if \`specifier\` is invalid (0) 1`] = `Invalid module '#' is not a valid internal imports specifier name imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > packageImportsResolve > should throw if \`specifier\` is invalid (0) 1`] = `Invalid module '#' is not a valid internal imports specifier name imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > packageImportsResolve > should throw if \`specifier\` is invalid (1) 1`] = `Invalid module '#/' is not a valid internal imports specifier name imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > packageImportsResolve > should throw if \`specifier\` is invalid (1) 1`] = `Invalid module '#/' is not a valid internal imports specifier name imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > packageImportsResolve > should throw if \`specifier\` is invalid (2) 1`] = `Invalid module '@flex-development/mlly' is not a valid internal imports specifier name imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > packageImportsResolve > should throw if \`specifier\` is invalid (2) 1`] = `Invalid module '@flex-development/mlly' is not a valid internal imports specifier name imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > packageImportsResolve > should throw if package import is not defined 1`] = `Package import specifier '#mocks' is not defined in package \${process.cwd()}/package.json imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > packageImportsResolve > should throw if package import is not defined 1`] = `Package import specifier '#mocks' is not defined in package \${process.cwd()}/package.json imported from \${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > packageResolve > should throw if \`specifier\` cannot be resolved 1`] = `Cannot find package 'missing-package' imported from \${process.cwd()}/__fixtures__/parent.ts`; +exports[`unit:lib/resolver > packageResolve > should throw if \`specifier\` cannot be resolved 1`] = `Cannot find package 'missing-package' imported from \${process.cwd()}/__fixtures__/parent.mts`; -exports[`unit:lib/resolver > packageResolve > should throw if \`specifier\` is invalid (0) 1`] = `Invalid module '@flex-development\\errnode' is not a valid package name imported from file://\${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > packageResolve > should throw if \`specifier\` is invalid (0) 1`] = `Invalid module '@flex-development\\errnode' is not a valid package name imported from file://\${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > packageResolve > should throw if \`specifier\` is invalid (1) 1`] = `Invalid module '@' is not a valid package name imported from file://\${process.cwd()}/src/lib/__tests__/resolver.spec.ts`; +exports[`unit:lib/resolver > packageResolve > should throw if \`specifier\` is invalid (1) 1`] = `Invalid module '@' is not a valid package name imported from file://\${process.cwd()}/src/lib/__tests__/resolver.spec.mts`; -exports[`unit:lib/resolver > packageTargetResolve > should throw if package config is invalid 1`] = `Invalid package config \${process.cwd()}/__fixtures__/node_modules/invalid-package-config/package.json while importing file://\${process.cwd()}/src/lib/__tests__/resolver.spec.ts. "exports" cannot contain numeric property keys`; +exports[`unit:lib/resolver > packageTargetResolve > should throw if package config is invalid 1`] = `Invalid package config \${process.cwd()}/__fixtures__/node_modules/invalid-package-config/package.json while importing file://\${process.cwd()}/src/lib/__tests__/resolver.spec.mts. "exports" cannot contain numeric property keys`; diff --git a/src/lib/__tests__/can-parse-url.spec.ts b/src/lib/__tests__/can-parse-url.spec.mts similarity index 100% rename from src/lib/__tests__/can-parse-url.spec.ts rename to src/lib/__tests__/can-parse-url.spec.mts diff --git a/src/lib/__tests__/cwd.spec.ts b/src/lib/__tests__/cwd.spec.mts similarity index 100% rename from src/lib/__tests__/cwd.spec.ts rename to src/lib/__tests__/cwd.spec.mts diff --git a/src/lib/__tests__/default-conditions.spec.ts b/src/lib/__tests__/default-conditions.spec.mts similarity index 100% rename from src/lib/__tests__/default-conditions.spec.ts rename to src/lib/__tests__/default-conditions.spec.mts diff --git a/src/lib/__tests__/default-extensions.spec.ts b/src/lib/__tests__/default-extensions.spec.mts similarity index 100% rename from src/lib/__tests__/default-extensions.spec.ts rename to src/lib/__tests__/default-extensions.spec.mts diff --git a/src/lib/__tests__/extension-format-map.spec.ts b/src/lib/__tests__/extension-format-map.spec.mts similarity index 100% rename from src/lib/__tests__/extension-format-map.spec.ts rename to src/lib/__tests__/extension-format-map.spec.mts diff --git a/src/lib/__tests__/is-absolute-specifier.spec.ts b/src/lib/__tests__/is-absolute-specifier.spec.mts similarity index 100% rename from src/lib/__tests__/is-absolute-specifier.spec.ts rename to src/lib/__tests__/is-absolute-specifier.spec.mts diff --git a/src/lib/__tests__/is-array-index.spec.ts b/src/lib/__tests__/is-array-index.spec.mts similarity index 100% rename from src/lib/__tests__/is-array-index.spec.ts rename to src/lib/__tests__/is-array-index.spec.mts diff --git a/src/lib/__tests__/is-bare-specifier.spec.ts b/src/lib/__tests__/is-bare-specifier.spec.mts similarity index 100% rename from src/lib/__tests__/is-bare-specifier.spec.ts rename to src/lib/__tests__/is-bare-specifier.spec.mts diff --git a/src/lib/__tests__/is-directory.spec.ts b/src/lib/__tests__/is-directory.spec.mts similarity index 94% rename from src/lib/__tests__/is-directory.spec.ts rename to src/lib/__tests__/is-directory.spec.mts index 97215c26..80cd83a6 100644 --- a/src/lib/__tests__/is-directory.spec.ts +++ b/src/lib/__tests__/is-directory.spec.mts @@ -13,7 +13,7 @@ describe('unit:lib/isDirectory', () => { it.each([ 'directory', new URL('node:fs'), - String(new URL('src/index.ts', cwd())) + String(new URL('src/index.mts', cwd())) ])('should return `false` if `id` is not a directory (%#)', id => { expect(testSubject(id, fs)).to.be.false }) diff --git a/src/lib/__tests__/is-file.spec.ts b/src/lib/__tests__/is-file.spec.mts similarity index 93% rename from src/lib/__tests__/is-file.spec.ts rename to src/lib/__tests__/is-file.spec.mts index 7a419d97..0054812f 100644 --- a/src/lib/__tests__/is-file.spec.ts +++ b/src/lib/__tests__/is-file.spec.mts @@ -20,7 +20,7 @@ describe('unit:lib/isFile', () => { it.each([ pathToFileURL('package.json'), - String(new URL('vitest.config.ts', cwd())) + String(new URL('vitest.config.mts', cwd())) ])('should return `true` if `id` is a file (%#)', id => { expect(testSubject(id)).to.be.true }) diff --git a/src/lib/__tests__/is-imports-subpath.spec.ts b/src/lib/__tests__/is-imports-subpath.spec.mts similarity index 100% rename from src/lib/__tests__/is-imports-subpath.spec.ts rename to src/lib/__tests__/is-imports-subpath.spec.mts diff --git a/src/lib/__tests__/is-relative-specifier.spec.ts b/src/lib/__tests__/is-relative-specifier.spec.mts similarity index 100% rename from src/lib/__tests__/is-relative-specifier.spec.ts rename to src/lib/__tests__/is-relative-specifier.spec.mts diff --git a/src/lib/__tests__/lookup-package-scope.spec.ts b/src/lib/__tests__/lookup-package-scope.spec.mts similarity index 100% rename from src/lib/__tests__/lookup-package-scope.spec.ts rename to src/lib/__tests__/lookup-package-scope.spec.mts diff --git a/src/lib/__tests__/pattern-key-compare.spec.ts b/src/lib/__tests__/pattern-key-compare.spec.mts similarity index 100% rename from src/lib/__tests__/pattern-key-compare.spec.ts rename to src/lib/__tests__/pattern-key-compare.spec.mts diff --git a/src/lib/__tests__/pattern-match.spec.ts b/src/lib/__tests__/pattern-match.spec.mts similarity index 100% rename from src/lib/__tests__/pattern-match.spec.ts rename to src/lib/__tests__/pattern-match.spec.mts diff --git a/src/lib/__tests__/read-package-json.spec.ts b/src/lib/__tests__/read-package-json.spec.mts similarity index 97% rename from src/lib/__tests__/read-package-json.spec.ts rename to src/lib/__tests__/read-package-json.spec.mts index 07b9b3f4..526055e3 100644 --- a/src/lib/__tests__/read-package-json.spec.ts +++ b/src/lib/__tests__/read-package-json.spec.mts @@ -37,7 +37,7 @@ describe('unit:lib/readPackageJson', () => { try { testSubject(id, specifier, parent) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect diff --git a/src/lib/__tests__/resolve-alias.spec.ts b/src/lib/__tests__/resolve-alias.spec.mts similarity index 92% rename from src/lib/__tests__/resolve-alias.spec.ts rename to src/lib/__tests__/resolve-alias.spec.mts index 44124671..e959958e 100644 --- a/src/lib/__tests__/resolve-alias.spec.ts +++ b/src/lib/__tests__/resolve-alias.spec.mts @@ -19,10 +19,10 @@ describe('unit:lib/resolveAlias', () => { it.each>([ ['#lib', { aliases: { '#lib': ['src/lib/index'] } }], ['#lib/resolve-alias', { - aliases: { '#lib/*': ['src/lib/*.ts'] }, + aliases: { '#lib/*': ['src/lib/*.mts'] }, parent: import.meta.url }], - ['#tests/reporters/notifier.ts', { + ['#tests/reporters/notifier.mts', { absolute: true, aliases: { '#tests/*': ['__tests__/*'] } }], diff --git a/src/lib/__tests__/resolve-module.spec.ts b/src/lib/__tests__/resolve-module.spec.mts similarity index 98% rename from src/lib/__tests__/resolve-module.spec.ts rename to src/lib/__tests__/resolve-module.spec.mts index 3da95768..eb3bd3b3 100644 --- a/src/lib/__tests__/resolve-module.spec.ts +++ b/src/lib/__tests__/resolve-module.spec.mts @@ -52,7 +52,7 @@ describe('unit:lib/resolveModule', () => { try { testSubject(specifier, parent, options) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect diff --git a/src/lib/__tests__/resolver.spec.ts b/src/lib/__tests__/resolver.spec.mts similarity index 94% rename from src/lib/__tests__/resolver.spec.ts rename to src/lib/__tests__/resolver.spec.mts index 0e32fc92..27bfd7bc 100644 --- a/src/lib/__tests__/resolver.spec.ts +++ b/src/lib/__tests__/resolver.spec.mts @@ -43,7 +43,7 @@ describe('unit:lib/resolver', () => { parent ) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -68,13 +68,13 @@ describe('unit:lib/resolver', () => { new Set(['browser']) ], ['#lib/resolver', import.meta.url, fixtureConditions], - ['../resolver.ts', import.meta.url], - ['@flex-development/mkbuild', pathToFileURL('build.config.ts')], + ['../resolver.mts', import.meta.url], + ['@flex-development/mkbuild', pathToFileURL('build.config.mts')], ['fs', import.meta.url], ['node:fs/promises', import.meta.url], ['node:url', import.meta.url], ['vitest', import.meta.url], - [String(pathToFileURL('src/lib/index.ts')), import.meta.url], + [String(pathToFileURL('src/lib/index.mts')), import.meta.url], [errnode.name, import.meta.url], [exportsSugar.name, parent], [exportsSugarA.name, parent], @@ -82,7 +82,7 @@ describe('unit:lib/resolver', () => { [legacyMain1.name, parent], [legacyMain2.name, parent], [pkg.name + '/package.json', import.meta.url], - [resolve('src/index.ts'), import.meta.url], + [resolve('src/index.mts'), import.meta.url], [subpathExports.name + '/lib/a', parent], [subpathExports.name + '/lib/a.js', parent] ])('should return resolved URL (%#)', ( @@ -123,7 +123,7 @@ describe('unit:lib/resolver', () => { try { testSubject.moduleResolve(sep + 'lib%2futils.mjs', import.meta.url) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -141,7 +141,7 @@ describe('unit:lib/resolver', () => { try { testSubject.moduleResolve(specifier, import.meta.url) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -153,14 +153,14 @@ describe('unit:lib/resolver', () => { it('should throw if `specifier` resolves to missing file', () => { // Arrange - const specifier: string = resolve('src/index.mts') + const specifier: string = resolve('src/index.ts') let error!: NodeError // Act try { testSubject.moduleResolve(specifier, import.meta.url) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -202,7 +202,7 @@ describe('unit:lib/resolver', () => { fs ) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -222,12 +222,12 @@ describe('unit:lib/resolver', () => { testSubject.packageExportsResolve( cwd(), dot, - { [dot]: './dist/index.mjs', 'ts-node': './src/index.ts' }, + { [dot]: './dist/index.mjs', 'ts-node': './src/index.mts' }, null, import.meta.url ) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -251,7 +251,7 @@ describe('unit:lib/resolver', () => { import.meta.url ) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -271,7 +271,7 @@ describe('unit:lib/resolver', () => { try { testSubject.packageImportsResolve('#mocks', import.meta.url) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -292,7 +292,7 @@ describe('unit:lib/resolver', () => { try { testSubject.packageImportsResolve(specifier, import.meta.url) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -311,7 +311,7 @@ describe('unit:lib/resolver', () => { try { testSubject.packageResolve('missing-package', parent) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -331,7 +331,7 @@ describe('unit:lib/resolver', () => { try { testSubject.packageResolve(specifier, parent) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -372,7 +372,7 @@ describe('unit:lib/resolver', () => { import.meta.url ) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -397,7 +397,7 @@ describe('unit:lib/resolver', () => { import.meta.url ) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect @@ -505,7 +505,7 @@ describe('unit:lib/resolver', () => { fs ) } catch (e: unknown) { - error = e + error = e as typeof error } // Expect diff --git a/src/lib/__tests__/to-relative-specifier.spec.ts b/src/lib/__tests__/to-relative-specifier.spec.mts similarity index 92% rename from src/lib/__tests__/to-relative-specifier.spec.ts rename to src/lib/__tests__/to-relative-specifier.spec.mts index 2beec36b..6838fd2b 100644 --- a/src/lib/__tests__/to-relative-specifier.spec.ts +++ b/src/lib/__tests__/to-relative-specifier.spec.mts @@ -10,7 +10,7 @@ describe('unit:lib/toRelativeSpecifier', () => { it.each>([ [ pathe.pathToFileURL('src/lib'), - pathe.pathToFileURL('src/lib/resolve-alias.ts') + pathe.pathToFileURL('src/lib/resolve-alias.mts') ], [pathe.pathToFileURL('src/lib/cwd'), pathe.pathToFileURL('src/lib')], [pathe.pathToFileURL('src/lib/to-relative-specifier'), import.meta.url], diff --git a/src/lib/can-parse-url.ts b/src/lib/can-parse-url.mts similarity index 100% rename from src/lib/can-parse-url.ts rename to src/lib/can-parse-url.mts diff --git a/src/lib/cwd.ts b/src/lib/cwd.mts similarity index 100% rename from src/lib/cwd.ts rename to src/lib/cwd.mts diff --git a/src/lib/default-conditions.ts b/src/lib/default-conditions.mts similarity index 100% rename from src/lib/default-conditions.ts rename to src/lib/default-conditions.mts diff --git a/src/lib/default-extensions.ts b/src/lib/default-extensions.mts similarity index 100% rename from src/lib/default-extensions.ts rename to src/lib/default-extensions.mts diff --git a/src/lib/default-main-fields.ts b/src/lib/default-main-fields.mts similarity index 100% rename from src/lib/default-main-fields.ts rename to src/lib/default-main-fields.mts diff --git a/src/lib/extension-format-map.ts b/src/lib/extension-format-map.mts similarity index 100% rename from src/lib/extension-format-map.ts rename to src/lib/extension-format-map.mts diff --git a/src/lib/formats.ts b/src/lib/formats.mts similarity index 100% rename from src/lib/formats.ts rename to src/lib/formats.mts diff --git a/src/lib/index.ts b/src/lib/index.mts similarity index 100% rename from src/lib/index.ts rename to src/lib/index.mts diff --git a/src/lib/is-absolute-specifier.ts b/src/lib/is-absolute-specifier.mts similarity index 100% rename from src/lib/is-absolute-specifier.ts rename to src/lib/is-absolute-specifier.mts diff --git a/src/lib/is-array-index.ts b/src/lib/is-array-index.mts similarity index 100% rename from src/lib/is-array-index.ts rename to src/lib/is-array-index.mts diff --git a/src/lib/is-bare-specifier.ts b/src/lib/is-bare-specifier.mts similarity index 100% rename from src/lib/is-bare-specifier.ts rename to src/lib/is-bare-specifier.mts diff --git a/src/lib/is-directory.ts b/src/lib/is-directory.mts similarity index 100% rename from src/lib/is-directory.ts rename to src/lib/is-directory.mts diff --git a/src/lib/is-file.ts b/src/lib/is-file.mts similarity index 100% rename from src/lib/is-file.ts rename to src/lib/is-file.mts diff --git a/src/lib/is-imports-subpath.ts b/src/lib/is-imports-subpath.mts similarity index 100% rename from src/lib/is-imports-subpath.ts rename to src/lib/is-imports-subpath.mts diff --git a/src/lib/is-relative-specifier.ts b/src/lib/is-relative-specifier.mts similarity index 100% rename from src/lib/is-relative-specifier.ts rename to src/lib/is-relative-specifier.mts diff --git a/src/lib/lookup-package-scope.ts b/src/lib/lookup-package-scope.mts similarity index 100% rename from src/lib/lookup-package-scope.ts rename to src/lib/lookup-package-scope.mts diff --git a/src/lib/pattern-key-compare.ts b/src/lib/pattern-key-compare.mts similarity index 100% rename from src/lib/pattern-key-compare.ts rename to src/lib/pattern-key-compare.mts diff --git a/src/lib/pattern-match.ts b/src/lib/pattern-match.mts similarity index 100% rename from src/lib/pattern-match.ts rename to src/lib/pattern-match.mts diff --git a/src/lib/read-package-json.ts b/src/lib/read-package-json.mts similarity index 98% rename from src/lib/read-package-json.ts rename to src/lib/read-package-json.mts index 829e7c0d..b8f8421c 100644 --- a/src/lib/read-package-json.ts +++ b/src/lib/read-package-json.mts @@ -67,7 +67,7 @@ function readPackageJson( * * @const {Error} cause */ - const cause: Error = e + const cause: Error = e as Error /** * Invalid package config error. diff --git a/src/lib/resolve-alias.ts b/src/lib/resolve-alias.mts similarity index 100% rename from src/lib/resolve-alias.ts rename to src/lib/resolve-alias.mts diff --git a/src/lib/resolve-module.ts b/src/lib/resolve-module.mts similarity index 98% rename from src/lib/resolve-module.ts rename to src/lib/resolve-module.mts index b6eb6af9..c55dd41d 100644 --- a/src/lib/resolve-module.ts +++ b/src/lib/resolve-module.mts @@ -95,7 +95,7 @@ function resolveModule( // add @types resolution attempts if package resolution failed. if ( e.code === codes.ERR_MODULE_NOT_FOUND && - !(e).url + !(e as ErrModuleNotFound).url ) { tries = [ specifier.startsWith('@types/') ? specifier : '@types/' + specifier @@ -110,7 +110,7 @@ function resolveModule( // add extensionless file resolution attempts if file resolution failed. if ( e.code === codes.ERR_MODULE_NOT_FOUND && - (e).url + (e as ErrModuleNotFound).url ) { tries = extensions.map(ext => specifier + pathe.formatExt(ext)) } diff --git a/src/lib/resolver.ts b/src/lib/resolver.mts similarity index 99% rename from src/lib/resolver.ts rename to src/lib/resolver.mts index a1bea39e..0d26d9e0 100644 --- a/src/lib/resolver.ts +++ b/src/lib/resolver.mts @@ -1009,7 +1009,7 @@ function packageTargetResolve( fs ) } catch (e: unknown) { - error = >e + error = e as NonNullable if (error.code !== codes.ERR_INVALID_PACKAGE_TARGET) throw error } @@ -1039,7 +1039,7 @@ function packageTargetResolve( // try resolving conditional target. for (const key of Object.getOwnPropertyNames(target)) { - if (conditions.has(key) || key === 'default') { + if (conditions.has(key as Condition) || key === 'default') { /** * Resolved package target URL. * @@ -1047,7 +1047,7 @@ function packageTargetResolve( */ const resolved: URL | null | undefined = packageTargetResolve( packageUrl, - (target)[key], + (target as ConditionalTargets)[key], subpath, patternMatch, isImports, @@ -1069,7 +1069,7 @@ function packageTargetResolve( throw invalidPackageTarget( packageUrl, subpath, - target, + target as never, isImports, parent ) diff --git a/src/lib/root.ts b/src/lib/root.mts similarity index 100% rename from src/lib/root.ts rename to src/lib/root.mts diff --git a/src/lib/to-relative-specifier.ts b/src/lib/to-relative-specifier.mts similarity index 100% rename from src/lib/to-relative-specifier.ts rename to src/lib/to-relative-specifier.mts diff --git a/src/types/__tests__/change-ext-fn.spec-d.ts b/src/types/__tests__/change-ext-fn.spec-d.mts similarity index 100% rename from src/types/__tests__/change-ext-fn.spec-d.ts rename to src/types/__tests__/change-ext-fn.spec-d.mts diff --git a/src/types/__tests__/main-field.spec-d.ts b/src/types/__tests__/main-field.spec-d.mts similarity index 100% rename from src/types/__tests__/main-field.spec-d.ts rename to src/types/__tests__/main-field.spec-d.mts diff --git a/src/types/__tests__/module-format.spec-d.ts b/src/types/__tests__/module-format.spec-d.mts similarity index 100% rename from src/types/__tests__/module-format.spec-d.ts rename to src/types/__tests__/module-format.spec-d.mts diff --git a/src/types/__tests__/module-id.spec-d.ts b/src/types/__tests__/module-id.spec-d.mts similarity index 100% rename from src/types/__tests__/module-id.spec-d.ts rename to src/types/__tests__/module-id.spec-d.mts diff --git a/src/types/__tests__/numeric.spec-d.ts b/src/types/__tests__/numeric.spec-d.mts similarity index 100% rename from src/types/__tests__/numeric.spec-d.ts rename to src/types/__tests__/numeric.spec-d.mts diff --git a/src/types/__tests__/pattern-key-compare-result.spec-d.ts b/src/types/__tests__/pattern-key-compare-result.spec-d.mts similarity index 100% rename from src/types/__tests__/pattern-key-compare-result.spec-d.ts rename to src/types/__tests__/pattern-key-compare-result.spec-d.mts diff --git a/src/types/__tests__/pattern-match.spec-d.ts b/src/types/__tests__/pattern-match.spec-d.mts similarity index 100% rename from src/types/__tests__/pattern-match.spec-d.ts rename to src/types/__tests__/pattern-match.spec-d.mts diff --git a/src/types/__tests__/protocol.spec-d.ts b/src/types/__tests__/protocol.spec-d.mts similarity index 100% rename from src/types/__tests__/protocol.spec-d.ts rename to src/types/__tests__/protocol.spec-d.mts diff --git a/src/types/change-ext-fn.ts b/src/types/change-ext-fn.mts similarity index 100% rename from src/types/change-ext-fn.ts rename to src/types/change-ext-fn.mts diff --git a/src/types/index.ts b/src/types/index.mts similarity index 100% rename from src/types/index.ts rename to src/types/index.mts diff --git a/src/types/main-field.ts b/src/types/main-field.mts similarity index 100% rename from src/types/main-field.ts rename to src/types/main-field.mts diff --git a/src/types/module-format.ts b/src/types/module-format.mts similarity index 100% rename from src/types/module-format.ts rename to src/types/module-format.mts diff --git a/src/types/module-id.ts b/src/types/module-id.mts similarity index 100% rename from src/types/module-id.ts rename to src/types/module-id.mts diff --git a/src/types/numeric.ts b/src/types/numeric.mts similarity index 100% rename from src/types/numeric.ts rename to src/types/numeric.mts diff --git a/src/types/pattern-key-compare-result.ts b/src/types/pattern-key-compare-result.mts similarity index 100% rename from src/types/pattern-key-compare-result.ts rename to src/types/pattern-key-compare-result.mts diff --git a/src/types/pattern-match.ts b/src/types/pattern-match.mts similarity index 100% rename from src/types/pattern-match.ts rename to src/types/pattern-match.mts diff --git a/src/types/protocol.ts b/src/types/protocol.mts similarity index 100% rename from src/types/protocol.ts rename to src/types/protocol.mts diff --git a/tsconfig.typecheck.json b/tsconfig.typecheck.json index 84e0a59f..1a2a3d84 100644 --- a/tsconfig.typecheck.json +++ b/tsconfig.typecheck.json @@ -7,12 +7,12 @@ "typings/@faker-js/faker/global.d.ts", "typings/@flex-development/pkg-types/index.d.mts", "typings/typescript/lib.es5.d.ts", - "vitest-env.d.ts" + "vitest-env.d.mts" ], "include": [ - "__fixtures__/**/**.ts", - "__tests__/**/**.ts", - "src/**/**.ts", - "src/**/.*.ts" + "__fixtures__/**/**.mts", + "__tests__/**/**.mts", + "src/**/**.mts", + "src/**/.*.mts" ] } diff --git a/vitest-env.d.ts b/vitest-env.d.mts similarity index 100% rename from vitest-env.d.ts rename to vitest-env.d.mts diff --git a/vitest.config.ts b/vitest.config.mts similarity index 88% rename from vitest.config.ts rename to vitest.config.mts index cc2ae7b3..46323c5f 100644 --- a/vitest.config.ts +++ b/vitest.config.mts @@ -18,7 +18,7 @@ import { BaseSequencer, type WorkspaceSpec } from 'vitest/node' import tsconfigJson from './tsconfig.test.json' /** - * Vitest configuration export. + * Vitest configuration. * * @const {UserConfigExport} config */ @@ -49,15 +49,16 @@ const config: UserConfigExport = defineConfig((env: ConfigEnv): UserConfig => { clean: true, cleanOnRerun: true, exclude: [ - '**/__mocks__/**', - '**/__tests__/**', + '**/*.d.mts', + '**/__mocks__/', + '**/__tests__/', '**/interfaces/', '**/types/', - '**/index.ts', - '!src/index.ts', - 'src/internal/*.browser.ts' + '**/index.mts', + '!src/index.mts', + 'src/internal/*.browser.mts' ], - extension: ['.ts'], + extension: ['.mts'], include: ['src'], provider: 'v8', reportOnFailure: !ci, @@ -71,7 +72,6 @@ const config: UserConfigExport = defineConfig((env: ConfigEnv): UserConfig => { environment: 'node', environmentOptions: {}, exclude: [ - '**/__tests__/*.bench.spec.ts?(x)', '.cache', '.git', '.idea', @@ -81,7 +81,7 @@ const config: UserConfigExport = defineConfig((env: ConfigEnv): UserConfig => { globalSetup: [], globals: true, hookTimeout: 10 * 1000, - include: [`**/__tests__/*.${LINT_STAGED ? '{spec,spec-d}' : 'spec'}.ts`], + include: [`**/__tests__/*.${LINT_STAGED ? '{spec,spec-d}' : 'spec'}.mts`], mockReset: true, outputFile: { blob: `.vitest-reports/${env.mode}.blob.json`, @@ -104,7 +104,7 @@ const config: UserConfigExport = defineConfig((env: ConfigEnv): UserConfig => { resolveSnapshotPath(file: string, extension: string): string { return pathe.resolve( pathe.resolve(pathe.dirname(pathe.dirname(file)), '__snapshots__'), - pathe.basename(file).replace(/\.spec.tsx?/, '') + extension + pathe.basename(file).replace(/\.spec.mts/, '') + extension ) }, restoreMocks: true, @@ -138,7 +138,7 @@ const config: UserConfigExport = defineConfig((env: ConfigEnv): UserConfig => { } } }, - setupFiles: ['./__tests__/setup/chai.ts', './__tests__/setup/faker.ts'], + setupFiles: ['./__tests__/setup/chai.mts', './__tests__/setup/faker.mts'], slowTestThreshold: 3000, snapshotFormat: { callToJSON: true, @@ -146,12 +146,12 @@ const config: UserConfigExport = defineConfig((env: ConfigEnv): UserConfig => { printBasicPrototype: false, printFunctionName: true }, - snapshotSerializers: ['./__tests__/serializers/cwd.ts'], + snapshotSerializers: ['./__tests__/serializers/cwd.mts'], typecheck: { allowJs: false, checker: 'tsc', ignoreSourceErrors: false, - include: ['**/__tests__/*.spec-d.ts'], + include: ['**/__tests__/*.spec-d.mts'], only: true, tsconfig: 'tsconfig.typecheck.json' },