From 6d95bb90aac6d20a4277c3d15a98ec245fd26dd0 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 9 Oct 2021 16:23:57 -0700 Subject: [PATCH 1/7] fix(bin): use relative file in argv loader --- src/bin.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index a30777d..18a65f7 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -27,7 +27,5 @@ if (argv.includes('-v') || argv.includes('--version')) { process.exit(0); } -let file = require('path').join(__dirname, 'loader.mjs'); -require('child_process').spawn('node', ['--loader', file, ...argv], { - stdio: 'inherit' -}).on('exit', process.exit); +argv = ['--loader', './loader.mjs', ...argv]; +require('child_process').spawn('node', argv, { stdio: 'inherit' }).on('exit', process.exit); From d5bda4f895a078f4917d92b3854e82e2e8b715c0 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 9 Oct 2021 16:31:07 -0700 Subject: [PATCH 2/7] fix(loader): use "file:///" prefix for config file --- src/loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loader.ts b/src/loader.ts index 1880533..ac61a9f 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -9,7 +9,7 @@ let config: Config; let esbuild: typeof import('esbuild'); let env = (tsm as TSM).$defaults('esm'); -let setup = env.file && import(env.file); +let setup = env.file && import('file:///' + env.file); type Promisable = Promise | T; type Source = string | SharedArrayBuffer | Uint8Array; From 0a31555e82bb5bdd67b0702ec47e620989cd2bbf Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 9 Oct 2021 16:31:34 -0700 Subject: [PATCH 3/7] chore(loader): use named `url` imports --- src/loader.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/loader.ts b/src/loader.ts index ac61a9f..546c4db 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -1,5 +1,5 @@ -import * as url from 'url'; import { existsSync } from 'fs'; +import { fileURLToPath, URL } from 'url'; import * as tsm from './utils.js'; import type { Config, Extension, Options } from 'tsm/config'; @@ -52,18 +52,18 @@ async function toOptions(uri: string): Promise { } function check(fileurl: string): string | void { - let tmp = url.fileURLToPath(fileurl); + let tmp = fileURLToPath(fileurl); if (existsSync(tmp)) return fileurl; } -const root = url.pathToFileURL(process.cwd() + '/'); +const root = new URL('file:///' + process.cwd() + '/'); export const resolve: Resolve = async function (ident, context, fallback) { // ignore "prefix:" and non-relative identifiers if (/^\w+\:?/.test(ident)) return fallback(ident, context, fallback); let match: RegExpExecArray | null; let idx: number, ext: Extension, path: string | void; - let output = new url.URL(ident, context.parentURL || root); + let output = new URL(ident, context.parentURL || root); // source ident includes extension if (match = EXTN.exec(output.href)) { From 9fb107a467346d93012b08da688a22d92a6e7384 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 9 Oct 2021 16:51:25 -0700 Subject: [PATCH 4/7] fix(require): ensure valid file paths after URL work --- src/require.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/require.ts b/src/require.ts index bc931db..2317c3d 100644 --- a/src/require.ts +++ b/src/require.ts @@ -18,8 +18,8 @@ let config: Config = (tsm as TSM).$finalize(env, uconf); declare const $$req: NodeJS.Require; const tsrequire = 'var $$req=require("module").createRequire(__filename);require=(' + function () { - let { existsSync } = $$req('fs'); - let { URL, pathToFileURL } = $$req('url'); + let { existsSync } = $$req('fs') as typeof import('fs'); + let $url = $$req('url') as typeof import('url'); return new Proxy(require, { // NOTE: only here if source is TS @@ -34,8 +34,8 @@ const tsrequire = 'var $$req=require("module").createRequire(__filename);require let match = /\.([mc])?js(?=\?|$)/.exec(ident); if (match == null) return $$req(ident); - let base = pathToFileURL(__filename) as import('url').URL; - let file = new URL(ident, base).pathname as string; + let base = $url.pathToFileURL(__filename); + let file = $url.fileURLToPath(new $url.URL(ident, base)); if (existsSync(file)) return $$req(ident); // ?js -> ?ts file From 9ad6ab6855adbe57cf941aef65bba266c42326db Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 9 Oct 2021 16:55:03 -0700 Subject: [PATCH 5/7] chore(bin): include `node bin` tests --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e596d0..4a19bbc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,3 +44,9 @@ jobs: - name: Tests <~ CommonJS <~ TypeScript run: node -r ./require.js test/config/index.ts --tsmconfig test/config/tsm.js + + - name: Tests <~ CLI + run: node bin.js test/index.mjs + + - name: Tests <~ CLI <~ TypeScript + run: node bin.js test/config/index.ts --tsmconfig test/config/tsm.js From 05c7b660ba8d0c92d8cbfe4f2865f6fe80817c62 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 9 Oct 2021 16:57:00 -0700 Subject: [PATCH 6/7] chore(bin): include windows in test matrix --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a19bbc..7a68830 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,11 +10,13 @@ on: jobs: test: - name: Node.js v${{ matrix.nodejs }} - runs-on: ubuntu-latest + name: Node.js v${{ matrix.nodejs }} (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 3 strategy: matrix: nodejs: [12, 14, 16] + os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 From 14f770cfc045f0b8a622d2f2c4f1062217779f1f Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 9 Oct 2021 16:59:40 -0700 Subject: [PATCH 7/7] chore(bin): revert to npm :( - don't want to deal with multiple "install / env" steps --- .github/workflows/ci.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a68830..08059c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,17 +23,14 @@ jobs: with: node-version: ${{ matrix.nodejs }} - - name: (env) pnpm - run: curl -L https://raw.githubusercontent.com/pnpm/self-installer/master/install.js | node - - name: Install - run: pnpm install + run: npm install - name: Compiles - run: pnpm run build + run: npm run build - name: Type Checks - run: pnpm run types + run: npm run types - name: Tests <~ ESM run: node --loader ./loader.mjs test/index.mjs