Skip to content

Commit

Permalink
refactor(next-drupal): rearrange files into multiple entry points
Browse files Browse the repository at this point in the history
Fixes #442
  • Loading branch information
JohnAlbin committed Oct 18, 2023
1 parent c1bc419 commit 40df14b
Show file tree
Hide file tree
Showing 30 changed files with 1,806 additions and 1,668 deletions.
73 changes: 72 additions & 1 deletion packages/next-drupal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,80 @@
"description": "Helpers for Next.js + Drupal.",
"version": "1.6.0",
"sideEffects": false,
"source": "src/index.ts",
"source": [
"src/index.ts",
"src/client.ts",
"src/navigation.ts",
"src/preview.ts",
"src/query.ts",
"src/translation.ts",
"src/utils.ts"
],
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.modern.js",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.modern.js"
},
"require": {
"types": "./dist/index.cjs.d.ts",
"default": "./dist/index.cjs"
}
},
"./client": {
"import": {
"types": "./dist/client.d.ts",
"default": "./dist/client.modern.js"
},
"require": {
"types": "./dist/client.cjs.d.ts",
"default": "./dist/client.cjs"
}
},
"./navigation": {
"import": {
"types": "./dist/navigation.d.ts",
"default": "./dist/navigation.modern.js"
},
"require": {
"types": "./dist/navigation.cjs.d.ts",
"default": "./dist/navigation.cjs"
}
},
"./preview": {
"import": {
"types": "./dist/preview.d.ts",
"default": "./dist/preview.modern.js"
},
"require": {
"types": "./dist/preview.cjs.d.ts",
"default": "./dist/preview.cjs"
}
},
"./query": {
"import": {
"types": "./dist/query.d.ts",
"default": "./dist/query.modern.js"
},
"require": {
"types": "./dist/query.cjs.d.ts",
"default": "./dist/query.cjs"
}
},
"./translation": {
"import": {
"types": "./dist/translation.d.ts",
"default": "./dist/translation.modern.js"
},
"require": {
"types": "./dist/translation.cjs.d.ts",
"default": "./dist/translation.cjs"
}
}
},
"types": "dist/types.d.ts",
"license": "MIT",
"publishConfig": {
Expand All @@ -18,6 +88,7 @@
},
"scripts": {
"prepare": "microbundle --no-compress --jsx React.createElement --format modern,cjs",
"postprepare": "node postBuild.mjs",
"dev": "microbundle watch --no-compress --jsx React.createElement --format modern,cjs",
"test": "jest",
"prepublishOnly": "yarn prepare"
Expand Down
20 changes: 20 additions & 0 deletions packages/next-drupal/postBuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { readdir, copyFile } from "node:fs/promises"

const files = await readdir("./dist")
for (const file of files) {
if (file.endsWith(".modern.js")) {
const base = file.replace(/\.modern\.js$/, "")

// Make a duplicate of the type definitions.
//
// From the TypeScript docs:
//
// "It’s important to note that the CommonJS entrypoint and the ES module
// entrypoint each needs its own declaration file, even if the contents are
// the same between them."
//
// @see https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing
await copyFile(`./dist/${base}.d.ts`, `./dist/${base}.cjs.d.ts`)
}
}
console.log(`Created unique *.d.ts files for CommonJS build.`)
Loading

0 comments on commit 40df14b

Please sign in to comment.