Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Merged
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ The following properties are used from `tsconfig.json` in the working directory:
- `jsxFactory`
- `jsxFragmentFactory`

#### Custom `tsconfig.json` path
By default, `tsconfig.json` will be detected from the current working directory.

To set a custom path, use the `ESBK_TSCONFIG_PATH` environment variable:

```sh
ESBK_TSCONFIG_PATH=./path/to/tsconfig.custom.json node --loader @esbuild/esm-loader ./file.ts
```

### Cache
Modules transformations are cached in the system cache directory ([`TMPDIR`](https://en.wikipedia.org/wiki/TMPDIR)). Transforms are cached by content hash so duplicate dependencies are not re-transformed.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@esbuild-kit/core-utils": "^2.0.0",
"get-tsconfig": "^4.0.5"
"get-tsconfig": "^4.1.0"
},
"devDependencies": {
"@pvtnbr/eslint-config": "^0.22.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import path from 'path';
import { installSourceMapSupport } from '@esbuild-kit/core-utils';
import { getTsconfig, createPathsMatcher } from 'get-tsconfig';
import {
getTsconfig,
parseTsconfig,
createPathsMatcher,
} from 'get-tsconfig';

export const sourcemaps = installSourceMapSupport();

const tsconfig = getTsconfig();
const tsconfig = (
process.env.ESBK_TSCONFIG_PATH
? {
path: process.env.ESBK_TSCONFIG_PATH,
config: parseTsconfig(process.env.ESBK_TSCONFIG_PATH),
}
: getTsconfig()
);

export const tsconfigRaw = tsconfig?.config;
export const tsconfigPathsMatcher = tsconfig && createPathsMatcher(tsconfig);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"jsxFactory": "console.error"
}
}
11 changes: 11 additions & 0 deletions tests/specs/typescript/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
expect(nodeProcess.stdout).toBe('div null hello world\nnull null goodbye world');
});

test('Custom tsconfig.json path', async () => {
const nodeProcess = await node.load('./src/tsx.tsx', {
cwd: './tsconfig',
env: {
ESBK_TSCONFIG_PATH: './tsconfig-custom/tsconfig.custom-name.json',
},
});
expect(nodeProcess.stdout).toBe('');
expect(nodeProcess.stderr).toMatch('div null hello world\nnull null goodbye world');
});

describe('paths', ({ test, describe }) => {
test('resolves baseUrl', async () => {
const nodeProcess = await node.load('./src/base-url.ts', {
Expand Down
4 changes: 4 additions & 0 deletions tests/utils/node-with-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Options = {
args: string[];
nodePath: string;
cwd?: string;
env?: NodeJS.ProcessEnv;
nodeOptions?: string[];
};

Expand All @@ -20,6 +21,7 @@ export const nodeWithLoader = (
{
env: {
ESBK_DISABLE_CACHE: '1',
...options.env,
},
nodeOptions: [
...(options.nodeOptions ?? []),
Expand Down Expand Up @@ -47,6 +49,7 @@ export async function createNode(
filePath: string,
options?: {
cwd?: string;
env?: typeof process.env;
nodeOptions?: string[];
},
) {
Expand All @@ -55,6 +58,7 @@ export async function createNode(
args: [filePath],
nodePath: node.path,
cwd: path.join(fixturePath, options?.cwd ?? ''),
env: options?.env,
nodeOptions: options?.nodeOptions,
},
);
Expand Down