diff --git a/.size-limit.json b/.size-limit.json index 601aa49e5c..7efd68e380 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -33,7 +33,7 @@ "build/globals.js", "build/deno.js" ], - "limit": "849.50 kB", + "limit": "850.00 kB", "brotli": false, "gzip": false }, @@ -66,8 +66,8 @@ "README.md", "LICENSE" ], - "limit": "911.20 kB", + "limit": "912.00 kB", "brotli": false, "gzip": false } -] +] \ No newline at end of file diff --git a/build/cli.cjs b/build/cli.cjs index 5b547df14e..362bb7396b 100755 --- a/build/cli.cjs +++ b/build/cli.cjs @@ -300,7 +300,13 @@ function readScript() { script = yield readScriptFromHttp(firstArg); tempPath = getFilepath(import_index.$.cwd, name, ext2); } else { - script = yield import_index.fs.readFile(firstArg, "utf8"); + try { + script = yield import_index.fs.readFile(firstArg, "utf8"); + } catch (err) { + console.error(`Error: Can't read ${firstArg}`); + import_node_process2.default.exitCode = 1; + throw new import_index.Fail(`Failed to read local script: ${firstArg} (${err.message})`); + } scriptPath = firstArg.startsWith("file:") ? import_node_url.default.fileURLToPath(firstArg) : import_index.path.resolve(firstArg); } const { ext, base, dir } = import_index.path.parse(tempPath || scriptPath); diff --git a/build/cli.js b/build/cli.js old mode 100644 new mode 100755 diff --git a/scripts/build-clean.mjs b/scripts/build-clean.mjs index 5e8c6e7292..1989aa61dd 100644 --- a/scripts/build-clean.mjs +++ b/scripts/build-clean.mjs @@ -14,9 +14,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { fileURLToPath } from 'node:url' +import path from 'node:path' import fs from 'node:fs' import glob from 'fast-glob' +const __dirname = path.dirname(fileURLToPath(import.meta.url)) + const redundants = await glob( ['build/{repl,globals-jsr}.d.ts', 'build/{deps,internals,util,vendor*}.js'], { diff --git a/scripts/build-dts.mjs b/scripts/build-dts.mjs index 0e738bdf2b..d0d9182904 100644 --- a/scripts/build-dts.mjs +++ b/scripts/build-dts.mjs @@ -14,6 +14,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { fileURLToPath } from 'node:url' +import path from 'node:path' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) + import fs from 'node:fs/promises' import { generateDtsBundle } from 'dts-bundle-generator' import glob from 'fast-glob' diff --git a/scripts/build-js.mjs b/scripts/build-js.mjs index e7228ee935..d7c2f85815 100644 --- a/scripts/build-js.mjs +++ b/scripts/build-js.mjs @@ -27,7 +27,9 @@ import esbuildResolvePlugin from 'esbuild-plugin-resolve' import minimist from 'minimist' import glob from 'fast-glob' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +import { fileURLToPath } from 'node:url' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) const argv = minimist(process.argv.slice(2), { default: { diff --git a/scripts/build-jsr.mjs b/scripts/build-jsr.mjs index 5975a51e23..dc0dcb04ea 100644 --- a/scripts/build-jsr.mjs +++ b/scripts/build-jsr.mjs @@ -14,7 +14,9 @@ import fs from 'node:fs' import path from 'node:path' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +import { fileURLToPath } from 'node:url' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) const root = path.resolve(__dirname, '..') const pkgJson = JSON.parse( fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8') diff --git a/scripts/build-pkgjson-lite.mjs b/scripts/build-pkgjson-lite.mjs index ec433df6c4..3d645491a4 100644 --- a/scripts/build-pkgjson-lite.mjs +++ b/scripts/build-pkgjson-lite.mjs @@ -18,7 +18,9 @@ import fs from 'node:fs' import path from 'node:path' import { depseekSync } from 'depseek' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +import { fileURLToPath } from 'node:url' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) const root = path.resolve(__dirname, '..') const source = 'package.json' const dest = 'package-lite.json' diff --git a/scripts/build-pkgjson-main.mjs b/scripts/build-pkgjson-main.mjs index 4786832b55..06f9e226e2 100644 --- a/scripts/build-pkgjson-main.mjs +++ b/scripts/build-pkgjson-main.mjs @@ -17,7 +17,9 @@ import fs from 'node:fs' import path from 'node:path' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +import { fileURLToPath } from 'node:url' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) const root = path.resolve(__dirname, '..') const source = 'package.json' const dest = 'package-main.json' diff --git a/scripts/build-tests.mjs b/scripts/build-tests.mjs index cd2b6bd4f3..406b2af3c7 100644 --- a/scripts/build-tests.mjs +++ b/scripts/build-tests.mjs @@ -26,10 +26,12 @@ const modules = [ ['cli', cli], ['index', index], ] -const root = path.resolve(new URL(import.meta.url).pathname, '../..') +import { fileURLToPath } from 'node:url' + +const root = path.resolve(fileURLToPath(import.meta.url), '../..') const filePath = path.resolve(root, `test/export.test.js`) -const copyright = await fs.readFileSync( +const copyright = fs.readFileSync( path.resolve(root, 'test/fixtures/copyright.txt'), 'utf8' ) diff --git a/scripts/build-versions.mjs b/scripts/build-versions.mjs index 0959ed2ac4..79b535acf6 100644 --- a/scripts/build-versions.mjs +++ b/scripts/build-versions.mjs @@ -17,9 +17,10 @@ import fs from 'fs-extra' import path from 'node:path' import minimist from 'minimist' +import { fileURLToPath } from 'node:url' -const root = path.resolve(new URL(import.meta.url).pathname, '../..') -const copyright = await fs.readFileSync( +const root = path.resolve(fileURLToPath(import.meta.url), '../..') +const copyright = fs.readFileSync( path.resolve(root, 'test/fixtures/copyright.txt'), 'utf8' ) diff --git a/src/cli.ts b/src/cli.ts index df1ea719f0..a16038b071 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -225,7 +225,15 @@ async function readScript() { script = await readScriptFromHttp(firstArg) tempPath = getFilepath($.cwd, name, ext) } else { - script = await fs.readFile(firstArg, 'utf8') + try { + script = await fs.readFile(firstArg, 'utf8') + } catch (err: any) { + console.error(`Error: Can't read ${firstArg}`) + process.exitCode = 1 + throw new Fail( + `Failed to read local script: ${firstArg} (${err.message})` + ) + } scriptPath = firstArg.startsWith('file:') ? url.fileURLToPath(firstArg) : path.resolve(firstArg) diff --git a/test/cli.test.js b/test/cli.test.js index 848cade891..a16bb5e626 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -290,6 +290,13 @@ console.log(a); await server.stop() }) + test('scripts from missing local file', async () => { + const out = await $`node build/cli.js non-existent-script.mjs`.nothrow() + assert.match(out.stderr, /Error: Can't read non-existent-script.mjs/) + assert.match(out.stderr, /Failed to read local script/) + assert.equal(out.exitCode, 1) + }) + test('scripts (md) from https', async () => { const resp = await fs.readFile(path.resolve('test/fixtures/md.http')) const port = await getPort() diff --git a/test/extra.test.js b/test/extra.test.js index f74d82fe33..44948b836c 100644 --- a/test/extra.test.js +++ b/test/extra.test.js @@ -16,7 +16,9 @@ import assert from 'node:assert' import { test, describe } from 'node:test' import { globby, fs, path } from '../build/index.js' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +import { fileURLToPath } from 'node:url' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) describe('extra', () => { test('every file should have a license', async () => {