@nestia/core 12.0.0-dev.20260612.2 → 12.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +3 -3
- package/lib/decorators/internal/load_controller.js +8 -7
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/transform.d.ts +4 -4
- package/lib/transform.js +8 -53
- package/lib/transform.js.map +1 -1
- package/package.json +10 -10
- package/src/decorators/internal/load_controller.ts +13 -10
- package/src/transform.ts +13 -88
package/MIGRATION.md
CHANGED
|
@@ -112,11 +112,11 @@ binary, but tooling may still inspect the entry.
|
|
|
112
112
|
|
|
113
113
|
### 7. Internal symbols removed
|
|
114
114
|
|
|
115
|
-
The `INestiaTransformOptions`, `INestiaTransformProject`, `PlainBodyProgrammer`, `TypedBodyProgrammer`, and the `programmers/` / `transformers/` directories were deleted. None were exported from `module.ts`; if your code imported them via deep paths it must be rewritten against the new pipeline or migrated to `@
|
|
115
|
+
The `INestiaTransformOptions`, `INestiaTransformProject`, `PlainBodyProgrammer`, `TypedBodyProgrammer`, and the `programmers/` / `transformers/` directories were deleted. None were exported from `module.ts`; if your code imported them via deep paths it must be rewritten against the new pipeline or migrated to `@ttsc/factory`.
|
|
116
116
|
|
|
117
|
-
### 8. `@
|
|
117
|
+
### 8. AST factory: `@ttsc/factory`
|
|
118
118
|
|
|
119
|
-
`@nestia/factory`
|
|
119
|
+
`@nestia/sdk` and `@nestia/migrate` build TypeScript source through [`@ttsc/factory`](https://www.npmjs.com/package/@ttsc/factory), a dependency-free, printer-compatible AST factory and printer that keeps working after the TypeScript-Go (tsgo) migration. Third-party code generators that previously reached into `@nestia/core`'s internal `factories/` can depend on `@ttsc/factory` directly.
|
|
120
120
|
|
|
121
121
|
### 9. Runtime requirement: Go 1.26+ on PATH
|
|
122
122
|
|
|
@@ -22,10 +22,7 @@ const load_controllers = (path, isTsNode) => __awaiter(void 0, void 0, void 0, f
|
|
|
22
22
|
const exclude = typeof path === "object" && !Array.isArray(path)
|
|
23
23
|
? ((_a = path.exclude) !== null && _a !== void 0 ? _a : [])
|
|
24
24
|
: [];
|
|
25
|
-
const filter = isTsNode === true
|
|
26
|
-
? (file) => file.substring(file.length - 3) === ".ts" &&
|
|
27
|
-
file.substring(file.length - 5) !== ".d.ts"
|
|
28
|
-
: (file) => file.substring(file.length - 3) === ".js";
|
|
25
|
+
const filter = isTsNode === true ? isTypeScriptSource : isJavaScriptModule;
|
|
29
26
|
const sources = yield SourceFinder_1.SourceFinder.find({
|
|
30
27
|
include,
|
|
31
28
|
exclude,
|
|
@@ -42,12 +39,10 @@ const load_controllers = (path, isTsNode) => __awaiter(void 0, void 0, void 0, f
|
|
|
42
39
|
// `.ts` file is then served as the transformed emit by the hooks.
|
|
43
40
|
if (!isTsxRuntime())
|
|
44
41
|
return controllers;
|
|
45
|
-
const tsFilter = (file) => file.substring(file.length - 3) === ".ts" &&
|
|
46
|
-
file.substring(file.length - 5) !== ".d.ts";
|
|
47
42
|
const fallback = yield SourceFinder_1.SourceFinder.find({
|
|
48
43
|
include,
|
|
49
44
|
exclude,
|
|
50
|
-
filter:
|
|
45
|
+
filter: isTypeScriptSource,
|
|
51
46
|
});
|
|
52
47
|
return fallback.length === 0 ? controllers : mount(fallback);
|
|
53
48
|
});
|
|
@@ -85,4 +80,10 @@ function isTsxRuntime() {
|
|
|
85
80
|
return (typeof process.env.TTSX_RUNTIME_MANIFEST === "string" &&
|
|
86
81
|
process.env.TTSX_RUNTIME_MANIFEST.length !== 0);
|
|
87
82
|
}
|
|
83
|
+
const isJavaScriptModule = (file) => /\.(?:[cm]?js)$/.test(file.toLowerCase());
|
|
84
|
+
const isTypeScriptSource = (file) => {
|
|
85
|
+
const lower = file.toLowerCase();
|
|
86
|
+
return (/\.(?:[cm]?ts)$/.test(lower) &&
|
|
87
|
+
/\.(?:d\.[cm]?ts|d\.ts)$/.test(lower) === false);
|
|
88
|
+
};
|
|
88
89
|
//# sourceMappingURL=load_controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load_controller.js","sourceRoot":"","sources":["../../../src/decorators/internal/load_controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAAoC;AAGpC,2DAAwD;AAEjD,MAAM,gBAAgB,GAAG,CAC9B,IAAmE,EACnE,QAAkB,EACU,EAAE;;IAC9B,MAAM,OAAO,GAAa,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAC3C,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ;YACxB,CAAC,CAAC,IAAI,CAAC,OAAO;YACd,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACb,MAAM,OAAO,GACX,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAC9C,CAAC,CAAC,OAAC,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAC;QACtB,CAAC,CAAC,EAAE,CAAC;IACT,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"load_controller.js","sourceRoot":"","sources":["../../../src/decorators/internal/load_controller.ts"],"names":[],"mappings":"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"}
|
package/lib/transform.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { ITtscPlugin, ITtscPluginFactoryContext } from "ttsc";
|
|
1
2
|
/**
|
|
2
3
|
* `@nestia/core` ttsc plugin descriptor.
|
|
3
4
|
*
|
|
4
5
|
* `@nestia/sdk` is not a standalone plugin: its Go transform is declared here
|
|
5
|
-
* as a `contributor` that ttsc statically links into this host binary, and
|
|
6
|
-
*
|
|
6
|
+
* as a `contributor` that ttsc statically links into this host binary, and only
|
|
7
|
+
* when `@nestia/sdk` is actually resolvable from the project. A project
|
|
7
8
|
* depending on `@nestia/core` alone never compiles any SDK transform code.
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
-
export default createTtscPlugin;
|
|
10
|
+
export default function createTtscPlugin(context: ITtscPluginFactoryContext): ITtscPlugin;
|
package/lib/transform.js
CHANGED
|
@@ -3,68 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports.default = createTtscPlugin;
|
|
7
|
+
const node_module_1 = require("node:module");
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const node_url_1 = require("node:url");
|
|
10
|
-
const filename = currentFilename();
|
|
11
|
-
const dirname = node_path_1.default.dirname(filename);
|
|
12
9
|
/**
|
|
13
10
|
* `@nestia/core` ttsc plugin descriptor.
|
|
14
11
|
*
|
|
15
12
|
* `@nestia/sdk` is not a standalone plugin: its Go transform is declared here
|
|
16
|
-
* as a `contributor` that ttsc statically links into this host binary, and
|
|
17
|
-
*
|
|
13
|
+
* as a `contributor` that ttsc statically links into this host binary, and only
|
|
14
|
+
* when `@nestia/sdk` is actually resolvable from the project. A project
|
|
18
15
|
* depending on `@nestia/core` alone never compiles any SDK transform code.
|
|
19
16
|
*/
|
|
20
17
|
function createTtscPlugin(context) {
|
|
21
|
-
const
|
|
18
|
+
const requireFrom = (0, node_module_1.createRequire)(node_path_1.default.join(context.projectRoot, "package.json"));
|
|
19
|
+
const root = node_path_1.default.dirname(requireFrom.resolve("@nestia/core/package.json"));
|
|
20
|
+
return {
|
|
22
21
|
name: "@nestia/core",
|
|
23
|
-
source: node_path_1.default.resolve(root
|
|
24
|
-
composes: ["typia/lib/transform"],
|
|
22
|
+
source: node_path_1.default.resolve(root, "native", "cmd", "ttsc-nestia"),
|
|
25
23
|
};
|
|
26
|
-
const sdk = resolveSdkContributorSource(context);
|
|
27
|
-
if (sdk !== null)
|
|
28
|
-
plugin.contributors = [{ name: "sdk", source: sdk }];
|
|
29
|
-
return plugin;
|
|
30
|
-
}
|
|
31
|
-
exports.default = createTtscPlugin;
|
|
32
|
-
function root(context) {
|
|
33
|
-
var _a;
|
|
34
|
-
return ((_a = resolvePackageRoot("@nestia/core/package.json", context.projectRoot)) !== null && _a !== void 0 ? _a : node_path_1.default.resolve(dirname, ".."));
|
|
35
|
-
}
|
|
36
|
-
function resolveSdkContributorSource(context) {
|
|
37
|
-
const manifest = resolvePackageRoot("@nestia/sdk/package.json", context.projectRoot);
|
|
38
|
-
if (manifest === null)
|
|
39
|
-
return null;
|
|
40
|
-
const source = node_path_1.default.resolve(manifest, "native", "sdk");
|
|
41
|
-
return node_fs_1.default.existsSync(source) ? source : null;
|
|
42
|
-
}
|
|
43
|
-
function resolvePackageRoot(packageJson, projectRoot) {
|
|
44
|
-
try {
|
|
45
|
-
return node_path_1.default.dirname(require.resolve(packageJson, { paths: [dirname, projectRoot] }));
|
|
46
|
-
}
|
|
47
|
-
catch (_a) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function currentFilename() {
|
|
52
|
-
var _a;
|
|
53
|
-
var _b, _c;
|
|
54
|
-
if (typeof __filename === "string" &&
|
|
55
|
-
__filename !== "[stdin]" &&
|
|
56
|
-
__filename.length !== 0)
|
|
57
|
-
return normalizeFilename(__filename);
|
|
58
|
-
const line = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").find((entry) => entry.includes("/src/transform.ts") ||
|
|
59
|
-
entry.includes("/lib/transform.js") ||
|
|
60
|
-
entry.includes("/lib/transform.mjs"));
|
|
61
|
-
const matched = line === null || line === void 0 ? void 0 : line.match(/\(([^()]+):\d+:\d+\)|at ([^\s()]+):\d+:\d+/);
|
|
62
|
-
const fallback = typeof __filename === "string" ? __filename : "";
|
|
63
|
-
return normalizeFilename((_c = (_b = matched === null || matched === void 0 ? void 0 : matched[1]) !== null && _b !== void 0 ? _b : matched === null || matched === void 0 ? void 0 : matched[2]) !== null && _c !== void 0 ? _c : fallback);
|
|
64
|
-
}
|
|
65
|
-
function normalizeFilename(value) {
|
|
66
|
-
if (value.startsWith("file:"))
|
|
67
|
-
return (0, node_url_1.fileURLToPath)(value);
|
|
68
|
-
return value;
|
|
69
24
|
}
|
|
70
25
|
//# sourceMappingURL=transform.js.map
|
package/lib/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA4C;AAC5C,0DAA6B;AAG7B;;;;;;;GAOG;AACH,0BACE,OAAkC;IAElC,MAAM,WAAW,GAAG,IAAA,2BAAa,EAC/B,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAC/C,CAAC;IACF,MAAM,IAAI,GAAW,mBAAI,CAAC,OAAO,CAC/B,WAAW,CAAC,OAAO,CAAC,2BAA2B,CAAC,CACjD,CAAC;IACF,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE,mBAAI,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC;KAC3D,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "12.0.0-
|
|
3
|
+
"version": "12.0.0-rc.1",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://nestia.io",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@typia/interface": "13.0.0-
|
|
50
|
-
"@typia/utils": "13.0.0-
|
|
49
|
+
"@typia/interface": "13.0.0-rc.1",
|
|
50
|
+
"@typia/utils": "13.0.0-rc.1",
|
|
51
51
|
"get-function-location": "^2.0.0",
|
|
52
52
|
"glob": "^11.0.3",
|
|
53
53
|
"path-parser": "^6.1.0",
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"reflect-metadata": ">=0.1.12",
|
|
56
56
|
"rxjs": ">=6.0.3",
|
|
57
57
|
"tgrid": "^1.1.0",
|
|
58
|
-
"typia": "13.0.0-
|
|
58
|
+
"typia": "13.0.0-rc.1",
|
|
59
59
|
"ws": "^7.5.3",
|
|
60
|
-
"@nestia/fetcher": "^12.0.0-
|
|
60
|
+
"@nestia/fetcher": "^12.0.0-rc.1"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@modelcontextprotocol/sdk": "^1.18.0",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"@nestjs/core": ">=7.0.1",
|
|
66
66
|
"reflect-metadata": ">=0.1.12",
|
|
67
67
|
"rxjs": ">=6.0.3",
|
|
68
|
-
"typia": "13.0.0-
|
|
69
|
-
"@nestia/fetcher": "^12.0.0-
|
|
68
|
+
"typia": "13.0.0-rc.1",
|
|
69
|
+
"@nestia/fetcher": "^12.0.0-rc.1"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
72
72
|
"@modelcontextprotocol/sdk": {
|
|
@@ -78,14 +78,14 @@
|
|
|
78
78
|
"@nestjs/common": "^11.1.6",
|
|
79
79
|
"@nestjs/core": "^11.1.6",
|
|
80
80
|
"@nestjs/platform-express": "^11.1.6",
|
|
81
|
-
"@typescript/native-preview": "7.0.0-dev.20260518.1",
|
|
82
81
|
"@types/express": "^4.17.15",
|
|
83
82
|
"@types/multer": "^1.4.12",
|
|
84
83
|
"@types/ws": "^8.5.10",
|
|
85
84
|
"fastify": "^4.28.1",
|
|
86
85
|
"rimraf": "^6.1.3",
|
|
87
|
-
"ttsc": "^0.
|
|
88
|
-
"tstl": "^3.0.0"
|
|
86
|
+
"ttsc": "^0.16.10",
|
|
87
|
+
"tstl": "^3.0.0",
|
|
88
|
+
"typescript": "7.0.1-rc"
|
|
89
89
|
},
|
|
90
90
|
"files": [
|
|
91
91
|
"README.md",
|
|
@@ -16,12 +16,7 @@ export const load_controllers = async (
|
|
|
16
16
|
typeof path === "object" && !Array.isArray(path)
|
|
17
17
|
? (path.exclude ?? [])
|
|
18
18
|
: [];
|
|
19
|
-
const filter =
|
|
20
|
-
isTsNode === true
|
|
21
|
-
? (file: string) =>
|
|
22
|
-
file.substring(file.length - 3) === ".ts" &&
|
|
23
|
-
file.substring(file.length - 5) !== ".d.ts"
|
|
24
|
-
: (file: string) => file.substring(file.length - 3) === ".js";
|
|
19
|
+
const filter = isTsNode === true ? isTypeScriptSource : isJavaScriptModule;
|
|
25
20
|
const sources: string[] = await SourceFinder.find({
|
|
26
21
|
include,
|
|
27
22
|
exclude,
|
|
@@ -38,13 +33,10 @@ export const load_controllers = async (
|
|
|
38
33
|
// `.ts` file is then served as the transformed emit by the hooks.
|
|
39
34
|
if (!isTsxRuntime()) return controllers;
|
|
40
35
|
|
|
41
|
-
const tsFilter = (file: string) =>
|
|
42
|
-
file.substring(file.length - 3) === ".ts" &&
|
|
43
|
-
file.substring(file.length - 5) !== ".d.ts";
|
|
44
36
|
const fallback: string[] = await SourceFinder.find({
|
|
45
37
|
include,
|
|
46
38
|
exclude,
|
|
47
|
-
filter:
|
|
39
|
+
filter: isTypeScriptSource,
|
|
48
40
|
});
|
|
49
41
|
return fallback.length === 0 ? controllers : mount(fallback);
|
|
50
42
|
};
|
|
@@ -89,3 +81,14 @@ function isTsxRuntime(): boolean {
|
|
|
89
81
|
process.env.TTSX_RUNTIME_MANIFEST.length !== 0
|
|
90
82
|
);
|
|
91
83
|
}
|
|
84
|
+
|
|
85
|
+
const isJavaScriptModule = (file: string): boolean =>
|
|
86
|
+
/\.(?:[cm]?js)$/.test(file.toLowerCase());
|
|
87
|
+
|
|
88
|
+
const isTypeScriptSource = (file: string): boolean => {
|
|
89
|
+
const lower: string = file.toLowerCase();
|
|
90
|
+
return (
|
|
91
|
+
/\.(?:[cm]?ts)$/.test(lower) &&
|
|
92
|
+
/\.(?:d\.[cm]?ts|d\.ts)$/.test(lower) === false
|
|
93
|
+
);
|
|
94
|
+
};
|
package/src/transform.ts
CHANGED
|
@@ -1,101 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
/** @internal */
|
|
6
|
-
interface ITtscPluginFactoryContext {
|
|
7
|
-
projectRoot: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/** @internal */
|
|
11
|
-
interface ITtscPlugin {
|
|
12
|
-
name: string;
|
|
13
|
-
source: string;
|
|
14
|
-
composes: string[];
|
|
15
|
-
contributors?: { name: string; source: string }[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const filename: string = currentFilename();
|
|
19
|
-
const dirname: string = path.dirname(filename);
|
|
3
|
+
import type { ITtscPlugin, ITtscPluginFactoryContext } from "ttsc";
|
|
20
4
|
|
|
21
5
|
/**
|
|
22
6
|
* `@nestia/core` ttsc plugin descriptor.
|
|
23
7
|
*
|
|
24
8
|
* `@nestia/sdk` is not a standalone plugin: its Go transform is declared here
|
|
25
|
-
* as a `contributor` that ttsc statically links into this host binary, and
|
|
26
|
-
*
|
|
9
|
+
* as a `contributor` that ttsc statically links into this host binary, and only
|
|
10
|
+
* when `@nestia/sdk` is actually resolvable from the project. A project
|
|
27
11
|
* depending on `@nestia/core` alone never compiles any SDK transform code.
|
|
28
12
|
*/
|
|
29
|
-
export function createTtscPlugin(
|
|
13
|
+
export default function createTtscPlugin(
|
|
30
14
|
context: ITtscPluginFactoryContext,
|
|
31
15
|
): ITtscPlugin {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
source: path.resolve(root(context), "native", "cmd", "ttsc-nestia"),
|
|
35
|
-
composes: ["typia/lib/transform"],
|
|
36
|
-
};
|
|
37
|
-
const sdk: string | null = resolveSdkContributorSource(context);
|
|
38
|
-
if (sdk !== null) plugin.contributors = [{ name: "sdk", source: sdk }];
|
|
39
|
-
return plugin;
|
|
40
|
-
}
|
|
41
|
-
export default createTtscPlugin;
|
|
42
|
-
|
|
43
|
-
function root(context: ITtscPluginFactoryContext): string {
|
|
44
|
-
return (
|
|
45
|
-
resolvePackageRoot("@nestia/core/package.json", context.projectRoot) ??
|
|
46
|
-
path.resolve(dirname, "..")
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function resolveSdkContributorSource(
|
|
51
|
-
context: ITtscPluginFactoryContext,
|
|
52
|
-
): string | null {
|
|
53
|
-
const manifest: string | null = resolvePackageRoot(
|
|
54
|
-
"@nestia/sdk/package.json",
|
|
55
|
-
context.projectRoot,
|
|
16
|
+
const requireFrom = createRequire(
|
|
17
|
+
path.join(context.projectRoot, "package.json"),
|
|
56
18
|
);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return fs.existsSync(source) ? source : null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function resolvePackageRoot(
|
|
63
|
-
packageJson: string,
|
|
64
|
-
projectRoot: string,
|
|
65
|
-
): string | null {
|
|
66
|
-
try {
|
|
67
|
-
return path.dirname(
|
|
68
|
-
require.resolve(packageJson, { paths: [dirname, projectRoot] }),
|
|
69
|
-
);
|
|
70
|
-
} catch {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function currentFilename(): string {
|
|
76
|
-
if (
|
|
77
|
-
typeof __filename === "string" &&
|
|
78
|
-
__filename !== "[stdin]" &&
|
|
79
|
-
__filename.length !== 0
|
|
80
|
-
)
|
|
81
|
-
return normalizeFilename(__filename);
|
|
82
|
-
|
|
83
|
-
const line: string | undefined = new Error().stack
|
|
84
|
-
?.split("\n")
|
|
85
|
-
.find(
|
|
86
|
-
(entry) =>
|
|
87
|
-
entry.includes("/src/transform.ts") ||
|
|
88
|
-
entry.includes("/lib/transform.js") ||
|
|
89
|
-
entry.includes("/lib/transform.mjs"),
|
|
90
|
-
);
|
|
91
|
-
const matched: RegExpMatchArray | null | undefined = line?.match(
|
|
92
|
-
/\(([^()]+):\d+:\d+\)|at ([^\s()]+):\d+:\d+/,
|
|
19
|
+
const root: string = path.dirname(
|
|
20
|
+
requireFrom.resolve("@nestia/core/package.json"),
|
|
93
21
|
);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
function normalizeFilename(value: string): string {
|
|
99
|
-
if (value.startsWith("file:")) return fileURLToPath(value);
|
|
100
|
-
return value;
|
|
22
|
+
return {
|
|
23
|
+
name: "@nestia/core",
|
|
24
|
+
source: path.resolve(root, "native", "cmd", "ttsc-nestia"),
|
|
25
|
+
};
|
|
101
26
|
}
|