fix: switch from tsc watch to chokidar (#11110)

This commit is contained in:
Harminder Virk
2025-01-23 19:12:07 +05:30
committed by GitHub
parent 31384855af
commit 0deffe7b9b
5 changed files with 133 additions and 77 deletions
+54 -2
View File
@@ -1,4 +1,5 @@
import path from "path"
import * as swcCore from "@swc/core"
import { execFile } from "child_process"
import { logger } from "@medusajs/framework/logger"
import { Compiler } from "@medusajs/framework/build-tools"
@@ -10,9 +11,18 @@ export default async function developPlugin({
}) {
let isBusy = false
const compiler = new Compiler(directory, logger)
const parsedConfig = await compiler.loadTSConfigFile()
if (!parsedConfig) {
return
}
const yalcBin = path.join(path.dirname(require.resolve("yalc")), "yalc.js")
await compiler.developPluginBackend(async () => {
/**
* Publishes the build output to the registry and updates
* installations
*/
function publishChanges() {
/**
* Here we avoid multiple publish calls when the filesystem is
* changed too quickly. This might result in stale content in
@@ -46,5 +56,47 @@ export default async function developPlugin({
console.error(stderr)
}
)
})
}
/**
* Transforms a given file using @swc/core
*/
async function transformFile(filePath: string) {
const output = await swcCore.transformFile(filePath, {
sourceMaps: "inline",
module: {
type: "commonjs",
strictMode: true,
noInterop: false,
},
jsc: {
externalHelpers: false,
target: "es2021",
parser: {
syntax: "typescript",
tsx: true,
decorators: true,
dynamicImport: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
react: {
throwIfNamespace: false,
useBuiltins: false,
pragma: "React.createElement",
pragmaFrag: "React.Fragment",
importSource: "react",
runtime: "automatic",
},
},
keepClassNames: true,
baseUrl: directory,
},
})
return output.code
}
await compiler.buildPluginBackend(parsedConfig)
await compiler.developPluginBackend(transformFile, publishChanges)
}