Skip to content

Commit

Permalink
refactor: move top level register and nx-transformer to src/
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpza committed Aug 18, 2024
1 parent 2fc9901 commit 6f0a280
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
8 changes: 6 additions & 2 deletions nx-transformer.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
"use strict";
module.exports = require("./").nxTransformerPlugin;
// Keeping register here in the root for backwards compatibiliy, TODO remove in the next major version
console.warn(
"typescript-transform-paths: Calling the top level nx-transformer file is deprecated and will be removed in the future. Use a tool that supports package.json exports",
);

module.exports = require("./dist/plugins/nx-transfomer-plugin").default;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./register": "./register.js",
"./nx-transformer": "./nx-transformer.js"
"./register": "./dist/register-entry.js",
"./nx-transformer": "./dist/plugins/nx-transformer-plugin.js"
},
"files": [
"dist",
Expand Down
16 changes: 5 additions & 11 deletions register.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
let tsNode;
try {
tsNode = require("ts-node");
} catch {
throw new Error(
`Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register`,
);
}

tsNode.register();
require("./").register();
// Keeping register here in the root for backwards compatibiliy, TODO remove in the next major version
console.warn(
"typescript-transform-paths: Calling the top level register file is deprecated and will be removed in the future. Use a tool that supports package.json exports",
);
require("./dist/register-entry");
2 changes: 1 addition & 1 deletion src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./nx-transformer-plugin";
export * as nxTransformerPlugin from "./nx-transformer-plugin";
11 changes: 5 additions & 6 deletions src/plugins/nx-transformer-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ const voidTransformer: ts.TransformerFactory<ts.SourceFile> = () => (s: ts.Sourc
* Transformer
* ****************************************************************************************************************** */

export const nxTransformerPlugin: NxTransformerPlugin = {
before: (pluginConfig, program) =>
pluginConfig?.afterDeclarations ? voidTransformer : transformer(program, { ...pluginConfig }),
afterDeclarations: (pluginConfig, program) =>
!pluginConfig?.afterDeclarations ? voidTransformer : transformer(program, { ...pluginConfig }),
};
export const before: NxTransformerFactory = (pluginConfig, program) =>
pluginConfig?.afterDeclarations ? voidTransformer : transformer(program, { ...pluginConfig });

export const afterDeclarations: NxTransformerFactory = (pluginConfig, program) =>
!pluginConfig?.afterDeclarations ? voidTransformer : transformer(program, { ...pluginConfig });
13 changes: 13 additions & 0 deletions src/register-entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let tsNode;
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
tsNode = require("ts-node");
} catch {
throw new Error(
`Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register`,
);
}

tsNode.register();
// eslint-disable-next-line @typescript-eslint/no-require-imports
require("./").register();

0 comments on commit 6f0a280

Please sign in to comment.