ts-arc 1.1.18 → 1.1.20
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/dist/bin.js +33 -20
- package/dist/cli.js +33 -20
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -34,8 +34,13 @@ function stripJsonComments(input) {
|
|
|
34
34
|
}
|
|
35
35
|
if (char === "/" && input[i + 1] === "*") {
|
|
36
36
|
i += 2;
|
|
37
|
-
while (i < input.length
|
|
38
|
-
|
|
37
|
+
while (i < input.length) {
|
|
38
|
+
if (input[i - 1] === "*" && input[i] === "/") {
|
|
39
|
+
i++;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
i++;
|
|
43
|
+
}
|
|
39
44
|
continue;
|
|
40
45
|
}
|
|
41
46
|
output += char;
|
|
@@ -47,17 +52,13 @@ function loadConfig(filePath) {
|
|
|
47
52
|
const content = fs.readFileSync(filePath, "utf8");
|
|
48
53
|
const stripped = stripJsonComments(content);
|
|
49
54
|
const config = JSON.parse(stripped);
|
|
50
|
-
if (!config.extends)
|
|
51
|
-
return config;
|
|
52
|
-
}
|
|
55
|
+
if (!config.extends) return config;
|
|
53
56
|
const extendsVal = config.extends;
|
|
54
57
|
const tsconfigDir = path.dirname(filePath);
|
|
55
58
|
let extendsPath;
|
|
56
59
|
if (extendsVal.startsWith("./") || extendsVal.startsWith("../")) {
|
|
57
60
|
extendsPath = path.resolve(tsconfigDir, extendsVal);
|
|
58
|
-
if (!extendsPath.endsWith(".json"))
|
|
59
|
-
extendsPath += ".json";
|
|
60
|
-
}
|
|
61
|
+
if (!extendsPath.endsWith(".json")) extendsPath += ".json";
|
|
61
62
|
} else {
|
|
62
63
|
try {
|
|
63
64
|
extendsPath = require2.resolve(extendsVal);
|
|
@@ -73,24 +74,36 @@ function loadConfig(filePath) {
|
|
|
73
74
|
function findTsConfig(dir) {
|
|
74
75
|
let current = dir;
|
|
75
76
|
while (current !== path.parse(current).root) {
|
|
76
|
-
const
|
|
77
|
-
if (fs.existsSync(
|
|
78
|
-
return tsconfigPath;
|
|
79
|
-
}
|
|
77
|
+
const tsconfigPath2 = path.join(current, "tsconfig.json");
|
|
78
|
+
if (fs.existsSync(tsconfigPath2)) return tsconfigPath2;
|
|
80
79
|
current = path.dirname(current);
|
|
81
80
|
}
|
|
82
81
|
return null;
|
|
83
82
|
}
|
|
84
|
-
var tsArcConfig = {
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
var tsArcConfig = {
|
|
84
|
+
baseUrl: null,
|
|
85
|
+
paths: {},
|
|
86
|
+
tsconfigDir: null
|
|
87
|
+
};
|
|
88
|
+
var tsconfigPath = findTsConfig(process.cwd());
|
|
89
|
+
if (tsconfigPath) {
|
|
90
|
+
const mergedConfig = loadConfig(tsconfigPath);
|
|
91
|
+
const compilerOptions = mergedConfig.compilerOptions || {};
|
|
92
|
+
const tsconfigDir = path.dirname(tsconfigPath);
|
|
93
|
+
const baseUrlStr = compilerOptions.baseUrl;
|
|
94
|
+
tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
|
|
95
|
+
tsArcConfig.paths = compilerOptions.paths || {};
|
|
96
|
+
tsArcConfig.tsconfigDir = tsconfigDir;
|
|
97
|
+
}
|
|
98
|
+
function registerLoader() {
|
|
99
|
+
register(loaderPath, import.meta.url, { data: tsArcConfig });
|
|
87
100
|
}
|
|
88
101
|
async function setArcTsConfig(directory) {
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
const mergedConfig = loadConfig(
|
|
102
|
+
const tsconfigPath2 = findTsConfig(directory);
|
|
103
|
+
if (tsconfigPath2) {
|
|
104
|
+
const mergedConfig = loadConfig(tsconfigPath2);
|
|
92
105
|
const compilerOptions = mergedConfig.compilerOptions || {};
|
|
93
|
-
const tsconfigDir = path.dirname(
|
|
106
|
+
const tsconfigDir = path.dirname(tsconfigPath2);
|
|
94
107
|
const baseUrlStr = compilerOptions.baseUrl;
|
|
95
108
|
tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
|
|
96
109
|
tsArcConfig.paths = compilerOptions.paths || {};
|
|
@@ -100,7 +113,7 @@ async function setArcTsConfig(directory) {
|
|
|
100
113
|
async function loadModule(scriptUrl) {
|
|
101
114
|
const scriptPath = url.fileURLToPath(scriptUrl);
|
|
102
115
|
setArcTsConfig(path.dirname(scriptPath));
|
|
103
|
-
|
|
116
|
+
registerLoader();
|
|
104
117
|
import(scriptUrl).catch((err) => {
|
|
105
118
|
console.error(err);
|
|
106
119
|
process.exit(1);
|
package/dist/cli.js
CHANGED
|
@@ -40,8 +40,13 @@ function stripJsonComments(input) {
|
|
|
40
40
|
}
|
|
41
41
|
if (char === "/" && input[i + 1] === "*") {
|
|
42
42
|
i += 2;
|
|
43
|
-
while (i < input.length
|
|
44
|
-
|
|
43
|
+
while (i < input.length) {
|
|
44
|
+
if (input[i - 1] === "*" && input[i] === "/") {
|
|
45
|
+
i++;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
i++;
|
|
49
|
+
}
|
|
45
50
|
continue;
|
|
46
51
|
}
|
|
47
52
|
output += char;
|
|
@@ -53,17 +58,13 @@ function loadConfig(filePath) {
|
|
|
53
58
|
const content = fs.readFileSync(filePath, "utf8");
|
|
54
59
|
const stripped = stripJsonComments(content);
|
|
55
60
|
const config = JSON.parse(stripped);
|
|
56
|
-
if (!config.extends)
|
|
57
|
-
return config;
|
|
58
|
-
}
|
|
61
|
+
if (!config.extends) return config;
|
|
59
62
|
const extendsVal = config.extends;
|
|
60
63
|
const tsconfigDir = path.dirname(filePath);
|
|
61
64
|
let extendsPath;
|
|
62
65
|
if (extendsVal.startsWith("./") || extendsVal.startsWith("../")) {
|
|
63
66
|
extendsPath = path.resolve(tsconfigDir, extendsVal);
|
|
64
|
-
if (!extendsPath.endsWith(".json"))
|
|
65
|
-
extendsPath += ".json";
|
|
66
|
-
}
|
|
67
|
+
if (!extendsPath.endsWith(".json")) extendsPath += ".json";
|
|
67
68
|
} else {
|
|
68
69
|
try {
|
|
69
70
|
extendsPath = require2.resolve(extendsVal);
|
|
@@ -79,24 +80,36 @@ function loadConfig(filePath) {
|
|
|
79
80
|
function findTsConfig(dir) {
|
|
80
81
|
let current = dir;
|
|
81
82
|
while (current !== path.parse(current).root) {
|
|
82
|
-
const
|
|
83
|
-
if (fs.existsSync(
|
|
84
|
-
return tsconfigPath;
|
|
85
|
-
}
|
|
83
|
+
const tsconfigPath2 = path.join(current, "tsconfig.json");
|
|
84
|
+
if (fs.existsSync(tsconfigPath2)) return tsconfigPath2;
|
|
86
85
|
current = path.dirname(current);
|
|
87
86
|
}
|
|
88
87
|
return null;
|
|
89
88
|
}
|
|
90
|
-
var tsArcConfig = {
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
var tsArcConfig = {
|
|
90
|
+
baseUrl: null,
|
|
91
|
+
paths: {},
|
|
92
|
+
tsconfigDir: null
|
|
93
|
+
};
|
|
94
|
+
var tsconfigPath = findTsConfig(process.cwd());
|
|
95
|
+
if (tsconfigPath) {
|
|
96
|
+
const mergedConfig = loadConfig(tsconfigPath);
|
|
97
|
+
const compilerOptions = mergedConfig.compilerOptions || {};
|
|
98
|
+
const tsconfigDir = path.dirname(tsconfigPath);
|
|
99
|
+
const baseUrlStr = compilerOptions.baseUrl;
|
|
100
|
+
tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
|
|
101
|
+
tsArcConfig.paths = compilerOptions.paths || {};
|
|
102
|
+
tsArcConfig.tsconfigDir = tsconfigDir;
|
|
103
|
+
}
|
|
104
|
+
function registerLoader() {
|
|
105
|
+
register(loaderPath, import.meta.url, { data: tsArcConfig });
|
|
93
106
|
}
|
|
94
107
|
async function setArcTsConfig(directory) {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const mergedConfig = loadConfig(
|
|
108
|
+
const tsconfigPath2 = findTsConfig(directory);
|
|
109
|
+
if (tsconfigPath2) {
|
|
110
|
+
const mergedConfig = loadConfig(tsconfigPath2);
|
|
98
111
|
const compilerOptions = mergedConfig.compilerOptions || {};
|
|
99
|
-
const tsconfigDir = path.dirname(
|
|
112
|
+
const tsconfigDir = path.dirname(tsconfigPath2);
|
|
100
113
|
const baseUrlStr = compilerOptions.baseUrl;
|
|
101
114
|
tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
|
|
102
115
|
tsArcConfig.paths = compilerOptions.paths || {};
|
|
@@ -106,7 +119,7 @@ async function setArcTsConfig(directory) {
|
|
|
106
119
|
async function loadModule(scriptUrl2) {
|
|
107
120
|
const scriptPath2 = url.fileURLToPath(scriptUrl2);
|
|
108
121
|
setArcTsConfig(path.dirname(scriptPath2));
|
|
109
|
-
|
|
122
|
+
registerLoader();
|
|
110
123
|
import(scriptUrl2).catch((err) => {
|
|
111
124
|
console.error(err);
|
|
112
125
|
process.exit(1);
|