-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: #965
- Loading branch information
Showing
18 changed files
with
519 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "../src", | ||
"target": "es2022", | ||
"module": "nodenext", | ||
"moduleResolution": "nodenext" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "./build.json", | ||
"include": [ | ||
"../src/**/*.ts", | ||
"../src/**/*.cts", | ||
"../src/**/*.tsx" | ||
], | ||
"exclude": [ | ||
".../src/**/*.mts" | ||
], | ||
"compilerOptions": { | ||
"outDir": "../.tshy-build-tmp/commonjs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./build.json", | ||
"include": [ | ||
"../src/**/*.ts", | ||
"../src/**/*.mts", | ||
"../src/**/*.tsx" | ||
], | ||
"compilerOptions": { | ||
"outDir": "../.tshy-build-tmp/esm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Blue Oak Model License | ||
|
||
Version 1.0.0 | ||
|
||
## Purpose | ||
|
||
This license gives everyone as much permission to work with | ||
this software as possible, while protecting contributors | ||
from liability. | ||
|
||
## Acceptance | ||
|
||
In order to receive this license, you must agree to its | ||
rules. The rules of this license are both obligations | ||
under that agreement and conditions to your license. | ||
You must not do anything with this software that triggers | ||
a rule that you cannot or will not follow. | ||
|
||
## Copyright | ||
|
||
Each contributor licenses you to do everything with this | ||
software that would otherwise infringe that contributor's | ||
copyright in it. | ||
|
||
## Notices | ||
|
||
You must ensure that everyone who gets a copy of | ||
any part of this software from you, with or without | ||
changes, also gets the text of this license or a link to | ||
<https://blueoakcouncil.org/license/1.0.0>. | ||
|
||
## Excuse | ||
|
||
If anyone notifies you in writing that you have not | ||
complied with [Notices](#notices), you can keep your | ||
license by taking all practical steps to comply within 30 | ||
days after the notice. If you do not do so, your license | ||
ends immediately. | ||
|
||
## Patent | ||
|
||
Each contributor licenses you to do everything with this | ||
software that would otherwise infringe any patent claims | ||
they can license or become able to license. | ||
|
||
## Reliability | ||
|
||
No contributor can revoke this license. | ||
|
||
## No Liability | ||
|
||
**_As far as the law allows, this software comes as is, | ||
without any warranty or condition, and no contributor | ||
will be liable to anyone for any damages related to this | ||
software or this license, under any kind of legal claim._** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `@tapjs/tsx` | ||
|
||
An alternative plugin to `@tapjs/typescript`. Load typescript | ||
tests using [`tsx`](https://github.com/privatenumber/tsx) instead | ||
of [`ts-node`](https://github.com/TypeStrong/ts-node). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { fileURLToPath } from 'url' | ||
|
||
// check if we need a globalPreload, because node 20 runs | ||
// loaders in separate isolated loaders thread. | ||
|
||
const v = process.version | ||
.replace(/[^0-9]/g, ' ') | ||
.trim() | ||
.split(' ') | ||
.map(s => parseInt(s, 10)) | ||
const separateLoadersThread = v[0] >= 20 | ||
|
||
const base = fileURLToPath(import.meta.url) | ||
export const globalPreload = () => | ||
!separateLoadersThread | ||
? '' | ||
: ` | ||
const { createRequire } = getBuiltin('module') | ||
const require = createRequire(${JSON.stringify(base)}) | ||
require('@esbuild-kit/cjs') | ||
` | ||
|
||
// otherwise, do it here | ||
if (!separateLoadersThread) { | ||
await import('@esbuild-kit/cjs-loader') | ||
} | ||
|
||
export * from '@esbuild-kit/esm-loader' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"name": "@tapjs/tsx", | ||
"version": "1.1.17", | ||
"description": "Alternative to @tapjs/typescript. Load typescript using tsx instead of ts-node.", | ||
"tshy": { | ||
"main": true, | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": "./src/index.ts", | ||
"./loader": "./src/loader.mts", | ||
"./import": "./src/import.mts" | ||
} | ||
}, | ||
"type": "module", | ||
"main": "./dist/commonjs/index.js", | ||
"types": "./dist/commonjs/index.d.ts", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": { | ||
"types": "./dist/esm/index.d.ts", | ||
"default": "./dist/esm/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/commonjs/index.d.ts", | ||
"default": "./dist/commonjs/index.js" | ||
} | ||
}, | ||
"./loader": { | ||
"import": { | ||
"types": "./dist/esm/loader.d.mts", | ||
"default": "./dist/esm/loader.mjs" | ||
} | ||
}, | ||
"./import": { | ||
"import": { | ||
"types": "./dist/esm/import.d.mts", | ||
"default": "./dist/esm/import.mjs" | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepare": "tshy", | ||
"pretest": "npm run prepare", | ||
"presnap": "npm run prepare", | ||
"test": "tap", | ||
"snap": "tap", | ||
"format": "prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache", | ||
"typedoc": "typedoc --tsconfig tsconfig/esm.json ./src/*.ts" | ||
}, | ||
"license": "BlueOak-1.0.0", | ||
"dependencies": { | ||
"tsx": "^4.1.2" | ||
}, | ||
"peerDependencies": { | ||
"@tapjs/core": "1.4.5" | ||
}, | ||
"tap": { | ||
"typecheck": false | ||
}, | ||
"keywords": [ | ||
"tapjs plugin" | ||
], | ||
"engines": { | ||
"node": "16 >=16.17.0 || 18 >= 18.6.0 || >=20" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
//@ts-ignore | ||
export * from 'tsx' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Exports a loader, which does all the work. | ||
// import('tsx') | ||
// import('@tapjs/core') | ||
export const loader = '@tapjs/tsx/loader' | ||
export const importLoader = '@tapjs/tsx/import' | ||
export const preload = true | ||
import type { TapPlugin } from '@tapjs/core' | ||
|
||
// the plugin just sets the configs for tsx, doesn't | ||
// add any functionality to the Test class. | ||
const env = (...keys: string[]) => { | ||
for (const key of keys) { | ||
if (process.env[`TAP_${key}`]) { | ||
process.env[key] = process.env[`TAP_${key}`] | ||
} | ||
} | ||
} | ||
let didWarning = false | ||
let didEnv = false | ||
|
||
/** | ||
* File types that this plugin adds support for | ||
*/ | ||
export const testFileExtensions = ['ts', 'cts', 'mts', 'tsx', 'jsx'] | ||
|
||
/** | ||
* Plugin function enabling tsx for running typescript tests | ||
* | ||
* The plugin function sets the tsx environment variables based on the tap | ||
* configs, and prints a warning when used along with the `@tapjs/typescript` | ||
* plugin, as this can cause strange conflicts, or at the very least, | ||
* unnecessarily slow down tests by compiling the typescript twice. | ||
*/ | ||
export const plugin: TapPlugin<{}> = () => { | ||
if (!didEnv) { | ||
env('TSX_TSCONFIG_PATH', 'TSX_DISABLE_CACHE') | ||
} | ||
const tp = process.env.TAP_PLUGIN || '' | ||
if (!/^!@tapjs\/typescript$/m.test(tp) && !didWarning) { | ||
didWarning = true | ||
console.error(` | ||
@tapjs/tsx may behave strangely when used along with | ||
the @tapjs/typescript default plugin. | ||
Please run: tap plugin rm @tapjs/typescript | ||
`) | ||
} | ||
return {} | ||
} | ||
|
||
/** | ||
* Configuration fields added by this plugin. | ||
* | ||
* @group Configuration | ||
*/ | ||
export const config = { | ||
/** | ||
* String option. Tell `tsx` where to find your tsconfig.json file. | ||
* | ||
* @group Configuration | ||
*/ | ||
'tsx-tsconfig-path': { | ||
type: 'string', | ||
description: `Tell tsx where to find your tsconfig.json file.`, | ||
}, | ||
/** | ||
* Flag. Tell `tsx` not to use a cache | ||
* | ||
* @group Configuration | ||
*/ | ||
'tsx-disable-cache': { | ||
type: 'boolean', | ||
description: `Tell tsx not to use a cache`, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//@ts-ignore | ||
export * from 'tsx/esm' | ||
//@ts-ignore | ||
import 'tsx/cjs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* IMPORTANT | ||
* This snapshot file is auto-generated, but designed for humans. | ||
* It should be checked into source control and tracked carefully. | ||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests. | ||
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[`test/index.js > TAP > config 1`] = ` | ||
Object { | ||
"esbk-disable-cache": Object { | ||
"description": "Tell @esbuild-kit not to use a cache", | ||
"type": "boolean", | ||
}, | ||
"esbk-tsconfig-path": Object { | ||
"description": String( | ||
Tell @esbuild-kit where to find your | ||
tsconfig.json file. | ||
), | ||
"type": "string", | ||
}, | ||
} | ||
` |
Oops, something went wrong.