fix: switch from tsc watch to chokidar (#11110)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user