Skip to content

Commit

Permalink
Fix broccoli esm import to not break node 22.
Browse files Browse the repository at this point in the history
  • Loading branch information
goodov committed Jan 21, 2025
1 parent 84d2e8b commit 80ff177
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.eslintcache
/.vscode
/build
/node_modules
/brave
Expand Down
2 changes: 2 additions & 0 deletions fern.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

require("./fern/fixup_esm_for_node22");

const program = require("commander");
const colors = require("colors");

Expand Down
37 changes: 37 additions & 0 deletions fern/fixup_esm_for_node22.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

const fs = require("fs");
const path = require("path");

const filePath = path.join("node_modules/broccoli/dist/load_brocfile.js");

try {
let content = fs.readFileSync(filePath, "utf8");
const originalContent = content;

// Comment out ESM-related lines
content = content.replace(
/^\s*(const esm_1 = __importDefault\(require\("esm"\)\));/m,
"// $1;"
);
content = content.replace(
/^\s*(const esmRequire = esm_1\.default\(module\));/m,
"// $1;"
);

// Replace esmRequire with require
content = content.replace(
/brocfile = esmRequire\(brocfilePath\);/,
"brocfile = require(brocfilePath);"
);

if (content !== originalContent) {
fs.writeFileSync(filePath, content);
console.log("Successfully patched load_brocfile.js");
}
} catch (error) {
console.error("Error patching load_brocfile.js:", error);
process.exit(1);
}

0 comments on commit 80ff177

Please sign in to comment.