Skip to content

Commit 9b9a9bd

Browse files
authored
Merge pull request #37 from n1ru4l/named-export
replace default export with a named export
2 parents 9938cb4 + a9f88de commit 9b9a9bd

File tree

8 files changed

+51
-7
lines changed

8 files changed

+51
-7
lines changed

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"esbuild.config.mjs",
1010
"jest.config.ts",
1111
"coverage",
12-
"dist"
12+
"dist",
13+
"smoke-tests"
1314
],
1415
"rules": {
1516
"@typescript-eslint/await-thenable": "warn",

.github/workflows/build.yml

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ jobs:
3030
id: test
3131
if: ${{ always() }}
3232
run: npm run test
33+
- name: Import with CJS
34+
if: ${{ always() }}
35+
run: node smoke-tests/smoke-test-cjs.js
36+
- name: Import with ESM
37+
if: ${{ always() }}
38+
run: node smoke-tests/smoke-test-esm.mjs
39+
- name: Import with both CJS and ESM
40+
if: ${{ always() }}
41+
run: node smoke-tests/smoke-test.js
3342
- name: lint
3443
if: ${{ always() }}
3544
run: npm run lint

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Simply add `TypeScriptLoader` to the list of loaders for the `.ts` file type:
2222

2323
```ts
2424
import { cosmiconfig } from "cosmiconfig";
25-
import TypeScriptLoader from "cosmiconfig-typescript-loader";
25+
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
2626

2727
const moduleName = "module";
2828
const explorer = cosmiconfig("test", {
@@ -51,7 +51,7 @@ Or more simply if you only support loading of a TypeScript based configuration f
5151

5252
```ts
5353
import { cosmiconfig } from "cosmiconfig";
54-
import TypeScriptLoader from "cosmiconfig-typescript-loader";
54+
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
5555

5656
const moduleName = "module";
5757
const explorer = cosmiconfig("test", {

lib/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "path";
22
import { cosmiconfig, cosmiconfigSync } from "cosmiconfig";
3-
import TypeScriptLoader from ".";
3+
import { TypeScriptLoader } from ".";
44

55
describe("TypeScriptLoader", () => {
66
const fixturesPath = path.resolve(__dirname, "__fixtures__");

lib/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import { TypeScriptLoader } from "./loader";
2-
3-
export default TypeScriptLoader;
1+
export { TypeScriptLoader } from "./loader";
42
export type { TypeScriptCompileError } from "./typescript-compile-error";

smoke-tests/smoke-test-cjs.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const mod = require("../dist/cjs/index.js");
2+
const { TypeScriptLoader } = mod;
3+
TypeScriptLoader();
4+
5+
console.info("Loaded with CJS successfully");

smoke-tests/smoke-test-esm.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import mod from "../dist/cjs/index.js";
2+
const { TypeScriptLoader } = mod;
3+
TypeScriptLoader();
4+
5+
console.info("Loaded with ESM successfully");

smoke-tests/smoke-test.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const assert = require("node:assert");
2+
3+
(async () => {
4+
try {
5+
const esm = await import("../dist/cjs/index.js");
6+
const cjs = require("../dist/cjs/index.js");
7+
8+
assert.strictEqual(
9+
esm.TypeScriptLoader,
10+
cjs.TypeScriptLoader,
11+
"esm.TypeScriptLoader === cjs.TypeScriptLoader"
12+
);
13+
14+
// try to create loaders
15+
esm.TypeScriptLoader();
16+
cjs.TypeScriptLoader();
17+
18+
console.info("Loaded with both CJS and ESM successfully");
19+
} catch (error) {
20+
console.error(error);
21+
console.debug(error.stack);
22+
23+
// Prevent an unhandled rejection, exit gracefully.
24+
process.exit(1);
25+
}
26+
})();

0 commit comments

Comments
 (0)