From ec1ff657f3150d34be2f674f071d918d51827acb Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 11:58:55 +0200 Subject: [PATCH 1/9] [exports] use lib folder instead of dist folder --- packages/react-responsive/package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-responsive/package.json b/packages/react-responsive/package.json index 7f6b47b..e060cc0 100644 --- a/packages/react-responsive/package.json +++ b/packages/react-responsive/package.json @@ -9,10 +9,10 @@ "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.js", + "browser": "./lib/react-responsive.modern.js", + "umd": "./lib/react-responsive.umd.js" }, "repository": "git@github.com:bloczjs/react-responsive.git", "keywords": [ From facdbc6016e93a798b103975acd5ad38eec55923 Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 12:03:00 +0200 Subject: [PATCH 2/9] [exports] include package.json + ./ --- packages/react-responsive/package.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/react-responsive/package.json b/packages/react-responsive/package.json index e060cc0..c552b8e 100644 --- a/packages/react-responsive/package.json +++ b/packages/react-responsive/package.json @@ -9,10 +9,14 @@ "module": "lib/react-responsive.modern.js", "types": "lib/index.d.ts", "exports": { - "require": "./lib/react-responsive.js", - "import": "./lib/react-responsive.modern.js", - "browser": "./lib/react-responsive.modern.js", - "umd": "./lib/react-responsive.umd.js" + ".": { + "require": "./lib/react-responsive.js", + "import": "./lib/react-responsive.modern.js", + "browser": "./lib/react-responsive.modern.js", + "umd": "./lib/react-responsive.umd.js" + }, + "./package.json": "./package.json", + "./": "./" }, "repository": "git@github.com:bloczjs/react-responsive.git", "keywords": [ From f472f40e4bacd09f152d04b7649fb650692ca567 Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 12:30:37 +0200 Subject: [PATCH 3/9] [tests] update tsconfig --- packages/tests/tsconfig.json | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/tests/tsconfig.json b/packages/tests/tsconfig.json index 6308cb8..e18c413 100644 --- a/packages/tests/tsconfig.json +++ b/packages/tests/tsconfig.json @@ -1,7 +1,11 @@ { "compilerOptions": { "target": "es5", - "lib": ["dom", "dom.iterable", "esnext"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, @@ -13,8 +17,10 @@ "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, - "jsx": "react", + "jsx": "react-jsx", "noFallthroughCasesInSwitch": true }, - "include": ["src"] + "include": [ + "src" + ] } From fd45649a46074516678f1253192f81bbe7d48a5c Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 12:30:55 +0200 Subject: [PATCH 4/9] [exports] use mjs extension as we aren't in a module --- packages/react-responsive/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-responsive/package.json b/packages/react-responsive/package.json index c552b8e..17511c5 100644 --- a/packages/react-responsive/package.json +++ b/packages/react-responsive/package.json @@ -6,12 +6,12 @@ "sideEffects": false, "main": "lib/react-responsive.js", "umd:main": "lib/react-responsive.umd.js", - "module": "lib/react-responsive.modern.js", + "module": "lib/react-responsive.modern.mjs", "types": "lib/index.d.ts", "exports": { ".": { "require": "./lib/react-responsive.js", - "import": "./lib/react-responsive.modern.js", + "import": "./lib/react-responsive.modern.mjs", "browser": "./lib/react-responsive.modern.js", "umd": "./lib/react-responsive.umd.js" }, From 5b9342d4d7d31d2a42ecadb851e587f6fdbab93a Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 12:31:18 +0200 Subject: [PATCH 5/9] [tests][exports] add tests for esm resolution + check generated files --- packages/tests/src/__tests__/esm.mjs | 4 ++ packages/tests/src/__tests__/resolver.ts | 48 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 packages/tests/src/__tests__/esm.mjs create mode 100644 packages/tests/src/__tests__/resolver.ts diff --git a/packages/tests/src/__tests__/esm.mjs b/packages/tests/src/__tests__/esm.mjs new file mode 100644 index 0000000..cb717a7 --- /dev/null +++ b/packages/tests/src/__tests__/esm.mjs @@ -0,0 +1,4 @@ +import * as ReactResponsive from "@blocz/react-responsive"; +import packageJSON from "@blocz/react-responsive/package.json"; + +console.log("Didn’t crash"); diff --git a/packages/tests/src/__tests__/resolver.ts b/packages/tests/src/__tests__/resolver.ts new file mode 100644 index 0000000..67f4dc7 --- /dev/null +++ b/packages/tests/src/__tests__/resolver.ts @@ -0,0 +1,48 @@ +import { execSync } from "child_process"; + +describe("ESM", () => { + it("should work in 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"), + ).not.toBeNull(); + expect( + require.resolve( + "@blocz/react-responsive/package.json", + ), + ).not.toBeNull(); + 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(); + }); +}); From b1cab100da117df06d86cc4f833bf34270d58782 Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 12:34:54 +0200 Subject: [PATCH 6/9] [tests][exports] rename tests --- packages/tests/src/__tests__/resolver.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/tests/src/__tests__/resolver.ts b/packages/tests/src/__tests__/resolver.ts index 67f4dc7..32e2bc0 100644 --- a/packages/tests/src/__tests__/resolver.ts +++ b/packages/tests/src/__tests__/resolver.ts @@ -1,7 +1,18 @@ import { execSync } from "child_process"; -describe("ESM", () => { - it("should work in ESM context", () => { +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", @@ -16,14 +27,6 @@ describe("ESM", () => { describe("built files", () => { it("should contain all necessary files", () => { - expect( - require.resolve("@blocz/react-responsive"), - ).not.toBeNull(); - expect( - require.resolve( - "@blocz/react-responsive/package.json", - ), - ).not.toBeNull(); expect( require.resolve( "@blocz/react-responsive/lib/react-responsive.js", From 90542e4bbc7c6294cfff27230323285ada4e11da Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 12:56:43 +0200 Subject: [PATCH 7/9] [tests] avoid using .mjs for module --- packages/react-responsive/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-responsive/package.json b/packages/react-responsive/package.json index 17511c5..4fa9bed 100644 --- a/packages/react-responsive/package.json +++ b/packages/react-responsive/package.json @@ -6,7 +6,7 @@ "sideEffects": false, "main": "lib/react-responsive.js", "umd:main": "lib/react-responsive.umd.js", - "module": "lib/react-responsive.modern.mjs", + "module": "lib/react-responsive.modern.js", "types": "lib/index.d.ts", "exports": { ".": { @@ -32,7 +32,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 ../..", From 03b0fcdc6ef3ea5ec289d5a009c4c99820c821d6 Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 13:06:16 +0200 Subject: [PATCH 8/9] [tests] remove support for node 13 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9fca990..88b25eb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 From 0fdc2cf06e85516fcfe0d4d2e12958cb99091409 Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Fri, 9 Apr 2021 14:09:42 +0200 Subject: [PATCH 9/9] [tests] remove deprecated ./ --- packages/react-responsive/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-responsive/package.json b/packages/react-responsive/package.json index 4fa9bed..29e680e 100644 --- a/packages/react-responsive/package.json +++ b/packages/react-responsive/package.json @@ -15,8 +15,7 @@ "browser": "./lib/react-responsive.modern.js", "umd": "./lib/react-responsive.umd.js" }, - "./package.json": "./package.json", - "./": "./" + "./package.json": "./package.json" }, "repository": "git@github.com:bloczjs/react-responsive.git", "keywords": [