Skip to content

Commit

Permalink
fix(tool-tool): do not require cli to be built in order to find its f…
Browse files Browse the repository at this point in the history
…older
  • Loading branch information
ianwremmel committed Jun 10, 2024
1 parent 37c56c6 commit ca0fdda
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/@code-like-a-carpenter/tool-tool/src/tool.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {existsSync} from 'node:fs';
import {mkdir, readFile, writeFile} from 'node:fs/promises';
import {createRequire} from 'node:module';
import path from 'node:path';
import {fileURLToPath} from 'node:url';

import findUp from 'find-up';
import kebabCase from 'lodash.kebabcase';
Expand Down Expand Up @@ -61,10 +61,16 @@ async function addAsCliPlugin(metadata) {
if (rootPkgPath) {
const rootPkg = await readPackageJson(rootPkgPath);
if (rootPkg.name === '@code-like-a-carpenter/workbench') {
const require = createRequire(import.meta.url);
// Need to put this in a variable so deps doesn't add it to package.json
// Need to put this in a variable so deps doesn't add it to package.json,
// which would lead to a circular dependency.
const cliPackageName = '@code-like-a-carpenter/cli';
const cliPkgPathResolvePath = require.resolve(cliPackageName);
// Reminder: import.meta.resolve works because it doesn't check for
// existence. createRequire().resolve() fails if the file does not exist.
// Since we're trying to fins package.json, we don't actually care if the
// entrypoint has been built yet.
const cliPkgPathResolvePath = fileURLToPath(
import.meta.resolve(cliPackageName)
);
const cliPkgPath = await findUp('package.json', {
cwd: path.dirname(cliPkgPathResolvePath),
});
Expand Down

0 comments on commit ca0fdda

Please sign in to comment.