@zntc/core 0.1.5 → 0.1.7
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/bin/zntc.mjs +55 -4
- package/package.json +10 -10
package/bin/zntc.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
unlinkSync,
|
|
18
18
|
writeFileSync,
|
|
19
19
|
} from 'node:fs';
|
|
20
|
-
import { resolve, dirname, basename, extname, join, sep } from 'node:path';
|
|
20
|
+
import { resolve, dirname, basename, extname, join, sep, relative, isAbsolute } from 'node:path';
|
|
21
21
|
import { createServer } from 'node:http';
|
|
22
22
|
import { createServer as createHttpsServer } from 'node:https';
|
|
23
23
|
import { createRequire } from 'node:module';
|
|
@@ -1229,12 +1229,17 @@ async function runTranspile(opts) {
|
|
|
1229
1229
|
|
|
1230
1230
|
if (opts.outfile || opts.outdir) {
|
|
1231
1231
|
const name = basename(opts.entryPoints[0]).replace(/\.[^.]+$/, '.js');
|
|
1232
|
+
// 맵이 놓일 자리 — sources 를 그 자리 기준으로 적어야 브라우저가 원본을 찾는다.
|
|
1233
|
+
const outPath = opts.outfile ? resolve(opts.outfile) : join(resolve(opts.outdir), name);
|
|
1234
|
+
const { code, map } = finishTranspileSourcemap(result, outPath, opts.sourcemapMode);
|
|
1232
1235
|
// transpile result.code / result.map 은 string — writeOutputFiles 는 contents
|
|
1233
1236
|
// (Uint8Array) 를 받으므로 `Buffer.from` 으로 한 번 변환. 같은 메모리 backing 의
|
|
1234
1237
|
// utf-8 byte view 라 추가 copy 없음.
|
|
1235
|
-
const outputFiles = [{ path: name, contents: Buffer.from(
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
+
const outputFiles = [{ path: name, contents: Buffer.from(code) }];
|
|
1239
|
+
// outdir 로 낼 때도 맵을 함께 낸다 — 예전엔 outfile 일 때만 내서
|
|
1240
|
+
// `--outdir --sourcemap` 이 조용히 맵 없이 끝났다.
|
|
1241
|
+
if (map) {
|
|
1242
|
+
outputFiles.push({ path: name + '.map', contents: Buffer.from(map) });
|
|
1238
1243
|
}
|
|
1239
1244
|
writeOutputFiles(outputFiles, opts.outfile, opts.outdir, opts.entryPoints, opts.allowOverwrite);
|
|
1240
1245
|
} else {
|
|
@@ -1246,6 +1251,52 @@ async function runTranspile(opts) {
|
|
|
1246
1251
|
}
|
|
1247
1252
|
}
|
|
1248
1253
|
|
|
1254
|
+
/**
|
|
1255
|
+
* transpile 결과의 소스맵을 출력 자리에 맞게 마무리한다.
|
|
1256
|
+
*
|
|
1257
|
+
* 셋 다 CLI 만 아는 것이라 여기서 한다 — 라이브러리 호출자는 출력 경로를
|
|
1258
|
+
* 스스로 정하므로 그쪽이 맡는다.
|
|
1259
|
+
*
|
|
1260
|
+
* 1. `sources` 를 **맵이 놓일 자리 기준**으로 고친다. 엔진은 넘겨받은 파일
|
|
1261
|
+
* 이름(대개 CWD 기준)을 그대로 적어서, `-o dist/x.js` 로 내면 브라우저가
|
|
1262
|
+
* `dist/src/x.ts` 를 찾다 못 찾는다. tsc·esbuild 도 출력 기준으로 적는다.
|
|
1263
|
+
* 2. `file` 에 생성 파일 이름을 채운다 — 소스맵 v3 의 `file` 은 *생성된* 파일이다.
|
|
1264
|
+
* 3. 모드대로 마무리한다. linked(기본)는 `//# sourceMappingURL=` 주석을 붙이고,
|
|
1265
|
+
* external 은 맵만 내고 주석은 안 붙이며, inline 은 맵을 파일로 내지 않고
|
|
1266
|
+
* data URL 로 코드에 심는다. 예전에는 어느 모드든 주석이 안 붙어, 맵을 내고도
|
|
1267
|
+
* 브라우저가 찾지 못했다(inline 인데 .map 파일이 따로 나오기도 했다).
|
|
1268
|
+
*/
|
|
1269
|
+
function finishTranspileSourcemap(result, outPath, mode) {
|
|
1270
|
+
if (!result.map) return { code: result.code, map: null };
|
|
1271
|
+
let json;
|
|
1272
|
+
try {
|
|
1273
|
+
json = JSON.parse(result.map);
|
|
1274
|
+
} catch {
|
|
1275
|
+
return { code: result.code, map: result.map }; // 못 읽으면 손대지 않는다
|
|
1276
|
+
}
|
|
1277
|
+
json.file = basename(outPath);
|
|
1278
|
+
const outDirAbs = dirname(outPath);
|
|
1279
|
+
json.sources = (json.sources ?? []).map((src) => {
|
|
1280
|
+
if (!src || src.startsWith('data:')) return src;
|
|
1281
|
+
const abs = isAbsolute(src) ? src : resolve(src);
|
|
1282
|
+
const rel = relative(outDirAbs, abs).split(sep).join('/');
|
|
1283
|
+
return rel.startsWith('.') ? rel : './' + rel;
|
|
1284
|
+
});
|
|
1285
|
+
const text = JSON.stringify(json);
|
|
1286
|
+
|
|
1287
|
+
if (mode === 'inline') {
|
|
1288
|
+
const url = 'data:application/json;base64,' + Buffer.from(text).toString('base64');
|
|
1289
|
+
return { code: appendSourceMappingURL(result.code, url), map: null };
|
|
1290
|
+
}
|
|
1291
|
+
if (mode === 'external') return { code: result.code, map: text };
|
|
1292
|
+
return { code: appendSourceMappingURL(result.code, basename(outPath) + '.map'), map: text };
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
function appendSourceMappingURL(code, url) {
|
|
1296
|
+
if (code.includes('//# sourceMappingURL=')) return code;
|
|
1297
|
+
return code.replace(/\n*$/, '\n') + '//# sourceMappingURL=' + url + '\n';
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1249
1300
|
// ─── Bundle 모드 ───
|
|
1250
1301
|
|
|
1251
1302
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zntc/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "ZNTC native transpiler & compiler binding",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bundler",
|
|
@@ -76,15 +76,15 @@
|
|
|
76
76
|
"@zntc/test-helpers": "0.0.0"
|
|
77
77
|
},
|
|
78
78
|
"optionalDependencies": {
|
|
79
|
-
"@zntc/core-darwin-arm64": "0.1.
|
|
80
|
-
"@zntc/core-darwin-x64": "0.1.
|
|
81
|
-
"@zntc/core-linux-arm64-gnu": "0.1.
|
|
82
|
-
"@zntc/core-linux-arm64-musl": "0.1.
|
|
83
|
-
"@zntc/core-linux-x64-gnu": "0.1.
|
|
84
|
-
"@zntc/core-linux-x64-musl": "0.1.
|
|
85
|
-
"@zntc/core-win32-arm64-msvc": "0.1.
|
|
86
|
-
"@zntc/core-win32-ia32-msvc": "0.1.
|
|
87
|
-
"@zntc/core-win32-x64-msvc": "0.1.
|
|
79
|
+
"@zntc/core-darwin-arm64": "0.1.7",
|
|
80
|
+
"@zntc/core-darwin-x64": "0.1.7",
|
|
81
|
+
"@zntc/core-linux-arm64-gnu": "0.1.7",
|
|
82
|
+
"@zntc/core-linux-arm64-musl": "0.1.7",
|
|
83
|
+
"@zntc/core-linux-x64-gnu": "0.1.7",
|
|
84
|
+
"@zntc/core-linux-x64-musl": "0.1.7",
|
|
85
|
+
"@zntc/core-win32-arm64-msvc": "0.1.7",
|
|
86
|
+
"@zntc/core-win32-ia32-msvc": "0.1.7",
|
|
87
|
+
"@zntc/core-win32-x64-msvc": "0.1.7",
|
|
88
88
|
"browserslist": "^4.24.0",
|
|
89
89
|
"core-js": "^3.49.0",
|
|
90
90
|
"core-js-compat": "^3.49.0",
|