ts-arc 1.2.8 → 1.3.0
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 +1 -1
- package/dist/cli.js +103 -41
- package/dist/loader.js +13 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -120,7 +120,7 @@ async function loadModule(scriptUrl) {
|
|
|
120
120
|
const scriptPath = url.fileURLToPath(scriptUrl);
|
|
121
121
|
setArcTsConfig(path.dirname(scriptPath));
|
|
122
122
|
registerLoader();
|
|
123
|
-
import(scriptUrl).catch((err) => {
|
|
123
|
+
await import(scriptUrl).catch((err) => {
|
|
124
124
|
console.error(err);
|
|
125
125
|
process.exit(1);
|
|
126
126
|
});
|
package/dist/cli.js
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
6
11
|
|
|
7
12
|
// src/bin.ts
|
|
13
|
+
var bin_exports = {};
|
|
14
|
+
__export(bin_exports, {
|
|
15
|
+
loadModule: () => loadModule,
|
|
16
|
+
registerLoader: () => registerLoader,
|
|
17
|
+
setArcTsConfig: () => setArcTsConfig
|
|
18
|
+
});
|
|
8
19
|
import * as fs from "node:fs";
|
|
9
20
|
import { register } from "node:module";
|
|
10
21
|
import { createRequire } from "node:module";
|
|
11
22
|
import * as path from "node:path";
|
|
12
23
|
import * as url from "node:url";
|
|
13
|
-
var __filename = url.fileURLToPath(import.meta.url);
|
|
14
|
-
var __dirname = path.dirname(__filename);
|
|
15
|
-
var loaderPath = path.join(__dirname, "loader.js");
|
|
16
|
-
var loaderUrl = url.pathToFileURL(loaderPath).href;
|
|
17
|
-
var require2 = createRequire(import.meta.url);
|
|
18
24
|
function stripJsonComments(input) {
|
|
19
25
|
let output = "";
|
|
20
26
|
let insideString = false;
|
|
@@ -86,25 +92,6 @@ function findTsConfig(dir) {
|
|
|
86
92
|
}
|
|
87
93
|
return null;
|
|
88
94
|
}
|
|
89
|
-
var tsArcConfig = {
|
|
90
|
-
baseUrl: null,
|
|
91
|
-
paths: {},
|
|
92
|
-
tsconfigDir: null,
|
|
93
|
-
emitDecoratorMetadata: false,
|
|
94
|
-
experimentalDecorators: false
|
|
95
|
-
};
|
|
96
|
-
var tsconfigPath = findTsConfig(process.cwd());
|
|
97
|
-
if (tsconfigPath) {
|
|
98
|
-
const mergedConfig = loadConfig(tsconfigPath);
|
|
99
|
-
const compilerOptions = mergedConfig.compilerOptions || {};
|
|
100
|
-
const tsconfigDir = path.dirname(tsconfigPath);
|
|
101
|
-
const baseUrlStr = compilerOptions.baseUrl;
|
|
102
|
-
tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
|
|
103
|
-
tsArcConfig.paths = compilerOptions.paths || {};
|
|
104
|
-
tsArcConfig.tsconfigDir = tsconfigDir;
|
|
105
|
-
tsArcConfig.emitDecoratorMetadata = compilerOptions.emitDecoratorMetadata || false;
|
|
106
|
-
tsArcConfig.experimentalDecorators = compilerOptions.experimentalDecorators || false;
|
|
107
|
-
}
|
|
108
95
|
function registerLoader() {
|
|
109
96
|
register(loaderPath, import.meta.url, { data: tsArcConfig });
|
|
110
97
|
}
|
|
@@ -122,25 +109,100 @@ async function setArcTsConfig(directory) {
|
|
|
122
109
|
tsArcConfig.experimentalDecorators = compilerOptions.experimentalDecorators || false;
|
|
123
110
|
}
|
|
124
111
|
}
|
|
125
|
-
async function loadModule(
|
|
126
|
-
const
|
|
127
|
-
setArcTsConfig(path.dirname(
|
|
112
|
+
async function loadModule(scriptUrl) {
|
|
113
|
+
const scriptPath = url.fileURLToPath(scriptUrl);
|
|
114
|
+
setArcTsConfig(path.dirname(scriptPath));
|
|
128
115
|
registerLoader();
|
|
129
|
-
import(
|
|
116
|
+
await import(scriptUrl).catch((err) => {
|
|
130
117
|
console.error(err);
|
|
131
118
|
process.exit(1);
|
|
132
119
|
});
|
|
133
120
|
}
|
|
121
|
+
var __filename, __dirname, loaderPath, loaderUrl, require2, tsArcConfig, tsconfigPath;
|
|
122
|
+
var init_bin = __esm({
|
|
123
|
+
"src/bin.ts"() {
|
|
124
|
+
__filename = url.fileURLToPath(import.meta.url);
|
|
125
|
+
__dirname = path.dirname(__filename);
|
|
126
|
+
loaderPath = path.join(__dirname, "loader.js");
|
|
127
|
+
loaderUrl = url.pathToFileURL(loaderPath).href;
|
|
128
|
+
require2 = createRequire(import.meta.url);
|
|
129
|
+
tsArcConfig = {
|
|
130
|
+
baseUrl: null,
|
|
131
|
+
paths: {},
|
|
132
|
+
tsconfigDir: null,
|
|
133
|
+
emitDecoratorMetadata: false,
|
|
134
|
+
experimentalDecorators: false
|
|
135
|
+
};
|
|
136
|
+
tsconfigPath = findTsConfig(process.cwd());
|
|
137
|
+
if (tsconfigPath) {
|
|
138
|
+
const mergedConfig = loadConfig(tsconfigPath);
|
|
139
|
+
const compilerOptions = mergedConfig.compilerOptions || {};
|
|
140
|
+
const tsconfigDir = path.dirname(tsconfigPath);
|
|
141
|
+
const baseUrlStr = compilerOptions.baseUrl;
|
|
142
|
+
tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
|
|
143
|
+
tsArcConfig.paths = compilerOptions.paths || {};
|
|
144
|
+
tsArcConfig.tsconfigDir = tsconfigDir;
|
|
145
|
+
tsArcConfig.emitDecoratorMetadata = compilerOptions.emitDecoratorMetadata || false;
|
|
146
|
+
tsArcConfig.experimentalDecorators = compilerOptions.experimentalDecorators || false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
134
150
|
|
|
135
151
|
// src/cli.ts
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
152
|
+
import * as path2 from "node:path";
|
|
153
|
+
import * as url2 from "node:url";
|
|
154
|
+
import * as child_process from "node:child_process";
|
|
155
|
+
var __filename2 = url2.fileURLToPath(import.meta.url);
|
|
156
|
+
var __dirname2 = path2.dirname(__filename2);
|
|
157
|
+
var CHILD_ENV_VAR = "TS_ARC_IS_CHILD";
|
|
158
|
+
if (process.env[CHILD_ENV_VAR] !== "1") {
|
|
159
|
+
const script = process.argv[2];
|
|
160
|
+
if (!script) {
|
|
161
|
+
console.error("Usage: ts-arc <script.ts> [args...]");
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
const loaderPath2 = path2.join(__dirname2, "loader.js");
|
|
165
|
+
const loaderUrl2 = url2.pathToFileURL(loaderPath2).href;
|
|
166
|
+
let childExecArgv = [...process.execArgv];
|
|
167
|
+
const enableSourceMapsFlag = "--enable-source-maps";
|
|
168
|
+
if (!childExecArgv.includes(enableSourceMapsFlag)) {
|
|
169
|
+
childExecArgv.unshift(enableSourceMapsFlag);
|
|
170
|
+
}
|
|
171
|
+
const childEnv = {
|
|
172
|
+
...process.env,
|
|
173
|
+
[CHILD_ENV_VAR]: "1"
|
|
174
|
+
};
|
|
175
|
+
const spawnArgs = [
|
|
176
|
+
...childExecArgv,
|
|
177
|
+
__filename2,
|
|
178
|
+
script,
|
|
179
|
+
...process.argv.slice(3)
|
|
180
|
+
];
|
|
181
|
+
const result = child_process.spawnSync(
|
|
182
|
+
process.execPath,
|
|
183
|
+
spawnArgs,
|
|
184
|
+
{
|
|
185
|
+
stdio: "inherit",
|
|
186
|
+
env: childEnv
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
if (result.signal) {
|
|
190
|
+
process.kill(process.pid, result.signal);
|
|
191
|
+
}
|
|
192
|
+
process.exit(result.status ?? 0);
|
|
140
193
|
}
|
|
141
|
-
var scriptPath = path2.resolve(script);
|
|
142
|
-
var scriptUrl = url2.pathToFileURL(scriptPath).href;
|
|
143
|
-
process.argv = [process.argv[0], script, ...process.argv.slice(3)];
|
|
144
194
|
(async () => {
|
|
145
|
-
|
|
146
|
-
|
|
195
|
+
const script = process.argv[2];
|
|
196
|
+
if (!script) {
|
|
197
|
+
console.error("Usage: ts-arc <script.ts> [args...]");
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
const scriptPath = path2.resolve(script);
|
|
201
|
+
const scriptUrl = url2.pathToFileURL(scriptPath).href;
|
|
202
|
+
process.argv = [process.argv[0], script, ...process.argv.slice(3)];
|
|
203
|
+
const { loadModule: loadModule2 } = await Promise.resolve().then(() => (init_bin(), bin_exports));
|
|
204
|
+
await loadModule2(scriptUrl);
|
|
205
|
+
})().catch((err) => {
|
|
206
|
+
console.error(err);
|
|
207
|
+
process.exit(1);
|
|
208
|
+
});
|
package/dist/loader.js
CHANGED
|
@@ -305,7 +305,19 @@ function addMetadataDecorators(code) {
|
|
|
305
305
|
async function resolve2(specifier, context, nextResolve) {
|
|
306
306
|
let parentPath = process.cwd();
|
|
307
307
|
if (context.parentURL) {
|
|
308
|
-
|
|
308
|
+
const parentUrl = new URL(context.parentURL);
|
|
309
|
+
if (parentUrl.protocol === "file:") {
|
|
310
|
+
parentPath = path.dirname(url.fileURLToPath(parentUrl));
|
|
311
|
+
} else if (parentUrl.protocol === "copycat:") {
|
|
312
|
+
const as = parentUrl.searchParams.get("as");
|
|
313
|
+
if (as && typeof as === "string") {
|
|
314
|
+
parentPath = path.dirname(as);
|
|
315
|
+
} else {
|
|
316
|
+
parentPath = process.cwd();
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
parentPath = process.cwd();
|
|
320
|
+
}
|
|
309
321
|
}
|
|
310
322
|
if (specifier.startsWith("copycat://")) {
|
|
311
323
|
const u = new URL(specifier);
|