Skip to content

Commit

Permalink
fix: fix windows import
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 30, 2023
1 parent 81df591 commit 8d1b248
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
Empty file added apps/.gitkeep
Empty file.
14 changes: 14 additions & 0 deletions tools/esbuild-config-custom/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @terwer/esbuild-config-custom

## 2.0.0

### Major Changes

- fix: fix windows import

### Minor Changes

- fix: windows build is ok now

### Patch Changes

- fix: fix windows build

## 1.2.0

### Minor Changes
Expand Down
37 changes: 24 additions & 13 deletions tools/esbuild-config-custom/build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,36 @@ class ZhiBuild {
let customConfig = {}
// 兼容 windows
const isWindows = os.platform() === "win32"
const esbuildConfigFile = isWindows ? `file:///${path.join(process.cwd(), cfg)}` : path.join(process.cwd(), cfg)
const esbuildConfigFile = isWindows
? `${path.join(process.cwd(), cfg)}`.replace(/\\/g, "/")
: path.join(process.cwd(), cfg)
console.log("reading user defined esbuild config from =>", esbuildConfigFile)
if (existsSync(esbuildConfigFile)) {
if (!existsSync(esbuildConfigFile)) {
console.warn(`userEsbuildConfig not found, using default`)
} else {
try {
// 兼容 mjs 和 cjs
const pkg = await import(esbuildConfigFile)
console.log("pkg=>", pkg)
let cfg = pkg
if (pkg.default) {
cfg = pkg.default
let customCfg
try {
console.log(`try import esbuildConfigFile => ${esbuildConfigFile}`)
// 兼容 mjs 和 cjs
const pkg = await import(esbuildConfigFile)
console.log("pkg=>", pkg)
customCfg = pkg
if (pkg.default) {
customCfg = pkg.default
}
} catch (e) {
console.log(`import error, using require instead.esbuildConfigFile => ${esbuildConfigFile}`)
customCfg = require(esbuildConfigFile)
}
userEsbuildConfig = cfg.esbuildConfig ?? {}
customConfig = cfg.customConfig ?? {}
} catch (error) {
console.error(`Failed to load esbuild config: ${error}`)
userEsbuildConfig = customCfg.esbuildConfig ?? {}
customConfig = customCfg.customConfig ?? {}
} catch (e2) {
console.error(`Failed to load esbuild config: ${e2}`)
process.exit(1)
}
}
// console.log("parsed user defined esbuild config", esbuildConfig)
console.log("parsed user defined esbuild config", userEsbuildConfig)

// ===================
// 默认集成的配置开始
Expand Down
2 changes: 1 addition & 1 deletion tools/esbuild-config-custom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@terwer/esbuild-config-custom",
"version": "1.2.0",
"version": "2.0.0",
"type": "module",
"description": "universal esbuild tool for library",
"bin": {
Expand Down

0 comments on commit 8d1b248

Please sign in to comment.