Skip to content

Commit

Permalink
fix: inject esm/cjs shims and fix import.meta compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
duniul committed Aug 7, 2023
1 parent 1665c85 commit 93fe69b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-mangos-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'clean-modules': patch
---

Fix `import.meta.url` not being transpiled to an equivalent value for CJS builds.
2 changes: 1 addition & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CleanCommand } from './commands/clean.command.js';

const [_node, _app, ...args] = process.argv;
const esmRequire = createRequire(import.meta.url);
const cliDir = fileDir(import.meta);
const cliDir = fileDir(import.meta.url);
const { name, version } = esmRequire(path.resolve(cliDir, '..', '..', 'package.json'));

const cli = new Cli({
Expand Down
2 changes: 1 addition & 1 deletion src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import { fileDir } from './utils/filesystem.js';

export const DEFAULT_GLOBS_FILE_PATH = path.resolve(
fileDir(import.meta),
fileDir(import.meta.url),
'..',
'.cleanmodules-default'
);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ export async function removeFiles(

/**
* Get directory of the file directory, like CommonJS `__dirname`.
* @example const thisFilesDir = fileDir(import.meta);
* @example const thisFilesDir = fileDir(import.meta.url);
*/
export function fileDir(importMeta: ImportMeta) {
return path.dirname(fileURLToPath(importMeta.url));
export function fileDir(importMetaUrl: string) {
return path.dirname(fileURLToPath(importMetaUrl));
}
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default defineConfig({
splitting: true,
sourcemap: false,
clean: true,
shims: true,
dts: true,
});

0 comments on commit 93fe69b

Please sign in to comment.