Skip to content

Commit

Permalink
fix: Fix CJS imports on Node.js ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Jun 8, 2024
1 parent 01b953b commit d192ddc
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/eight-donkeys-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@kosko/exec-utils": patch
"@kosko/generate": patch
"@kosko/cli": patch
---

Fix CJS imports on Node.js ESM.
5 changes: 5 additions & 0 deletions packages/cli/src/commands/generate/jsonpath.node.esm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createRequire } from "node:module";

const req = createRequire(import.meta.url);

export default req("jsonpath");
1 change: 1 addition & 0 deletions packages/cli/src/commands/generate/jsonpath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "jsonpath";
2 changes: 1 addition & 1 deletion packages/cli/src/commands/generate/set-option.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Reducer } from "@kosko/env";
import jp from "jsonpath";
import jp from "./jsonpath";
import { CLIError } from "@kosko/cli-utils";

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/exec-utils/src/cross-spawn.node.esm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createRequire } from "node:module";

const req = createRequire(import.meta.url);

export default req("cross-spawn");
1 change: 1 addition & 0 deletions packages/exec-utils/src/cross-spawn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "cross-spawn";
2 changes: 1 addition & 1 deletion packages/exec-utils/src/spawn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import crossSpawn from "cross-spawn";
import crossSpawn from "./cross-spawn";
import { StdioOptions } from "node:child_process";
import assert from "node:assert";
import { SpawnError } from "./error";
Expand Down
2 changes: 1 addition & 1 deletion packages/generate/src/glob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readdir } from "node:fs/promises";
import { join, posix } from "node:path";
import mm from "micromatch";
import mm from "./micromatch";

function createMatcher(patterns: readonly string[], baseOptions: mm.Options) {
const positivePatterns: string[] = [];
Expand Down
5 changes: 5 additions & 0 deletions packages/generate/src/micromatch.node.esm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createRequire } from "node:module";

const req = createRequire(import.meta.url);

export default req("micromatch");
1 change: 1 addition & 0 deletions packages/generate/src/micromatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "micromatch";

0 comments on commit d192ddc

Please sign in to comment.