diff --git a/.eslintrc.json b/.eslintrc.json index 4fb4681..da19365 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,7 +9,8 @@ "esbuild.config.mjs", "jest.config.ts", "coverage", - "dist" + "dist", + "smoke-tests" ], "rules": { "@typescript-eslint/await-thenable": "warn", diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e5083b1..084c396 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,6 +30,15 @@ jobs: id: test if: ${{ always() }} run: npm run test + - name: Import with CJS + if: ${{ always() }} + run: node smoke-tests/smoke-test-cjs.js + - name: Import with ESM + if: ${{ always() }} + run: node smoke-tests/smoke-test-esm.mjs + - name: Import with both CJS and ESM + if: ${{ always() }} + run: node smoke-tests/smoke-test.js - name: lint if: ${{ always() }} run: npm run lint diff --git a/README.md b/README.md index 40795d5..7d2a764 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Simply add `TypeScriptLoader` to the list of loaders for the `.ts` file type: ```ts import { cosmiconfig } from "cosmiconfig"; -import TypeScriptLoader from "cosmiconfig-typescript-loader"; +import { TypeScriptLoader } from "cosmiconfig-typescript-loader"; const moduleName = "module"; const explorer = cosmiconfig("test", { @@ -51,7 +51,7 @@ Or more simply if you only support loading of a TypeScript based configuration f ```ts import { cosmiconfig } from "cosmiconfig"; -import TypeScriptLoader from "cosmiconfig-typescript-loader"; +import { TypeScriptLoader } from "cosmiconfig-typescript-loader"; const moduleName = "module"; const explorer = cosmiconfig("test", { diff --git a/lib/index.spec.ts b/lib/index.spec.ts index e89f2c5..c1260f7 100644 --- a/lib/index.spec.ts +++ b/lib/index.spec.ts @@ -1,6 +1,6 @@ import path from "path"; import { cosmiconfig, cosmiconfigSync } from "cosmiconfig"; -import TypeScriptLoader from "."; +import { TypeScriptLoader } from "."; describe("TypeScriptLoader", () => { const fixturesPath = path.resolve(__dirname, "__fixtures__"); diff --git a/lib/index.ts b/lib/index.ts index 64c6fc8..bbbd207 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,2 @@ -import { TypeScriptLoader } from "./loader"; - -export default TypeScriptLoader; +export { TypeScriptLoader } from "./loader"; export type { TypeScriptCompileError } from "./typescript-compile-error"; diff --git a/smoke-tests/smoke-test-cjs.js b/smoke-tests/smoke-test-cjs.js new file mode 100644 index 0000000..9f17027 --- /dev/null +++ b/smoke-tests/smoke-test-cjs.js @@ -0,0 +1,5 @@ +const mod = require("../dist/cjs/index.js"); +const { TypeScriptLoader } = mod; +TypeScriptLoader(); + +console.info("Loaded with CJS successfully"); diff --git a/smoke-tests/smoke-test-esm.mjs b/smoke-tests/smoke-test-esm.mjs new file mode 100644 index 0000000..69c93bc --- /dev/null +++ b/smoke-tests/smoke-test-esm.mjs @@ -0,0 +1,5 @@ +import mod from "../dist/cjs/index.js"; +const { TypeScriptLoader } = mod; +TypeScriptLoader(); + +console.info("Loaded with ESM successfully"); diff --git a/smoke-tests/smoke-test.js b/smoke-tests/smoke-test.js new file mode 100644 index 0000000..6632ca3 --- /dev/null +++ b/smoke-tests/smoke-test.js @@ -0,0 +1,26 @@ +const assert = require("node:assert"); + +(async () => { + try { + const esm = await import("../dist/cjs/index.js"); + const cjs = require("../dist/cjs/index.js"); + + assert.strictEqual( + esm.TypeScriptLoader, + cjs.TypeScriptLoader, + "esm.TypeScriptLoader === cjs.TypeScriptLoader" + ); + + // try to create loaders + esm.TypeScriptLoader(); + cjs.TypeScriptLoader(); + + console.info("Loaded with both CJS and ESM successfully"); + } catch (error) { + console.error(error); + console.debug(error.stack); + + // Prevent an unhandled rejection, exit gracefully. + process.exit(1); + } +})();