Skip to content

Commit

Permalink
Merge pull request #37 from n1ru4l/named-export
Browse files Browse the repository at this point in the history
replace default export with a named export
  • Loading branch information
Codex- authored Aug 26, 2022
2 parents 9938cb4 + a9f88de commit 9b9a9bd
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"esbuild.config.mjs",
"jest.config.ts",
"coverage",
"dist"
"dist",
"smoke-tests"
],
"rules": {
"@typescript-eslint/await-thenable": "warn",
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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", {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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__");
Expand Down
4 changes: 1 addition & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import { TypeScriptLoader } from "./loader";

export default TypeScriptLoader;
export { TypeScriptLoader } from "./loader";
export type { TypeScriptCompileError } from "./typescript-compile-error";
5 changes: 5 additions & 0 deletions smoke-tests/smoke-test-cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const mod = require("../dist/cjs/index.js");
const { TypeScriptLoader } = mod;
TypeScriptLoader();

console.info("Loaded with CJS successfully");
5 changes: 5 additions & 0 deletions smoke-tests/smoke-test-esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import mod from "../dist/cjs/index.js";
const { TypeScriptLoader } = mod;
TypeScriptLoader();

console.info("Loaded with ESM successfully");
26 changes: 26 additions & 0 deletions smoke-tests/smoke-test.js
Original file line number Diff line number Diff line change
@@ -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);
}
})();

0 comments on commit 9b9a9bd

Please sign in to comment.