diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e596d0..08059c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,28 +10,27 @@ 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 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 @@ -44,3 +43,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 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); diff --git a/src/loader.ts b/src/loader.ts index 1880533..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'; @@ -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; @@ -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)) { 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