Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"build/globals.js",
"build/deno.js"
],
"limit": "849.50 kB",
"limit": "850.00 kB",
"brotli": false,
"gzip": false
},
Expand Down Expand Up @@ -66,8 +66,8 @@
"README.md",
"LICENSE"
],
"limit": "911.20 kB",
"limit": "912.00 kB",
"brotli": false,
"gzip": false
}
]
]
8 changes: 7 additions & 1 deletion build/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Empty file modified build/cli.js
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions scripts/build-clean.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
{
Expand Down
5 changes: 5 additions & 0 deletions scripts/build-dts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-js.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-jsr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-pkgjson-lite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-pkgjson-main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions scripts/build-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down
5 changes: 3 additions & 2 deletions scripts/build-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down
10 changes: 9 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,15 @@ async function readScript() {
script = await readScriptFromHttp(firstArg)
tempPath = getFilepath($.cwd, name, ext)
} else {
script = await fs.readFile(firstArg, 'utf8')
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Pull this into a separate function readScriptFromFile
  2. rm console.error. The exception will be caught and logged via main try-catch.
  3. Rollback scripts/*.mjs edits. Keep the PR purpose focus.

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)
Expand Down
7 changes: 7 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion test/extra.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down