Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension to paths in proxy package.json files #2487

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/lazy-lizards-change.md
Original file line number Diff line number Diff line change
@@ -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))
24 changes: 14 additions & 10 deletions scripts/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>}
*/
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")
);
}

/**
Expand All @@ -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))];
}

/**
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand All @@ -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)));
});
Expand Down