Skip to content

Commit

Permalink
Merge pull request #35 from bloczjs/fix-exports
Browse files Browse the repository at this point in the history
[exports] use lib folder instead of dist folder + fix esm
  • Loading branch information
Ayc0 authored Apr 9, 2021
2 parents 1558423 + 0fdc2cf commit 7bc5a79
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 13.x, 14.x]
node-version: [12.x, 14.x]

steps:
- uses: actions/checkout@v1
Expand Down
13 changes: 8 additions & 5 deletions packages/react-responsive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
"module": "lib/react-responsive.modern.js",
"types": "lib/index.d.ts",
"exports": {
"require": "./dist/react-responsive.js",
"import": "./dist/react-responsive.modern.js",
"browser": "./dist/react-responsive.modern.js",
"umd": "./dist/react-responsive.umd.js"
".": {
"require": "./lib/react-responsive.js",
"import": "./lib/react-responsive.modern.mjs",
"browser": "./lib/react-responsive.modern.js",
"umd": "./lib/react-responsive.umd.js"
},
"./package.json": "./package.json"
},
"repository": "[email protected]:bloczjs/react-responsive.git",
"keywords": [
Expand All @@ -28,7 +31,7 @@
"license": "MIT",
"bugs": "https://github.com/bloczjs/react-responsive/issues",
"scripts": {
"build": "yarn -s build:microbundle",
"build": "yarn -s build:microbundle && cp lib/react-responsive.modern.js lib/react-responsive.modern.mjs",
"build:dev": "yarn -s build:microbundle --compress false",
"build:microbundle": "microbundle --name $npm_package_name --globals react=React",
"link:readme": "rm ../../README.md && ln -s packages/react-responsive/README.md ../..",
Expand Down
4 changes: 4 additions & 0 deletions packages/tests/src/__tests__/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as ReactResponsive from "@blocz/react-responsive";
import packageJSON from "@blocz/react-responsive/package.json";

console.log("Didn’t crash");
51 changes: 51 additions & 0 deletions packages/tests/src/__tests__/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { execSync } from "child_process";

describe("Important files should be resolvable", () => {
it("should work in a CJS context", () => {
expect(
require.resolve("@blocz/react-responsive"),
).not.toBeNull();
expect(
require.resolve(
"@blocz/react-responsive/package.json",
),
).not.toBeNull();
});

it("should work in a ESM context", () => {
expect(
execSync(
"node --experimental-json-modules ./esm.mjs",
{
cwd: __dirname,
encoding: "utf-8",
},
),
).toBe("Didn’t crash\n");
});
});

describe("built files", () => {
it("should contain all necessary files", () => {
expect(
require.resolve(
"@blocz/react-responsive/lib/react-responsive.js",
),
).not.toBeNull();
expect(
require.resolve(
"@blocz/react-responsive/lib/react-responsive.modern.js",
),
).not.toBeNull();
expect(
require.resolve(
"@blocz/react-responsive/lib/react-responsive.modern.mjs",
),
).not.toBeNull();
expect(
require.resolve(
"@blocz/react-responsive/lib/react-responsive.umd.js",
),
).not.toBeNull();
});
});
12 changes: 9 additions & 3 deletions packages/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand All @@ -13,8 +17,10 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"jsx": "react-jsx",
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": [
"src"
]
}

0 comments on commit 7bc5a79

Please sign in to comment.