From 84a3f896fdbe0131b5f10ec314ec76b09b2347e7 Mon Sep 17 00:00:00 2001 From: Haz Date: Wed, 31 May 2023 04:47:20 +0200 Subject: [PATCH 1/2] Add extension to paths in proxy package.json files --- scripts/build/utils.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/scripts/build/utils.js b/scripts/build/utils.js index 2c712e0163..65cb1b7db2 100644 --- a/scripts/build/utils.js +++ b/scripts/build/utils.js @@ -154,14 +154,17 @@ export function getPublicFiles(sourcePath, prefix = "") { } /** - * Returns ["module", "path/to/module", ...] + * Returns { "module": "module", "path/to/module": "path/to/module/index" }] * @param {string} rootPath + * @returns {Record} */ export function getProxyFolders(rootPath) { const publicFiles = getPublicFiles(getSourcePath(rootPath)); - return Object.keys(publicFiles) - .map((name) => name.replace(/\/index$/, "")) - .filter((name) => name !== "index"); + return Object.fromEntries( + Object.keys(publicFiles) + .map((name) => [name.replace(/\/index$/, ""), name]) + .filter(([name]) => name !== "index") + ); } /** @@ -170,7 +173,7 @@ export function getProxyFolders(rootPath) { * @returns {string[]} */ export function getBuildFolders(rootPath) { - return [getCJSDir(), getESMDir(), ...getProxyFolders(rootPath)]; + return [getCJSDir(), getESMDir(), ...Object.keys(getProxyFolders(rootPath))]; } /** @@ -250,8 +253,9 @@ export function makeGitignore(rootPath) { /** * @param {string} rootPath * @param {string} moduleName + * @param {string} path */ -function getProxyPackageContents(rootPath, moduleName) { +function getProxyPackageContents(rootPath, moduleName, path) { const { name } = readPackageJson(rootPath); const mainDir = getCJSDir(); const moduleDir = getESMDir(); @@ -260,8 +264,8 @@ function getProxyPackageContents(rootPath, moduleName) { name: `${name}/${moduleName}`, private: true, sideEffects: false, - main: join(prefix, mainDir, moduleName), - module: join(prefix, moduleDir, moduleName), + main: join(prefix, mainDir, `${path}.cjs`), + module: join(prefix, moduleDir, `${path}.js`), }; return JSON.stringify(json, null, 2); } @@ -273,11 +277,11 @@ export function makeProxies(rootPath) { const pkg = readPackageJson(rootPath); /** @type {string[]} */ const created = []; - getProxyFolders(rootPath).forEach((name) => { + Object.entries(getProxyFolders(rootPath)).forEach(([name, path]) => { fse.ensureDirSync(name); writeFileSync( `${name}/package.json`, - getProxyPackageContents(rootPath, name) + getProxyPackageContents(rootPath, name, path) ); created.push(chalk.bold(chalk.green(name))); }); From 4048c52586e3ba3e5a38cb78d11585ebf24d6080 Mon Sep 17 00:00:00 2001 From: Haz Date: Wed, 31 May 2023 04:49:34 +0200 Subject: [PATCH 2/2] Add changeset --- .changeset/lazy-lizards-change.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changeset/lazy-lizards-change.md diff --git a/.changeset/lazy-lizards-change.md b/.changeset/lazy-lizards-change.md new file mode 100644 index 0000000000..178013e181 --- /dev/null +++ b/.changeset/lazy-lizards-change.md @@ -0,0 +1,8 @@ +--- +"@ariakit/core": patch +"@ariakit/react": patch +"@ariakit/react-core": patch +"@ariakit/test": patch +--- + +Added `.cjs` and `.js` extensions to paths in proxy package.json files to support bundlers that can't automaically resolve them. ([#2487](https://github.com/ariakit/ariakit/pull/2487))