mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
Migrate babel-worker.cjs to ESM (#17681)
* Migrate `babel-worker.cjs` to ESM * Will CircleCI fail? * Revert "Will CircleCI fail?" This reverts commit 50c39523d391fa8a06858f893f45aa094c846375.
This commit is contained in:
+13
-8
@@ -34,7 +34,7 @@ import babelPluginToggleBooleanFlag from "./scripts/babel-plugin-toggle-boolean-
|
||||
// @ts-expect-error no types
|
||||
import formatCode from "./scripts/utils/formatCode.js";
|
||||
// @ts-expect-error no types
|
||||
import { log } from "./scripts/utils/logger.cjs";
|
||||
import { log } from "./scripts/utils/logger.js";
|
||||
import { commonJS } from "$repo-utils";
|
||||
|
||||
import type { NodePath, PluginItem, types } from "@babel/core";
|
||||
@@ -259,20 +259,25 @@ function createWorker(useWorker: boolean) {
|
||||
// For some reason, on CircleCI the workers hang indefinitely.
|
||||
process.env.CIRCLECI
|
||||
) {
|
||||
return require("./babel-worker.cjs");
|
||||
// @ts-expect-error no types
|
||||
return import("./babel-worker.mjs");
|
||||
}
|
||||
const worker = new JestWorker(require.resolve("./babel-worker.cjs"), {
|
||||
enableWorkerThreads: true,
|
||||
numWorkers,
|
||||
exposedMethods: ["transform"],
|
||||
});
|
||||
const worker = new JestWorker(
|
||||
new URL("./babel-worker.mjs", import.meta.url),
|
||||
{
|
||||
enableWorkerThreads: true,
|
||||
numWorkers,
|
||||
exposedMethods: ["transform"],
|
||||
}
|
||||
);
|
||||
|
||||
worker.getStdout().pipe(process.stdout);
|
||||
worker.getStderr().pipe(process.stderr);
|
||||
return worker;
|
||||
}
|
||||
|
||||
async function buildBabel(useWorker: boolean, ignore: PackageInfo[] = []) {
|
||||
const worker = createWorker(useWorker);
|
||||
const worker = await createWorker(useWorker);
|
||||
const files = new Glob(defaultSourcesGlob, {
|
||||
ignore: ignore.map(p => `${p.src}/**`),
|
||||
posix: true,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
const { transformAsync } = require("@babel/core");
|
||||
const { mkdirSync, statSync, readFileSync, writeFileSync } = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { log } = require("./scripts/utils/logger.cjs");
|
||||
const colors = require("picocolors");
|
||||
import { transformAsync } from "@babel/core";
|
||||
import { mkdirSync, statSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { log } from "./scripts/utils/logger.js";
|
||||
import colors from "picocolors";
|
||||
|
||||
/** * Check if the source file needs to be compiled based on its modification time
|
||||
* compared to the destination file.
|
||||
@@ -30,7 +29,7 @@ function needCompile(src, dest) {
|
||||
return srcStat.mtimeMs >= destStat.mtimeMs;
|
||||
}
|
||||
|
||||
exports.transform = async function transform(src, dest, opts = {}) {
|
||||
export async function transform(src, dest, opts = {}) {
|
||||
mkdirSync(path.dirname(dest), { recursive: true });
|
||||
if (!needCompile(src, dest)) {
|
||||
return;
|
||||
@@ -63,4 +62,4 @@ exports.transform = async function transform(src, dest, opts = {}) {
|
||||
// @ts-expect-error code must not be for our project source
|
||||
writeFileSync(dest, code, "utf8");
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
* @param {string} msg - The message to log.
|
||||
* @param {...any} args - Additional arguments to log.
|
||||
*/
|
||||
exports.log = function (msg, ...args) {
|
||||
export function log(msg, ...args) {
|
||||
const time = new Date().toLocaleTimeString("en-US", { hour12: false });
|
||||
console.log(`[${time}] ${msg}`, ...args);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user