From ae6d4912bb6c53cab4909969b87c0ca612e8626f Mon Sep 17 00:00:00 2001 From: hyrious Date: Fri, 20 Sep 2024 14:46:42 +0800 Subject: [PATCH] refactor: ensure .esbuild-dev/package.json --- CHANGELOG.md | 4 ++++ package-lock.json | 17 +++++++++++++++++ package.json | 1 + src/build.ts | 7 +++++-- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c43cf81..c4debc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- **refactor**: Test `.esbuild-dev/package.json` instead of its parent dir. + ## 0.10.11 - **refactor**: Disable `--cache` by default, it might be too aggressive. diff --git a/package-lock.json b/package-lock.json index 9274a67..1cd2f12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@hyrious/esbuild-plugin-external": "^0.1.4", "@types/node": "^20.14.13", "esbuild": "^0.21.5", + "prettier": "^3.3.3", "undici": "^6.19.4", "vitepress": "^1.3.1" }, @@ -2247,6 +2248,22 @@ "url": "https://opencollective.com/preact" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmmirror.com/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/rfdc": { "version": "1.4.1", "resolved": "https://registry.npmmirror.com/rfdc/-/rfdc-1.4.1.tgz", diff --git a/package.json b/package.json index 8a82960..c53cdd8 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "@hyrious/esbuild-plugin-external": "^0.1.4", "@types/node": "^20.14.13", "esbuild": "^0.21.5", + "prettier": "^3.3.3", "undici": "^6.19.4", "vitepress": "^1.3.1" }, diff --git a/src/build.ts b/src/build.ts index 7f1b304..e4d483c 100644 --- a/src/build.ts +++ b/src/build.ts @@ -44,7 +44,10 @@ const supportsPackagesExternal = /*#__PURE__*/ (() => { })(); class BuildError extends Error implements BuildFailure { - constructor(public errors: Message[], public warnings: Message[]) { + constructor( + public errors: Message[], + public warnings: Message[], + ) { super("Build failed"); this.name = "BuildFailure"; } @@ -79,7 +82,7 @@ export async function build( watchOptions?: { onRebuild: (error: BuildFailure | null, stop: () => void) => void }, ) { let tmpdir = tempDirectory(cacheOptions?.cwd); - if (!existsSync(tmpdir)) { + if (!existsSync(join(tmpdir, "package.json"))) { mkdirSync(tmpdir, { recursive: true }); writeFileSync(join(tmpdir, "package.json"), '{"type":"module"}'); }