Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@clc/nx/executors/esbuild/executor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const runExecutor = async (options) => {
bundle: true,
entryPoints: eps,
format,
// `import.meta` compiles to an empty object under cjs, so
// `import.meta.resolve(...)` becomes a runtime TypeError. esbuild only
// warns, which is easy to scroll past; promote it to an error.
logOverride: {'empty-import-meta': 'error'},
outExtension: {'.js': format === 'cjs' ? '.cjs' : '.mjs'},
outdir: outDir,
packages: 'external',
Expand Down
19 changes: 8 additions & 11 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 @@ -64,17 +64,14 @@ async function addAsCliPlugin(metadata) {
// 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';
// 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)
// Resolve the package.json subpath rather than the package entrypoint:
// resolution has to succeed before the CLI has been built, and
// package.json is the one file guaranteed to be on disk. This relies on
// the CLI exporting "./package.json"; without that entry Node raises
// ERR_PACKAGE_PATH_NOT_EXPORTED no matter what is on disk.
const cliPkgPath = createRequire(rootPkgPath).resolve(
`${cliPackageName}/package.json`
);
const cliPkgPath = await findUp('package.json', {
cwd: path.dirname(cliPkgPathResolvePath),
});
assert(cliPkgPath, 'Could not locate directory containing package.json');
const cliPkg = await readPackageJson(cliPkgPath);
await addToPackageJson(cliPkg, cliPkgPath, pkg.name);
return;
Expand Down
Loading