{"id":283967,"date":"2023-10-11T09:00:58","date_gmt":"2023-10-11T01:00:58","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=283967"},"modified":"2023-09-30T18:59:55","modified_gmt":"2023-09-30T10:59:55","slug":"bvfbzbxdjyxs","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/bvfbzbxdjyxs.html","title":{"rendered":"Bun v1.0.3 \u53d1\u5e03\uff0cZig \u7f16\u5199\u7684 JavaScript \u8fd0\u884c\u65f6"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nBun \u53d1\u5e03\u4e86\u5176\u6700\u65b0\u7248\u672c v1.0.3\uff0c\u8fd9\u662f\u4e00\u4e2a\u96c6 JavaScript \u8fd0\u884c\u65f6\u3001\u6253\u5305\u5668\u3001\u8f6c\u8bd1\u5668\u548c\u5305\u7ba1\u7406\u5668\u4e8e\u4e00\u4f53\u7684\u5de5\u5177\u3002\u8fd9\u6b21\u7684\u66f4\u65b0\u4e0d\u4ec5\u4fee\u590d\u4e86\u4f17\u591a\u5df2\u77e5\u7684\u95ee\u9898\uff0c\u8fd8\u5f15\u5165\u4e86\u4e00\u7cfb\u5217\u4ee4\u4eba\u671f\u5f85\u7684\u65b0\u529f\u80fd\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u9996\u5148\uff0cBun \u5728\u8fd9\u4e2a\u7248\u672c\u4e2d\u589e\u52a0\u4e86\u5bf9 TypeScript \u7684 emitDecoratorMetadata \u7684\u652f\u6301\uff0c\u8fd9\u610f\u5473\u7740\u5f00\u53d1\u8005\u73b0\u5728\u53ef\u4ee5\u5728 Bun \u4e2d\u65e0\u7f1d\u5730\u4f7f\u7528 Nest.js \u8fd9\u6837\u7684\u6846\u67b6\u3002Nest.js \u662f Node.js \u751f\u6001\u7cfb\u7edf\u4e2d\u7684\u4e00\u4e2a\u53d7\u6b22\u8fce\u7684\u6846\u67b6\uff0c\u800c Bun \u5bf9\u5176\u7684\u652f\u6301\u65e0\u7591\u5c06\u8fdb\u4e00\u6b65\u6269\u5927\u5176\u5728\u5f00\u53d1\u8005\u793e\u533a\u4e2d\u7684\u5f71\u54cd\u529b\u3002<\/p>\n

\"\"<\/p>\n

\u6b64\u5916\uff0cBun \u8fd8\u5f15\u5165\u4e86\u5bf9 module.parent \u7684\u652f\u6301\u3002\u8fd9\u662f Node.js \u4e2d\u7684\u4e00\u4e2a\u7279\u6027\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u786e\u5b9a\u4e00\u4e2a\u6a21\u5757\u662f\u76f4\u63a5\u8fd0\u884c\u8fd8\u662f\u88ab\u53e6\u4e00\u4e2a\u6a21\u5757\u6240\u9700\u3002\u8fd9\u4e2a\u529f\u80fd\u7684\u5f15\u5165\u8fdb\u4e00\u6b65\u589e\u5f3a\u4e86 Bun \u4e0e Node.js \u7684\u517c\u5bb9\u6027\u3002<\/p>\n

\u5728\u79c1\u6709 npm \u4ed3\u5e93\u7684\u652f\u6301\u65b9\u9762\uff0cBun \u4e5f\u505a\u4e86\u5927\u91cf\u7684\u5de5\u4f5c\u3002\u73b0\u5728\uff0c\u5b83\u5df2\u7ecf\u4e0e Azure Artifacts \u548c JFrog Artifactory \u8fd9\u6837\u7684\u79c1\u6709 npm \u4ed3\u5e93\u5b9e\u73b0\u4e86\u66f4\u597d\u7684\u517c\u5bb9\u6027\u3002\u7528\u6237\u53ef\u4ee5\u4f7f\u7528 bunfig.toml \u6587\u4ef6\u6765\u914d\u7f6e\u8fd9\u4e9b\u79c1\u6709\u4ed3\u5e93\uff0c\u8fd9\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u66f4\u5927\u7684\u7075\u6d3b\u6027\u3002<\/p>\n

\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u5e94\u5e7f\u5927\u7528\u6237\u7684\u53cd\u9988\uff0cBun \u51b3\u5b9a\u9ed8\u8ba4\u5173\u95ed [0.5ms] env loaded \u6d88\u606f\u3002\u8fd9\u662f\u4e00\u4e2a\u5c0f\u6539\u52a8\uff0c\u4f46\u5b83\u53cd\u6620\u4e86 Bun \u5bf9\u7528\u6237\u53cd\u9988\u7684\u91cd\u89c6\u3002<\/p>\n

\u5728\u4e0e Node.js \u7684\u517c\u5bb9\u6027\u65b9\u9762\uff0cBun \u4e5f\u505a\u4e86\u5927\u91cf\u7684\u5de5\u4f5c\u3002\u8fd9\u6b21\u7684\u66f4\u65b0\u4e2d\uff0cBun \u5b9e\u73b0\u4e86 console.Console \u6784\u9020\u51fd\u6570\uff0c\u5e76\u4fee\u590d\u4e86\u73af\u5883\u53d8\u91cf\u5904\u7406\u4e2d\u7684\u95ee\u9898\u3002\u8fd9\u4e9b\u6539\u8fdb\u90fd\u662f\u4e3a\u4e86\u786e\u4fdd Bun \u80fd\u591f\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e0e Node.js \u4e00\u81f4\u7684\u5f00\u53d1\u4f53\u9a8c\u3002<\/p>\n

import { Console } from \"console\";\r\nimport { createWriteStream } from \"fs\";\r\n\r\nconst writer = new Console({ stdout: createWriteStream(\"log.txt\") });\r\n\r\nwriter.log(\"hello\");\r\nwriter.log(\"world\", { x: 2 });<\/pre>\n

\u6b64\u5916\uff0cBun \u8fd8\u4fee\u590d\u4e86\u4e00\u7cfb\u5217\u5df2\u77e5\u7684\u95ee\u9898\u3002\u5176\u4e2d\u5305\u62ec request.json() \u4e2d\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u4ee5\u53ca\u4e0e bun pm rm cache \u547d\u4ee4\u76f8\u5173\u7684\u4e00\u4e2a\u95ee\u9898\u3002\u8fd9\u4e9b\u4fee\u590d\u90fd\u662f\u4e3a\u4e86\u786e\u4fdd Bun \u80fd\u591f\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e00\u4e2a\u7a33\u5b9a\u548c\u53ef\u9760\u7684\u5f00\u53d1\u73af\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u9996\u5148\uff0cBun \u5728\u8fd9\u4e2a\u7248\u672c\u4e2d\u589e\u52a0\u4e86\u5bf9 TypeScript \u7684 emitDecoratorMetadata \u7684\u652f […]<\/p>\n","protected":false},"author":1479,"featured_media":172449,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[21],"tags":[],"class_list":["post-283967","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/283967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=283967"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/283967\/revisions"}],"predecessor-version":[{"id":284174,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/283967\/revisions\/284174"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/172449"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=283967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=283967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=283967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}