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