Skip to content
Closed
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 .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Build
run: yarn build
- name: Upload package artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: ts-node-packed.tgz
path: tests/ts-node-packed.tgz
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
- name: Build tests
run: yarn build-tsc
- name: Download package artifact
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4
with:
name: ts-node-packed.tgz
path: tests/
Expand All @@ -147,7 +147,7 @@ jobs:
files: yarn-error.log
- name: Upload yarn logs
if: ${{ failure() && steps.check-yarn-logs-exist.outputs.files_exists == 'true' }}
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: yarn-logs-${{ matrix.os }}-node-${{ matrix.nodeFlag }}-typescript-${{ matrix.typescriptFlag }}
path: yarn-error.log
Expand Down
28 changes: 28 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,34 @@ export function register(serviceOrOpts: Service | RegisterOptions | undefined):
if (!(serviceOrOpts as Service)?.[TS_NODE_SERVICE_BRAND]) {
// Not a service; is options
service = create((serviceOrOpts ?? {}) as RegisterOptions);

//@ts-expect-error
if (require.main && Module.registerHooks) {
const urls = {};

//@ts-expect-error
Module.registerHooks({
//@ts-expect-error
load(url, context, nextLoad) {
const isTypeScript =
(url.endsWith('.ts') && context.format === null) || context.format === 'commonjs-typescript';

//@ts-expect-error
if (isTypeScript && !urls[url]) {
//@ts-expect-error
urls[url] = true;

require(fileURLToPath(url));
return {
format: 'commonjs',
source: '',
shortCircuit: true,
};
}
return nextLoad(url, context);
},
});
}
}

const originalJsHandler = require.extensions['.js'];
Expand Down